Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created July 11, 2015 01:41
Show Gist options
  • Select an option

  • Save TheBuzzSaw/c756b0919760372095e5 to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/c756b0919760372095e5 to your computer and use it in GitHub Desktop.
The postgres API is gross...
#include <libpq-fe.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
PGconn* connection = PQconnectdb(
"host=localhost port=5432 dbname=swccg user=postgres");
if (PQstatus(connection) == CONNECTION_OK)
{
PGresult* result = PQexec(connection, "SELECT * FROM legacy_card_info");
cout << PQntuples(result) << " rows" << endl;
cout << PQnfields(result) << " columns" << endl;
PQclear(result);
}
else
{
cerr << PQerrorMessage(connection) << '\n';
}
PQfinish(connection);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment