如何为 ColdFusion 中的查询参数分配空值?
我有一个数据库表,其中的 int 列也可以为空。向列添加 int 没问题,但将其设置回 null 会导致错误。由于 ColdFusion 不支持 null 值,因此我通常将该值作为空字符串传递:
local.myParam = "";
但这会导致错误,因为 ""
不是数字类型。
post.addParam(name="parentId", cfsqltype="CF_SQL_INTEGER", value=arguments.parentId);
我有什么想法可以解决这个限制吗?
I have a database table with an int column that can also be null. Adding an int to the column is fine, but setting it back to null causes an error. Since ColdFusion does not support null values, I usually pass the value as an empty string:
local.myParam = "";
This causes an error however, that ""
is not of type numeric.
post.addParam(name="parentId", cfsqltype="CF_SQL_INTEGER", value=arguments.parentId);
Any ideas how I can work around this limitation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望将空字符串作为
null
发送,您可以执行以下操作:即
和addparam
> 除了name
或cfsqltype
等其他参数之外,还支持null
参数。将null
设置为true
会将给定值作为正确的 null 提供给数据库。为了方便起见,我使用三元条件运算符来内联 true 或 false 值。您可以使用iif()
实现同样的事情,老派。If you want the empty string to be sent as
null
, you can do something like this:Which is to say,
<cfqueryparam>
andaddparam
support anull
argument in addition to the others likename
orcfsqltype
. Settingnull
astrue
will provide the given value to the database as a proper null. For convenience, I'm using the ternary conditional operator to inline a true or false value. You could achieve the same thing, old-school, by usingiif()
.我想你想要这个...
I think you want this...