コード例 #1
0
ファイル: App.cs プロジェクト: zymITsky/ExcelToSqlScripts
        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);
            }
        }
コード例 #2
0
        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");
            }
        }
コード例 #3
0
 public H2MergeQueryMaker(ValueRenderer valueRenderer)
 {
     _valueRenderer = valueRenderer;
 }
コード例 #4
0
 public UpdateQueryMaker(ValueRenderer valueRenderer)
 {
     _valueRenderer = valueRenderer;
 }
コード例 #5
0
 public OracleMergeQueryMaker(ValueRenderer valueRenderer)
 {
     _valueRenderer = valueRenderer;
 }
コード例 #6
0
 public InsertQueryMaker(ValueRenderer valueRenderer)
 {
     _valueRenderer = valueRenderer;
 }