|
|
|
@ -203,7 +203,6 @@ bool pqxxSqlConnection::drv_useDatabase( const TQString &dbName, bool *cancelled
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
d->pqxxsql = new pqxx::connection( conninfo.latin1() );
|
|
|
|
|
drv_executeSQL( "SET DEFAULT_WITH_OIDS TO ON" ); //Postgres 8.1 changed the default to no oids but we need them
|
|
|
|
|
|
|
|
|
|
if (d->version) {
|
|
|
|
|
//! @todo set version using the connection pointer when we drop libpqxx for libpq
|
|
|
|
@ -259,6 +258,15 @@ bool pqxxSqlConnection::drv_dropDatabase( const TQString &dbName )
|
|
|
|
|
//Execute an SQL statement
|
|
|
|
|
bool pqxxSqlConnection::drv_executeSQL( const TQString& statement )
|
|
|
|
|
{
|
|
|
|
|
std::string temp = std::string(statement.utf8());
|
|
|
|
|
// Adding xmin result output for inserting rows
|
|
|
|
|
bool isInserted = false;
|
|
|
|
|
pqxx::result::const_iterator itRow;
|
|
|
|
|
if (statement.find("INSERT INTO") == 0 || statement.find("UPDATE") == 0) {
|
|
|
|
|
temp += " RETURNING xmin";
|
|
|
|
|
isInserted = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KexiDBDrvDbg << "pqxxSqlConnection::drv_executeSQL: " << statement << endl;
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
|
@ -277,7 +285,15 @@ bool pqxxSqlConnection::drv_executeSQL( const TQString& statement )
|
|
|
|
|
// m_trans = new pqxx::nontransaction(*m_pqxxsql);
|
|
|
|
|
// KexiDBDrvDbg << "About to execute" << endl;
|
|
|
|
|
//Create a result object through the transaction
|
|
|
|
|
d->res = new pqxx::result(m_trans->data->exec(std::string(statement.utf8())));
|
|
|
|
|
d->res = new pqxx::result(m_trans->data->exec(temp));
|
|
|
|
|
|
|
|
|
|
// Get the xmin of the last inserted row
|
|
|
|
|
if (isInserted) {
|
|
|
|
|
itRow = d->res->begin();
|
|
|
|
|
itRow[0].to(temp);
|
|
|
|
|
lastRowId = temp.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KexiDBDrvDbg << "Executed" << endl;
|
|
|
|
|
//Commit the transaction
|
|
|
|
|
if (implicityStarted) {
|
|
|
|
@ -327,11 +343,9 @@ TQ_ULLONG pqxxSqlConnection::drv_lastInsertRowID()
|
|
|
|
|
{
|
|
|
|
|
if (d->res)
|
|
|
|
|
{
|
|
|
|
|
pqxx::oid theOid = d->res->inserted_oid();
|
|
|
|
|
|
|
|
|
|
if (theOid != pqxx::oid_none)
|
|
|
|
|
if (!lastRowId.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return (TQ_ULLONG)theOid;
|
|
|
|
|
return lastRowId.toULong();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|