summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel/qsqldatabase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql/kernel/qsqldatabase.cpp')
-rw-r--r--src/sql/kernel/qsqldatabase.cpp73
1 files changed, 63 insertions, 10 deletions
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index 1a786ed..1fb06a2 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -1,7 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtSql module of the Qt Toolkit.
@@ -21,9 +20,10 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
@@ -129,11 +129,16 @@ Q_GLOBAL_STATIC(QConnectionDict, dbDict)
class QSqlDatabasePrivate
{
public:
- QSqlDatabasePrivate(QSqlDriver *dr = 0):
+ QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = 0):
+ q(d),
driver(dr),
port(-1)
{
ref = 1;
+ if(driver)
+ precisionPolicy = driver->numericalPrecisionPolicy();
+ else
+ precisionPolicy= QSql::LowPrecisionDouble;
}
QSqlDatabasePrivate(const QSqlDatabasePrivate &other);
~QSqlDatabasePrivate();
@@ -142,6 +147,7 @@ public:
void disable();
QAtomicInt ref;
+ QSqlDatabase *q;
QSqlDriver* driver;
QString dbname;
QString uname;
@@ -151,6 +157,7 @@ public:
int port;
QString connOptions;
QString connName;
+ QSql::NumericalPrecisionPolicy precisionPolicy;
static QSqlDatabasePrivate *shared_null();
static QSqlDatabase database(const QString& name, bool open);
@@ -164,6 +171,7 @@ public:
QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other)
{
ref = 1;
+ q = other.q;
dbname = other.dbname;
uname = other.uname;
pword = other.pword;
@@ -172,6 +180,7 @@ QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other)
port = other.port;
connOptions = other.connOptions;
driver = other.driver;
+ precisionPolicy = other.precisionPolicy;
}
QSqlDatabasePrivate::~QSqlDatabasePrivate()
@@ -216,7 +225,7 @@ DriverDict &QSqlDatabasePrivate::driverDict()
QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null()
{
static QSqlNullDriver dr;
- static QSqlDatabasePrivate n(&dr);
+ static QSqlDatabasePrivate n(NULL, &dr);
return &n;
}
@@ -281,6 +290,7 @@ QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)
*/
void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other)
{
+ q = other->q;
dbname = other->dbname;
uname = other->uname;
pword = other->pword;
@@ -288,6 +298,7 @@ void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other)
drvName = other->drvName;
port = other->port;
connOptions = other->connOptions;
+ precisionPolicy = other->precisionPolicy;
}
void QSqlDatabasePrivate::disable()
@@ -352,7 +363,7 @@ void QSqlDatabasePrivate::disable()
a database.
\ingroup database
- \mainclass
+
\inmodule QtSql
The QSqlDatabase class provides an interface for accessing a
@@ -658,7 +669,7 @@ QStringList QSqlDatabase::connectionNames()
QSqlDatabase::QSqlDatabase(const QString &type)
{
- d = new QSqlDatabasePrivate();
+ d = new QSqlDatabasePrivate(this);
d->init(type);
}
@@ -670,7 +681,7 @@ QSqlDatabase::QSqlDatabase(const QString &type)
QSqlDatabase::QSqlDatabase(QSqlDriver *driver)
{
- d = new QSqlDatabasePrivate(driver);
+ d = new QSqlDatabasePrivate(this, driver);
}
/*!
@@ -949,7 +960,7 @@ bool QSqlDatabase::rollback()
connection, set the database name, and call open() again. \note
The \e{database name} is not the \e{connection name}. The
connection name must be passed to addDatabase() at connection
- object create time.
+ object create time.
For the QOCI (Oracle) driver, the database name is the TNS
Service Name.
@@ -1252,6 +1263,7 @@ QSqlRecord QSqlDatabase::record(const QString& tablename) const
\i
\list
\i QSQLITE_BUSY_TIMEOUT
+ \i QSQLITE_OPEN_READONLY
\endlist
\i
@@ -1469,6 +1481,47 @@ QString QSqlDatabase::connectionName() const
return d->connName;
}
+/*!
+ \since 4.6
+
+ Sets the default numerical precision policy used by queries created
+ on this database connection to \a precisionPolicy.
+
+ Note: Drivers that don't support fetching numerical values with low
+ precision will ignore the precision policy. You can use
+ QSqlDriver::hasFeature() to find out whether a driver supports this
+ feature.
+
+ Note: Setting the default precision policy to \a precisionPolicy
+ doesn't affect any currently active queries.
+
+ \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(),
+ QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy()
+*/
+void QSqlDatabase::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
+{
+ if(driver())
+ driver()->setNumericalPrecisionPolicy(precisionPolicy);
+ d->precisionPolicy = precisionPolicy;
+}
+
+/*!
+ \since 4.6
+
+ Returns the current default precision policy for the database connection.
+
+ \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(),
+ QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy()
+*/
+QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy() const
+{
+ if(driver())
+ return driver()->numericalPrecisionPolicy();
+ else
+ return d->precisionPolicy;
+}
+
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSqlDatabase &d)
{