Where put SQLLite file

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Where put SQLLite file

Post by info26 » Mon May 30, 2011 9:36 am

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

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Where put SQLLite file

Post by Klaus » Mon May 30, 2011 12:37 pm

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

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Mon May 30, 2011 3:17 pm

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

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Where put SQLLite file

Post by Klaus » Mon May 30, 2011 4:13 pm

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

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Mon May 30, 2011 4:45 pm

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
Attachments
win.jpg
my application is called VetMobile
win.jpg (50.09 KiB) Viewed 9499 times

JosepM
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 344
Joined: Tue Jul 20, 2010 12:40 pm

Re: Where put SQLLite file

Post by JosepM » Tue May 31, 2011 8:35 am

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

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Wed Jun 01, 2011 7:21 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Where put SQLLite file

Post by bn » Wed Jun 01, 2011 8:37 am

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

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Wed Jun 01, 2011 11:14 am

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

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Where put SQLLite file

Post by Klaus » Wed Jun 01, 2011 11:27 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Where put SQLLite file

Post by bn » Wed Jun 01, 2011 11:38 am

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

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Wed Jun 01, 2011 1:45 pm

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

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Where put SQLLite file

Post by Klaus » Wed Jun 01, 2011 2:28 pm

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. :D

Don't take this personally, there may be language problems, did you understand anything of our explanations and concepts?


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Where put SQLLite file

Post by bn » Wed Jun 01, 2011 3:38 pm

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.
mimmoSave.zip
(30.4 KiB) Downloaded 332 times
Look at the code and see if it works for you.

Kind regards

Bernd

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Where put SQLLite file

Post by info26 » Sat Jun 04, 2011 9:41 am

Thank's Bern

Mimmo

Post Reply