Is it me or is it a bug? (Ghost Function...) Part I
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Is it me or is it a bug? (Ghost Function...) Part I
I'm developing an App including:
- Sqlite DB
- DataGrid
- Local Notifications
Several strange things are happening that I can't explain / fix for which I will appreciate your help.
Let start from the beginning...
The very simple attached program:
- has One Sqlite dB with Two Tables, Table 1 & Table 2.
- The Tables are almost equal, they have just one column which is different, DateT1 on Table1 and DateT2 on Table2.
- Button "Insert Records" should add one record to each table
- Button "Table1" should retrieve and show Table 1 contentes on the DataGrid
- Likewise Button "Table2" for Table 2
When running on the desktop (Mac):
- Column DateTX only shows its contents after clicking twice on the corresponding button !!!
When running on the simulator (or the actual device):
- Contents never shows up on the datagrid even though records are added to the DB as can easily been seen looking at the dgText contents...
You can see all this with your own eyes by watching it here https://youtu.be/rZJRBoGWUjo
- Sqlite DB
- DataGrid
- Local Notifications
Several strange things are happening that I can't explain / fix for which I will appreciate your help.
Let start from the beginning...
The very simple attached program:
- has One Sqlite dB with Two Tables, Table 1 & Table 2.
- The Tables are almost equal, they have just one column which is different, DateT1 on Table1 and DateT2 on Table2.
- Button "Insert Records" should add one record to each table
- Button "Table1" should retrieve and show Table 1 contentes on the DataGrid
- Likewise Button "Table2" for Table 2
When running on the desktop (Mac):
- Column DateTX only shows its contents after clicking twice on the corresponding button !!!
When running on the simulator (or the actual device):
- Contents never shows up on the datagrid even though records are added to the DB as can easily been seen looking at the dgText contents...
You can see all this with your own eyes by watching it here https://youtu.be/rZJRBoGWUjo
- Attachments
-
- GhostFunction.zip
- The stack
- (4.96 KiB) Downloaded 282 times
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
you are accessing your db with this command:
But this will ONLY work on your Mac, because specialfolderpath("documents") on a Mac is a completely different folder than on mobile (device or simulator!)!
Despite the fact that the file "ghost.sqlite"" does of course not ecxist in MY documents folder!
So you first need to make sure that you:
1. include your SQLite database file via the "Copy files" tab in the standalone builder settings.
2. Copied that file right after your app starts up to the device/simulator specific specidalfolderpath("documents"), if not yet present!
3. Access the database file from that location.
P.S.
You are opening the database at least two times but never close one of the connections!
That is asking for trouble!
Best
Klaus
you are accessing your db with this command:
Code: Select all
...
put specialFolderPath("documents") & "/ghost.sqlite" into tDatabasePath
...
Despite the fact that the file "ghost.sqlite"" does of course not ecxist in MY documents folder!

So you first need to make sure that you:
1. include your SQLite database file via the "Copy files" tab in the standalone builder settings.
2. Copied that file right after your app starts up to the device/simulator specific specidalfolderpath("documents"), if not yet present!
3. Access the database file from that location.
P.S.
You are opening the database at least two times but never close one of the connections!
That is asking for trouble!

Best
Klaus
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Klaus, many thanks for your answer...see my comments below
you said
you said
you said
not sure why as according to the Dictionary...specialfolderpath("documents") on a Mac is a completely different folder than on mobile (device or simulator!)!
you saidOn iOS systems, only create files in the "documents", "cache" and "temporary" folders
you are right, but it is created when I click on the "Insert Records" button. By the way I can see the records were in fact added by checking the variable "tData" contents on the retrieveData function. The problem is that I can get tData to be displayed on the DataGrid......the file "ghost.sqlite"" does of course not ecxist..
you said
Point taken, beginner fault !!!You are opening the database at least two times
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
This has to do with "Sandboxing" which means that our apps can only live in its own little world, including their own 1"Documents" folderinside of the application package.
if you issue a "revopendatabase..." and you try to access a database file which is NOT present, then a new and EMPTY datagbase file will be created.
This way you will end with a new and empty database file, like here in my Documents folder
, named "ghost.sqlite", which you then fill with the new data in your handler,
which THEN will of course be displayed inside of your datagrid
Best
Klaus
Same applies to the other mobile platform, Android!simon.schvartzman wrote:Hi Klaus, many thanks for your answer...see my comments below
you saidnot sure why as according to the Dictionary...specialfolderpath("documents") on a Mac is a completely different folder than on mobile (device or simulator!)!On iOS systems, only create files in the "documents", "cache" and "temporary" folders
This has to do with "Sandboxing" which means that our apps can only live in its own little world, including their own 1"Documents" folderinside of the application package.
Yes, but that is how LC works!simon.schvartzman wrote:you saidyou are right, but it is created when I click on the "Insert Records" button. By the way I can see the records were in fact added by checking the variable "tData" contents on the retrieveData function. The problem is that I can get tData to be displayed on the DataGrid.....the file "ghost.sqlite"" does of course not ecxist..
if you issue a "revopendatabase..." and you try to access a database file which is NOT present, then a new and EMPTY datagbase file will be created.
This way you will end with a new and empty database file, like here in my Documents folder

