Page 1 of 1
Storing Data (to/from Data Grids) in Standalone Application
Posted: Fri Sep 13, 2013 10:02 pm
by buchacho
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?
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Sat Sep 14, 2013 2:24 am
by dunbarx
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
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 11:10 am
by MaxV
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.
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 3:53 pm
by Simon
ooops MaxV,
You
can store data in a datagrid
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
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 6:22 pm
by buchacho
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.
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 8:23 pm
by Simon
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
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 8:41 pm
by buchacho
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?
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Mon Sep 16, 2013 8:43 pm
by Simon
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Thu Sep 26, 2013 1:18 am
by buchacho
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
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Thu Sep 26, 2013 4:25 am
by Simon
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
Re: Storing Data (to/from Data Grids) in Standalone Applicat
Posted: Thu Oct 03, 2013 7:31 pm
by buchacho
This example is helpful, thanks Simon!