public void GetCommands(DmlfBatch res, DatabaseInfo db, IDialectDataAdapter dda, ICdlValueConvertor converter) { var cmd = new DmlfInsert(); cmd.InsertTarget = TargetTable; var table = db.FindTable(TargetTable); if (table == null) { return; } var autoinc = table.FindAutoIncrementColumn(); bool isAutoInc = autoinc != null && Values.Any(x => x.Column == autoinc.Name); GetValues(cmd.Columns, Values, table, dda, converter); if (isAutoInc) { res.AllowIdentityInsert(table.FullName, true); } res.Commands.Add(cmd); if (isAutoInc) { res.AllowIdentityInsert(table.FullName, false); } }
public DataSetModel(DatabaseInfo targetDatabase, IShellContext context, IDatabaseFactory factory) { _targetDatabase = targetDatabase; _context = context; _factory = factory; _dda = _factory.CreateDataAdapter(); }
public void GetCommands(DmlfBatch res, DatabaseInfo db, IDialectDataAdapter dda, ICdlValueConvertor converter) { var cmd = new DmlfInsert(); cmd.InsertTarget = TargetTable; var table = db.FindTable(TargetTable); if (table == null) return; var autoinc = table.FindAutoIncrementColumn(); bool isAutoInc = autoinc != null && Values.Any(x => x.Column == autoinc.Name); GetValues(cmd.Columns, Values, table, dda, converter); if (isAutoInc) { res.AllowIdentityInsert(table.FullName, true); } res.Commands.Add(cmd); if (isAutoInc) { res.AllowIdentityInsert(table.FullName, false); } }
public SqlDumper(ISqlOutputStream stream, ISqlDialect dialect, SqlFormatProperties props) { m_stream = stream; m_props = props; m_dialect = dialect; m_DDA = dialect.CreateDataAdapter(); m_formatterState.DDA = m_DDA; }
public SqlDumper(ISqlOutputStream stream, IDatabaseFactory factory, SqlFormatProperties props) { m_stream = stream; m_props = props; m_factory = factory; m_DDA = m_factory.CreateDataAdapter(); m_formatterState.DDA = m_DDA; m_dialect = m_factory.CreateDialect(); }
public static string GetSqlLiteralAndRead(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, object val, DbTypeBase dsttype) { if (state == null) { state = new SqlFormatterState(); } state._Holder.ReadFrom(val); return(GetSqlLiteral(props, dda, state, state._Holder, dsttype)); }
public BedAdapter(IPhysicalConnection conn, string queryTemplate, bool isFullTableSelect) { m_queryTemplate = queryTemplate; m_conn = conn; m_isFullTableSelect = isFullTableSelect; if (m_conn != null) { m_dda = m_conn.Dialect.CreateDataAdapter(); } }
public RecordToDbAdapter(ITableStructure recordFormat, ITableStructure targetTable, ISqlDialect targetDialect, DataFormatSettings formatSettings) { m_dstColTypes = new List <DbTypeBase>(); foreach (var col in recordFormat.Columns) { m_dstColTypes.Add(targetTable.Columns[col.ColumnName].DataType); } m_dda = targetDialect.CreateDataAdapter(); m_outputConv = new BedValueConvertor(formatSettings); }
public SqlDumper(ISqlOutputStream stream, IDatabaseFactory factory, SqlFormatProperties props) { _stream = stream; _props = props; _factory = factory; _DDA = _factory.CreateDataAdapter(); _formatterState.DDA = _DDA; _dialect = _factory.CreateDialect(); _dumperCaps = _factory.DumperCaps; _dialectCaps = _factory.DialectCaps; }
public void WriteRecord(StreamWriter fw, ITableStructure table, IBedRecord record, int index, object manager) { if (m_dda == null) { m_dda = (m_dialect ?? GenericDialect.Instance).CreateDataAdapter(); } fw.Write("INSERT INTO "); fw.Write(m_tableName); fw.Write(" ("); bool was = false; for (int i = 0; i < record.FieldCount; i++) { if (was) { fw.Write(","); } fw.Write(record.GetName(i)); was = true; } fw.Write(") VALUES ("); was = false; for (int i = 0; i < record.FieldCount; i++) { if (was) { fw.Write(","); } record.ReadValue(i); fw.Write(m_dda.GetSqlLiteral(record)); //TypeStorage type = record.GetFieldType(); //if (record.IsDBNull(i)) //{ // fw.Write("NULL"); //} //else //{ // fw.Write(m_quoteCharacter); // string val = XmlTool.ObjectToString(record.GetValue(i)); // val = val.Replace("" + m_quoteCharacter, m_escapedQuote); // fw.Write(val); // fw.Write(m_quoteCharacter); //} was = true; } fw.Write(")"); fw.Write(m_statementSeparator.ReplaceCEscapes()); }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, IBedValueReader reader, DbTypeBase dsttype) { if (props.BinaryStrings) { switch (reader.GetFieldType()) { case TypeStorage.String: if (props.BinaryStrings) { return(dda.GetSqlLiteral(props.RealBinaryEncoding.GetBytes(reader.GetString()), dsttype)); } break; } } return(dda.GetSqlLiteral(reader, dsttype)); }
public Synchronizer(IDatabaseSource src, IDatabaseSource dst, IProgressInfo progress, DataSynDef datasyn, DataSynReportEnv repenv, string outFile, DataSynGuiEnv guienv) { m_source = src; m_target = dst; m_progress = progress; m_datasyn = datasyn; m_outFile = outFile; m_srcSada = m_source.Dialect.CreateDataSynAdapter(); m_dstSada = m_target.Dialect.CreateDataSynAdapter(); m_dstDDA = m_target.GetAnyDDA(); m_reportEnvObj = repenv; m_reportEnv = repenv; m_guienv = guienv; if (m_reportEnv == null) { m_reportEnv = new DummyDataSynReportEnv(); } }
protected static void GetValues(DmlfUpdateFieldCollection fields, List<ChangeSetValue> values, TableInfo table, IDialectDataAdapter dda, ICdlValueConvertor converter) { var input = new CdlValueHolder(); var output = new CdlValueHolder(); foreach (var col in values) { var colinfo = table.FindColumn(col.Column); if (colinfo == null) continue; input.ReadFrom(col.Value); dda.AdaptValue(input, colinfo.CommonType, output, converter); fields.Add(new DmlfUpdateField { TargetColumn = colinfo.Name, Expr = new DmlfLiteralExpression { Value = output.GetValue(), } }); } }
public static string GetSqlLiteralAndRead(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, object val) { return(GetSqlLiteralAndRead(props, dda, state, val, null)); }
private static void WriteFormattedValue(ISqlDialect dialect, SqlFormatProperties props, StringBuilder sb, object val, char fmt, SqlFormatterState state, IDialectDataAdapter dda) { switch (fmt) { case 'i': // quote identifier DumpSeparatorIfNeeded(sb, props, state); if (val is string) { sb.Append(QuoteIdentifier(dialect, props, (string)val)); } else if (val is ColumnReference) { sb.Append(QuoteIdentifier(dialect, props, ((ColumnReference)val).RefColumn.Name)); } else { throw new InternalError("DBSH-00044 Identifier must be of type string or IColumnReference"); } DataDumped(state); break; case 'f': // quote full name DumpSeparatorIfNeeded(sb, props, state); if (val is NameWithSchema) { sb.Append(QuoteFullName(dialect, props, state, (NameWithSchema)val)); } else if (val is IFullNamedObject) { sb.Append(QuoteFullName(dialect, props, state, ((IFullNamedObject)val).FullName)); } else { throw new InternalError("DBSH-00045 Full name must be of type NameWithSchema or IFullNamedObject"); } DataDumped(state); break; case 'l': // quote linked server name DumpSeparatorIfNeeded(sb, props, state); var linked = val as LinkedDatabaseInfo; if (linked == null && val != null) { throw new InternalError("DBSH-00162 Linked name must be LinkedDatabaseInfo or null"); } if (linked != null && linked.LinkedServerName != null) { sb.Append(QuoteIdentifier(dialect, props, linked.LinkedServerName)); sb.Append("."); sb.Append(QuoteIdentifier(dialect, props, linked.LinkedDatabaseName)); sb.Append("."); state.ForceFullName = true; } if (linked != null && linked.ExplicitDatabaseName != null) { sb.Append(QuoteIdentifier(dialect, props, linked.ExplicitDatabaseName)); sb.Append("."); state.ForceFullName = true; } break; case 's': // string - copy character data if (val != null) { DumpSeparatorIfNeeded(sb, props, state); sb.Append(val.ToString()); DataDumped(state); } break; case 'k': // keyword DumpSeparatorIfNeeded(sb, props, state); if (!(val is string)) { throw new InternalError("DBSH-00046 Identifier must be of type string"); } foreach (char c2 in (string)val) { sb.Append(GetCasedChar(c2, props.SqlCommandCase)); } DataDumped(state); break; case 'K': // multi-word keyword if (!(val is IEnumerable <string>)) { throw new InternalError("DBSH-00047 Identifier must be of type string"); } foreach (string s in ((IEnumerable <string>)val)) { DumpSeparatorIfNeeded(sb, props, state); sb.Append(GetCasedString(s, props.SqlCommandCase)); if (state != null) { state.SeparatorNeeded = true; } else { sb.Append(" "); } DataDumped(state); } break; case 'v': // value - copy character data DumpSeparatorIfNeeded(sb, props, state); var vth = val as ValueTypeHolder; if (vth != null) { sb.Append(GetSqlLiteralAndRead(props, dda, state, vth.Value, vth.DbType)); } else { sb.Append(GetSqlLiteralAndRead(props, dda, state, val)); } DataDumped(state); break; case 't': // version test if (val != null && !props.OmitVersionTests) { sb.Append(val.ToString()); } break; default: throw new InternalError("DBSH-00048 Unknown format character: " + fmt); } }
public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter) { var table = db.FindTable(TargetTable); if (table == null) return; if ((UpdateReferences || model.UpdateReferences) && IsUpdatingPk(db)) { var refs = GenerateCascadeUpdates(db); foreach (var item in refs) { item.GetCommands(res, db, model, dda, converter); } } if (!IsDuplicatingIdentity(db, model)) { var cmd = new DmlfUpdate(); cmd.UpdateTarget = new DmlfSource { TableOrView = TargetTable, LinkedInfo = LinkedInfo, Alias = "basetbl", }; cmd.From.Add(new DmlfFromItem { Source = cmd.UpdateTarget, }); if (GetConditions(cmd, this, Conditions, db)) { GetValues(cmd.Columns, Values, table, dda, converter); res.Commands.Add(cmd); } } }
public void GetInsertCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter) { var table = db.FindTable(TargetTable); if (table == null) return; if (IsDuplicatingIdentity(db, model)) { res.AllowIdentityInsert(table.FullName, true); var insert = new DmlfInsertSelect { TargetTable = table.FullName, }; insert.Select = new DmlfSelect(); insert.Select.SingleFrom = new DmlfFromItem { Source = new DmlfSource { TableOrView = table.FullName, Alias = "basetbl", } }; GetConditions(insert.Select, this, Conditions, db); foreach (var col in table.Columns) { var valcol = Values.FirstOrDefault(x => x.Column == col.Name); insert.TargetColumns.Add(col.Name); if (valcol == null) { insert.Select.Columns.Add(DmlfResultField.BuildFromColumn(col.Name, insert.Select.SingleFrom.Source)); } else { insert.Select.Columns.Add(new DmlfResultField { Expr = new DmlfLiteralExpression { Value = valcol.Value, } }); } } res.Commands.Add(insert); res.AllowIdentityInsert(table.FullName, false); } }
public static string Format(ISqlDialect dialect, SqlFormatProperties props, SqlFormatterState state, string format, params object[] args) { IDialectDataAdapter dda = null; if (state != null) { dda = state.DDA; } if (dda == null) { dda = dialect.CreateDataAdapter(); } int argindex = 0; StringBuilder sb = new StringBuilder(); int i = 0; while (i < format.Length) { char c = format[i]; switch (c) { case '^': // SQL keyword { i++; SymbolPosition original = null; if (format[i] == ':') { original = (SymbolPosition)args[argindex]; argindex++; i++; } DumpSeparatorIfNeeded(sb, props, state, original); while (i < format.Length && (Char.IsLetter(format, i) || format[i] == '_')) { sb.Append(GetCasedChar(format[i], props.SqlCommandCase)); i++; } DataDumped(state); } break; case '&': // indentation & spacing { i++; c = format[i]; i++; char level = '0'; if (c == '1' || c == '2' || c == '3' || c == '5') { level = c; c = format[i]; i++; } if (level != '0') { // indentation levels if (props.IndentationLevel == SqlIndentationLevel.Original || props.IndentationLevel == SqlIndentationLevel.SingleLine) { if (c == 'n' || c == 's') { if (state != null) { state.SeparatorNeeded = true; } else { sb.Append(" "); } } // when original indentation is used, don't use our separators break; } bool valid = (props.IndentationLevel == SqlIndentationLevel.Compact && (level == '2' || level == '5')) || (props.IndentationLevel == SqlIndentationLevel.Large && (level == '3' || level == '5')); if (!valid) { break; // mark is not for this indentation level } } switch (c) { case '&': sb.Append("&"); break; case 'n': if (state == null) { DumpEoln(sb, props, state); } else { state.LineFeedNeeded = true; } break; case '>': if (state != null) { state.IndentLevel++; } break; case '<': if (state != null) { state.IndentLevel--; } break; case 's': if (state != null) { state.SeparatorNeeded = true; } else { sb.Append(" "); } break; default: throw new InternalError("DAE-00041 Unknown & formatting instruction:" + c); } } break; case '%': // format parameter { i++; c = format[i]; if (c == '%') { sb.Append('%'); i++; } else if (c == ',') // comma separated list { i++; c = format[i]; bool ok = false; if (args[argindex] is IEnumerable) { ok = true; } if (args[argindex] is IBedRecord && c == 'v') { ok = true; } if (!ok) { throw new InternalError("DAE-00042 List must be of type Enumerable"); } bool was = false; if (args[argindex] is IEnumerable) { foreach (object item in (IEnumerable)args[argindex]) { if (was) { sb.Append(", "); } WriteFormattedValue(dialect, props, sb, item, c, null, state, dda); was = true; } } else { var rec = (IBedRecord)args[argindex]; for (int x = 0; x < rec.FieldCount; x++) { if (was) { sb.Append(", "); } rec.ReadValue(x); sb.Append(GetSqlLiteral(props, dda, state, rec)); was = true; } } argindex++; i++; } else if (c == ':') { object orig = args[argindex]; argindex++; i++; c = format[i]; object arg = args[argindex]; argindex++; i++; WriteFormattedValue(dialect, props, sb, arg, c, orig, state, dda); } else { WriteFormattedValue(dialect, props, sb, args[argindex], c, null, state, dda); argindex++; i++; } } break; default: { if (Char.IsWhiteSpace(c)) { if (state != null) { state.SeparatorNeeded = false; } } else { DumpSeparatorIfNeeded(sb, props, state, null); } sb.Append(c); i++; } break; } } return(sb.ToString()); }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader) { return GetSqlLiteral(props, dda, state, reader, null); }
public static string GetSqlLiteralAndRead(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, object val) { return GetSqlLiteralAndRead(props, dda, state, val, null); }
public static string GetSqlLiteral(this IDialectDataAdapter dda, object value) { return(dda.GetSqlLiteral(value, null)); }
private static void WriteFormattedValue(ISqlDialect dialect, SqlFormatProperties props, StringBuilder sb, object val, char fmt, object orig, SqlFormatterState state, IDialectDataAdapter dda) { switch (fmt) { case 'i': // quote identifier DumpSeparatorIfNeeded(sb, props, state, (SymbolPosition)orig); if (val is string) { sb.Append(QuoteIdentifier(dialect, props, (string)val, (SymbolPosition)orig)); } else if (val is IColumnReference) { sb.Append(QuoteIdentifier(dialect, props, ((IColumnReference)val).ColumnName, (SymbolPosition)orig)); } else { throw new InternalError("DAE-00043 Identifier must be of type string or IColumnReference"); } DataDumped(state); break; case 'f': // quote full name DumpSeparatorIfNeeded(sb, props, state, (SymbolPosition)orig); if (val is NameWithSchema) { sb.Append(QuoteFullName(dialect, props, (NameWithSchema)val)); } else if (val is IFullNamedObject) { sb.Append(QuoteFullName(dialect, props, ((IFullNamedObject)val).FullName)); } else { throw new InternalError("DAE-00044 Full name must be of type NameWithSchema or IFullNamedObject"); } DataDumped(state); break; case 's': // string - copy character data if (val != null) { DumpSeparatorIfNeeded(sb, props, state, (SymbolPosition)orig); sb.Append(val.ToString()); DataDumped(state); } break; case 'k': // keyword DumpSeparatorIfNeeded(sb, props, state, (SymbolPosition)orig); if (!(val is string)) { throw new InternalError("DAE-00045 Identifier must be of type string"); } if (props.SqlCommandCase == CharacterCase.Original && orig != null) { sb.Append(((SymbolPosition)orig).GetOriginalToken()); } else { foreach (char c2 in (string)val) { sb.Append(GetCasedChar(c2, props.SqlCommandCase)); } } DataDumped(state); break; case 'K': // multi-word keyword if (!(val is IEnumerable <string>)) { throw new InternalError("DAE-00046 Identifier must be of type string"); } if (orig != null) { foreach (var sym in ((IEnumerable <SymbolPosition>)orig)) { DumpSeparatorIfNeeded(sb, props, state, sym); sb.Append(GetCasedString(sym.GetOriginalToken(), props.SqlCommandCase)); if (state != null) { state.SeparatorNeeded = true; } else { sb.Append(" "); } DataDumped(state); } } else { foreach (string s in ((IEnumerable <string>)val)) { DumpSeparatorIfNeeded(sb, props, state, null); sb.Append(GetCasedString(s, props.SqlCommandCase)); if (state != null) { state.SeparatorNeeded = true; } else { sb.Append(" "); } DataDumped(state); } } break; case 'v': // value - copy character data DumpSeparatorIfNeeded(sb, props, state, (SymbolPosition)orig); if (props.UseOriginalValues && orig != null) { sb.Append(((SymbolPosition)orig).GetOriginalToken()); } else { var vth = val as ValueTypeHolder; if (vth != null) { sb.Append(GetSqlLiteralAndRead(props, dda, state, vth.Value, vth.DbType)); } else { sb.Append(GetSqlLiteralAndRead(props, dda, state, val)); } } DataDumped(state); break; case 't': // version test if (val != null && !props.OmitVersionTests) { sb.Append(val.ToString()); } break; default: throw new InternalError("DAE-00047 Unknown format character: " + fmt); } }
public static string GetSqlLiteral(this IDialectDataAdapter dda, IBedValueReader reader) { return(dda.GetSqlLiteral(reader, null)); }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, IBedValueReader reader) { return(GetSqlLiteral(props, dda, state, reader, null)); }
private static void WriteFormattedValue(ISqlDialect dialect, SqlFormatProperties props, StringBuilder sb, object val, char fmt, SqlFormatterState state, IDialectDataAdapter dda) { switch (fmt) { case 'i': // quote identifier DumpSeparatorIfNeeded(sb, props, state); if (val is string) { sb.Append(QuoteIdentifier(dialect, props, (string) val)); } else if (val is ColumnReference) { sb.Append(QuoteIdentifier(dialect, props, ((ColumnReference) val).RefColumn.Name)); } else { throw new InternalError("DBSH-00044 Identifier must be of type string or IColumnReference"); } DataDumped(state); break; case 'f': // quote full name DumpSeparatorIfNeeded(sb, props, state); if (val is NameWithSchema) sb.Append(QuoteFullName(dialect, props, state, (NameWithSchema) val)); else if (val is IFullNamedObject) sb.Append(QuoteFullName(dialect, props, state, ((IFullNamedObject)val).FullName)); else throw new InternalError("DBSH-00045 Full name must be of type NameWithSchema or IFullNamedObject"); DataDumped(state); break; case 'l': // quote linked server name DumpSeparatorIfNeeded(sb, props, state); var linked = val as LinkedDatabaseInfo; if (linked == null && val != null) { throw new InternalError("DBSH-00162 Linked name must be LinkedDatabaseInfo or null"); } if (linked != null && linked.LinkedServerName != null) { sb.Append(QuoteIdentifier(dialect, props, linked.LinkedServerName)); sb.Append("."); sb.Append(QuoteIdentifier(dialect, props, linked.LinkedDatabaseName)); sb.Append("."); state.ForceFullName = true; } if (linked != null && linked.ExplicitDatabaseName != null) { sb.Append(QuoteIdentifier(dialect, props, linked.ExplicitDatabaseName)); sb.Append("."); state.ForceFullName = true; } break; case 's': // string - copy character data if (val != null) { DumpSeparatorIfNeeded(sb, props, state); sb.Append(val.ToString()); DataDumped(state); } break; case 'k': // keyword DumpSeparatorIfNeeded(sb, props, state); if (!(val is string)) throw new InternalError("DBSH-00046 Identifier must be of type string"); foreach (char c2 in (string) val) sb.Append(GetCasedChar(c2, props.SqlCommandCase)); DataDumped(state); break; case 'K': // multi-word keyword if (!(val is IEnumerable<string>)) throw new InternalError("DBSH-00047 Identifier must be of type string"); foreach (string s in ((IEnumerable<string>) val)) { DumpSeparatorIfNeeded(sb, props, state); sb.Append(GetCasedString(s, props.SqlCommandCase)); if (state != null) state.SeparatorNeeded = true; else sb.Append(" "); DataDumped(state); } break; case 'v': // value - copy character data DumpSeparatorIfNeeded(sb, props, state); var vth = val as ValueTypeHolder; if (vth != null) { sb.Append(GetSqlLiteralAndRead(props, dda, state, vth.Value, vth.DbType)); } else { sb.Append(GetSqlLiteralAndRead(props, dda, state, val)); } DataDumped(state); break; case 't': // version test if (val != null && !props.OmitVersionTests) sb.Append(val.ToString()); break; default: throw new InternalError("DBSH-00048 Unknown format character: " + fmt); } }
public void GetInsertCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter) { var table = db.FindTable(TargetTable); if (table == null) { return; } if (IsDuplicatingIdentity(db, model)) { res.AllowIdentityInsert(table.FullName, true); var insert = new DmlfInsertSelect { TargetTable = table.FullName, }; insert.Select = new DmlfSelect(); insert.Select.SingleFrom = new DmlfFromItem { Source = new DmlfSource { TableOrView = table.FullName, Alias = "basetbl", } }; GetConditions(insert.Select, this, Conditions, db); foreach (var col in table.Columns) { var valcol = Values.FirstOrDefault(x => x.Column == col.Name); insert.TargetColumns.Add(col.Name); if (valcol == null) { insert.Select.Columns.Add(DmlfResultField.BuildFromColumn(col.Name, insert.Select.SingleFrom.Source)); } else { insert.Select.Columns.Add(new DmlfResultField { Expr = new DmlfLiteralExpression { Value = valcol.Value, } }); } } res.Commands.Add(insert); res.AllowIdentityInsert(table.FullName, false); } }
public static string GetSqlLiteralAndRead(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, object val, DbTypeBase dsttype) { if (state == null) state = new SqlFormatterState(); state._Holder.ReadFrom(val); return GetSqlLiteral(props, dda, state, state._Holder, dsttype); }
public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter) { var table = db.FindTable(TargetTable); if (table == null) { return; } if ((UpdateReferences || model.UpdateReferences) && IsUpdatingPk(db)) { var refs = GenerateCascadeUpdates(db); foreach (var item in refs) { item.GetCommands(res, db, model, dda, converter); } } if (!IsDuplicatingIdentity(db, model)) { var cmd = new DmlfUpdate(); cmd.UpdateTarget = new DmlfSource { TableOrView = TargetTable, LinkedInfo = LinkedInfo, Alias = "basetbl", }; cmd.From.Add(new DmlfFromItem { Source = cmd.UpdateTarget, }); if (GetConditions(cmd, this, Conditions, db)) { GetValues(cmd.Columns, Values, table, dda, converter); res.Commands.Add(cmd); } } }
public static string GetSqlLiteral(SqlFormatProperties props, IDialectDataAdapter dda, SqlFormatterState state, ICdlValueReader reader, DbTypeBase dsttype) { if (props.BinaryStrings) { switch (reader.GetFieldType()) { case TypeStorage.String: if (props.BinaryStrings) { return dda.GetSqlLiteral(props.RealBinaryEncoding.GetBytes(reader.GetString()), dsttype); } break; } } return dda.GetSqlLiteral(reader, dsttype); }
protected static void GetValues(DmlfUpdateFieldCollection fields, List <ChangeSetValue> values, TableInfo table, IDialectDataAdapter dda, ICdlValueConvertor converter) { var input = new CdlValueHolder(); var output = new CdlValueHolder(); foreach (var col in values) { var colinfo = table.FindColumn(col.Column); if (colinfo == null) { continue; } input.ReadFrom(col.Value); dda.AdaptValue(input, colinfo.CommonType, output, converter); fields.Add(new DmlfUpdateField { TargetColumn = colinfo.Name, Expr = new DmlfLiteralExpression { Value = output.GetValue(), } }); } }
public RecordToDbAdapter(TargetColumnMap columnMap, IDatabaseFactory targetFactory, DataFormatSettings formatSettings) { _columnMap = columnMap; _dda = targetFactory.CreateDataAdapter(); _outputConv = new CdlValueConvertor(formatSettings); }