sqlite3-ruby icon indicating copy to clipboard operation
sqlite3-ruby copied to clipboard

Provide the erroneous query in the SQLException class

Open penguinpowernz opened this issue 10 years ago • 0 comments

Would be good to be able to pull the specific query that caused the error from the SQLException class. For example:

begin
  ids = ids.join(",")
  db.execute("SELECT * FROM table WHERE id IN(#{ids});")
rescue SQLite3::SQLException => e
  log.error e.message # near ",": syntax error
                      # (WTF?)
  log.debug e.query   # SELECT * FROM table WHERE id IN(,1,2,3,4);
                      # (oh, right there's a nil entry in the array)
end

Gives some context to the particular SQL error that happened, assisting in troubleshooting code. I would submit a pull request, but I can't see in the code where I could set a attribute on the exception class (looks like it's done from C?).

Cheers

penguinpowernz avatar Oct 07 '15 20:10 penguinpowernz