예제 #1
0
        protected override void BuildEndCreateTableStatement(SqlCreateTableStatement createTable)
        {
            var table = createTable.Table;

            if (table.TableOptions.IsTemporaryOptionSet())
            {
                StringBuilder.AppendLine(table.TableOptions.HasIsTransactionTemporaryData()
                                        ? "ON COMMIT DELETE ROWS"
                                        : "ON COMMIT PRESERVE ROWS");
            }

            base.BuildEndCreateTableStatement(createTable);
        }
예제 #2
0
        protected override void BuildCreateTablePrimaryKey(SqlCreateTableStatement createTable, string pkName, IEnumerable <string> fieldNames)
        {
            AppendIndent();

            if (!pkName.StartsWith("[PK_#") && !createTable.Table.TableOptions.IsTemporaryOptionSet())
            {
                StringBuilder.Append("CONSTRAINT ");
                Convert(StringBuilder, pkName, ConvertType.NameToQueryTable).Append(' ');
            }

            StringBuilder.Append("PRIMARY KEY CLUSTERED (");
            StringBuilder.Append(string.Join(InlineComma, fieldNames));
            StringBuilder.Append(')');
        }
예제 #3
0
 protected override void BuildDropTableStatement(SqlCreateTableStatement createTable)
 {
     if (_identityField == null)
     {
         base.BuildDropTableStatement(createTable);
     }
     else
     {
         StringBuilder
         .Append("DROP TRIGGER TIDENTITY_")
         .Append(createTable.Table.PhysicalName)
         .AppendLine();
     }
 }
예제 #4
0
        protected override void BuildEndCreateTableStatement(SqlCreateTableStatement createTable)
        {
            base.BuildEndCreateTableStatement(createTable);

            if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists())
            {
                if (!IsTemporary(createTable.Table.TableName.Name, createTable.Table.TableOptions))
                {
                    Indent--;
                    AppendIndent().AppendLine("')");
                }

                Indent--;
            }
        }
예제 #5
0
        protected override void BuildCreateTablePrimaryKey(SqlCreateTableStatement createTable, string pkName, IEnumerable <string> fieldNames)
        {
            // DB2 doesn't support constraints on temp tables
            if (createTable.Table.TableOptions.IsTemporaryOptionSet())
            {
                var idx = StringBuilder.Length - 1;
                while (idx >= 0 && StringBuilder[idx] != ',')
                {
                    idx--;
                }
                StringBuilder.Length = idx == -1 ? 0 : idx;
                return;
            }

            base.BuildCreateTablePrimaryKey(createTable, pkName, fieldNames);
        }
예제 #6
0
        protected override void BuildStartCreateTableStatement(SqlCreateTableStatement createTable)
        {
            if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists())
            {
                AppendIndent().AppendLine(@"BEGIN");

                Indent++;

                AppendIndent().AppendLine(@"DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' BEGIN END;");
                AppendIndent().AppendLine(@"EXECUTE IMMEDIATE '");

                Indent++;
            }

            base.BuildStartCreateTableStatement(createTable);
        }
