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); }
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); }
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); }
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); }
protected virtual SqlStatement VisitCreateTable(CreateTableStatement statement) { return new CreateTableStatement(statement.TableName, statement.Columns) { Temporary = statement.Temporary, IfNotExists = statement.IfNotExists }; }
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; }
internal Prepared(ObjectName tableName, CreateTableStatement.Prepared createStatement) { TableName = tableName; CreateStatement = createStatement; }
public AlterCreateTableStatement(string tableName, CreateTableStatement createStatement) { TableName = tableName; CreateStatement = createStatement; }