Page 1 of 1
Where put SQLLite file
Posted: Mon May 30, 2011 9:36 am
by info26
I must save a sqlfile that whn I upgrading my application is is not delete.
I try in specialFolder path ("documents") but the file is into the application
I try "home" but the file is not created.
I try tu craete a folder into MEDIA and into MEDIA/ApplicationDocument but the file is not created
Where i can save my file?
Thanks'
Mimmo
Re: Where put SQLLite file
Posted: Mon May 30, 2011 12:37 pm
by Klaus
Hi Mimmo,
-> specialfolderpath("documents") is the correct place!
Do you get any errors? Can you show us the script(s) that you use?
Best
Klaus
Re: Where put SQLLite file
Posted: Mon May 30, 2011 3:17 pm
by info26
Now I put the file into docuemnts folder, but docuemts folder is into my application folder and when the application is updated the filse is deleted. If the user have data into this file, he loses the his data
I must find anothe position thank's
Mimmo
Re: Where put SQLLite file
Posted: Mon May 30, 2011 4:13 pm
by Klaus
Hi Mimmo,
info26 wrote:Now I put the file into docuemnts folder, but docuemts folder is into my application folder and when the application is updated the filse is deleted.
Sorry, don't understand this!?
Do you have a subfolder named "Documents" inside of your Application package?
Best
Klaus
Re: Where put SQLLite file
Posted: Mon May 30, 2011 4:45 pm
by info26
If I use
put SpecialFolderPath("documents") & "myfile.sqlite" intio tdocname
etc
(create sql table and fileds)
the file is in the myApplication/documents folder (into myApplycation)
I have test it with a file/folder iphone browser
When I reload myApplication with xCode the folder documets into myApplycation is replaced with an empty one
I hope I have explained the problem well
Re: Where put SQLLite file
Posted: Tue May 31, 2011 8:35 am
by JosepM
Hi Mimmo,
At start you must check if your database exist ("there is a file") into SpecialFolderPath("documents") & "myfile.sqlite".
If not exist copy your database to SpecialFolderPath("documents") & "myfile.sqlite", if exist do nothing and continue.
The path to the "Documents" folder that is where you can write the App files is:
/var/mobile/Applications/XXXXXXXXXXX-ID/Documents
In settings you need add the SQLite "fresh" database, and then the database will be stored into the "engine" folder that is read only.
Your documents folder, I guess is created by you from the standalone settings, isn't?
This is the code that work for me.
Code: Select all
on preopenstack
if the environment is "mobile" then
put specialFolderPath("Documents") & "/yourdatabasename.sqlite" into tPathToDatabase
put specialFolderPath("engine") & "/yourdatabasename.sqlite" into tPathToStartLoc
try
if not (there is a file tPathToDatabase) then
--Copy
put url ("binfile:" & tPathToStartLoc) into temp
put temp into url ("binfile:" & tPathToDatabase )
wait 5 milliseconds with messages
else
--Exist
end if
catch pErr
answer pErr
end try
end if
end preopenstack
Salut,
Josep
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 7:21 am
by info26
Thank Josep,
I had a similar idea myself, but I have to put a copy of the database file into the folder "engine" that is read-only.
I've tried to make a copy of the file when the stack is lclosed, but when you press the button "home" on the iPhone, the onclosestack event does not work.
Work still on your idea
Thanks
MImmo
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 8:37 am
by bn
Hi Mimmo,
use
on shutdown
instead of on closestack
put the on shutdown into the mainstack script for example.
have a look here
http://forums.runrev.com/phpBB2/viewtop ... own#p32673
make shure your you watch out for case sensitivity.
Kind regards
Bernd
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 11:14 am
by info26
HI Bernd
I have try but on shutDown on iPhone 3 don't work
Code: Select all
on shutDown
put specialFolderPath("documents") & "/macvet.sqlite" into tparti
put specialFolderPath("engine") & "/macvet.sqlite" into tarrivi
put url ("binfile:" & tparti) into temp
put temp into url ("binfile:" & tarrivi )
wait 5 milliseconds with messages
end shutDown
did I something wrong?
Thank's
Mimmo
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 11:27 am
by Klaus
Hi Mimmo,
1. this most important fact does not seem to be clear to you:
You are NOT allowed to write to -> specialfolderpath("engine")
So your script will of course not work!
2. The other posters recommended to copy the database file from out of your
Application packes into the current users documents folder, where you ARE allowed
to write and which is the way to go!
Your script does the opposite!
You copy the file from the users documents folder back into your app package???
3. Of course you need to copy the database file to the users documents folder only ONCE (the first time)
So your workflow should be like this:
a. Check if there is a database file in the users dicuments folder (Joseph already supplied a complete script for this!)
b. If it is NOT there, then you copy it to that folder
c. That's it!
Hint:
Just to be sure:
specialfolderpath("documents") is NOT the FOLDER "Documents" inside of your app package!!!!
Please check these stacks here, great resource, not only for beginners:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 11:38 am
by bn
Hi Mimmo,
as far as I see you want to save the file "macvet.sqlite" on shutDown from the folder "documents" to the folder "engine".
I don't think you are allowed to write to the folder "engine". You can copy a file from there to documents, but not the other way around.
On the first time you start your app and you added "macvet.sqlite" to the build it will be in "engine". You could not make any changes to "macvet.sqlite" in "engine". I would on the first start of your app test if "macvet.sqlite" is in "documents" if not then copy "macvet.sqlite" to "documents" and from then on you always work on "macvet.sqlite" in "documents". On starting your app you test if there is a file "macvet.sqlite" in "documents" and work with that file. As I said if it is not there then it must be the first time you start your app.
Folder "documents" will not change when updating your app. Only if you delete your app is documents gone.
"documents" is also backed up when syncing with iTunes.
I don't know exactly what you try to do but if you want do save changes to "macvet.sqlite" when the app quits then you should use on shutdown and just save file "macvet.sqlite" in "documents", if that is what you want to do.
Look at the iOS Release notes for the folders and what you are allowed in those folders (engine, temp, cache and documents).
Kind regards
Bernd
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 1:45 pm
by info26
you wrote
specialfolderpath("documents") is NOT the FOLDER "Documents" inside of your app package!!!!
Why then if I write
specialfolderpath("documents") & "/databasenale.sqlite"
the file is put into the application folder and when I replace the application data no longer exists? It is lost?
Ok the engine folder is locked there is another position where i put the file?
Thank's
Mimmo
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 2:28 pm
by Klaus
Hi Mimmo,
info26 wrote:you wrote
specialfolderpath("documents") is NOT the FOLDER "Documents" inside of your app package!!!!
Sorry, I just found out that the "iPhone Explorer" screenshot is misleading!
It looked to me as if you have a subfolder "Documents" inside of your Application package, but that's not true!
info26 wrote:...the file is put into the application folder and when I replace the application data no longer exists? It is lost?
Yes, when you replace that file with a "fresh" one all the data is lost. But that is not the point!
You only need to copy the database file to the users "documents" folder ONCE when the app starts the VERY FIRST TIME!
info26 wrote:Ok the engine folder is locked there is another position where i put the file?
No, that is correct, you do not have another way to deliver the database.
Don't take this personally, there may be language problems, did you understand anything of our explanations and concepts?
Best
Klaus
Re: Where put SQLLite file
Posted: Wed Jun 01, 2011 3:38 pm
by bn
Mimmo,
I made a little stack that has a file that goes along. The file Loremipsum.txt is copied to the engine folder.
On openstack in the stack script this file is copied to the documents folder if it is not there.
some buttons let you test where the file is and edit the file in a text field.
You can save the changes to the file you made in the text field or let the app save your changes when you hit the home button. (on shutdown in the stack script)
Then restart the app to see that your changes to the file were saved
I then installed a changed version of the app via Xcode.
It was the same app except I copied an additional button into it. The button has no function, just so I could tell the two versions apart.
I then build a standalone application again and copied it via Xcode to my iPhone allowing replace.
The Loremipsum.txt file I had changed in the first version of the app still had the changes. It was not replaced when I copied the new app via Xcode.
If you want to start from zero you have to delete your app from the iPhone. Otherwise the file Loremipsum.txt will not be newly created by your app.
Look at the code and see if it works for you.
Kind regards
Bernd
Re: Where put SQLLite file
Posted: Sat Jun 04, 2011 9:41 am
by info26
Thank's Bern
Mimmo