src/sql/drivers/sqlite/qsql_sqlite.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   120     QSQLiteResult* q;
   120     QSQLiteResult* q;
   121     sqlite3 *access;
   121     sqlite3 *access;
   122 
   122 
   123     sqlite3_stmt *stmt;
   123     sqlite3_stmt *stmt;
   124 
   124 
   125     uint skippedStatus: 1; // the status of the fetchNext() that's skipped
   125     bool skippedStatus; // the status of the fetchNext() that's skipped
   126     uint skipRow: 1; // skip the next fetchNext()?
   126     bool skipRow; // skip the next fetchNext()?
   127     uint utf8: 1;
       
   128     QSqlRecord rInf;
   127     QSqlRecord rInf;
       
   128     QVector<QVariant> firstRow;
   129 };
   129 };
   130 
   130 
   131 QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult* res) : q(res), access(0),
   131 QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult* res) : q(res), access(0),
   132     stmt(0), skippedStatus(false), skipRow(false), utf8(false)
   132     stmt(0), skippedStatus(false), skipRow(false)
   133 {
   133 {
   134 }
   134 }
   135 
   135 
   136 void QSQLiteResultPrivate::cleanup()
   136 void QSQLiteResultPrivate::cleanup()
   137 {
   137 {
   187 
   187 
   188     if (skipRow) {
   188     if (skipRow) {
   189         // already fetched
   189         // already fetched
   190         Q_ASSERT(!initialFetch);
   190         Q_ASSERT(!initialFetch);
   191         skipRow = false;
   191         skipRow = false;
       
   192         for(int i=0;i<firstRow.count();i++)
       
   193             values[i]=firstRow[i];
   192         return skippedStatus;
   194         return skippedStatus;
   193     }
   195     }
   194     skipRow = initialFetch;
   196     skipRow = initialFetch;
       
   197 
       
   198     if(initialFetch) {
       
   199         firstRow.clear();
       
   200         firstRow.resize(sqlite3_column_count(stmt));
       
   201     }
   195 
   202 
   196     if (!stmt) {
   203     if (!stmt) {
   197         q->setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult", "Unable to fetch row"),
   204         q->setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult", "Unable to fetch row"),
   198                                   QCoreApplication::translate("QSQLiteResult", "No query"), QSqlError::ConnectionError));
   205                                   QCoreApplication::translate("QSQLiteResult", "No query"), QSqlError::ConnectionError));
   199         q->setAt(QSql::AfterLastRow);
   206         q->setAt(QSql::AfterLastRow);
   226                         break;
   233                         break;
   227                     case QSql::LowPrecisionInt64:
   234                     case QSql::LowPrecisionInt64:
   228                         values[i + idx] = sqlite3_column_int64(stmt, i);
   235                         values[i + idx] = sqlite3_column_int64(stmt, i);
   229                         break;
   236                         break;
   230                     case QSql::LowPrecisionDouble:
   237                     case QSql::LowPrecisionDouble:
   231                         values[i + idx] = sqlite3_column_double(stmt, i);
       
   232                         break;
       
   233                     case QSql::HighPrecision:
   238                     case QSql::HighPrecision:
   234                     default:
   239                     default:
   235                         values[i + idx] = QString::fromUtf16(static_cast<const ushort *>(
   240                         values[i + idx] = sqlite3_column_double(stmt, i);
   236                                             sqlite3_column_text16(stmt, i)),
       
   237                                             sqlite3_column_bytes16(stmt, i) / sizeof(ushort));
       
   238                         break;
   241                         break;
   239                 };
   242                 };
   240                 break;
   243                 break;
   241             case SQLITE_NULL:
   244             case SQLITE_NULL:
   242                 values[i + idx] = QVariant(QVariant::String);
   245                 values[i + idx] = QVariant(QVariant::String);
   401     } else {
   404     } else {
   402         setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult",
   405         setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult",
   403                         "Parameter count mismatch"), QString(), QSqlError::StatementError));
   406                         "Parameter count mismatch"), QString(), QSqlError::StatementError));
   404         return false;
   407         return false;
   405     }
   408     }
   406     d->skippedStatus = d->fetchNext(cache(), 0, true);
   409     d->skippedStatus = d->fetchNext(d->firstRow, 0, true);
   407     if (lastError().isValid()) {
   410     if (lastError().isValid()) {
   408         setSelect(false);
   411         setSelect(false);
   409         setActive(false);
   412         setActive(false);
   410         return false;
   413         return false;
   411     }
   414     }