private static void CreateTestTable(IQuery query, string testName) { var tableName = ObjectName.Parse("APP.test_table"); query.Access().CreateTable(table => { table .Named(tableName) .WithColumn(column => column.Named("id") .HavingType(PrimitiveTypes.Integer()) .WithDefault(SqlExpression.FunctionCall("UNIQUEKEY", new SqlExpression[] { SqlExpression.Constant(tableName.FullName) }))) .WithColumn("first_name", PrimitiveTypes.String()) .WithColumn("last_name", PrimitiveTypes.String()) .WithColumn("birth_date", PrimitiveTypes.DateTime()) .WithColumn(column => column .Named("active") .HavingType(PrimitiveTypes.Boolean()) .NotNull(testName.Equals("NotNullColumnViolation"))); if (testName.EndsWith("WithLob")) { table.WithColumn("bio", PrimitiveTypes.Clob(2048)); } else if (testName.EndsWith("WithUserType")) { var userType = query.Access().ResolveUserType("type1"); table.WithColumn("user_obj", userType); } }); query.Access().AddPrimaryKey(tableName, "id", "PK_TEST_TABLE"); }
internal SqlType GetSqlType() { switch (SqlType) { case SqlTypeCode.Boolean: case SqlTypeCode.Bit: return(PrimitiveTypes.Boolean(SqlType)); case SqlTypeCode.TinyInt: case SqlTypeCode.SmallInt: case SqlTypeCode.Integer: case SqlTypeCode.BigInt: return(PrimitiveTypes.Numeric(SqlType)); case SqlTypeCode.Real: case SqlTypeCode.Float: case SqlTypeCode.Decimal: case SqlTypeCode.Double: case SqlTypeCode.Numeric: return(PrimitiveTypes.Numeric(SqlType, Precision, Scale)); case SqlTypeCode.String: case SqlTypeCode.Char: case SqlTypeCode.VarChar: return(PrimitiveTypes.String(SqlType, Size)); case SqlTypeCode.Binary: case SqlTypeCode.VarBinary: return(PrimitiveTypes.Binary(SqlType, Size)); case SqlTypeCode.Time: case SqlTypeCode.Date: case SqlTypeCode.DateTime: case SqlTypeCode.TimeStamp: return(PrimitiveTypes.DateTime(SqlType)); case SqlTypeCode.DayToSecond: case SqlTypeCode.YearToMonth: return(PrimitiveTypes.Interval(SqlType)); case SqlTypeCode.Clob: case SqlTypeCode.LongVarChar: return(PrimitiveTypes.Clob(Size)); case SqlTypeCode.Blob: case SqlTypeCode.LongVarBinary: return(PrimitiveTypes.Blob(Size)); default: throw new NotSupportedException(); } }
private static void InsertData(IQuery query) { var tableName = ObjectName.Parse("APP.test_table"); var table = query.Access().GetMutableTable(tableName); var bio = CreateBio(query, testBio); var row = table.NewRow(); row["id"] = Field.Integer(1); row["first_name"] = Field.String("Antonello"); row["last_name"] = Field.String("Provenzano"); row["birth_date"] = Field.Date(new SqlDateTime(1980, 06, 04)); row["active"] = Field.BooleanTrue; row["bio"] = new Field(PrimitiveTypes.Clob(2048), bio); table.AddRow(row); }
private static void CreateTable(IQuery query) { var tableName = ObjectName.Parse("APP.test_table"); query.Access().CreateTable(table => table .Named(tableName) .WithColumn(column => column .Named("id") .HavingType(PrimitiveTypes.Integer()) .WithDefault(SqlExpression.FunctionCall("UNIQUEKEY", new SqlExpression[] { SqlExpression.Constant(tableName.FullName) }))) .WithColumn("first_name", PrimitiveTypes.String()) .WithColumn("last_name", PrimitiveTypes.String()) .WithColumn("birth_date", PrimitiveTypes.DateTime()) .WithColumn("active", PrimitiveTypes.Boolean()) .WithColumn("bio", PrimitiveTypes.Clob(2048))); query.Session.Access().AddPrimaryKey(tableName, "id", "PK_TEST_TABLE"); }
protected override bool OnSetUp(string testName, IQuery query) { var tableName = ObjectName.Parse("APP.test_table"); var tableInfo = new TableInfo(tableName); tableInfo.AddColumn("id", PrimitiveTypes.Integer()); tableInfo.AddColumn("name", PrimitiveTypes.VarChar()); tableInfo.AddColumn("age", PrimitiveTypes.TinyInt()); if (testName.EndsWith("Lob")) { tableInfo.AddColumn("bio", PrimitiveTypes.Clob(6030)); } query.Access().CreateObject(tableInfo); AddTestData(testName, query); return(true); }
private void CreateTestTable(string testName, IQuery query) { var tableName1 = ObjectName.Parse("APP.test_table"); query.Access().CreateTable(table => { table .Named(tableName1) .WithColumn(column => column .Named("id") .HavingType(PrimitiveTypes.Integer()) .WithDefault(SqlExpression.FunctionCall("UNIQUEKEY", new SqlExpression[] { SqlExpression.Constant(tableName1.FullName) }))) .WithColumn("first_name", PrimitiveTypes.String()) .WithColumn("last_name", PrimitiveTypes.String()) .WithColumn("birth_date", PrimitiveTypes.DateTime()) .WithColumn("active", PrimitiveTypes.Boolean()); if (testName.EndsWith("WithLob")) { table.WithColumn("bio", PrimitiveTypes.Clob()); } }); query.Access().AddPrimaryKey(tableName1, "id", "PK_TEST_TABLE"); if (testName.EndsWith("ConstraintCheck") || testName.EndsWith("Violation")) { var tableName2 = ObjectName.Parse("APP.test_table2"); query.Access().CreateTable(table => { table .Named(tableName2) .WithColumn(column => column .Named("id") .HavingType(PrimitiveTypes.Integer()) .WithDefault(SqlExpression.FunctionCall("UNIQUEKEY", new SqlExpression[] { SqlExpression.Constant(tableName2.FullName) }))); if (testName.StartsWith("SetDefault")) { table.WithColumn(column => column .Named("person_id") .HavingType(PrimitiveTypes.Integer()) .WithDefault(SqlExpression.Constant(1))); } else { table.WithColumn(column => column .Named("person_id") .HavingType(PrimitiveTypes.Integer()) .NotNull(testName.EndsWith("Violation"))); } table.WithColumn("dept_no", PrimitiveTypes.Integer()); }); query.Access().AddPrimaryKey(tableName2, "id", "PK_TEST_TABLE2"); ForeignKeyAction?onDelete = null; if (testName.StartsWith("SetNullOnDelete")) { onDelete = ForeignKeyAction.SetNull; } else if (testName.StartsWith("SetDefaultOnDelete")) { onDelete = ForeignKeyAction.SetDefault; } else if (testName.StartsWith("CascadeOnDelete")) { onDelete = ForeignKeyAction.Cascade; } if (onDelete != null) { query.Access() .AddForeignKey(tableName2, new[] { "person_id" }, tableName1, new[] { "id" }, onDelete.Value, ForeignKeyAction.NoAction, "FKEY_TEST_TABLE2"); } } }