PDA

View Full Version : SQLite.Query action



pjborg
10-10-2005, 01:54 AM
Does the SQLite.Query action accept variables as input?

I am trying to put the action in a "for" loop, where several variables change each time through.

Using the Online Help as a guide, I inserted these lines:

(before the "for" loop)

db = SQLite.Open(dbname);

SQLite.Query(db,"create table Users(userid integer primary key, LastName text, FirstName text, Age integer)");

(inside the "for" loop )

SQLite.Query(db,"insert into Users values(1,'Sellers','Ted',48)");

and tried using variables in place of the "1" "'Sellers'" etc. I tried various ways of doing it, but so far no luck. I know the variables are valid, for example using "count" for the number, and my_table.value as a string variable. And it works fine using regular numbers and text. Maybe I don't have the syntax down pat yet? I thank you in advance for any help you can offer.

Worm
10-10-2005, 04:39 AM
for n=1, 10 do
x = n + 100;
SQLite.Query(db,"insert into Users values("..n..",'Sellers','Ted',"..x..);
end

TJ_Tigger
10-10-2005, 08:42 AM
As Worm pointed out, the actual query send to the DB is a string and as with any string within AMS you need to concatenate the variable into the string to have it function correctly. Just remember to properly quote text components within your query.



for n=1, 10 do
x = n + 100;
strlastname = "Sellers"..x
strfirstname = "Ted"..x --added the X for uniqueness :D
SQLite.Query(db,"insert into Users values("..n..",\""..strlastname.."\",\""..strfirstname.."\","..x..);
end



Tigg

Worm
10-10-2005, 08:45 AM
Kinda wordy aren't ya Tig?

Didn't even realize that I didn't explain why. Thanks for having my back :yes

TJ_Tigger
10-10-2005, 09:36 AM
Kinda wordy aren't ya Tig?

Didn't even realize that I didn't explain why. Thanks for having my back :yes

yeah I can get that way some times. Just depends on the day of the week and the time of the day and if I have had too much caffeine in the morning. Yeah if I have had too much of that caffeine then I tend to ramble on and on and on and on until the caffeine wears out and . . . oh I did it again.

:D

Worm
10-10-2005, 09:38 AM
:yes :D :yes

pjborg
10-10-2005, 10:25 AM
Thanks, I figured maybe it was me concatenating incorrectly... I've done it before.
I guess I'm still discovering the many joys of concatenation. pj