The statement object used to create a table in a database.
상속: SqlStatement, IPreparableStatement
예제 #1
0
        public static void ColumnWithDefault()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                                                     new[] {
                new SqlTableColumn("a", PrimitiveTypes.Integer())
                {
                    DefaultExpression = SqlExpression.Constant(1)
                },
                new SqlTableColumn("b", PrimitiveTypes.String())
                {
                    IsNotNull = true
                }
            });

            var sql = statement.ToString();

            var expected = new StringBuilder();

            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  a INTEGER DEFAULT 1,");
            expected.AppendLine("  b STRING NOT NULL");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
예제 #2
0
 protected virtual SqlStatement VisitCreateTable(CreateTableStatement statement)
 {
     return(new CreateTableStatement(statement.TableName, statement.Columns)
     {
         Temporary = statement.Temporary,
         IfNotExists = statement.IfNotExists
     });
 }
        public void SimpleCreate()
        {
            var tableName = ObjectName.Parse("APP.test");
            var columns = new SqlTableColumn[] {
                new SqlTableColumn("id", PrimitiveTypes.Integer()),
                new SqlTableColumn("name", PrimitiveTypes.VarChar()),
            };
            var statement = new CreateTableStatement(tableName, columns);

            ITable result = null;
            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
        }
예제 #4
0
        public void SimpleCreate()
        {
            var tableName = ObjectName.Parse("APP.test");
            var columns   = new SqlTableColumn[] {
                new SqlTableColumn("id", PrimitiveTypes.Integer()),
                new SqlTableColumn("name", PrimitiveTypes.VarChar()),
            };
            var statement = new CreateTableStatement(tableName, columns);

            ITable result = null;

            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
        }
        public static void SimpleTable()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                new[] {
                    new SqlTableColumn("a", PrimitiveTypes.Integer()),
                    new SqlTableColumn("b", PrimitiveTypes.String()),
                });

            var sql = statement.ToString();

            var expected = new StringBuilder();
            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  a INTEGER,");
            expected.AppendLine("  b STRING");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
예제 #6
0
        public static void SimpleTable()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                                                     new[] {
                new SqlTableColumn("a", PrimitiveTypes.Integer()),
                new SqlTableColumn("b", PrimitiveTypes.String()),
            });

            var sql = statement.ToString();

            var expected = new StringBuilder();

            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  a INTEGER,");
            expected.AppendLine("  b STRING");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public void WithColumnDefault()
        {
            var tableName = ObjectName.Parse("APP.test");
            var columns = new SqlTableColumn[] {
                new SqlTableColumn("id", PrimitiveTypes.Integer()),
                new SqlTableColumn("name", PrimitiveTypes.VarChar()) {
                    DefaultExpression = SqlExpression.Parse("((67 * 90) + 22)")
                },
                new SqlTableColumn("date", PrimitiveTypes.TimeStamp()) {
                    DefaultExpression = SqlExpression.Parse("GetDate()")
                }
            };

            var statement = new CreateTableStatement(tableName, columns);

            ITable result = null;
            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
        }
예제 #8
0
        public static void WithIdentityColumn()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                                                     new[] {
                new SqlTableColumn("id", PrimitiveTypes.Integer())
                {
                    IsIdentity = true
                },
                new SqlTableColumn("name", PrimitiveTypes.String()),
            });

            var sql = statement.ToString();

            var expected = new StringBuilder();

            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  id INTEGER IDENTITY,");
            expected.AppendLine("  name STRING");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void ColumnWithDefault()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                new[] {
                    new SqlTableColumn("a", PrimitiveTypes.Integer()) {
                        DefaultExpression = SqlExpression.Constant(1)
                    },
                    new SqlTableColumn("b", PrimitiveTypes.String()) {
                        IsNotNull = true
                    }
                });

            var sql = statement.ToString();

            var expected = new StringBuilder();
            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  a INTEGER DEFAULT 1,");
            expected.AppendLine("  b STRING NOT NULL");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
예제 #10
0
        public void WithColumnDefault()
        {
            var tableName = ObjectName.Parse("APP.test");
            var columns   = new SqlTableColumn[] {
                new SqlTableColumn("id", PrimitiveTypes.Integer()),
                new SqlTableColumn("name", PrimitiveTypes.VarChar())
                {
                    DefaultExpression = SqlExpression.Parse("((67 * 90) + 22)")
                },
                new SqlTableColumn("date", PrimitiveTypes.TimeStamp())
                {
                    DefaultExpression = SqlExpression.Parse("GetDate()")
                }
            };

            var statement = new CreateTableStatement(tableName, columns);

            ITable result = null;

            Assert.DoesNotThrow(() => result = statement.Execute(Query));
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);
        }
예제 #11
0
 protected virtual SqlStatement VisitCreateTable(CreateTableStatement statement)
 {
     return new CreateTableStatement(statement.TableName, statement.Columns) {
         Temporary = statement.Temporary,
         IfNotExists = statement.IfNotExists
     };
 }
예제 #12
0
        private static SqlStatement MakeCreateTable(string tableName, IEnumerable<SqlTableColumn> columns, bool ifNotExists,
			bool temporary)
        {
            var objTableName = ObjectName.Parse(tableName);
            var tree = new CreateTableStatement(objTableName, columns.ToList());
            tree.IfNotExists = ifNotExists;
            tree.Temporary = temporary;
            return tree;
        }
        public static void WithIdentityColumn()
        {
            var statement = new CreateTableStatement(new ObjectName("test_table"),
                new[] {
                    new SqlTableColumn("id", PrimitiveTypes.Integer()) {
                        IsIdentity = true
                    },
                    new SqlTableColumn("name", PrimitiveTypes.String()),
                });

            var sql = statement.ToString();

            var expected = new StringBuilder();
            expected.AppendLine("CREATE TABLE test_table (");
            expected.AppendLine("  id INTEGER IDENTITY,");
            expected.AppendLine("  name STRING");
            expected.Append(")");

            Assert.AreEqual(expected.ToString(), sql);
        }
예제 #14
0
 internal Prepared(ObjectName tableName, CreateTableStatement.Prepared createStatement)
 {
     TableName = tableName;
     CreateStatement = createStatement;
 }
예제 #15
0
 public AlterCreateTableStatement(string tableName, CreateTableStatement createStatement)
 {
     TableName = tableName;
     CreateStatement = createStatement;
 }