Identifier() public static méthode

Throws an exception if 'name' is not a valid SQL database object name. Function returns given argument so it can be used as fluent interface. In some cases the function may change the identifier (limit identifier length to 30 on Oracle database, e.g.).
public static Identifier ( string name ) : string
name string
Résultat string
        public static string GetSchemaName(string fullObjectName)
        {
            int dotPosition = fullObjectName.IndexOf('.');

            if (dotPosition == -1)
            {
                throw new FrameworkException($"Missing schema name for database object '{fullObjectName}'.");
            }

            var schema = fullObjectName.Substring(0, dotPosition);

            return(SqlUtility.Identifier(schema));
        }
Exemple #2
0
        public static string GetShortName(string fullObjectName)
        {
            int dotPosition = fullObjectName.IndexOf('.');

            if (dotPosition == -1)
            {
                return(fullObjectName);
            }

            var shortName = fullObjectName.Substring(dotPosition + 1);

            int secondDot = shortName.IndexOf('.');

            if (secondDot != -1 || string.IsNullOrEmpty(shortName))
            {
                throw new FrameworkException("Invalid database object name: '" + fullObjectName + "'. Expected format is 'schema.name' or 'name'.");
            }
            return(SqlUtility.Identifier(shortName));
        }
Exemple #3
0
        public static string GetSchemaName(string fullObjectName)
        {
            int dotPosition = fullObjectName.IndexOf('.');

            if (dotPosition == -1)
            {
                if (DatabaseLanguageIsMsSql.Value)
                {
                    return("dbo");
                }
                else if (DatabaseLanguageIsOracle.Value)
                {
                    throw new FrameworkException("Missing schema name for database object '" + fullObjectName + "'.");
                }
                else
                {
                    throw new FrameworkException(UnsupportedLanguageError);
                }
            }

            var schema = fullObjectName.Substring(0, dotPosition);

            return(SqlUtility.Identifier(schema));
        }