ID:1508008
 
Resolved
Quoting strings in database queries was incorrect in some cases.
BYOND Version:506
Operating System:Windows 7 Home Premium
Web Browser:Firefox 27.0
Applies to:Dream Maker
Status: Resolved (506.1237)

This issue has been resolved.
Descriptive Problem Summary:
Looks like sqlite is quoting a (') sign twice.


Code Snippet (if applicable) to Reproduce Problem:
var/database/database = new("test.db")

proc/query_db(var/database/query/query,var/database/database)
query.Execute(database)
if(query.Error())
return 0
return query.RowsAffected()>0 ? query.RowsAffected() : 1

mob
verb/test_bad()
var/database/query/query = new()
query.Add("INSERT INTO test (a) VALUES (?);","'")
world << "[query]"
if(!query_db(query,database))
world << "Error #[query.Error()] - [query.ErrorMsg()]"
verb/test_good()
var/database/query/query = new()
query.Add("INSERT INTO test (a) VALUES ('''');")
world << "[query]"
if(!query_db(query,database))
world << "Error #[query.Error()] - [query.ErrorMsg()]"


Expected Results:
No table found (test_good())

INSERT INTO test (a) VALUES ('''');
Error #1 - no such table: test

Actual Results:
Unrecognized token (test_bad())

INSERT INTO test (a) VALUES (''''');
Error #1 - unrecognized token: "''''');"


Didn't Lummox say they're doing their own escaping instead of using the SQLite binding routines? I guess this is why you're not supposed to do that.
He did, but he also said that he doesn't see it being functionally different.

If it is using the built-in binding or not, either it should not handle escaping at all, or it should do it correctly if it tries. Adding two random ' signs doesn't really help anyone here.
Lummox JR resolved issue with message:
Quoting strings in database queries was incorrect in some cases.
In response to Pirion
Pirion wrote:
He did, but he also said that he doesn't see it being functionally different.

Considering this bug, it is functionally different. There's a reason they provide binding functions, and it's pretty similar to the reason I don't write my own AES implementations ;)