C#/.Net 中疾速批量給SQLite數據庫拔出測試數據。本站提示廣大學習愛好者:(C#/.Net 中疾速批量給SQLite數據庫拔出測試數據)文章只能為提供參考,不一定能成為您想要的結果。以下是C#/.Net 中疾速批量給SQLite數據庫拔出測試數據正文
應用transaction:
var stopwatch = new Stopwatch(); using (var cmd = new SQLiteCommand(db_con)) using (var transaction = db_con.BeginTransaction()) { stopwatch.Reset(); stopwatch.Start(); foreach (var item in sorted) { sql = string.Format("insert into db (st1, st2) values ('{0}', {1})", item.Key.WordStr("'", "''"), item.Value); cmd.CommandText = sql; cmd.ExecuteNonQuery(); ++readCnt; if (++readCnt % 1000000 == 0) { Console.Write("\rDumped {0} lines...", readCnt); } } Console.Write("\rCommitting...."); transaction.Commit(); stopwatch.Stop(); Console.Write("\rDumped {0} lines using {1} seconds...", readCnt, stopwatch.Elapsed.TotalSeconds); }