39 lines
1.6 KiB
C#
39 lines
1.6 KiB
C#
|
using Microsoft.Data.Sqlite;
|
|||
|
using System.Globalization;
|
|||
|
|
|||
|
namespace TimeTable.controll {
|
|||
|
internal static class SqliteTaskCommands {
|
|||
|
|
|||
|
public static string select = "select uid, lfdr, start, end, text, time from tasks";
|
|||
|
private static CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("de-de");
|
|||
|
private static string insertPrefix = "insert into tasks (";
|
|||
|
private static string insertIntermediate = ") values(";
|
|||
|
private static string insertPostfix = ");";
|
|||
|
|
|||
|
private static string updatePrefix = "update tasks set ";
|
|||
|
private static string updateIntermediate = " where uid = ";
|
|||
|
private static string updatePostfix = ";";
|
|||
|
|
|||
|
|
|||
|
public static void CreateTableIfNotExists(string sqlConnection) {
|
|||
|
SqliteConnection con = new SqliteConnection(sqlConnection);
|
|||
|
con.Open();
|
|||
|
SqliteCommand sqliteCmd = con.CreateCommand();
|
|||
|
sqliteCmd.CommandText = @"SELECT name FROM sqlite_master WHERE type='table' AND name='tasks';";
|
|||
|
|
|||
|
var name = sqliteCmd.ExecuteScalar();
|
|||
|
if (name != null && name.ToString() == "tasks") {
|
|||
|
return;
|
|||
|
}
|
|||
|
var cols = "lfdr INTEGER PRIMARY KEY AUTOINCREMENT,";
|
|||
|
string[] columns = new string[5] { "start", "end", "text", "time", "uid" };
|
|||
|
cols += string.Join(" VARCHAR,", columns);
|
|||
|
cols = cols + " Varchar";
|
|||
|
sqliteCmd.CommandText = "CREATE TABLE tasks (" + cols + ")";
|
|||
|
con.Open();
|
|||
|
sqliteCmd.ExecuteNonQuery();
|
|||
|
con.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|