当 Option[String] 为 None 时插入它的正确方法是什么?下面的代码插入一个空字符串,这与mysql中的NULL不同。
是根据partnerCode的内容预先构建SQL字符串的唯一方法吗?叹息……异常……
DB.withConnection { implicit connection =>
val id: Option[Long] = SQL(
"""
INSERT INTO users (email, partner_code, is_active, created, pass) VALUES ({email}, {partnerCode}, 0, NOW(), {pass})
"""
).on(
'email -> user.email,
'partnerCode -> user.partnerCode.getOrElse(""), // FIXME: how to use NULL keyword instead of empty string? Is Anorm just this dumb?
'pass -> hashPassword(user.password.get)
).executeInsert()
id.get
}
None
如果你导入的话实际上应该可以正常工作anorm._
or anorm.toParameterValue
:
'partnerCode -> user.partnerCode
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)