private List <IModelProperties> GetModelProperties(string tableName) { var result = new List <IModelProperties>(); using (var con = new SQLiteConnection(connstr)) { con.Open(); using (var cmd = new SQLiteCommand(con)) { cmd.CommandText = $"PRAGMA table_info([{tableName}])"; using (var rd = cmd.ExecuteReader()) { while (rd.Read()) { var mp = new IModelProperties(); mp.Name = rd["name"].ToString(); mp.Type = rd["type"].ToString(); mp.PK = rd["pk"].ToString() == "1"; result.Add(mp); } } } } return(result); }
/// <summary> /// 生成创建列SQL语句 /// </summary> /// <param name="tableName">表名</param> /// <param name="properties">属性</param> /// <returns></returns> private string GetCreateColumnSQL(string tableName, IModelProperties properties) { string typeDefault = properties.NotNull ? properties.Type == "int" ? "NOT NULL DEFAULT 0" : "NOT NULL DEFAULT ''" : ""; return($"ALTER table {tableName} ADD COLUMN [{properties.Name}] {properties.Type} {typeDefault}"); }