public static void Print(string p_dir, string p_include_list, SearchOption p_recurse_dir) { string[] files = new string[1]; string[] include_list = p_include_list.Split(','); foreach (string filetype in include_list) { string[] matchedFiles = Directory.GetFiles(p_dir, filetype, p_recurse_dir); if (matchedFiles.Length > 0) { int startPos = files.Length; if (startPos == 1) startPos = 0; // compensate files array[1] declaration Array.Resize(ref files, startPos + matchedFiles.Length); Array.Copy(matchedFiles, 0, files, startPos, matchedFiles.Length); } } foreach (string filename in files) { //Console.WriteLine("xxx"+filename); StreamReader r = new StreamReader(filename, Encoding.GetEncoding(Settings.getEncoding(false))); SQLPlusScanner scanner = new SQLPlusScanner(r, filename); try { do { try { do { scanner.get(); } while (true); } catch (EOBException) { if (scanner.currCommand.action != "REMARK") Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", filename, scanner.getModeDesc(), scanner.currCommand.action, scanner.currCommand.cmdName, scanner.currCommand.objectName, scanner.currCommand.alterType, scanner.currCommand.secondaryCmdName, scanner.currCommand.secondaryObjectName); scanner.resetBlockType(); } } while (true); } catch (EOFException) { } } }
public static void BasicStats(string p_dir, SearchOption p_recurse_dir) { // Read configuration string configSqlFileList = SQLMake.Util.Settings.getSqlFileList(true); // disable variable substitution as we are just scanning through files Settings.overrideSqlPlusVariableSubstitutionFlag(false); int dmlModeCount = 0; // insert, update, delete, select int ddlModeCount = 0; // all other SQL int tabColCommentsModeCount = 0; // int plsqlModeCount = 0; int sqlPlusModeCount = 0; int unknownModeCount = 0; int numberOfScripts = 0; string[] files = FolderSearch.Search(p_dir, Settings.getRecurseFlag(true), Settings.getSqlFileList(true), Settings.getIgnoreDirList(true), Settings.getIgnoreFileList(true)); foreach (string filename in files) { //Console.WriteLine(filename); numberOfScripts++; StreamReader r = new StreamReader(filename, Encoding.GetEncoding(Settings.getEncoding(false))); SQLPlusScanner scanner = new SQLPlusScanner(r, filename); try { do { try { do { scanner.get(); } while (true); } catch (EOBException) { switch (scanner.currCommand.cmdType) { case CommandTypes.Sql: if (scanner.currCommand.action == "SELECT" || scanner.currCommand.action == "INSERT" || scanner.currCommand.action == "UPDATE" || scanner.currCommand.action == "DELETE") dmlModeCount++; else if (scanner.currCommand.action == "COMMENT") tabColCommentsModeCount++; else ddlModeCount++; break; case CommandTypes.Plsql: plsqlModeCount++; break; case CommandTypes.SqlPlus: sqlPlusModeCount++; break; case CommandTypes.Unknown: //Console.WriteLine("Unknown BLOCK found in file {0} from line {1} to {2}", filename, scanner.startLineIndex + 1, scanner.currLineIndex + 1); //Console.WriteLine(scanner.getCurrentLine()); unknownModeCount++; break; } //Console.WriteLine(" mode {1}, action {0} {2}, plsql:{3}, sql:{4}, sqlplus:{5}", scanner.action, scanner.getModeDesc(), scanner.currSubMode, plsqlModeCount, ddlModeCount, sqlPlusModeCount); scanner.resetBlockType(); } } while (true); } catch (EOFException) { if (scanner.currCommand.cmdType != CommandTypes.Unknown) { Log.Warning("stat", "Last {0} in file {1} not correctly terminated", scanner.getModeDesc(), filename); Console.WriteLine("Last {0} in file {1} not correctly terminated", scanner.getModeDesc(), filename); } } } Console.WriteLine("Number of scripts: {0}", numberOfScripts); Console.WriteLine("Number of DDL commands: {0}", ddlModeCount); Console.WriteLine("Number of table/column comments: {0}", tabColCommentsModeCount); Console.WriteLine("Number of DML commands: {0}", dmlModeCount); Console.WriteLine("Number of PLSQL commands: {0}", plsqlModeCount); Console.WriteLine("Number of SQLPlus commands: {0}", sqlPlusModeCount); Console.WriteLine("Number of Unknown commands: {0}", unknownModeCount); }
public static Object[] Load(string filename) { int sqlModeCount = 0; int plsqlModeCount = 0; int sqlPlusModeCount = 0; int unknownModeCount = 0; int seqInFile = 0; string commandType = ""; string objectType = ""; string action = ""; StreamReader r = new StreamReader(filename, Encoding.GetEncoding(Settings.getEncoding(false))); SQLPlusScanner scanner = new SQLPlusScanner(r, filename); ArrayList sqlObjectList = new ArrayList(); try { do { try { //Console.WriteLine(filename); do { scanner.get(); if ((scanner.currCommand.cmdType == CommandTypes.Plsql || scanner.currCommand.cmdType == CommandTypes.WrappedPlsql) && scanner.currCommand.objectName != "") break; } while (true); if (scanner.currCommand.cmdType == CommandTypes.Plsql || scanner.currCommand.cmdType == CommandTypes.WrappedPlsql) { do { scanner.getLine(); } while (true); } } catch (EOBException) { commandType = "Unknown"; seqInFile++; action = scanner.currCommand.action; // CREATE, ALTER, DROP, INSERT, ... objectType = scanner.currCommand.cmdName; //TABLE, PACKAGE, TRIGGER, INDEX, ... switch (scanner.currCommand.cmdType) { case CommandTypes.Sql: sqlModeCount++; commandType = "SQL"; if (action == "ALTER" && objectType == "TABLE" && scanner.currCommand.alterType == "ADD CONSTRAINT") { action = "CREATE"; objectType = scanner.currCommand.secondaryCmdName; if (objectType != "CHECK") objectType += " KEY"; } if (action == "COMMENT") { action = "CREATE"; objectType = "COMMENT"; } //Console.WriteLine("[{6},{7}] action {0}, currSubMode {1}, primaryObject {2}, alterType {3}, secondaryObject {4}, secondaryObjectType {5}", scanner.action, scanner.currSubMode, scanner.primaryObject, scanner.alterType, scanner.secondaryObject, scanner.secondaryObjectType, scanner.blockStartLine+1, scanner.currLineIndex+1); //Console.WriteLine(scanner.currBlock.ToString().Trim()); break; case CommandTypes.Plsql: commandType = "PLSQL"; plsqlModeCount++; //Console.WriteLine("[{6},{7}] action {0}, currSubMode {1}, primaryObject {2}, alterType {3}, secondaryObject {4}, secondaryObjectType {5}", scanner.action, scanner.currSubMode, scanner.primaryObject, scanner.alterType, scanner.secondaryObject, scanner.secondaryObjectType, scanner.blockStartLine+1, scanner.currLineIndex+1); break; case CommandTypes.WrappedPlsql: commandType = "PLSQL"; plsqlModeCount++; //Console.WriteLine("[{6},{7}] action {0}, currSubMode {1}, primaryObject {2}, alterType {3}, secondaryObject {4}, secondaryObjectType {5}", scanner.action, scanner.currSubMode, scanner.primaryObject, scanner.alterType, scanner.secondaryObject, scanner.secondaryObjectType, scanner.blockStartLine+1, scanner.currLineIndex+1); break; case CommandTypes.SqlPlus: commandType = "SQLPlus"; //Console.WriteLine("action {0}, currSubMode {1}, primaryObject {2}, alterType {3}, secondaryObject {4}, secondaryObjectType {5}", scanner.action, scanner.currSubMode, scanner.primaryObject, scanner.alterType, scanner.secondaryObject, scanner.secondaryObjectType); sqlPlusModeCount++; break; case CommandTypes.SqlPlusStart: commandType = "SQLPlus"; //Console.WriteLine("action {0}, currSubMode {1}, primaryObject {2}, alterType {3}, secondaryObject {4}, secondaryObjectType {5}", scanner.action, scanner.currSubMode, scanner.primaryObject, scanner.alterType, scanner.secondaryObject, scanner.secondaryObjectType); sqlPlusModeCount++; break; case CommandTypes.Unknown: commandType = "Unknown"; //Console.WriteLine("Unknown BLOCK found in file {0} from line {1} to {2}", filename, scanner.blockStartLine + 1, scanner.currLineIndex + 1); //Console.WriteLine(scanner.getCurrentLine()); unknownModeCount++; break; default: throw new NotImplementedException(); } sqlObjectList.Add(new SqlObject(commandType, scanner.currCommand.objectName, scanner.currCommand.secondaryObjectName, action, objectType, filename, seqInFile, scanner.blockStartLine + 1, scanner.currLineIndex + 1, scanner.currBlockText.ToString().Trim())); scanner.resetBlockType(); } } while (true); } catch (EOFException) { if (scanner.currCommand.cmdType != CommandTypes.Unknown) { Log.ExitError(String.Format("Last {0} in file {1} not correctly terminated", scanner.getModeDesc(), filename)); } } //foreach (SqlObject s in sqlObjectList) //{ // Console.WriteLine("[{0},{1}] action {2}, objectType {3}, objectName {4}, secondaryObjectName {5}", s.lineStart, s.lineEnd, s.action, s.objectType, s.objectName, s.secondaryObjectName); //} return sqlObjectList.ToArray(); }