dan*_*dan 6 ruby postgresql pg
我正在使用pggem与Ruby中的PostgreSQL交谈.有没有更好的方法来检查是否没有结果而不是使用res.ntuples == 0?
conn = PGconn.connect config
cmd = "select * from labels inner join labels_mail using(label_id) " +
"where labels_mail.mail_id = $1 and labels.name = $2"
res = conn.exec(cmd, [mail_id, mailbox])
if res.ntuples == 0 # <=== is there a better way to check this?
cmd = "insert into labels_mail (mail_id, label_id) values ($1, $2)"
conn.exec(cmd, [mail_id, label_id(mailbox)])
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2862 次 |
| 最近记录: |