--- qsql_odbc.cpp.orig	2009-12-21 10:31:11.003133436 +0100
+++ qsql_odbc.cpp	2009-12-21 17:28:30.733340172 +0100
@@ -144,6 +144,7 @@
 
     QSqlRecord rInf;
     QVector<QVariant> fieldCache;
+    QVector<wchar_t *> paramCache;
     int fieldCacheIdx;
     int disconnectCount;
     bool hasSQLFetchScroll;
@@ -190,7 +191,7 @@
                 *nativeCode = nativeCode_;
             QString tmpstore;
 #ifdef UNICODE
-            tmpstore = QString((const QChar*)description_, msgLen);
+            tmpstore = QString::fromWCharArray((const wchar_t*)description_, msgLen);
 #else
             tmpstore = QString::fromLocal8Bit((const char*)description_, msgLen);
 #endif
@@ -321,10 +322,11 @@
     } 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
         }
     }
-    char* buf = new char[colSize];
+
+    char *buf = (char *)malloc(colSize+65536);
     while (true) {
         r = SQLGetData(hStmt,
                         column+1,
@@ -342,9 +344,9 @@
             // 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((QChar*) buf, rSize / 2);
+                fieldVal += QString::fromWCharArray((wchar_t*) buf, rSize / sizeof(wchar_t));
             } else {
                 fieldVal += QString::fromAscii(buf, rSize);
             }
@@ -360,7 +362,7 @@
             break;
         }
     }
-    delete[] buf;
+    free(buf);
     return fieldVal;
 }
 
@@ -520,7 +522,7 @@
     }
 
 #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
@@ -1174,9 +1176,12 @@
 
     // 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);
@@ -1339,13 +1344,15 @@
 #ifndef Q_ODBC_VERSION_2
                 if (d->unicode) {
                     QString str = val.toString();
-                    str.utf16();
+                    //str.utf16();
                     if (*ind != SQL_NULL_DATA)
-                        *ind = str.length() * sizeof(QChar);
-                    int strSize = str.length() * sizeof(QChar);
+                        *ind = str.length() * sizeof(wchar_t);
+                    int strSize = str.length() * sizeof(wchar_t);
 
                     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],
@@ -1357,9 +1364,13 @@
                                             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],
@@ -1367,9 +1378,10 @@
                                           strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR,
                                           strSize,
                                           0,
-                                          (void *)str.constData(),
+                                          (void *)temp,
                                           strSize,
                                           ind);
+                    wcharstorage.replace(i,temp);
                     break;
                 }
                 else
@@ -1419,6 +1431,13 @@
         }
     }
     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",
@@ -1782,6 +1801,8 @@
     SQLUINTEGER fFunc;
 
     unicode = false;
+//    sql_char_type = QVariant::String;
+//    return;
     r = SQLGetInfo(hDbc,
                     SQL_CONVERT_CHAR,
                     (SQLPOINTER)&fFunc,
