Storing Data (to/from Data Grids) in Standalone Application

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
buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Storing Data (to/from Data Grids) in Standalone Application

Post by buchacho » Fri Sep 13, 2013 10:02 pm

I have an app that uses a dozen or so different data grids to present data/information. I just found the persistent aspect of data stored there only applies to the development program. What is an efficient way of storing the data in each data grid in a separate file when the app closes and then loading it upon opening the program? Would there be a way of automating it, like saying store every data grid of certain cards to a file and then retrieving the information from the file without having to specify every grid?

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

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by dunbarx » Sat Sep 14, 2013 2:24 am

Hi.

You can save dataGrid contents in a standalone. There is no reason you can't. You have to make sure that you have indeed updated each DG when its values have changed, but otherwise they act like any other control. What are you seeing?

Craig Newman

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

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by MaxV » Mon Sep 16, 2013 11:10 am

Hi,
fist of all you can't save data inside a Standalone Application, as you know Stand Alone application is like a read only file. So you have to use an external file as resource. Many datagrids mean many files, it's very uncomfortable...
I suggest you to use only one file, a SQLite db (for example: mydata.sqlite). Livecode embeds SQLite and this permits you to store a lot of informations in a single file.
Note: datagrids are array, so you have to arrayDecode and arrayEncode to store them.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by Simon » Mon Sep 16, 2013 3:53 pm

ooops MaxV,
You can store data in a datagrid :D
If the data is static, there is no problem retaining information. Right:)

buchacho,
What is being said here is if your information is not changing then just save your stack with the data in it. Simples.
Now if the end user is adding/deleting/changing data then, yes you store the information in an external file/stack. Here is the Lesson:
http://lessons.runrev.com/s/lessons/m/d ... ata-source
But that one does leave a lot out (odd). Here is the actual save to file:
http://lessons.runrev.com/s/lessons/m/4 ... put-output
Again that one is weird but it does do the saving.

There is much to be gained by saving information in an external stack, like saving binary files, if you need more information on that just ask. :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by buchacho » Mon Sep 16, 2013 6:22 pm

Thanks for the suggestions... I am trying to see if I can store all the data grid arrays into one file. Eventually I want to interface with a mySQL database, but do not have one available yet at this phase of development.

Friday evening I was working on trying to use arrayEncode / arrayDecode to store data. I had played around with it earlier based on the Livecode tutorial, and got it working for storing data for one data grid. I am thinking there is a way to store multiple data grids in a larger multi-dimensional array in just one file, but maybe I am not using them correctly. Here is my test code for multiple data grids:

Code: Select all

   put the dgData of group "CardGrid" into gridArray["CardGrid"]
   put the dgData of group "NameGrid" into gridArray["NameGrid"]
   put the dgData of group "PNGrid" into gridArray["PNGrid"]
   
   ask file "Save grid array data to file:"
   put it into theFile
   
   if theFile is not empty then 
      put arrayEncode(gridArray) into theEncodedArray 
      put theEncodedArray into URL ("file:" & theFile) 
   end if
   
   ## Load master data grid array from file
   answer file "Select file containing data grid data:"
   put it into theFile
   
   if theFile is not empty then
      put URL ("binfile:" & theFile) into theEncodedArray
      put arrayDecode(theEncodedArray) into theDecodedArray
      
      put theDecodedArray["CardGrid"] into theContents
      
      --put the data into a new data grid as a test
      set the dgData of group "DataGrid 5" to theContents
   end if
The code chokes at arrayDecode (arrayDecode: failure), so I am guessing the function is having some issue with the structure of the array, even though arrayEncode can handle it. The code works if I comment out the second and third data grids that are saved into the variable gridArray.
Last edited by buchacho on Mon Sep 16, 2013 8:27 pm, edited 1 time in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by Simon » Mon Sep 16, 2013 8:23 pm

Hi buchacho,
Since you say you will move this to mysql why aren't you using the built in sqlite? It will make transitioning to mysql easy.

Ok onward. You use "file:" when you store the file but "binfile:" when you retrieve it?
Doc's say:
The arrayEncode function returns a string of binary data...
so I'm thinking binfile: should be used for both.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by buchacho » Mon Sep 16, 2013 8:41 pm

Thanks Simon, that did the trick... I think in my play I was changing the type and did not change them for both. It was odd that it would work for one saved sub-array, but not more.

I will look into the sqlite functionality.... does this option save data to a separate file as well?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by Simon » Mon Sep 16, 2013 8:43 pm

I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by buchacho » Thu Sep 26, 2013 1:18 am

I thought I saw an example somewhere, but now I cannot find it... Is there a way to get the results from a SQLite database query in the form of a variable with the colums of the table matching the columns of an array, thereby being able to update records in the data grid using the dgData handler instead of dgText? The reason I ask is if it is done that way, I do not have to worry about the order of the columns in the SQLite database matching the data grid.

This code uses dgText, but I want to use dgData to set the data grid contents.

Code: Select all

....

set the dgText of group "DataGrid8" to databaseGetData("Interface")

.....

function databaseGetData dbTableName
   ## Query the database for contact details to be displayed in the field
   put getDatabaseID() into tDatabaseID
   put "SELECT * from " & dbTableName into tSQL
   put revDataFromQuery(tab,return,tDatabaseID,tSQL) into tRecords

   return tRecords
end databaseGetData

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by Simon » Thu Sep 26, 2013 4:25 am

I think you want this:
http://lessons.runrev.com/s/lessons/m/4 ... grid-array
Watch out when using the given sample it has a mistake:
put "example" into theDBUser
should be:
put "runrev_example" into theDBUser :)

I think I posted the problem to them a couple of weeks ago.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Re: Storing Data (to/from Data Grids) in Standalone Applicat

Post by buchacho » Thu Oct 03, 2013 7:31 pm

This example is helpful, thanks Simon!

Post Reply