private void autodetectBlockContent() { sqlPlusKeyword = ""; string upperToken = token.ToUpper(); int tokenCountWithoutCommentsAndDetour = tokenCountWithoutComments - detourTaken; // System.Console.WriteLine("---------------------------------------------------------------------"); // System.Console.WriteLine("tokenCountWithoutComments={0} currCommand.action={1} upperToken={2}", tokenCountWithoutComments, currCommand.action, upperToken); // System.Console.WriteLine("tokenCountWithoutCommentsAndDetour == {0}, detourTaken = {1}", tokenCountWithoutCommentsAndDetour, detourTaken); // System.Console.WriteLine("autodetectMode = {1}, currCommand.cmdType = {0}", currCommand.cmdType, autodetectMode); if (autodetectMode == AutodetectMode.Normal || autodetectMode == AutodetectMode.ObjectName) { // detour detection ////////////////////////////////////////////////////////////////////////////////////////////// // CREATE [OR REPLACE] ... checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "OR", "OR REPLACE"); // UPDATE [ONLY] (....) .... checkForAndBeginDetour(1, CommandTypes.Sql, "UPDATE", "ONLY", "UPDATE ONLY"); // UPDATE [(]SELECT EMPNO FROM EMP) .... checkForAndBeginDetour(1, CommandTypes.Sql, "UPDATE", "(", "UPDATE SUBQUERY"); // INSERT INTO (....) .... checkForAndBeginDetour(1, CommandTypes.Sql, "INSERT", "INTO", "INSERT INTO"); // INSERT INTO (SUBQUERY) .... checkForAndBeginDetour(1, CommandTypes.Sql, "INSERT", "(", "INSERT SUBQUERY"); // DELETE FROM (....) .... checkForAndBeginDetour(1, CommandTypes.Sql, "DELETE", "FROM", "DELETE FROM"); // DELETE (SUBQUERY) .... checkForAndBeginDetour(1, CommandTypes.Sql, "DELETE", "(", "DELETE SUBQUERY"); // DELETE ONLY .... checkForAndBeginDetour(1, CommandTypes.Sql, "DELETE", "ONLY", "DELETE ONLY"); // CREATE [GLOBAL TEMPORARY] TABLE checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "GLOBAL", "GLOBAL TEMPORARY"); // CREATE [PUBLIC] SYNONYM, DATABASE LINK checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "PUBLIC", "PUBLIC"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "PUBLIC", "PUBLIC"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "PUBLIC", "PUBLIC"); checkForAndBeginDetour(1, CommandTypes.Unknown, "DROP", "PUBLIC", "PUBLIC"); checkForAndBeginDetour(1, CommandTypes.Unknown, "ALTER", "PUBLIC", "PUBLIC"); // CREATE [PRIVATE] OUTLINE checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "PRIVATE", "PRIVATE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "PRIVATE", "PRIVATE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "PRIVATE", "PRIVATE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "ALTER", "PRIVATE", "PRIVATE"); // CREATE [SHARED] PUBLIC DATABASE LINK checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "SHARED", "SHARED"); checkForAndBeginDetour(1, CommandTypes.Unknown, "ALTER", "SHARED", "SHARED"); // CREATE BIGFILE TABLESPACE checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "BIGFILE", "BIGFILE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "UNDO", "UNDO"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "TEMPORARY", "TEMPORARY"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "SMALLFILE", "SMALLFILE"); // CREATE UNIQUE INDEX checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "UNIQUE", "UNIQUE"); // CREATE BITMAP INDEX checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "BITMAP", "BITMAP"); // CREATE EDITIONING VIEW checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "EDITIONING", "EDITIONING"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "EDITIONING", "EDITIONING"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "EDITIONING", "EDITIONING"); // CREATE FORCE VIEW checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "FORCE", "FORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "FORCE", "FORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "FORCE", "FORCE"); // CREATE NO FORCE VIEW checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "NO", "NO FORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "NO", "NO FORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "NO", "NO FORCE"); // CREATE OR REPLACE (AND (RESOLVE | COMPILE)) JAVA checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "AND", "AND RESOLVE COMPILE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "AND", "AND RESOLVE COMPILE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "AND", "AND RESOLVE COMPILE"); // CREATE OR REPLACE NOFORCE JAVA checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE", "NOFORCE", "NOFORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "REPLACE", "NOFORCE", "NOFORCE"); checkForAndBeginDetour(1, CommandTypes.Unknown, "CREATE OR REPLACE", "NOFORCE", "NOFORCE"); // CREATE FLASHBACK ARCHIVE DEFAULT ... checkForAndBeginDetour(3, CommandTypes.Sql, "CREATE", "FLASHBACK ARCHIVE", "DEFAULT", "DEFAULT"); // CREATE TYPE TEST OID 'xyz' ... checkForAndBeginDetour(3, CommandTypes.Sql, "CREATE", "TYPE", "OID", "OID"); checkForAndBeginDetour(3, CommandTypes.Sql, "REPLACE", "TYPE", "OID", "OID"); checkForAndBeginDetour(3, CommandTypes.Sql, "CREATE OR REPLACE", "TYPE", "OID", "OID"); // CREATE TYPE TEST TIMESTAMP 'xyz' ... checkForAndBeginDetour(3, CommandTypes.Sql, "CREATE", "TYPE", "TIMESTAMP", "TIMESTAMP"); checkForAndBeginDetour(3, CommandTypes.Sql, "REPLACE", "TYPE", "TIMESTAMP", "TIMESTAMP"); checkForAndBeginDetour(3, CommandTypes.Sql, "CREATE OR REPLACE", "TYPE", "TIMESTAMP", "TIMESTAMP"); // FLASHBACK STANDBY DATABASE TO TIMESTAMP SYSDATE-1; checkForAndBeginDetour(1, CommandTypes.Sql, "FLASHBACK", "STANDBY", "STANDBY"); // REVOKE ... ON [DIRECTORY|EDITION|MINING MODEL|JAVA SOURCE|JAVA RESOURCE] schema.object if (currCommand.action == "REVOKE" && autodetectMode == AutodetectMode.ObjectName && (upperToken == "JAVA" || upperToken == "MINING" || upperToken == "EDITION" || upperToken == "DIRECTORY")) { autodetectMode = AutodetectMode.Detour; detourStart = tokenCountWithoutComments; detourPath = "REVOKE_OBJECT_CLAUSE"; } } if (autodetectMode == AutodetectMode.ObjectNameList) { if (listTerminatorTokenHashSet.ContainsKey(token.ToUpper())) autodetectMode = AutodetectMode.Normal; else { if (currCommand.objectName == "") detourTaken = detourTaken - 1; if (token == listSeparator) { appendObjectName(token); detourTaken = detourTaken + 1; } else { appendObjectName(token); detourTaken = detourTaken + 1; } } } if (autodetectMode == AutodetectMode.SecondaryObjectNameList) { if (listTerminatorTokenHashSet.ContainsKey(token.ToUpper())) autodetectMode = AutodetectMode.Normal; else { if (currCommand.secondaryObjectName == "") detourTaken = detourTaken - 1; if (token == listSeparator) { appendSecondaryObject(token); detourTaken = detourTaken + 1; } else { appendSecondaryObject(token); detourTaken = detourTaken + 1; } } } if (autodetectMode == AutodetectMode.CommandNameList) { if (listTerminatorTokenHashSet.ContainsKey(token.ToUpper())) autodetectMode = AutodetectMode.Normal; else { if (currCommand.cmdName == "") detourTaken = detourTaken - 1; if (token == listSeparator) { appendCurrCmdName(token); detourTaken = detourTaken + 1; } else { appendCurrCmdName(token); detourTaken = detourTaken + 1; } } } if (autodetectMode == AutodetectMode.Detour) { // System.Console.WriteLine("detourStart == {0}", detourStart); int detourTokenCountWithoutComments = tokenCountWithoutComments - detourStart + 1; // CREATE --> OR REPLACE <-- // Affects CommandObject.Action handleDetourStep("OR REPLACE", 1, "OR", false); if (handleDetourStep("OR REPLACE", 2, "REPLACE", true)) currCommand.action = currCommand.action + " " + detourPath; // UPDATE ONLY (....) .... handleDetourStep("UPDATE ONLY", 1, "ONLY", true); // UPDATE (SELECT EMPNO FROM EMP) .... handleDetourStep("UPDATE SUBQUERY", 1, "(", true); // INSERT INTO (....) .... handleDetourStep("INSERT INTO", 1, "INTO", true); // INSERT INTO (SELECT EMPNO FROM EMP) .... handleDetourStep("INSERT SUBQUERY", 1, "(", true); // DELETE FROM (....) .... handleDetourStep("DELETE FROM", 1, "FROM", true); // DELETE (SUBQUERY) .... handleDetourStep("DELETE SUBQUERY", 1, "(", true); // DELETE ONLY .... handleDetourStep("DELETE ONLY", 1, "ONLY", false); handleDetourStep("DELETE ONLY", 2, "(", true); // CREATE --> GLOBAL TEMPORARY <-- TABLE // Affects CommandObject.Action handleDetourStep("GLOBAL TEMPORARY", 1, "GLOBAL", false); if (handleDetourStep("GLOBAL TEMPORARY", 2, "TEMPORARY", true)) appendCurrCmdName(detourPath); // CREATE --> PUBLIC <-- SYNONYM || DATABASE LINK // Affects CommandObject.CmdName if (handleDetourStep("PUBLIC", 1, "PUBLIC", true)) appendCurrCmdName(detourPath); // CREATE --> PRIVATE <-- OUTLINE // Affects CommandObject.CmdName if (handleDetourStep("PRIVATE", 1, "PRIVATE", true)) appendCurrCmdName(detourPath); // CREATE --> SHARED <-- PUBLIC DATABASE LINK // Affects CommandObject.CmdName if (handleDetourStep("SHARED", 1, "SHARED", true)) appendCurrCmdName(detourPath); // CREATE --> BIGFILE <-- // Affects CommandObject.CmdName if (handleDetourStep("BIGFILE", 1, "BIGFILE", true)) appendCurrCmdName(detourPath); if (handleDetourStep("TEMPORARY", 1, "TEMPORARY", true)) appendCurrCmdName(detourPath); if (handleDetourStep("UNDO", 1, "UNDO", true)) appendCurrCmdName(detourPath); if (handleDetourStep("SMALLFILE", 1, "SMALLFILE", true)) appendCurrCmdName(detourPath); // CREATE --> BITMAP <-- // Affects CommandObject.CmdName if (handleDetourStep("BITMAP", 1, "BITMAP", true)) appendCurrCmdName(detourPath); // CREATE --> UNIQUE <-- // Affects CommandObject.CmdName if (handleDetourStep("UNIQUE", 1, "UNIQUE", true)) appendCurrCmdName(detourPath); // CREATE --> EDITIONING <-- // Affects CommandObject.CmdName if (handleDetourStep("EDITIONING", 1, "EDITIONING", true)) appendCurrCmdName(detourPath); // CREATE --> FORCE <-- // Affects CommandObject.CmdName if (handleDetourStep("FORCE", 1, "FORCE", true)) appendCurrCmdName(detourPath); // CREATE --> NO FORCE <-- VIEW // Affects CommandObject.Action handleDetourStep("NO FORCE", 1, "NO", false); if (handleDetourStep("NO FORCE", 2, "FORCE", true)) appendCurrCmdName(detourPath); // CREATE --> AND RESOLVE | COMPILE <-- JAVA ... // Affects CommandObject.CmdName handleDetourStep("AND RESOLVE COMPILE", 1, "AND", false); handleDetourStep("AND RESOLVE COMPILE", 2, new String[2] {"RESOLVE", "COMPILE"}, true); // CREATE --> AND RESOLVE | COMPILE <-- JAVA ... // Affects CommandObject.CmdName handleDetourStep("NOFORCE", 1, "NOFORCE", true); // CREATE FLASHBACK ARCHIVE --> DEFAULT <-- ... // Affects CommandObject.CmdName if (handleDetourStep("DEFAULT", 1, "DEFAULT", true)) nextTokenWillBeObjectName(); // CREATE TYPE xyz --> OID 'aaaaaaaa' <-- ... // Affects CommandObject.CmdName handleDetourStep("OID", 1, "OID", false); handleDetourStep("OID", 2, "", true); // CREATE TYPE xyz --> TIMESTAMP 'aaaaaaaa' <-- ... // Affects CommandObject.CmdName handleDetourStep("TIMESTAMP", 1, "TIMESTAMP", false); handleDetourStep("TIMESTAMP", 2, "", true); // FLASHBACK --> STANDBY <-- DATABASE TO TIMESTAMP SYSDATE-1; if (handleDetourStep("STANDBY", 1, "STANDBY", true)) appendCurrCmdName(detourPath); if (handleDetourStep("REVOKE_OBJECT_CLAUSE", 1, new String[4] { "JAVA", "MINING", "EDITION", "DIRECTORY"}, false)) if (upperToken == "EDITION" || upperToken == "DIRECTORY") { nextTokenWillBeObjectName(); detourStart = -1; } if (handleDetourStep("REVOKE_OBJECT_CLAUSE", 2, new String[3] { "MODEL", "SOURCE", "RESOURCE" }, true)) nextTokenWillBeObjectName(); } else if (autodetectMode == AutodetectMode.ObjectName) { setObjectName(token); autodetectMode = AutodetectMode.Normal; } else if (autodetectMode == AutodetectMode.SecondaryObjectName) { currCommand.secondaryObjectName = token; autodetectMode = AutodetectMode.Normal; } else if (autodetectMode == AutodetectMode.ObjectNameList || autodetectMode == AutodetectMode.CommandNameList || autodetectMode == AutodetectMode.SecondaryObjectNameList) { // do nothing here, just skiping no detour path of ELSE statement } else { //System.Console.WriteLine("No detour"); if (tokenCountWithoutCommentsAndDetour == 0) { // First check if it is SQLPlus reserved word //**************************************************** if (sqlPlusKeywords.ContainsKey(upperToken)) { setCurrCmdType(CommandTypes.SqlPlus); sqlPlusKeyword = sqlPlusKeywords[upperToken].ToString(); currCommand.action = sqlPlusKeyword; // With @, @ and start, lexer uses space as separator between literals if (sqlPlusKeyword == "@" || sqlPlusKeyword == "@@" || sqlPlusKeyword == "START") { setCurrCmdType(CommandTypes.SqlPlusStart); } } // The ARCHIVE LOG command in SQL*PLUS else if (upperToken == "ARCHIVE") { setCurrCmdTypeAndAppendCmdName(CommandTypes.SqlPlus, "ARCHIVE"); } // SET command is used both as a SQLPlus reserved word // and SQL reserved word //**************************************************** else if (upperToken == "SET") { // lets stay in unknown mode, could be SQL or SQLPlus } // Anonymous PL/SQL block //**************************************************** else if (upperToken == "BEGIN" || upperToken == "DECLARE") { setCurrCmdTypeAndAppendCmdName(CommandTypes.Plsql, "ANONYMOUS"); } else if (upperToken == "CREATE") { // lets stay in unknown mode, could be SQL or PLSQL } // Single SQL command //**************************************************** else if (upperToken == "ANALYZE" || upperToken == "COMMENT" || upperToken == "SELECT" || upperToken == "WITH" || upperToken == "INSERT" || upperToken == "UPDATE" || upperToken == "DELETE" || upperToken == "COMMIT" || upperToken == "ROLLBACK" || upperToken == "GRANT" || upperToken == "REVOKE" || upperToken == "AUDIT" || upperToken == "NOAUDIT" || upperToken == "RENAME" || upperToken == "TRUNCATE" || upperToken == "CALL" || upperToken == "EXPLAIN" || upperToken == "LOCK" || upperToken == "MERGE" || upperToken == "FLASHBACK" || upperToken == "PURGE") { setCurrCmdType(CommandTypes.Sql); } else if (upperToken == "SAVEPOINT") { setCurrCmdType(CommandTypes.Sql); nextTokenWillBeObjectName(); } else if (upperToken == "ASSOCIATE") { setCurrCmdType(CommandTypes.Sql); currCommand.action = "ASSOCIATE STATISTICS"; } else if (upperToken == "DISASSOCIATE") { setCurrCmdType(CommandTypes.Sql); currCommand.action = "DISASSOCIATE STATISTICS"; } else if (upperToken == "ALTER" || upperToken == "DROP") { } // This condition is skipped in SQLPlus compatibility mode // With comment do not modify current mode !! else if (SQLPlusCompatible && (tokenType == TokenTypes.BlockComment || tokenType == TokenTypes.LineComment)) { } // We treat unknown command as SQLPlusCommand else { setCurrCmdType(CommandTypes.SqlPlus); } if (tokenType == TokenTypes.BlockComment) currCommand.action = "Block comment"; else if (tokenType == TokenTypes.LineComment) currCommand.action = "Line comment"; else if (currCommand.cmdType == CommandTypes.Sql && upperToken == "WITH") currCommand.action = "SELECT"; else if (currCommand.cmdType != CommandTypes.SqlPlus && currCommand.action == "") currCommand.action = upperToken; if (upperToken == "CALL") nextTokenWillBeObjectName(); if (upperToken == "GRANT") { nextTokenWillBeCommandNameList(); listTerminatorTokenHashSet.Add("TO", ""); listTerminatorTokenHashSet.Add("ON", ""); } if (upperToken == "REVOKE") { nextTokenWillBeCommandNameList(); listTerminatorTokenHashSet.Add("FROM", ""); listTerminatorTokenHashSet.Add("ON", ""); } } // we have already read the first token // and are currently reading the second one // check if this can change the mode if (tokenCountWithoutCommentsAndDetour == 1) { if (currCommand.action == "ALTER" || currCommand.action == "DROP" || currCommand.action == "ANALYZE" || currCommand.action == "LOCK" || currCommand.action == "TRUNCATE" || currCommand.action == "FLASHBACK") { if (upperToken == "DATABASE") { setCurrCmdType(CommandTypes.Sql); appendCurrCmdName(upperToken); setBaseCmdName(upperToken); } else if (upperToken == "PACKAGE") setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); else if (upperToken == "TYPE") { appendCurrCmdName(upperToken); } else if (upperToken == "FLASHBACK") setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); else if (upperToken == "MATERIALIZED") { setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "PROCEDURE" || upperToken == "FUNCTION" || upperToken == "TRIGGER") { setCurrCmdType(CommandTypes.Sql); appendCurrCmdName(upperToken); setBaseCmdName(upperToken); nextTokenWillBeObjectName(); } else if (upperToken == "ROLLBACK") { setBaseCmdName("ROLLBACK SEGMENT"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "RESOURCE") { setBaseCmdName("RESOURCE COST"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "RESTORE") { setBaseCmdName("RESTORE POINT"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "JAVA") { setBaseCmdName("JAVA"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "SESSION") { setBaseCmdName("SESSION"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "SYSTEM") { setBaseCmdName("SYSTEM"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (currCommand.action == "LOCK" && upperToken == "TABLE") { appendCurrCmdName(upperToken); setBaseCmdName(upperToken); nextTokenWillBeObjectNameList(); listTerminatorTokenHashSet.Add("IN", ""); } else { setCurrCmdType(CommandTypes.Sql); appendCurrCmdName(upperToken); setBaseCmdName(upperToken); nextTokenWillBeObjectName(); } } if (currCommand.cmdType == CommandTypes.Unknown && currCommand.action == "SET") { switch (upperToken) { case "CONSTRAINT": setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); break; case "CONSTRAINTS": setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); break; case "ROLE": setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); break; case "TRANSACTION": setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); break; default: setCurrCmdTypeAndAppendCmdName(CommandTypes.SqlPlus, upperToken); break; } } if (currCommand.cmdType == CommandTypes.Unknown && (currCommand.action == "CREATE" || currCommand.action == "REPLACE" || currCommand.action == "CREATE OR REPLACE")) { if (upperToken == "FUNCTION" || upperToken == "LIBRARY" || upperToken == "PROCEDURE" || upperToken == "TRIGGER" ) { setBaseCmdName(upperToken); setCurrCmdTypeAndAppendCmdName(CommandTypes.Plsql, upperToken); nextTokenWillBeObjectName(); } else if (upperToken == "PACKAGE") setCurrCmdTypeAndAppendCmdName(CommandTypes.Plsql, upperToken); else if (upperToken == "JAVA") setCurrCmdTypeAndAppendCmdName(CommandTypes.Plsql, upperToken); else if (upperToken == "FLASHBACK") setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); else if (upperToken == "ROLLBACK") { setBaseCmdName("ROLLBACK SEGMENT"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "RESTORE") { setBaseCmdName("RESTORE POINT"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "SCHEMA") { setBaseCmdName("SCHEMA"); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "TYPE") { appendCurrCmdName(upperToken); } else if (upperToken == "MATERIALIZED") { setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else if (upperToken == "DATABASE") { setBaseCmdName(upperToken); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); } else { setBaseCmdName(upperToken); setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, upperToken); nextTokenWillBeObjectName(); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "INSERT") { if (upperToken == "ALL") currCommand.objectName = "[MULTI TABLE]"; else if (upperToken == "FIRST") currCommand.objectName = "[MULTI TABLE]"; else if (upperToken == "SELECT") currCommand.objectName = "[SUBQUERY]"; else if (upperToken == "TABLE") currCommand.objectName = "[TABLE COLLECTION]"; else currCommand.objectName = upperToken; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "UPDATE") { if (upperToken == "SELECT") currCommand.objectName = "[SUBQUERY]"; else if (upperToken == "TABLE") currCommand.objectName = "[TABLE COLLECTION]"; else currCommand.objectName = upperToken; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "DELETE") { if (upperToken == "SELECT") currCommand.objectName = "[SUBQUERY]"; else if (upperToken == "TABLE") currCommand.objectName = "[TABLE COLLECTION]"; else currCommand.objectName = upperToken; } // we have no token look ahead, so we have to compensate using some extra IFs // for ASSOCIATE STATISTICS if (currCommand.cmdType == CommandTypes.Sql && (currCommand.action == "ASSOCIATE STATISTICS" ||currCommand.action == "DISASSOCIATE STATISTICS")) { if (upperToken != "STATISTICS") raiseSyntaxErrorFoundException("STATISTICS expected"); } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "PURGE") { appendCurrCmdName(upperToken); } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "RENAME") { currCommand.objectName = upperToken; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "EXPLAIN") { if (upperToken != "PLAN") raiseSyntaxErrorFoundException("PLAN expected"); currCommand.action += " " + upperToken; } } if (tokenCountWithoutCommentsAndDetour == 2) { // we have no token look ahead, so we have to compensate using some extra IFs // for TYPE BODY if (currCommand.cmdName == "TYPE") { if (upperToken == "BODY") { setBaseCmdName("TYPE BODY"); if (currCommand.action == "ALTER" || currCommand.action == "DROP") setCurrCmdTypeAndAppendCmdName(CommandTypes.Sql, "BODY"); else setCurrCmdTypeAndAppendCmdName(CommandTypes.Plsql, "BODY"); nextTokenWillBeObjectName(); } else { setBaseCmdName("TYPE"); setCurrCmdType(CommandTypes.Sql); setObjectName(token); } } // we have no token look ahead, so we have to compensate using some extra IFs // for PACKAGE BODY if (currCommand.cmdName == "PACKAGE") { if (upperToken == "BODY") { setBaseCmdName("PACKAGE BODY"); appendCurrCmdName("BODY"); nextTokenWillBeObjectName(); } else { setBaseCmdName("PACKAGE"); setObjectName(token); } } // we have no token look ahead, so we have to compensate using some extra IFs // for ROLLBACK SEGMENT if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "ROLLBACK SEGMENT") { if (upperToken == "SEGMENT") { appendCurrCmdName("SEGMENT"); nextTokenWillBeObjectName(); } else { raiseSyntaxErrorFoundException("SEGMENT expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // for RESOURCE COST if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "RESOURCE COST") { if (upperToken == "COST") { appendCurrCmdName("COST");} else { raiseSyntaxErrorFoundException("COST expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // for RESTORE POINT if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "RESTORE POINT") { if (upperToken == "POINT") { appendCurrCmdName("POINT"); nextTokenWillBeObjectName(); } else { raiseSyntaxErrorFoundException("POINT expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // for RESTORE POINT if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "SCHEMA") { if (upperToken == "AUTHORIZATION") { nextTokenWillBeObjectName(); } else { raiseSyntaxErrorFoundException("AUTHORIZATION expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // to distinguishe between DATABASE and DATABASE LINK if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "DATABASE") { if (upperToken == "LINK") { setBaseCmdName("DATABASE LINK"); appendCurrCmdName("LINK"); nextTokenWillBeObjectName(); } } // we have no token look ahead, so we have to compensate using some extra IFs // for FLASHBACK ARCHIVE if (currCommand.cmdType == CommandTypes.Sql && currCommand.cmdName == "FLASHBACK") { if (upperToken == "ARCHIVE") { setBaseCmdName("FLASHBACK ARCHIVE"); appendCurrCmdName("ARCHIVE"); nextTokenWillBeObjectName(); } else { raiseSyntaxErrorFoundException("ARCHIVE expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // for MATERIALIZED VIEW (LOG) if (currCommand.cmdType == CommandTypes.Sql && currCommand.cmdName == "MATERIALIZED") { if (upperToken == "VIEW") { appendCurrCmdName(upperToken); } else { raiseSyntaxErrorFoundException("VIEW expected"); } } // we have no token look ahead, so we have to compensate using some extra IFs // for DROP JAVA (SOURCE || CLASS || RESOURCE) xyz if ((currCommand.action == "DROP" || currCommand.action == "ALTER") && currCommand.baseCmdName == "JAVA") { if (upperToken == "SOURCE" || upperToken == "CLASS" || upperToken == "RESOURCE") { appendCurrCmdName(upperToken); nextTokenWillBeObjectName(); } else { raiseSyntaxErrorFoundException("SOURCE|CLASS|RESOURCE expected"); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "COMMENT") { appendCurrCmdName(upperToken); } // we have no token look ahead, so we have to compensate using some extra IFs // for ASSOCIATE STATISTICS if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ASSOCIATE STATISTICS") { if (upperToken != "WITH") raiseSyntaxErrorFoundException("WITH expected"); } // we have no token look ahead, so we have to compensate using some extra IFs // for DISASSOCIATE STATISTICS if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "DISASSOCIATE STATISTICS") { if (upperToken != "FROM") raiseSyntaxErrorFoundException("FROM expected"); } // GRANT SELECT, UPDATE ---> ON <---- SOME_TABLE TO // GRANT SELECT ANY TABLE, DROP ANY TABLE ---> TO <---- USER1, USER2 if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "GRANT") { if (upperToken == "ON") nextTokenWillBeObjectName(); else if (upperToken == "TO") { nextTokenWillBeSecondaryObjectNameList(); listTerminatorTokenHashSet.Add("WITH", ""); } else raiseSyntaxErrorFoundException("ON|TO expected"); } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "REVOKE") { if (upperToken == "ON") nextTokenWillBeObjectName(); else if (upperToken == "FROM") { nextTokenWillBeSecondaryObjectNameList(); listTerminatorTokenHashSet.Add("CASCADE", ""); listTerminatorTokenHashSet.Add("FORCE", ""); } else raiseSyntaxErrorFoundException("ON|FROM expected"); } } if (tokenCountWithoutCommentsAndDetour == 3) { // we have no token look ahead, so we have to compensate using some extra IFs // for MATERIALIZED VIEW (LOG) if (currCommand.cmdType == CommandTypes.Sql && currCommand.cmdName == "MATERIALIZED VIEW") { if (upperToken == "LOG") { setBaseCmdName("MATERIALIZED VIEW LOG"); appendCurrCmdName(upperToken); } else { setObjectName(token); setBaseCmdName("MATERIALIZED VIEW"); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.baseCmdName == "SYNONYM" && upperToken == "FOR") { nextTokenWillBeSecondaryObjectName(); } if ((currCommand.cmdType == CommandTypes.Sql || currCommand.cmdType == CommandTypes.Plsql) && (currCommand.baseCmdName == "TYPE" || currCommand.baseCmdName == "PROCEDURE" || currCommand.baseCmdName == "FUNCTION" || currCommand.baseCmdName == "PACKAGE" || currCommand.baseCmdName == "LIBRARY") && upperToken == "WRAPPED") { setCurrCmdType(CommandTypes.WrappedPlsql); } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE") { currCommand.alterType = upperToken; } // we have no token look ahead, so we have to compensate using some extra IFs // for ASSOCIATE STATISTICS if (currCommand.cmdType == CommandTypes.Sql && (currCommand.action == "ASSOCIATE STATISTICS" || currCommand.action == "DISASSOCIATE STATISTICS")) { setBaseCmdName(upperToken); currCommand.cmdName = upperToken; nextTokenWillBeObjectNameList(); listTerminatorTokenHashSet.Add("USING", ""); listTerminatorTokenHashSet.Add("DEFAULT", ""); } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "COMMENT") { if (currCommand.cmdName == "MATERIALIZED" || currCommand.cmdName == "MINING") { appendCurrCmdName(upperToken); currCommand.baseCmdName = currCommand.cmdName; } else { if (currCommand.cmdName == "COLUMN") { // split table.column when comment on column ... string[] table_column = token.Split('.'); if (table_column.Length == 2) { setObjectName(table_column[0]); currCommand.secondaryObjectName = table_column[1]; } else if (table_column.Length == 3) { setObjectName(table_column[0] + "." + table_column[1]); currCommand.secondaryObjectName = table_column[2]; } else raiseSyntaxErrorFoundException("Column is not identified by 2|3 parts"); } else setObjectName(token); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "RENAME") { currCommand.secondaryObjectName = upperToken; } } if (tokenCountWithoutCommentsAndDetour == 4) { if (currCommand.cmdType == CommandTypes.Plsql && (currCommand.baseCmdName == "TYPE BODY" || currCommand.baseCmdName == "PACKAGE BODY") && upperToken == "WRAPPED") { setCurrCmdType(CommandTypes.WrappedPlsql); } // we have no token look ahead, so we have to compensate using some extra IFs // for MATERIALIZED VIEW (LOG) ON if (currCommand.cmdType == CommandTypes.Sql && currCommand.cmdName == "MATERIALIZED VIEW LOG") { if (upperToken == "ON") nextTokenWillBeSecondaryObjectName(); else { raiseSyntaxErrorFoundException("ON expected"); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD" && upperToken == "CONSTRAINT") { currCommand.alterType += " " + upperToken; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "COMMENT") { if (currCommand.cmdName == "MATERIALIZED VIEW" || currCommand.cmdName == "MINING MODEL") setObjectName(token); } // GRANT SELECT, UPDATE ON SOME_TABLE ---> TO <---- somebody if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "GRANT") { if (upperToken == "TO") { nextTokenWillBeSecondaryObjectNameList(); listTerminatorTokenHashSet.Add("WITH", ""); } } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "REVOKE") { if (upperToken == "FROM") {nextTokenWillBeSecondaryObjectNameList(); listTerminatorTokenHashSet.Add("CASCADE", ""); listTerminatorTokenHashSet.Add("FORCE", ""); } } } if (tokenCountWithoutCommentsAndDetour == 5) { if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD CONSTRAINT") { currCommand.secondaryObjectName = token; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD" && upperToken == "CONSTRAINT") { currCommand.alterType += " " + upperToken; } } if (tokenCountWithoutCommentsAndDetour == 6) { if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD CONSTRAINT" && currCommand.secondaryObjectName != "") { currCommand.secondaryCmdName = token; } if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD CONSTRAINT" && currCommand.secondaryObjectName == "") { currCommand.secondaryObjectName = token; } } if (tokenCountWithoutCommentsAndDetour == 7) { if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "ALTER" && currCommand.cmdName == "TABLE" && currCommand.alterType == "ADD CONSTRAINT" && currCommand.secondaryCmdName == "") { currCommand.secondaryCmdName = token; } } } // this is to fish out table name on which index is created if (currCommand.cmdType == CommandTypes.Sql && currCommand.action == "CREATE" && (currCommand.cmdName == "INDEX" || currCommand.cmdName == "UNIQUE INDEX") && prevToken == "ON" && currCommand.secondaryObjectName == "") { currCommand.secondaryObjectName = token; } }
public void nextTokenWillBeSecondaryObjectNameList() { autodetectMode = AutodetectMode.SecondaryObjectNameList; listSeparator = ","; listTerminatorTokenHashSet = new Dictionary<string,string>(); }
public void resetBlockType() { prevBlockType = currCommand.cmdType; prevBlockText = currBlockText; currCommand.cmdType = CommandTypes.Unknown; currBlockText = new StringBuilder(); prevToken = ""; token = ""; currCommand.action = ""; currCommand.baseCmdName = ""; currCommand.cmdName = ""; currCommand.objectName = ""; currCommand.alterType = ""; currCommand.secondaryObjectName = ""; currCommand.secondaryCmdName = ""; currCommand.syntaxErrorFound = false; tokenCountWithoutComments = 0; blockStartLine = -1; autodetectMode = AutodetectMode.Normal; detourTaken = 0; detourStart = -1; detourPath = ""; }
public void nextTokenWillBeObjectName() { autodetectMode = AutodetectMode.ObjectName; }
public void nextTokenWillBeCommandNameList(string listSeparator) { autodetectMode = AutodetectMode.CommandNameList; this.listSeparator = listSeparator; listTerminatorTokenHashSet = new Dictionary<string,string>(); }
private bool handleDetourStep(String detourName, int detourStepSeq, String[] whichTokensAreExpected, bool endOfDetour) { if (detourPath == detourName) { int detourTokenCountWithoutComments = tokenCountWithoutComments - detourStart + 1; if (detourTokenCountWithoutComments == detourStepSeq) { if (whichTokensAreExpected.Length != 0) { string upperToken = token.ToUpper(); string tokenFound = Array.Find(whichTokensAreExpected, s => s.Equals(upperToken)); if (tokenFound == "") { raiseSyntaxErrorFoundException(string.Join(",", whichTokensAreExpected) + " expected"); autodetectMode = AutodetectMode.Normal; detourStart = -1; return false; } } if (endOfDetour) { autodetectMode = AutodetectMode.Normal; detourStart = -1; detourTaken = detourTaken + detourStepSeq; } return true; } } return false; }
private bool handleDetourStep(String detourName, int detourStepSeq, String whichTokenIsExpected, bool endOfDetour) { if (detourPath == detourName) { int detourTokenCountWithoutComments = tokenCountWithoutComments - detourStart + 1; if (detourTokenCountWithoutComments == detourStepSeq) { string upperToken = token.ToUpper(); if (whichTokenIsExpected != "" && upperToken != whichTokenIsExpected) { raiseSyntaxErrorFoundException(whichTokenIsExpected + " expected"); autodetectMode = AutodetectMode.Normal; detourStart = -1; return false; } if (endOfDetour) { autodetectMode = AutodetectMode.Normal; detourStart = -1; detourTaken = detourTaken + detourStepSeq; } return true; } } return false; }
private void checkForAndBeginDetour(int detourStartsAtToken, CommandTypes cmdTypeBefore, String actionBefore, String baseCmdNameBefore, String detourStartsWithToken, String detourUniqueName) { int tokenCountWithoutCommentsAndDetour = tokenCountWithoutComments - detourTaken; string upperToken = token.ToUpper(); if (tokenCountWithoutCommentsAndDetour == detourStartsAtToken && currCommand.cmdType == cmdTypeBefore && currCommand.action == actionBefore && currCommand.baseCmdName == baseCmdNameBefore && upperToken == detourStartsWithToken) { autodetectMode = AutodetectMode.Detour; detourStart = tokenCountWithoutComments; detourPath = detourUniqueName; } }