Beispiel #1
0
        private ResultInfoList GetResultInfoList(
            Dictionary <string, IEnumerable <Tuple <string, bool> > > tableColumnNamesList
            , ResultInfoAST.PrimaryKeyCompletion primaryKeyCompletion = ResultInfoAST.PrimaryKeyCompletion.None)
        {
            var stmt = this.GetStmt();

            // SELECT文以外は処理の対象外である
            if (stmt.Type != StmtType.Select)
            {
                return(new ResultInfoList());
            }

            // ResultInfoASTに渡すためのテーブル列情報を作成する
            var tableColumns = new Dictionary <string, IEnumerable <TableResultInfo> >();

            foreach (var tableColumnNames in tableColumnNamesList)
            {
                var tableName           = tableColumnNames.Key;
                var tableResultInfoList = new List <TableResultInfo>();
                foreach (var tableColumnName in tableColumnNames.Value)
                {
                    var isPrimaryKey    = tableColumnName.Item2;
                    var tableResultInfo = new TableResultInfo(tableName, tableColumnName.Item1, !isPrimaryKey, isPrimaryKey);
                    tableResultInfoList.Add(tableResultInfo);
                }
                tableColumns.Add(tableName, tableResultInfoList);
            }
            // SELECT句の解析を行う
            var resultInfoAST = new ResultInfoAST((SelectStmt)stmt, tableColumns, primaryKeyCompletion);

            return(resultInfoAST.GetResultInfoList());
        }
Beispiel #2
0
        public static string GetResultInfoList(string inputText
                                               , DBMSType dbmsType
                                               , Dictionary <string, string> placeHolders = null)
        {
            var ast = MiniSqlParserAST.CreateStmts(inputText, dbmsType);

            var placeHolderNodes = SetPlaceHoldersVisitor.ConvertPlaceHolders(placeHolders);

            // テスト用テーブル列
            var tableColumns = new Dictionary <string, IEnumerable <TableResultInfo> >();
            var tableT       = new List <TableResultInfo>();

            tableT.Add(new TableResultInfo("T", "x", false, true));
            tableT.Add(new TableResultInfo("T", "y", false));
            tableT.Add(new TableResultInfo("T", "z", true));
            tableColumns.Add("T", tableT);
            var tableU = new List <TableResultInfo>();

            tableU.Add(new TableResultInfo("U", "x", false, true));
            tableU.Add(new TableResultInfo("U", "y", false));
            tableU.Add(new TableResultInfo("U", "z", true));
            tableColumns.Add("U", tableU);
            var tableV = new List <TableResultInfo>();

            tableV.Add(new TableResultInfo("V", "x1", false, true));
            tableV.Add(new TableResultInfo("V", "x2", false, true));
            tableV.Add(new TableResultInfo("V", "x3", false, true));
            tableColumns.Add("V", tableV);
            var tableTBL = new List <TableResultInfo>();

            tableTBL.Add(new TableResultInfo("TBL", "COLUMN", false, true));
            tableTBL.Add(new TableResultInfo("TBL", "column", false, true));
            tableColumns.Add("TBL", tableTBL);
            var tableTbl = new List <TableResultInfo>();

            tableTbl.Add(new TableResultInfo("Tbl", "COL", false, true));
            tableTbl.Add(new TableResultInfo("Tbl", "col", false, true));
            tableColumns.Add("Tbl", tableTbl);

            var resultInfoAST = new ResultInfoAST((SelectStmt)ast[0]
                                                  , tableColumns
                                                  , ResultInfoAST.PrimaryKeyCompletion.AllQuery);

            var stringifier = new BeautifulStringifier(144, placeHolderNodes);

            ast.Accept(stringifier);

            return(stringifier.ToString() + System.Environment.NewLine +
                   resultInfoAST.Print(true));
        }