private int Process(string mode) { try { Directory.CreateDirectory(_options.OutputDirectory); ExcelReader excelReader = new ExcelReader(_options.ReadEmptyRecords, _options.WorksheetsToRead?.ToArray()); ValueRenderer valueRenderer = new ValueRenderer(_options.NullReplacements?.ToArray()); IQueryMaker queryMaker = QueryMakerFactory.Create(mode, valueRenderer); TableScriptGenerator tableScriptGenerator = new TableScriptGenerator(queryMaker); IEnumerable <Table> tables = excelReader.Read(_options.InputFile); foreach (Table table in tables) { string filePath = Path.Combine(_options.OutputDirectory, table.Name + ".sql"); Write($"writing {filePath} ..."); if (table.Records.Any()) { using (Script script = tableScriptGenerator.GenerateTableScript(table)) { using (FileStream fileStream = File.Create(filePath)) { script.Content.CopyTo(fileStream); WriteLine(" done"); } } } else { WriteLine(" empty (skipped)"); } } return(0); } catch (Exception ex) { Error.WriteLine($"Error: {ex.GetType().Name}"); Error.WriteLine($"Error: {ex.Message}"); #if DEBUG Error.WriteLine(ex.StackTrace); #endif return(1); } }
public static IQueryMaker Create(string mode, ValueRenderer valueRenderer) { switch (mode.ToLower()) { case "insert": return(new InsertQueryMaker(valueRenderer)); case "update": return(new UpdateQueryMaker(valueRenderer)); case "merge": return(new OracleMergeQueryMaker(valueRenderer)); default: throw new ArgumentException("invalid mode specified"); } }
public H2MergeQueryMaker(ValueRenderer valueRenderer) { _valueRenderer = valueRenderer; }
public UpdateQueryMaker(ValueRenderer valueRenderer) { _valueRenderer = valueRenderer; }
public OracleMergeQueryMaker(ValueRenderer valueRenderer) { _valueRenderer = valueRenderer; }
public InsertQueryMaker(ValueRenderer valueRenderer) { _valueRenderer = valueRenderer; }