Something amiss with my use of INSERT INTO??

Creating desktop or client-server database solutions?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Something amiss with my use of INSERT INTO??

Post by marksmithhfx » Fri May 25, 2018 3:00 am

The following example works...

Code: Select all

      put "INSERT INTO Baby (EventID) values(:1)" into tCmd
      revExecuteSQL gconnectID, tCmd, "tEventID" -- creates a new empty record with mothers EventID
So far so good. But, the next example does not...

Code: Select all

      put "INSERT INTO Baby (EventID, Baby) values(:1,:2)" into tCmd
      revExecuteSQL gconnectID, tCmd, "tEventID, tBaby" -- creates a new empty record with mothers EventID and Baby-A,B,C,etc
Should it?

PS I am aware that placeholders (:1, :2) cannot refer to column names, and in this case they don't. These are just variables with single values assigned to them.

Thanks!!
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

Klaus
Posts: 10381
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Something amiss with my use of INSERT INTO??

Post by Klaus » Fri May 25, 2018 9:56 am

Hi Mark,

I think you need to put all values into quotes separately. Try this:

Code: Select all

...
put "INSERT INTO Baby (EventID, Baby) values(:1,:2)" into tCmd
## revExecuteSQL gconnectID, tCmd, "tEventID, tBaby" 
revExecuteSQL gconnectID, tCmd, "tEventID", "tBaby" 
...
Otherwise LC will treat this as ONE value, as you have experienced.


Best

Klaus

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Re: Something amiss with my use of INSERT INTO??

Post by marksmithhfx » Sat May 26, 2018 3:47 am

Klaus, thanks so much. As the following demonstrates, we have success :)
Screen Shot 2018-05-25 at 9.09.44 PM.png
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

SparkOut
Posts: 1802
Joined: Sun Sep 23, 2007 4:58 pm

Re: Something amiss with my use of INSERT INTO??

Post by SparkOut » Sat May 26, 2018 7:18 am

Or use an array where key 1 has the value for :1 and key 2 has the value for :2 etc

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 483
Joined: Thu Nov 13, 2008 6:48 am
Location: Winnipeg, Manitoba

Re: Something amiss with my use of INSERT INTO??

Post by marksmithhfx » Sat May 26, 2018 7:57 pm

Thanks Sparkout. Was aware of that option, and I use it a lot, but was puzzled over my two variable solution not working. Wasn't sure if that was a bug or... ?? It turned out to be my #1 bugaboo: SYNTAX. Anyone else hate syntax as much as I do :)

You would think by now computers were smart enough to figure out what you wanted... or you could just have a chat with them. Hey Mark?? LC 12.0 perchance :)
macOS 10.13.6 High Sierra, Xcode 9.4, LC 9.0.1, iOS 11.4.1
Targets: Mac, iOS

Post Reply

Return to “Databases”