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

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

Overview
Comment:Optimize and fix the DataAdapter tests, shorten the locktest duration
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: bb2c450c632f7f92ae8e0e5531dc4d24c9863a78
User & Date: rmsimpson 2006-01-12 20:55:03
Context
2006-01-13
03:35
no message check-in: 83d82c5bea user: rmsimpson tags: sourceforge
2006-01-12
20:55
Optimize and fix the DataAdapter tests, shorten the locktest duration check-in: bb2c450c63 user: rmsimpson tags: sourceforge
20:54
Latest Jan 12 CVS HEAD check-in: a7f98646af user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/TestCases.cs.

   310    310             if (b[2000] != 4) throw new ArgumentException();
   311    311             if (b[3000] != 5) throw new ArgumentException();
   312    312   
   313    313             using (DbConnection clone = (DbConnection)((ICloneable)cnn).Clone())
   314    314             {
   315    315               using (DbCommand newcmd = clone.CreateCommand())
   316    316               {
   317         -              newcmd.CommandText = "CREATE TABLE Bar(ID INTEGER PRIMARY KEY)";
   318         -              newcmd.CommandTimeout = 10;
          317  +              newcmd.CommandText = "DELETE FROM TestCase WHERE Field6 IS NULL";
          318  +              newcmd.CommandTimeout = 2;
   319    319                 int cmdStart = Environment.TickCount;
   320    320                 int cmdEnd;
   321    321   
   322    322                 try
   323    323                 {
   324    324                   newcmd.ExecuteNonQuery(); // should fail because there's a reader on the database
   325    325                   throw new ArgumentException(); // If we got here, the test failed
   326    326                 }
   327    327                 catch
   328    328                 {
   329    329                   cmdEnd = Environment.TickCount;
   330         -                if (cmdEnd - cmdStart < 10000 || cmdEnd - cmdStart > 11000)
          330  +                if (cmdEnd - cmdStart < 2000 || cmdEnd - cmdStart > 3000)
   331    331                     throw new ArgumentException(); // Didn't wait the right amount of time
   332    332   
   333    333                 }
   334    334               }
   335    335             }
   336    336           }
   337    337         }
