示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TriggerOrder"/> class.
 /// </summary>
 /// <param name="table">The table this trigger is defined on.</param>
 /// <param name="statementType">Type of the statement.</param>
 /// <param name="order">The defined order.</param>
 /// <param name="trigger">The trigger.</param>
 public TriggerOrder(Name table, SmallName statementType, SmallName order, Name trigger)
     : base(table.Unescaped + "_" + statementType.Unescaped + "_" + order)
 {
     Order         = order;
     StatementType = statementType;
     Trigger       = trigger;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Index"/> class.
 /// </summary>
 /// <param name="name">The index name.</param>
 /// <param name="table">The indexed table.</param>
 /// <param name="clustered">if set to <c>true</c> [clustered].</param>
 /// <param name="unique">if set to <c>true</c> [unique].</param>
 public Index(string name, Name table, bool clustered, bool unique)
     : base(table.Unescaped + "." + ((SmallName)name).Unescaped)
 {
     Clustered        = clustered;
     ColumnDirections = new List <SmallName>();
     Columns          = new List <SmallName>();
     Enabled          = true;
     Include          = new List <SmallName>();
     IndexName        = name;
     Table            = table;
     Unique           = unique;
 }
示例#3
0
        private bool IsDifferent(PermissionSet other, DifferenceSet differences, Name name)
        {
            if (!other.permissions.ContainsKey(name))
            {
                return(true);
            }

            foreach (SmallName account in permissions[name].Keys)
            {
                if (!other.permissions[name].ContainsKey(account))
                {
                    return(true);
                }

                foreach (SmallName grantType in permissions[name][account].Keys)
                {
                    SmallName permission      = permissions[name][account][grantType];
                    SmallName otherPermission = null;

                    bool granted = other.permissions[name][account].ContainsKey(grantType);
                    if (!granted && grantType == "exec" && other.permissions[name][account].ContainsKey("execute"))
                    {
                        granted         = true;
                        otherPermission = other.permissions[name][account]["execute"];
                    }
                    if (!granted && grantType == "execute" && other.permissions[name][account].ContainsKey("exec"))
                    {
                        granted         = true;
                        otherPermission = other.permissions[name][account]["exec"];
                    }
                    if (!granted)
                    {
                        return(true);
                    }

                    if (otherPermission == null)
                    {
                        otherPermission = other.permissions[name][account][grantType];
                    }

                    if (permission != otherPermission)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Sets a permission.
        /// </summary>
        /// <param name="permissionType">Type of the permission.</param>
        /// <param name="account">The account.</param>
        /// <param name="grantingObject">The granting object.</param>
        /// <param name="grantType">Type of the grant.</param>
        private void SetPermission(SmallName permissionType, SmallName account, Name grantingObject, SmallName grantType)
        {
            if (!permissions.ContainsKey(grantingObject))
            {
                permissions[grantingObject] = new Dictionary <SmallName, Dictionary <SmallName, SmallName> >();
            }
            Dictionary <SmallName, Dictionary <SmallName, SmallName> > granting = permissions[grantingObject];

            if (!granting.ContainsKey(account))
            {
                granting[account] = new Dictionary <SmallName, SmallName>();
            }
            Dictionary <SmallName, SmallName> permission = granting[account];

            permission[permissionType] = grantType;
        }
示例#5
0
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            if (obj is SmallName)
            {
                SmallName other = obj as SmallName;

                if (other == null)
                {
                    other = new SmallName(obj as string);
                }

                if (other == null)
                {
                    return(false);
                }

                return(objectName.ToLower() == other.objectName.ToLower());
            }
            return(false);
        }
示例#6
0
 /// <summary>
 /// Gets or sets the <see cref="System.String"/> with the specified name.
 /// </summary>
 /// <value></value>
 public string this[SmallName name]
 {
     get { return(values[name]); }
     set { values[name] = value; }
 }
示例#7
0
 /// <summary>
 /// Determines whether the specified column is defined in this row.
 /// </summary>
 /// <param name="name">The column name.</param>
 /// <returns>
 ///     <c>true</c> if the specified column is defined in this row; otherwise, <c>false</c>.
 /// </returns>
 public bool ContainsColumn(SmallName name)
 {
     return(values.ContainsKey(name));
 }
示例#8
0
        /// <summary>
        /// Flattens this token and its children into a single string.
        /// </summary>
        /// <returns></returns>
        public string FlattenTree(bool escapeValues)
        {
            string val = Value;

            if (escapeValues && this.Type == TokenType.Identifier)
            {
                if (Children.Count == 0)
                {
                    val = new DBTypes.SmallName(val).ToString();
                }
                else
                {
                    val = ((DBTypes.Name)val).ToString();
                }
            }

            StringBuilder retVal = new StringBuilder();

            if (Type == TokenType.Dot || Type == TokenType.Operator)
            {
                if (Children.Count > 2)
                {
                    throw new Exception("Unexpected child count");
                }

                //if 2 operands, value is middle otherwise value 1st
                if (Children.Count > 1)
                {
                    retVal.Append(Children.First.FlattenTree(escapeValues));
                    if (Type == TokenType.Operator)
                    {
                        retVal.Append(" ");
                    }
                }
                retVal.Append(val);
                if (Children.Count > 1)
                {
                    if (Type == TokenType.Operator)
                    {
                        retVal.Append(" ");
                    }
                    retVal.Append(Children.Last.FlattenTree(escapeValues));
                }
                else if (Children.Count > 0)
                {
                    retVal.Append(Children.First.FlattenTree(escapeValues));
                }
            }
            else if (Value.ToLower() == "and" || Value.ToLower() == "or")
            {
                if (Children.Count > 2)
                {
                    throw new Exception("Unexpected child count");
                }

                //if 2 operands, value is middle otherwise value 1st
                if (Children.Count > 1)
                {
                    retVal.Append(Children.First.FlattenTree(escapeValues) + " ");
                }
                retVal.Append(val);
                if (Children.Count > 1)
                {
                    retVal.Append(" " + Children.Last.FlattenTree(escapeValues));
                }
                else if (Children.Count > 0)
                {
                    retVal.Append(" " + Children.First.FlattenTree(escapeValues));
                }
            }
            else
            {
                retVal.Append(val);
                foreach (Token child in Children)
                {
                    retVal.Append(" " + child.FlattenTree(escapeValues));
                }
            }
            return(retVal.ToString());
        }
示例#9
0
        /// <summary>
        /// Generates a create script.
        /// </summary>
        /// <returns></returns>
        public override Script GenerateCreateScript()
        {
            StringBuilder output = new StringBuilder();

            output.Append("CREATE");
            if (Unique)
            {
                output.Append(" UNIQUE");
            }
            if (Clustered)
            {
                output.Append(" CLUSTERED");
            }
            output.Append(" INDEX " + IndexName);
            output.Append("\r\nON " + Table + "(");
            for (int i = 0; i < Columns.Count; i++)
            {
                SmallName column    = Columns[i];
                SmallName direction = (SmallName)ColumnDirections[i];
                output.Append("\r\n\t" + column);
                if (direction != null)
                {
                    output.Append(" " + direction.Unescaped);
                }
                output.Append(",");
            }
            output.Remove(output.Length - 1, 1);
            output.Append("\r\n)\r\n");
            if (Include.Count > 0)
            {
                output.Append("INCLUDE(");
                for (int i = 0; i < Include.Count; i++)
                {
                    SmallName column = Include[i];
                    output.Append("\r\n\t" + column);
                    output.Append(",");
                }
                output.Remove(output.Length - 1, 1);
                output.Append("\r\n)\r\n");
            }
            if (Where != null && Where != "")
            {
                output.Append("WHERE " + Where);
                output.Append("\r\n");
            }
            if (With != null && With != "")
            {
                output.Append("WITH " + With);
                output.Append("\r\n");
            }
            if (FileGroup != null && "" != FileGroup.Unescaped)
            {
                output.Append("ON " + FileGroup);
                output.Append("\r\n");
            }
            if (!Enabled)
            {
                output.AppendLine();
                output.Append("ALTER INDEX ");
                output.Append(IndexName);
                output.Append(" ON ");
                output.Append(Table);
                output.Append(" DISABLE");
                output.Append("\r\n");
            }

            return(new Script(output.ToString(), Name, Clustered ? ScriptType.ClusteredIndex : ScriptType.Index));
        }
示例#10
0
 /// <summary>
 /// Check if two identifiers are primary file groups
 /// </summary>
 /// <param name="group0">The group0.</param>
 /// <param name="group1">The group1.</param>
 /// <returns>True if both names match as primary filegroups</returns>
 protected bool PrimaryFileGroups(SmallName group0, SmallName group1)
 {
     return((group0 == null || group0.Unescaped.ToLower().Trim() == "primary") &&
            (group1 == null || group1.Unescaped.ToLower().Trim() == "primary"));
 }
示例#11
0
 /// <summary>
 /// Denies the specified permission.
 /// </summary>
 /// <param name="permissionType">Type of the permission.</param>
 /// <param name="account">The account.</param>
 /// <param name="grantingObject">The granting object.</param>
 public void Deny(string permissionType, SmallName account, Name grantingObject)
 {
     SetPermission(permissionType, account, grantingObject, "DENY");
 }
示例#12
0
 /// <summary>
 /// Grants the specified permission.
 /// </summary>
 /// <param name="permissionType">Type of the permission.</param>
 /// <param name="account">The account.</param>
 /// <param name="grantingObject">The granting object.</param>
 public void Grant(SmallName permissionType, SmallName account, Name grantingObject)
 {
     SetPermission(permissionType, account, grantingObject, "GRANT");
 }