The statement object used to create a table in a database.
Inheritance: 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
     });
 }
コード例 #3
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);
        }
コード例 #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);
        }
コード例 #5
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);
        }
コード例 #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);
        }
コード例 #7
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);
        }
コード例 #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);
        }
コード例 #9
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);
        }
コード例 #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
ファイル: StatementVisitor.cs プロジェクト: deveel/deveeldb
 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;
        }
コード例 #13
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);
        }
コード例 #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;
 }