Пример #1
0
 /// <summary>
 /// Creates a relational INDEX on a specified temporary table.
 /// </summary>
 /// <param name="prev">A predecessor object.</param>
 /// <param name="table">The name of a temporary table.</param>
 /// <param name="index">The name of the relational index.</param>
 /// <param name="indexType">Is a type of the index.</param>
 public static CreateTempTableIndexChainer CreateTempTableIndex(this IAny prev,
                                                                string table, string index, Designer.IndexType indexType = Designer.IndexType.Nonclustered)
 {
     return(new CreateTempTableIndexChainer((Chainer)prev, table, index, indexType));
 }
Пример #2
0
        internal CreateTempTableIndexChainer(Chainer prev, string table, string index, Designer.IndexType indexType)
            : base(prev)
        {
            CheckNullAndThrow(Arg(() => table, table));
            CheckNullAndThrow(Arg(() => index, index));

            if (!GetRoot().TempTableExists(table))
            {
                Throw(QueryTalkExceptionType.UnknownTempTable,
                      String.Format("temp table = {0}{1}   index = {2}", table, Environment.NewLine, index));
            }

            if (Common.CheckIdentifier(index) != IdentifierValidity.RegularIdentifier)
            {
                Throw(QueryTalkExceptionType.InvalidIndexName, ArgVal(() => index, index));
            }

            Build = (buildContext, buildArgs) =>
            {
                var sql = Text.GenerateSql(200)
                          .NewLine(Text.Create).S();

                switch (indexType)
                {
                case Designer.IndexType.Nonclustered: sql.Append(Text.Nonclustered).S(); break;

                case Designer.IndexType.Clustered: sql.Append(Text.Clustered).S(); break;

                case Designer.IndexType.UniqueNonclustered: sql.Append(Text.NonclusteredUnique).S(); break;

                case Designer.IndexType.UniqueClustered: sql.Append(Text.ClusteredUnique).S(); break;
                }

                sql.Append(Text.Index).S()
                .Append(index).S()
                .Append(Text.On).S()
                .Append(table);

                return(sql.ToString());
            };
        }