Returning a value from an SQL query

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Mikofig
Posts: 5
Joined: Thu Jan 31, 2019 3:00 pm

Returning a value from an SQL query

Post by Mikofig » Thu Jan 31, 2019 3:07 pm

I am using MAMP in order to connect to an SQL database. I can connect just fine but the problem arises when I try to execute my query. I am trying to perform a count(*) query on a table and return the value but every time I run it the result is "OK" which apparently counts as a number because it causes my "if the result is a number" statement to trigger. any ideas as to how I could fix this?

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 312
Joined: Tue Apr 10, 2012 9:18 am

Re: Returning a value from an SQL query

Post by ghettocottage » Thu Jan 31, 2019 3:33 pm

can we see the code you have so far? or the query and return section of it?

Mikofig
Posts: 5
Joined: Thu Jan 31, 2019 3:00 pm

Re: Returning a value from an SQL query

Post by Mikofig » Thu Jan 31, 2019 3:37 pm

put "SELECT COUNT(*) FROM scores" into tSQL
revExecuteSQL gConnectionID, tSQL
if the result is a number then
put it into temp
put "00000" + temp into ScoreID
else
answer"nope"
end if
answer ScoreID

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 83
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: Returning a value from an SQL query

Post by matthiasr » Thu Jan 31, 2019 4:55 pm

You have to use the function revDatafromQuery for this.

revExecuteSQL is used for example for inserting, updating, deleting a record.

Mikofig
Posts: 5
Joined: Thu Jan 31, 2019 3:00 pm

Re: Returning a value from an SQL query

Post by Mikofig » Thu Feb 07, 2019 3:41 pm

Thank you very much, everything works fine now

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

Re: Returning a value from an SQL query

Post by Klaus » Thu Feb 07, 2019 3:50 pm

A look into the Dictionary, which is better than its reputaiton, usually clears these kind of "misunderstandings"! 8)

Post Reply

Return to “Talking LiveCode”