public override InsertStatementBuilder GetInsertStatementBuilder(object obj) { InsertStatementBuilder sb = base.GetInsertStatementBuilder(obj); sb.Values.Add(new KeyOpValue(_columnName, false, KvOpertation.None)); return(sb); }
protected virtual object ExecuteInsertIntKey(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider) { SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog); sql.SqlCommandText = AddIdentitySelectToInsert(sql.SqlCommandText); return(provider.ExecuteScalar(sql)); }
public virtual InsertStatementBuilder GetInsertStatementBuilder(object obj) { var isv = new InsertStatementBuilder(this.Context.Info.From); this.Context.Handler.SetValuesForInsert(isv, obj); return(isv); }
public void TestCreatedOn() { var dc = new DataProvider("SQLite"); var sb = new InsertStatementBuilder(new FromClause("user")); sb.Values.Add(new KeyOpValue("CreatedOn", null, KvOpertation.Now)); SqlStatement sql = sb.ToSqlStatement(dc.Dialect, null); Assert.AreEqual("INSERT INTO [user] ([CreatedOn]) VALUES (DATETIME(CURRENT_TIMESTAMP, 'localtime'));\n", sql.SqlCommandText); }
protected override object ExecuteInsertIntKey(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider) { string seqStr = GetSelectSequenceSql(info.From.MainTableName); var seq = new SqlStatement(CommandType.Text, seqStr); object key = provider.ExecuteScalar(seq); sb.Values.Add(new KeyOpValue(info.KeyMembers[0].Name, key, KvOpertation.None)); SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog); provider.ExecuteNonQuery(sql); return(key); }
private void SetManyToManyRelation(Type t, object key1, object key2) { if ((Info.CrossTables.ContainsKey(t) && (key1 != null)) && (key2 != null)) { CrossTable table = Info.CrossTables[t]; var builder = new InsertStatementBuilder(new FromClause(table.Name, "")); builder.Values.Add(new KeyOpValue(table[0].Column, key1, KvOpertation.None)); builder.Values.Add(new KeyOpValue(table[1].Column, key2, KvOpertation.None)); SqlStatement sql = builder.ToSqlStatement(Provider.Dialect, Info.QueryRequiredFields, Info.AllowSqlLog); Provider.ExecuteNonQuery(sql); } }
private IStatementBuildProvider CreateProvider() { var selectStatementBuilder = new SelectStatementBuilder(); var insertStatementBuilder = new InsertStatementBuilder(); var updateStatementBuilder = new UpdateStatementBuilder(); var conditionBuilder = new ConditionBuilder(); return(new SqlStatementBuildProvider(selectStatementBuilder, insertStatementBuilder, updateStatementBuilder, conditionBuilder)); }
public override SqlStatement GetDeleteStatement(object obj) { SqlStatement sql = base.GetDeleteStatement(obj); InsertStatementBuilder sb = GetInsertStatementBuilder(obj); sb.Values.Add(new KeyOpValue("DeletedOn", null, KvOpertation.Now)); sb.From = new FromClause(Context.Info.DeleteToTableName, ""); SqlStatement isql = sb.ToSqlStatement(Context); sql.SqlCommandText += isql.SqlCommandText; sql.Parameters.Add(isql.Parameters); return(sql); }
public virtual object ExecuteInsert(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider) { if (info.HasOnePrimaryKey && info.KeyMembers[0].MemberType == typeof(Guid)) { if (info.KeyMembers[0].Is.DbGenerateGuid) { Guid key = Util.NewGuid(); sb.Values[0].Value = key; } SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog); provider.ExecuteNonQuery(sql); return(sb.Values[0].Value); } return(ExecuteInsertIntKey(sb, info, provider)); }
public void WriteToServer(IDataReader reader) { ProcessWrite(delegate { while (reader.Read()) { var sb = new InsertStatementBuilder(new FromClause(this.DestinationTableName)); for (int i = 0; i < reader.FieldCount; i++) { object o = GetValue(reader[i]); sb.Values.Add(new KeyOpValue(reader.GetName(i), o, KvOpertation.None)); } if (!WriteSingleToServer(sb)) { break; } } }); }
public void WriteToServer(DataTable table) { ProcessWrite(delegate { foreach (DataRow dr in table.Rows) { var sb = new InsertStatementBuilder(new FromClause(this.DestinationTableName)); for (int i = 0; i < table.Columns.Count; i++) { object o = GetValue(dr[i]); sb.Values.Add(new KeyOpValue(table.Columns[i].ColumnName, o, KvOpertation.None)); } if (!WriteSingleToServer(sb)) { break; } } }); }
public IRelationalCommand Build <TEntity>(SqlStatementKind statementKind, IEntityModel model, TEntity entity, IEntityMapping entityMapping) { switch (statementKind) { case SqlStatementKind.CreateTable: ISqlStatementBuilder <CreateTableStatement> statementBuilder = new CreateTableStatementBuilder(model, entityMapping); ISqlStatement statement = statementBuilder.BuildStatement(); return(new RelationalCommand(statement.GetText(), null)); case SqlStatementKind.Insert: ISqlStatementBuilder <InsertStatement> insertStatementBuilder = new InsertStatementBuilder(entity, entityMapping); InsertStatement insertStatement = insertStatementBuilder.BuildStatement(); return(new RelationalCommand(insertStatement.GetText(), insertStatement.Parameters)); case SqlStatementKind.Update: ISqlStatementBuilder <UpdateStatement> updateStatementBuilder = new UpdateStatementBuilder(entity, entityMapping); UpdateStatement updateStatement = updateStatementBuilder.BuildStatement(); return(new RelationalCommand(updateStatement.GetText(), updateStatement.Parameters)); case SqlStatementKind.Delete: ISqlStatementBuilder <DeleteStatement> deleteStatementBuilder = new DeleteStatementBuilder(entity, entityMapping); DeleteStatement deleteStatement = deleteStatementBuilder.BuildStatement(); return(new RelationalCommand(deleteStatement.GetText(), deleteStatement.Parameters)); default: throw new NotImplementedException(); } }
private bool WriteSingleToServer(InsertStatementBuilder sb) { SqlStatement sql = sb.ToSqlStatement(_provider.Dialect, null); sql.SqlTimeOut = _bulkCopyTimeout; _provider.ExecuteNonQuery(sql); _count++; if (_batchSize > 0 && (_count % _batchSize) == 0) { var cc = Scope <ConnectionContext> .Current; cc.Commit(); cc.BeginTransaction(); } if (SqlRowsCopied != null && _notifyAfter > 0 && ((_count % _notifyAfter) == 0)) { var e = new SqlRowsCopiedEventArgs(_count); SqlRowsCopied(this, e); if (e.Abort) { return(false); } } return(true); }
public void TestInitialize() { _insertStatementBuilder = new InsertStatementBuilder(); }