public void SQLite_does_not_support_dropping_schemas() { using var cnn = TestUtil.CreateSQLiteWrappedCnx(); var schema = new SQLiteSchema(cnn); Assert.False(schema.Drop()); }
public void Can_get_schema() { using var cnn = TestUtil.CreateSQLiteWrappedCnx(); var schema = new SQLiteSchema(cnn); Assert.True(schema.IsExists()); }
public void When_new_database_is_created_schema_is_empty() { using var cnn = TestUtil.CreateSQLiteWrappedCnx(); var schema = new SQLiteSchema(cnn); Assert.True(schema.IsEmpty()); }
/// <summary> /// 创建一个数据库架构实例 /// </summary> /// <param name="db">数据提供程序实例</param> /// <returns></returns> public static DbSchema Create(Database db) { DbSchema schema = null; switch (db.DatabaseType) { case DatabaseType.SqlServer: //schema = new SqlServerSchema(db); schema = new SqlServerSchema(db); break; case DatabaseType.Oracle: schema = new OracleSchema(db); break; case DatabaseType.MySql: schema = new MySqlSchema(db); break; case DatabaseType.DB2: schema = new DB2Schema(db); break; case DatabaseType.SQLite: schema = new SQLiteSchema(db); break; default: break; } return(schema); }
public void SQLite_does_not_support_creating_schemas() { using (var cnn = TestUtil.CreateSQLiteWrappedCnx()) { var schema = new SQLiteSchema(cnn); Assert.False(schema.Create()); } }
public List <SQLiteSchema> GetTableSchema(string dbConnection, string tableName) { try { List <SQLiteSchema> fields = new List <SQLiteSchema>(); string sql = $"SELECT * FROM {tableName} LIMIT 1"; DataTable dt = new DataTable(); using (var c = new SQLiteConnection(dbConnection)) { c.Open(); using (SQLiteCommand cmd = new SQLiteCommand(sql, c)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { dt = rdr.GetSchemaTable(); foreach (DataRow row in dt.Rows) { SQLiteSchema schema = new SQLiteSchema(); fields.Add(schema); foreach (DataColumn col in dt.Columns) { try { object val = row[col]; if (val != DBNull.Value) { schema.GetType().GetProperty(col.ColumnName).SetValue(schema, val); } } catch (Exception ee) { Console.WriteLine($"{ee.Message}[{tableName}:{col.ColumnName}]"); } } } } } c.Close(); } return(fields); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public SQLiteLogTable(ITaskScheduler scheduler, LogDataCache cache, string fileName) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (cache == null) throw new ArgumentNullException("cache"); if (fileName == null) throw new ArgumentNullException("fileName"); _scheduler = scheduler; _cache = cache; _fileName = fileName; _listeners = new LogTableListenerCollection(this); _accessQueue = new LogDataAccessQueue<LogEntryIndex, LogEntry>(); _schema = new SQLiteSchema(string.Empty); _task = _scheduler.StartPeriodic(Update, ToString()); }
/// <summary> /// Reads the current schema from the given database and then forces a schema update /// of all listeners in case the schema has changed compared to the previous one. /// </summary> /// <param name="connection"></param> private void UpdateSchema(SQLiteConnection connection) { string tableName; if (TryFindTable(connection, out tableName)) { SQLiteSchema schema = GetSchema(connection, tableName); TryChangeSchema(schema); } else { Log.WarnFormat("Unable to find a fitting table in database {0}", _fileName); var schema = new SQLiteSchema(string.Empty); TryChangeSchema(schema); } }
/// <summary> /// Changes the schema of this table, if necessary. /// </summary> /// <param name="schema"></param> private void TryChangeSchema(SQLiteSchema schema) { if (!Equals(_schema, schema)) { Log.DebugFormat("Schema of {0} changed from {1} to {2}", _fileName, _schema, schema); _schema = schema; _rowCount = 0; _cache.Remove(this); _listeners.OnSchemaChanged(_schema); _listeners.OnRead(LogEntryIndex.Invalid, 0); } }