I have a function that finds an oid from a field in a table. According to the docs, the oid field is automatically created and auto incremented. Sounds great.
def teddy_bear_id_by_url(url)
query = "select oid from teddy_bears where url = \"#{url}\""
res = $db.execute(query)
return res
end
Unfortunately this code returns a [] (empty array), when running the query in the sqlite shell gives a 'good' value (e.g. 4).
def teddy_bear_id_by_url(url)
return $db.execute("select oid from teddy_bears where url = '?'", url)
end
The above doesn't work either.
I did indeed check that urlcontains what I think it does.
What might be happening?
urlcontains what you think it does? No leading or trailing whitespace? What happens if you leave thewhereclause out? And as an aside, you really should be using single quotes for string literals in SQL (SQLite allows double quotes but that just leads to bad habits) and you should be using placeholders instead of pretending you're a PHP programmer in 1999.urldoes indeed contain what I think it does. I logged it, and it returns precisely what it should. No leading or trailing whitespace. I replaced it with single quotes and still no dice. Thanks for the placeholders tips, but I did indeed try with placeholders with the same results.$db.execute("select oid from teddy_bears where url = ?", url)(i.e. no quotes around the placeholder).urlhas or could have spaces. The one with which I'm testing has spaces.