................................................................................
   375    375         using (DbTransaction dbTrans = cnn.BeginTransaction())
   376    376         {
   377    377           using (DbDataAdapter adp = fact.CreateDataAdapter())
   378    378           {
   379    379             using (DbCommand cmd = cnn.CreateCommand())
   380    380             {
   381    381               cmd.Transaction = dbTrans;
   382         -            cmd.CommandText = "SELECT * FROM TestCase";
          382  +            cmd.CommandText = "SELECT * FROM TestCase WHERE 1 = 2";
   383    383               adp.SelectCommand = cmd;
   384    384   
   385         -            // We're deliberately not loading the data adapter with an insert command
   386         -            // unless we're doing the identity fetch.  This tests the CommandBuilder's ability
   387         -            // to autogenerate that command when the insert occurs, which consequently tests
   388         -            // the SQLiteDataAdapter's ability to raise events.
   389         -
   390    385               using (DbCommandBuilder bld = fact.CreateCommandBuilder())
   391    386               {
   392    387                 bld.DataAdapter = adp;
   393         -
   394         -              if (bWithIdentity)
          388  +              using (adp.InsertCommand = (DbCommand)((ICloneable)bld.GetInsertCommand()).Clone())
   395    389                 {
   396         -                adp.InsertCommand = bld.GetInsertCommand();
   397         -                adp.InsertCommand.CommandText += ";SELECT [ID] FROM TestCase WHERE RowID = last_insert_rowid()";
   398         -                adp.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
   399         -              }
          390  +                if (bWithIdentity)
          391  +                {
          392  +                  adp.InsertCommand.CommandText += ";SELECT last_insert_rowid() AS [ID]";
          393  +                  adp.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
          394  +                }
          395  +                bld.DataAdapter = null;
   400    396   
   401         -              using (DataTable tbl = new DataTable())
   402         -              {
   403         -                adp.Fill(tbl);
   404         -                for (int n = 0; n < 10000; n++)
          397  +                using (DataTable tbl = new DataTable())
   405    398                   {
   406         -                  DataRow row = tbl.NewRow();
   407         -                  row[1] = n + 10000;
   408         -                  tbl.Rows.Add(row);
          399  +                  adp.Fill(tbl);
          400  +                  for (int n = 0; n < 10000; n++)
          401  +                  {
          402  +                    DataRow row = tbl.NewRow();
          403  +                    row[1] = n + (50000 * ((bWithIdentity == true) ? 2 : 1));
          404  +                    tbl.Rows.Add(row);
          405  +                  }
          406  +
          407  +                  Console.WriteLine(String.Format("          Inserting using CommandBuilder and DataAdapter\r\n          ->{0} (10,000 rows) ...", (bWithIdentity == true) ? "(with identity fetch)" : ""));
          408  +                  int dtStart = Environment.TickCount;
          409  +                  adp.Update(tbl);
          410  +                  int dtEnd = Environment.TickCount;
          411  +                  dtEnd -= dtStart;
          412  +                  Console.Write(String.Format("          -> Insert Ends in {0} ms ... ", (dtEnd)));
          413  +
          414  +                  dtStart = Environment.TickCount;
          415  +                  dbTrans.Commit();
          416  +                  dtEnd = Environment.TickCount;
          417  +                  dtEnd -= dtStart;
          418  +                  Console.WriteLine(String.Format("Commits in {0} ms", (dtEnd)));
   409    419                   }
   410         -
   411         -                Console.WriteLine(String.Format("          Inserting using CommandBuilder and DataAdapter\r\n          ->{0} (10,000 rows) ...", (bWithIdentity == true) ? "(with identity fetch)" : ""));
   412         -                int dtStart = Environment.TickCount;
   413         -                adp.Update(tbl);
   414         -                int dtEnd = Environment.TickCount;
   415         -                dtEnd -= dtStart;
   416         -                Console.Write(String.Format("          -> Insert Ends in {0} ms ... ", (dtEnd)));
   417         -
   418         -                dtStart = Environment.TickCount;
   419         -                dbTrans.Commit();
   420         -                dtEnd = Environment.TickCount;
   421         -                dtEnd -= dtStart;
   422         -                Console.WriteLine(String.Format("Commits in {0} ms", (dtEnd)));
   423    420                 }
   424    421               }
   425    422             }
   426    423           }
   427    424         }
   428    425       }
   429    426   
................................................................................
   441    438   
   442    439             cmd.Parameters.Add(Field1);
   443    440   
   444    441             Console.WriteLine(String.Format("          Fast insert using parameters and prepared statement\r\n          -> (100,000 rows) Begins ... "));
   445    442             dtStart = Environment.TickCount;
   446    443             for (int n = 0; n < 100000; n++)
   447    444             {
   448         -            Field1.Value = n + 100000;
          445  +            Field1.Value = n + 200000;
   449    446               cmd.ExecuteNonQuery();
   450    447             }
   451    448   
   452    449             dtEnd = Environment.TickCount;
   453    450             dtEnd -= dtStart;
   454    451             Console.Write(String.Format("          -> Ends in {0} ms ... ", (dtEnd)));
   455    452           }

Changes to testce/TestCases.cs.

   311    311             if (b[2000] != 4) throw new ArgumentException();
   312    312             if (b[3000] != 5) throw new ArgumentException();
   313    313   
   314    314             using (DbConnection clone = (DbConnection)((ICloneable)cnn).Clone())
   315    315             {
   316    316               using (DbCommand newcmd = clone.CreateCommand())
   317    317               {
   318         -              newcmd.CommandText = "CREATE TABLE Bar(ID INTEGER PRIMARY KEY)";
   319         -              newcmd.CommandTimeout = 10;
          318  +              newcmd.CommandText = "DELETE FROM TestCase WHERE Field6 IS NULL";
          319  +              newcmd.CommandTimeout = 2;
   320    320                 int cmdStart = Environment.TickCount;
   321    321                 int cmdEnd;
   322    322   
   323    323                 try
   324    324                 {
   325    325                   newcmd.ExecuteNonQuery(); // should fail because there's a reader on the database
   326    326                   throw new ArgumentException(); // If we got here, the test failed
   327    327                 }
   328    328                 catch
   329    329                 {
   330    330                   cmdEnd = Environment.TickCount;
   331         -                if (cmdEnd - cmdStart < 10000 || cmdEnd - cmdStart > 11000)
          331  +                if (cmdEnd - cmdStart < 2000 || cmdEnd - cmdStart > 3000)
   332    332                     throw new ArgumentException(); // Didn't wait the right amount of time
   333    333                 }
   334    334               }
   335    335             }
   336    336           }
   337    337         }
   338    338       }
