SQL does not evaluate variables

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ptatray
Posts: 1
Joined: Thu Oct 02, 2014 11:37 am
Location: Stockholm

SQL does not evaluate variables

Post by ptatray » Tue Feb 24, 2015 8:20 pm

I have the following problem. Can anybody advice me?

I need to create and maintain sqlite databases for my applications. Creating the DB and the tables goes just fine.

The following line of code does what it should:
put "INSERT into sticky_table VALUES (1235,1235,'200,456',90,70,'120,90,30','green','this is a message');" after tSQL

but the one below does nothing:
put "INSERT into sticky_table VALUES (1234,gShortID,'123,456',90,70,'yellow','black','this is a message');" into tSQL

that is, if I have variable names in the insert statement, they don't get evaluated, even though the variables have
values; that I have verified with the message box.

What am I missing?

The total environment for the insert looks like this:
on databaseInsertSticky
## Insert names and email addresses into the database
local tDatabaseID,tSQL
put getDatabaseID() into tDatabaseID
show message box
put gShortID into message
put "INSERT into sticky_table VALUES (1234,gShortID,'123,456',90,70,'yellow','black','Lorem ipsum');" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseInsertSticky

which, as I indicated, works fine for specific constant values, but not for variables.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: SQL does not evaluate variables

Post by Simon » Tue Feb 24, 2015 8:42 pm

Hi ptatray,
Do you see that you have your variable gShortID inside quotation marks, makes it a string.
Try this

Code: Select all

put "INSERT into sticky_table VALUES (1234," & gShortID & ",'123,456',90,70,'yellow','black','this is a message');" into tSQL
Simon
Edit; Oh and Welcome to the forum.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: SQL does not evaluate variables

Post by Klaus » Tue Feb 24, 2015 8:45 pm

Hi ptatray,

1. welcome to the forum! :D

2. You are passing the STRING "gShortID" and not its content!
Do as Simon, who beats me by a minute or two, says! :D


Best

Klaus

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: SQL does not evaluate variables

Post by Simon » Tue Feb 24, 2015 8:46 pm

That is a first! :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply

Return to “Databases”