Page 1 of 1

Read a result of database query

Posted: Thu Oct 06, 2016 5:27 pm
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?

Re: Read a result of database query

Posted: Thu Oct 06, 2016 6:00 pm
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

Re: Read a result of database query

Posted: Fri Oct 07, 2016 2:47 pm
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.

Re: Read a result of database query

Posted: Fri Oct 07, 2016 2:58 pm
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

Re: Read a result of database query

Posted: Fri Oct 07, 2016 3:34 pm
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

Re: Read a result of database query

Posted: Fri Oct 07, 2016 3:43 pm
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...
...

Re: Read a result of database query

Posted: Fri Oct 07, 2016 3:46 pm
by polecat
Great!!!
I'll try soon. :-D
LiveCode is strange for me :-P

Re: Read a result of database query

Posted: Fri Oct 07, 2016 3:53 pm
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

Re: Read a result of database query

Posted: Fri Oct 14, 2016 9:45 am
by MaxV