transaction qry
This commit is contained in:
@@ -73,12 +73,67 @@ namespace PSqLiteWrapper
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExecuteQuery(string[] queries)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DBPath))
|
||||
throw new ArgumentException("Empty DBPath");
|
||||
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conn = Connection)
|
||||
{
|
||||
conn.Open();
|
||||
PSqLite.ExecuteQuery(conn, "BEGIN TRANSACTION;");
|
||||
|
||||
for (int i = 0; i < queries.Length; i++)
|
||||
{
|
||||
SQLiteCommand command = new SQLiteCommand(queries[i], conn);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
PSqLite.ExecuteQuery(conn, "END TRANSACTION;");
|
||||
Connection.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExecuteQueryAsync(string query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DBPath))
|
||||
throw new ArgumentException("Empty DBPath");
|
||||
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conn = Connection)
|
||||
{
|
||||
conn.Open();
|
||||
SQLiteCommand command = new SQLiteCommand(query, conn);
|
||||
command.ExecuteNonQueryAsync();
|
||||
Connection.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExecuteQuery(SQLiteConnection openedConn, string query)
|
||||
{
|
||||
SQLiteCommand command = new SQLiteCommand(query, openedConn);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void ExecuteQueryAsync(SQLiteConnection openedConn, string query)
|
||||
{
|
||||
SQLiteCommand command = new SQLiteCommand(query, openedConn);
|
||||
command.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public static DataSet ExecuteSelectQuery(string query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DBPath))
|
||||
|
@@ -47,52 +47,77 @@ namespace SQLite_Console
|
||||
Console.WriteLine();
|
||||
watch.Restart();
|
||||
|
||||
List<Thread> threads = new List<Thread>();
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
threads.Add(new Thread(() => InsertRandomRows($"t{i + 1}", 1000)));
|
||||
}
|
||||
// Cach size
|
||||
PSqLite.ExecuteQuery("PRAGMA cache_size=10000;");
|
||||
|
||||
foreach (Thread thread in threads)
|
||||
{
|
||||
thread.Start();
|
||||
}
|
||||
watch.Stop();
|
||||
Console.WriteLine($"set cach size to 10000: {watch.ElapsedMilliseconds}ms");
|
||||
Console.WriteLine();
|
||||
watch.Restart();
|
||||
|
||||
//Random rnd = new Random();
|
||||
//for (int i = 0; i < 2000; i++)
|
||||
//List<Thread> threads = new List<Thread>();
|
||||
//for (int i = 0; i < 20; i++)
|
||||
//{
|
||||
// string guid = Guid.NewGuid().ToString();
|
||||
// int age = rnd.Next(1, 100);
|
||||
// string name = $"Robo#{i + 1}";
|
||||
// string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
// PSqLite.ExecuteQuery(insertQry);
|
||||
// threads.Add(new Thread(() => InsertRandomRows($"t{i + 1}", 1000)));
|
||||
//}
|
||||
|
||||
//watch.Stop();
|
||||
//Console.WriteLine($"insert 2000 row case1: {watch.ElapsedMilliseconds}ms");
|
||||
//Console.WriteLine();
|
||||
//watch.Restart();
|
||||
|
||||
//rnd = new Random();
|
||||
//using (SQLiteConnection conn = PSqLite.Connection)
|
||||
//foreach (Thread thread in threads)
|
||||
//{
|
||||
// conn.Open();
|
||||
// for (int i = 0; i < 2000; i++)
|
||||
// {
|
||||
// string guid = Guid.NewGuid().ToString();
|
||||
// int age = rnd.Next(1, 100);
|
||||
// string name = $"Robo#{i + 1}";
|
||||
// string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
// PSqLite.ExecuteQuery(conn, insertQry);
|
||||
// }
|
||||
|
||||
// conn.Close();
|
||||
// thread.Start();
|
||||
//}
|
||||
|
||||
//watch.Stop();
|
||||
//Console.WriteLine($"insert 2000 row case2: {watch.ElapsedMilliseconds}ms");
|
||||
//Console.WriteLine();
|
||||
//watch.Restart();
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < 2000; i++)
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
int age = rnd.Next(1, 100);
|
||||
string name = $"Robo#{i + 1}";
|
||||
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
PSqLite.ExecuteQuery(insertQry);
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
Console.WriteLine($"insert 2000 row case1: {watch.ElapsedMilliseconds}ms");
|
||||
Console.WriteLine();
|
||||
watch.Restart();
|
||||
|
||||
rnd = new Random();
|
||||
using (SQLiteConnection conn = PSqLite.Connection)
|
||||
{
|
||||
conn.Open();
|
||||
for (int i = 0; i < 2000; i++)
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
int age = rnd.Next(1, 100);
|
||||
string name = $"Robo#{i + 1}";
|
||||
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
PSqLite.ExecuteQuery(conn, insertQry);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
Console.WriteLine($"insert 2000 row case2: {watch.ElapsedMilliseconds}ms");
|
||||
Console.WriteLine();
|
||||
watch.Restart();
|
||||
|
||||
rnd = new Random();
|
||||
string[] queries = new string[2000];
|
||||
for (int i = 0; i < 2000; i++)
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
int age = rnd.Next(1, 100);
|
||||
string name = $"Robo#{i + 1}";
|
||||
queries[i] = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
}
|
||||
|
||||
PSqLite.ExecuteQuery(queries);
|
||||
|
||||
watch.Stop();
|
||||
Console.WriteLine($"insert 2000 row case3: {watch.ElapsedMilliseconds}ms");
|
||||
Console.WriteLine();
|
||||
watch.Restart();
|
||||
|
||||
//DataSet select = PSqLite.ExecuteSelectQuery("SELECT * FROM member");
|
||||
//DataRowCollection rows = select.Tables[0].Rows;
|
||||
@@ -146,15 +171,18 @@ namespace SQLite_Console
|
||||
using (SQLiteConnection conn = PSqLite.Connection)
|
||||
{
|
||||
conn.Open();
|
||||
PSqLite.ExecuteQuery("BEGIN TRANSACTION;");
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
int age = rnd.Next(1, 100);
|
||||
string name = $"{identifier} Robo#{i + 1}";
|
||||
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
|
||||
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}');";
|
||||
PSqLite.ExecuteQuery(conn, insertQry);
|
||||
}
|
||||
|
||||
PSqLite.ExecuteQuery("BEGIN TRANSACTION;");
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user