File iO bug?

Hi,

When creating a sqlite database in my project folder I used to put in an empty string in the pathForFile API. But it seems like it is not working. I just filed this as a bug, anyone else that have tried this?

require "sqlite3";  
local path = system.pathForFile("gameDB.db","");  
db = sqlite3.open( path );   
  

Regards, Joakim [import]uid: 81188 topic_id: 21872 reply_id: 321872[/import]

Not saying that things aren’t changing, but I believe leaving out the optional param is how to achieve default (system.ResourceDirectory). [import]uid: 21331 topic_id: 21872 reply_id: 86958[/import]

TheREalTonyK is correct. Passing “” is actually passing an empty string value as the the second argument. In order to get the default system.ResourceDirectory, you need to pass ‘nil’, which is the same as just leaving it out.

More information on File I/O on today’s tutorial blog post:
http://blog.anscamobile.com/2012/02/reading-and-writing-files-in-corona/ [import]uid: 52430 topic_id: 21872 reply_id: 86964[/import]

Hi, I think I am about to get tired after 2 months of programming the fantastic LUA language :slight_smile:

Joakim [import]uid: 81188 topic_id: 21872 reply_id: 87041[/import]

Hmmm, if I am passing in NIL - I am getting this error:
bad argument #1 to ‘open’ (string expected, got nil)

EDIT:

Even if I am passing in system.ResourceDirectory it says the same - so it feels like a bug?

Joakim [import]uid: 81188 topic_id: 21872 reply_id: 87047[/import]

Ok. I was generalizing the issue too much.

You cannot create a file in system.ResourceDirectory. use system.DocumentsDirectory and you will have success.

If you include a db in your build, you can READ from the ResourceDirectory…

Read the link provided by Jonathan, this will answer all. [import]uid: 21331 topic_id: 21872 reply_id: 87096[/import]

Ok, but is apple allowing me to put the db in that folder?

In my previous game i had my db in the project folder and was using:

system.pathForFile(“gamelevels.db”,"")

Regards, Joakim [import]uid: 81188 topic_id: 21872 reply_id: 87102[/import]

As long as the file exists, and you are reading, it should be fine. I have not used a db for some time, so as far as Apple’s current restrictions, someone with more experience may need to chime in. [import]uid: 21331 topic_id: 21872 reply_id: 87135[/import]

i don’t know if it works with sqlite database, but for copying files to to docs directory, or using untar, it seams to work better when opening and copying files are done in binary mode

 local rfh = io.open( rfilePath, "rb" )   
 local wfh = io.open( wfilePath, "wb" )  
  

i remember reading somewhere that if you want to use a database it is always best to copy it to the docs directory first then open it.

http://developer.anscamobile.com/reference/index/filewrite
[import]uid: 89663 topic_id: 21872 reply_id: 98029[/import]