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