src/sql/drivers/sqlite2/qsql_sqlite2.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 0 1918ee327afb
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtSql module of the Qt Toolkit.
     7 ** This file is part of the QtSql module of the Qt Toolkit.
     8 **
     8 **
   108     // and we have too keep our own struct for the data (sqlite works via
   108     // and we have too keep our own struct for the data (sqlite works via
   109     // callback.
   109     // callback.
   110     const char *currentTail;
   110     const char *currentTail;
   111     sqlite_vm *currentMachine;
   111     sqlite_vm *currentMachine;
   112 
   112 
   113     uint skippedStatus: 1; // the status of the fetchNext() that's skipped
   113     bool skippedStatus; // the status of the fetchNext() that's skipped
   114     uint skipRow: 1; // skip the next fetchNext()?
   114     bool skipRow; // skip the next fetchNext()?
   115     uint utf8: 1;
   115     bool utf8;
   116     QSqlRecord rInf;
   116     QSqlRecord rInf;
       
   117     QVector<QVariant> firstRow;
   117 };
   118 };
   118 
   119 
   119 static const uint initial_cache_size = 128;
   120 static const uint initial_cache_size = 128;
   120 
   121 
   121 QSQLite2ResultPrivate::QSQLite2ResultPrivate(QSQLite2Result* res) : q(res), access(0), currentTail(0),
   122 QSQLite2ResultPrivate::QSQLite2ResultPrivate(QSQLite2Result* res) : q(res), access(0), currentTail(0),
   190 
   191 
   191     if (skipRow) {
   192     if (skipRow) {
   192         // already fetched
   193         // already fetched
   193         Q_ASSERT(!initialFetch);
   194         Q_ASSERT(!initialFetch);
   194         skipRow = false;
   195         skipRow = false;
       
   196         for(int i=0;i<firstRow.count(); i++)
       
   197             values[i] = firstRow[i];
   195         return skippedStatus;
   198         return skippedStatus;
   196     }
   199     }
   197     skipRow = initialFetch;
   200     skipRow = initialFetch;
   198 
   201 
   199     if (!currentMachine)
   202     if (!currentMachine)
   207 #else
   210 #else
   208         sleep(1);
   211         sleep(1);
   209 #endif
   212 #endif
   210     }
   213     }
   211 
   214 
       
   215     if(initialFetch) {
       
   216         firstRow.clear();
       
   217         firstRow.resize(colNum);
       
   218     }
       
   219     
   212     switch(res) {
   220     switch(res) {
   213     case SQLITE_ROW:
   221     case SQLITE_ROW:
   214         // check to see if should fill out columns
   222         // check to see if should fill out columns
   215         if (rInf.isEmpty())
   223         if (rInf.isEmpty())
   216             // must be first call.
   224             // must be first call.
   297         setActive(false);
   305         setActive(false);
   298         return false;
   306         return false;
   299     }
   307     }
   300     // we have to fetch one row to find out about
   308     // we have to fetch one row to find out about
   301     // the structure of the result set
   309     // the structure of the result set
   302     d->skippedStatus = d->fetchNext(cache(), 0, true);
   310     d->skippedStatus = d->fetchNext(d->firstRow, 0, true);
   303     if (lastError().isValid()) {
   311     if (lastError().isValid()) {
   304         setSelect(false);
   312         setSelect(false);
   305         setActive(false);
   313         setActive(false);
   306         return false;
   314         return false;
   307     }
   315     }