Added kexi hotfix to support versions 12 and higher, fixing issue #15

Signed-off-by: ormorph <roma251078@mail.ru>
pull/16/head
ormorph 3 years ago
parent 1968391ae9
commit 5274e5d455

@ -3227,6 +3227,10 @@ bool Connection::updateRow(QuerySchema &query, RowData& data, RowEditBuffer& buf
setError(ERR_UPDATE_SERVER_ERROR, i18n("Row updating on the server failed.")); setError(ERR_UPDATE_SERVER_ERROR, i18n("Row updating on the server failed."));
return false; return false;
} }
if (m_driver->beh->ROW_ID_FIELD_NAME == "xmin")
data[data.size()-1]=drv_lastInsertRowID();
//success: now also assign new values in memory: //success: now also assign new values in memory:
TQMap<QueryColumnInfo*,int> columnsOrderExpanded; TQMap<QueryColumnInfo*,int> columnsOrderExpanded;
updateRowDataWithNewValues(query, data, b, columnsOrderExpanded); updateRowDataWithNewValues(query, data, b, columnsOrderExpanded);

@ -203,7 +203,6 @@ bool pqxxSqlConnection::drv_useDatabase( const TQString &dbName, bool *cancelled
try try
{ {
d->pqxxsql = new pqxx::connection( conninfo.latin1() ); 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) { if (d->version) {
//! @todo set version using the connection pointer when we drop libpqxx for libpq //! @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 //Execute an SQL statement
bool pqxxSqlConnection::drv_executeSQL( const TQString& 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; // KexiDBDrvDbg << "pqxxSqlConnection::drv_executeSQL: " << statement << endl;
bool ok = false; bool ok = false;
@ -277,7 +285,15 @@ bool pqxxSqlConnection::drv_executeSQL( const TQString& statement )
// m_trans = new pqxx::nontransaction(*m_pqxxsql); // m_trans = new pqxx::nontransaction(*m_pqxxsql);
// KexiDBDrvDbg << "About to execute" << endl; // KexiDBDrvDbg << "About to execute" << endl;
//Create a result object through the transaction //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; // KexiDBDrvDbg << "Executed" << endl;
//Commit the transaction //Commit the transaction
if (implicityStarted) { if (implicityStarted) {
@ -327,11 +343,9 @@ TQ_ULLONG pqxxSqlConnection::drv_lastInsertRowID()
{ {
if (d->res) if (d->res)
{ {
pqxx::oid theOid = d->res->inserted_oid(); if (!lastRowId.isEmpty())
if (theOid != pqxx::oid_none)
{ {
return (TQ_ULLONG)theOid; return lastRowId.toULong();
} }
else else
{ {

@ -90,6 +90,7 @@ class pqxxSqlConnection : public Connection
pqxxSqlConnectionInternal *d; pqxxSqlConnectionInternal *d;
private: private:
TQString lastRowId;
TQString escapeName(const TQString &tn) const; TQString escapeName(const TQString &tn) const;
// pqxx::transaction_base* m_trans; // pqxx::transaction_base* m_trans;
//! temporary solution for executeSQL()... //! temporary solution for executeSQL()...

@ -41,7 +41,7 @@ pqxxSqlDriver::pqxxSqlDriver( TQObject *parent, const char *name, const TQString
//! @todo enable this when kexidb supports multiple: d->features = MultipleTransactions | CursorForward | CursorBackward; //! @todo enable this when kexidb supports multiple: d->features = MultipleTransactions | CursorForward | CursorBackward;
beh->UNSIGNED_TYPE_KEYWORD = ""; beh->UNSIGNED_TYPE_KEYWORD = "";
beh->ROW_ID_FIELD_NAME = "oid"; beh->ROW_ID_FIELD_NAME = "xmin";
beh->SPECIAL_AUTO_INCREMENT_DEF = false; beh->SPECIAL_AUTO_INCREMENT_DEF = false;
beh->AUTO_INCREMENT_TYPE = "SERIAL"; beh->AUTO_INCREMENT_TYPE = "SERIAL";
beh->AUTO_INCREMENT_FIELD_OPTION = ""; beh->AUTO_INCREMENT_FIELD_OPTION = "";

Loading…
Cancel
Save