Page 1 of 1

SQL does not evaluate variables

Posted: Tue Feb 24, 2015 8:20 pm
by ptatray
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.

Re: SQL does not evaluate variables

Posted: Tue Feb 24, 2015 8:42 pm
by Simon
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.

Re: SQL does not evaluate variables

Posted: Tue Feb 24, 2015 8:45 pm
by Klaus
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

Re: SQL does not evaluate variables

Posted: Tue Feb 24, 2015 8:46 pm
by Simon
That is a first! :)