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; }
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; } } } } } }