System.Data.SQLite
Check-in [bf66bbedce]
Not logged in

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

Overview
Comment:Misc. code optimizations
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: bf66bbedceb0ce29bcdabccc7df156e90bd298df
User & Date: rmsimpson 2005-03-02 23:10:43
Context
2005-03-04
21:29
More performance enhancements to SQLiteCommand check-in: 8502a3ae6d user: rmsimpson tags: sourceforge
2005-03-02
23:10
Misc. code optimizations check-in: bf66bbedce user: rmsimpson tags: sourceforge
16:00
Release build now targets the bin directory check-in: b483cda274 user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   282    282               return "TEXT";
   283    283           }
   284    284         }
   285    285       }
   286    286   
   287    287       internal override int ColumnIndex(SQLiteStatement stmt, string columnName)
   288    288       {
   289         -      for (int n = 0; n < ColumnCount(stmt); n++)
          289  +      int x = ColumnCount(stmt);
          290  +
          291  +      for (int n = 0; n < x; n++)
   290    292         {
   291    293           if (String.Compare(columnName, ColumnName(stmt, n), true) == 0) return n;
   292    294         }
   293    295         return -1;
   294    296       }
   295    297   
   296    298       internal override double GetDouble(SQLiteStatement stmt, int index)

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

    15     15     /// <summary>
    16     16     /// SQLite implementation of DbCommand.
    17     17     /// </summary>
    18     18     public sealed class SQLiteCommand : DbCommand
    19     19     {
    20     20       private string                    _commandText;
    21     21       private SQLiteConnection          _cnn;
    22         -    private SQLiteDataReader          _dataReader;
           22  +    private bool                      _isReaderOpen;
    23     23       private int                       _commandTimeout;
    24     24       private bool                      _designTimeVisible;
    25     25       private UpdateRowSource           _updateRowSource;
    26     26       private SQLiteParameterCollection _parameterCollection;
    27     27   
    28     28       internal SQLiteStatement[]        _statementList;
    29     29   
................................................................................
    66     66       {
    67     67         Initialize(null, cnn);
    68     68       }
    69     69   
    70     70       private void Initialize(string strSql, SQLiteConnection cnn)
    71     71       {
    72     72         _statementList = null;
    73         -      _dataReader = null;
           73  +      _isReaderOpen = false;
    74     74         _commandTimeout = 30;
    75     75         _parameterCollection = new SQLiteParameterCollection(this);
    76     76         _designTimeVisible = true;
    77     77         _updateRowSource = UpdateRowSource.FirstReturnedRecord;
    78     78   
    79     79         if (strSql != null)
    80     80           CommandText = strSql;
................................................................................
    88     88       /// </summary>
    89     89       /// <param name="disposing"></param>
    90     90       protected override void Dispose(bool disposing)
    91     91       {
    92     92         base.Dispose(disposing);
    93     93         ClearCommands();
    94     94         _parameterCollection.Clear();
           95  +      _cnn = null;
           96  +      _commandText = null;
    95     97       }
    96     98   
    97     99       internal void ClearCommands()
    98    100       {
    99    101         if (_statementList == null) return;
   100    102   
   101         -      for (int n = 0; n < _statementList.Length; n++)
          103  +      int x = _statementList.Length;
          104  +      for (int n = 0; n < x; n++)
   102    105           _statementList[n].Dispose();
   103    106   
   104    107         _statementList = null;
   105    108   
   106    109         _parameterCollection.Unbind();
   107    110       }
   108    111   
................................................................................
   150    153         {
   151    154           return _commandText;
   152    155         }
   153    156         set
   154    157         {
   155    158           if (_commandText == value) return;
   156    159   
   157         -        if (_dataReader != null)
          160  +        if (_isReaderOpen)
   158    161           {
   159    162             throw new InvalidOperationException("Cannot set CommandText while a DataReader is active");
   160    163           }
   161    164   
   162    165   //        if (value == null)
   163    166   //          throw new ArgumentNullException();
   164    167   
................................................................................
   220    223       {
   221    224         get
   222    225         {
   223    226           return _cnn;
   224    227         }
   225    228         set
   226    229         {
   227         -        if (_dataReader != null)
          230  +        if (_isReaderOpen)
   228    231             throw new InvalidOperationException("Cannot set Connection while a DataReader is active");
   229    232   
   230    233           if (_cnn != null)
   231    234           {
   232    235             ClearCommands();
   233    236             _cnn._commandList.Remove(this);
   234    237           }
................................................................................
   276    279       /// <summary>
   277    280       /// 
   278    281       /// </summary>
   279    282       /// <param name="behavior"></param>
   280    283       /// <returns></returns>
   281    284       protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
   282    285       {
   283         -      if (_dataReader != null)
          286  +      if (_isReaderOpen )
   284    287           throw new InvalidOperationException("DataReader already active on this command");
   285    288   
   286    289         if (_cnn == null)
   287    290           throw new InvalidOperationException("No connection associated with this Command");
   288    291   
   289    292         if (_cnn.State != ConnectionState.Open)
   290    293           throw new InvalidOperationException("Database is not open");
   291    294   
   292    295         int n;
          296  +      int x;
   293    297   
   294    298         if (_statementList.Length == 0)
   295    299         {
   296    300           BuildCommands();
   297    301         }
   298    302   
   299    303         // Make sure all parameters are mapped properly to associated statement(s)
   300    304         _parameterCollection.MapParameters();
   301    305   
          306  +      x = _statementList.Length;
   302    307         // Bind all parameters to their statements
   303         -      for (n = 0; n < _statementList.Length; n++)
          308  +      for (n = 0; n < x; n++)
   304    309           _statementList[n].BindParameters();
   305    310   
   306    311         _cnn._sql.SetTimeout(_commandTimeout * 1000);
   307    312   
   308         -      _dataReader = new SQLiteDataReader(this, behavior);
          313  +      _isReaderOpen = true;
   309    314   
   310         -      return _dataReader;
          315  +      return new SQLiteDataReader(this, behavior);
   311    316       }
   312    317   
   313    318       internal void ClearDataReader()
   314    319       {
   315         -      _dataReader = null;
          320  +      _isReaderOpen = false;
   316    321       }
   317    322   
   318    323       /// <summary>
   319    324       /// Execute the command and return the number of rows inserted/updated affected by it.
   320    325       /// </summary>
   321    326       /// <returns></returns>
   322    327       public override int ExecuteNonQuery()

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

   254    254       /// <summary>
   255    255       /// When the database connection is closed, all commands linked to this connection are automatically reset.
   256    256       /// </summary>
   257    257       public override void Close()
   258    258       {
   259    259         if (_sql != null)
   260    260         {
   261         -        for (int n = 0; n < _commandList.Count; n++)
          261  +        int x = _commandList.Count;
          262  +        for (int n = 0; n < x; n++)
   262    263           {
   263    264             _commandList[n].ClearCommands();
   264    265           }
   265    266           _sql.Close();
   266    267         }
   267    268   
   268    269         _sql = null;
................................................................................
   380    381         List<KeyValuePair<string, string>> ls = new List<KeyValuePair<string, string>>();
   381    382   
   382    383         // First split into semi-colon delimited values.  The Split() function of SQLiteBase accounts for and properly
   383    384         // skips semi-colons in quoted strings
   384    385         string[] arParts = SQLiteConvert.Split(s, ';');
   385    386         string[] arPiece;
   386    387   
          388  +      int x = arParts.Length;
   387    389         // For each semi-colon piece, split into key and value pairs by the presence of the = sign
   388         -      for (n = 0; n < arParts.Length; n++)
          390  +      for (n = 0; n < x; n++)
   389    391         {
   390    392           arPiece = SQLiteConvert.Split(arParts[n], '=');
   391    393           if (arPiece.Length == 2)
   392    394           {
   393    395             kv.Key = arPiece[0];
   394    396             kv.Value = arPiece[1];
   395    397             ls.Add(kv);
................................................................................
   407    409       /// </summary>
   408    410       /// <param name="opts">The Key/Value pair array to look in</param>
   409    411       /// <param name="key">The key to find</param>
   410    412       /// <param name="defValue">The default value to return if the key is not found</param>
   411    413       /// <returns>The value corresponding to the specified key, or the default value if not found.</returns>
   412    414       internal string FindKey(KeyValuePair<string, string>[] opts, string key, string defValue)
   413    415       {
   414         -      for (int n = 0; n < opts.Length; n++)
          416  +      int x = opts.Length;
          417  +      for (int n = 0; n < x; n++)
   415    418         {
   416    419           if (String.Compare(opts[n].Key, key, true) == 0)
   417    420           {
   418    421             return opts[n].Value;
   419    422           }
   420    423         }
   421    424         return defValue;

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

    90     90         }
    91     91   
    92     92         // If the datareader's behavior includes closing the connection, then do so here.
    93     93         if ((_commandBehavior & CommandBehavior.CloseConnection) != 0)
    94     94           _command.Connection.Close();
    95     95   
    96     96         _command = null;
           97  +      _activeStatement = null;
           98  +      _fieldTypeArray = null;
    97     99       }
    98    100   
    99    101       /// <summary>
   100    102       /// Disposes the datareader.  Calls Close() to ensure everything is cleaned up.
   101    103       /// </summary>
   102    104       public override void Dispose()
   103    105       {
................................................................................
   464    466           // Create a new command based on the original.  The only difference being that this new command returns
   465    467           // fully-qualified Database.Table.Column column names because of the above pragma
   466    468           using (SQLiteCommand cmd = new SQLiteCommand(_activeStatement._sqlStatement, cnn))
   467    469           {
   468    470             using (DbDataReader rd = cmd.ExecuteReader())
   469    471             {
   470    472               // No need to Read() from this reader, we just want the column names
   471         -            for (int n = 0; n < FieldCount; n++)
          473  +            for (int n = 0; n < _fieldCount; n++)
   472    474               {
   473    475                 strTable = "";
   474    476                 strCatalog = "main";
   475    477   
   476    478                 row = tbl.NewRow();
   477    479   
   478    480                 // Default settings for the column

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

   363    363       /// Disposes of any active contextData variables that were not automatically cleaned up.  Sometimes this can happen if
   364    364       /// someone closes the connection while a DataReader is open.
   365    365       /// </summary>
   366    366       public void Dispose()
   367    367       {
   368    368         Dispose(true);
   369    369   
   370         -      _InvokeFunc = null;
   371         -      _StepFunc = null;
   372         -      _FinalFunc = null;
   373         -      _CompareFunc = null;
   374         -
   375    370         IDisposable disp;
   376    371   
   377    372   #if !PLATFORM_COMPACTFRAMEWORK
   378    373         foreach (KeyValuePair<int, object> kv in _contextDataList)
   379    374   #else
   380    375         foreach (DictionaryEntry kv in _contextDataList)
   381    376   #endif
................................................................................
   382    377         {
   383    378           disp = kv.Value as IDisposable;
   384    379           if (disp != null)
   385    380             disp.Dispose();
   386    381         }
   387    382         _contextDataList.Clear();
   388    383   
          384  +      _InvokeFunc = null;
          385  +      _StepFunc = null;
          386  +      _FinalFunc = null;
          387  +      _CompareFunc = null;
          388  +      _base = null;
          389  +      _contextDataList = null;
          390  +
   389    391         GC.SuppressFinalize(this);
   390    392       }
   391    393   
   392    394       /// <summary>
   393    395       /// Using reflection, enumerate all assemblies in the current appdomain looking for classes that
   394    396       /// have a SQLiteFunctionAttribute attribute, and registering them accordingly.
   395    397       /// </summary>
................................................................................
   492    494       /// </remarks>
   493    495       /// <param name="sqlbase">The base SQLite connection object</param>
   494    496       /// <param name="ar">An array of user-defined functions for this object</param>
   495    497       internal static void UnbindFunctions(SQLiteBase sqlbase, SQLiteFunction[] ar)
   496    498       {
   497    499         if (ar == null) return;
   498    500   
   499         -      for (int n = 0; n < ar.Length; n++)
          501  +      int x = ar.Length;
          502  +      for (int n = 0; n < x; n++)
   500    503         {
   501    504           sqlbase.FreeFunction(ar[n]._interopCookie);
   502    505           ar[n].Dispose();
   503    506         }
   504    507       }
   505    508     }
   506    509   }

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

   151    151   
   152    152       /// <summary>
   153    153       /// 
   154    154       /// </summary>
   155    155       /// <param name="values"></param>
   156    156       public void AddRange(SQLiteParameter[] values)
   157    157       {
   158         -      for (int n = 0; n < values.Length; n++)
          158  +      int x = values.Length;
          159  +      for (int n = 0; n < x; n++)
   159    160           Add(values[n]);
   160    161       }
   161    162   
   162    163       /// <summary>
   163    164       /// 
   164    165       /// </summary>
   165    166       /// <param name="values"></param>
   166    167       public override void AddRange(Array values)
   167    168       {
   168         -      for (int n = 0; n < values.Length; n++)
          169  +      int x = values.Length;
          170  +      for (int n = 0; n < x; n++)
   169    171           Add((SQLiteParameter)(values.GetValue(n)));
   170    172       }
   171    173   
   172    174       /// <summary>
   173    175       /// 
   174    176       /// </summary>
   175    177       /// <param name="parameterName"></param>
................................................................................
   252    254       /// <summary>
   253    255       /// 
   254    256       /// </summary>
   255    257       /// <param name="parameterName"></param>
   256    258       /// <returns></returns>
   257    259       public override int IndexOf(string parameterName)
   258    260       {
   259         -      for (int n = 0; n < _parameterList.Count; n++)
          261  +      int x = _parameterList.Count;
          262  +      for (int n = 0; n < x; n++)
   260    263         {
   261    264           if (String.Compare(parameterName, _parameterList[n].ParameterName, true) == 0) return n;
   262    265         }
   263    266         return -1;
   264    267       }
   265    268   
   266    269       /// <summary>
................................................................................
   360    363           s = p.ParameterName;
   361    364           if (s == null)
   362    365           {
   363    366             s = String.Format(";{0}", nUnnamed);
   364    367             nUnnamed++;
   365    368           }
   366    369   
   367         -        for (n = 0; n < _command._statementList.Length; n++)
          370  +        int x = _command._statementList.Length;
          371  +        for (n = 0; n < x; n++)
   368    372           {
   369    373             stmt = _command._statementList[n];
   370    374             if (stmt._paramNames != null)
   371    375             {
   372    376               stmt.MapParameter(s, p);
   373    377             }
   374    378           }
   375    379         }
   376    380         _unboundFlag = false;
   377    381       }
   378    382     }
   379    383   }

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

    56     56         }
    57     57       }
    58     58   
    59     59       internal void MapParameter(string s, SQLiteParameter p)
    60     60       {
    61     61         if (_paramNames == null) return;
    62     62   
    63         -      for (int n = 0; n < _paramNames.Length; n++)
           63  +      int x = _paramNames.Length;
           64  +      for (int n = 0; n < x; n++)
    64     65         {
    65     66           if (String.Compare(_paramNames[n], s, true) == 0)
    66     67           {
    67     68             _paramValues[n] = p;
    68     69             break;
    69     70           }
    70     71         }
................................................................................
    73     74       #region IDisposable Members
    74     75       public void Dispose()
    75     76       {
    76     77         _sql.Finalize(this);
    77     78         
    78     79         _paramNames = null;
    79     80         _paramValues = null;
           81  +      _sql = null;
           82  +      _sqlStatement = null;
    80     83   
    81     84         GC.SuppressFinalize(this);
    82     85       }
    83     86       #endregion
    84     87       
    85     88       /// <summary>
    86     89       ///  Bind all parameters, making sure the caller didn't miss any

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

    63     63       /// <summary>
    64     64       /// Disposes the transaction.  If it is currently active, any changes are rolled back.
    65     65       /// </summary>
    66     66       public override void Dispose()
    67     67       {
    68     68         if (_cnn != null) 
    69     69           Rollback();
           70  +
           71  +      _cnn = null;
           72  +
    70     73         GC.SuppressFinalize(this);
    71     74       }
    72     75   
    73     76       /// <summary>
    74     77       /// Gets the isolation level of the transaction.  SQLite does not support isolation levels, so this always returns Unspecified.
    75     78       /// </summary>
    76     79       public override IsolationLevel IsolationLevel

Changes to bin/SQLite.Interop.dll.

cannot compute difference between binary files

Changes to bin/System.Data.SQLite.dll.

cannot compute difference between binary files

Changes to bin/test.exe.

cannot compute difference between binary files