which THEN will of course be displayed inside of your datagrid
Best
Klaus
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Sorry for bother you Klaus but I'm having difficulties to follow your answers.
Can you please give me an example as how should I open/create the file on the iPhone instead of using ...specialfolderpath("documents")...
Many thanks in advance
Can you please give me an example as how should I open/create the file on the iPhone instead of using ...specialfolderpath("documents")...
Many thanks in advance
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
my pleasure!
Do this:
1. Add your SQLite file via the "Copy files..." TAB in the standalone builder settings.
Then you will find this, and all other added files/folders, here -> specialfolderpath("resources")
2. When your app starts (simulator or device) check if the database file is already there:
3. Done, now use the dB in DOCS folder as desired!
Best
Klaus
my pleasure!
Do this:
1. Add your SQLite file via the "Copy files..." TAB in the standalone builder settings.
Then you will find this, and all other added files/folders, here -> specialfolderpath("resources")
2. When your app starts (simulator or device) check if the database file is already there:
Code: Select all
...
put specialfolderpath("resources") & "/ghost.sqlite" into tSourceDB
put specialfolderpath("documents") & "/ghost.sqlite" into tTargetDB
## VERY first app start, so we need to copy the db file to the documents folder, where we have WRITE permission, VERY important!
if there is NOT a file tTargetDB then
put url ("binfile:" & tSourceDB) into url("binfile:" & tTargetDB)
end if
## Now use that new path to open the file:
put revOpenDatabase("sqlite", tTargetDB,,,,) into tResult
...

Best
Klaus
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Many thanks Klaus
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Dear Klaus, still trying to understand what I'm doing wrong, I have to questions, but feel free to not to answer if you think I'm being to lazy to search for the answers on the DB Docs.
1 - I don't get why do I need to copy the sqLite DB file from the desktop to the device if it can be locally created (on openCard) and populated (button Insert Records)
2 -On the desktop, how to explain the need to click twice in sequence, the same button in order for the DataGrid to properly display all its columns contentes.
Cheers!
1 - I don't get why do I need to copy the sqLite DB file from the desktop to the device if it can be locally created (on openCard) and populated (button Insert Records)
2 -On the desktop, how to explain the need to click twice in sequence, the same button in order for the DataGrid to properly display all its columns contentes.
Cheers!
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
I had the impression that your database file already contains data, that's why I advised to copy that file to the users docs folder first.
If you only need an empty database (with no tables, fields and data!) you can of course simply create it with "revopendatabase..."
Where do I have to click?
Best
Klaus
You do not need this explicitely!simon.schvartzman wrote:1 - I don't get why do I need to copy the sqLite DB file from the desktop to the device if it can be locally created (on openCard) and populated (button Insert Records)

I had the impression that your database file already contains data, that's why I advised to copy that file to the users docs folder first.
If you only need an empty database (with no tables, fields and data!) you can of course simply create it with "revopendatabase..."
What is exactly the problem?simon.schvartzman wrote:2 -On the desktop, how to explain the need to click twice in sequence, the same button in order for the DataGrid to properly display all its columns contentes.
Where do I have to click?
Best
Klaus
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Thanks Klaus, see explanation below for
Now if you click button "Table1" should see the same thing happening with columns DateT1
Hope is clear enough
If you Click button "Table2" again, then DateT2 gets its content correctly.What is exactly the problem?
Where do I have to click?
Now if you click button "Table1" should see the same thing happening with columns DateT1
Hope is clear enough
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Klaus, I found the solution, I hope you can explain why...
On the retrieveData function I originally had:
If I retrieve the Column Titles before the Data then the problem disappears.
Does it make sense? Did I miss the instructions on the DOCs?
Now I need to make it work on the device...(it is not...)
Best!
On the retrieveData function I originally had:
Code: Select all
-- get the data
put "SELECT * FROM " & tTableName into tSQL
put revDataFromQuery(tab, cr, sDatabaseID, tSQL) into tData
set the dgText of group "DataGrid 1" of card "Alerts" to tData
-- Get the Column Titles
put revDatabaseColumnNames (sDatabaseID, tTableName ) into tColumnTitles
replace comma with return in tColumnTitles
set the dgProp[ "columns" ] of group "DataGrid 1" of card "Alerts" to tColumnTitles
Code: Select all
-- Get the Column Titles
put revDatabaseColumnNames (sDatabaseID, tTableName ) into tColumnTitles
replace comma with return in tColumnTitles
set the dgProp[ "columns" ] of group "DataGrid 1" of card "Alerts" to tColumnTitles
-- get the data
put "SELECT * FROM " & tTableName into tSQL
put revDataFromQuery(tab, cr, sDatabaseID, tSQL) into tData
set the dgText of group "DataGrid 1" of card "Alerts" to tData
Now I need to make it work on the device...(it is not...)
Best!
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Klaus, It seems it is a bug after all!
I just Deleted the DataGrid from my card and then added a "fresh" one with the same name and it worked like a charm both on the Simulator / iPhone exactly the same as in the desktop.
p.s.: I saved a copy of the original faulty stack and will open a bug report.
Many thanks for your help.
I just Deleted the DataGrid from my card and then added a "fresh" one with the same name and it worked like a charm both on the Simulator / iPhone exactly the same as in the desktop.
p.s.: I saved a copy of the original faulty stack and will open a bug report.
Many thanks for your help.
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
must tested and it works as advertised!?
I see data from table 2 immediately in the datagrid!
I even quit and restarted LC, same result/success.
Best
Klaus
must tested and it works as advertised!?
I see data from table 2 immediately in the datagrid!
I even quit and restarted LC, same result/success.
Best
Klaus
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Is it me or is it a bug? (Ghost Function...) Part I
Just to close the post: bug was reported and confirmed here:
http://quality.livecode.com/show_bug.cgi?id=18057
http://quality.livecode.com/show_bug.cgi?id=18057
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Is it me or is it a bug? (Ghost Function...) Part I
Hi Simon,
oh, sorry, I obviously missed the "simulator" part!
Best
Klaus
oh, sorry, I obviously missed the "simulator" part!
Best
Klaus