Exemplo n.º 1
0
        public void Run(string[] args)
        {
            int i = 0;

            while (i < args.Length)
            {

                switch (args[i++])
                {
                    case "/cfg":
                        i++;
                        break;

                    case "/i":
                        if (i < args.Length && !args[i].StartsWith("/"))
                        {
                            string inputfile = args[i++];
                            string server = cfg.GetValue<string>(Configuration._SERVER0);
                            var pvd = cfg.GetProvider(server);
                            var theSide = new Side(pvd);
                            theSide.ExecuteScript(inputfile);
                            break;
                        }
                        else
                        {
                            stdio.WriteLine("/i undefined sql script file name");
                            return;
                        }

                    case "/o":
                        if (i < args.Length && !args[i].StartsWith("/"))
                        {
                            cfg.OutputFile = args[i++];
                            break;
                        }
                        else
                        {
                            stdio.WriteLine("/o undefined sql script file name");
                            return;
                        }

                    default:
                        Program.Help();
                        return;

                }
            }

            new SqlShell(cfg).DoCommand();
        }
Exemplo n.º 2
0
        public void Run(string[] args)
        {
            int i = 0;

            while (i < args.Length)
            {
                string arg = args[i++];
                switch (arg)
                {
                case "/cfg":
                    i++;
                    break;


                case "/i":
                    if (i < args.Length && !args[i].StartsWith("/"))
                    {
                        IConnectionConfiguration connection = cfg.Connection;
                        string inputfile = args[i++];
                        string server    = connection.Home;
                        var    pvd       = connection.GetProvider(server);
                        var    theSide   = new Side(pvd);
                        theSide.ExecuteScript(inputfile, verbose: false);
                        break;
                    }
                    else
                    {
                        cout.WriteLine("/i undefined sql script file name");
                        return;
                    }

                case "/o":
                    if (i < args.Length && !args[i].StartsWith("/"))
                    {
                        cfg.OutputFile = args[i++];
                        break;
                    }
                    else
                    {
                        cout.WriteLine("/o undefined sql script file name");
                        return;
                    }

                default:
                    if (!string.IsNullOrEmpty(arg))
                    {
                        RunBatch(arg, args);
                    }
                    else
                    {
                        ShowHelp();
                    }

                    return;
                }
            }


            Shell = new Shell(cfg);
            Context.DS.AddHostObject(Context.SHELL, Shell);
            Shell.DoConsole();
        }
Exemplo n.º 3
0
        public void execute(Command cmd, Side theSide)
        {
            if (cmd.HasHelp)
            {
                stdio.WriteLine("execute sql script files");
                stdio.WriteLine("execute variable_name /s");
                stdio.WriteLine("execute file");
                stdio.WriteLine("       /s                     : execute multiple sql script files defined on the user.cfg");
                stdio.WriteLine("examples:");
                stdio.WriteLine("  execute northwind.sql       : execute single sql script file");
                stdio.WriteLine("  execute db_install /s       : variable db_install = {file1, file2, ...};");
                stdio.WriteLine("                                defined on the user.cfg");
                return;
            }

            string inputfile;
            if (cmd.arg1 != null)
                inputfile = cmd.arg1;
            else
            {
                stdio.ErrorFormat("input undefined");
                return;
            }

            if (cmd.IsSchema)
            {
                string tag = inputfile;
                string[] files = mgr.Configuration.GetValue<string[]>(tag);
                if (files == null)
                {
                    stdio.ErrorFormat("no varible string[] {0} found on config file: {0}", tag);
                    return;
                }

                foreach (var file in files)
                {
                    if (!theSide.ExecuteScript(file))
                    {
                        if (!stdio.YesOrNo("are you sure to continue to run next file(y/n)?"))
                        {
                            stdio.ErrorFormat("interupted on {0}", file);
                            return;
                        }
                    }
                }
            }
            else
                theSide.ExecuteScript(inputfile);
        }