use of org.nutz.dao.sql.Sql in project nutz by nutzam.
the class SimpleDaoExecTest method test_simple_mysql_exec.
// Mysql支持存储过程
@Test
public void test_simple_mysql_exec() {
if (!dao.meta().isMySql())
// Only test for mysql now
return;
dao.create(Pet.class, true);
dao.insert(Pet.create("wendal"));
dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_getCount"));
dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_getCount()\nBEGIN\n\tSELECT name FROM t_pet;\nEND"));
// 单一结果集,且没有输入输出参数
Sql sql = Sqls.fetchString("CALL proc_pet_getCount()");
dao.execute(sql);
assertEquals("wendal", sql.getString());
}
use of org.nutz.dao.sql.Sql in project nutz by nutzam.
the class ExtDaoInvocationHandler method queryCount.
/**
* 查询某sql的结果条数
*/
public static long queryCount(Dao dao, String sql) {
String tmpTable = "as _nutz_tmp";
if (dao.meta().isDB2())
tmpTable = "as nutz_tmp_" + R.UU32();
else if (dao.meta().isOracle())
tmpTable = "";
else
tmpTable += "_" + R.UU32();
Sql sql2 = Sqls.fetchInt("select count(1) from (" + sql + ")" + tmpTable);
dao.execute(sql2);
return sql2.getInt();
}
use of org.nutz.dao.sql.Sql in project nutz by nutzam.
the class SimpleDaoTest method test_xxx.
@Test
public void test_xxx() {
Sql task_sql = Sqls.create("SELECT * FROM act_ru_task WHERE CATEGORY_=@category AND ( ASSIGNEE_=@userId $assignee ) ORDER BY create_time_ desc");
task_sql.params().set("category", 1);
task_sql.params().set("userId", 2);
task_sql.vars().set("assignee", "and name != 'hi'");
System.out.println(task_sql.toPreparedStatement());
System.out.println(task_sql.forPrint());
System.out.println(">>" + task_sql);
}
use of org.nutz.dao.sql.Sql in project nutz by nutzam.
the class SimpleDaoTest method test_bean_uuid.
@Test
public void test_bean_uuid() {
Sql sql = Sqls.queryRecord("select * from t_pet");
sql.setPager(dao.createPager(1, 10));
dao.execute(sql);
}
use of org.nutz.dao.sql.Sql in project nutz by nutzam.
the class SimpleDaoTest method run_2_sqls_with_error.
@Test
public void run_2_sqls_with_error() {
assertEquals(0, dao.count(Pet.class));
Sql sql1 = Sqls.create("INSERT INTO t_pet (name) VALUES ('A')");
Sql sql2 = Sqls.create("INSERT INTO t_pet (nocol) VALUES ('B')");
try {
dao.execute(sql1, sql2);
fail();
} catch (DaoException e) {
}
assertEquals(0, dao.count(Pet.class));
}
Aggregations