Saving a File that you package with your app.

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Saving a File that you package with your app.

Post by Kaubs » Thu Sep 08, 2011 7:22 pm

Hello,

I am trying to copy a SQlite file from my prepackaged app to the docs folder on my iPhone. I have had no success following another example I found on the forums that was similar. This is the code that I have modified. Any ideas? The file does exist in the docs folder it just seems to be corrupt as it contains no data and is 0kb in size after being copied. Originally the file is 3kb and had some tables in it.

Code: Select all

      if the environment is "mobile" then
      put (specialFolderPath("Documents") & "/System.sqlite") into tPathToDatabase
      put (specialFolderPath("engine") & "System.sqlite") into tPathToStartLoc
      
      try
         if not (there is a file tPathToDatabase) then
            put url ("binfile:" & tPathToStartLoc) into temp
            put temp into url ("binfile:" & specialfolderpath("Documents") & "/System.sqlite")
            wait 5 milliseconds with messages
         end if
      catch pErr
         put pErr into field 1
      end try
      try
         go stack tPathToDatabase
      catch pErr
         put pErr into field 1
      end try
   end if

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Saving a File that you package with your app.

Post by Jellicle » Fri Sep 09, 2011 2:13 am

This works for me:

Code: Select all

put (specialFolderPath("engine") & "/db.sqlite") into tOriginPath
 put url ("binfile:" & tOriginPath) into dbTemp
  put dbTemp into url ("binfile:"&   (specialFolderPath("Documents") & "/db.sqlite"))
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Saving a File that you package with your app.

Post by SparkOut » Fri Sep 09, 2011 9:44 am

I think it's just a simple typo. Probably your line
put (specialFolderPath("engine") & "System.sqlite") into tPathToStartLoc
is the culprit. Check the difference with the line defining tPathToDatabase. I think you're missing a slash to separate the engine folder path from the db name.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Saving a File that you package with your app.

Post by Jellicle » Fri Sep 09, 2011 9:48 am

SparkOut wrote:I think it's just a simple typo.
Yeah, good call. Looks like that's it.
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: Saving a File that you package with your app.

Post by Kaubs » Fri Sep 09, 2011 5:46 pm

Thanks for catching that typo! I did make the change but unfortunately its still just a zero kb file :( still not working. Really strange....

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: Saving a File that you package with your app.

Post by Kaubs » Fri Sep 09, 2011 6:28 pm

and.....WIN!

Thanks a ton guys!

Code: Select all

   put (specialFolderPath("Documents") & "/db.sqlite") into tPathToDatabase
   
   if there is a file tPathToDatabase then
      put revOpenDatabase("sqlite", tPathToDatabase,,,,,,) into conID
      put the result into temp  -- for debugging
      put "SQLite DB: " &  specialFolderPath("documents") & "/db.sqlite"  into field status-- display SQLIte flile name with path
      answer information return & "Connected to: " & tPathToDatabase & return & " conID is: " & conID
      
      else
   put (specialFolderPath("engine") & "/db.sqlite") into tOriginPath
   put url ("binfile:" & tOriginPath) into dbTemp
   put dbTemp into url ("binfile:"&   (specialFolderPath("Documents") & "/db.sqlite"))
   put revOpenDatabase("sqlite", tPathToDatabase,,,,,,) into conID
   put the result into temp  -- for debugging
   put "SQLite DB: " &  specialFolderPath("documents") & "/db.sqlite"  into field status-- display SQLIte flile name with path
   answer information return & "Connected to: " & tPathToDatabase & return & " conID is: " & conID
   
   end if

Post Reply