Save database between standalone sessions
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 25
- Joined: Mon Feb 25, 2013 4:00 am
Save database between standalone sessions
I want a SQLite database that the mobile user can add and save to... then on subsequent uses be able to access the data they added on prior sessions... I have been able to get the add and save function working on my pc but the save function between sessions doesn't work in standalone (i think bc of read only files maybe)... so to clarify, on mobile devices it does save for the current session and the user can add then access the updated info until they close the app at which point the database restores to it's original data set.... i am able to save custom properties using txt. files, however, unsure how to do this with an SQLite database.... thanks
Re: Save database between standalone sessions
Hi sincipient820,
I'm not sure what your problem is
After each update/write etc. action the SQLite database is uptodate, no need to save, this happens automatically!
Maybe your db file is in a folder where you resp. your standalone does not have write permission?
Where resides your database file and how do you access it?
Please post the script(s).
Best
Klaus
I'm not sure what your problem is

After each update/write etc. action the SQLite database is uptodate, no need to save, this happens automatically!
Maybe your db file is in a folder where you resp. your standalone does not have write permission?
Where resides your database file and how do you access it?
Please post the script(s).
Best
Klaus
-
- Posts: 25
- Joined: Mon Feb 25, 2013 4:00 am
Re: Save database between standalone sessions
Sorry the "code" function wasn't working when i wrote this.... anyway, its Android and to open the db i use
put URL ("binfile:" & specialFolderPath("engine") & "/Alert.sqlite") into URL ("binfile:" & specialFolderPath("Documents") & "/Alert.sqlite")
local tDatabasePath, tSQLQuery
put specialFolderPath ("documents") & "/Alert.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite", tDatabasePath, , , ,) into sDatabaseID
if sDatabaseID is not a number then
answer "Pending alerts not found!"
end if
-- select pending alerts
put "SELECT RowId, Name, AlertType from AlertPending" into tSQLQuery
put revDataFromQuery (tab, return, sDatabaseID, tSQLQuery) into field "pending"
to set a new entry in the db i use...
local tDatabasePath, tSQLQuery
put specialFolderPath ("documents") & "/Alert.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite", tDatabasePath, , , ,) into sDatabaseID
if sDatabaseID is not a number then
answer "Pending alerts not found!"
end if
-- select pending alerts
put "INSERT INTO AlertPending VALUES (:1, :2, :3, :4)" into tSQL
revExecuteSQL sDatabaseID, tSQL, "tNotificationTime", "tAlertBody", "tAlertContact" , "tAlertMessage"
-- check the result and display the data or an error message
if the result is a number then
answer info "Alert Set."
else
answer error "Error Setting Alert"
end if
So, when in session it adds and updates... but if i close the app it will resort to the original entries and not include anything added in the prior sessions
put URL ("binfile:" & specialFolderPath("engine") & "/Alert.sqlite") into URL ("binfile:" & specialFolderPath("Documents") & "/Alert.sqlite")
local tDatabasePath, tSQLQuery
put specialFolderPath ("documents") & "/Alert.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite", tDatabasePath, , , ,) into sDatabaseID
if sDatabaseID is not a number then
answer "Pending alerts not found!"
end if
-- select pending alerts
put "SELECT RowId, Name, AlertType from AlertPending" into tSQLQuery
put revDataFromQuery (tab, return, sDatabaseID, tSQLQuery) into field "pending"
to set a new entry in the db i use...
local tDatabasePath, tSQLQuery
put specialFolderPath ("documents") & "/Alert.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite", tDatabasePath, , , ,) into sDatabaseID
if sDatabaseID is not a number then
answer "Pending alerts not found!"
end if
-- select pending alerts
put "INSERT INTO AlertPending VALUES (:1, :2, :3, :4)" into tSQL
revExecuteSQL sDatabaseID, tSQL, "tNotificationTime", "tAlertBody", "tAlertContact" , "tAlertMessage"
-- check the result and display the data or an error message
if the result is a number then
answer info "Alert Set."
else
answer error "Error Setting Alert"
end if
So, when in session it adds and updates... but if i close the app it will resort to the original entries and not include anything added in the prior sessions
Re: Save database between standalone sessions
Hi sincipient820 (?)
looks likes you overwrite the db file every time!?
Try this:
Best
Klaus
looks likes you overwrite the db file every time!?

Try this:
Code: Select all
...
put specialFolderPath("Documents") & "/Alert.sqlite") into tDBFile
## Dont overwrite current and probably up to date database file!
if there is NOT a file tDBFile then
put URL ("binfile:" & specialFolderPath("engine") & "/Alert.sqlite") into URL ("binfile:" & tDBFile")
end if
...
Best
Klaus