n00b Data Grid <-> MySQL Display Issue

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
afrizen
Posts: 5
Joined: Sat Mar 16, 2013 1:08 am

n00b Data Grid <-> MySQL Display Issue

Post by afrizen » Tue Mar 19, 2013 2:53 pm

Brand new to LC and helped kickstart. My first post and question:

Dropped a datagrid (called dg1) on a new stack and card with the basic DB connection code working nicely.
Although the debugger shows the dbCursor and dbDgArray to both be fully populated with the table's contents after the following code is run, the dg1 data grid just sits on the card unmodified, laughing at me! :)
There are four rows of data in the DB table, and there are four "editable" rows in the data grid, but no data is displayed.
Obviously there is some display mechanism I'm missing, but my reviews of the doc and forum have led me here. Clues anyone?
adTHANKSvance!

Code: Select all

  ## Query the database for data
   put "my_table" into tDbTableName
   put revQueryDatabase( gConID, "SELECT * FROM " & tDbTableName & ";") into dbCursor
   
   if dbCursor is an integer then
      #DEBUG answer info "Cursor is integer " & dbCursor
      ConvertSQLCursorToArray dbCursor, dbDgArray
      put the result into dbError
      
      if dbError is empty then
         ## The cursor was successfully converted to an array.
         ## Assign it to the data grid. 
          lock screen
          set the dgData of group "dg1" to dbDgArray
          unlock screen
      end if
      
      ## Close the database cursor 
      revCloseCursor dbCursor
   end if
~mark->

If you build it, we will break it. QA rules!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: n00b Data Grid <-> MySQL Display Issue

Post by dunbarx » Tue Mar 19, 2013 3:01 pm

Hi.

Welcome.

I use dataGrids, but am no expert. I am not alone.

But once you think you have reloaded data into such a beast, have you tried:

dispatch "resetList" to group "yourDataGrid"? Let me know how this comes out.

Craig Newman

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: n00b Data Grid <-> MySQL Display Issue

Post by bangkok » Tue Mar 19, 2013 5:13 pm

One advice, if you start with MySQL and LiveCode, and especially Datagrid : keep it simple. :D

-for instance, why using "cursors" ? Cursors are very specific.
-instead use revDataFromQuery, that will retrieve a nice chunck of text (by default, columns separated by TAB, and rows by CR), this text will be injected directly into the datagrid. No hassle

Code: Select all

put "SELECT * from my table" into dbSQL
put revDataFromQuery(,,gConID,dbSQL) into tData
set the dgText of group "dg1" to tData
By keeping it simple at this stage, you'll save brain power... for datagrids (very powerfull beast, but can be tricky sometimes when you want to add behavior, objects etc.).

afrizen
Posts: 5
Joined: Sat Mar 16, 2013 1:08 am

Re: n00b Data Grid <-> MySQL Display Issue

Post by afrizen » Wed Mar 20, 2013 6:05 pm

Haha. Thank you both. Solved the problem myself while trapped on an airplane. I was missing the column names in the DG table! Doh!

Especially appreciate the alternative approach other than cursors. It was the first example of data grids and DB that I encountered. I agree with the KISS principle, but have to know what simple even *is* for LiveCode. I will research this a bit more.
~mark->

If you build it, we will break it. QA rules!

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

Re: n00b Data Grid <-> MySQL Display Issue

Post by Klaus » Wed Mar 20, 2013 6:41 pm

Well, that was exactly my first thought, but then you "spoiled" it with:
###... and there are four "editable" rows in the data grid, ...
8)

Anyway, welcome to the forum! :D


Best

Klaus

afrizen
Posts: 5
Joined: Sat Mar 16, 2013 1:08 am

Re: n00b Data Grid <-> MySQL Display Issue

Post by afrizen » Thu Mar 21, 2013 3:46 am

It's QA's job to "spoil" good development. :twisted:

Really appreciating the community here.

BTW, Klaus et al, looking forward to your perspectives on this question: http://forums.runrev.com/viewtopic.php?f=12&t=14484
~mark->

If you build it, we will break it. QA rules!

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

Re: n00b Data Grid <-> MySQL Display Issue

Post by Klaus » Thu Mar 21, 2013 10:57 am

Hi Mark,

sorry, never heard of "Table status" nor am I an SQL expert, so sorry, no idea...


Best

Klaus

Post Reply