System.Data.SQLite
Check-in [53b6595afd]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More bugfixes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 53b6595afd668bb975fb0a49781ab086e08d5291
User & Date: rmsimpson 2005-12-28 17:39:18
Context
2005-12-30
16:43
1.0.24.2 check-in: be65e0d94a user: rmsimpson tags: sourceforge
2005-12-28
17:39
More bugfixes check-in: 53b6595afd user: rmsimpson tags: sourceforge
2005-12-27
15:32
Implemented RecordsAffected property check-in: 673edbfb15 user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteDataReader.cs.

    75     75       /// <summary>
    76     76       /// Initializes and resets the datareader's member variables
    77     77       /// </summary>
    78     78       internal void Initialize()
    79     79       {
    80     80         _activeStatementIndex = -1;
    81     81         _activeStatement = null;
    82         -      _rowsAffected = 0;
           82  +      _rowsAffected = -1;
    83     83         _fieldCount = -1;
    84     84       }
    85     85   
    86     86       /// <summary>
    87     87       /// Closes the datareader, potentially closing the connection as well if CommandBehavior.CloseConnection was specified.
    88     88       /// </summary>
    89     89       public override void Close()
................................................................................
   661    661         SQLiteStatement stmt = null;
   662    662         int fieldCount;
   663    663   
   664    664         while (true)
   665    665         {
   666    666           if (_activeStatement != null && stmt == null)
   667    667           {
          668  +          // Reset the previously-executed statement
          669  +          _activeStatement._sql.Reset(_activeStatement);
          670  +          
   668    671             // If we're only supposed to return a single rowset, step through all remaining statements once until
   669    672             // they are all done and return false to indicate no more resultsets exist.
   670    673             if ((_commandBehavior & CommandBehavior.SingleResult) != 0)
   671    674             {
   672         -            // Reset the previously-executed command
   673         -            _activeStatement._sql.Reset(_activeStatement);
   674         -
   675    675               for (; ; )
   676    676               {
   677         -              stmt = _command.GetStatement(_activeStatementIndex);
   678         -              _activeStatementIndex++;
          677  +              stmt = _command.GetStatement(_activeStatementIndex + 1);
   679    678                 if (stmt == null) break;
          679  +              _activeStatementIndex++;
   680    680   
   681    681                 stmt._sql.Step(stmt);
   682         -              _rowsAffected += stmt._sql.Changes;
          682  +              if (stmt._sql.ColumnCount(stmt) == 0)
          683  +              {
          684  +                if (_rowsAffected == -1) _rowsAffected = 0;
          685  +                _rowsAffected += stmt._sql.Changes;
          686  +              }
   683    687                 stmt._sql.Reset(stmt); // Gotta reset after every step to release any locks and such!
   684    688               }
   685    689               return false;
   686    690             }
   687         -          else
   688         -          {
   689         -            // Reset the previously-executed command
   690         -            _activeStatement._sql.Reset(_activeStatement);
   691         -          }
   692    691           }
   693    692   
   694    693           // Get the next statement to execute
   695    694           stmt = _command.GetStatement(_activeStatementIndex + 1);
   696    695   
   697    696           // If we've reached the end of the statements, return false, no more resultsets
   698    697           if (stmt == null)
................................................................................
   702    701           if (_readingState < 1)
   703    702             _readingState = 1;
   704    703   
   705    704           _activeStatementIndex++;
   706    705   
   707    706           fieldCount = stmt._sql.ColumnCount(stmt);
   708    707   
   709         -        // If we're told to get schema information only, then don't perform an initial step() through the resultset
          708  +        // If the statement is not a select statement or we're not retrieving schema only, then perform the initial step
   710    709           if ((_commandBehavior & CommandBehavior.SchemaOnly) == 0 || fieldCount == 0)
   711    710           {
   712    711             if (stmt._sql.Step(stmt))
   713    712             {
   714    713               _readingState = -1;
   715    714             }
   716    715             else if (fieldCount == 0) // No rows returned, if fieldCount is zero, skip to the next statement
   717    716             {
          717  +            if (_rowsAffected == -1) _rowsAffected = 0;
   718    718               _rowsAffected += stmt._sql.Changes;
   719    719               stmt._sql.Reset(stmt);
   720    720               continue; // Skip this command and move to the next, it was not a row-returning resultset
   721    721             }
   722    722             else // No rows, fieldCount is non-zero so stop here
   723    723             {
   724    724               _readingState = 1; // This command returned columns but no rows, so return true, but HasRows = false and Read() returns false
................................................................................
   774    774       }
   775    775   
   776    776       /// <summary>
   777    777       /// Retrieve the count of records affected by an update/insert command.  Only valid once the data reader is closed!
   778    778       /// </summary>
   779    779       public override int RecordsAffected
   780    780       {
   781         -      get { return (IsClosed) ? _rowsAffected : -1; }
          781  +      get { return _rowsAffected; }
   782    782       }
   783    783   
   784    784       /// <summary>
   785    785       /// Indexer to retrieve data from a column given its name
   786    786       /// </summary>
   787    787       /// <param name="name">The name of the column to retrieve data for</param>
   788    788       /// <returns>The value contained in the column</returns>