我不喜欢依赖位置参数,使用HDBC可以做到吗
我可以看到将[(String, SqlValue)]而不是[SqlValue]作为参数传递给this package的各种执行函数。
简而言之,我宁愿
select
t.f1
, t.f2
, t.f3
from
schema.table t
where
t.f1 > @param1
and t.f2 < @param2比
select
t.f1
, t.f2
, t.f3
from
schema.table t
where
t.f1 > ?
and t.f2 < ?发布于 2013-10-16 03:29:03
不是直接使用hdbc,而是在莎士比亚文本包的帮助下:
quickQuery cn (T.unpack
[st|select bar, baz, foo
from table1 r
inner join location l on r.locat_id = l.location_id
where r.record_id = #{pageIdxId page}
and foo > #{var1 + var2}
order by 1|]) []注意#{}占位符中的haskell变量和表达式。
不过,使用字符串拼接时要小心。
对字符串值使用sql转义函数。
sqlEscape :: Text -> Text
sqlEscape = T.replace "'" "''" 然后
[st|update foo set bar = '#{sqlEscape someString}' where recid = #{myRecId}|]或者,如果您能够胜任这项任务,则可以使用莎士比亚文本库,并对其进行少量更改,以自动转义所有isString类型。
https://stackoverflow.com/questions/19137803
复制相似问题