Example #1
0
 private void CreateIndexPrimaryKey(View view, Index index)
 {
     log("Creating Primary Key: " + view.Name + " (" + index.Columns + ")");
     ExecuteNonQuery(string.Format("CREATE UNIQUE CLUSTERED INDEX {1} ON [{0}] ({2});", view.Name, index.Name, EscapeColumnList(false, index.Columns)));
 }
Example #2
0
        private bool CreateView(View view, bool alterInsteadOfCreate)
        {
            StringBuilder sb = new StringBuilder("CREATE VIEW ");
            sb.AppendFormat("[dbo].[{0}]", view.Name);

            if (view.Indexes != null && view.Indexes.Length > 0)
                sb.Append(" WITH SCHEMABINDING");

            sb.AppendLine(" AS ");
            sb.AppendLine(view.Body.Trim());

            string oldCreateStatement = (string)ExecuteScalar("SELECT OBJECT_DEFINITION(OBJECT_ID(@p1));", view.Name);
            string createStatement = sb.ToString();

            if (oldCreateStatement == createStatement)
                return false;

            log("Creating View: " + view.Name);

            if (!alterInsteadOfCreate)
                RunCallback(view, CallbackAction.Before);
            else
                createStatement = "ALTER" + createStatement.Substring("CREATE".Length);

            ExecuteNonQuery(createStatement);

            ExecuteNonQuery("GRANT ALL, VIEW DEFINITION ON [" + view.Name + "] TO mine_users");
            RunCallback(view, CallbackAction.After);
            return true;
        }
Example #3
0
 private void CreateIndex(View view, Index index)
 {
     RunCallback(index, CallbackAction.Before);
     switch (index.Type)
     {
         case IndexType.PrimaryKey:
             CreateIndexPrimaryKey(view, index);
             break;
         case IndexType.Index:
             CreateIndexRegular(view.Name, null, false, index);
             break;
         case IndexType.Unique:
             CreateIndexUnique(view.Name, index);
             break;
         default:
             break;
     }
     RunCallback(index, CallbackAction.After);
 }