public void JumpTo(string jumpString) { _jumpString = jumpString; string filterStr = String.Empty; CustomStringTokenizer tok = new CustomStringTokenizer(jumpString); IList <CustomToken> tokens = new List <CustomToken>(); string tmp = String.Empty; CustomToken token = null; do { token = tok.Next(); if (token.Kind == CustomTokenKind.EOL || token.Kind == CustomTokenKind.EOF || token.Kind == CustomTokenKind.Unknown || token.Kind == CustomTokenKind.WhiteSpace || (token.Kind == CustomTokenKind.Symbol && token.Value != ".") ) { continue; } tokens.Add(token); } while (token.Kind != CustomTokenKind.EOF); if (tokens.Count == 0 || tokens[tokens.Count - 1].Value == ".") { filterStr = String.Empty; } else { filterStr = "( DisplayName Like '" + tokens[tokens.Count - 1].Value + "%')"; } _bsListItems.Filter = filterStr; if (_bsListItems.Count > 0) { _bsListItems.Position = 0; _bsListItems.Sort = "DisplayName ASC"; } else { _bsListItems.Sort = String.Empty; } }
public void JumpTo(string jumpString, SqlAnalyzerResults aResults) { _aResults = aResults; string parentNamePlaceHolder = "$\x26\x26\x26$"; string parentName = String.Empty; string filterStr = String.Empty; string dbName = _defaultDatabase; string schemaName = "???"; bool isInvalidFilter = false; label1.Text = jumpString; CustomStringTokenizer tok = new CustomStringTokenizer(jumpString); IList <CustomToken> tokens = new List <CustomToken>(); CustomToken token = null; do { token = tok.Next(); if (token.Kind == CustomTokenKind.EOL || token.Kind == CustomTokenKind.EOF || token.Kind == CustomTokenKind.Unknown || (token.Kind == CustomTokenKind.Symbol && token.Value != ".") ) { continue; } tokens.Add(token); } while (token.Kind != CustomTokenKind.EOF); if (tokens.Count == 0) { filterStr = " ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Usr')"; schemaName = "dbo"; } // 1- Object1 else if (tokens.Count == 1) { filterStr = " ( Type <> 'Param' AND Type <> 'Col' ) " + " AND ( Name Like '" + tokens[0].Value + "%') "; schemaName = "dbo"; } // 2- Object1. else if (tokens.Count == 2) { CustomToken lastToken = tokens[1]; if (lastToken.Value == ".") { CustomToken parentToken = tokens[0]; if (IsValidDatabase(parentToken.Value)) { dbName = parentToken.Value; filterStr = "( Type = 'Usr' )"; } else if (IsValidUser(parentToken.Value)) { dbName = _defaultDatabase; filterStr = "( Catalog = '" + _defaultDatabase + "' OR Catalog = '') " + " AND ( Schema = '" + parentToken.Value + "' OR Schema = '') " + " AND ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Usr' AND Type <> 'Db') "; schemaName = parentToken.Value; } else { dbName = _defaultDatabase; parentName = parentToken.Value; filterStr = "ParentName = '" + parentNamePlaceHolder + "' " + " AND ( " + " ( ( Catalog = '" + _defaultDatabase + "' OR Catalog = '') " + " AND ( Schema = 'dbo' ) OR ( Schema = '')" + " AND ( Type = 'Param' OR Type = 'Col' ) ) " + " OR (IsOffline = 1) " + " )"; schemaName = "dbo"; } } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } // 3- Object1.Object2, Object1.. else if (tokens.Count == 3) { CustomToken lastToken = tokens[2]; // 3.1 - Object1.. if (lastToken.Value == ".") { CustomToken parentToken = tokens[0]; if (IsValidDatabase(parentToken.Value)) { dbName = parentToken.Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = 'dbo' OR Schema = '') " + " AND ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Db' AND Type <> 'Usr') "; schemaName = "dbo"; } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } // 3.2 - Object1.Object2 else { CustomToken parentToken = tokens[0]; // Object1 if (IsValidDatabase(parentToken.Value)) { dbName = parentToken.Value; filterStr = "Name Like '" + tokens[2].Value + "%' " + " AND ( Type = 'Usr')"; schemaName = "dbo"; } else if (IsValidUser(parentToken.Value)) { dbName = _defaultDatabase; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + parentToken.Value + "' OR Schema = '') " + " AND ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Db' AND Type <> 'Usr') " + " AND ( Name Like '" + tokens[2].Value + "%') "; schemaName = parentToken.Value; } else { dbName = _defaultDatabase; parentName = parentToken.Value; filterStr = "ParentName = '" + parentNamePlaceHolder + "' " + " AND ( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = 'dbo' OR Schema = '') " + " AND ( Type = 'Param' OR Type = 'Col') " + " AND ( Name Like '" + tokens[2].Value + "%') "; schemaName = "dbo"; } } } // 4- Object1.Object2. else if (tokens.Count == 4) { if (tokens[3].Value == ".") //. { if (IsValidDatabase(tokens[0].Value) && IsValidUser(tokens[2].Value)) // Object1 and Object2 { dbName = tokens[0].Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + tokens[2].Value + "' OR Schema = '')" + " AND ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Usr' AND Type <> 'Db' ) "; schemaName = tokens[2].Value; } else if (IsValidUser(tokens[0].Value)) { dbName = _defaultDatabase; parentName = tokens[2].Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + tokens[0].Value + "' OR Schema = '')" + " AND ( Type = 'Param' OR Type = 'Col')" + " AND ( ParentName = '" + parentNamePlaceHolder + "' ) "; schemaName = tokens[2].Value; } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } // 5- Object1.Object2.Object3 else if (tokens.Count == 5) { if (IsValidDatabase(tokens[0].Value) && IsValidUser(tokens[2].Value)) // Object1 and Object2 { dbName = tokens[0].Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + tokens[2].Value + "' OR Schema = '')" + " AND ( Type <> 'Param' AND Type <> 'Col' AND Type <> 'Usr' AND Type <> 'Db' ) " + " AND ( Name Like '" + tokens[4].Value + "%') "; schemaName = tokens[2].Value; } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } // 6- Object1.Object2.Object3. else if (tokens.Count == 6) { if (tokens[5].Value == ".") { if (IsValidDatabase(tokens[0].Value) && IsValidUser(tokens[2].Value)) // Object1 and Object2 { dbName = tokens[0].Value; parentName = tokens[4].Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + tokens[2].Value + "' OR Schema = '')" + " AND ( Type = 'Param' OR Type = 'Col')" + " AND ( ParentName = '" + parentNamePlaceHolder + "') "; schemaName = tokens[2].Value; } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } // 7- Object1.Object2.Object3.Object4 else if (tokens.Count == 7) { if (IsValidDatabase(tokens[0].Value) && IsValidUser(tokens[2].Value)) // Object1 and Object2 { dbName = tokens[0].Value; parentName = tokens[4].Value; filterStr = "( Catalog = '" + dbName + "' OR Catalog = '') " + " AND ( Schema = '" + tokens[2].Value + "' OR Schema = '')" + " AND ( Type = 'Param' OR Type = 'Col')" + " AND ( ParentName = '" + parentNamePlaceHolder + "') " + " AND ( Name Like '" + tokens[6].Value + "%') "; } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } } else { dbName = _defaultDatabase; // Invalid filter filterStr = " ( Type = '@@@')"; isInvalidFilter = true; } if (_currentDatabase.ToLowerInvariant() != dbName.ToLowerInvariant()) { _currentDatabase = dbName; PopulateCodeCompletionList(false); } if (_bsObjects.DataSource == null || _tblObjects == null) { this.Hide(); return; } if (!_parsedObjectsAvailable) { ClearParsedObjects(); InsertParsedObjects(aResults); } if (!String.IsNullOrEmpty(parentName)) { parentName = TableNameFromAlias(parentName); filterStr = filterStr.Replace(parentNamePlaceHolder, parentName); } _bsObjects.Filter = filterStr; _bsObjects.Sort = "Order ASC, Name ASC"; if (_bsObjects.Count > 0) { _bsObjects.Position = 0; } if (!isInvalidFilter) { label2.Text = "Catalog = '" + dbName + "', Schema = '" + schemaName + "'"; } else { label2.Text = "Can not parse code completion proposal!"; } }