此代码不会更改fullname
表中person
列中的数据,也不会产生任何错误。
我使用变量$editKey
来获取要编辑的记录,因此它按计划运行:
def upDateRecord
getInputs
puts $editKey
puts $fullname
db = SQLite3::Database.open "ruby-test-02.db"
db.execute "UPDATE person SET fullname = $fullname WHERE ID = $editKey"
rescue SQLite3::Exception => e
puts "Exception occured"
puts e
ensure
db.close
puts $editKey
puts $fullname
end
答案 0 :(得分:0)
Sloved ..
def upDateRecord 把“放在upDateRecord” getInputs
db = SQLite3::Database.new "ruby-test-02.db"
stm = db.prepare "UPDATE person Set fullname=? WHERE ID=?"; stm.bind_param 1, $fullname; stm.bind_param 2, $editKey;stm.execute;stm.close
stm = db.prepare "UPDATE person Set sex=? WHERE ID=?"; stm.bind_param 1, $sex; stm.bind_param 2, $editKey;stm.execute;stm.close
stm = db.prepare "UPDATE person Set birth=? WHERE ID=?"; stm.bind_param 1, $birth; stm.bind_param 2, $editKey;stm.execute;stm.close
stm = db.prepare "UPDATE person Set death=? WHERE ID=?"; stm.bind_param 1, $death; stm.bind_param 2, $editKey;stm.execute;stm.close
救援SQLite3 :: Exception => Ë 把“例外发生” 把e 确保 db.close 端