summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp2
-rw-r--r--src/sql/drivers/mysql/qsql_mysql_p.h60
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp189
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp2
-rw-r--r--src/sql/drivers/psql/qsql_psql_p.h62
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp22
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite_p.h24
-rw-r--r--src/sql/kernel/qsqldatabase.h2
-rw-r--r--src/sql/kernel/qsqlfield.cpp6
-rw-r--r--src/sql/models/qsqlquerymodel.h18
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp8
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.h22
-rw-r--r--src/sql/models/qsqltablemodel.h26
13 files changed, 205 insertions, 238 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index db54ce84da..9fd7e2b57f 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -670,6 +670,8 @@ QVariant QMYSQLResult::data(int field)
bool QMYSQLResult::isNull(int field)
{
+ if (field < 0 || field >= d->fields.count())
+ return true;
if (d->preparedQuery)
return d->fields.at(field).nullIndicator;
else
diff --git a/src/sql/drivers/mysql/qsql_mysql_p.h b/src/sql/drivers/mysql/qsql_mysql_p.h
index 601193f4b5..7cf2c9317c 100644
--- a/src/sql/drivers/mysql/qsql_mysql_p.h
+++ b/src/sql/drivers/mysql/qsql_mysql_p.h
@@ -75,26 +75,26 @@ public:
explicit QMYSQLResult(const QMYSQLDriver* db);
~QMYSQLResult();
- QVariant handle() const;
+ QVariant handle() const Q_DECL_OVERRIDE;
protected:
void cleanup();
- bool fetch(int i);
- bool fetchNext();
- bool fetchLast();
- bool fetchFirst();
- QVariant data(int field);
- bool isNull(int field);
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- QVariant lastInsertId() const;
- QSqlRecord record() const;
- void virtual_hook(int id, void *data);
- bool nextResult();
+ bool fetch(int i) Q_DECL_OVERRIDE;
+ bool fetchNext() Q_DECL_OVERRIDE;
+ bool fetchLast() Q_DECL_OVERRIDE;
+ bool fetchFirst() Q_DECL_OVERRIDE;
+ QVariant data(int field) Q_DECL_OVERRIDE;
+ bool isNull(int field) Q_DECL_OVERRIDE;
+ bool reset (const QString& query) Q_DECL_OVERRIDE;
+ int size() Q_DECL_OVERRIDE;
+ int numRowsAffected() Q_DECL_OVERRIDE;
+ QVariant lastInsertId() const Q_DECL_OVERRIDE;
+ QSqlRecord record() const Q_DECL_OVERRIDE;
+ void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
+ bool nextResult() Q_DECL_OVERRIDE;
#if MYSQL_VERSION_ID >= 40108
- bool prepare(const QString& stmt);
- bool exec();
+ bool prepare(const QString& stmt) Q_DECL_OVERRIDE;
+ bool exec() Q_DECL_OVERRIDE;
#endif
private:
QMYSQLResultPrivate* d;
@@ -109,29 +109,29 @@ public:
explicit QMYSQLDriver(QObject *parent=0);
explicit QMYSQLDriver(MYSQL *con, QObject * parent=0);
~QMYSQLDriver();
- bool hasFeature(DriverFeature f) const;
+ bool hasFeature(DriverFeature f) const Q_DECL_OVERRIDE;
bool open(const QString & db,
const QString & user,
const QString & password,
const QString & host,
int port,
- const QString& connOpts);
- void close();
- QSqlResult *createResult() const;
- QStringList tables(QSql::TableType) const;
- QSqlIndex primaryIndex(const QString& tablename) const;
- QSqlRecord record(const QString& tablename) const;
+ const QString& connOpts) Q_DECL_OVERRIDE;
+ void close() Q_DECL_OVERRIDE;
+ QSqlResult *createResult() const Q_DECL_OVERRIDE;
+ QStringList tables(QSql::TableType) const Q_DECL_OVERRIDE;
+ QSqlIndex primaryIndex(const QString& tablename) const Q_DECL_OVERRIDE;
+ QSqlRecord record(const QString& tablename) const Q_DECL_OVERRIDE;
QString formatValue(const QSqlField &field,
- bool trimStrings) const;
- QVariant handle() const;
- QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
+ bool trimStrings) const Q_DECL_OVERRIDE;
+ QVariant handle() const Q_DECL_OVERRIDE;
+ QString escapeIdentifier(const QString &identifier, IdentifierType type) const Q_DECL_OVERRIDE;
- bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const;
+ bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const Q_DECL_OVERRIDE;
protected:
- bool beginTransaction();
- bool commitTransaction();
- bool rollbackTransaction();
+ bool beginTransaction() Q_DECL_OVERRIDE;
+ bool commitTransaction() Q_DECL_OVERRIDE;
+ bool rollbackTransaction() Q_DECL_OVERRIDE;
private:
void init();
};
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index 2b14809943..9462df8f97 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -222,12 +222,7 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
if (nativeCode)
*nativeCode = nativeCode_;
- QString tmpstore;
-#ifdef UNICODE
- tmpstore = fromSQLTCHAR(description_, msgLen);
-#else
- tmpstore = QString::fromUtf8((const char*)description_.constData(), msgLen);
-#endif
+ const QString tmpstore = fromSQLTCHAR(description_, msgLen);
if(result != tmpstore) {
if(!result.isEmpty())
result += QLatin1Char(' ');
@@ -241,17 +236,39 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode
return result;
}
+static QString qODBCWarn(const SQLHANDLE hStmt, const SQLHANDLE envHandle = 0,
+ const SQLHANDLE pDbC = 0, int *nativeCode = 0)
+{
+ QString result;
+ if (envHandle)
+ result += qWarnODBCHandle(SQL_HANDLE_ENV, envHandle, nativeCode);
+ if (pDbC) {
+ const QString dMessage = qWarnODBCHandle(SQL_HANDLE_DBC, pDbC, nativeCode);
+ if (!dMessage.isEmpty()) {
+ if (!result.isEmpty())
+ result += QLatin1Char(' ');
+ result += dMessage;
+ }
+ }
+ if (hStmt) {
+ const QString hMessage = qWarnODBCHandle(SQL_HANDLE_STMT, hStmt, nativeCode);
+ if (!hMessage.isEmpty()) {
+ if (!result.isEmpty())
+ result += QLatin1Char(' ');
+ result += hMessage;
+ }
+ }
+ return result;
+}
+
static QString qODBCWarn(const QODBCPrivate* odbc, int *nativeCode = 0)
{
- return QString(qWarnODBCHandle(SQL_HANDLE_ENV, odbc->dpEnv()) + QLatin1Char(' ')
- + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->dpDbc()) + QLatin1Char(' ')
- + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)).simplified();
+ return qODBCWarn(odbc->hStmt, odbc->dpEnv(), odbc->dpDbc(), nativeCode);
}
static QString qODBCWarn(const QODBCDriverPrivate* odbc, int *nativeCode = 0)
{
- return QString(qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ')
- + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode)).simplified();
+ return qODBCWarn(0, odbc->hEnv, odbc->hDbc, nativeCode);
}
static void qSqlWarning(const QString& message, const QODBCPrivate* odbc)
@@ -264,6 +281,11 @@ static void qSqlWarning(const QString &message, const QODBCDriverPrivate *odbc)
qWarning() << message << "\tError:" << qODBCWarn(odbc);
}
+static void qSqlWarning(const QString &message, const SQLHANDLE hStmt)
+{
+ qWarning() << message << "\tError:" << qODBCWarn(hStmt);
+}
+
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, const QODBCPrivate* p)
{
int nativeCode = -1;
@@ -279,10 +301,8 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
return QSqlError(QLatin1String("QODBC3: ") + err, qODBCWarn(p), type, nativeCode);
}
-template<class T>
-static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, const T* p, bool isSigned = true)
+static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, bool isSigned = true)
{
- Q_UNUSED(p);
QVariant::Type type = QVariant::Invalid;
switch (sqltype) {
case SQL_DECIMAL:
@@ -362,7 +382,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
0,
&lengthIndicator);
if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && lengthIndicator > 0)
- colSize = lengthIndicator/sizeof(SQLTCHAR) + 1;
+ colSize = int(lengthIndicator / sizeof(SQLTCHAR) + 1);
QVarLengthArray<SQLTCHAR> buf(colSize);
memset(buf.data(), 0, colSize*sizeof(SQLTCHAR));
while (true) {
@@ -392,7 +412,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
// contain the number of bytes returned - it contains the
// total number of bytes that CAN be fetched
// colSize-1: remove 0 termination when there is more data to fetch
- int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator/sizeof(SQLTCHAR);
+ int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : int(lengthIndicator / sizeof(SQLTCHAR));
fieldVal += fromSQLTCHAR(buf, rSize);
if (lengthIndicator < SQLLEN(colSize*sizeof(SQLTCHAR))) {
// workaround for Drivermanagers that don't return SQL_NO_DATA
@@ -569,6 +589,21 @@ static QVariant qGetBigIntData(SQLHANDLE hStmt, int column, bool isSigned = true
return quint64(lngbuf);
}
+static bool isAutoValue(const SQLHANDLE hStmt, int column)
+{
+ SQLLEN nNumericAttribute = 0; // Check for auto-increment
+ const SQLRETURN r = ::SQLColAttribute(hStmt, column + 1, SQL_DESC_AUTO_UNIQUE_VALUE,
+ 0, 0, 0, &nNumericAttribute);
+ if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
+ qSqlWarning(QStringLiteral("qMakeField: Unable to get autovalue attribute for column ")
+ + QString::number(column), hStmt);
+ return false;
+ }
+ return nNumericAttribute != SQL_FALSE;
+}
+
+static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, int i, QString *errorMessage);
+
// creates a QSqlField from a valid hStmt generated
// by SQLColumns. The hStmt has to point to a valid position.
static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, const QODBCDriverPrivate* p)
@@ -593,6 +628,15 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, const QODBCDriverPrivate*
static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
{
+ QString errorMessage;
+ const QSqlField result = qMakeFieldInfo(p->hStmt, i, &errorMessage);
+ if (!errorMessage.isEmpty())
+ qSqlWarning(errorMessage, p);
+ return result;
+}
+
+static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, int i, QString *errorMessage)
+{
SQLSMALLINT colNameLen;
SQLSMALLINT colType;
SQLULEN colSize;
@@ -600,7 +644,8 @@ static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
SQLSMALLINT nullable;
SQLRETURN r = SQL_ERROR;
QVarLengthArray<SQLTCHAR> colName(COLNAMESIZE);
- r = SQLDescribeCol(p->hStmt,
+ errorMessage->clear();
+ r = SQLDescribeCol(hStmt,
i+1,
colName.data(),
(SQLSMALLINT)COLNAMESIZE,
@@ -611,12 +656,12 @@ static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
&nullable);
if (r != SQL_SUCCESS) {
- qSqlWarning(QString::fromLatin1("qMakeField: Unable to describe column %1").arg(i), p);
+ *errorMessage = QStringLiteral("qMakeField: Unable to describe column ") + QString::number(i);
return QSqlField();
}
SQLLEN unsignedFlag = SQL_FALSE;
- r = SQLColAttribute (p->hStmt,
+ r = SQLColAttribute (hStmt,
i + 1,
SQL_DESC_UNSIGNED,
0,
@@ -624,16 +669,13 @@ static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
0,
&unsignedFlag);
if (r != SQL_SUCCESS) {
- qSqlWarning(QString::fromLatin1("qMakeField: Unable to get column attributes for column %1").arg(i), p);
+ qSqlWarning(QStringLiteral("qMakeField: Unable to get column attributes for column ")
+ + QString::number(i), hStmt);
}
-#ifdef UNICODE
- QString qColName(fromSQLTCHAR(colName, colNameLen));
-#else
- QString qColName = QString::fromUtf8((const char *)colName.constData());
-#endif
+ const QString qColName(fromSQLTCHAR(colName, colNameLen));
// nullable can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
- QVariant::Type type = qDecodeODBCType(colType, p, unsignedFlag == SQL_FALSE);
+ QVariant::Type type = qDecodeODBCType(colType, unsignedFlag == SQL_FALSE);
QSqlField f(qColName, type);
f.setSqlType(colType);
f.setLength(colSize == 0 ? -1 : int(colSize));
@@ -643,6 +685,7 @@ static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
else if (nullable == SQL_NULLABLE)
f.setRequired(false);
// else we don't know
+ f.setAutoValue(isAutoValue(hStmt, i));
return f;
}
@@ -664,11 +707,7 @@ QChar QODBCDriverPrivate::quoteChar()
sizeof(driverResponse),
&length);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
-#ifdef UNICODE
quote = QChar(driverResponse[0]);
-#else
- quote = QLatin1Char(driverResponse[0]);
-#endif
else
quote = QLatin1Char('"');
isQuoteInitialized = true;
@@ -713,11 +752,7 @@ bool QODBCDriverPrivate::setConnectionOptions(const QString& connOpts)
} else if (opt.toUpper() == QLatin1String("SQL_ATTR_CURRENT_CATALOG")) {
val.utf16(); // 0 terminate
r = SQLSetConnectAttr(hDbc, SQL_ATTR_CURRENT_CATALOG,
-#ifdef UNICODE
toSQLTCHAR(val).data(),
-#else
- (SQLCHAR*) val.toUtf8().data(),
-#endif
val.length()*sizeof(SQLTCHAR));
} else if (opt.toUpper() == QLatin1String("SQL_ATTR_METADATA_ID")) {
if (val.toUpper() == QLatin1String("SQL_TRUE")) {
@@ -735,11 +770,7 @@ bool QODBCDriverPrivate::setConnectionOptions(const QString& connOpts)
} else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACEFILE")) {
val.utf16(); // 0 terminate
r = SQLSetConnectAttr(hDbc, SQL_ATTR_TRACEFILE,
-#ifdef UNICODE
toSQLTCHAR(val).data(),
-#else
- (SQLCHAR*) val.toUtf8().data(),
-#endif
val.length()*sizeof(SQLTCHAR));
} else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACE")) {
if (val.toUpper() == QLatin1String("SQL_OPT_TRACE_OFF")) {
@@ -944,16 +975,9 @@ bool QODBCResult::reset (const QString& query)
return false;
}
-#ifdef UNICODE
r = SQLExecDirect(d->hStmt,
toSQLTCHAR(query).data(),
(SQLINTEGER) query.length());
-#else
- QByteArray query8 = query.toUtf8();
- r = SQLExecDirect(d->hStmt,
- (SQLCHAR*) query8.data(),
- (SQLINTEGER) query8.length());
-#endif
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r!= SQL_NO_DATA) {
setLastError(qMakeError(QCoreApplication::translate("QODBCResult",
"Unable to execute statement"), QSqlError::StatementError, d));
@@ -1290,16 +1314,9 @@ bool QODBCResult::prepare(const QString& query)
return false;
}
-#ifdef UNICODE
r = SQLPrepare(d->hStmt,
toSQLTCHAR(query).data(),
(SQLINTEGER) query.length());
-#else
- QByteArray query8 = query.toUtf8();
- r = SQLPrepare(d->hStmt,
- (SQLCHAR*) query8.data(),
- (SQLINTEGER) query8.length());
-#endif
if (r != SQL_SUCCESS) {
setLastError(qMakeError(QCoreApplication::translate("QODBCResult",
@@ -1889,11 +1906,7 @@ bool QODBCDriver::open(const QString & db,
memset(connOut.data(), 0, connOut.size() * sizeof(SQLTCHAR));
r = SQLDriverConnect(d->hDbc,
NULL,
-#ifdef UNICODE
toSQLTCHAR(connQStr).data(),
-#else
- (SQLCHAR*)connQStr.toUtf8().data(),
-#endif
(SQLSMALLINT)connQStr.length(),
connOut.data(),
1024,
@@ -2097,15 +2110,10 @@ void QODBCDriverPrivate::checkDBMS()
r = SQLGetInfo(hDbc,
SQL_DBMS_NAME,
serverString.data(),
- serverString.size() * sizeof(SQLTCHAR),
+ SQLSMALLINT(serverString.size() * sizeof(SQLTCHAR)),
&t);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
- QString serverType;
-#ifdef UNICODE
- serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR));
-#else
- serverType = QString::fromUtf8((const char *)serverString.constData(), t);
-#endif
+ const QString serverType = fromSQLTCHAR(serverString, t / sizeof(SQLTCHAR));
if (serverType.contains(QLatin1String("PostgreSQL"), Qt::CaseInsensitive))
dbmsType = QSqlDriver::PostgreSQL;
else if (serverType.contains(QLatin1String("Oracle"), Qt::CaseInsensitive))
@@ -2120,15 +2128,10 @@ void QODBCDriverPrivate::checkDBMS()
r = SQLGetInfo(hDbc,
SQL_DRIVER_NAME,
serverString.data(),
- serverString.size() * sizeof(SQLTCHAR),
+ SQLSMALLINT(serverString.size() * sizeof(SQLTCHAR)),
&t);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
- QString serverType;
-#ifdef UNICODE
- serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR));
-#else
- serverType = QString::fromUtf8((const char *)serverString.constData(), t);
-#endif
+ const QString serverType = fromSQLTCHAR(serverString, t / sizeof(SQLTCHAR));
isFreeTDSDriver = serverType.contains(QLatin1String("tdsodbc"), Qt::CaseInsensitive);
unicode = unicode && !isFreeTDSDriver;
}
@@ -2151,14 +2154,10 @@ void QODBCDriverPrivate::checkHasMultiResults()
SQLRETURN r = SQLGetInfo(hDbc,
SQL_MULT_RESULT_SETS,
driverResponse.data(),
- driverResponse.size() * sizeof(SQLTCHAR),
+ SQLSMALLINT(driverResponse.size() * sizeof(SQLTCHAR)),
&length);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
-#ifdef UNICODE
hasMultiResultSets = fromSQLTCHAR(driverResponse, length/sizeof(SQLTCHAR)).startsWith(QLatin1Char('Y'));
-#else
- hasMultiResultSets = QString::fromUtf8((const char *)driverResponse.constData(), length).startsWith(QLatin1Char('Y'));
-#endif
}
void QODBCDriverPrivate::checkDateTimePrecision()
@@ -2299,11 +2298,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const
0,
NULL,
0,
-#ifdef UNICODE
toSQLTCHAR(joinedTableTypeString).data(),
-#else
- (SQLCHAR*)joinedTableTypeString.toUtf8().data(),
-#endif
joinedTableTypeString.length() /* characters, not bytes */);
if (r != SQL_SUCCESS)
@@ -2379,23 +2374,11 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
(SQLPOINTER)SQL_CURSOR_FORWARD_ONLY,
SQL_IS_UINTEGER);
r = SQLPrimaryKeys(hStmt,
-#ifdef UNICODE
catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
-#else
- catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
-#endif
catalog.length(),
-#ifdef UNICODE
schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
-#else
- schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
-#endif
schema.length(),
-#ifdef UNICODE
toSQLTCHAR(table).data(),
-#else
- (SQLCHAR*)table.toUtf8().data(),
-#endif
table.length() /* in characters, not in bytes */);
// if the SQLPrimaryKeys() call does not succeed (e.g the driver
@@ -2404,23 +2387,11 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
if (r != SQL_SUCCESS) {
r = SQLSpecialColumns(hStmt,
SQL_BEST_ROWID,
-#ifdef UNICODE
catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
-#else
- catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
-#endif
catalog.length(),
-#ifdef UNICODE
schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
-#else
- schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
-#endif
schema.length(),
-#ifdef UNICODE
toSQLTCHAR(table).data(),
-#else
- (SQLCHAR*)table.toUtf8().data(),
-#endif
table.length(),
SQL_SCOPE_CURROW,
SQL_NULLABLE);
@@ -2505,23 +2476,11 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const
(SQLPOINTER)SQL_CURSOR_FORWARD_ONLY,
SQL_IS_UINTEGER);
r = SQLColumns(hStmt,
-#ifdef UNICODE
catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
-#else
- catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
-#endif
catalog.length(),
-#ifdef UNICODE
schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
-#else
- schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
-#endif
schema.length(),
-#ifdef UNICODE
toSQLTCHAR(table).data(),
-#else
- (SQLCHAR*)table.toUtf8().data(),
-#endif
table.length(),
NULL,
0);
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 4268ea06f6..455e1f46ca 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -200,7 +200,7 @@ public:
preparedQueriesEnabled(false)
{ }
- QString fieldSerial(int i) const { return QLatin1Char('$') + QString::number(i + 1); }
+ QString fieldSerial(int i) const Q_DECL_OVERRIDE { return QLatin1Char('$') + QString::number(i + 1); }
void deallocatePreparedStmt();
const QPSQLDriverPrivate * privDriver() const
{
diff --git a/src/sql/drivers/psql/qsql_psql_p.h b/src/sql/drivers/psql/qsql_psql_p.h
index 4d8283ff48..b840fa8ed9 100644
--- a/src/sql/drivers/psql/qsql_psql_p.h
+++ b/src/sql/drivers/psql/qsql_psql_p.h
@@ -71,23 +71,23 @@ public:
QPSQLResult(const QPSQLDriver* db);
~QPSQLResult();
- QVariant handle() const;
- void virtual_hook(int id, void *data);
+ QVariant handle() const Q_DECL_OVERRIDE;
+ void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
protected:
void cleanup();
- bool fetch(int i);
- bool fetchFirst();
- bool fetchLast();
- QVariant data(int i);
- bool isNull(int field);
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- QSqlRecord record() const;
- QVariant lastInsertId() const;
- bool prepare(const QString& query);
- bool exec();
+ bool fetch(int i) Q_DECL_OVERRIDE;
+ bool fetchFirst() Q_DECL_OVERRIDE;
+ bool fetchLast() Q_DECL_OVERRIDE;
+ QVariant data(int i) Q_DECL_OVERRIDE;
+ bool isNull(int field) Q_DECL_OVERRIDE;
+ bool reset (const QString& query) Q_DECL_OVERRIDE;
+ int size() Q_DECL_OVERRIDE;
+ int numRowsAffected() Q_DECL_OVERRIDE;
+ QSqlRecord record() const Q_DECL_OVERRIDE;
+ QVariant lastInsertId() const Q_DECL_OVERRIDE;
+ bool prepare(const QString& query) Q_DECL_OVERRIDE;
+ bool exec() Q_DECL_OVERRIDE;
};
class QPSQLDriverPrivate;
@@ -117,34 +117,34 @@ public:
explicit QPSQLDriver(QObject *parent=0);
explicit QPSQLDriver(PGconn *conn, QObject *parent=0);
~QPSQLDriver();
- bool hasFeature(DriverFeature f) const;
+ bool hasFeature(DriverFeature f) const Q_DECL_OVERRIDE;
bool open(const QString & db,
const QString & user,
const QString & password,
const QString & host,
int port,
- const QString& connOpts);
- bool isOpen() const;
- void close();
- QSqlResult *createResult() const;
- QStringList tables(QSql::TableType) const;
- QSqlIndex primaryIndex(const QString& tablename) const;
- QSqlRecord record(const QString& tablename) const;
+ const QString& connOpts) Q_DECL_OVERRIDE;
+ bool isOpen() const Q_DECL_OVERRIDE;
+ void close() Q_DECL_OVERRIDE;
+ QSqlResult *createResult() const Q_DECL_OVERRIDE;
+ QStringList tables(QSql::TableType) const Q_DECL_OVERRIDE;
+ QSqlIndex primaryIndex(const QString& tablename) const Q_DECL_OVERRIDE;
+ QSqlRecord record(const QString& tablename) const Q_DECL_OVERRIDE;
Protocol protocol() const;
- QVariant handle() const;
+ QVariant handle() const Q_DECL_OVERRIDE;
- QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
- QString formatValue(const QSqlField &field, bool trimStrings) const;
+ QString escapeIdentifier(const QString &identifier, IdentifierType type) const Q_DECL_OVERRIDE;
+ QString formatValue(const QSqlField &field, bool trimStrings) const Q_DECL_OVERRIDE;
- bool subscribeToNotification(const QString &name);
- bool unsubscribeFromNotification(const QString &name);
- QStringList subscribedToNotifications() const;
+ bool subscribeToNotification(const QString &name) Q_DECL_OVERRIDE;
+ bool unsubscribeFromNotification(const QString &name) Q_DECL_OVERRIDE;
+ QStringList subscribedToNotifications() const Q_DECL_OVERRIDE;
protected:
- bool beginTransaction();
- bool commitTransaction();
- bool rollbackTransaction();
+ bool beginTransaction() Q_DECL_OVERRIDE;
+ bool commitTransaction() Q_DECL_OVERRIDE;
+ bool rollbackTransaction() Q_DECL_OVERRIDE;
private Q_SLOTS:
void _q_handleNotification(int);
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp
index 84b6bbe80e..fa79230aa1 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.cpp
+++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp
@@ -110,19 +110,19 @@ class QSQLiteResult : public QSqlCachedResult
public:
explicit QSQLiteResult(const QSQLiteDriver* db);
~QSQLiteResult();
- QVariant handle() const;
+ QVariant handle() const Q_DECL_OVERRIDE;
protected:
- bool gotoNext(QSqlCachedResult::ValueCache& row, int idx);
- bool reset(const QString &query);
- bool prepare(const QString &query);
- bool exec();
- int size();
- int numRowsAffected();
- QVariant lastInsertId() const;
- QSqlRecord record() const;
- void detachFromResultSet();
- void virtual_hook(int id, void *data);
+ bool gotoNext(QSqlCachedResult::ValueCache& row, int idx) Q_DECL_OVERRIDE;
+ bool reset(const QString &query) Q_DECL_OVERRIDE;
+ bool prepare(const QString &query) Q_DECL_OVERRIDE;
+ bool exec() Q_DECL_OVERRIDE;
+ int size() Q_DECL_OVERRIDE;
+ int numRowsAffected() Q_DECL_OVERRIDE;
+ QVariant lastInsertId() const Q_DECL_OVERRIDE;
+ QSqlRecord record() const Q_DECL_OVERRIDE;
+ void detachFromResultSet() Q_DECL_OVERRIDE;
+ void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
private:
QSQLiteResultPrivate* d;
diff --git a/src/sql/drivers/sqlite/qsql_sqlite_p.h b/src/sql/drivers/sqlite/qsql_sqlite_p.h
index 45a5bd75ac..5b5792b469 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite_p.h
+++ b/src/sql/drivers/sqlite/qsql_sqlite_p.h
@@ -70,24 +70,24 @@ public:
explicit QSQLiteDriver(QObject *parent = 0);
explicit QSQLiteDriver(sqlite3 *connection, QObject *parent = 0);
~QSQLiteDriver();
- bool hasFeature(DriverFeature f) const;
+ bool hasFeature(DriverFeature f) const Q_DECL_OVERRIDE;
bool open(const QString & db,
const QString & user,
const QString & password,
const QString & host,
int port,
- const QString & connOpts);
- void close();
- QSqlResult *createResult() const;
- bool beginTransaction();
- bool commitTransaction();
- bool rollbackTransaction();
- QStringList tables(QSql::TableType) const;
+ const QString & connOpts) Q_DECL_OVERRIDE;
+ void close() Q_DECL_OVERRIDE;
+ QSqlResult *createResult() const Q_DECL_OVERRIDE;
+ bool beginTransaction() Q_DECL_OVERRIDE;
+ bool commitTransaction() Q_DECL_OVERRIDE;
+ bool rollbackTransaction() Q_DECL_OVERRIDE;
+ QStringList tables(QSql::TableType) const Q_DECL_OVERRIDE;
- QSqlRecord record(const QString& tablename) const;
- QSqlIndex primaryIndex(const QString &table) const;
- QVariant handle() const;
- QString escapeIdentifier(const QString &identifier, IdentifierType) const;
+ QSqlRecord record(const QString& tablename) const Q_DECL_OVERRIDE;
+ QSqlIndex primaryIndex(const QString &table) const Q_DECL_OVERRIDE;
+ QVariant handle() const Q_DECL_OVERRIDE;
+ QString escapeIdentifier(const QString &identifier, IdentifierType) const Q_DECL_OVERRIDE;
};
QT_END_NAMESPACE
diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h
index d5f381102e..9e304fe3ee 100644
--- a/src/sql/kernel/qsqldatabase.h
+++ b/src/sql/kernel/qsqldatabase.h
@@ -58,7 +58,7 @@ template <class T>
class QSqlDriverCreator : public QSqlDriverCreatorBase
{
public:
- QSqlDriver *createObject() const { return new T; }
+ QSqlDriver *createObject() const Q_DECL_OVERRIDE { return new T; }
};
class Q_SQL_EXPORT QSqlDatabase
diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp
index 3fd2c68296..a76e38b6f1 100644
--- a/src/sql/kernel/qsqlfield.cpp
+++ b/src/sql/kernel/qsqlfield.cpp
@@ -534,6 +534,12 @@ QDebug operator<<(QDebug dbg, const QSqlField &f)
Returns \c true if the value is auto-generated by the database,
for example auto-increment primary key values.
+ \note When using the ODBC driver, due to limitations in the ODBC API,
+ the \c isAutoValue() field is only populated in a QSqlField resulting from a
+ QSqlRecord obtained by executing a \c SELECT query. It is \c false in a QSqlField
+ resulting from a QSqlRecord returned from QSqlDatabase::record() or
+ QSqlDatabase::primaryIndex().
+
\sa setAutoValue()
*/
bool QSqlField::isAutoValue() const
diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h
index 95910513df..93b1303807 100644
--- a/src/sql/models/qsqlquerymodel.h
+++ b/src/sql/models/qsqlquerymodel.h
@@ -54,19 +54,19 @@ public:
explicit QSqlQueryModel(QObject *parent = 0);
virtual ~QSqlQueryModel();
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QSqlRecord record(int row) const;
QSqlRecord record() const;
- QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
+ QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
- int role = Qt::EditRole);
+ int role = Qt::EditRole) Q_DECL_OVERRIDE;
- bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
+ bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
void setQuery(const QSqlQuery &query);
void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
@@ -76,8 +76,8 @@ public:
QSqlError lastError() const;
- void fetchMore(const QModelIndex &parent = QModelIndex());
- bool canFetchMore(const QModelIndex &parent = QModelIndex()) const;
+ void fetchMore(const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool canFetchMore(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
protected:
void beginInsertRows(const QModelIndex &parent, int first, int last);
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index 8f89f27cde..c6ef1570c0 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -150,7 +150,7 @@ class QRelatedTableModel : public QSqlTableModel
{
public:
QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase());
- bool select();
+ bool select() Q_DECL_OVERRIDE;
private:
bool firstSelect;
QRelation *relation;
@@ -262,12 +262,12 @@ public:
{}
QString fullyQualifiedFieldName(const QString &tableName, const QString &fieldName) const;
- int nameToIndex(const QString &name) const;
+ int nameToIndex(const QString &name) const Q_DECL_OVERRIDE;
mutable QVector<QRelation> relations;
QSqlRecord baseRec; // the record without relations
void clearChanges();
- void clearCache();
- void revertCachedRow(int row);
+ void clearCache() Q_DECL_OVERRIDE;
+ void revertCachedRow(int row) Q_DECL_OVERRIDE;
void translateFieldNames(QSqlRecord &values) const;
QSqlRelationalTableModel::JoinMode joinMode;
diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h
index 8a9ab43443..92ddb03c6c 100644
--- a/src/sql/models/qsqlrelationaltablemodel.h
+++ b/src/sql/models/qsqlrelationaltablemodel.h
@@ -74,27 +74,27 @@ public:
QSqlDatabase db = QSqlDatabase());
virtual ~QSqlRelationalTableModel();
- QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
- bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole);
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
+ QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
+ bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
- void clear();
- bool select();
+ void clear() Q_DECL_OVERRIDE;
+ bool select() Q_DECL_OVERRIDE;
- void setTable(const QString &tableName);
+ void setTable(const QString &tableName) Q_DECL_OVERRIDE;
virtual void setRelation(int column, const QSqlRelation &relation);
QSqlRelation relation(int column) const;
virtual QSqlTableModel *relationModel(int column) const;
void setJoinMode( QSqlRelationalTableModel::JoinMode joinMode );
public Q_SLOTS:
- void revertRow(int row);
+ void revertRow(int row) Q_DECL_OVERRIDE;
protected:
- QString selectStatement() const;
- bool updateRowInTable(int row, const QSqlRecord &values);
- bool insertRowIntoTable(const QSqlRecord &values);
- QString orderByClause() const;
+ QString selectStatement() const Q_DECL_OVERRIDE;
+ bool updateRowInTable(int row, const QSqlRecord &values) Q_DECL_OVERRIDE;
+ bool insertRowIntoTable(const QSqlRecord &values) Q_DECL_OVERRIDE;
+ QString orderByClause() const Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QSqlRelationalTableModel)
diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h
index 4263d387ea..98841118f8 100644
--- a/src/sql/models/qsqltablemodel.h
+++ b/src/sql/models/qsqltablemodel.h
@@ -59,19 +59,19 @@ public:
virtual void setTable(const QString &tableName);
QString tableName() const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QSqlRecord record() const;
QSqlRecord record(int row) const;
- QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool isDirty() const;
bool isDirty(const QModelIndex &index) const;
- void clear();
+ void clear() Q_DECL_OVERRIDE;
virtual void setEditStrategy(EditStrategy strategy);
EditStrategy editStrategy() const;
@@ -80,17 +80,17 @@ public:
QSqlDatabase database() const;
int fieldIndex(const QString &fieldName) const;
- void sort(int column, Qt::SortOrder order);
+ void sort(int column, Qt::SortOrder order) Q_DECL_OVERRIDE;
virtual void setSort(int column, Qt::SortOrder order);
QString filter() const;
virtual void setFilter(const QString &filter);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
- bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
bool insertRecord(int row, const QSqlRecord &record);
bool setRecord(int row, const QSqlRecord &record);
@@ -101,8 +101,8 @@ public Q_SLOTS:
virtual bool select();
virtual bool selectRow(int row);
- bool submit();
- void revert();
+ bool submit() Q_DECL_OVERRIDE;
+ void revert() Q_DECL_OVERRIDE;
bool submitAll();
void revertAll();
@@ -125,7 +125,7 @@ protected:
void setPrimaryKey(const QSqlIndex &key);
void setQuery(const QSqlQuery &query);
- QModelIndex indexInQuery(const QModelIndex &item) const;
+ QModelIndex indexInQuery(const QModelIndex &item) const Q_DECL_OVERRIDE;
QSqlRecord primaryValues(int row) const;
};