Skip to content

Instantly share code, notes, and snippets.

@TheFern2
Last active April 4, 2022 12:18
Show Gist options
  • Save TheFern2/6790b26d7fbc3119ca45b85396bd3df9 to your computer and use it in GitHub Desktop.
Save TheFern2/6790b26d7fbc3119ca45b85396bd3df9 to your computer and use it in GitHub Desktop.
libpqxx pqxx windows install guide
#include <iostream>
#include <pqxx/pqxx>
int main()
{
std::string conn_str = "host=localhost port=5432 dbname=test01 user=postgres password=sdfsdfsdf";
try
{
pqxx::connection conn(conn_str.c_str());
pqxx::work w(conn);
pqxx::row r = w.exec1("SELECT pg_database_size('test01') / 1024 / 1024;");
std::cout << "Db size: " << r[0].as<int>() << "MB" << std::endl;
pqxx::result r1 = w.exec("SELECT * FROM users");
for (auto const& row : r1)
{
for (auto const& field : row) std::cout << field.c_str() << '\t';
std::cout << std::endl;
}
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
}
system("pause");
}

Steps to build libpqxx on Windows

Clone needed version

git clone --depth 1 --branch 6.4.7 https://github.com/jtv/libpqxx.git

Open cmake gui as admin

  • Hit Configure
  • Uncheck Build_Test
  • Only need Debug/Release (Or if you only need release delete debug)
  • Ensure install path is correct
  • Hit Generate, Open project
  • Ensure pqxx_shared, static, and ALL_BUILD are using c++ version needed
  • Right click build on ALL_BUILD, then right click build on INSTALL

source: http://en.wiki.imlint.org/Pqxx_tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment