Write a chunk of sql into a variable

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Write a chunk of sql into a variable

Post by jalz » Wed Sep 25, 2013 11:53 pm

Hi Guys,

I've got the following sql statement in live code, which I would like to write and execute as elegantly as possible. My connection ID is stored in a field called gConnID. I've got the code below broken down, but its not working, can someone help me to write it broken down.

Code: Select all

put "CREATE TEMPORARY TABLE tmp AS SELECT customerID, title, first_name, last_name, position, telephone, mobile, email FROM customer_contact WHERE customerID=" && var_customerID && ";" into tTheSQLQuery1
   put "UPDATE tmp SET customerID=" && new_customer_id &&";" into tTheSQLQuery1
   put "INSERT INTO customer_contact(customerID, title, first_name, last_name, position, telephone, mobile, email) SELECT * FROM tmp; " into tTheSQLQuery1
   put "DROP TABLE tmp;" into tTheSQLQuery1
   
   revExecuteSQL gConnID, tTheSQLQuery1

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Write a chunk of sql into a variable

Post by bangkok » Thu Sep 26, 2013 5:46 am

You put 4 SQL queries.... into only one var, without executing it ! Use "after"

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

Re: Write a chunk of sql into a variable

Post by Simon » Thu Sep 26, 2013 6:44 am

That's what I saw, just the OP's use of "broken down" had me confused.
I thought it meant "shortened code".

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Write a chunk of sql into a variable

Post by edgore » Fri Oct 11, 2013 5:43 am

One more thing that pops out - you should not be using ; at the end of SQL queries in livecode. Pretty sure you need single quotes around you values too.

Also, is there a reason you have the connection id in a field, rather than using a global variable? Or, even better, closing the connection when it's not needed and reconnecting when you need to in order to reduce overhead on the database?

Lastly, look up the merge function. It will change your life.

Post Reply