Executing queries

So let's execute an actual query. There is no "query class" in libpqxx; we really do try to keep your life simple.

You execute queries within a transaction, by passing the query string to the transaction object's exec method or one of its variants. If the query fails to complete successfully, these methods will throw the appropriate exception.

The query itself is a standard C string in this case, ie. a char const * but you'll frequently want to use a C++ string to make it easy to include variables:

	void DeleteEntry(work &T, string Table, long ID)
	{
	T.exec("DELETE FROM " + Table + " WHERE ID=" + to_string(ID));
	}
      

In some places, even stringstreams will work, so you can use the full stream formatting capabilities, locales etc. in the standard C++ library to compose your SQL queries.