protected static bool InsertOrReplaceImpl <T>(T instance, DataSource ds, ColumnMode mode, params DataColumn[] columns) where T : DbTable { if (ds.Provider.SupperReplace) { InsertBucket bucket = TDbTable <T> .GetInsertSql(ds, instance, mode, columns); string sql = ds.Provider.BuildInsertOrReplaceSql(GetTableName <T>(), bucket.Names, bucket.Values, bucket.Id); return(ds.ExecuteNonQuery(sql, bucket.Parameters) > 0); } DataWhereQueue ps = null; KeyValuePair <string, FieldInfo>[] pks = TDbTable <T> .PrimaryKeys; foreach (KeyValuePair <string, FieldInfo> pair in pks) { if (ps == null) { ps = new DataParameter(pair.Key, pair.Value.GetValue(instance)); } else { ps &= new DataParameter(pair.Key, pair.Value.GetValue(instance)); } } if (ExecuteCount <T>(ds, ps) > 0) { return(UpdateImpl <T>(instance, ds, mode, columns, ps) > 0); } return(InsertImpl <T>(instance, ds, mode, columns)); }
protected static bool InsertImpl <T>(T instance, DataSource ds, ColumnMode mode, params DataColumn[] columns) where T : DbTable { InsertBucket bucket = TDbTable <T> .GetInsertSql(ds, instance, mode, columns); string sql = ds.Provider.BuildInsertSql(GetTableName <T>(), bucket.Names, bucket.Values, bucket.Id); return(InsertImpl(ds, sql, instance, bucket.Parameters)); }
protected static int UpdateImpl <T>(T instance, DataSource ds, ColumnMode mode, DataColumn[] columns, DataWhereQueue ps = null) where T : DbTable { UpdateBucket bucket = TDbTable <T> .GetUpdateSql(ds, instance, mode, columns, ps); return(ds.ExecuteNonQuery(ds.Provider.BuildUpdateSql(GetTableName <T>(), bucket.Sets, bucket.Wheres), bucket.Parameters)); }
protected static int DeleteImpl <T>(T instance, DataSource ds, DataWhereQueue ps = null) where T : DbTable { DeleteBucket bucket = TDbTable <T> .GetDeleteSql(ds, instance, null, ps); return(ds.ExecuteNonQuery(ds.Provider.BuildDeleteSql(GetTableName <T>(), bucket.Wheres), bucket.Parameters)); }
protected static int DeleteImpl <T>(T instance, DataSource ds, params DataColumn[] columns) where T : DbTable { DeleteBucket bucket = TDbTable <T> .GetDeleteSql(ds, instance, columns, null); return(ds.ExecuteNonQuery(ds.Provider.BuildDeleteSql(GetTableName <T>(), bucket.Wheres), bucket.Parameters)); }
public static int CreateTable <T>(DataSource ds) where T : DbTable { return(ds.ExecuteNonQuery(TDbTable <T> .GetCreateTableSql(ds.Provider, GetTableName <T>()))); }