QTBUG-18435 fix stored procedure output parameters on ODBC
[profile/ivi/qtbase.git] / src / sql / drivers / odbc / qsql_odbc.cpp
index 40cd2e6..9b1b7fa 100644 (file)
@@ -573,6 +573,11 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, const QODBCDriverPrivate*
     QString fname = qGetStringData(hStmt, 3, -1, p->unicode);
     int type = qGetIntData(hStmt, 4).toInt(); // column type
     QSqlField f(fname, qDecodeODBCType(type, p));
+    QVariant var = qGetIntData(hStmt, 6);
+    f.setLength(var.isNull() ? -1 : var.toInt()); // column size
+    var = qGetIntData(hStmt, 8).toInt();
+    f.setPrecision(var.isNull() ? -1 : var.toInt()); // precision
+    f.setSqlType(type);
     int required = qGetIntData(hStmt, 10).toInt(); // nullable-flag
     // required can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
     if (required == SQL_NO_NULLS)
@@ -580,11 +585,6 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, const QODBCDriverPrivate*
     else if (required == SQL_NULLABLE)
         f.setRequired(false);
     // else we don't know
-    QVariant var = qGetIntData(hStmt, 6);
-    f.setLength(var.isNull() ? -1 : var.toInt()); // column size
-    var = qGetIntData(hStmt, 8).toInt();
-    f.setPrecision(var.isNull() ? -1 : var.toInt()); // precision
-    f.setSqlType(type);
     return f;
 }
 
@@ -1502,8 +1502,9 @@ bool QODBCResult::exec()
                     int strSize = str.length() * sizeof(SQLTCHAR);
 
                     if (bindValueType(i) & QSql::Out) {
-                        QVarLengthArray<SQLTCHAR> ba(toSQLTCHAR(str));
-                        ba.reserve(str.capacity());
+                        QVarLengthArray<SQLTCHAR> a(toSQLTCHAR(str));
+                        a.reserve(str.capacity());
+                        QByteArray ba((const char *)a.constData(), a.size() * sizeof(SQLTCHAR));
                         r = SQLBindParameter(d->hStmt,
                                             i + 1,
                                             qParamType[(QFlag)(bindValueType(i)) & QSql::InOut],
@@ -1511,10 +1512,10 @@ bool QODBCResult::exec()
                                             strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR,
                                             0, // god knows... don't change this!
                                             0,
-                                            (void *)ba.constData(),
+                                            (void *)ba.data(),
                                             ba.size(),
                                             ind);
-                        tmpStorage.append(QByteArray((const char *)ba.constData(), ba.size()*sizeof(SQLTCHAR)));
+                        tmpStorage.append(ba);
                         break;
                     }
                     QByteArray strba((const char *)toSQLTCHAR(str).constData(), str.size()*sizeof(SQLTCHAR));
@@ -1638,7 +1639,7 @@ bool QODBCResult::exec()
                         QByteArray first = tmpStorage.takeFirst();
                         QVarLengthArray<SQLTCHAR> array;
                         array.append((SQLTCHAR *)first.constData(), first.size());
-                        values[i] = fromSQLTCHAR(array, first.size()/sizeof(SQLTCHAR*));
+                        values[i] = fromSQLTCHAR(array, first.size()/sizeof(SQLTCHAR));
                     }
                     break;
                 }
@@ -2540,7 +2541,7 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType)
     return res;
 }
 
-bool QODBCDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType) const
+bool QODBCDriver::isIdentifierEscaped(const QString &identifier, IdentifierType) const
 {
     QChar quote = d->quoteChar();
     return identifier.size() > 2