summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/odbc
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2010-02-10 00:50:59 (GMT)
committerBill King <bill.king@nokia.com>2010-02-10 00:50:59 (GMT)
commit4935ec52fc07d4aaa7ae594cfe9986e25ca62dcb (patch)
treec18beeadf18cb1f5dce7a69854631029e72a7fe1 /src/sql/drivers/odbc
parentefbef9186785dcc522b41978b391411aa272b0c7 (diff)
downloadQt-4935ec52fc07d4aaa7ae594cfe9986e25ca62dcb.zip
Qt-4935ec52fc07d4aaa7ae594cfe9986e25ca62dcb.tar.gz
Qt-4935ec52fc07d4aaa7ae594cfe9986e25ca62dcb.tar.bz2
(ODBC) Use wchar_t instead of assuming 2 bytes.
On some platforms, especially iODBC, wchar_t is a 32bit value, not 16 Task-number: QTBUG-6928
Diffstat (limited to 'src/sql/drivers/odbc')
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index 2049a76..4d3663e 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -144,6 +144,7 @@ public:
QSqlRecord rInf;
QVector<QVariant> fieldCache;
+ QVector<wchar_t *> paramCache;
int fieldCacheIdx;
int disconnectCount;
bool hasSQLFetchScroll;
@@ -202,7 +203,7 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode
*nativeCode = nativeCode_;
QString tmpstore;
#ifdef UNICODE
- tmpstore = QString((const QChar*)description_.data(), msgLen);
+ tmpstore = QString::fromWCharArray((const wchar_t*)description_, msgLen);
#else
tmpstore = QString::fromLocal8Bit((const char*)description_.data(), msgLen);
#endif
@@ -332,7 +333,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
} else {
colSize++; // make sure there is room for more than the 0 termination
if (unicode) {
- colSize *= 2; // a tiny bit faster, since it saves a SQLGetData() call
+ colSize *= sizeof(wchar_t); // a tiny bit faster, since it saves a SQLGetData() call
}
}
QVarLengthArray<char> buf(colSize);
@@ -353,9 +354,9 @@ 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) ? (unicode ? colSize-2 : colSize-1) : lengthIndicator;
+ int rSize = (r == SQL_SUCCESS_WITH_INFO) ? (unicode ? colSize-sizeof(wchar_t) : colSize-1) : lengthIndicator;
if (unicode) {
- fieldVal += QString((const QChar*) buf.constData(), rSize / 2);
+ fieldVal += QString::fromWCharArray((wchar_t*)buf.constData(), rSize / sizeof(wchar_t));
} else {
fieldVal += QString::fromAscii(buf.constData(), rSize);
}
@@ -551,7 +552,7 @@ static QSqlField qMakeFieldInfo(const QODBCPrivate* p, int i )
}
#ifdef UNICODE
- QString qColName((const QChar*)colName, colNameLen);
+ QString qColName = QString::fromWCharArray((const wchar_t*)colName, colNameLen);
#else
QString qColName = QString::fromLocal8Bit((const char*)colName);
#endif
@@ -1270,9 +1271,12 @@ bool QODBCResult::exec()
// bind parameters - only positional binding allowed
QVector<QVariant>& values = boundValues();
+ QVector<wchar_t *> wcharstorage;
+
int i;
SQLRETURN r;
for (i = 0; i < values.count(); ++i) {
+ wcharstorage.append(NULL);
if (bindValueType(i) & QSql::Out)
values[i].detach();
const QVariant &val = values.at(i);
@@ -1435,13 +1439,14 @@ bool QODBCResult::exec()
#ifndef Q_ODBC_VERSION_2
if (d->unicode) {
QString str = val.toString();
- str.utf16();
+ int strSize = str.length() * sizeof(wchar_t);
if (*ind != SQL_NULL_DATA)
- *ind = str.length() * sizeof(QChar);
- int strSize = str.length() * sizeof(QChar);
+ *ind = strSize;
if (bindValueType(i) & QSql::Out) {
- QByteArray ba((char*)str.constData(), str.capacity() * sizeof(QChar));
+ wchar_t *temp=new wchar_t[str.capacity()*sizeof(wchar_t)];
+ str.toWCharArray(temp);
+ QByteArray ba((char*)temp, str.capacity() * sizeof(wchar_t));
r = SQLBindParameter(d->hStmt,
i + 1,
qParamType[(QFlag)(bindValueType(i)) & QSql::InOut],
@@ -1453,9 +1458,13 @@ bool QODBCResult::exec()
ba.size(),
ind);
tmpStorage.append(ba);
+ wcharstorage.replace(i,temp);
break;
}
+ wchar_t *temp=new wchar_t[(1+str.length())*sizeof(wchar_t)];
+ str.toWCharArray(temp);
+ temp[str.length()]=0;
r = SQLBindParameter(d->hStmt,
i + 1,
qParamType[(QFlag)(bindValueType(i)) & QSql::InOut],
@@ -1463,9 +1472,10 @@ bool QODBCResult::exec()
strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR,
strSize,
0,
- (void *)str.constData(),
+ (void *)temp,
strSize,
ind);
+ wcharstorage.replace(i,temp);
break;
}
else
@@ -1515,6 +1525,13 @@ bool QODBCResult::exec()
}
}
r = SQLExecute(d->hStmt);
+
+ for(int i=0;i<wcharstorage.size();i++)
+ {
+ if(wcharstorage.at(i))
+ delete [](wcharstorage.at(i));
+ }
+
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
qWarning() << "QODBCResult::exec: Unable to execute statement:" << qODBCWarn(d);
setLastError(qMakeError(QCoreApplication::translate("QODBCResult",