Exemple #1
0
        static void Main(string[] args)
        {
            var opts = new Options(args);

            if (opts.ShowedHelp)
            {
                return;
            }

            var connectionStringProvider = new ConnectionStringProvider(opts);

            opts.Files.ForEach(file =>
            {
                using (var reader = new StatementReader(file))
                {
                    string statement;
                    while ((statement = reader.Next()) != null)
                    {
                        using (var conn = ConnectionFactory.Open(connectionStringProvider.ConnectionString))
                            using (var cmd = conn.CreateCommand())
                            {
                                cmd.CommandText = $"{DISABLE_CONSTRAINTS}{Environment.NewLine}{statement}";
                                LogStatement(opts, statement);
                                try
                                {
                                    cmd.ExecuteNonQuery();
                                }
                                catch (MySqlException ex)
                                {
                                    if (opts.StopOnError)
                                    {
                                        throw;
                                    }

                                    Console.WriteLine($"[FAIL] {ex.Message}");
                                }
                            }
                    }
                }
            });
        }
Exemple #2
0
        private static void RunAllScriptFiles(Options opts, ConnectionStringProvider connectionStringProvider)
        {
            opts.Files.ForEach((file, idx) =>
            {
                var info         = new FileInfo(file);
                var readBytes    = 0L;
                using var reader = new StatementReader(file);
                string statement;
                while ((statement = reader.Next()) != null)
                {
                    readBytes     += reader.LastReadBytes;
                    using var conn = ConnectionFactory.Open(connectionStringProvider.ConnectionString);

                    using var cmd   = conn.CreateCommand();
                    cmd.CommandText = $"{DISABLE_CONSTRAINTS}{Environment.NewLine}{statement}";
                    LogStatement(opts.Verbose, opts.NoProgress, statement, readBytes, info.Length, idx, opts.Files.Count);
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (MySqlException ex)
                    {
                        if (opts.StopOnError)
                        {
                            throw;
                        }

                        if (!opts.Verbose)
                        {
                            ClearProgress();
                            LogStatement(true, true, statement, readBytes, info.Length, idx, opts.Files.Count);
                        }

                        Console.WriteLine($"[FAIL] {ex.Message}");
                    }
                }
            });
            ClearProgress();
        }