A parser that detects the type and name of a sql object from a script.
Exemplo n.º 1
0
        public SqlName Append(string objectName)
        {
            if (Table != Object)
            {
                throw new InvalidOperationException("Cannot get a child of an object that is not a table");
            }

            SqlName child = (SqlName)MemberwiseClone();

            child.Object = SqlParser.UnformatSqlName(objectName);

            return(child);
        }
Exemplo n.º 2
0
        public SqlName(string fullName, int expectedParts)
        {
            Original = fullName;

            var split = SplitSqlName(fullName);

            if (split.Length < expectedParts)
            {
                fullName = "[dbo]." + fullName;
                split    = SplitSqlName(fullName);
            }

            // in some special cases (autoproc, permissions), we just need the original
            if (split.Length > expectedParts)
            {
                return;
            }

            if (split.Length == 1)
            {
                Table  = split[0];
                Object = split[0];
            }
            else if (split.Length == 2)
            {
                Schema = split[0];
                Table  = split[1];
                Object = split[1];
            }
            else if (split.Length == 3)
            {
                Schema = split[0];
                Table  = split[1];
                Object = split[2];
            }

            if (split.Length > 1 && String.IsNullOrWhiteSpace(Schema))
            {
                Schema = "dbo";
            }

            Schema = SqlParser.UnformatSqlName(Schema);
            Table  = SqlParser.UnformatSqlName(Table);
            Object = SqlParser.UnformatSqlName(Object);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validate that the schema is a valid schema. This checks names and duplicate objects.
        /// </summary>
        public void Validate()
        {
            // check for duplicate objects and invalid names
            foreach (SchemaObject schemaObject in this)
            {
                if (schemaObject.SchemaObjectType == SchemaObjectType.Unused)
                {
                    continue;
                }

                // validate the name
                SqlParser.AssertValidSqlName(schemaObject.Name);

                // if there are any duplicates, throw an exception
                if (this.Count(o => o.Name == schemaObject.Name) > 1)
                {
                    throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, Properties.Resources.DuplicateObjectName, schemaObject.Name));
                }
            }
        }