Exemplo n.º 1
0
        public static void ImportData(SdbUtils sdbutils)
        {
            var sw             = Stopwatch.StartNew();
            var singleThreaded = false;

            sdbutils.LoopTables((table, tableIdx) =>
            {
                var mapping = sdbutils.Mapping.First(x => x.Id == table.Id);

                if (!singleThreaded)
                {
                    using var conn = new NpgsqlConnection(Program.Config.SqlConnStr);
                    conn.Open();

                    ImportDataToTable(mapping, table, conn);
                }
                else
                {
                    ImportDataToTable(mapping, table);
                }
            }, !singleThreaded);

            sw.Stop();
            Console.WriteLine($"Importing data for {sdbutils.Mapping.Count} took {sw.Elapsed}");
        }
Exemplo n.º 2
0
        public static void CreateNameMappingViews(SdbUtils sdbutils)
        {
            var sqls = new List <string>();

            for (var index = 0; index < sdbutils.Mapping.Count; index++)
            {
                var table     = sdbutils.Mapping[index];
                var sb        = new StringBuilder();
                var tableName = Program.Config.UseNamesInTables ? table.Name : $"H_{table.Id:X}";
                var viewName  = table.Name ?? $"H_{table.Id:X}";
                sb.AppendLine($"CREATE VIEW \"VM_{viewName}\" AS SELECT ");

                for (var i = 0; i < table.Colums.Count; i++)
                {
                    var colum     = table.Colums[i];
                    var columName = Program.Config.UseNamesInTables ? colum.Name : $"H_{colum.Id:X}";
                    sb.Append($"\"{columName}\"");

                    if (colum.Name != null)
                    {
                        sb.Append(" as ");
                        sb.Append($"\"{colum.Name}\"");
                    }

                    if (i != table.Colums.Count - 1)
                    {
                        sb.AppendLine(", ");
                    }
                    else
                    {
                        sb.AppendLine();
                    }
                }

                sb.Append(" FROM ");
                sb.Append($"\"{tableName}\"");
                sb.AppendLine(";");

                var sqlStr = sb.ToString();
                sqls.Add(sqlStr);
            }

            foreach (var sql in sqls)
            {
                var cmd = new NpgsqlCommand(sql, Conn);
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 3
0
        private static void Main(string connStr = null, string dir = null)
        {
            if (dir != null)
            {
                Directory.SetCurrentDirectory(dir);
            }

            Config            = Config.Load(SettingsPath);
            Config.SqlConnStr = connStr ?? Config.SqlConnStr;

            Directory.CreateDirectory(Config.OutDir);

            var swTotalTime = Stopwatch.StartNew();
            var sw          = Stopwatch.StartNew();
            var sdbUtils    = new SdbUtils(Config);

            sw.Stop();
            Console.WriteLine($"Loaded sdb and built mapping in {sw.Elapsed}");

            var sw2 = Stopwatch.StartNew();

            SqlUtils.Init();
            SqlUtils.CreateSchema();
            SqlUtils.DropAllViewsInMapping(sdbUtils.Mapping);
            SqlUtils.DropAllInMapping(sdbUtils.Mapping);
            SqlUtils.CreateTypes();
            SqlUtils.CreateCreateSqls(sdbUtils.Mapping, true);

            SqlUtils.CreateNameMappingViews(sdbUtils);
            sw2.Stop();
            Console.WriteLine($"Created DB schema in {sw2.Elapsed}");

            SqlUtils.ImportData(sdbUtils);
            swTotalTime.Stop();
            Console.WriteLine($"All done in {swTotalTime.Elapsed}");
        }