Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to pcall an sqlite prepared statement? — Gideros Forum

How to pcall an sqlite prepared statement?

piepie Member
edited February 1 in Code snippets
Hi, I have a random crash which might come from a corrupted db file and I wanted to pcall the query, but I am unable to get it working:
this is the statement:
 stmt = db:prepare("SELECT * FROM items WHERE category = \'wearable\' ")
I thought it should be:
r, stmt = pcall(db.prepare, "SELECT * FROM items WHERE category = \'wearable\' ")
print(r, stmt)
but this is my output
false invalid argument #1 to 'prepare' (:sqlite3 expected, got string)

thank you :)
Tagged:

Comments

  • keszeghkeszegh Member
    Accepted Answer
    maybe
    r, stmt = pcall(db.prepare, db,"SELECT * FROM items WHERE category = \'wearable\' ")
    would work as calling a function with ":" invisibly adds the parent (in this case 'db') as the first argument. so in pcall you need to do this explicitly as there you have db.prepare which does not do this.

    Likes: MoKaLux, pie

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.