Exemplo n.º 1
0
        public void testGetTableColumn()
        {
            TGetTableColumn getTableColumn = new TGetTableColumn(EDbVendor.dbvoracle);

            getTableColumn.listStarColumn               = false;
            getTableColumn.showTreeStructure            = false;
            getTableColumn.showTableEffect              = true;
            getTableColumn.showColumnLocation           = true;
            getTableColumn.linkOrphanColumnToFirstTable = true;
            getTableColumn.isConsole = false;
            //getTableColumn.setMetaDatabase(new sampleMetaDB());

            String sqlText = "MERGE INTO bonuses D\r\n" +
                             "   USING(SELECT employee_id, salary, department_id FROM employees\r\n" +
                             "   WHERE department_id = 80) S\r\n" +
                             "   ON(D.employee_id = S.employee_id)\r\n" +
                             "   WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary * .01\r\n" +
                             "   WHEN NOT MATCHED THEN INSERT(D.employee_id, D.bonus)\r\n" +
                             "   VALUES(S.employee_id, S.salary * 0.1);";

            getTableColumn.runText(sqlText);
            String[] actualLines = getTableColumn.outList.ToString().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            String   requiredStr = "Tables:\n"
                                   + "bonuses\n"
                                   + "employees\n"
                                   + "Fields:\n"
                                   + "bonuses.bonus\n"
                                   + "bonuses.employee_id\n"
                                   + "employees.department_id\n"
                                   + "employees.employee_id\n"
                                   + "employees.salary";

            String[] requiredLines = requiredStr.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            compareTwoStringArray(requiredLines, actualLines, "Inline Query");
        }
Exemplo n.º 2
0
        private void doGetTableColumn(EDbVendor dbvendor, String sqlText, String requiredStr)
        {
            TGetTableColumn getTableColumn = new TGetTableColumn(dbvendor);

            getTableColumn.listStarColumn               = false;
            getTableColumn.showTreeStructure            = false;
            getTableColumn.showTableEffect              = true;
            getTableColumn.showColumnLocation           = true;
            getTableColumn.linkOrphanColumnToFirstTable = true;
            getTableColumn.isConsole = false;
            //getTableColumn.setMetaDatabase(new sampleMetaDB());

            getTableColumn.runText(sqlText);
            String[] actualLines   = getTableColumn.outList.ToString().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            String[] requiredLines = requiredStr.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            compareTwoStringArray(requiredLines, actualLines, "Inline Query");
        }
Exemplo n.º 3
0
        private void doTableColumnFiles(EDbVendor dbVendor, String dir, List <String> includeFiles)
        {
            if (!Directory.Exists(dir))
            {
                Console.WriteLine("Skip this testcase, directory not exists:" + dir);
                return;
            }

            TGetTableColumn getTableColumn = new TGetTableColumn(dbVendor);

            getTableColumn.listStarColumn               = false;
            getTableColumn.showTreeStructure            = false;
            getTableColumn.showTableEffect              = false;
            getTableColumn.showColumnLocation           = false;
            getTableColumn.linkOrphanColumnToFirstTable = true;
            getTableColumn.isConsole   = false;
            getTableColumn.showSummary = true;


            String[] allFiles = System.IO.Directory.GetFiles(dir, "*.sql", System.IO.SearchOption.AllDirectories);

            foreach (var file in allFiles)
            {
                FileInfo info = new FileInfo(file);
                if (!includeFile(info.Name, includeFiles))
                {
                    continue;
                }
                //sqlFile = new FileInfo(args[argList.IndexOf("/f") + 1]);
                getTableColumn.runText(File.ReadAllText(info.FullName));
                String outFile = Path.ChangeExtension(info.FullName, ".outn");
                if (!File.Exists(outFile))
                {
                    outFile = Path.ChangeExtension(info.FullName, ".out");
                }

                String[] requiredLines = File.ReadAllLines(outFile);
                String[] actualLines   = getTableColumn.outList.ToString().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                compareTwoStringArray(requiredLines, actualLines, info.Name);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            EDbVendor dbVendor = Common.GetEDbVendor(args);

            if (args.Length < 2)
            {
                displayInitInformation();
                return;
            }

            IList <string> argList = new List <string>(args);

            FileInfo sqlFile    = null;
            FileInfo outputFile = null;

            if (argList.IndexOf("/f") != -1 && argList.Count > argList.IndexOf("/f") + 1)
            {
                sqlFile = new FileInfo(args[argList.IndexOf("/f") + 1]);
                if (!sqlFile.Exists)
                {
                    Console.WriteLine(sqlFile + " is not a valid file.");
                    return;
                }
            }

            if (argList.IndexOf("/d") != -1 && argList.Count > argList.IndexOf("/d") + 1)
            {
                sqlFile = new FileInfo(args[argList.IndexOf("/d") + 1]);
                if (!sqlFile.Attributes.HasFlag(FileAttributes.Directory))
                {
                    Console.WriteLine(sqlFile + " is not a valid directory.");
                    return;
                }
            }


            if (sqlFile == null)
            {
                displayInitInformation();
                return;
            }

            if (argList.IndexOf("/o") != -1 && argList.Count > argList.IndexOf("/o") + 1)
            {
                outputFile = new FileInfo(args[argList.IndexOf("/o") + 1]);
                if (!outputFile.Exists)
                {
                    if (!outputFile.Directory.Exists)
                    {
                        Directory.CreateDirectory(outputFile.Directory.FullName);
                    }
                }
            }


            System.IO.FileStream writer = null;
            StreamWriter         sw     = null;

            if (outputFile != null)
            {
                try
                {
                    writer = new System.IO.FileStream(outputFile.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    sw     = new StreamWriter(writer);
                    Console.SetOut(sw);
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }

            TGetTableColumn getTableColumn = new TGetTableColumn(dbVendor);

            getTableColumn.showDetail                   = false;
            getTableColumn.showSummary                  = true;
            getTableColumn.showTreeStructure            = false;
            getTableColumn.showBySQLClause              = false;
            getTableColumn.showJoin                     = false;
            getTableColumn.showColumnLocation           = true;
            getTableColumn.linkOrphanColumnToFirstTable = false;
            getTableColumn.showIndex                    = true;
            getTableColumn.showDatatype                 = true;
            getTableColumn.showTableEffect              = false;

            if (argList.IndexOf("/showDetail") != -1)
            {
                getTableColumn.showSummary = false;
                getTableColumn.showDetail  = true;
            }
            else if (argList.IndexOf("/showTreeStructure") != -1)
            {
                getTableColumn.showSummary       = false;
                getTableColumn.showTreeStructure = true;
            }
            else if (argList.IndexOf("/showBySQLClause") != -1)
            {
                getTableColumn.showSummary     = false;
                getTableColumn.showBySQLClause = true;
            }
            else if (argList.IndexOf("/showJoin") != -1)
            {
                getTableColumn.showSummary = false;
                getTableColumn.showJoin    = true;
            }

            getTableColumn.runFile(sqlFile);


            try
            {
                if (sw != null && writer != null)
                {
                    sw.Close();
                    writer.Close();
                }
                else
                {
                    Console.ReadLine();
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }