use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientSqlServerTest method execTestWithParametersForSpWithoutOutParameter.
@Test
public void execTestWithParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "exec " + SP_WITHOUT_OUT_PARAM + " @v_id=?, @v_quantity=?, @v_type=?, @v_address=?";
// set disordered parameter by name
StatementParameters parameters = new StatementParameters();
parameters.set("v_quantity", Types.INTEGER, 10);
parameters.set("v_id", Types.INTEGER, 4);
parameters.set("v_type", Types.SMALLINT, 3);
parameters.set("v_address", Types.VARCHAR, "SZ INFO");
DalHints hints = new DalHints();
Map<String, ?> res = client.call(callSql, parameters, hints);
Assert.assertTrue(null != res);
Assert.assertEquals(0, res.size());
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(4, models.size());
// set disordered parameter by index and name
StatementParameters parameters2 = new StatementParameters();
int index = 1;
parameters2.set(index++, "v_quantity", Types.INTEGER, 10);
parameters2.set(index++, "v_id", Types.INTEGER, 4);
parameters2.set(index++, "v_type", Types.SMALLINT, 3);
parameters2.set(index++, "v_address", Types.VARCHAR, "SZ INFO");
try {
client.call(callSql, parameters2, new DalHints());
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("doesn't match with the index"));
}
// set disordered parameter by index
StatementParameters parameters3 = new StatementParameters();
index = 1;
parameters3.set(index++, Types.VARCHAR, "SZ INFO");
parameters3.set(index++, Types.INTEGER, 10);
parameters3.set(index++, Types.INTEGER, 4);
parameters3.set(index++, Types.SMALLINT, 3);
try {
client.call(callSql, parameters3, new DalHints());
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Error converting data type varchar to int"));
}
// set ordered parameter by index
StatementParameters parameters4 = new StatementParameters();
index = 1;
parameters4.set(index++, Types.INTEGER, 5);
parameters4.set(index++, Types.INTEGER, 10);
parameters4.set(index++, Types.SMALLINT, 3);
parameters4.set(index++, Types.VARCHAR, "SZ INFO");
try {
client.call(callSql, parameters4, new DalHints());
} catch (Exception e) {
Assert.fail();
}
Assert.assertTrue(null != res);
Assert.assertEquals(0, res.size());
models = this.queryModelsByIds();
Assert.assertEquals(5, models.size());
// set ordered parameter by index and name
StatementParameters parameters5 = new StatementParameters();
index = 1;
parameters5.set(index++, "v_id", Types.INTEGER, 6);
parameters5.set(index++, "v_quantity", Types.INTEGER, 10);
parameters5.set(index++, "v_type", Types.SMALLINT, 3);
parameters5.set(index++, "v_address", Types.VARCHAR, "SZ INFO");
try {
client.call(callSql, parameters5, new DalHints());
} catch (Exception e) {
Assert.fail();
}
Assert.assertTrue(null != res);
Assert.assertEquals(0, res.size());
models = this.queryModelsByIds();
Assert.assertEquals(6, models.size());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientSqlServerTest method execTestWithoutParametersForSpWithoutOutParameter.
@Test
public void execTestWithoutParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "exec " + SP_WITHOUT_OUT_PARAM + " @v_id=4, @v_quantity=12, @v_type=1, @v_address='SZ INFO'";
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
Map<String, ?> res = client.call(callSql, parameters, hints);
Assert.assertTrue(null != res);
Assert.assertEquals(0, res.size());
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(4, models.size());
}
Aggregations