--- C:/QtSDK/QtSources/4.7.4/src/sql/drivers/oci/qsql_oci.cpp Fri Mar 23 12:32:22 2012 +++ C:/Quati/develop/QtSrc/qt-everywhere-opensource-src-4.7.4/src/sql/drivers/oci/qsql_oci.cpp Thu Mar 29 14:31:04 2012 @@ -82,6 +82,9 @@ //#define QOCI_DEBUG +Q_DECLARE_METATYPE(QOCIResult *) + + Q_DECLARE_METATYPE(OCIEnv*) Q_DECLARE_METATYPE(OCIStmt*) @@ -340,6 +343,18 @@ const_cast(&rptr->id), -1, SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT); + } else if (qVariantCanConvert(val) && isOutValue(pos)) { + QOCIResult *res = qVariantValue(val); + + if (res->internal_prepare()) { + r = OCIBindByPos(sql, hbnd, err, + pos + 1, + const_cast(&res->d->sql), + (sb4)0, + SQLT_RSET, indPtr, 0, 0, 0, 0, OCI_DEFAULT); + + res->isCursor = true; + } } else { qWarning("Unknown bind variable"); r = OCI_ERROR; @@ -1795,6 +1810,7 @@ : QSqlCachedResult(db) { d = new QOCIResultPrivate(this, p); + isCursor = false; } QOCIResult::~QOCIResult() @@ -1890,12 +1906,14 @@ return rowCount; } -bool QOCIResult::prepare(const QString& query) -{ +bool QOCIResult::internal_prepare() { int r = 0; - QSqlResult::prepare(query); + QString noStr; + QSqlResult::prepare(noStr); + + if (d->cols) + delete d->cols; - delete d->cols; d->cols = 0; QSqlCachedResult::cleanup(); @@ -1904,20 +1922,34 @@ if (r != OCI_SUCCESS) qOraWarning("QOCIResult::prepare: unable to free statement handle:", d->err); } - if (query.isEmpty()) - return false; + r = OCIHandleAlloc(d->env, reinterpret_cast(&d->sql), OCI_HTYPE_STMT, 0, 0); + if (r != OCI_SUCCESS) { qOraWarning("QOCIResult::prepare: unable to alloc statement:", d->err); setLastError(qMakeError(QCoreApplication::translate("QOCIResult", "Unable to alloc statement"), QSqlError::StatementError, d->err)); return false; } + d->setStatementAttributes(); + + return true; +} + +bool QOCIResult::prepare(const QString& query) +{ + if (query.isEmpty()) + return false; + + if (!internal_prepare()) + return false; + + int r; const OraText *txt = reinterpret_cast(query.utf16()); const int len = query.length() * sizeof(QChar); r = OCIStmtPrepare(d->sql, @@ -1982,23 +2014,26 @@ return false; } - // execute - r = OCIStmtExecute(d->svc, - d->sql, - d->err, - iters, - 0, - 0, - 0, - mode); - if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) { - qOraWarning("QOCIResult::exec: unable to execute statement:", d->err); - setLastError(qMakeError(QCoreApplication::translate("QOCIResult", - "Unable to execute statement"), QSqlError::StatementError, d->err)); -#ifdef QOCI_DEBUG - qDebug() << "lastQuery()" << lastQuery(); -#endif - return false; + if (!isCursor) + { + // execute + r = OCIStmtExecute(d->svc, + d->sql, + d->err, + iters, + 0, + 0, + 0, + mode); + if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) { + qOraWarning("QOCIResult::exec: unable to execute statement:", d->err); + setLastError(qMakeError(QCoreApplication::translate("QOCIResult", + "Unable to execute statement"), QSqlError::StatementError, d->err)); + #ifdef QOCI_DEBUG + qDebug() << "lastQuery()" << lastQuery(); + #endif + return false; + } } if (stmtType == OCI_STMT_SELECT) {