Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Modified from libpq example code.
- // This code is made available under the same license as the original.
- // Build commmand:
- // gcc -o libpq-bench libpq-bench.c -I`pg_config --includedir` -L`pg_config --libdir` -lpq
- #include <stdio.h>
- #include <stdlib.h>
- #include <libpq-fe.h>
- int
- main(int argc, char **argv)
- {
- const char *conninfo;
- PGconn *conn;
- PGresult *res;
- if (argc > 1)
- conninfo = argv[1];
- else
- conninfo = "";
- conn = PQconnectdb(conninfo);
- if (PQstatus(conn) != CONNECTION_OK)
- {
- fprintf(stderr, "Connection to database failed: %s",
- PQerrorMessage(conn));
- PQfinish(conn);
- exit(1);
- }
- int value;
- if (!PQsendQuery(conn, "select generate_series(1, 10000000)"))
- {
- fprintf(stderr, "Send query failed: %s", PQerrorMessage(conn));
- PQfinish(conn);
- exit(1);
- }
- int i, j;
- for (;;) {
- res = PQgetResult(conn);
- if (res == NULL)
- break;
- for (i = 0; i < PQntuples(res); i++) {
- value = atoi(PQgetvalue(res, i, 0));
- }
- PQclear(res);
- }
- printf("%d\n", value);
- PQfinish(conn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement