Esempio n. 1
0
        public View(TCreateViewSqlStatement view)
        {
            if (view == null)
            {
                throw new System.ArgumentException("Table arguments can't be null.");
            }

            id = ++Table.TABLE_ID;

            this.viewObject = view;

            TSourceToken startToken = viewObject.startToken;
            TSourceToken endToken   = viewObject.endToken;

            if (viewObject.ViewName != null)
            {
                startToken = viewObject.ViewName.startToken;
                endToken   = viewObject.ViewName.endToken;
                this.name  = viewObject.ViewName.ToString();
            }
            else
            {
                this.name = "";
                Console.Error.WriteLine();
                Console.Error.WriteLine("Can't get view name. View is ");
                Console.Error.WriteLine(view.ToString());
            }

            this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
            this.endPosition   = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);
        }
Esempio n. 2
0
        private bool checkCondition(TExpression[] expression)
        {
            string expr = expression[0].ToScript();

            if (string.ReferenceEquals(expr, null))
            {
                return(false);
            }

            if (expr.IndexOf("@") == -1)
            {
                return(true);
            }

            TSourceToken     start  = expression[0].startToken;
            TSourceToken     end    = expression[0].endToken;
            TSourceTokenList stlist = start.container;

            //int t = 0;
            for (int k = start.posinlist; k <= end.posinlist; k++)
            {
                if (stlist[k].tokentype == ETokenType.ttsqlvar)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
        public ResultSet(TParseTreeNode gspObject)
        {
            if (gspObject == null)
            {
                throw new System.ArgumentException("ResultSet arguments can't be null.");
            }

            id = ++Table.TABLE_ID;

            this.gspObject = gspObject;

            TSourceToken startToken = gspObject.startToken;
            TSourceToken endToken   = gspObject.endToken;

            if (startToken != null)
            {
                this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
            }
            else
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine("Can't get start token, the start token is null");
            }
            if (endToken != null)
            {
                this.endPosition = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);
            }
            else
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine("Can't get end token, the end token is null");
            }
        }
        private Boolean isInjected_comment_at_the_end_statement()
        {
            Boolean ret = false;

            if (!this.e_comment_at_the_end_of_statement)
            {
                return(false);
            }
            TSourceToken st = null;

            for (int j = this.sqlParser.SourceTokenList.Count() - 1; j >= 0; j--)
            {
                st = this.sqlParser.SourceTokenList[j];
                if ((st.TokenType == TTokenType.ttWhiteSpace) ||
                    (st.TokenType == TTokenType.ttReturn)
                    )
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
            if ((st.TokenType == TTokenType.ttDoublehyphenComment) || (st.TokenType == TTokenType.ttSlashStarComment))
            {
                this.getSqlInjections().Add(new TSQLInjection(ESQLInjectionType.comment_at_the_end_of_statement));
                ret = true;
            }
            return(ret);
        }
Esempio n. 5
0
        public Table(TTable table)
        {
            if (table == null)
            {
                throw new System.ArgumentException("Table arguments can't be null.");
            }

            id = ++TABLE_ID;

            this.tableObject = table;

            TSourceToken startToken = table.startToken;
            TSourceToken endToken   = table.endToken;

            this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
            this.endPosition   = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);

            if (table.LinkTable != null)
            {
                this.fullName = table.LinkTable.FullName;
                this.name     = table.LinkTable.Name;
                this.alias    = table.Name;
            }
            else
            {
                this.fullName = table.FullName;
                this.name     = table.Name;
                this.alias    = table.AliasName;
            }

            if (table.Subquery != null)
            {
                subquery = true;
            }
        }
 public virtual string renderHighlightingElement(TSourceToken token)
 {
     if (!isInit)
     {
         init();
     }
     return(render.renderToken(token));
 }
Esempio n. 7
0
        private void checkTryCatchClause(procedureInfo procedureInfo, TMssqlCreateProcedure procedure)
        {
            TSourceTokenList tokenList = procedure.sourcetokenlist;

            for (int i = 0; i < tokenList.size(); i++)
            {
                TSourceToken token = tokenList.get(i);
                if (token.tokentype == ETokenType.ttkeyword && token.astext.Trim().Equals("try", StringComparison.OrdinalIgnoreCase))
                {
                    procedureInfo.hasTryCatch = true;
                }
            }
        }
Esempio n. 8
0
        public void testMdxTokenlizer3()
        {
            TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmdx);

            sqlparser.sqltext = "SELECT Measures.MEMBERS^ ON COLUMNS,\n" + "Product.Style.CHILDREN ON ROWS\n" + "FROM [Total Profit [Domestic]]]\t\n" + ";";
            sqlparser.tokenizeSqltext();
            string outstr = "";

            for (int i = 0; i < sqlparser.sourcetokenlist.size(); i++)
            {
                TSourceToken st = sqlparser.sourcetokenlist.get(i);
                outstr += string.Format("{0},type:{1},code:{2:D}\n", st.tokentype == ETokenType.ttreturn ? "linebreak" : st.ToString(), st.tokentype, st.tokencode);
            }
            // System.out.println(outstr);
            Assert.IsTrue(outstr.Trim().Equals("SELECT,type:ttkeyword,code:301\n" + " ,type:ttwhitespace,code:259\n" + "Measures,type:ttidentifier,code:264\n" + ".,type:ttperiod,code:46\n" + "MEMBERS,type:ttkeyword,code:630\n" + "^,type:ttcaret,code:94\n" + " ,type:ttwhitespace,code:259\n" + "ON,type:ttkeyword,code:323\n" + " ,type:ttwhitespace,code:259\n" + "COLUMNS,type:ttkeyword,code:559\n" + ",,type:ttcomma,code:44\n" + "linebreak,type:ttreturn,code:260\n" + "Product,type:ttidentifier,code:264\n" + ".,type:ttperiod,code:46\n" + "Style,type:ttidentifier,code:264\n" + ".,type:ttperiod,code:46\n" + "CHILDREN,type:ttkeyword,code:555\n" + " ,type:ttwhitespace,code:259\n" + "ON,type:ttkeyword,code:323\n" + " ,type:ttwhitespace,code:259\n" + "ROWS,type:ttkeyword,code:661\n" + "linebreak,type:ttreturn,code:260\n" + "FROM,type:ttkeyword,code:329\n" + " ,type:ttwhitespace,code:259\n" + "[Total Profit [Domestic]]],type:ttidentifier,code:282\n" + "\t,type:ttwhitespace,code:259\n" + "linebreak,type:ttreturn,code:260\n" + ";,type:ttsemicolon,code:59", StringComparison.CurrentCultureIgnoreCase));
        }
Esempio n. 9
0
        public void testTokenlizer7()
        {
            TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmdx);

            sqlparser.sqltext = "SELECT \n" + "[x].&foo&[1]&bar.[y] ON 0\n" + "FROM [Adventure Works];";

            sqlparser.tokenizeSqltext();
            string outstr = "";

            for (int i = 0; i < sqlparser.sourcetokenlist.size(); i++)
            {
                TSourceToken st = sqlparser.sourcetokenlist.get(i);
                outstr += string.Format("{0},type:{1},code:{2:D}\n", st.tokentype == ETokenType.ttreturn ? "linebreak" : st.ToString(), st.tokentype, st.tokencode);
            }
            // System.out.println(outstr);
            Assert.IsTrue(outstr.Trim().Equals("SELECT,type:ttkeyword,code:301\n" + " ,type:ttwhitespace,code:259\n" + "linebreak,type:ttreturn,code:260\n" + "[x],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "&foo,type:ttidentifier,code:286\n" + "&[1],type:ttidentifier,code:285\n" + "&bar,type:ttidentifier,code:286\n" + ".,type:ttperiod,code:46\n" + "[y],type:ttidentifier,code:282\n" + " ,type:ttwhitespace,code:259\n" + "ON,type:ttkeyword,code:323\n" + " ,type:ttwhitespace,code:259\n" + "0,type:ttnumber,code:263\n" + "linebreak,type:ttreturn,code:260\n" + "FROM,type:ttkeyword,code:329\n" + " ,type:ttwhitespace,code:259\n" + "[Adventure Works],type:ttidentifier,code:282\n" + ";,type:ttsemicolon,code:59", StringComparison.CurrentCultureIgnoreCase));
        }
Esempio n. 10
0
        public void testMdxTokenlizer5()
        {
            TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmdx);

            sqlparser.sqltext = "// This member returns the gross profit margin for product types\n" + "// and reseller types crossjoined by year.\n" + "SELECT \n" + "    [Date].[Calendar Time].[Calendar Year].Members *\n" + "      [Reseller].[Reseller Type].Children ON 0,\n" + "    [Product].[Category].[Category].Members ON 1\n" + "FROM // Select from the Adventure Works cube.\n" + "    [Adventure Works]\n" + "WHERE\n" + "    [Measures].[Gross Profit Margin]\n" + ";";

            sqlparser.tokenizeSqltext();
            string outstr = "";

            for (int i = 0; i < sqlparser.sourcetokenlist.size(); i++)
            {
                TSourceToken st = sqlparser.sourcetokenlist.get(i);
                outstr += string.Format("{0},type:{1},code:{2:D}\n", st.tokentype == ETokenType.ttreturn ? "linebreak" : st.ToString(), st.tokentype, st.tokencode);
            }
            // System.out.println(outstr);
            Assert.IsTrue(outstr.Trim().Equals("// This member returns the gross profit margin for product types,type:ttCPPComment,code:258\n" + "linebreak,type:ttreturn,code:260\n" + "// and reseller types crossjoined by year.,type:ttCPPComment,code:258\n" + "linebreak,type:ttreturn,code:260\n" + "SELECT,type:ttkeyword,code:301\n" + " ,type:ttwhitespace,code:259\n" + "linebreak,type:ttreturn,code:260\n" + "[Date],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Calendar Time],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Calendar Year],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "Members,type:ttkeyword,code:630\n" + " ,type:ttwhitespace,code:259\n" + "*,type:ttasterisk,code:42\n" + "linebreak,type:ttreturn,code:260\n" + "[Reseller],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Reseller Type],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "Children,type:ttkeyword,code:555\n" + " ,type:ttwhitespace,code:259\n" + "ON,type:ttkeyword,code:323\n" + " ,type:ttwhitespace,code:259\n" + "0,type:ttnumber,code:263\n" + ",,type:ttcomma,code:44\n" + "linebreak,type:ttreturn,code:260\n" + "[Product],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Category],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Category],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "Members,type:ttkeyword,code:630\n" + " ,type:ttwhitespace,code:259\n" + "ON,type:ttkeyword,code:323\n" + " ,type:ttwhitespace,code:259\n" + "1,type:ttnumber,code:263\n" + "linebreak,type:ttreturn,code:260\n" + "FROM,type:ttkeyword,code:329\n" + " ,type:ttwhitespace,code:259\n" + "// Select from the Adventure Works cube.,type:ttCPPComment,code:258\n" + "linebreak,type:ttreturn,code:260\n" + "[Adventure Works],type:ttidentifier,code:282\n" + "linebreak,type:ttreturn,code:260\n" + "WHERE,type:ttkeyword,code:317\n" + "linebreak,type:ttreturn,code:260\n" + "[Measures],type:ttidentifier,code:282\n" + ".,type:ttperiod,code:46\n" + "[Gross Profit Margin],type:ttidentifier,code:282\n" + "linebreak,type:ttreturn,code:260\n" + ";,type:ttsemicolon,code:59", StringComparison.CurrentCultureIgnoreCase));
        }
Esempio n. 11
0
        public void testCTEMainQueryToString()
        {
            String varname1 = "";

            varname1 = varname1 + "WITH prep1 " + "\n";
            varname1 = varname1 + "     AS ( SELECT 'First' AS colval, " + "\n";
            varname1 = varname1 + "                 1       AS joincol " + "\n";
            varname1 = varname1 + "          FROM " + "\n";
            varname1 = varname1 + "            SYSIBM.sysdummy1 ) , prep2 " + "\n";
            varname1 = varname1 + "     AS ( SELECT 'Second' AS colval, " + "\n";
            varname1 = varname1 + "                 1        AS joincol " + "\n";
            varname1 = varname1 + "          FROM " + "\n";
            varname1 = varname1 + "            SYSIBM.sysdummy1 ) , prep3 " + "\n";
            varname1 = varname1 + "     AS ( SELECT 'Third' AS colval, " + "\n";
            varname1 = varname1 + "                 1       AS joincol " + "\n";
            varname1 = varname1 + "          FROM " + "\n";
            varname1 = varname1 + "            SYSIBM.sysdummy1 ) " + "\n";
            varname1 = varname1 + "SELECT prep1.colval AS firstcolval, " + "\n";
            varname1 = varname1 + "       prep2.colval AS secondcolval, " + "\n";
            varname1 = varname1 + "       prep3.colval " + "\n";
            varname1 = varname1 + "FROM " + "\n";
            varname1 = varname1 + "  prep1 " + "\n";
            varname1 = varname1 + "  INNER JOIN prep2 " + "\n";
            varname1 = varname1 + "  ON prep1.joincol = prep2.joincol " + "\n";
            varname1 = varname1 + "  INNER JOIN prep3 " + "\n";
            varname1 = varname1 + "  ON prep1.joincol = prep3.joincol";

            TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvdb2);

            sqlparser.sqltext = varname1;
            Assert.IsTrue(sqlparser.parse() == 0);

            TSelectSqlStatement select = (TSelectSqlStatement)sqlparser.sqlstatements.get(0);
            TSourceToken        st     = select.startToken; // keep origin start token

            select.startToken = select.SelectToken;
            //Console.WriteLine(select.ToString());
            select.startToken = st; // restore to origin start token
            //Console.WriteLine(select.ToString());
        }
Esempio n. 12
0
 private void checkFunction(spInfo spInfo, TSourceTokenList tokenList)
 {
     for (int i = 0; i < tokenList.size(); i++)
     {
         TSourceToken token = tokenList.get(i);
         if (token.DbObjType == EDbObjectType.function)
         {
             List <TParseTreeNode> list = token.nodesStartFromThisToken;
             for (int j = 0; j < list.Count; j++)
             {
                 TParseTreeNode node = (TParseTreeNode)list[j];
                 if (node is TFunctionCall)
                 {
                     builtInFunctionInfo function = new builtInFunctionInfo();
                     function.function = token.astext;
                     function.lineNo   = token.lineNo;
                     function.columnNo = token.columnNo;
                     TCustomSqlStatement stmt = token.stmt;
                     if (stmt == null)
                     {
                         bool flag = false;
                         for (int k = token.posinlist - 1; k >= 0; k--)
                         {
                             TSourceToken before = node.Gsqlparser.sourcetokenlist.get(k);
                             if (token.nodesStartFromThisToken != null)
                             {
                                 for (int z = 0; z < before.nodesStartFromThisToken.Count; z++)
                                 {
                                     if (before.nodesStartFromThisToken[z] is TCustomSqlStatement)
                                     {
                                         TCustomSqlStatement tempStmt = (TCustomSqlStatement)before.nodesStartFromThisToken[z];
                                         if (tempStmt.startToken.posinlist <= token.posinlist && tempStmt.endToken.posinlist >= token.posinlist)
                                         {
                                             stmt = tempStmt;
                                             flag = true;
                                             break;
                                         }
                                     }
                                 }
                             }
                             if (flag)
                             {
                                 break;
                             }
                         }
                     }
                     if (stmt is TInsertSqlStatement)
                     {
                         function.stmtType = usageType.Insert;
                     }
                     else if (stmt is TSelectSqlStatement)
                     {
                         function.stmtType = usageType.Read;
                     }
                     else if (stmt is TUpdateSqlStatement)
                     {
                         function.stmtType = usageType.Update;
                     }
                     else if (stmt is TDeleteSqlStatement)
                     {
                         function.stmtType = usageType.Delete;
                     }
                     else if (stmt is TMssqlDropTable)
                     {
                         function.stmtType = usageType.Drop;
                     }
                     else if (stmt is TDropTableSqlStatement)
                     {
                         function.stmtType = usageType.Drop;
                     }
                     else if (stmt is TMssqlExecute)
                     {
                         function.stmtType = usageType.Exec;
                     }
                     else if (stmt is TMssqlCreateProcedure)
                     {
                         function.stmtType = usageType.Create;
                     }
                     spInfo.functions.Add(function);
                 }
             }
         }
     }
 }
Esempio n. 13
0
        public virtual string renderToken(TSourceToken token)
        {
            bool       isLineBreak = false;
            string     tokenString = token.astext;
            ETokenType type        = token.tokentype;

            tokenString = tokenString.Replace(" ", "&nbsp;");
            tokenString = tokenString.Replace("\t", option.tabHtmlString);

            if (ETokenType.ttwhitespace.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSpan).render(tokenString);
            }
            else if (ETokenType.ttreturn.Equals(type))
            {
                if (tokenString.Contains(RETURN_CODE))
                {
                    tokenString = tokenString.Replace(RETURN_CODE, RETURN_CODE + "<br>");
                }
                else
                {
                    tokenString = tokenString.Replace("\n", RETURN_CODE + "<br>");
                }
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSpan).render(tokenString);
                isLineBreak = true;
            }
            else if (ETokenType.ttsimplecomment.Equals(type))
            {
                tokenString = tokenString.Replace("--", "&#45;&#45;");
                if (TCompactMode.Cpmugly.Equals(option.compactMode))
                {
                    tokenString = ("/* " + tokenString + "*/");
                }
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkComment_dh).render(tokenString);
            }
            else if (ETokenType.ttbracketedcomment.Equals(type))
            {
                if (tokenString.Contains(RETURN_CODE))
                {
                    tokenString = tokenString.Replace(RETURN_CODE, RETURN_CODE + "<br>");
                }
                else
                {
                    tokenString = tokenString.Replace("\n", RETURN_CODE + "<br>");
                }
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkComment_dh).render(tokenString);
            }
            else if (ETokenType.ttidentifier.Equals(type) || ETokenType.ttdqstring.Equals(type) || ETokenType.ttdbstring.Equals(type) || ETokenType.ttbrstring.Equals(type))
            {
                if (ETokenType.ttdqstring.Equals(type) || ETokenType.ttdbstring.Equals(type))
                {
                    tokenString = tokenString.Replace("\"", "&quot;");
                }

                int dbObjType = (int)token.DbObjType;
                switch (dbObjType)
                {
                case TObjectName.ttobjFunctionName:
                    if (isVendorBuiltInFunction(tokenString, dbVendor))
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkBuiltInFunction).render(tokenString);
                    }
                    else
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkFunction).render(tokenString);
                    }
                    break;

                case TObjectName.ttobjDatatype:
                    tokenString = config.getHighlightingElementRender(HighlightingElement.sfkDatatype).render(tokenString);
                    break;

                default:
                    if (EDbVendor.dbvmssql.Equals(dbVendor) && isMSSQLSystemVar(tokenString))
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkMssqlsystemvar).render(tokenString);
                    }
                    else
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkIdentifer).render(tokenString);
                    }
                    break;
                }
            }
            else if (ETokenType.ttnumber.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkNumber).render(tokenString);
            }
            else if (ETokenType.ttsqstring.Equals(type))
            {
                tokenString = tokenString.Replace("&nbsp;", " ");
                tokenString = tokenString.Replace("&", "&#38;");
                tokenString = tokenString.Replace(" ", "&nbsp;");
                tokenString = tokenString.Replace("\"", "&quot;");
                tokenString = tokenString.Replace("<", "&#60;");
                if (tokenString.Contains(RETURN_CODE))
                {
                    tokenString = tokenString.Replace(RETURN_CODE, RETURN_CODE + "<br>");
                }
                else
                {
                    tokenString = tokenString.Replace("\n", RETURN_CODE + "<br>");
                }
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSQString).render(tokenString);
            }
            else if (ETokenType.ttkeyword.Equals(type))
            {
                int dbObjType = (int)token.DbObjType;
                switch (dbObjType)
                {
                case TObjectName.ttobjFunctionName:
                    if (isVendorBuiltInFunction(tokenString, dbVendor))
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkBuiltInFunction).render(tokenString);
                    }
                    else
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkFunction).render(tokenString);
                    }
                    break;

                case TObjectName.ttobjDatatype:
                    tokenString = config.getHighlightingElementRender(HighlightingElement.sfkDatatype).render(tokenString);
                    break;

                default:
                    if (EDbVendor.dbvmssql.Equals(dbVendor) && isMSSQLSystemVar(tokenString))
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkMssqlsystemvar).render(tokenString);
                    }
                    else
                    {
                        tokenString = config.getHighlightingElementRender(HighlightingElement.sfkStandardkeyword).render(tokenString);
                    }
                    break;
                }
            }
            else if (ETokenType.ttsqlvar.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfksqlvar).render(tokenString);
            }
            else if (ETokenType.ttbindvar.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkbindvar).render(tokenString);
            }
            else if (ETokenType.ttmulticharoperator.Equals(type))
            {
                tokenString = tokenString.Replace("<", "&lt;");
                tokenString = tokenString.Replace(">", "&gt;");
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSymbol).render(tokenString);
            }
            else if (ETokenType.ttsinglecharoperator.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSymbol).render(tokenString);
            }
            else if (ETokenType.ttcomma.Equals(type) || ETokenType.ttperiod.Equals(type) || ETokenType.ttsemicolon.Equals(type) || ETokenType.ttdolorsign.Equals(type) || ETokenType.ttcolon.Equals(type) || ETokenType.ttplussign.Equals(type) || ETokenType.ttminussign.Equals(type) || ETokenType.ttasterisk.Equals(type) || ETokenType.ttslash.Equals(type) || ETokenType.ttstmt_delimiter.Equals(type) || ETokenType.ttequals.Equals(type) || ETokenType.ttatsign.Equals(type) || ETokenType.ttsemicolon2.Equals(type) || ETokenType.ttsemicolon3.Equals(type) || ETokenType.ttquestionmark.Equals(type))
            // || ETokenType.ttOpenSquareBracket.equals( type )
            // || ETokenType.ttCloseSquareBracket.equals( type )
            // || ETokenType.ttdot.equals( type )
            // || ETokenType.ttmulti.equals( type )
            // || ETokenType.ttHat.equals( type )
            // || ETokenType.ttDiv.equals( type )
            // || ETokenType.ttBitWise.equals( type )
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSymbol).render(tokenString);
            }
            else if (ETokenType.ttlessthan.Equals(type))
            {
                tokenString = "&lt;";
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSymbol).render(tokenString);
            }
            else if (ETokenType.ttgreaterthan.Equals(type))
            {
                tokenString = "&gt;";
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkSymbol).render(tokenString);
            }
            else if (ETokenType.ttleftparenthesis.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkopenbracket).render(tokenString);
            }
            else if (ETokenType.ttrightparenthesis.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkclosebracket).render(tokenString);
            }
            else if (ETokenType.ttsqlpluscmd.Equals(type))
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkOraclesqlplus).render(tokenString);
            }
            // else if ( ETokenType.ttUserCustomized.equals( type )){
            // tokenString = config.getHighlightingElementRender(
            // HighlightingElement.sfkUserCustomized )
            // .render( tokenString );
            // }
            else
            {
                tokenString = config.getHighlightingElementRender(HighlightingElement.sfkDefault).render(tokenString);
            }

            if (TCompactMode.Cpmugly.Equals(option.compactMode))
            {
                if (isLineBreak)
                {
                    tokenString += "\r\n";
                }
            }
            return(tokenString);
        }
Esempio n. 14
0
        private void modifyTableName(TCustomSqlStatement stmt)
        {
            for (int k = 0; k < stmt.tables.size(); k++)
            {
                TTable table = stmt.tables.getTable(k);

                bool isfound = false;
                for (int m = 0; m < table.LinkedColumns.size(); m++)
                {
                    TObjectName column = table.LinkedColumns.getObjectName(m);
                    isfound = false;
                    if (column.TableString != null && column.TableString.Equals(this.sourceTable, StringComparison.OrdinalIgnoreCase))
                    {
                        isfound = true;
                        if (!string.ReferenceEquals(this.sourceSchema, null))
                        { // check schema of this
                          // table
                            if (column.SchemaString != null)
                            {
                                isfound = this.sourceSchema.Equals(column.SchemaString, StringComparison.OrdinalIgnoreCase);
                            }
                            else
                            {
                                isfound = false;
                            }
                        }
                    }

                    if (isfound)
                    {
                        // rename this table
                        TSourceToken st = column.ColumnToken;
                        if (column.TableString != null)
                        {
                            column.TableToken.String = this.targetTable;
                        }
                        else
                        {
                            st.String = this.targetTable + "." + st.astext;
                        }

                        if (!string.ReferenceEquals(this.targetSchema, null))
                        {
                            if (column.SchemaString != null)
                            {
                                column.SchemaToken.String = this.targetSchema;
                            }
                            else if (column.TableString != null)
                            {
                                column.TableToken.String = this.targetSchema + "." + column.TableString;
                            }
                            else
                            {
                                st.String = this.targetSchema + "." + st.astext;
                            }
                        }

                        this.renamedObjectsNum++;
                    }
                }

                if (table.TableName != null && table.TableName.TableString != null && table.TableName.TableString.Equals(this.sourceTable, StringComparison.OrdinalIgnoreCase))
                {
                    isfound = true;
                    if (!string.ReferenceEquals(this.sourceSchema, null))
                    { // check schema of this table
                        if (table.TableName.SchemaString != null)
                        {
                            isfound = this.sourceSchema.Equals(table.TableName.SchemaString, StringComparison.OrdinalIgnoreCase);
                        }
                        else
                        {
                            isfound = false;
                        }
                    }
                }

                if (isfound)
                {
                    if (table.TableName != null)
                    {
                        // rename this table
                        TSourceToken st = table.TableName.TableToken;
                        st.String = this.targetTable;
                        if (!string.ReferenceEquals(this.targetSchema, null))
                        {
                            if (table.PrefixSchema != null)
                            {
                                table.TableName.SchemaToken.String = this.targetSchema;
                            }
                            else
                            {
                                st.String = this.targetSchema + "." + st.astext;
                            }
                        }
                        this.renamedObjectsNum++;
                    }
                }
            }

            for (int j = 0; j < stmt.Statements.size(); j++)
            {
                modifyTableName(stmt.Statements.get(j));
            }
        }
        public SelectSetResultColumn(ResultSet resultSet, ResultColumn resultColumn)
        {
            if (resultColumn == null || resultSet == null)
            {
                throw new System.ArgumentException("ResultColumn arguments can't be null.");
            }

            id = ++TableColumn.TABLE_COLUMN_ID;

            this.resultSet = resultSet;
            resultSet.addColumn(this);

            if (resultColumn.ColumnObject is TResultColumn)
            {
                TResultColumn resultColumnObject = (TResultColumn)resultColumn.ColumnObject;
                if (resultColumnObject.AliasClause != null)
                {
                    this.alias = resultColumnObject.AliasClause.ToString();
                    TSourceToken aliasStartToken = resultColumnObject.AliasClause.startToken;
                    TSourceToken aliasEndToken   = resultColumnObject.AliasClause.endToken;
                    this.aliasStartPosition = new Tuple <long, long>(aliasStartToken.lineNo, aliasStartToken.columnNo);
                    this.aliasEndPosition   = new Tuple <long, long>(aliasEndToken.lineNo, aliasEndToken.columnNo + aliasEndToken.astext.Length);

                    this.name = this.alias;
                }
                else
                {
                    if (resultColumnObject.Expr.ExpressionType == EExpressionType.simple_constant_t)
                    {
                        if (resultSet is SelectResultSet)
                        {
                            this.name = "DUMMY" + getIndexOf(((SelectResultSet)resultSet).ResultColumnObject, resultColumnObject);
                        }
                        else if (resultSet is SelectSetResultSet)
                        {
                            this.name = "DUMMY" + getIndexOf(((SelectSetResultSet)resultSet).ResultColumnObject, resultColumnObject);
                        }
                        else
                        {
                            this.name = resultColumnObject.ToString();
                        }
                    }
                    else if (resultColumnObject.Expr.ExpressionType == EExpressionType.function_t)
                    {
                        this.name = resultColumnObject.Expr.FunctionCall.FunctionName.ToString();
                    }
                    else if (resultColumnObject.ColumnNameOnly != null && !"".Equals(resultColumnObject.ColumnNameOnly))
                    {
                        this.name = resultColumnObject.ColumnNameOnly;
                    }
                    else
                    {
                        this.name = resultColumnObject.ToString();
                    }
                }

                if (resultColumnObject.Expr.ExpressionType == EExpressionType.function_t)
                {
                    this.fullName = resultColumnObject.Expr.FunctionCall.FunctionName.ToString();
                }
                else
                {
                    this.fullName = resultColumnObject.ToString();
                }

                TSourceToken startToken = resultColumnObject.startToken;
                TSourceToken endToken   = resultColumnObject.endToken;
                this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
                this.endPosition   = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);
                this.columnObject  = resultColumnObject;
            }
            else if (resultColumn.ColumnObject is TObjectName)
            {
                TObjectName resultColumnObject = (TObjectName)resultColumn.ColumnObject;

                if (resultColumnObject.ColumnNameOnly != null && !"".Equals(resultColumnObject.ColumnNameOnly))
                {
                    this.name = resultColumnObject.ColumnNameOnly;
                }
                else
                {
                    this.name = resultColumnObject.ToString();
                }

                this.fullName = this.name;

                TSourceToken startToken = resultColumnObject.startToken;
                TSourceToken endToken   = resultColumnObject.endToken;
                this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
                this.endPosition   = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);
                this.columnObject  = resultColumnObject;
            }
            else
            {
                this.name     = resultColumn.Name;
                this.fullName = this.name;

                TSourceToken startToken = resultColumn.ColumnObject.startToken;
                TSourceToken endToken   = resultColumn.ColumnObject.endToken;
                this.startPosition = new Tuple <long, long>(startToken.lineNo, startToken.columnNo);
                this.endPosition   = new Tuple <long, long>(endToken.lineNo, endToken.columnNo + endToken.astext.Length);
                this.columnObject  = resultColumn.ColumnObject;
            }
        }