qsql_sqlite and qsql_sqlite2: don't hold driver data in result
Change-Id: Ia4f6adc6daaea97ac06246e9d01c6561de1227ea Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
parent
a5cd081879
commit
371c2e4786
@ -150,8 +150,6 @@ public:
|
||||
void initColumns(bool emptyResultset);
|
||||
void finalize();
|
||||
|
||||
sqlite3 *access;
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
bool skippedStatus; // the status of the fetchNext() that's skipped
|
||||
@ -326,7 +324,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
|
||||
// SQLITE_ERROR is a generic error code and we must call sqlite3_reset()
|
||||
// to get the specific error message.
|
||||
res = sqlite3_reset(stmt);
|
||||
q->setLastError(qMakeError(access, QCoreApplication::translate("QSQLiteResult",
|
||||
q->setLastError(qMakeError(drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to fetch row"), QSqlError::ConnectionError, res));
|
||||
q->setAt(QSql::AfterLastRow);
|
||||
return false;
|
||||
@ -334,7 +332,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
|
||||
case SQLITE_BUSY:
|
||||
default:
|
||||
// something wrong, don't get col info, but still return false
|
||||
q->setLastError(qMakeError(access, QCoreApplication::translate("QSQLiteResult",
|
||||
q->setLastError(qMakeError(drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to fetch row"), QSqlError::ConnectionError, res));
|
||||
sqlite3_reset(stmt);
|
||||
q->setAt(QSql::AfterLastRow);
|
||||
@ -347,7 +345,6 @@ QSQLiteResult::QSQLiteResult(const QSQLiteDriver* db)
|
||||
: QSqlCachedResult(*new QSQLiteResultPrivate(this, db))
|
||||
{
|
||||
Q_D(QSQLiteResult);
|
||||
d->access = d->drv_d_func()->access;
|
||||
const_cast<QSQLiteDriverPrivate*>(d->drv_d_func())->results.append(this);
|
||||
}
|
||||
|
||||
@ -383,7 +380,7 @@ bool QSQLiteResult::prepare(const QString &query)
|
||||
const void *pzTail = NULL;
|
||||
|
||||
#if (SQLITE_VERSION_NUMBER >= 3003011)
|
||||
int res = sqlite3_prepare16_v2(d->access, query.constData(), (query.size() + 1) * sizeof(QChar),
|
||||
int res = sqlite3_prepare16_v2(d->drv_d_func()->access, query.constData(), (query.size() + 1) * sizeof(QChar),
|
||||
&d->stmt, &pzTail);
|
||||
#else
|
||||
int res = sqlite3_prepare16(d->access, query.constData(), (query.size() + 1) * sizeof(QChar),
|
||||
@ -391,12 +388,12 @@ bool QSQLiteResult::prepare(const QString &query)
|
||||
#endif
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
|
||||
setLastError(qMakeError(d->drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to execute statement"), QSqlError::StatementError, res));
|
||||
d->finalize();
|
||||
return false;
|
||||
} else if (pzTail && !QString(reinterpret_cast<const QChar *>(pzTail)).trimmed().isEmpty()) {
|
||||
setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
|
||||
setLastError(qMakeError(d->drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to execute multiple statements at a time"), QSqlError::StatementError, SQLITE_MISUSE));
|
||||
d->finalize();
|
||||
return false;
|
||||
@ -417,7 +414,7 @@ bool QSQLiteResult::exec()
|
||||
|
||||
int res = sqlite3_reset(d->stmt);
|
||||
if (res != SQLITE_OK) {
|
||||
setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
|
||||
setLastError(qMakeError(d->drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to reset statement"), QSqlError::StatementError, res));
|
||||
d->finalize();
|
||||
return false;
|
||||
@ -477,7 +474,7 @@ bool QSQLiteResult::exec()
|
||||
}
|
||||
}
|
||||
if (res != SQLITE_OK) {
|
||||
setLastError(qMakeError(d->access, QCoreApplication::translate("QSQLiteResult",
|
||||
setLastError(qMakeError(d->drv_d_func()->access, QCoreApplication::translate("QSQLiteResult",
|
||||
"Unable to bind parameters"), QSqlError::StatementError, res));
|
||||
d->finalize();
|
||||
return false;
|
||||
@ -513,14 +510,14 @@ int QSQLiteResult::size()
|
||||
int QSQLiteResult::numRowsAffected()
|
||||
{
|
||||
Q_D(const QSQLiteResult);
|
||||
return sqlite3_changes(d->access);
|
||||
return sqlite3_changes(d->drv_d_func()->access);
|
||||
}
|
||||
|
||||
QVariant QSQLiteResult::lastInsertId() const
|
||||
{
|
||||
Q_D(const QSQLiteResult);
|
||||
if (isActive()) {
|
||||
qint64 id = sqlite3_last_insert_rowid(d->access);
|
||||
qint64 id = sqlite3_last_insert_rowid(d->drv_d_func()->access);
|
||||
if (id)
|
||||
return id;
|
||||
}
|
||||
|
@ -127,8 +127,6 @@ public:
|
||||
void init(const char **cnames, int numCols);
|
||||
void finalize();
|
||||
|
||||
sqlite *access;
|
||||
|
||||
// and we have too keep our own struct for the data (sqlite works via
|
||||
// callback.
|
||||
const char *currentTail;
|
||||
@ -136,7 +134,6 @@ public:
|
||||
|
||||
bool skippedStatus; // the status of the fetchNext() that's skipped
|
||||
bool skipRow; // skip the next fetchNext()?
|
||||
bool utf8;
|
||||
QSqlRecord rInf;
|
||||
QVector<QVariant> firstRow;
|
||||
};
|
||||
@ -148,8 +145,7 @@ QSQLite2ResultPrivate::QSQLite2ResultPrivate(QSQLite2Result *q, const QSQLite2Dr
|
||||
currentTail(0),
|
||||
currentMachine(0),
|
||||
skippedStatus(false),
|
||||
skipRow(false),
|
||||
utf8(false)
|
||||
skipRow(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -261,7 +257,7 @@ bool QSQLite2ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
|
||||
if (idx < 0 && !initialFetch)
|
||||
return true;
|
||||
for (i = 0; i < colNum; ++i)
|
||||
values[i + idx] = utf8 ? QString::fromUtf8(fvals[i]) : QString::fromLatin1(fvals[i]);
|
||||
values[i + idx] = drv_d_func()->utf8 ? QString::fromUtf8(fvals[i]) : QString::fromLatin1(fvals[i]);
|
||||
return true;
|
||||
case SQLITE_DONE:
|
||||
if (rInf.isEmpty())
|
||||
@ -283,9 +279,6 @@ bool QSQLite2ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
|
||||
QSQLite2Result::QSQLite2Result(const QSQLite2Driver* db)
|
||||
: QSqlCachedResult(*new QSQLite2ResultPrivate(this, db))
|
||||
{
|
||||
Q_D(QSQLite2Result);
|
||||
d->access = d->drv_d_func()->access;
|
||||
d->utf8 = d->drv_d_func()->utf8;
|
||||
}
|
||||
|
||||
QSQLite2Result::~QSQLite2Result()
|
||||
@ -316,8 +309,8 @@ bool QSQLite2Result::reset (const QString& query)
|
||||
// Um, ok. callback based so.... pass private static function for this.
|
||||
setSelect(false);
|
||||
char *err = 0;
|
||||
int res = sqlite_compile(d->access,
|
||||
d->utf8 ? query.toUtf8().constData()
|
||||
int res = sqlite_compile(d->drv_d_func()->access,
|
||||
d->drv_d_func()->utf8 ? query.toUtf8().constData()
|
||||
: query.toLatin1().constData(),
|
||||
&(d->currentTail),
|
||||
&(d->currentMachine),
|
||||
@ -359,8 +352,8 @@ int QSQLite2Result::size()
|
||||
|
||||
int QSQLite2Result::numRowsAffected()
|
||||
{
|
||||
Q_D(const QSQLite2Result);
|
||||
return sqlite_changes(d->access);
|
||||
Q_D(QSQLite2Result);
|
||||
return sqlite_changes(d->drv_d_func()->access);
|
||||
}
|
||||
|
||||
QSqlRecord QSQLite2Result::record() const
|
||||
|
Loading…
Reference in New Issue
Block a user