Page 1 of 1

Records with ,s and returns

Posted: Fri Apr 03, 2020 1:37 pm
by egolombek
I am very new to SQL and databases, so I apologize for what is probably an obvious question.

I am using data that includes commas and returns. This seems to be a problem when building SQL Queries. I discovered that I could solve this problem when I insert a record by using :s as follows:

put "INSERT INTO students (name,class,group1,group2) VALUES (:1,:2,:3,:4)" into scrpt
revExecuteSQL connectID, scrpt,"stName","stClass","stGroup1","stGroup2"

But, I cannot figure out how to do the equivalent with updating. The following does not work:

put "UPDATE students SET (name,class,group1,group2) VALUES (:1,:2,:3,:4) WHERE id="&stID into scrpt
revExecuteSQL connectID, scrpt,"stName","stClass","stGroup1","stGroup2"


Any help would be most appreciated!!! (And if there is a better reference than the LiveCode lessons which are so basic, I'd really appreciate a link)

Thanks! Eric

Re: Records with ,s and returns

Posted: Fri Apr 03, 2020 5:58 pm
by cpuandnet
Change your update SQL statement to

Code: Select all

put "UPDATE students SET name = :1, class = :2, group1 = :3, group2 = :4 WHERE id="&stID into scrpt
I would also go a step further and also put the stID into the placeholders for clarity and consistency

Code: Select all

put "UPDATE students SET name = :1, class = :2, group1 = :3, group2 = :4 WHERE id = :5" into scrpt
revExecuteSQL connectID, scrpt,"stName","stClass","stGroup1","stGroup2", "stID"

Re: Records with ,s and returns

Posted: Fri Apr 03, 2020 6:46 pm
by Klaus

Re: Records with ,s and returns

Posted: Sat Apr 04, 2020 8:09 pm
by egolombek
That works! Thank you!!! Eric