Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为自定义SQL的参数占位符设值,不支持列表、数组等类型 #121

Closed
conanca opened this issue Nov 28, 2011 · 2 comments
Closed

Comments

@conanca
Copy link

conanca commented Nov 28, 2011

上代码:

long[] idArr = { 1, 2, 3 };
// 以下这句是OK的
query(Cnd.where("ID", "IN", idArr), null);
// 以下的代码报错
Sql sql = Sqls.create("SELECT * FROM PETS WHERE ID IN @idarr");
sql.params().set("idArr", idArr);
dao().execute(sql);

下面是报错信息
DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM PETS WHERE ID IN '[J@a0560e'
Syntax error in SQL statement "SELECT * FROM PETS WHERE ID IN ?"; expected "("; SQL statement:

Cnd的where()方法实现的很好啊,为什么自定义SQL的参数占位符设值不支持呢?

@zozoh
Copy link
Member

zozoh commented Nov 30, 2011

参数

xxx  @idArr  xxxx

最终要变成 PreparedStatement 的参数的,但是处理参数的时候,我们没有对数组或者集合进行处理

@zozoh
Copy link
Member

zozoh commented Nov 30, 2011

对于 PreparedStatement ,如果想要实现 setArray ,需要将值变成 Array 接口
不同的数据库,对这个接口有不同的封装,所以做起来很麻烦

如果没有特别的需要,建议用

xxxx $idArr xxx 

的固定形式占位符来替代

@zozoh zozoh closed this as completed Nov 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants