Read a result of database query

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
polecat
Posts: 8
Joined: Tue Jun 28, 2016 9:52 pm

Read a result of database query

Post by polecat »

I connected on mysql and made a query.
the result is store on tData variable (i don't know if is an array).
How to can i read this variable?
I put data on field but how can i read and use it?
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Read a result of database query

Post by dunbarx »

Hi.

In the handler that makes the query, if you place a breakpoint at an appropriate line of code, you can read tData.

If it is an array, you can expand tData in the debugger as required. Note that an array will not be readable in the clear unless you transform it into an ordinary variable using the "combine" command.

Craig Newman
polecat
Posts: 8
Joined: Tue Jun 28, 2016 9:52 pm

Re: Read a result of database query

Post by polecat »

When i use combine function i don't have any more an array and i can't access to stored data using syntax like array[2]. Your answer give me a fact: i can't access to data stored into array if this array isn't transform with combine function. how can i put some of this result on a variable and use it. The code must use data retrieved from msql query. I think is a simple question and i'm apology for this question but i'm steel disoriented with livecode.
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read a result of database query

Post by Klaus »

Hi polecat,

if you use:
...
put revdatafromquery(......) into tData
...
then tData is NOT an array!

Instead it will be a CR and TAB delimited string in this format:
one rcord per line (CR delimited) and in each line TAB delimited the database fileds that you defined in your SQL query

tData:
field1_of_record1 TAB field2_of_record1 TAB field3...
field1_of_record2 TAB field2_of_record2 TAB field3...
field1_of_record3 TAB field2_of_record3 TAB field3...
...

Example with an simple address database with three fields: name, first name, emailaddress.
Then tData would look like this:
Pitt TAB Brad TAB brad@brangelina.com
Ford TAB Harrison TAB h.ford@indi_jones.com
...
Get the picture?


Best

Klaus
polecat
Posts: 8
Joined: Tue Jun 28, 2016 9:52 pm

Re: Read a result of database query

Post by polecat »

ok tData is not an array.
in your example how can i put one name on a single variable. I need to access data and use it
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read a result of database query

Post by Klaus »

Do something like this:

Code: Select all

...
set itemdel to TAB
put item 1 of line 1 of tData into first_record_name
put item 2 of line 1 of tData into first_record_first_name
put item 3 of line 1 of tData into first_record_mailaddress

put item 1 of line 2 of tData into second_record_name
put item 2 of line 2 of tData into second_record_first_name
put item 3 of line 2 of tData into second_record_mailaddress
## etc...
...
polecat
Posts: 8
Joined: Tue Jun 28, 2016 9:52 pm

Re: Read a result of database query

Post by polecat »

Great!!!
I'll try soon. :-D
LiveCode is strange for me :-P
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read a result of database query

Post by Klaus »

Hi polecat,

did you already check these stacks?
http://www.hyperactivesw.com/revscriptc ... ences.html
They cover the basics of LC to make you more familiar with LC. :D


Best

Klaus
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Read a result of database query

Post by MaxV »

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Post Reply