................................................................................
   380    380               cmd.Transaction = dbTrans;
   381    381               cmd.CommandText = "SELECT * FROM TestCase WHERE 1=2";
   382    382               adp.SelectCommand = cmd;
   383    383   
   384    384               using (DbCommandBuilder bld = new SQLiteCommandBuilder())
   385    385               {
   386    386                 bld.DataAdapter = adp;
   387         -              adp.InsertCommand = bld.GetInsertCommand();
   388         -
   389         -              if (bWithIdentity)
          387  +              using (adp.InsertCommand = (SQLiteCommand)((ICloneable)bld.GetInsertCommand()).Clone())
   390    388                 {
   391         -                adp.InsertCommand.CommandText += ";SELECT [ID] FROM TestCase WHERE RowID = last_insert_rowid()";
   392         -                adp.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
   393         -              }
   394         -
   395         -              using (DataTable tbl = new DataTable())
   396         -              {
   397         -                adp.Fill(tbl);
   398         -                for (int n = 0; n < nmax; n++)
          389  +                bld.DataAdapter = null;
          390  +                if (bWithIdentity)
   399    391                   {
   400         -                  DataRow row = tbl.NewRow();
   401         -                  row[1] = n + nmax;
   402         -                  tbl.Rows.Add(row);
          392  +                  adp.InsertCommand.CommandText += ";SELECT last_insert_rowid() AS [ID]";
          393  +                  adp.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
   403    394                   }
   404    395   
   405         -                frm.Write(String.Format("          InsertMany{0} ({1} rows) Begins ... ", (bWithIdentity == true) ? "WithIdentityFetch":"                 ", nmax));
   406         -                int dtStart = Environment.TickCount;
   407         -                adp.Update(tbl);
   408         -                int dtEnd = Environment.TickCount;
   409         -                dtEnd -= dtStart;
   410         -                frm.Write(String.Format("Ends in {0} ms ... ", (dtEnd)));
          396  +                using (DataTable tbl = new DataTable())
          397  +                {
          398  +                  adp.Fill(tbl);
          399  +                  for (int n = 0; n < nmax; n++)
          400  +                  {
          401  +                    DataRow row = tbl.NewRow();
          402  +                    row[1] = n + nmax;
          403  +                    tbl.Rows.Add(row);
          404  +                  }
   411    405   
   412         -                dtStart = Environment.TickCount;
   413         -                dbTrans.Commit();
   414         -                dtEnd = Environment.TickCount;
   415         -                dtEnd -= dtStart;
   416         -                frm.WriteLine(String.Format("Commits in {0} ms", (dtEnd)));
          406  +                  frm.Write(String.Format("          InsertMany{0} ({1} rows) Begins ... ", (bWithIdentity == true) ? "WithIdentityFetch" : "                 ", nmax));
          407  +                  int dtStart = Environment.TickCount;
          408  +                  adp.Update(tbl);
          409  +                  int dtEnd = Environment.TickCount;
          410  +                  dtEnd -= dtStart;
          411  +                  frm.Write(String.Format("Ends in {0} ms ... ", (dtEnd)));
          412  +
          413  +                  dtStart = Environment.TickCount;
          414  +                  dbTrans.Commit();
          415  +                  dtEnd = Environment.TickCount;
          416  +                  dtEnd -= dtStart;
          417  +                  frm.WriteLine(String.Format("Commits in {0} ms", (dtEnd)));
          418  +                }
   417    419                 }
   418    420               }
   419    421             }
   420    422           }
   421    423         }
   422    424       }
   423    425