stuck again why isnt this update working

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kcwvc52
Posts: 49
Joined: Sun Jun 12, 2011 9:55 pm

stuck again why isnt this update working

Post by kcwvc52 » Tue Jun 14, 2011 10:11 pm

i took this code from a working example. i do not understand why it works one place but doesn't work in another any suggestion on how to make this work would be much appreciated.

Code: Select all

 
global dataid
on mouseUp
   put card field "name" into updatename
    put card field "blah" into updateblah
    put "UPDATE user SET blah="& updateblah &    "WHERE name=" & updatename   into tSQL
 revExecuteSQL dataid, tSQL
   
   
end mouseUp


dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: stuck again why isnt this update working

Post by dglass » Tue Jun 14, 2011 10:51 pm

First guess is that the strings aren't escaped, and are being considered column names by the DB engine.

You should put a breakpoint in there and check both tSQL before the DB call, and the result after the DB call to see what the error is.

EDIT: and there aren't enough spaces in your SQL. Given your variable values and SQL statement, what you are sending to the DB is this:

UPDATE user SET blah=blahWHERE name=name

What you want is probably something like:

UPDATE user SET blah = 'blah' WHERE name = 'name'

kcwvc52
Posts: 49
Joined: Sun Jun 12, 2011 9:55 pm

Re: stuck again why isnt this update working

Post by kcwvc52 » Tue Jun 14, 2011 11:21 pm

got it thanks the code should have been

Code: Select all

global dataid
on mouseUp
   put card field "name" into updatename
    put card field "blah" into updateblah
    put "UPDATE user SET blah = ' " & updateblah & " '  WHERE name = ' " & updatename &" ' " into tSQL
   
revExecuteSQL dataid, tSQL 
   
   
end mouseUp
this works properly. makes much more sense now

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: stuck again why isnt this update working

Post by dglass » Tue Jun 14, 2011 11:29 pm

kcwvc52 wrote:

Code: Select all

global dataid
    put "UPDATE user SET blah = ' " & updateblah & " '  WHERE name = ' " & updatename &" ' " into tSQL
   
this works properly. makes much more sense now
If it's working now, it's probably coincidental. :)

You are now sending this to the DB engine:

UPDATE user SET blah = ' blah ' WHERE name = ' name '

Note the leading and trailing spaces around your variable values.

So, a) your 'blah' value is going to get inserted with leading and trailing spaces, and your 'name' value is only going to match if it has leading and trailing spaces.

kcwvc52
Posts: 49
Joined: Sun Jun 12, 2011 9:55 pm

Re: stuck again why isnt this update working

Post by kcwvc52 » Tue Jun 14, 2011 11:45 pm

that is interesting because when i told into answer tSQL

UPDATE user SET blah = '3.7' WHERE name = 'george'

but when i told it to go into another field it did this

UPDATE user SET blah = ' 3.7 ' WHERE name = ' george '

you are saying this could cause problems right? this isn't an actual program i am making i am just trying to learn how i can use sqlite with the programs i am making. please explain how this could mess things up. and did livecode just do the fixing for me in that situation?

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: stuck again why isnt this update working

Post by dglass » Tue Jun 14, 2011 11:56 pm

Yes, I believe those extra spaces will cause problems.

I don't know why it would display one way in an answer dialog, and a different way in a field.

kcwvc52
Posts: 49
Joined: Sun Jun 12, 2011 9:55 pm

Re: stuck again why isnt this update working

Post by kcwvc52 » Wed Jun 15, 2011 6:09 am

that is confusing but i got it working thanks to your help and i have now corrected it to make sure it does not cause problems. do you know if livecode is capable of connecting to multiple databases at once as long as they have different connection variables?

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: stuck again why isnt this update working

Post by Klaus » Wed Jun 15, 2011 10:27 am

Hi kcwvc52,
kcwvc52 wrote:do you know if livecode is capable of connecting to multiple databases at once as long as they have different connection variables?
Yes, I know :D








Just kidding, yes, you can connect to multiple database at once. 8)


Best

Klaus

kcwvc52
Posts: 49
Joined: Sun Jun 12, 2011 9:55 pm

Re: stuck again why isnt this update working

Post by kcwvc52 » Wed Jun 15, 2011 10:27 pm

great thanks guys this is tons of help!!!

Post Reply