summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-03-20 23:30:31 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-20 23:30:31 +0100
commite5a11fbb3251a98fafd6bebf0b6fc366acb19088 (patch)
tree8e1bd6704205307e0a23484221ea1bb67a9f411e /src/sql
parent0646d1131b4bc65cdd9af29f4ce00fdd2398a3df (diff)
parent76c0be34cd4ff4564693162fa7528463e23ce9d8 (diff)
Merge "Merge branch 'dev' into stable" into refs/staging/stable
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/doc/snippets/code/doc_src_sql-driver.cpp2
-rw-r--r--src/sql/doc/src/qsqldatatype-table.qdoc2
-rw-r--r--src/sql/doc/src/sql-driver.qdoc4
-rw-r--r--src/sql/doc/src/sql-programming.qdoc14
-rw-r--r--src/sql/drivers/db2/qsql_db2.cpp2
-rw-r--r--src/sql/drivers/db2/qsql_db2.pri2
-rw-r--r--src/sql/drivers/db2/qsql_db2_p.h (renamed from src/sql/drivers/db2/qsql_db2.h)22
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.cpp28
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.pri2
-rw-r--r--src/sql/drivers/ibase/qsql_ibase_p.h (renamed from src/sql/drivers/ibase/qsql_ibase.h)44
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp12
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.pri2
-rw-r--r--src/sql/drivers/mysql/qsql_mysql_p.h (renamed from src/sql/drivers/mysql/qsql_mysql.h)20
-rw-r--r--src/sql/drivers/oci/qsql_oci.cpp34
-rw-r--r--src/sql/drivers/oci/qsql_oci.pri4
-rw-r--r--src/sql/drivers/oci/qsql_oci_p.h (renamed from src/sql/drivers/oci/qsql_oci.h)48
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp70
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.pri2
-rw-r--r--src/sql/drivers/odbc/qsql_odbc_p.h (renamed from src/sql/drivers/odbc/qsql_odbc.h)21
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp46
-rw-r--r--src/sql/drivers/psql/qsql_psql.pri2
-rw-r--r--src/sql/drivers/psql/qsql_psql_p.h (renamed from src/sql/drivers/psql/qsql_psql.h)20
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp32
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.pri2
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite_p.h (renamed from src/sql/drivers/sqlite/qsql_sqlite.h)47
-rw-r--r--src/sql/drivers/sqlite2/qsql_sqlite2.cpp31
-rw-r--r--src/sql/drivers/sqlite2/qsql_sqlite2.pri2
-rw-r--r--src/sql/drivers/sqlite2/qsql_sqlite2_p.h (renamed from src/sql/drivers/sqlite2/qsql_sqlite2.h)44
-rw-r--r--src/sql/drivers/tds/qsql_tds.cpp66
-rw-r--r--src/sql/drivers/tds/qsql_tds.pri2
-rw-r--r--src/sql/drivers/tds/qsql_tds_p.h (renamed from src/sql/drivers/tds/qsql_tds.h)41
-rw-r--r--src/sql/kernel/qsql.h4
-rw-r--r--src/sql/kernel/qsqldatabase.cpp18
-rw-r--r--src/sql/kernel/qsqldatabase.h4
-rw-r--r--src/sql/kernel/qsqldriver.h4
-rw-r--r--src/sql/kernel/qsqldriverplugin.h4
-rw-r--r--src/sql/kernel/qsqlerror.cpp44
-rw-r--r--src/sql/kernel/qsqlerror.h15
-rw-r--r--src/sql/kernel/qsqlfield.h4
-rw-r--r--src/sql/kernel/qsqlindex.h4
-rw-r--r--src/sql/kernel/qsqlquery.cpp14
-rw-r--r--src/sql/kernel/qsqlquery.h4
-rw-r--r--src/sql/kernel/qsqlrecord.h4
-rw-r--r--src/sql/kernel/qsqlresult.cpp59
-rw-r--r--src/sql/kernel/qsqlresult.h10
-rw-r--r--src/sql/kernel/qsqlresult_p.h8
-rw-r--r--src/sql/models/qsqlquerymodel.h4
-rw-r--r--src/sql/models/qsqlquerymodel_p.h2
-rw-r--r--src/sql/models/qsqlrelationaldelegate.h4
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp2
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.h4
-rw-r--r--src/sql/models/qsqltablemodel.h4
52 files changed, 498 insertions, 392 deletions
diff --git a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
index 48eb324cb8..695e7cdce8 100644
--- a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
+++ b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
@@ -62,7 +62,7 @@ db.setDatabaseName("C:\\test.gdb");
//! [25]
-// connect to database using the Latin-1 character set
+// connect to database using the Latin-1 character set
db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
db.open();
//! [25]
diff --git a/src/sql/doc/src/qsqldatatype-table.qdoc b/src/sql/doc/src/qsqldatatype-table.qdoc
index b278e045bb..8480b5d412 100644
--- a/src/sql/doc/src/qsqldatatype-table.qdoc
+++ b/src/sql/doc/src/qsqldatatype-table.qdoc
@@ -29,7 +29,7 @@
\page sql-types.html
\title Data Types for Qt-supported Database Systems
\brief Recommended data types for database systems
-
+
\ingroup qt-sql
\section1 Recommended Data Types for Qt-Supported Database Systems
diff --git a/src/sql/doc/src/sql-driver.qdoc b/src/sql/doc/src/sql-driver.qdoc
index 28db62537f..3de898c344 100644
--- a/src/sql/doc/src/sql-driver.qdoc
+++ b/src/sql/doc/src/sql-driver.qdoc
@@ -212,7 +212,7 @@
\li Open the DOS prompt, go to \c{C:\MySQL\MySQL51\lib\opt}, and run
the following commands:
- \list
+ \list
\li \c{reimp -d libmysql.lib}
\li \c{dlltool -k -d libmysql.def -l libmysql.a}
\endlist
@@ -227,7 +227,7 @@
\li Open the DOS prompt, go to
\c{C:\Qt\4.6.2\src\plugins\sqldrivers\mysql} and run the
- following command:
+ following command:
\list
\li \c{qmake "INCLUDEPATH+=C:/MySQL/MySQL51/include" "LIBS+=-L. mysql" mysql.pro}
\endlist
diff --git a/src/sql/doc/src/sql-programming.qdoc b/src/sql/doc/src/sql-programming.qdoc
index d4089c8ab2..9b5e9318e0 100644
--- a/src/sql/doc/src/sql-programming.qdoc
+++ b/src/sql/doc/src/sql-programming.qdoc
@@ -64,7 +64,7 @@
\li \l{Using the SQL Model Classes}
\li \l{Presenting Data in a Table View}
\li \l{Creating Data-Aware Forms}
- \endlist
+ \endlist
\section1 Database Classes
@@ -142,7 +142,7 @@
\l{QSqlDatabase::addDatabase()} {addDatabase()} specifies the type
of database driver to use for the connection. The set of database
drivers included with Qt are shown in the table of \l{SQL Database
- Drivers#Supported Databases} {supported database drivers}.
+ Drivers#Supported Databases} {supported database drivers}.
The connection in the snippet will be the \e{default} connection,
because we don't pass the second argument to
@@ -176,11 +176,11 @@
\page sql-sqlstatements.html
\title Executing SQL Statements
\ingroup qt-sql
-
+
\previouspage Connecting to Databases
\contentspage SQL Programming
\nextpage Using the SQL Model Classes
-
+
The QSqlQuery class provides an interface for executing SQL
statements and navigating through the result set of a query.
@@ -328,7 +328,7 @@
\page sql-model.html
\title Using the SQL Model Classes
\ingroup qt-sql
-
+
\previouspage Executing SQL Statements
\contentspage SQL Programming
\nextpage Presenting Data in a Table View
@@ -475,7 +475,7 @@
\page sql-presenting.html
\title Presenting Data in a Table View
\ingroup qt-sql
-
+
\previouspage Using the SQL Model Classes
\contentspage SQL Programming
\nextpage Creating Data-Aware Forms
@@ -580,7 +580,7 @@
\page sql-forms.html
\title Creating Data-Aware Forms
\ingroup qt-sql
-
+
\previouspage Presenting Data in a Table View
\contentspage SQL Programming
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp
index 9406861d4c..50a9af23bc 100644
--- a/src/sql/drivers/db2/qsql_db2.cpp
+++ b/src/sql/drivers/db2/qsql_db2.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_db2.h"
+#include "qsql_db2_p.h"
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qsqlfield.h>
diff --git a/src/sql/drivers/db2/qsql_db2.pri b/src/sql/drivers/db2/qsql_db2.pri
index 963732aaee..c9e65e2c2e 100644
--- a/src/sql/drivers/db2/qsql_db2.pri
+++ b/src/sql/drivers/db2/qsql_db2.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_db2.h
+HEADERS += $$PWD/qsql_db2_p.h
SOURCES += $$PWD/qsql_db2.cpp
unix {
diff --git a/src/sql/drivers/db2/qsql_db2.h b/src/sql/drivers/db2/qsql_db2_p.h
index 4e25c317eb..68563448ed 100644
--- a/src/sql/drivers/db2/qsql_db2.h
+++ b/src/sql/drivers/db2/qsql_db2_p.h
@@ -42,6 +42,19 @@
#ifndef QSQL_DB2_H
#define QSQL_DB2_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
#ifdef QT_PLUGIN
#define Q_EXPORT_SQLDRIVER_DB2
#else
@@ -51,15 +64,8 @@
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqldriver.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QDB2Driver;
class QDB2DriverPrivate;
class QDB2ResultPrivate;
@@ -126,6 +132,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_DB2_H
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp
index 5fd07318ec..abf6a74c3e 100644
--- a/src/sql/drivers/ibase/qsql_ibase.cpp
+++ b/src/sql/drivers/ibase/qsql_ibase.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_ibase.h"
+#include "qsql_ibase_p.h"
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qvariant.h>
@@ -47,6 +47,7 @@
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
+#include <QtSql/private/qsqlcachedresult_p.h>
#include <qlist.h>
#include <qvector.h>
#include <qtextcodec.h>
@@ -346,6 +347,31 @@ static void qFreeEventBuffer(QIBaseEventBuffer* eBuffer)
delete eBuffer;
}
+class QIBaseResultPrivate;
+
+class QIBaseResult : public QSqlCachedResult
+{
+ friend class QIBaseResultPrivate;
+
+public:
+ explicit QIBaseResult(const QIBaseDriver* db);
+ virtual ~QIBaseResult();
+
+ bool prepare(const QString& query);
+ bool exec();
+ QVariant handle() const;
+
+protected:
+ bool gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx);
+ bool reset (const QString& query);
+ int size();
+ int numRowsAffected();
+ QSqlRecord record() const;
+
+private:
+ QIBaseResultPrivate* d;
+};
+
class QIBaseResultPrivate
{
public:
diff --git a/src/sql/drivers/ibase/qsql_ibase.pri b/src/sql/drivers/ibase/qsql_ibase.pri
index 26017e8727..ef3b68d34e 100644
--- a/src/sql/drivers/ibase/qsql_ibase.pri
+++ b/src/sql/drivers/ibase/qsql_ibase.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_ibase.h
+HEADERS += $$PWD/qsql_ibase_p.h
SOURCES += $$PWD/qsql_ibase.cpp
unix {
diff --git a/src/sql/drivers/ibase/qsql_ibase.h b/src/sql/drivers/ibase/qsql_ibase_p.h
index 2ce20966c6..b2560ca17c 100644
--- a/src/sql/drivers/ibase/qsql_ibase.h
+++ b/src/sql/drivers/ibase/qsql_ibase_p.h
@@ -42,47 +42,26 @@
#ifndef QSQL_IBASE_H
#define QSQL_IBASE_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqldriver.h>
-#include <QtSql/private/qsqlcachedresult_p.h>
#include <ibase.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QIBaseDriverPrivate;
-class QIBaseResultPrivate;
class QIBaseDriver;
-class QIBaseResult : public QSqlCachedResult
-{
- friend class QIBaseResultPrivate;
-
-public:
- explicit QIBaseResult(const QIBaseDriver* db);
- virtual ~QIBaseResult();
-
- bool prepare(const QString& query);
- bool exec();
- QVariant handle() const;
-
-protected:
- bool gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx);
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- QSqlRecord record() const;
-
-private:
- QIBaseResultPrivate* d;
-};
-
class QIBaseDriver : public QSqlDriver
{
Q_OBJECT
@@ -132,5 +111,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
#endif // QSQL_IBASE_H
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index b4aa5cd4cc..a529d8c32d 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_mysql.h"
+#include "qsql_mysql_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
@@ -166,7 +166,7 @@ class QMYSQLResultPrivate : public QObject
{
Q_OBJECT
public:
- QMYSQLResultPrivate(const QMYSQLDriver* dp, const QMYSQLResult* d) : driver(dp), result(0), q(d),
+ QMYSQLResultPrivate(const QMYSQLDriver* dp, const QMYSQLResult* d) : driver(dp), result(0), q(d),
rowsAffected(0), hasBlobs(false)
#if MYSQL_VERSION_ID >= 40108
, stmt(0), meta(0), inBinds(0), outBinds(0)
@@ -788,7 +788,7 @@ bool QMYSQLResult::nextResult()
{
if(!d->driver)
return false;
-#if MYSQL_VERSION_ID >= 40100
+#if MYSQL_VERSION_ID >= 40100
setAt(-1);
setActive(false);
@@ -796,7 +796,7 @@ bool QMYSQLResult::nextResult()
mysql_free_result(d->result);
d->result = 0;
setSelect(false);
-
+
for (int i = 0; i < d->fields.count(); ++i)
delete[] d->fields[i].outField;
d->fields.clear();
@@ -1374,14 +1374,14 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const
if(type & QSql::Tables) {
QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'");
q.exec(sql);
-
+
while(q.next())
tl.append(q.value(0).toString());
}
if(type & QSql::Views) {
QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'");
q.exec(sql);
-
+
while(q.next())
tl.append(q.value(0).toString());
}
diff --git a/src/sql/drivers/mysql/qsql_mysql.pri b/src/sql/drivers/mysql/qsql_mysql.pri
index 0423eb4ed9..50f49ca548 100644
--- a/src/sql/drivers/mysql/qsql_mysql.pri
+++ b/src/sql/drivers/mysql/qsql_mysql.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_mysql.h
+HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp
!isEmpty(MYSQL_PATH) {
diff --git a/src/sql/drivers/mysql/qsql_mysql.h b/src/sql/drivers/mysql/qsql_mysql_p.h
index 37e18c8fb1..c23bcd92d7 100644
--- a/src/sql/drivers/mysql/qsql_mysql.h
+++ b/src/sql/drivers/mysql/qsql_mysql_p.h
@@ -42,6 +42,17 @@
#ifndef QSQL_MYSQL_H
#define QSQL_MYSQL_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqldriver.h>
#include <QtSql/qsqlresult.h>
@@ -57,15 +68,8 @@
#define Q_EXPORT_SQLDRIVER_MYSQL Q_SQL_EXPORT
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QMYSQLDriverPrivate;
class QMYSQLResultPrivate;
class QMYSQLDriver;
@@ -142,6 +146,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_MYSQL_H
diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp
index e2bb9a4eaf..b0950110e0 100644
--- a/src/sql/drivers/oci/qsql_oci.cpp
+++ b/src/sql/drivers/oci/qsql_oci.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_oci.h"
+#include "qsql_oci_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
@@ -51,6 +51,7 @@
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
+#include <QtSql/private/qsqlcachedresult_p.h>
#include <qstringlist.h>
#include <qvarlengtharray.h>
#include <qvector.h>
@@ -99,7 +100,7 @@ enum { QOCIEncoding = 2000 }; // AL16UTF16
// Always set the OCI_ATTR_CHARSET_FORM to SQLCS_NCHAR is safe
// because Oracle server will deal with the implicit Conversion
// Between CHAR and NCHAR.
-// see: http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89857/oci05bnd.htm#422705
+// see: http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89857/oci05bnd.htm#422705
static const ub1 qOraCharsetForm = SQLCS_NCHAR;
#endif
@@ -162,6 +163,33 @@ Q_DECLARE_METATYPE(QOCIRowIdPointer)
QT_END_INCLUDE_NAMESPACE
class QOCICols;
+struct QOCIResultPrivate;
+
+class Q_EXPORT_SQLDRIVER_OCI QOCIResult : public QSqlCachedResult
+{
+ friend class QOCIDriver;
+ friend struct QOCIResultPrivate;
+ friend class QOCICols;
+public:
+ QOCIResult(const QOCIDriver * db, const QOCIDriverPrivate* p);
+ ~QOCIResult();
+ bool prepare(const QString& query);
+ bool exec();
+ QVariant handle() const;
+
+protected:
+ bool gotoNext(ValueCache &values, int index);
+ bool reset (const QString& query);
+ int size();
+ int numRowsAffected();
+ QSqlRecord record() const;
+ QVariant lastInsertId() const;
+ bool execBatch(bool arrayBind = false);
+ void virtual_hook(int id, void *data);
+
+private:
+ QOCIResultPrivate *d;
+};
struct QOCIResultPrivate
{
@@ -2183,7 +2211,7 @@ bool QOCIDriver::open(const QString & db,
// Connect without tnsnames.ora if a hostname is given
QString connectionString = db;
if (!hostname.isEmpty())
- connectionString =
+ connectionString =
QString::fromLatin1("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))"
"(CONNECT_DATA=(SID=%3)))").arg(hostname).arg((port > -1 ? port : 1521)).arg(db);
diff --git a/src/sql/drivers/oci/qsql_oci.pri b/src/sql/drivers/oci/qsql_oci.pri
index 60ccc4c227..66ccdb1abb 100644
--- a/src/sql/drivers/oci/qsql_oci.pri
+++ b/src/sql/drivers/oci/qsql_oci.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_oci.h
+HEADERS += $$PWD/qsql_oci_p.h
SOURCES += $$PWD/qsql_oci.cpp
unix {
@@ -6,4 +6,4 @@ unix {
} else {
LIBS *= -loci
}
-macx:QMAKE_LFLAGS += -Wl,-flat_namespace,-U,_environ
+mac:QMAKE_LFLAGS += -Wl,-flat_namespace,-U,_environ
diff --git a/src/sql/drivers/oci/qsql_oci.h b/src/sql/drivers/oci/qsql_oci_p.h
index 2488e696d2..fecc828434 100644
--- a/src/sql/drivers/oci/qsql_oci.h
+++ b/src/sql/drivers/oci/qsql_oci_p.h
@@ -42,9 +42,19 @@
#ifndef QSQL_OCI_H
#define QSQL_OCI_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqldriver.h>
-#include <QtSql/private/qsqlcachedresult_p.h>
#ifdef QT_PLUGIN
#define Q_EXPORT_SQLDRIVER_OCI
@@ -52,48 +62,14 @@
#define Q_EXPORT_SQLDRIVER_OCI Q_SQL_EXPORT
#endif
-QT_BEGIN_HEADER
-
typedef struct OCIEnv OCIEnv;
typedef struct OCISvcCtx OCISvcCtx;
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QOCIDriver;
class QOCICols;
struct QOCIDriverPrivate;
-struct QOCIResultPrivate;
-
-class Q_EXPORT_SQLDRIVER_OCI QOCIResult : public QSqlCachedResult
-{
- friend class QOCIDriver;
- friend struct QOCIResultPrivate;
- friend class QOCICols;
-public:
- QOCIResult(const QOCIDriver * db, const QOCIDriverPrivate* p);
- ~QOCIResult();
- bool prepare(const QString& query);
- bool exec();
- QVariant handle() const;
-
-protected:
- bool gotoNext(ValueCache &values, int index);
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- QSqlRecord record() const;
- QVariant lastInsertId() const;
- bool execBatch(bool arrayBind = false);
- void virtual_hook(int id, void *data);
-
-private:
- QOCIResultPrivate *d;
-};
class Q_EXPORT_SQLDRIVER_OCI QOCIDriver : public QSqlDriver
{
@@ -131,6 +107,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_OCI_H
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index c6fd49d1ea..56c38774ec 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_odbc.h"
+#include "qsql_odbc_p.h"
#include <qsqlrecord.h>
#if defined (Q_OS_WIN32)
@@ -115,9 +115,10 @@ class QODBCDriverPrivate
{
public:
enum DefaultCase{Lower, Mixed, Upper, Sensitive};
+ enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase};
QODBCDriverPrivate()
- : hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19), isMySqlServer(false),
- isMSSqlServer(false), isFreeTDSDriver(false), hasSQLFetchScroll(true),
+ : hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19),
+ dbmsType(UnknownDB), isFreeTDSDriver(false), hasSQLFetchScroll(true),
hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
{
}
@@ -129,15 +130,14 @@ public:
bool useSchema;
int disconnectCount;
int datetime_precision;
- bool isMySqlServer;
- bool isMSSqlServer;
+ DBMSType dbmsType;
bool isFreeTDSDriver;
bool hasSQLFetchScroll;
bool hasMultiResultSets;
bool checkDriver() const;
void checkUnicode();
- void checkSqlServer();
+ void checkDBMS();
void checkHasSQLFetchScroll();
void checkHasMultiResults();
void checkSchemaUsage();
@@ -1677,6 +1677,38 @@ QSqlRecord QODBCResult::record() const
return d->rInf;
}
+QVariant QODBCResult::lastInsertId() const
+{
+ QString sql;
+
+ switch (d->driverPrivate->dbmsType) {
+ case QODBCDriverPrivate::MSSqlServer:
+ case QODBCDriverPrivate::Sybase:
+ sql = QLatin1String("SELECT @@IDENTITY;");
+ break;
+ case QODBCDriverPrivate::MySqlServer:
+ sql = QLatin1String("SELECT LAST_INSERT_ID();");
+ break;
+ case QODBCDriverPrivate::PostgreSQL:
+ sql = QLatin1String("SELECT lastval();");
+ break;
+ default:
+ break;
+ }
+
+ if (!sql.isEmpty()) {
+ QSqlQuery qry(driver()->createResult());
+ if (qry.exec(sql) && qry.next())
+ return qry.value(0);
+
+ qSqlWarning(QLatin1String("QODBCResult::lastInsertId: Unable to get lastInsertId"), d);
+ } else {
+ qSqlWarning(QLatin1String("QODBCResult::lastInsertId: not implemented for this DBMS"), d);
+ }
+
+ return QVariant();
+}
+
QVariant QODBCResult::handle() const
{
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hStmt);
@@ -1797,16 +1829,20 @@ bool QODBCDriver::hasFeature(DriverFeature f) const
return true;
case QuerySize:
case NamedPlaceholders:
- case LastInsertId:
case BatchOperations:
case SimpleLocking:
case EventNotifications:
case CancelQuery:
return false;
+ case LastInsertId:
+ return (d->dbmsType == QODBCDriverPrivate::MSSqlServer)
+ || (d->dbmsType == QODBCDriverPrivate::Sybase)
+ || (d->dbmsType == QODBCDriverPrivate::MySqlServer)
+ || (d->dbmsType == QODBCDriverPrivate::PostgreSQL);
case MultipleResultSets:
return d->hasMultiResultSets;
case BLOB: {
- if(d->isMySqlServer)
+ if (d->dbmsType == QODBCDriverPrivate::MySqlServer)
return true;
else
return false;
@@ -1896,13 +1932,13 @@ bool QODBCDriver::open(const QString & db,
d->checkUnicode();
d->checkSchemaUsage();
- d->checkSqlServer();
+ d->checkDBMS();
d->checkHasSQLFetchScroll();
d->checkHasMultiResults();
d->checkDateTimePrecision();
setOpen(true);
setOpenError(false);
- if(d->isMSSqlServer) {
+ if (d->dbmsType == QODBCDriverPrivate::MSSqlServer) {
QSqlQuery i(createResult());
i.exec(QLatin1String("SET QUOTED_IDENTIFIER ON"));
}
@@ -2069,7 +2105,7 @@ void QODBCDriverPrivate::checkSchemaUsage()
useSchema = (val != 0);
}
-void QODBCDriverPrivate::checkSqlServer()
+void QODBCDriverPrivate::checkDBMS()
{
SQLRETURN r;
QVarLengthArray<SQLTCHAR> serverString(200);
@@ -2088,8 +2124,16 @@ void QODBCDriverPrivate::checkSqlServer()
#else
serverType = QString::fromUtf8((const char *)serverString.constData(), t);
#endif
- isMySqlServer = serverType.contains(QLatin1String("mysql"), Qt::CaseInsensitive);
- isMSSqlServer = serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive);
+ if (serverType.contains(QLatin1String("PostgreSQL"), Qt::CaseInsensitive))
+ dbmsType = PostgreSQL;
+ else if (serverType.contains(QLatin1String("Oracle"), Qt::CaseInsensitive))
+ dbmsType = Oracle;
+ else if (serverType.contains(QLatin1String("MySql"), Qt::CaseInsensitive))
+ dbmsType = MySqlServer;
+ else if (serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive))
+ dbmsType = MSSqlServer;
+ else if (serverType.contains(QLatin1String("Sybase"), Qt::CaseInsensitive))
+ dbmsType = Sybase;
}
r = SQLGetInfo(hDbc,
SQL_DRIVER_NAME,
diff --git a/src/sql/drivers/odbc/qsql_odbc.pri b/src/sql/drivers/odbc/qsql_odbc.pri
index 19ff784a04..b206df37c3 100644
--- a/src/sql/drivers/odbc/qsql_odbc.pri
+++ b/src/sql/drivers/odbc/qsql_odbc.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_odbc.h
+HEADERS += $$PWD/qsql_odbc_p.h
SOURCES += $$PWD/qsql_odbc.cpp
unix {
diff --git a/src/sql/drivers/odbc/qsql_odbc.h b/src/sql/drivers/odbc/qsql_odbc_p.h
index 4fba49b9c5..191f64f072 100644
--- a/src/sql/drivers/odbc/qsql_odbc.h
+++ b/src/sql/drivers/odbc/qsql_odbc_p.h
@@ -42,6 +42,17 @@
#ifndef QSQL_ODBC_H
#define QSQL_ODBC_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqldriver.h>
#include <QtSql/qsqlresult.h>
@@ -70,15 +81,8 @@
#include <sqlext.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QODBCPrivate;
class QODBCDriverPrivate;
class QODBCDriver;
@@ -93,6 +97,7 @@ public:
bool prepare(const QString& query);
bool exec();
+ QVariant lastInsertId() const;
QVariant handle() const;
virtual void setForwardOnly(bool forward);
@@ -158,6 +163,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_ODBC_H
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 2bc03715ee..4749b8b97b 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_psql.h"
+#include "qsql_psql_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
@@ -194,11 +194,12 @@ PGresult * QPSQLDriverPrivate::exec(const QString & stmt) const
class QPSQLResultPrivate
{
public:
- QPSQLResultPrivate(QPSQLResult *qq): q(qq), driver(0), result(0), currentSize(-1), preparedQueriesEnabled(false) {}
+ QPSQLResultPrivate(QPSQLResult *qq): q(qq), privDriver(0), result(0), currentSize(-1), preparedQueriesEnabled(false) {}
static QString fieldSerial(int i) { return QLatin1Char('$') + QString::number(i + 1); }
+ void deallocatePreparedStmt();
QPSQLResult *q;
- const QPSQLDriverPrivate *driver;
+ const QPSQLDriverPrivate *privDriver;
PGresult *result;
int currentSize;
bool preparedQueriesEnabled;
@@ -237,7 +238,7 @@ bool QPSQLResultPrivate::processResults()
return true;
}
q->setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
- "Unable to create query"), QSqlError::StatementError, driver, result));
+ "Unable to create query"), QSqlError::StatementError, privDriver, result));
return false;
}
@@ -287,22 +288,22 @@ static QVariant::Type qDecodePSQLType(int t)
return type;
}
-static void qDeallocatePreparedStmt(QPSQLResultPrivate *d)
+void QPSQLResultPrivate::deallocatePreparedStmt()
{
- const QString stmt = QLatin1String("DEALLOCATE ") + d->preparedStmtId;
- PGresult *result = d->driver->exec(stmt);
+ const QString stmt = QLatin1String("DEALLOCATE ") + preparedStmtId;
+ PGresult *result = privDriver->exec(stmt);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
- qWarning("Unable to free statement: %s", PQerrorMessage(d->driver->connection));
+ qWarning("Unable to free statement: %s", PQerrorMessage(privDriver->connection));
PQclear(result);
- d->preparedStmtId.clear();
+ preparedStmtId.clear();
}
QPSQLResult::QPSQLResult(const QPSQLDriver* db, const QPSQLDriverPrivate* p)
: QSqlResult(db)
{
d = new QPSQLResultPrivate(this);
- d->driver = p;
+ d->privDriver = p;
d->preparedQueriesEnabled = db->hasFeature(QSqlDriver::PreparedQueries);
}
@@ -311,7 +312,7 @@ QPSQLResult::~QPSQLResult()
cleanup();
if (d->preparedQueriesEnabled && !d->preparedStmtId.isNull())
- qDeallocatePreparedStmt(d);
+ d->deallocatePreparedStmt();
delete d;
}
@@ -370,7 +371,7 @@ QVariant QPSQLResult::data(int i)
case QVariant::Bool:
return QVariant((bool)(val[0] == 't'));
case QVariant::String:
- return d->driver->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val);
+ return d->privDriver->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val);
case QVariant::LongLong:
if (val[0] == '-')
return QString::fromLatin1(val).toLongLong();
@@ -468,7 +469,7 @@ bool QPSQLResult::reset (const QString& query)
return false;
if (!driver()->isOpen() || driver()->isOpenError())
return false;
- d->result = d->driver->exec(query);
+ d->result = d->privDriver->exec(query);
return d->processResults();
}
@@ -484,7 +485,12 @@ int QPSQLResult::numRowsAffected()
QVariant QPSQLResult::lastInsertId() const
{
- if (isActive()) {
+ if (d->privDriver->pro >= QPSQLDriver::Version81) {
+ QSqlQuery qry(driver()->createResult());
+ // Most recent sequence value obtained from nextval
+ if (qry.exec(QLatin1String("SELECT lastval();")) && qry.next())
+ return qry.value(0);
+ } else if (isActive()) {
Oid id = PQoidValue(d->result);
if (id != InvalidOid)
return QVariant(id);
@@ -501,7 +507,7 @@ QSqlRecord QPSQLResult::record() const
int count = PQnfields(d->result);
for (int i = 0; i < count; ++i) {
QSqlField f;
- if (d->driver->isUtf8)
+ if (d->privDriver->isUtf8)
f.setName(QString::fromUtf8(PQfname(d->result, i)));
else
f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
@@ -568,16 +574,16 @@ bool QPSQLResult::prepare(const QString &query)
cleanup();
if (!d->preparedStmtId.isEmpty())
- qDeallocatePreparedStmt(d);
+ d->deallocatePreparedStmt();
const QString stmtId = qMakePreparedStmtId();
const QString stmt = QString::fromLatin1("PREPARE %1 AS ").arg(stmtId).append(QSqlResultPrivate::positionalToNamedBinding(query, QPSQLResultPrivate::fieldSerial));
- PGresult *result = d->driver->exec(stmt);
+ PGresult *result = d->privDriver->exec(stmt);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
- "Unable to prepare statement"), QSqlError::StatementError, d->driver, result));
+ "Unable to prepare statement"), QSqlError::StatementError, d->privDriver, result));
PQclear(result);
d->preparedStmtId.clear();
return false;
@@ -596,13 +602,13 @@ bool QPSQLResult::exec()
cleanup();
QString stmt;
- const QString params = qCreateParamString(boundValues(), d->q->driver());
+ const QString params = qCreateParamString(boundValues(), driver());
if (params.isEmpty())
stmt = QString::fromLatin1("EXECUTE %1").arg(d->preparedStmtId);
else
stmt = QString::fromLatin1("EXECUTE %1 (%2)").arg(d->preparedStmtId).arg(params);
- d->result = d->driver->exec(stmt);
+ d->result = d->privDriver->exec(stmt);
return d->processResults();
}
diff --git a/src/sql/drivers/psql/qsql_psql.pri b/src/sql/drivers/psql/qsql_psql.pri
index 9b647d8200..d0ded5e625 100644
--- a/src/sql/drivers/psql/qsql_psql.pri
+++ b/src/sql/drivers/psql/qsql_psql.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_psql.h
+HEADERS += $$PWD/qsql_psql_p.h
SOURCES += $$PWD/qsql_psql.cpp
unix|win32-g++* {
diff --git a/src/sql/drivers/psql/qsql_psql.h b/src/sql/drivers/psql/qsql_psql_p.h
index 444ef1bccc..6f60a2a34f 100644
--- a/src/sql/drivers/psql/qsql_psql.h
+++ b/src/sql/drivers/psql/qsql_psql_p.h
@@ -42,6 +42,17 @@
#ifndef QSQL_PSQL_H
#define QSQL_PSQL_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqldriver.h>
@@ -51,18 +62,11 @@
#define Q_EXPORT_SQLDRIVER_PSQL Q_SQL_EXPORT
#endif
-QT_BEGIN_HEADER
-
typedef struct pg_conn PGconn;
typedef struct pg_result PGresult;
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QPSQLResultPrivate;
class QPSQLDriverPrivate;
class QPSQLDriver;
@@ -158,6 +162,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_PSQL_H
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp
index 04c88dd188..854705b3f6 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.cpp
+++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_sqlite.h"
+#include "qsql_sqlite_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
@@ -47,6 +47,7 @@
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
+#include <QtSql/private/qsqlcachedresult_p.h>
#include <qstringlist.h>
#include <qvector.h>
#include <qdebug.h>
@@ -67,7 +68,7 @@ Q_DECLARE_METATYPE(sqlite3_stmt*)
QT_BEGIN_NAMESPACE
-static QString _q_escapeIdentifier(const QString &identifier)
+static QString _q_escapeIdentifier(const QString &identifier)
{
QString res = identifier;
if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {
@@ -106,6 +107,33 @@ static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::Er
type, errorCode);
}
+class QSQLiteResultPrivate;
+
+class QSQLiteResult : public QSqlCachedResult
+{
+ friend class QSQLiteDriver;
+ friend class QSQLiteResultPrivate;
+public:
+ explicit QSQLiteResult(const QSQLiteDriver* db);
+ ~QSQLiteResult();
+ QVariant handle() const;
+
+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);
+
+private:
+ QSQLiteResultPrivate* d;
+};
+
class QSQLiteDriverPrivate
{
public:
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.pri b/src/sql/drivers/sqlite/qsql_sqlite.pri
index a2e80d4c74..e323f2eba5 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.pri
+++ b/src/sql/drivers/sqlite/qsql_sqlite.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_sqlite.h
+HEADERS += $$PWD/qsql_sqlite_p.h
SOURCES += $$PWD/qsql_sqlite.cpp
!system-sqlite:!contains(LIBS, .*sqlite3.*) {
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.h b/src/sql/drivers/sqlite/qsql_sqlite_p.h
index 0fdcd4e240..548d1da97c 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.h
+++ b/src/sql/drivers/sqlite/qsql_sqlite_p.h
@@ -42,9 +42,19 @@
#ifndef QSQL_SQLITE_H
#define QSQL_SQLITE_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqldriver.h>
#include <QtSql/qsqlresult.h>
-#include <QtSql/private/qsqlcachedresult_p.h>
struct sqlite3;
@@ -54,44 +64,11 @@ struct sqlite3;
#define Q_EXPORT_SQLDRIVER_SQLITE Q_SQL_EXPORT
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QSQLiteDriverPrivate;
-class QSQLiteResultPrivate;
class QSQLiteDriver;
-class QSQLiteResult : public QSqlCachedResult
-{
- friend class QSQLiteDriver;
- friend class QSQLiteResultPrivate;
-public:
- explicit QSQLiteResult(const QSQLiteDriver* db);
- ~QSQLiteResult();
- QVariant handle() const;
-
-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);
-
-private:
- QSQLiteResultPrivate* d;
-};
-
class Q_EXPORT_SQLDRIVER_SQLITE QSQLiteDriver : public QSqlDriver
{
Q_OBJECT
@@ -125,6 +102,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_SQLITE_H
diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
index 02e4004901..1a16b85470 100644
--- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
+++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_sqlite2.h"
+#include "qsql_sqlite2_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
@@ -50,6 +50,7 @@
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
+#include <QtSql/private/qsqlcachedresult_p.h>
#include <qstringlist.h>
#include <qvector.h>
@@ -94,6 +95,30 @@ QSQLite2DriverPrivate::QSQLite2DriverPrivate() : access(0)
utf8 = (qstrcmp(sqlite_encoding, "UTF-8") == 0);
}
+class QSQLite2ResultPrivate;
+
+class QSQLite2Result : public QSqlCachedResult
+{
+ friend class QSQLite2Driver;
+ friend class QSQLite2ResultPrivate;
+public:
+ explicit QSQLite2Result(const QSQLite2Driver* db);
+ ~QSQLite2Result();
+ QVariant handle() const;
+
+protected:
+ bool gotoNext(QSqlCachedResult::ValueCache& row, int idx);
+ bool reset (const QString& query);
+ int size();
+ int numRowsAffected();
+ QSqlRecord record() const;
+ void detachFromResultSet();
+ void virtual_hook(int id, void *data);
+
+private:
+ QSQLite2ResultPrivate* d;
+};
+
class QSQLite2ResultPrivate
{
public:
@@ -170,7 +195,7 @@ void QSQLite2ResultPrivate::init(const char **cnames, int numCols)
for (int i = 0; i < numCols; ++i) {
const char* lastDot = strrchr(cnames[i], '.');
const char* fieldName = lastDot ? lastDot + 1 : cnames[i];
-
+
//remove quotations around the field name if any
QString fieldStr = QString::fromLatin1(fieldName);
QLatin1Char quote('\"');
@@ -219,7 +244,7 @@ bool QSQLite2ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
firstRow.clear();
firstRow.resize(colNum);
}
-
+
switch(res) {
case SQLITE_ROW:
// check to see if should fill out columns
diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.pri b/src/sql/drivers/sqlite2/qsql_sqlite2.pri
index 9a9f6cdf9e..5baba30db0 100644
--- a/src/sql/drivers/sqlite2/qsql_sqlite2.pri
+++ b/src/sql/drivers/sqlite2/qsql_sqlite2.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_sqlite2.h
+HEADERS += $$PWD/qsql_sqlite2_p.h
SOURCES += $$PWD/qsql_sqlite2.cpp
!contains(LIBS, .*sqlite.*):LIBS += -lsqlite
diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.h b/src/sql/drivers/sqlite2/qsql_sqlite2_p.h
index f141ad1cc2..7a075210ae 100644
--- a/src/sql/drivers/sqlite2/qsql_sqlite2.h
+++ b/src/sql/drivers/sqlite2/qsql_sqlite2_p.h
@@ -42,11 +42,21 @@
#ifndef QSQL_SQLITE2_H
#define QSQL_SQLITE2_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqldriver.h>
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqlrecord.h>
#include <QtSql/qsqlindex.h>
-#include <QtSql/private/qsqlcachedresult_p.h>
#if defined (Q_OS_WIN32)
# include <QtCore/qt_windows.h>
@@ -54,41 +64,11 @@
struct sqlite;
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QSQLite2DriverPrivate;
-class QSQLite2ResultPrivate;
class QSQLite2Driver;
-class QSQLite2Result : public QSqlCachedResult
-{
- friend class QSQLite2Driver;
- friend class QSQLite2ResultPrivate;
-public:
- explicit QSQLite2Result(const QSQLite2Driver* db);
- ~QSQLite2Result();
- QVariant handle() const;
-
-protected:
- bool gotoNext(QSqlCachedResult::ValueCache& row, int idx);
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- QSqlRecord record() const;
- void detachFromResultSet();
- void virtual_hook(int id, void *data);
-
-private:
- QSQLite2ResultPrivate* d;
-};
-
class QSQLite2Driver : public QSqlDriver
{
Q_OBJECT
@@ -127,6 +107,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_SQLITE2_H
diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp
index 45bba42ca7..996a1bdd1a 100644
--- a/src/sql/drivers/tds/qsql_tds.cpp
+++ b/src/sql/drivers/tds/qsql_tds.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsql_tds.h"
+#include "qsql_tds_p.h"
#include <qglobal.h>
#ifdef Q_OS_WIN32 // We assume that MS SQL Server is used. Set Q_USE_SYBASE to force Sybase.
@@ -58,6 +58,7 @@
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
+#include <QtSql/private/qsqlcachedresult_p.h>
#include <qstringlist.h>
#include <qvector.h>
@@ -145,6 +146,33 @@ public:
bool initialized;
};
+struct QTDSColumnData
+{
+ void *data;
+ DBINT nullbind;
+};
+Q_DECLARE_TYPEINFO(QTDSColumnData, Q_MOVABLE_TYPE);
+
+class QTDSResultPrivate;
+
+class QTDSResult : public QSqlCachedResult
+{
+public:
+ explicit QTDSResult(const QTDSDriver* db);
+ ~QTDSResult();
+ QVariant handle() const;
+
+protected:
+ void cleanup();
+ bool reset (const QString& query);
+ int size();
+ int numRowsAffected();
+ bool gotoNext(QSqlCachedResult::ValueCache &values, int index);
+ QSqlRecord record() const;
+
+private:
+ QTDSResultPrivate* d;
+};
class QTDSResultPrivate
{
@@ -156,7 +184,7 @@ public:
void addErrorMsg(QString& errMsg) { errorMsgs.append(errMsg); }
QString getErrorMsgs() { return errorMsgs.join(QLatin1String("\n")); }
void clearErrorMsgs() { errorMsgs.clear(); }
- QVector<void *> buffer;
+ QVector<QTDSColumnData> buffer;
QSqlRecord rec;
private:
@@ -325,8 +353,8 @@ void QTDSResult::cleanup()
{
d->clearErrorMsgs();
d->rec.clear();
- for (int i = 0; i < d->buffer.size() / 2; ++i)
- free(d->buffer.at(i * 2));
+ for (int i = 0; i < d->buffer.size(); ++i)
+ free(d->buffer.at(i * 2).data);
d->buffer.clear();
// "can" stands for "cancel"... very clever.
dbcanquery(d->dbproc);
@@ -340,9 +368,9 @@ QVariant QTDSResult::handle() const
return QVariant(qRegisterMetaType<DBPROCESS *>("DBPROCESS*"), &d->dbproc);
}
-static inline bool qIsNull(const void *ind)
+static inline bool qIsNull(const QTDSColumnData &p)
{
- return *reinterpret_cast<const DBINT *>(&ind) == -1;
+ return p.nullbind == -1;
}
bool QTDSResult::gotoNext(QSqlCachedResult::ValueCache &values, int index)
@@ -364,33 +392,33 @@ bool QTDSResult::gotoNext(QSqlCachedResult::ValueCache &values, int index)
int idx = index + i;
switch (d->rec.field(i).type()) {
case QVariant::DateTime:
- if (qIsNull(d->buffer.at(i * 2 + 1))) {
+ if (qIsNull(d->buffer.at(i))) {
values[idx] = QVariant(QVariant::DateTime);
} else {
- DBDATETIME *bdt = (DBDATETIME*) d->buffer.at(i * 2);
+ DBDATETIME *bdt = (DBDATETIME*) d->buffer.at(i).data;
QDate date = QDate::fromString(QLatin1String("1900-01-01"), Qt::ISODate);
QTime time = QTime::fromString(QLatin1String("00:00:00"), Qt::ISODate);
values[idx] = QDateTime(date.addDays(bdt->dtdays), time.addMSecs(int(bdt->dttime / 0.3)));
}
break;
case QVariant::Int:
- if (qIsNull(d->buffer.at(i * 2 + 1)))
+ if (qIsNull(d->buffer.at(i)))
values[idx] = QVariant(QVariant::Int);
else
- values[idx] = *((int*)d->buffer.at(i * 2));
+ values[idx] = *((int*)d->buffer.at(i).data);
break;
case QVariant::Double:
case QVariant::String:
- if (qIsNull(d->buffer.at(i * 2 + 1)))
+ if (qIsNull(d->buffer.at(i)))
values[idx] = QVariant(QVariant::String);
else
- values[idx] = QString::fromLocal8Bit((const char*)d->buffer.at(i * 2)).trimmed();
+ values[idx] = QString::fromLocal8Bit((const char*)d->buffer.at(i).data).trimmed();
break;
case QVariant::ByteArray: {
- if (qIsNull(d->buffer.at(i * 2 + 1)))
+ if (qIsNull(d->buffer.at(i)))
values[idx] = QVariant(QVariant::ByteArray);
else
- values[idx] = QByteArray((const char*)d->buffer.at(i * 2));
+ values[idx] = QByteArray((const char*)d->buffer.at(i).data);
break;
}
default:
@@ -430,7 +458,7 @@ bool QTDSResult::reset (const QString& query)
setSelect((DBCMDROW(d->dbproc) == SUCCEED)); // decide whether or not we are dealing with a SELECT query
int numCols = dbnumcols(d->dbproc);
if (numCols > 0) {
- d->buffer.resize(numCols * 2);
+ d->buffer.resize(numCols);
init(numCols);
}
for (int i = 0; i < numCols; ++i) {
@@ -470,11 +498,11 @@ bool QTDSResult::reset (const QString& query)
break;
}
if (ret == SUCCEED) {
- d->buffer[i * 2] = p;
- ret = dbnullbind(d->dbproc, i+1, (DBINT*)(&d->buffer[i * 2 + 1]));
+ d->buffer[i].data = p;
+ ret = dbnullbind(d->dbproc, i+1, &d->buffer[i].nullbind);
} else {
- d->buffer[i * 2] = 0;
- d->buffer[i * 2 + 1] = 0;
+ d->buffer[i].data = 0;
+ d->buffer[i].nullbind = 0;
free(p);
}
if ((ret != SUCCEED) && (ret != -1)) {
diff --git a/src/sql/drivers/tds/qsql_tds.pri b/src/sql/drivers/tds/qsql_tds.pri
index 38aab2f3e4..67d037aa6b 100644
--- a/src/sql/drivers/tds/qsql_tds.pri
+++ b/src/sql/drivers/tds/qsql_tds.pri
@@ -1,4 +1,4 @@
-HEADERS += $$PWD/qsql_tds.h
+HEADERS += $$PWD/qsql_tds_p.h
SOURCES += $$PWD/qsql_tds.cpp
unix|win32-g++*: {
diff --git a/src/sql/drivers/tds/qsql_tds.h b/src/sql/drivers/tds/qsql_tds_p.h
index 38cb2dc42e..5336f183ef 100644
--- a/src/sql/drivers/tds/qsql_tds.h
+++ b/src/sql/drivers/tds/qsql_tds_p.h
@@ -42,9 +42,19 @@
#ifndef QSQL_TDS_H
#define QSQL_TDS_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtSql/qsqlresult.h>
#include <QtSql/qsqldriver.h>
-#include <QtSql/private/qsqlcachedresult_p.h>
#ifdef Q_OS_WIN32
#define WIN32_LEAN_AND_MEAN
@@ -67,38 +77,11 @@
#define Q_EXPORT_SQLDRIVER_TDS Q_SQL_EXPORT
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-#if 0
-#pragma qt_no_master_include
-#pragma qt_sync_stop_processing
-#endif
-
class QTDSDriverPrivate;
-class QTDSResultPrivate;
class QTDSDriver;
-class QTDSResult : public QSqlCachedResult
-{
-public:
- explicit QTDSResult(const QTDSDriver* db);
- ~QTDSResult();
- QVariant handle() const;
-
-protected:
- void cleanup();
- bool reset (const QString& query);
- int size();
- int numRowsAffected();
- bool gotoNext(QSqlCachedResult::ValueCache &values, int index);
- QSqlRecord record() const;
-
-private:
- QTDSResultPrivate* d;
-};
-
class Q_EXPORT_SQLDRIVER_TDS QTDSDriver : public QSqlDriver
{
Q_OBJECT
@@ -137,6 +120,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_TDS_H
diff --git a/src/sql/kernel/qsql.h b/src/sql/kernel/qsql.h
index 54c5fc13b6..9b9381f797 100644
--- a/src/sql/kernel/qsql.h
+++ b/src/sql/kernel/qsql.h
@@ -44,8 +44,6 @@
#include <QtCore/qglobal.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
#ifndef QT_STATIC
@@ -97,6 +95,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QSql::ParamType)
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQL_H
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index 36422f5f62..0ca79fd39f 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -48,31 +48,31 @@
#endif
#ifdef QT_SQL_PSQL
-#include "../drivers/psql/qsql_psql.h"
+#include "../drivers/psql/qsql_psql_p.h"
#endif
#ifdef QT_SQL_MYSQL
-#include "../drivers/mysql/qsql_mysql.h"
+#include "../drivers/mysql/qsql_mysql_p.h"
#endif
#ifdef QT_SQL_ODBC
-#include "../drivers/odbc/qsql_odbc.h"
+#include "../drivers/odbc/qsql_odbc_p.h"
#endif
#ifdef QT_SQL_OCI
-#include "../drivers/oci/qsql_oci.h"
+#include "../drivers/oci/qsql_oci_p.h"
#endif
#ifdef QT_SQL_TDS
// conflicting RETCODE typedef between odbc and freetds
#define RETCODE DBRETCODE
-#include "../drivers/tds/qsql_tds.h"
+#include "../drivers/tds/qsql_tds_p.h"
#undef RETCODE
#endif
#ifdef QT_SQL_DB2
-#include "../drivers/db2/qsql_db2.h"
+#include "../drivers/db2/qsql_db2_p.h"
#endif
#ifdef QT_SQL_SQLITE
-#include "../drivers/sqlite/qsql_sqlite.h"
+#include "../drivers/sqlite/qsql_sqlite_p.h"
#endif
#ifdef QT_SQL_SQLITE2
-#include "../drivers/sqlite2/qsql_sqlite2.h"
+#include "../drivers/sqlite2/qsql_sqlite2_p.h"
#endif
#ifdef QT_SQL_IBASE
#undef SQL_FLOAT // avoid clash with ODBC
@@ -82,7 +82,7 @@
#undef SQL_TYPE_DATE
#undef SQL_DATE
#define SCHAR IBASE_SCHAR // avoid clash with ODBC (older versions of ibase.h with Firebird)
-#include "../drivers/ibase/qsql_ibase.h"
+#include "../drivers/ibase/qsql_ibase_p.h"
#undef SCHAR
#endif
diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h
index f0e920ade1..7249e223a5 100644
--- a/src/sql/kernel/qsqldatabase.h
+++ b/src/sql/kernel/qsqldatabase.h
@@ -45,8 +45,6 @@
#include <QtCore/qstring.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -146,6 +144,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLDATABASE_H
diff --git a/src/sql/kernel/qsqldriver.h b/src/sql/kernel/qsqldriver.h
index aaa879e957..5e0950e57b 100644
--- a/src/sql/kernel/qsqldriver.h
+++ b/src/sql/kernel/qsqldriver.h
@@ -47,8 +47,6 @@
#include <QtCore/qstringlist.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -139,6 +137,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLDRIVER_H
diff --git a/src/sql/kernel/qsqldriverplugin.h b/src/sql/kernel/qsqldriverplugin.h
index a111c1257a..ca2e0f2474 100644
--- a/src/sql/kernel/qsqldriverplugin.h
+++ b/src/sql/kernel/qsqldriverplugin.h
@@ -46,8 +46,6 @@
#include <QtCore/qfactoryinterface.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -68,6 +66,4 @@ public:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLDRIVERPLUGIN_H
diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp
index adcb8de4d4..9beaf10a32 100644
--- a/src/sql/kernel/qsqlerror.cpp
+++ b/src/sql/kernel/qsqlerror.cpp
@@ -63,9 +63,7 @@ QDebug operator<<(QDebug dbg, const QSqlError &s)
A QSqlError object can provide database-specific error data,
including the driverText() and databaseText() messages (or both
concatenated together as text()), and the error number() and
- type(). The functions all have setters so that you can create and
- return QSqlError objects from your own classes, for example from
- your own SQL drivers.
+ type().
\sa QSqlDatabase::lastError(), QSqlQuery::lastError()
*/
@@ -149,7 +147,7 @@ QSqlError::~QSqlError()
Returns the text of the error as reported by the driver. This may
contain database-specific descriptions. It may also be empty.
- \sa setDriverText(), databaseText(), text()
+ \sa databaseText(), text()
*/
QString QSqlError::driverText() const
{
@@ -157,21 +155,29 @@ QString QSqlError::driverText() const
}
/*!
+ \fn void QSqlError::setDriverText(const QString &driverText)
+ \obsolete
+
Sets the driver error text to the value of \a driverText.
+ Use QSqlError(const QString &driverText, const QString &databaseText,
+ ErrorType type, int number) instead
+
\sa driverText(), setDatabaseText(), text()
*/
+#if QT_DEPRECATED_SINCE(5, 1)
void QSqlError::setDriverText(const QString& driverText)
{
driverError = driverText;
}
+#endif
/*!
Returns the text of the error as reported by the database. This
may contain database-specific descriptions; it may be empty.
- \sa setDatabaseText(), driverText(), text()
+ \sa driverText(), text()
*/
QString QSqlError::databaseText() const
@@ -180,20 +186,26 @@ QString QSqlError::databaseText() const
}
/*!
+ \fn void QSqlError::setDatabaseText(const QString &databaseText)
+ \obsolete
+
Sets the database error text to the value of \a databaseText.
+ Use QSqlError(const QString &driverText, const QString &databaseText,
+ ErrorType type, int number) instead
+
\sa databaseText(), setDriverText(), text()
*/
+#if QT_DEPRECATED_SINCE(5, 1)
void QSqlError::setDatabaseText(const QString& databaseText)
{
databaseError = databaseText;
}
+#endif
/*!
Returns the error type, or -1 if the type cannot be determined.
-
- \sa setType()
*/
QSqlError::ErrorType QSqlError::type() const
@@ -202,21 +214,27 @@ QSqlError::ErrorType QSqlError::type() const
}
/*!
+ \fn void QSqlError::setType(ErrorType type)
+ \obsolete
+
Sets the error type to the value of \a type.
+ Use QSqlError(const QString &driverText, const QString &databaseText,
+ ErrorType type, int number) instead
+
\sa type()
*/
+#if QT_DEPRECATED_SINCE(5, 1)
void QSqlError::setType(ErrorType type)
{
errorType = type;
}
+#endif
/*!
Returns the database-specific error number, or -1 if it cannot be
determined.
-
- \sa setNumber()
*/
int QSqlError::number() const
@@ -225,15 +243,23 @@ int QSqlError::number() const
}
/*!
+ \fn void QSqlError::setNumber(int number)
+ \obsolete
+
Sets the database-specific error number to \a number.
+ Use QSqlError(const QString &driverText, const QString &databaseText,
+ ErrorType type, int number) instead
+
\sa number()
*/
+#if QT_DEPRECATED_SINCE(5, 1)
void QSqlError::setNumber(int number)
{
errorNumber = number;
}
+#endif
/*!
This is a convenience function that returns databaseText() and
diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h
index beab5f27ba..39c4cda958 100644
--- a/src/sql/kernel/qsqlerror.h
+++ b/src/sql/kernel/qsqlerror.h
@@ -45,8 +45,6 @@
#include <QtCore/qstring.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -71,16 +69,19 @@ public:
~QSqlError();
QString driverText() const;
- void setDriverText(const QString& driverText);
QString databaseText() const;
- void setDatabaseText(const QString& databaseText);
ErrorType type() const;
- void setType(ErrorType type);
int number() const;
- void setNumber(int number);
QString text() const;
bool isValid() const;
+#if QT_DEPRECATED_SINCE(5, 1)
+ QT_DEPRECATED void setDriverText(const QString &driverText);
+ QT_DEPRECATED void setDatabaseText(const QString &databaseText);
+ QT_DEPRECATED void setType(ErrorType type);
+ QT_DEPRECATED void setNumber(int number);
+#endif
+
private:
QString driverError;
QString databaseError;
@@ -94,6 +95,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlError &);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLERROR_H
diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h
index 626cce16ca..a642721039 100644
--- a/src/sql/kernel/qsqlfield.h
+++ b/src/sql/kernel/qsqlfield.h
@@ -46,8 +46,6 @@
#include <QtCore/qstring.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -110,6 +108,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLFIELD_H
diff --git a/src/sql/kernel/qsqlindex.h b/src/sql/kernel/qsqlindex.h
index 83e1f21e9d..96c2f614f1 100644
--- a/src/sql/kernel/qsqlindex.h
+++ b/src/sql/kernel/qsqlindex.h
@@ -46,8 +46,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -78,6 +76,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLINDEX_H
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index cac2f1dad4..5b103f1bff 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -325,7 +325,7 @@ bool QSqlQuery::isNull(int field) const
}
/*!
-
+
Executes the SQL in \a query. Returns true and sets the query state
to \l{isActive()}{active} if the query was successful; otherwise
returns false. The \a query string must use syntax appropriate for
@@ -579,7 +579,7 @@ bool QSqlQuery::seek(int index, bool relative)
}
/*!
-
+
Retrieves the next record in the result, if available, and positions
the query on the retrieved record. Note that the result must be in
the \l{isActive()}{active} state and isSelect() must return true
@@ -783,7 +783,7 @@ bool QSqlQuery::isValid() const
}
/*!
-
+
Returns true if the query is \e{active}. An active QSqlQuery is one
that has been \l{QSqlQuery::exec()} {exec()'d} successfully but not
yet finished with. When you are finished with an active query, you
@@ -1143,7 +1143,7 @@ QString QSqlQuery::executedQuery() const
behavior is undefined.
For MySQL databases the row's auto-increment field will be returned.
-
+
\note For this function to work in PSQL, the table table must
contain OIDs, which may not have been created by default. Check the
\c default_with_oids configuration variable to be sure.
@@ -1199,7 +1199,7 @@ QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const
call this function, but it may be helpful in order to free resources
such as locks or cursors if you intend to re-use the query at a
later time.
-
+
Sets the query to inactive. Bound values retain their values.
\sa prepare(), exec(), isActive()
@@ -1216,7 +1216,7 @@ void QSqlQuery::finish()
/*!
\since 4.4
-
+
Discards the current result set and navigates to the next if available.
Some databases are capable of returning multiple result sets for
@@ -1224,7 +1224,7 @@ void QSqlQuery::finish()
multiple statements). If multiple result sets are available after
executing a query this function can be used to navigate to the next
result set(s).
-
+
If a new result set is available this function will return true.
The query will be repositioned on an \e invalid record in the new
result set and must be navigated to a valid record before data
diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h
index 5c14f3808b..3719643174 100644
--- a/src/sql/kernel/qsqlquery.h
+++ b/src/sql/kernel/qsqlquery.h
@@ -46,8 +46,6 @@
#include <QtSql/qsqldatabase.h>
#include <QtCore/qstring.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -122,6 +120,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLQUERY_H
diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h
index 0d0fae1460..bc8c6a8a57 100644
--- a/src/sql/kernel/qsqlrecord.h
+++ b/src/sql/kernel/qsqlrecord.h
@@ -45,8 +45,6 @@
#include <QtCore/qstring.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -109,6 +107,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlRecord &);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLRECORD_H
diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp
index ea972abf50..db55ad7813 100644
--- a/src/sql/kernel/qsqlresult.cpp
+++ b/src/sql/kernel/qsqlresult.cpp
@@ -218,11 +218,24 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query)
QSqlResult::QSqlResult(const QSqlDriver *db)
{
- d = new QSqlResultPrivate(this);
+ d_ptr = new QSqlResultPrivate;
+ Q_D(QSqlResult);
+ d->q_ptr = this;
d->sqldriver = const_cast<QSqlDriver *>(db);
- if(db) {
- setNumericalPrecisionPolicy(db->numericalPrecisionPolicy());
- }
+ if (d->sqldriver)
+ setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy());
+}
+
+/*! \internal
+*/
+QSqlResult::QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db)
+{
+ d_ptr = &dd;
+ Q_D(QSqlResult);
+ d->q_ptr = this;
+ d->sqldriver = const_cast<QSqlDriver *>(db);
+ if (d->sqldriver)
+ setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy());
}
/*!
@@ -231,6 +244,7 @@ QSqlResult::QSqlResult(const QSqlDriver *db)
QSqlResult::~QSqlResult()
{
+ Q_D(QSqlResult);
delete d;
}
@@ -243,6 +257,7 @@ QSqlResult::~QSqlResult()
void QSqlResult::setQuery(const QString& query)
{
+ Q_D(QSqlResult);
d->sql = query;
}
@@ -255,6 +270,7 @@ void QSqlResult::setQuery(const QString& query)
QString QSqlResult::lastQuery() const
{
+ Q_D(const QSqlResult);
return d->sql;
}
@@ -267,6 +283,7 @@ QString QSqlResult::lastQuery() const
*/
int QSqlResult::at() const
{
+ Q_D(const QSqlResult);
return d->idx;
}
@@ -281,6 +298,7 @@ int QSqlResult::at() const
bool QSqlResult::isValid() const
{
+ Q_D(const QSqlResult);
return d->idx != QSql::BeforeFirstRow && d->idx != QSql::AfterLastRow;
}
@@ -298,6 +316,7 @@ bool QSqlResult::isValid() const
bool QSqlResult::isActive() const
{
+ Q_D(const QSqlResult);
return d->active;
}
@@ -310,6 +329,7 @@ bool QSqlResult::isActive() const
void QSqlResult::setAt(int index)
{
+ Q_D(QSqlResult);
d->idx = index;
}
@@ -325,6 +345,7 @@ void QSqlResult::setAt(int index)
void QSqlResult::setSelect(bool select)
{
+ Q_D(QSqlResult);
d->isSel = select;
}
@@ -337,6 +358,7 @@ void QSqlResult::setSelect(bool select)
bool QSqlResult::isSelect() const
{
+ Q_D(const QSqlResult);
return d->isSel;
}
@@ -347,6 +369,7 @@ bool QSqlResult::isSelect() const
const QSqlDriver *QSqlResult::driver() const
{
+ Q_D(const QSqlResult);
return d->sqldriver;
}
@@ -360,6 +383,7 @@ const QSqlDriver *QSqlResult::driver() const
void QSqlResult::setActive(bool active)
{
+ Q_D(QSqlResult);
if (active && d->executedQuery.isEmpty())
d->executedQuery = d->sql;
@@ -375,6 +399,7 @@ void QSqlResult::setActive(bool active)
void QSqlResult::setLastError(const QSqlError &error)
{
+ Q_D(QSqlResult);
d->error = error;
}
@@ -385,6 +410,7 @@ void QSqlResult::setLastError(const QSqlError &error)
QSqlError QSqlResult::lastError() const
{
+ Q_D(const QSqlResult);
return d->error;
}
@@ -519,6 +545,7 @@ bool QSqlResult::fetchPrevious()
*/
bool QSqlResult::isForwardOnly() const
{
+ Q_D(const QSqlResult);
return d->forwardOnly;
}
@@ -540,6 +567,7 @@ bool QSqlResult::isForwardOnly() const
*/
void QSqlResult::setForwardOnly(bool forward)
{
+ Q_D(QSqlResult);
d->forwardOnly = forward;
}
@@ -554,6 +582,7 @@ void QSqlResult::setForwardOnly(bool forward)
*/
bool QSqlResult::savePrepare(const QString& query)
{
+ Q_D(QSqlResult);
if (!driver())
return false;
d->clear();
@@ -579,6 +608,7 @@ bool QSqlResult::savePrepare(const QString& query)
*/
bool QSqlResult::prepare(const QString& query)
{
+ Q_D(QSqlResult);
d->sql = query;
if (d->holders.isEmpty()) {
// parse the query to memorize parameter location
@@ -595,6 +625,7 @@ bool QSqlResult::prepare(const QString& query)
*/
bool QSqlResult::exec()
{
+ Q_D(QSqlResult);
bool ret;
// fake preparation - just replace the placeholders..
QString query = lastQuery();
@@ -647,6 +678,7 @@ bool QSqlResult::exec()
*/
void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType paramType)
{
+ Q_D(QSqlResult);
d->binds = PositionalBinding;
d->indexes[QSqlResultPrivate::fieldSerial(index)].append(index);
if (d->values.count() <= index)
@@ -675,6 +707,7 @@ void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType param
void QSqlResult::bindValue(const QString& placeholder, const QVariant& val,
QSql::ParamType paramType)
{
+ Q_D(QSqlResult);
d->binds = NamedBinding;
// if the index has already been set when doing emulated named
// bindings - don't reset it
@@ -696,6 +729,7 @@ void QSqlResult::bindValue(const QString& placeholder, const QVariant& val,
*/
void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType)
{
+ Q_D(QSqlResult);
d->binds = PositionalBinding;
bindValue(d->bindCount, val, paramType);
++d->bindCount;
@@ -709,6 +743,7 @@ void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType)
*/
QVariant QSqlResult::boundValue(int index) const
{
+ Q_D(const QSqlResult);
return d->values.value(index);
}
@@ -722,6 +757,7 @@ QVariant QSqlResult::boundValue(int index) const
*/
QVariant QSqlResult::boundValue(const QString& placeholder) const
{
+ Q_D(const QSqlResult);
QList<int> indexes = d->indexes.value(placeholder);
return d->values.value(indexes.value(0,-1));
}
@@ -733,6 +769,7 @@ QVariant QSqlResult::boundValue(const QString& placeholder) const
*/
QSql::ParamType QSqlResult::bindValueType(int index) const
{
+ Q_D(const QSqlResult);
return d->types.value(index, QSql::In);
}
@@ -744,6 +781,7 @@ QSql::ParamType QSqlResult::bindValueType(int index) const
*/
QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const
{
+ Q_D(const QSqlResult);
return d->types.value(d->indexes.value(placeholder).value(0,-1), QSql::In);
}
@@ -754,6 +792,7 @@ QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const
*/
int QSqlResult::boundValueCount() const
{
+ Q_D(const QSqlResult);
return d->values.count();
}
@@ -765,7 +804,8 @@ int QSqlResult::boundValueCount() const
*/
QVector<QVariant>& QSqlResult::boundValues() const
{
- return d->values;
+ Q_D(const QSqlResult);
+ return const_cast<QSqlResultPrivate *>(d)->values;
}
/*!
@@ -773,6 +813,7 @@ QVector<QVariant>& QSqlResult::boundValues() const
*/
QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const
{
+ Q_D(const QSqlResult);
return d->binds;
}
@@ -782,6 +823,7 @@ QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const
*/
void QSqlResult::clear()
{
+ Q_D(QSqlResult);
d->clear();
}
@@ -795,11 +837,13 @@ void QSqlResult::clear()
*/
QString QSqlResult::executedQuery() const
{
+ Q_D(const QSqlResult);
return d->executedQuery;
}
void QSqlResult::resetBindCount()
{
+ Q_D(QSqlResult);
d->resetBindCount();
}
@@ -811,6 +855,7 @@ void QSqlResult::resetBindCount()
*/
QString QSqlResult::boundValueName(int index) const
{
+ Q_D(const QSqlResult);
return d->holderAt(index);
}
@@ -822,6 +867,7 @@ QString QSqlResult::boundValueName(int index) const
*/
bool QSqlResult::hasOutValues() const
{
+ Q_D(const QSqlResult);
if (d->types.isEmpty())
return false;
QHash<int, QSql::ParamType>::ConstIterator it;
@@ -901,6 +947,7 @@ void QSqlResult::virtual_hook(int, void *)
bool QSqlResult::execBatch(bool arrayBind)
{
Q_UNUSED(arrayBind);
+ Q_D(QSqlResult);
QVector<QVariant> values = d->values;
if (values.count() == 0)
@@ -924,6 +971,7 @@ void QSqlResult::detachFromResultSet()
*/
void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy)
{
+ Q_D(QSqlResult);
d->precisionPolicy = policy;
}
@@ -931,6 +979,7 @@ void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy poli
*/
QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy() const
{
+ Q_D(const QSqlResult);
return d->precisionPolicy;
}
diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h
index 134b96e81d..05f3d7ffec 100644
--- a/src/sql/kernel/qsqlresult.h
+++ b/src/sql/kernel/qsqlresult.h
@@ -46,8 +46,6 @@
#include <QtCore/qvector.h>
#include <QtSql/qsql.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -61,9 +59,9 @@ class QSqlResultPrivate;
class Q_SQL_EXPORT QSqlResult
{
+ Q_DECLARE_PRIVATE(QSqlResult)
friend class QSqlQuery;
friend class QSqlTableModelPrivate;
- friend class QSqlResultPrivate;
public:
virtual ~QSqlResult();
@@ -76,6 +74,7 @@ protected:
};
explicit QSqlResult(const QSqlDriver * db);
+ QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db);
int at() const;
QString lastQuery() const;
QSqlError lastError() const;
@@ -134,8 +133,7 @@ protected:
virtual bool nextResult();
void resetBindCount(); // HACK
-private:
- QSqlResultPrivate* d;
+ QSqlResultPrivate *d_ptr;
private:
Q_DISABLE_COPY(QSqlResult)
@@ -143,6 +141,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLRESULT_H
diff --git a/src/sql/kernel/qsqlresult_p.h b/src/sql/kernel/qsqlresult_p.h
index 246b914ec7..46ee6ce195 100644
--- a/src/sql/kernel/qsqlresult_p.h
+++ b/src/sql/kernel/qsqlresult_p.h
@@ -70,9 +70,10 @@ struct QHolder {
class Q_SQL_EXPORT QSqlResultPrivate
{
+
public:
- QSqlResultPrivate(QSqlResult *d)
- : q(d),
+ QSqlResultPrivate()
+ : q_ptr(0),
idx(QSql::BeforeFirstRow),
active(false),
isSel(false),
@@ -81,6 +82,7 @@ public:
bindCount(0),
binds(QSqlResult::PositionalBinding)
{ }
+ virtual ~QSqlResultPrivate() { }
void clearValues()
{
@@ -116,7 +118,7 @@ public:
QString namedToPositionalBinding(const QString &query);
QString holderAt(int index) const;
- QSqlResult *q;
+ QSqlResult *q_ptr;
QPointer<QSqlDriver> sqldriver;
int idx;
QString sql;
diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h
index 25e0a68f9d..c00d905ec0 100644
--- a/src/sql/models/qsqlquerymodel.h
+++ b/src/sql/models/qsqlquerymodel.h
@@ -45,8 +45,6 @@
#include <QtCore/qabstractitemmodel.h>
#include <QtSql/qsqldatabase.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -113,6 +111,4 @@ protected:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLQUERYMODEL_H
diff --git a/src/sql/models/qsqlquerymodel_p.h b/src/sql/models/qsqlquerymodel_p.h
index a79b62cda1..9d7b71faec 100644
--- a/src/sql/models/qsqlquerymodel_p.h
+++ b/src/sql/models/qsqlquerymodel_p.h
@@ -69,7 +69,7 @@ class QSqlQueryModelPrivate: public QAbstractItemModelPrivate
public:
QSqlQueryModelPrivate() : atEnd(false), nestedResetLevel(0) {}
~QSqlQueryModelPrivate();
-
+
void prefetch(int);
void initColOffsets(int size);
int columnInQuery(int modelColumn) const;
diff --git a/src/sql/models/qsqlrelationaldelegate.h b/src/sql/models/qsqlrelationaldelegate.h
index 8cecc02821..b878280bca 100644
--- a/src/sql/models/qsqlrelationaldelegate.h
+++ b/src/sql/models/qsqlrelationaldelegate.h
@@ -49,8 +49,6 @@
#include <QtWidgets/qcombobox.h>
#include <QtSql/qsqlrelationaltablemodel.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -110,8 +108,6 @@ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_WIDGETS_LIB
#endif // QSQLRELATIONALDELEGATE_H
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index 7cc7de2347..fb45468d2e 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -241,7 +241,7 @@ bool QRelation::isValid()
-QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) :
+QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) :
QSqlTableModel(parent, db), firstSelect(true), relation(rel)
{
}
diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h
index 29acb88137..0ccfecd1c7 100644
--- a/src/sql/models/qsqlrelationaltablemodel.h
+++ b/src/sql/models/qsqlrelationaltablemodel.h
@@ -44,8 +44,6 @@
#include <QtSql/qsqltablemodel.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -112,6 +110,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLRELATIONALTABLEMODEL_H
diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h
index efb9663a1c..7a9ffebe8f 100644
--- a/src/sql/models/qsqltablemodel.h
+++ b/src/sql/models/qsqltablemodel.h
@@ -45,8 +45,6 @@
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquerymodel.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -140,6 +138,4 @@ protected:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSQLTABLEMODEL_H