예제 #7
0
 protected override void BuildStartCreateTableStatement(SqlCreateTableStatement createTable)
 {
     if (createTable.StatementHeader == null)
     {
         AppendIndent().Append("CREATE COLUMN TABLE ");
         BuildPhysicalTable(createTable.Table !, null);
     }
     else
     {
         var name = WithStringBuilder(
             new StringBuilder(),
             () =>
         {
             BuildPhysicalTable(createTable.Table !, null);
             return(StringBuilder.ToString());
         });
예제 #8
0
        protected override void BuildEndCreateTableStatement(SqlCreateTableStatement createTable)
        {
            base.BuildEndCreateTableStatement(createTable);

            if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists())
            {
                Indent--;

                AppendIndent()
                .AppendLine("';");

                Indent--;

                StringBuilder
                .AppendLine("END");
            }
        }
예제 #9
0
 protected override void BuildCreateTablePrimaryKey(SqlCreateTableStatement createTable, string pkName, IEnumerable <string> fieldNames)
 {
     if (createTable.Table.Fields.Values.Any(f => f.IsIdentity))
     {
         while (StringBuilder[StringBuilder.Length - 1] != ',')
         {
             StringBuilder.Length--;
         }
         StringBuilder.Length--;
     }
     else
     {
         AppendIndent();
         StringBuilder.Append("CONSTRAINT ").Append(pkName).Append(" PRIMARY KEY (");
         StringBuilder.Append(fieldNames.Aggregate((f1, f2) => f1 + ", " + f2));
         StringBuilder.Append(")");
     }
 }
예제 #10
0
        protected override void BuildDropTableStatement(SqlCreateTableStatement createTable)
        {
            if (_identityField == null)
            {
                base.BuildDropTableStatement(createTable);
            }
            else
            {
                var schemaPrefix = string.IsNullOrWhiteSpace(createTable.Table.Owner)
                                ? string.Empty
                                : createTable.Table.Owner + ".";

                StringBuilder
                .Append("DROP TRIGGER ")
                .Append(schemaPrefix)
                .Append("TIDENTITY_")
                .Append(createTable.Table.PhysicalName)
                .AppendLine();
            }
        }
예제 #11
0
        protected override void BuildDropTableStatement(SqlCreateTableStatement createTable)
        {
            var table = createTable.Table;

            if (table.PhysicalName.StartsWith("#"))
            {
                AppendIndent().Append("DROP TABLE ");
                BuildPhysicalTable(table, null);
                StringBuilder.AppendLine();
            }
            else
            {
                StringBuilder.Append("IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'");
                BuildPhysicalTable(table, null);
                StringBuilder.AppendLine("') AND type in (N'U'))");

                AppendIndent().Append("BEGIN DROP TABLE ");
                BuildPhysicalTable(table, null);
                StringBuilder.AppendLine(" END");
            }
        }
예제 #12
0
 public override void Visit(SqlCreateTableStatement codeObject)
 {
 }
예제 #13
0
 internal CreateTable(SqlCreateTableStatement createTable)
 {
     _CreateTable = createTable;
     _Table       = new Table(createTable.Name);
 }
예제 #14
0
            public static async Task <ITable <T> > QueryAsync(
                IDataContext dataContext,
                string?tableName,
                string?serverName,
                string?databaseName,
                string?schemaName,
                string?statementHeader,
                string?statementFooter,
                DefaultNullable defaultNullable,
                TableOptions tableOptions,
                CancellationToken token)
            {
                var sqlTable    = new SqlTable <T>(dataContext.MappingSchema);
                var createTable = new SqlCreateTableStatement(sqlTable);

                if (tableName != null)
                {
                    sqlTable.PhysicalName = tableName;
                }
                if (serverName != null)
                {
                    sqlTable.Server = serverName;
                }
                if (databaseName != null)
                {
                    sqlTable.Database = databaseName;
                }
                if (schemaName != null)
                {
                    sqlTable.Schema = schemaName;
                }
                if (tableOptions.IsSet())
                {
                    sqlTable.TableOptions = tableOptions;
                }

                createTable.StatementHeader = statementHeader;
                createTable.StatementFooter = statementFooter;
                createTable.DefaultNullable = defaultNullable;

                var query = new Query <int>(dataContext, null)
                {
                    Queries = { new QueryInfo {
                                    Statement = createTable,
                                } }
                };

                SetNonQueryQuery(query);

                await query.GetElementAsync(dataContext, ExpressionInstances.UntypedNull, null, null, token).ConfigureAwait(Common.Configuration.ContinueOnCapturedContext);

                ITable <T> table = new Table <T>(dataContext);

                if (sqlTable.PhysicalName != null)
                {
                    table = table.TableName(sqlTable.PhysicalName);
                }
                if (sqlTable.Server != null)
                {
                    table = table.ServerName(sqlTable.Server);
                }
                if (sqlTable.Database != null)
                {
                    table = table.DatabaseName(sqlTable.Database);
                }
                if (sqlTable.Schema != null)
                {
                    table = table.SchemaName(sqlTable.Schema);
                }
                if (sqlTable.TableOptions.IsSet())
                {
                    table = table.TableOptions(sqlTable.TableOptions);
                }

                return(table);
            }
            public static ITable <T> Query(
                IDataContext dataContext,
                string?tableName,
                string?serverName,
                string?databaseName,
                string?schemaName,
                string?statementHeader,
                string?statementFooter,
                DefaultNullable defaultNullable,
                TableOptions tableOptions)
            {
                var sqlTable    = new SqlTable <T>(dataContext.MappingSchema);
                var createTable = new SqlCreateTableStatement(sqlTable);

                if (tableName != null)
                {
                    sqlTable.PhysicalName = tableName;
                }
                if (serverName != null)
                {
                    sqlTable.Server = serverName;
                }
                if (databaseName != null)
                {
                    sqlTable.Database = databaseName;
                }
                if (schemaName != null)
                {
                    sqlTable.Schema = schemaName;
                }
                if (tableOptions.IsSet())
                {
                    sqlTable.TableOptions = tableOptions;
                }

                createTable.StatementHeader = statementHeader;
                createTable.StatementFooter = statementFooter;
                createTable.DefaultNullable = defaultNullable;

                var query = new Query <int>(dataContext, null)
                {
                    Queries = { new QueryInfo {
                                    Statement = createTable,
                                } }
                };

                SetNonQueryQuery(query);

                query.GetElement(dataContext, Expression.Constant(null), null, null);

                ITable <T> table = new Table <T>(dataContext);

                if (sqlTable.PhysicalName != null)
                {
                    table = table.TableName(sqlTable.PhysicalName);
                }
                if (sqlTable.Server != null)
                {
                    table = table.ServerName(sqlTable.Server);
                }
                if (sqlTable.Database != null)
                {
                    table = table.DatabaseName(sqlTable.Database);
                }
                if (sqlTable.Schema != null)
                {
                    table = table.SchemaName(sqlTable.Schema);
                }
                if (sqlTable.TableOptions.IsSet())
                {
                    table = table.TableOptions(sqlTable.TableOptions);
                }

                return(table);
            }