private void DumpSubFolder(ISqlDumper dmp, string subfolder) { string dir = GetPrivateSubFolder(subfolder); if (!Directory.Exists(dir)) { return; } string[] files = Directory.GetFiles(dir); Array.Sort(files); foreach (string f in files) { if (!f.ToLower().EndsWith(".sql")) { continue; } using (StreamReader sr = new StreamReader(f)) { foreach (string sql in QueryTools.GoSplit(sr)) { dmp.WriteRaw(sql); dmp.EndCommand(); } } } }
private void RunScript(ISqlDumper dmp) { using (var fr = GetInputStream()) { foreach (string sql in QueryTools.GoSplit(fr)) { dmp.WriteRaw(sql); dmp.EndCommand(); } } }
public override void GenSql(ISqlDumper dmp) { dmp.Put("^insert ^into %f ", InsertTarget); dmp.Put("(%,i) ^ values (", Columns.Select(x => x.TargetColumn)); for (int i = 0; i < Columns.Count; i++) { if (i > 0) dmp.Put(", "); Columns[i].Expr.GenSql(dmp); } dmp.Put(")"); dmp.EndCommand(); }
public void GenerateScript(TableDataScript script, TableDataSetProperties props, ISqlDumper dmp) { switch (script) { case TableDataScript.Delete: if (!m_deleteQuery.IsEmpty()) { dmp.WriteRaw(m_deleteQuery); if (!props.FilterSqlCondition.IsEmpty()) { dmp.WriteRaw(" WHERE "); dmp.WriteRaw(props.FilterSqlCondition); } dmp.EndCommand(); } break; case TableDataScript.Select: dmp.WriteRaw(GetQuery(props, QueryType.Select)); dmp.EndCommand(); break; } }
public override void GenSql(ISqlDumper dmp) { dmp.Put("^insert ^into %f ", InsertTarget); dmp.Put("(%,i) ^ values (", Columns.Select(x => x.TargetColumn)); for (int i = 0; i < Columns.Count; i++) { if (i > 0) { dmp.Put(", "); } Columns[i].Expr.GenSql(dmp); } dmp.Put(")"); dmp.EndCommand(); }
public override void GenerateSqlRow(IBedRecord row, ISqlDumper dmp, string[] selcolumns) { dmp.Put("^update %f ^set ", FullTableName); bool was = false; foreach (string col in GetColumns(ValueColumns, row.Structure, selcolumns)) { if (was) { dmp.Put(", "); } dmp.Put("%i = %v", col, new ValueTypeHolder(row.GetValue(col), row.Structure.Columns[col].DataType)); was = true; } GenerateWhere(row, dmp, selcolumns); dmp.EndCommand(); }
public void GenerateRegister(ISqlDumper dmp) { dmp.Put("^CREATE ^FUNCTION %i (", Attribute.Name ?? Function.Name); bool was = false; foreach (var arg in Function.GetParameters()) { if (was) { dmp.Put(", "); } dmp.Put("@%s %s", arg.Name, AssemblyWrapper.GetSqlType(arg.ParameterType)); was = true; } dmp.Put(") ^RETURNS %s", AssemblyWrapper.GetSqlType(Function.ReturnType)); dmp.Put(" ^EXTERNAL ^NAME %i.%i.%i", m_wrapper.m_name, Function.DeclaringType.FullName, Function.Name); dmp.EndCommand(); }
private void InsertTableData(TableInfo table) { if (!_options.TableOptions.Insert) { return; } ColumnInfo autoinc = table.FindAutoIncrementColumn(); if (autoinc != null && !_options.TableOptions.SkipAutoincrementColumn) { _dmp.AllowIdentityInsert(table.FullName, true); } var colIndexes = new List <int>(); for (int i = 0; i < table.ColumnCount; i++) { colIndexes.Add(i); } var colNames = table.Columns.Select(x => x.Name).ToList(); if (_options.TableOptions.SkipAutoincrementColumn && autoinc != null) { int index = table.Columns.IndexOf(autoinc); colIndexes.RemoveAt(index); colNames.RemoveAt(index); } var colIndexesArray = colIndexes.ToArray(); using (var reader = CreateTableReader(table, out var cmd)) { try { int processedRows = 0; while (reader.Read()) { if (IsFull || _isCanceled) { cmd.Cancel(); return; } LogMessage($"Exported {processedRows} rows from {table.Name}"); if (_options.TableOptions.OmitNulls) { var values = reader.GetValuesByCols(colIndexesArray).ToList(); var colNamesCopy = new List <string>(colNames); for (int i = values.Count - 1; i >= 0; i--) { if (values[i] == null) { values.RemoveAt(i); colNamesCopy.RemoveAt(i); } } _dmp.Put("^insert ^into %f (%,i) ^values (%,v);&n", table.FullName, colNamesCopy, values); } else { _dmp.Put("^insert ^into %f (%,i) ^values (%,v);&n", table.FullName, colNames, reader.GetValuesByCols(colIndexesArray)); } if (_sqlo.CurrentCommandLength > MaxBatchInsertSize) { _dmp.EndCommand(); } processedRows++; } } finally { _cancelable?.RemoveCancelMethod(cmd); } } if (autoinc != null && !_options.TableOptions.SkipAutoincrementColumn) { _dmp.AllowIdentityInsert(table.FullName, false); } }
public void GenerateDrop(ISqlDumper dmp) { dmp.WriteRaw(StdScripts.dropassembly.Replace("#ASMNAME#", m_name)); dmp.EndCommand(); }
public override void GenerateSqlRow(IBedRecord row, ISqlDumper dmp, string[] selcolumns) { dmp.Put("^delete ^from %f ", FullTableName); GenerateWhere(row, dmp, selcolumns); dmp.EndCommand(); }