Page 1 of 1

Saving a File that you package with your app.

Posted: Thu Sep 08, 2011 7:22 pm
by Kaubs
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

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

Posted: Fri Sep 09, 2011 2:13 am
by Jellicle
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

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

Posted: Fri Sep 09, 2011 9:44 am
by SparkOut
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.

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

Posted: Fri Sep 09, 2011 9:48 am
by Jellicle
SparkOut wrote:I think it's just a simple typo.
Yeah, good call. Looks like that's it.

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

Posted: Fri Sep 09, 2011 5:46 pm
by Kaubs
Thanks for catching that typo! I did make the change but unfortunately its still just a zero kb file :( still not working. Really strange....

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

Posted: Fri Sep 09, 2011 6:28 pm
by Kaubs
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