1. normal Custom SQL statements
Create a custom SQL statement in Nutz with the implementation class ORG.NUTZ.DAO.SQLS of the Org.nutz.dao.sql.Sql interface . The code is as follows:
SQL SQL =sqls.create ("DELETE from t_abc WHERE name= ' Peter '");
2. Custom SQL statements that support placeholders
In Nutz, you can also build dynamic SQL statements in a placeholder way . The code is as follows:
SQL SQL =sqls.create ("DELETE from $table WHERE [email protected]");
Sql.vars (). Set ("Table", "T_ABC");
Sql.params (). Set ("Name", "Peter");
· Use $table to represent table names, replace them with T_ABC tables, and $ to represent variable placeholders
· Use @name to represent field names, replace with Peter, @ to represent parameter placeholders
· There is also a special placeholder, $condition,
Its usage is as follows:
SQL sql= sqls.create ("Select name from T_pet $condition");
Sql.setcondition (Cnd.where ("id", ">", 35));
as follows :
VoiddemoCondition2 (dao dao) {
SQL sql = sqls.create ("UPDATE t_pet [email protected] $condition");
Sql.params (). Set ("MasterID", 45);
Sql.setcondition (Cnd.wrap ("id>35"));
Dao.execute (SQL);
}