Access violation at qsql_oci when executing/preparing QSqlQuery
-
In SqlTreeModel.cpp, I first successfully connect to an Oracle database
db
, then I checkeddb.isValid()
is true anddb.isOpen()
is true. Then, I create a QSqlQuery and prepare/execute it:QSqlQuery table_query(db); // table_query.exec("SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER=%1"_L1 % db.userName().toUpper()); // Prepared statement if (const bool prepared = table_query.prepare("SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER=':owner'"); not prepared) { qWarning() << "Failed to prepare SELECT TABLE_NAME query:" << table_query.lastError(); } table_query.bindValue(":owner", db.userName().toUpper()); table_query.exec(); // set active if return true
However, the program throws an exception 0xc0000005 encountered at address 0x7ffe0936c683: Access violation reading location 0xffffffffffffffff at
table_query.prepare()
By debugging, the exception occurs at line 1911delete d->cols
inqsql_oci.cpp
:bool QOCIResult::internal_prepare() { Q_D(QOCIResult); int r = 0; QString noStr; QSqlResult::prepare(noStr); delete d->cols; ... }
Here, the value of d is 0xcdcdcdcdcdcdcdcd, i.e., d is initialized.
The function call stack is
SqlTreeModel::refresh()->QSqlQuery::exec()->QOCIResult::reset->QOCIResult::prepare->QOCIResult:internal_prepare
How to fix this exception? -
Then apply the patch or use Qt6. 8
-
What Qt version do you use? see https://bugreports.qt.io/browse/QTBUG-136024
-
What Qt version do you use? see https://bugreports.qt.io/browse/QTBUG-136024
@Christian-Ehrlicher Yes I'm using Qt 6.9.0 and my case is exactly the same as this bug.
-
Then apply the patch or use Qt6. 8
-
Then apply the patch or use Qt6. 8
@Christian-Ehrlicher Hello, I applied the patch in my Qt installation directory, rebuilt and re-installed the SQL driver in that directory, and completely rebuilt my app, but the problem still exists
-
Then you most likely did something wrong. Make sure the oci driver is really built and installed. Also post the complete backtrace once you made sure the new driver is used.
-
Then you most likely did something wrong. Make sure the oci driver is really built and installed. Also post the complete backtrace once you made sure the new driver is used.
@Christian-Ehrlicher Thank you. I found that after I add
-DCMAKE_BUILD_TYPE=Debug
when I build qoci the qsqlocid.dll, etc. are built and installed, then the problem can be fixed -