Multiple Database Tables into single DataGrid

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Multiple Database Tables into single DataGrid

Post by dcpbarrington » Fri Mar 08, 2013 9:03 pm

I have a database with multiple tables that are very similar that I would like to display into a single DataGrid Table.

I SELECT the values from the database and create a multi-dimensional array that easily goes into the DataGrid.
I've been looking for a way to define a column in the DataGrid and had multiple DB columns in the same column.

Data Example

Table ABC
Date
Time
ValueABC
UnitsABC

Table XYZ
Date
Time
ValueXYZ
UnitsXYZ

Can I create a DataGrid with Columns = Date, Time, Value and Units and then configure a way to display ValueABC in the Value column when TableABC is selected and ValueXYZ in the Value Column when the TableXYZ is selected.

The only way I found was to create a column for both ValueABC and ValueXYZ and then to change the visibility based on what Table is selected.

Anyone have a better option. Thanks in advance for the help.

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

Re: Multiple Database Tables into single DataGrid

Post by Klaus » Sat Mar 09, 2013 12:04 pm

Hi dcpbarrington,

I am not sure I understand, but can't you somehow combine (not the Liveocde term! ;-) )
the two arrays with the data of each database call and THEN oput them into a datagrid?


Best

Klaus

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Multiple Database Tables into single DataGrid

Post by dcpbarrington » Tue Mar 19, 2013 5:42 pm

Klaus,

Thanks you for your response.
Wow. I think I was over complicating the situation, but thinking that I could do it as part of a column group function. Some times you just need someone else to look at the problem.

Convert the Array tags before sending them to the DataGrid so the Array Tags would match the column tags of the DataGrid.
Basically I would need to go through each element of the Array in a REPEAT loop and change the tag names of the array values.

Thank
dcpbarrington

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

Re: Multiple Database Tables into single DataGrid

Post by Klaus » Tue Mar 19, 2013 7:34 pm

Okie Dokie :D

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Multiple Database Tables into single DataGrid

Post by mwieder » Tue Mar 19, 2013 9:17 pm

If the two tables have the same format, a simpler thing might be to use a SQL union command. Then just throw the result into the datagrid.

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: Multiple Database Tables into single DataGrid

Post by NigelS » Wed Apr 10, 2013 9:08 pm

I'm making a deduction from your question that you are referring to is doing a sql "SELECT" to get data? If this is so you can do calls within the "SELECT" command that bring the record set from all the tables into a list.

if you pop across to this link http://forums.runrev.com/viewtopic.php?f=8&t=14672 ,look at the code snippet for this is what I actually do when I need data from more than one table

Regards
Nigel

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Multiple Database Tables into single DataGrid

Post by sturgis » Thu Apr 11, 2013 4:17 pm

Don't have time to look at it right this sec but.. first you might see if dot notation will work for you during your select.

Something like select tablename1.column,tablename2.column from tablename1,tablename2...

And also look at the "AS" option. select tablename1.date as date1,tablename2.date as date2 from tablename1,tablename2

I haven't tested, and don't know what differences there are between sqlite, mysql, postgresql etc but it might simplify things. Do a single select, teh data comes in as normal, but with headers matching the "as..." names you gave them. So the date from table 1 would have the header date1 and date2 for the date field from table 2.

As I said, haven't tested, and it is untweaked, but seems like it might be a good avenue to look at.

EDIT: Nvm the dot notation, found your other post and you're already doing that. But the select AS still might apply, and you should still be able to use your current join.

Post Reply