summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-21 05:20:03 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-21 05:20:03 (GMT)
commit8079a0c5b4ee6550501476410fab457d63c705b6 (patch)
tree6d7bb6335ebe494546296911b1ff1239335212b9 /src/sql/drivers
parent5a3db7268eb9203e91fc09e5db6d8690274464d7 (diff)
parent6ca14dce65634e202b36499c76c268c87f78ceb6 (diff)
downloadQt-8079a0c5b4ee6550501476410fab457d63c705b6.zip
Qt-8079a0c5b4ee6550501476410fab457d63c705b6.tar.gz
Qt-8079a0c5b4ee6550501476410fab457d63c705b6.tar.bz2
Merge commit 'qt/master' into graphicseffects
Conflicts: src/gui/graphicsview/graphicsview.pri src/gui/graphicsview/qgraphicsitem_p.h src/gui/graphicsview/qgraphicsscene.cpp src/gui/graphicsview/qgraphicsscene.h src/gui/graphicsview/qgraphicsview.cpp
Diffstat (limited to 'src/sql/drivers')
-rw-r--r--src/sql/drivers/db2/qsql_db2.cpp32
-rw-r--r--src/sql/drivers/oci/qsql_oci.cpp9
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp34
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp49
-rw-r--r--src/sql/drivers/sqlite2/qsql_sqlite2.cpp4
5 files changed, 70 insertions, 58 deletions
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp
index 1a82377..474c53d 100644
--- a/src/sql/drivers/db2/qsql_db2.cpp
+++ b/src/sql/drivers/db2/qsql_db2.cpp
@@ -51,10 +51,6 @@
#include <qvector.h>
#include <QDebug>
-#ifndef UNICODE
-#define UNICODE
-#endif
-
#if defined(Q_CC_BOR)
// DB2's sqlsystm.h (included through sqlcli1.h) defines the SQL_BIGINT_TYPE
// and SQL_BIGUINT_TYPE to wrong the types for Borland; so do the defines to
@@ -63,6 +59,8 @@
#define SQL_BIGUINT_TYPE quint64
#endif
+#define UNICODE
+
#include <sqlcli1.h>
#include <string.h>
@@ -111,22 +109,14 @@ public:
static QString qFromTChar(SQLTCHAR* str)
{
-#ifdef UNICODE
return QString::fromUtf16(str);
-#else
- return QString::fromLocal8Bit((const char*) str);
-#endif
}
// dangerous!! (but fast). Don't use in functions that
// require out parameters!
static SQLTCHAR* qToTChar(const QString& str)
{
-#ifdef UNICODE
return (SQLTCHAR*)str.utf16();
-#else
- return (unsigned char*) str.ascii();
-#endif
}
static QString qWarnDB2Handle(int handleType, SQLHANDLE handle)
@@ -347,12 +337,8 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool& is
while (true) {
r = SQLGetData(hStmt,
- column+1,
-#ifdef UNICODE
+ column + 1,
SQL_C_WCHAR,
-#else
- SQL_C_CHAR,
-#endif
(SQLPOINTER)buf,
colSize * sizeof(SQLTCHAR),
&lengthIndicator);
@@ -740,7 +726,6 @@ bool QDB2Result::exec()
ind);
break; }
case QVariant::String:
-#ifdef UNICODE
{
QString str(values.at(i).toString());
if (*ind != SQL_NULL_DATA)
@@ -774,8 +759,6 @@ bool QDB2Result::exec()
}
break;
}
-#endif
- // fall through
default: {
QByteArray ba = values.at(i).toString().toAscii();
int len = ba.length() + 1;
@@ -849,12 +832,9 @@ bool QDB2Result::exec()
case QVariant::ByteArray:
break;
case QVariant::String:
-#ifdef UNICODE
if (bindValueType(i) & QSql::Out)
values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData());
break;
-#endif
- // fall through
default: {
values[i] = QString::fromAscii(tmpStorage.takeFirst().constData());
break; }
@@ -1542,13 +1522,7 @@ bool QDB2Driver::hasFeature(DriverFeature f) const
case FinishQuery:
return true;
case Unicode:
- // this is the query that shows the codepage for the types:
- // select typename, codepage from syscat.datatypes
-#ifdef UNICODE
return true;
-#else
- return false;
-#endif
}
return false;
}
diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp
index d5fb10f..617f116 100644
--- a/src/sql/drivers/oci/qsql_oci.cpp
+++ b/src/sql/drivers/oci/qsql_oci.cpp
@@ -609,7 +609,7 @@ static QSqlField qFromOraInf(const OraFieldInfo &ofi)
QSqlField f(ofi.name, ofi.type);
f.setRequired(ofi.oraIsNull == 0);
- if (ofi.type == QVariant::String)
+ if (ofi.type == QVariant::String && ofi.oraType != SQLT_NUM && ofi.oraType != SQLT_VNU)
f.setLength(ofi.oraFieldLength);
else
f.setLength(ofi.oraPrecision == 0 ? 38 : int(ofi.oraPrecision));
@@ -1586,9 +1586,12 @@ void QOCICols::getValues(QVector<QVariant> &v, int index)
} else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt64)
&& (fld.typ == QVariant::LongLong)) {
qint64 qll = 0;
- OCINumberToInt(d->err, reinterpret_cast<OCINumber *>(fld.data), sizeof(qint64),
+ int r = OCINumberToInt(d->err, reinterpret_cast<OCINumber *>(fld.data), sizeof(qint64),
OCI_NUMBER_SIGNED, &qll);
- v[index + i] = qll;
+ if(r == OCI_SUCCESS)
+ v[index + i] = qll;
+ else
+ v[index + i] = QVariant();
break;
} else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt32)
&& (fld.typ == QVariant::Int)) {
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index 6ceee82..2df0073 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -89,7 +89,8 @@ public:
enum DefaultCase{Lower, Mixed, Upper, Sensitive};
QODBCDriverPrivate()
: hEnv(0), hDbc(0), useSchema(false), disconnectCount(0), isMySqlServer(false),
- isMSSqlServer(false), hasSQLFetchScroll(true), hasMultiResultSets(false)
+ isMSSqlServer(false), hasSQLFetchScroll(true), hasMultiResultSets(false),
+ isQuoteInitialized(false), quote(QLatin1Char('"'))
{
unicode = false;
}
@@ -116,7 +117,10 @@ public:
QString &schema, QString &table);
DefaultCase defaultCase() const;
QString adjustCase(const QString&) const;
- QChar quoteChar() const;
+ QChar quoteChar();
+private:
+ bool isQuoteInitialized;
+ QChar quote;
};
class QODBCPrivate
@@ -255,9 +259,11 @@ static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, const T* p, bool isSi
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_BIT:
- case SQL_TINYINT:
type = isSigned ? QVariant::Int : QVariant::UInt;
break;
+ case SQL_TINYINT:
+ type = QVariant::UInt;
+ break;
case SQL_BIGINT:
type = isSigned ? QVariant::LongLong : QVariant::ULongLong;
break;
@@ -564,10 +570,8 @@ static int qGetODBCVersion(const QString &connOpts)
return SQL_OV_ODBC2;
}
-QChar QODBCDriverPrivate::quoteChar() const
+QChar QODBCDriverPrivate::quoteChar()
{
- static bool isQuoteInitialized = false;
- static QChar quote = QChar::fromLatin1('"');
if (!isQuoteInitialized) {
char driverResponse[4];
SQLSMALLINT length;
@@ -577,9 +581,9 @@ QChar QODBCDriverPrivate::quoteChar() const
sizeof(driverResponse),
&length);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
- quote = QChar::fromLatin1(driverResponse[0]);
+ quote = QLatin1Char(driverResponse[0]);
} else {
- quote = QChar::fromLatin1('"');
+ quote = QLatin1Char('"');
}
isQuoteInitialized = true;
}
@@ -1111,7 +1115,7 @@ QVariant QODBCResult::data(int field)
d->fieldCache[i] = qGetBinaryData(d->hStmt, i);
break;
case QVariant::String:
- d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), true);
+ d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), d->unicode);
break;
case QVariant::Double:
switch(numericalPrecisionPolicy()) {
@@ -1536,6 +1540,7 @@ bool QODBCResult::exec()
values[i] = QVariant(QDateTime(QDate(dt.year, dt.month, dt.day),
QTime(dt.hour, dt.minute, dt.second, dt.fraction / 1000000)));
break; }
+ case QVariant::Bool:
case QVariant::Int:
case QVariant::UInt:
case QVariant::Double:
@@ -1778,7 +1783,7 @@ bool QODBCDriver::open(const QString & db,
if (!d->checkDriver()) {
setLastError(qMakeError(tr("Unable to connect - Driver doesn't support all "
- "needed functionality"), QSqlError::ConnectionError, d));
+ "functionality required"), QSqlError::ConnectionError, d));
setOpenError(true);
return false;
}
@@ -1842,14 +1847,7 @@ void QODBCDriverPrivate::checkUnicode()
unicode = false;
return;
#endif
-#if defined(Q_WS_WIN)
- QT_WA(
- {},
- {
- unicode = false;
- return;
- })
-#endif
+
SQLRETURN r;
SQLUINTEGER fFunc;
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 0c92013..c61c526 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -54,11 +54,33 @@
#include <qstringlist.h>
#include <qmutex.h>
+
#include <libpq-fe.h>
#include <pg_config.h>
#include <stdlib.h>
#include <math.h>
+// below code taken from an example at http://www.gnu.org/software/hello/manual/autoconf/Function-Portability.html
+#ifndef isnan
+ # define isnan(x) \
+ (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
+ : sizeof (x) == sizeof (double) ? isnan_d (x) \
+ : isnan_f (x))
+ static inline int isnan_f (float x) { return x != x; }
+ static inline int isnan_d (double x) { return x != x; }
+ static inline int isnan_ld (long double x) { return x != x; }
+#endif
+
+#ifndef isinf
+ # define isinf(x) \
+ (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
+ : sizeof (x) == sizeof (double) ? isinf_d (x) \
+ : isinf_f (x))
+ static inline int isinf_f (float x) { return isnan (x - x); }
+ static inline int isinf_d (double x) { return isnan (x - x); }
+ static inline int isinf_ld (long double x) { return isnan (x - x); }
+#endif
+
// workaround for postgres defining their OIDs in a private header file
#define QBOOLOID 16
@@ -601,10 +623,9 @@ static QPSQLDriver::Protocol getPSQLVersion(PGconn* connection)
{
QPSQLDriver::Protocol serverVersion = QPSQLDriver::Version6;
PGresult* result = PQexec(connection, "select version()");
- int status = PQresultStatus(result);
+ int status = PQresultStatus(result);
if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) {
QString val = QString::fromAscii(PQgetvalue(result, 0, 0));
- PQclear(result);
QRegExp rx(QLatin1String("(\\d+)\\.(\\d+)"));
rx.setMinimal(true); // enforce non-greedy RegExp
if (rx.indexIn(val) != -1) {
@@ -645,6 +666,7 @@ static QPSQLDriver::Protocol getPSQLVersion(PGconn* connection)
}
}
}
+ PQclear(result);
if (serverVersion < QPSQLDriver::Version71)
qWarning("This version of PostgreSQL is not supported and may not work.");
@@ -1161,6 +1183,21 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
qPQfreemem(data);
break;
}
+ case QVariant::Double: {
+ double val = field.value().toDouble();
+ if (isnan(val))
+ r = QLatin1String("'NaN'");
+ else {
+ int res = isinf(val);
+ if (res == 1)
+ r = QLatin1String("'Infinity'");
+ else if (res == -1)
+ r = QLatin1String("'-Infinity'");
+ else
+ r = QSqlDriver::formatValue(field, trimStrings);
+ }
+ break;
+ }
default:
r = QSqlDriver::formatValue(field, trimStrings);
break;
@@ -1265,15 +1302,15 @@ QStringList QPSQLDriver::subscribedToNotificationsImplementation() const
void QPSQLDriver::_q_handleNotification(int)
{
PQconsumeInput(d->connection);
- PGnotify *notify = PQnotifies(d->connection);
- if (notify) {
- QString name(QLatin1String(notify->relname));
+ PGnotify *notify = 0;
+ while((notify = PQnotifies(d->connection)) != 0) {
+ QString name(QLatin1String(notify->relname));
if (d->seid.contains(name))
emit notification(name);
else
qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.",
- qPrintable(name));
+ qPrintable(name));
qPQfreemem(notify);
}
diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
index 1989c45..d30e82c 100644
--- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
+++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp
@@ -388,7 +388,7 @@ bool QSQLite2Driver::open(const QString & db, const QString &, const QString &,
char* err = 0;
d->access = sqlite_open(QFile::encodeName(db), 0, &err);
if (err) {
- setLastError(QSqlError(tr("Error to open database"), QString::fromAscii(err),
+ setLastError(QSqlError(tr("Error opening database"), QString::fromAscii(err),
QSqlError::ConnectionError));
sqlite_freemem(err);
err = 0;
@@ -463,7 +463,7 @@ bool QSQLite2Driver::rollbackTransaction()
if (res == SQLITE_OK)
return true;
- setLastError(QSqlError(tr("Unable to rollback Transaction"),
+ setLastError(QSqlError(tr("Unable to rollback transaction"),
QString::fromAscii(err), QSqlError::TransactionError, res));
sqlite_freemem(err);
return false;