internal void CreateFirebirdIdTable(string tableName, string columnName, DatabaseAgent agent) { string IdTableName = string.Format("{0}NID", tableName); // create a table to hold the next id for the specified table /* * This is specifically for Firebird since it doesn't have a way to * easily create an autoincrementing id field. The closest thing they * have is "Generators" used in "before insert" triggers. Attempts * to go in that direction is proving time consuming. So, I'm * implementing my own ID Generator to be used internally to this component. */ try { agent.ExecuteSqlFormat(DatabaseAgent.CREATETABLEFORMAT, IdTableName, string.Format("{0} BIGINT", columnName)); agent.ExecuteSqlFormat(DatabaseAgent.INSERTFORMAT, IdTableName, columnName, "0"); } catch (Exception ex) { CreateTableResult result = CatchException(ex, IdTableName); if (result != CreateTableResult.Success && result != CreateTableResult.AlreadyExists) { throw ex; } } }
public YingDataBaseManager() { yconnection.CreateTable <zyy_users>(); CreateTableResult yresult = yconnection.CreateTable <zyy_settings>(); yconnection.CreateTable <zyy_yggdrasil_profile>(); yconnection.CreateTable <zyy_yggdrasil_texture>(); yconnection.CreateTable <zyy_yggdrasil_tokens>(); yconnection.CreateTable <zyy_verification_code>(); if (yresult == CreateTableResult.Created) { this.yconnection.Insert(new zyy_settings { ykey = "yid", yvalue = Guid.NewGuid().ToString("N"), ydescription = "服务器唯一标识符 (请不要随意修改)" }); this.yconnection.Insert(new zyy_settings { ykey = "yname", yvalue = "Ying", ydescription = "服务器名称" }); this.yconnection.Insert(new zyy_settings { ykey = "ydescription", yvalue = "一个Minecraft服务器", ydescription = "服务器简介" }); this.yconnection.Insert(new zyy_settings { ykey = "yip", yvalue = "0.0.0.0", ydescription = "服务器ip" }); this.yconnection.Insert(new zyy_settings { ykey = "yport", yvalue = "6040", ydescription = "服务器端口 (默认 6040)" }); this.yconnection.Insert(new zyy_yggdrasil_texture { ytextureid = "zyy2a2a1399140968341fdedc4aa8b94", yskin = "http://zyy.com:6040/yingyggdrasil/ytextures/zyy2a2a1399140968341fdedc4aa8b94", yskinmetadata = "default", ytimestamp = getYTimeStamp().TotalMilliseconds }); } }
private static async Task <SQLiteAsyncConnection> GetDatabaseConnection() { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); SQLiteAsyncConnection database = new SQLiteAsyncConnection(Path.Combine(folderPath, "stats.db3")); CreateTableResult createTableResult = await database.CreateTableAsync <StatisticsEntity>(); return(database); }
static internal SQLiteConnection OpenDatabase() { var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "todo.db3"); SQLiteConnection database = new SQLiteConnection(path); CreateTableResult createResult = database.CreateTable <ToDoItem>(); return(database); }
static internal void CreateDatabase() { var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "todo.db3"); var database = new SQLiteConnection(path); CreateTableResult createResult = database.CreateTable <ToDoItem>(); System.Console.WriteLine(createResult); database.Close(); }
private async System.Threading.Tasks.Task <bool> CreateConnectionAsync() { bool ret = false; try { Stopwatch sw = Stopwatch.StartNew(); this.HistoryDic.Clear(); this.HasChanged.WriteFullFence(false); this.DeletedCount.WriteFullFence(0); this.AddedCount.WriteFullFence(0); //FullMutex for safe multithreading SQLiteOpenFlags flags = SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex; if (this.ReadOnly) { flags = flags | SQLiteOpenFlags.ReadOnly; } else { flags = flags | SQLiteOpenFlags.ReadWrite; } if (this.IsSQLiteDBConnected()) { this.DisposeConnection(); } //If the database file doesn't exist, the default behaviour is to create a new file sqlite_conn = new SQLiteAsyncConnection(this.Filename, flags, true); //make sure table exists: CreateTableResult ctr = await sqlite_conn.CreateTableAsync <History>(); await sqlite_conn.ExecuteScalarAsync <int>(@"PRAGMA journal_mode = 'WAL';", new object[] { }); await sqlite_conn.ExecuteScalarAsync <int>(@"PRAGMA busy_timeout = 30000;", new object[] { }); sw.Stop(); Global.Log($"Created connection to SQLite db v{sqlite_conn.LibVersionNumber} in {sw.ElapsedMilliseconds}ms - TableCreate={ctr.ToString()}: {this.Filename}"); HasChanged.WriteFullFence(true); } catch (Exception ex) { Global.Log("Error: " + Global.ExMsg(ex)); } return(ret); }
public JsonResultModel CreateTable(string dbName, TableVo tableVo) { JsonResultModel response = new JsonResultModel(); CreateTableResult returnValue = RealCreateTable(dbName, tableVo); response.Status = (int)returnValue; response.Message = EnumExtension.GetDescription(returnValue); return(response); }
private void InitDbThread() { db = new SQLiteConnection("gamedb.db"); CreateTableResult result = db.CreateTable <GameInfo>(); Console.WriteLine("Create Table Result " + result); if (result == CreateTableResult.Created) { // first time Console.WriteLine("success create db file!"); UpdateTitleKey(); } _gameLists = db.Table <GameInfo>().OrderBy(x => x.tid).ToList <GameInfo>(); SearchGameName(); }
public void ResetToFactory() { sQLiteConnection.DeleteAll <SQL_CableTable>(); CreateTableResult result = sQLiteConnection.CreateTable <SQL_CableTable>(); var s = sQLiteConnection.Insert(new SQL_CableTable() { Name = "cable 1m xyz", Symbol = "P000003-000", // Pins_A = 6, //PinsConnections = "1;2;3;4;5;6", Printer = "xxxx" }); s = sQLiteConnection.Insert(new SQL_CableTable() { Name = "Kabel zasilający xyz", Symbol = "P000002-000", Pins_A = 5, PinsConnections = "B4;B3;B1;B2;B5", Printer = "yyyy" }); s = sQLiteConnection.Insert(new SQL_CableTable() { Name = "Kabel xyz", Symbol = "P000001-000", Pins_A = 4, PinsConnections = ";;;", Printer = "yyyy" }); s = sQLiteConnection.Insert(new SQL_CableTable() { Name = "Kabel TESTOWY", Symbol = "P0000000-000", Pins_A = 6, PinsConnections = "B1,B3;B2;B3,B1;B4;B5;B6", Printer = "xxxx" }); }
private bool CreateConnection() { using var Trace = new Trace(); //This c# 8.0 using feature will auto dispose when the function is done. bool ret = false; try { Stopwatch sw = Stopwatch.StartNew(); Global.UpdateProgressBar("Debug: Initializing history database...", 1, 1, 1); this.HistoryDic.Clear(); this.RecentlyDeleted = new ConcurrentQueue <History>(); this.RecentlyAdded = new ConcurrentQueue <History>(); //https://www.sqlite.org/threadsafe.html SQLiteOpenFlags flags = SQLiteOpenFlags.SharedCache; // SQLiteOpenFlags.Create; // | SQLiteOpenFlags.NoMutex; //| SQLiteOpenFlags.FullMutex; string sflags = "SharedCache"; if (this.ReadOnly) { flags = flags | SQLiteOpenFlags.ReadOnly; sflags += ";ReadOnly"; } else { flags = flags | SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite; sflags += ";Create;ReadWrite"; } if (this.IsSQLiteDBConnected()) { this.DisposeConnection(); } //If the database file doesn't exist, the default behaviour is to create a new file this.sqlite_conn = new SQLiteConnection(this.Filename, flags, true); if (!this.ReadOnly) { //backup once a day this.sqlite_conn.Backup(this.Filename + ".bak"); //make sure table exists: CreateTableResult ctr = this.sqlite_conn.CreateTable <History>(); } this.sqlite_conn.ExecuteScalar <int>(@"PRAGMA journal_mode = 'WAL';", new object[] { }); this.sqlite_conn.ExecuteScalar <int>(@"PRAGMA busy_timeout = 30000;", new object[] { }); sw.Stop(); Log($"Debug: Created connection to SQLite db v{this.sqlite_conn.LibVersionNumber} in {sw.ElapsedMilliseconds}ms, Flags='{sflags}': {this.Filename}", "None", "None", "None"); } catch (Exception ex) { Log("Error: " + Global.ExMsg(ex), "None", "None", "None"); } return(ret); }
public int Execute <T>(IDatabaseconnection _Idatabaseconnection) { CreateTableResult result = _Idatabaseconnection.SQLiteConnection.CreateTable <T>(); return((int)result); }
public Repository(SQLiteAsyncConnection connection) { _connection = connection; CreateTableResult createTableResult = _connection.CreateTableAsync <T>().Result; }
public bool CreatePreferenceTable() { CreateTableResult result = _db.CreateTable <UserPreference>(); return(result == CreateTableResult.Created); }