public SqlInnerJoin(Func <Type, SqlitePropertiesAndCommands> resolver) { this.a1 = resolver(typeof(A)); this.t1 = resolver(typeof(T)); this.t2 = resolver(typeof(Y)); }
public void UpdateTableStructure(SqliteConnection conn) { List <(string, string)> columns = new List <(string, string)>(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = $"PRAGMA table_info(\"{propertiesAndCommands.tableName}\");"; using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var name = (string)rdr["name"]; var type = (string)rdr["type"]; columns.Add((name, type)); } } } foreach (var c in propertiesAndCommands.SqlFields()) { if (columns.All(x => x.Item1 != c.Name)) { if (SqlitePropertiesAndCommands.ConvertPropertyType(c.PropertyType) == "text") { using (var cmd = conn.CreateCommand()) { L.Trace($"Adding new column - {c.Name} to table {propertiesAndCommands.tableName}"); cmd.CommandText = propertiesAndCommands.AddColumnCommand(c.Name, ColumnType.String); cmd.ExecuteNonQuery(); } using (var cmd = conn.CreateCommand()) { L.Trace($"Updating value of {c.Name} in table {propertiesAndCommands.tableName}"); string value = c.PropertyType.IsEnum ? Enum.GetNames(c.PropertyType)[0] : ""; cmd.CommandText = propertiesAndCommands.UpdateColumnValuesCommandStr(c.Name, value); cmd.ExecuteNonQuery(); } } else if (SqlitePropertiesAndCommands.ConvertPropertyType(c.PropertyType) == "numeric") { using (var cmd = conn.CreateCommand()) { L.Trace($"Adding new column - {c.Name} to table {propertiesAndCommands.tableName}"); cmd.CommandText = propertiesAndCommands.AddColumnCommand(c.Name, ColumnType.Numeric); cmd.ExecuteNonQuery(); } using (var cmd = conn.CreateCommand()) { L.Trace($"Updating value of {c.Name} in table {propertiesAndCommands.tableName}"); cmd.CommandText = propertiesAndCommands.UpdateColumnValuesCommandNumeric(c.Name, 0); cmd.ExecuteNonQuery(); } } else { throw new Exception($"Unexpected proeprty type to create new Sqlite column: {c.PropertyType} - name of field - {c.Name}"); } } } }
public SqlTableWithPrimaryKey(SqlitePropertiesAndCommands propertiesAndCommands) : base(propertiesAndCommands.tableName) { this.propertiesAndCommands = propertiesAndCommands; }
public DataRecordHelper(SqlitePropertiesAndCommands propertiesAndCommands, IDataRecord record) { this.propertiesAndCommands = propertiesAndCommands; Record = record; }