internal static void fillParameters(SqliteCommand cmd, object parameters, ReaderCachedCollection typeCollection) { if (parameters == null) { return; } var type = typeCollection.GetInfo(parameters.GetType()); foreach (var p in type.Items) { if (!p.CanRead) { continue; } var value = TypeHelper.ReadParamValue(p, parameters); adjustInsertValue(ref value, p, parameters); if (value is null) { value = DBNull.Value; } cmd.Parameters.AddWithValue(p.Name, value); } }
internal static string buildInsertSql <T>(ReaderCachedCollection typeCollection, OnConflict resolution, string tableName = null) { var info = typeCollection.GetInfo <T>(); if (tableName == null) { tableName = info.TypeName; } var names = getNames(info, !info.IsAnonymousType); var fields = string.Join(",", names); var values = string.Join(",", names.Select(n => $"@{n}")); if (resolution == OnConflict.Abort) { return($"INSERT INTO {tableName} ({fields}) VALUES ({values}); SELECT last_insert_rowid();"); } else { string txtConflict = resolution switch { OnConflict.RollBack => "ROLLBACK", OnConflict.Fail => "FAIL", OnConflict.Ignore => "IGNORE", OnConflict.Replace => "REPLACE", _ => throw new ArgumentException($"Invalid resolution: {resolution}"), }; return($"INSERT OR {txtConflict} INTO {tableName} ({fields}) VALUES ({values}); SELECT last_insert_rowid();"); } }
/// <summary> /// Adds a table /// </summary> public IColumnMapper Add <T>() where T : new() { var info = typeCollection.GetInfo <T>(); tables.Add(Table.FromType(info)); return(this); }