我正在尝试检查我的 sqlite 数据库中名为“Products”的表中是否存在特定 ID。
def existsCheck( db, id )
temp = db.execute( "select exists(
select 1
from Products
where promoID = ?
) ", [id] )
end
这是我当前的代码,但它返回一个数组,这意味着我必须先处理转换,然后才能将其用作布尔值。有什么想法可以改变它,以便它返回一个值为 1 的 int 吗?
不需要使用子查询:
def existsCheck( db, id )
db.execute( "select 1
from Products
where promoID = ?",
[id] ).length > 0
end
这将返回一个布尔结果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)