Search in sources :

Example 1 with InsertSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.InsertSqlBuilder in project dal by ctripcorp.

the class InsertSqlBuilderTest method testBuildSqlsvr.

@Test
public void testBuildSqlsvr() throws SQLException {
    InsertSqlBuilder isb = new InsertSqlBuilder().from("table").setDatabaseCategory(DatabaseCategory.SqlServer);
    isb.set("f1", 1, Types.INTEGER);
    isb.setSensitive("f2", "abc", Types.VARBINARY);
    assertEquals("INSERT INTO [table] ([f1], [f2]) VALUES(?, ?)", isb.build());
    assertEquals("INSERT INTO [table_0] ([f1], [f2]) VALUES(?, ?)", isb.build("_0"));
    StatementParameters p = isb.buildParameters();
    assertEquals(2, p.size());
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) InsertSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.InsertSqlBuilder) Test(org.junit.Test)

Example 2 with InsertSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.InsertSqlBuilder in project dal by ctripcorp.

the class InsertSqlBuilderTest method testBuildMySql.

@Test
public void testBuildMySql() throws SQLException {
    InsertSqlBuilder isb = new InsertSqlBuilder().from("table").setDatabaseCategory(DatabaseCategory.MySql);
    isb.set("f1", 1, Types.INTEGER);
    isb.setSensitive("f2", "abc", Types.VARBINARY);
    assertEquals("INSERT INTO `table` (`f1`, `f2`) VALUES(?, ?)", isb.build());
    assertEquals("INSERT INTO `table_0` (`f1`, `f2`) VALUES(?, ?)", isb.build("_0"));
    StatementParameters p = isb.buildParameters();
    assertEquals(2, p.size());
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) InsertSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.InsertSqlBuilder) Test(org.junit.Test)

Aggregations

StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)2 InsertSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.InsertSqlBuilder)2 Test (org.junit.Test)2