Queries and Data Grids

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

Queries and Data Grids

Post by smith8867 » Sat Jan 23, 2016 12:55 am

I have been trying to get to grips with the LiveCode and databases and I'm getting there, slowly... I can get connected, add data and select it. However, I am struggling to display the data nicely.

Whilst viewing this: http://lessons.livecode.com/m/4071/l/70 ... l-database
I was under the impression a datagrid is the best way forward, however I cannot seem to be able to get them working. If someone could explain to me how to set up the data grid columns and get the data from the query into the columns, it would be much appreciated.
Thanks guys.

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

Re: Queries and Data Grids

Post by Klaus » Sun Jan 24, 2016 3:26 pm

Hi Mr. Smith,

OK, lets start with an easy example.
You have a database with 3 db fields
1. name
2. address
3. phone

When you execute this in Livecode:
select * from your_table
you get a TAB and CR delimited (text) list like:
name1 TAB address1 TAB phone1name2 TAB address2 TAB phone2
etc...

OK, so far?

Now you need to set up a datagrid of type TABLE*** with 3 columns in the same order as the fields in the database:
1. name
2. address
3. phone

*** This type only supports ONE Line data per column, if you have db fields that contain more than 1 line, the display will get messed up!
However type FORM is a BIT more complicated, see below 8)

Then you can simply put the result of your query into the datagrid like:

Code: Select all

...
put "seelect * from your_table" into tSQL
put revDataFromQuery(tab, return, tConnectionId, tSQL) into tDBResult
## Error checking:
if tDBResult begins with "revdberr" then
  answer "error!"
  exit to top
end if
## Success, now "fill datagrid with data:
set the DGTEXT of grp "your datagrid name here" to tDBResult
...
Et voila, nicely displayed records in a datagrid.
Hope this gets you started!

Load the complete Datagrid docs in PDF here: http://lessons.livecode.com/m/datagrid
and work through it a couple of times, Datagrid are higly complex beasts, to say the least.

Best

Klaus

smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

Re: Queries and Data Grids

Post by smith8867 » Sun Jan 24, 2016 10:19 pm

Hi Klaus,
Thanks for replying. Do I have to set the different columns in the datagrid before hand? I can't seem to find where I can do that.

smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

Re: Queries and Data Grids

Post by smith8867 » Sun Jan 24, 2016 10:28 pm

Okay that worked. Its just that the query data columns in the grid are labelled "Col 1" "Col 2" etc, is there a way to change that to the field names ?

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Queries and Data Grids

Post by quailcreek » Mon Jan 25, 2016 12:58 am

smith8867,
If you're running LC 6 or 7 the columns are managed in the DG property inspector. LC 8 doesn't have this yet.
Tom
MacBook Pro OS Mojave 10.14

smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

Re: Queries and Data Grids

Post by smith8867 » Mon Jan 25, 2016 8:57 am

quailcreek wrote:smith8867,
If you're running LC 6 or 7 the columns are managed in the DG property inspector. LC 8 doesn't have this yet.
Yea I have LiveCode 8, that'll be why then. Thanks.

Post Reply

Return to “Databases”