/// <summary> /// Main conversion function when used in GUI mode /// </summary> /// <param name="args"></param> /// <param name="inputQuery"></param> /// <param name="resultSummary"></param> /// <param name="numOfStatements"></param> /// <param name="numOfErrors"></param> /// <returns></returns> public string RunConversion(string[] args, string inputQuery, out string resultSummary, out int numOfStatements, out int numOfErrors) { Config.Initialize(args, null); ApplyLocalSettings(); if (inputQuery == null || inputQuery.Length == 0) { resultSummary = ""; numOfErrors = 0; numOfStatements = 0; return(""); } StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); StringBuilder sbSummary = new StringBuilder(); StringWriter writerSummary = new StringWriter(sbSummary); StatusReporter.Initialize(writerSummary); numOfStatements = TranslateQueryInt(writer, inputQuery, writerSummary); writer.Close(); writerSummary.Close(); numOfErrors = 0; resultSummary = writerSummary.ToString(); return(sb.ToString()); }
/// <summary> /// Call case fixing for given statements /// </summary> /// <param name="translatedStatement">Statements to be translated</param> /// <param name="infoWriter">Stream for info/summary, may be null.</param> private void CaseFixStatements(Statement translatedStatement, TextWriter infoWriter) { if (translatedStatement == null) { return; } CharacterCaseFixer fixer = new CharacterCaseFixer(Config.DBServer, Config.DBSchema, Config.DBUser, Config.DBPasswd); bool displayWarn = true; if (Config.UseCaseFixer) { StatusReporter.SetStage(ResStr.MSG_CASEFIXING_STEP); } if (translatedStatement is BlockStatement) { foreach (Statement st in ((BlockStatement)translatedStatement).Statements) { displayWarn = CaseFixStatement(fixer, st, infoWriter, displayWarn); } } else { displayWarn = CaseFixStatement(fixer, translatedStatement, infoWriter, true); } }
public static void SetInputQueries(Statement rootStatement) { inputQueries = rootStatement; Scanner sc = new Scanner(); sc.Scan(inputQueries); numInQueries = StatusReporter.GetCount(); //First statement can be StartSQLStatement if (numInQueries > 1) { --numInQueries; } }
public virtual void Scan(GrammarNode node) { //DebugWrite(node); //Sometimes in lists we can have null items when grammar can't process the node, returns null if (node != null) { StatusReporter.ReportProgress(node); CallAction(node, CallActionType.PreActionType); if (CallAction(node, CallActionType.ActionType)) { ScanChildren(node); } CallAction(node, CallActionType.PostActionType); } ChildInfo = null; }
/// <summary> /// Main function used when called command line mode. /// </summary> /// <param name="args"></param> /// <param name="startUI"></param> public void Run(string[] args, out bool startUI) { if (ProcessConfigFile(args, out startUI)) { return; } StatusReporter.Initialize(Console.Out); StreamWriter writer = CreateOutputFile(Config.OutputFile); String input = ReadInput(); int numOfStatements = TranslateQueryInt(writer, input, Console.Out); if (writer != null) { writer.Flush(); writer.Close(); } DbUtil.ReleaseSingleton(); }
/// <summary> /// Translate input statements. Returns output statement. /// </summary> /// <param name="statements"></param> /// <param name="infoWriter"></param> /// <param name="statementsCount"></param> /// <param name="translatedStatement"></param> void TranslateStatements(IList <Statement> statements, TextWriter infoWriter, out Statement translatedStatement) { Modifier md = new Modifier(); BlockStatement RootStatement = WrapInputStatements(statements, md); StatusReporter.SetStage(ResStr.MSG_SCAN_INPUT_STATEMENTS, string.Empty); StatusReporter.SetInputQueries(RootStatement); StatusReporter.Message(" " + ResStr.MSG_INPUT_STATEMENTS_FOUND + StatusReporter.InputQueriesCount); StatusReporter.SetStage(ResStr.MSG_CONVERSION_STAGE, ResStr.MSG_CONVERSION_STEP); md.Scan(RootStatement); Statement translated = md.Statement; StatusReporter.SetOutputQueries(translated, StatusReporter.GetCount()); CaseFixStatements(translated, infoWriter); translatedStatement = translated; StatusReporter.Message("\n\n" + ResStr.MSG_DIFFERENT_STATEMENTS_COUNT); StatusReporter.Finish(); }
private void ScanIdentifiers(DbUtil util, List <IdentifierRequest> listToVerify, ObjectType objType) { if (listToVerify.Count == 0) { return; } List <string> tableList = new List <string>(); foreach (IdentifierRequest ir in listToVerify) { foreach (string table in ir.mTables) { if (tableList.Find(s => s == table) == null) { tableList.Add(table); } } } if (objType == ObjectType.INDEX) { tableList.Add(string.Empty); } List <IdentifierRequest> irBatch = new List <IdentifierRequest>(); List <string> nameBatch = new List <string>(); foreach (string table in tableList) { irBatch.Clear(); nameBatch.Clear(); //collect columns for one table foreach (IdentifierRequest ir in listToVerify) { if (string.IsNullOrEmpty(ir.mName) == false) { if ((string.IsNullOrEmpty(table) && ir.mTables.Count == 0) || string.IsNullOrEmpty(table) == false && ir.ContainsTable(table)) { irBatch.Add(ir); nameBatch.Add(ir.mName); } } } if (irBatch.Count == 0) { //Table without column to solve continue; } SortedDictionary <string, List <string> > nameTable = new SortedDictionary <string, List <string> >(); List <string> ret = null; if (objType == ObjectType.COLUMN) { StatusReporter.ReportProgress(); ret = util.GetColumnsNames(ref nameTable, table, nameBatch); } else { StatusReporter.ReportProgress(); ret = util.GetIndexesNames(ref nameTable, table, nameBatch); } FixNames(ret, table, irBatch, objType); } //names which left are not found in DB foreach (IdentifierRequest ir in listToVerify) { if (string.IsNullOrEmpty(ir.mName) == false) { //not found in DB foreach (DbObject dbObj in ir.mObjects) { switch (objType) { case ObjectType.COLUMN: AddNote(dbObj, Note.CASEFIXER, String.Format(ResStr.CF_COLUMN_NOT_FOUND, ir.mName)); break; case ObjectType.INDEX: AddNote(dbObj, Note.CASEFIXER, String.Format(ResStr.CF_OBJECT_NOT_FOUND, ObjectTypeName[(int)objType], ir.mName)); break; case ObjectType.CONSTRAINT: AddNote(dbObj, Note.CASEFIXER, String.Format(ResStr.CF_CONSTRAINT_NOT_FOUND, ir.mName)); break; } QuoteLastIdentifierIfNeeded(dbObj.Identifiers); } } } }
private void ScanObjects(DbUtil util, ObjectType objType, List <DbObjectNode> objToCheck) { if (objToCheck.Count == 0) { return; } Dictionary <string, HashSet <string> > groupedIdens = GroupObjectBySchema(objToCheck); foreach (KeyValuePair <string, HashSet <string> > pair in groupedIdens) { StatusReporter.ReportProgress(); util.LoadObjectNames(pair.Key, ObjectTypeName[(int)objType].ToUpper(), pair.Value); } foreach (DbObjectNode tn in objToCheck) { // some could be already processed durign checking the columns if (string.IsNullOrEmpty(tn.identifier) == false) { string[] names = util.GetCachedObjectName(tn.identifier, ObjectTypeName[(int)objType].ToUpper()); if (names[0] == null) { //no object found AddNote(tn.grammarNode, Note.CASEFIXER, String.Format(ResStr.CF_OBJECT_NOT_FOUND, ObjectTypeName[(int)objType], tn.identifier)); tn.grammarNode.Identifiers.Last().Type = IdentifierType.Quoted; } else { string clearIden = tn.identifier; foreach (DbObjectNode tn2 in objToCheck) { if (tn2.identifier == clearIden) { Identifier iden = tn2.grammarNode.Identifiers[0]; if (tn2.grammarNode.Identifiers.Count == 2) { //cover schema name if (iden.Name != names[0]) { AddNote(tn2.grammarNode, Note.CASEFIXER, String.Format(ResStr.CF_OBJECT_NAME_FIXED, ObjectTypeName[(int)ObjectType.SCHEMA], iden.Name, names[0])); iden.Name = names[0]; } iden = tn2.grammarNode.Identifiers[1]; } //object name if (iden.Name != names[1]) { AddNote(tn2.grammarNode, Note.CASEFIXER, String.Format(ResStr.CF_OBJECT_NAME_FIXED, ObjectTypeName[(int)objType], iden.Name, names[1])); iden.Name = names[1]; if (iden.Name.ToUpper() != iden.Name) { //case sensitive table name - change identifier to quoted iden.Type = IdentifierType.Quoted; } } else if (iden.Type == IdentifierType.Plain && iden.Name.ToUpper() != iden.Name) { iden.Type = IdentifierType.Quoted; } tn2.identifier = string.Empty; } } } } } }