So, I want SQL errors to prevent c++ code from compiling via some cmake script or something. I know I could add some kind of runtime error checking but I don't want the following code to build sucessfully (not a question about pqxx, but SQL errors in c++ in general):
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main() {
connection conn("dbname=d user=u");
conn.prepare("invalid_sql", "SELECT 1 FROM WHERE a = $1");
nontransaction txn(conn);
txn.prepared("invalid_sql")(1.0).exec();
cout << "the process already died due to invalid SQL" << endl;
return 0;
}
Closing this question. The other answer is fine, but that's not what I did.
What I decided to do was put the prepared statements in a init_sql() method and call that using boost/test/unit_test.hpp against a replicated database with jenkins, which provides notifications for unit test failures.