-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a26185
commit 0b85724
Showing
8 changed files
with
78 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
add_subdirectory(polygeist) | ||
add_subdirectory(sql) | ||
if (ENABLE_SQL) | ||
add_subdirectory(sql) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
add_subdirectory(polygeist) | ||
add_subdirectory(sql) | ||
if (ENABLE_SQL) | ||
add_subdirectory(sql) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,57 @@ | ||
#include <libpq-fe.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <libpq-fe.h> | ||
|
||
// PGresult *PQexec(PGconn*, const char* command); | ||
// PQgetvalue | ||
// %7 = call @PQexec(%2, %6) : (memref<?x1xi8>, memref<?xi8>) -> memref<?x1xi8> | ||
#pragma lower_to(num_rows_fn, "sql.num_results") | ||
int num_rows_fn(size_t);// char* | ||
// %7 = call @PQexec(%2, %6) : (memref<?x1xi8>, memref<?xi8>) -> | ||
// memref<?x1xi8> | ||
// #pragma lower_to(num_rows_fn, "sql.num_results") | ||
// int num_rows_fn(size_t);// char* | ||
|
||
#pragma lower_to(get_value_fn_int, "sql.get_value") | ||
int get_value_fn_int(size_t, int, int); | ||
// #pragma lower_to(get_value_fn_int, "sql.get_value") | ||
// int get_value_fn_int(size_t, int, int); | ||
|
||
#pragma lower_to(get_value_fn_double, "sql.get_value") | ||
double get_value_fn_double(size_t, int, int); | ||
// #pragma lower_to(get_value_fn_double, "sql.get_value") | ||
// double get_value_fn_double(size_t, int, int); | ||
|
||
// #pragma lower_to(execute, "sql.execute") | ||
// PGresult* execute(size_t, char*); | ||
|
||
void do_exit(PGconn *conn) { | ||
PQfinish(conn); | ||
exit(1); | ||
PQfinish(conn); | ||
exit(1); | ||
} | ||
|
||
int main() { | ||
|
||
PGconn *conn = PQconnectdb("user=janbodnar dbname=testdb"); | ||
|
||
if (PQstatus(conn) == CONNECTION_BAD) { | ||
|
||
fprintf(stderr, "Connection to database failed: %s\n", | ||
PQerrorMessage(conn)); | ||
do_exit(conn); | ||
} | ||
|
||
PGresult *res = PQexec(conn, "SELECT VERSION()"); | ||
|
||
if (PQresultStatus(res) != PGRES_TUPLES_OK) { | ||
PGconn *conn = PQconnectdb("user=carl dbname=testdb"); | ||
|
||
printf("No data retrieved\n"); | ||
PQclear(res); | ||
do_exit(conn); | ||
} | ||
|
||
printf("%s\n", PQgetvalue(res, 0, 0)); | ||
printf("%d\n", get_value_fn_int((size_t)res, 0, 0)); | ||
printf("%d\n", num_rows_fn((size_t)res)); | ||
// res, 0, 0)); | ||
if (PQstatus(conn) == CONNECTION_BAD) { | ||
|
||
fprintf(stderr, "Connection to database failed: %s\n", | ||
PQerrorMessage(conn)); | ||
do_exit(conn); | ||
} | ||
|
||
// PGresult *res = PQexec(conn, "SELECT 17"); | ||
PGresult *res = PQexec(conn, "SELECT a FROM table1"); | ||
PGresult *res1 = PQexec(conn, "SELECT * FROM table1 WHERE b > 10 OR c < 10 AND a <= 20"); | ||
PGresult *res2 = PQexec(conn, "SELECT * FROM table1 WHERE b > 10 AND c < 10"); | ||
PGresult *res3 = PQexec(conn, "SELECT b, c FROM table1 WHERE a <= 10 LIMIT 10"); | ||
// PGresult *res3 = PQexec(conn, "SELECT b, c FROM table1 LIMIT ALL"); | ||
if (PQresultStatus(res) != PGRES_TUPLES_OK) { | ||
|
||
printf("No data retrieved\n"); | ||
PQclear(res); | ||
PQfinish(conn); | ||
do_exit(conn); | ||
} | ||
|
||
PQclear(res); | ||
PQclear(res1); | ||
PQclear(res2); | ||
PQclear(res3); | ||
PQfinish(conn); | ||
|
||
return 0; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters