[bug] failing to quote primary key if not a number

This is the place to post technical queries about SQL Yoga

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

[bug] failing to quote primary key if not a number

Post by trevordevore » Fri Oct 11, 2013 1:41 pm

[This post is an archive from the old SQL Yoga forums]

Can someone confirm that trying to set some condition for a query like:

put ":1 is in" && primaryKeyForTable(pTable) into theFilterA["conditions"]

put sqlyoga_escapeString("sqlite",tKey) into theFilterA["condition bindings"][1]

sqlrecord_find pTable, theFilterA, tLocalRecordA

Where the primary key is a string value. This generates a query like:

sqlyoga_executesql_err,Database Error: SQL error or missing database

Query: SELECT templates.title AS "templates.title", templates.type AS "templates.type", templates.content AS "templates.content", templates.datemodified AS "templates.datemodified" FROM templates WHERE MP4 Video IN (title)

As we can see the value MP4 Video should be quoted, if I manually put quotes around it, then when the query is generated, the value is double quoted?!

I am using SQL Yoga 1.0 build 15
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: [bug] failing to quote primary key if not a number

Post by trevordevore » Fri Oct 11, 2013 1:42 pm

When working with "conditions" (the WHERE clause) and bindings SQL Yoga will escape special characters in the value you insert but will not add the single quotes around it. This is because certain conditions don't work if single quotes are around them (i.e. WHERE ID IN (:1) ).

Code: Select all

put "':1' is in" && primaryKeyForTable(pTable) into theFilterA["conditions"]

put tKey into theFilterA["condition bindings"][1]

sqlrecord_find pTable, theFilterA, tLocalRecordA

You can read more about the "conditions" property on the sqlquery_set page:

http://www.bluemangolearning.com/revolu ... ry_set.htm

By the way, if you define a table object for your table then "primary key" becomes an accessible property.

Code: Select all

put tableobj_get(pTable, "primary key") into thePrimaryKey
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply

Return to “SQL Yoga”