diff options
Diffstat (limited to 'src/sql/drivers')
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 22 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 24 |
2 files changed, 29 insertions, 17 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 06ee3e1..43658f7 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -126,8 +126,8 @@ private: class QODBCPrivate { public: - QODBCPrivate() - : hEnv(0), hDbc(0), hStmt(0), useSchema(false), hasSQLFetchScroll(true) + QODBCPrivate(QODBCDriverPrivate *dpp) + : hStmt(0), useSchema(false), hasSQLFetchScroll(true), driverPrivate(dpp) { unicode = false; } @@ -135,8 +135,8 @@ public: inline void clearValues() { fieldCache.fill(QVariant()); fieldCacheIdx = 0; } - SQLHANDLE hEnv; - SQLHANDLE hDbc; + SQLHANDLE dpEnv() const { return driverPrivate ? driverPrivate->hEnv : 0;} + SQLHANDLE dpDbc() const { return driverPrivate ? driverPrivate->hDbc : 0;} SQLHANDLE hStmt; uint unicode :1; @@ -147,6 +147,7 @@ public: int fieldCacheIdx; int disconnectCount; bool hasSQLFetchScroll; + QODBCDriverPrivate *driverPrivate; bool isStmtHandleValid(const QSqlDriver *driver); void updateStmtHandleState(const QSqlDriver *driver); @@ -208,8 +209,8 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode static QString qODBCWarn(const QODBCPrivate* odbc, int *nativeCode = 0) { - return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ') - + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc) + QLatin1Char(' ') + return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->dpEnv()) + QLatin1Char(' ') + + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->dpDbc()) + QLatin1Char(' ') + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)); } @@ -247,6 +248,7 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, template<class T> static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, const T* p, bool isSigned = true) { + Q_UNUSED(p); QVariant::Type type = QVariant::Invalid; switch (sqltype) { case SQL_DECIMAL: @@ -799,9 +801,7 @@ QString QODBCDriverPrivate::adjustCase(const QString &identifier) const QODBCResult::QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p) : QSqlResult(db) { - d = new QODBCPrivate(); - d->hEnv = p->hEnv; - d->hDbc = p->hDbc; + d = new QODBCPrivate(p); d->unicode = p->unicode; d->useSchema = p->useSchema; d->disconnectCount = p->disconnectCount; @@ -839,7 +839,7 @@ bool QODBCResult::reset (const QString& query) } } r = SQLAllocHandle(SQL_HANDLE_STMT, - d->hDbc, + d->dpDbc(), &d->hStmt); if (r != SQL_SUCCESS) { qSqlWarning(QLatin1String("QODBCResult::reset: Unable to allocate statement handle"), d); @@ -1180,7 +1180,7 @@ bool QODBCResult::prepare(const QString& query) } } r = SQLAllocHandle(SQL_HANDLE_STMT, - d->hDbc, + d->dpDbc(), &d->hStmt); if (r != SQL_SUCCESS) { qSqlWarning(QLatin1String("QODBCResult::prepare: Unable to allocate statement handle"), d); diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 81afbf9..db7950d 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -502,15 +502,27 @@ static int qGetSqliteTimeout(QString opts) enum { DefaultTimeout = 5000 }; opts.remove(QLatin1Char(' ')); - if (opts.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { - bool ok; - int nt = opts.mid(21).toInt(&ok); - if (ok) - return nt; + foreach(QString option, opts.split(QLatin1Char(';'))) { + if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { + bool ok; + int nt = option.mid(21).toInt(&ok); + if (ok) + return nt; + } } return DefaultTimeout; } +static int qGetSqliteOpenMode(QString opts) +{ + opts.remove(QLatin1Char(' ')); + foreach(QString option, opts.split(QLatin1Char(';'))) { + if (option == QLatin1String("QSQLITE_OPEN_READONLY")) + return SQLITE_OPEN_READONLY; + } + return SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; +} + /* SQLite dbs have no user name, passwords, hosts or ports. just file names. @@ -523,7 +535,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c if (db.isEmpty()) return false; - if (sqlite3_open16(db.constData(), &d->access) == SQLITE_OK) { + if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, qGetSqliteOpenMode(conOpts), NULL) == SQLITE_OK) { sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts)); setOpen(true); setOpenError(false); |