Swift-Kuery icon indicating copy to clipboard operation
Swift-Kuery copied to clipboard

Kuery not escaping apostrophe characters in Insert queries

Open NocturnalSolutions opened this issue 7 years ago • 1 comments

This seems like a big one; surely I'm not the first to notice this…? But I don't see any mention of it elsewhere in this issue queue… Is it expected that we need to escape apostrophes ourselves?

I was seeing insert queries fail, and I narrowed it down to the failure happening when one of the fields I was trying to insert to contained an apostrophe. By examining the compiled queries, I confirmed that Kuery is not escaping the apostrophe in its compiled insert queries. Here's a sample insert query that caused a failure when I had just a single apostrophe character in the relevant field ("raw") when using SQLite:

INSERT INTO "pastes" ("uuid", "date", "raw", "mode") VALUES ('3229439B-A6BC-4D91-BCF8-955BFA0717EC', '2018-06-09T03:27:12Z', ''', '_plain_')

I thought it might be just an SQLite thing so I rejiggered my app to work with MySQL. The resulting query is slightly different, but the failure is still there:

INSERT INTO `pastes` (`uuid`, `date`, `raw`, `mode`) VALUES ('7A90E481-F3BD-4708-B1F5-77B41ECFC767', '2018-06-09T03:44:04Z', ''', 'objectivec')

Here's the code constructing the Insert object:

        let i = Insert(into: pasteTable, valueTuples: [
            (pasteTable.uuid, uuid.uuidString),
            (pasteTable.date, ISO8601DateFormatter().string(from: Date())),
            (pasteTable.raw, raw),
            (pasteTable.mode, mode)
        ])

Not patching this myself because, one, it's late here and I'm not actually living up to my username very well recently, and two, again, this seems like such an obvious bug that I'm not sure it wasn't intentional…? But if the latter isn't the case, I'll throw something together and make a PR.

NocturnalSolutions avatar Jun 09 '18 03:06 NocturnalSolutions

I am in agreement that this is a bug.

If you are happy to put together a PR with a fix then it would be great.

kilnerm avatar Jun 11 '18 10:06 kilnerm