/// <summary> /// Script a object using the type extracted from declarationItem /// </summary> /// <param name="declarationItem">The Declarartion object that matched with the selected token</param> /// <param name="tokenText">The text of the selected token</param> /// <param name="schemaName">Schema name</param> /// <returns></returns> internal DefinitionResult GetDefinitionUsingDeclarationType(DeclarationType type, string databaseQualifiedName, string tokenText, string schemaName) { if (sqlScriptGetters.ContainsKey(type) && sqlObjectTypes.ContainsKey(type)) { // With SqlLogin authentication, the defaultSchema property throws an Exception when accessed. // This workaround ensures that a schema name is present by attempting // to get the schema name from the declaration item. // If all fails, the default schema name is assumed to be "dbo" if ((connectionInfo != null && connectionInfo.ConnectionDetails.AuthenticationType.Equals(Constants.SqlLoginAuthenticationType)) && string.IsNullOrEmpty(schemaName)) { string fullObjectName = databaseQualifiedName; schemaName = this.GetSchemaFromDatabaseQualifiedName(fullObjectName, tokenText); } Location[] locations = GetSqlObjectDefinition( sqlScriptGetters[type], tokenText, schemaName, sqlObjectTypes[type] ); DefinitionResult result = new DefinitionResult { IsErrorResult = this.error, Message = this.errorMessage, Locations = locations }; return(result); } // If a type was found but is not in sqlScriptGetters, then the type is not supported return(GetDefinitionErrorResult(SR.PeekDefinitionTypeNotSupportedError)); }
/// <summary> /// Get the script of the selected token based on the type of the token /// </summary> /// <param name="declarationItems"></param> /// <param name="tokenText"></param> /// <param name="schemaName"></param> /// <returns>Location object of the script file</returns> internal DefinitionResult GetScript(IEnumerable <Declaration> declarationItems, string tokenText, string schemaName) { foreach (Declaration declarationItem in declarationItems) { if (declarationItem.Title == null) { continue; } if (declarationItem.Title.Equals(tokenText)) { // Script object using SMO based on type DeclarationType type = declarationItem.Type; if (sqlScriptGetters.ContainsKey(type) && sqlObjectTypes.ContainsKey(type)) { // On *nix and mac systems, the defaultSchema property throws an Exception when accessed. // This workaround ensures that a schema name is present by attempting // to get the schema name from the declaration item // If all fails, the default schema name is assumed to be "dbo" if ((connectionInfo != null && connectionInfo.ConnectionDetails.AuthenticationType.Equals(Constants.SqlLoginAuthenticationType)) && string.IsNullOrEmpty(schemaName)) { string fullObjectName = declarationItem.DatabaseQualifiedName; schemaName = this.GetSchemaFromDatabaseQualifiedName(fullObjectName, tokenText); } Location[] locations = GetSqlObjectDefinition( sqlScriptGetters[type], tokenText, schemaName, sqlObjectTypes[type] ); DefinitionResult result = new DefinitionResult { IsErrorResult = this.error, Message = this.errorMessage, Locations = locations }; return(result); } // sql object type is currently not supported return(GetDefinitionErrorResult(SR.PeekDefinitionTypeNotSupportedError)); } } // no definition found return(GetDefinitionErrorResult(SR.PeekDefinitionNoResultsError)); }
/// <summary> /// Script an object using the type extracted from quickInfo Text /// </summary> /// <param name="quickInfoText">the text from the quickInfo for the selected token</param> /// <param name="tokenText">The text of the selected token</param> /// <param name="schemaName">Schema name</param> /// <returns></returns> internal DefinitionResult GetDefinitionUsingQuickInfoText(string quickInfoText, string tokenText, string schemaName) { if (this.Database == null) { return(GetDefinitionErrorResult(SR.PeekDefinitionDatabaseError)); } StringComparison caseSensitivity = this.Database.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; string tokenType = GetTokenTypeFromQuickInfo(quickInfoText, tokenText, caseSensitivity); if (tokenType != null) { if (sqlScriptGettersFromQuickInfo.ContainsKey(tokenType.ToLowerInvariant())) { // With SqlLogin authentication, the defaultSchema property throws an Exception when accessed. // This workaround ensures that a schema name is present by attempting // to get the schema name from the declaration item. // If all fails, the default schema name is assumed to be "dbo" if ((connectionInfo != null && connectionInfo.ConnectionDetails.AuthenticationType.Equals(Constants.SqlLoginAuthenticationType)) && string.IsNullOrEmpty(schemaName)) { string fullObjectName = this.GetFullObjectNameFromQuickInfo(quickInfoText, tokenText, caseSensitivity); schemaName = this.GetSchemaFromDatabaseQualifiedName(fullObjectName, tokenText); } Location[] locations = GetSqlObjectDefinition( sqlScriptGettersFromQuickInfo[tokenType.ToLowerInvariant()], tokenText, schemaName, sqlObjectTypesFromQuickInfo[tokenType.ToLowerInvariant()] ); DefinitionResult result = new DefinitionResult { IsErrorResult = this.error, Message = this.errorMessage, Locations = locations }; return(result); } else { // If a type was found but is not in sqlScriptGettersFromQuickInfo, then the type is not supported return(GetDefinitionErrorResult(SR.PeekDefinitionTypeNotSupportedError)); } } // no definition found return(GetDefinitionErrorResult(SR.PeekDefinitionNoResultsError)); }