On 7 Jul 2010, at 11:12pm, Chris wrote: > I would like to know what the accepted practice is for where to put > the database in my Eclipse Android project folder structure, and how > to access it in my java code. > > Is it possible to do this or do I have to open the db file as a > regular file and copy it to a new file I create via my code and then > open that new file as a SQLite db?
A SQLite database is just a file: the SQLite library doesn't demand it's stored in a certain way or tagged with some special tag. The file format on all platforms is identical. You can make the file on your desktop computer, put whatever data into it you like (using SQLite functions), copy it to your phone, and use the application on your phone to open it and read the data (using SQLite functions). You can also go the other way: use SQLite function calls to make a database on your phone, copy the file to your computer, and read the data out using an application on your computer. > I am very unclear about this as I am beginning to understand that the > db becomes part of the application itself and I have never worked in a > model like that. Your phrase "the db becomes part of the application" is not part of the sqlite approach -- sqlite will handle the file wherever it is. It may be part of the Android way of doing things (just like it is part of the iPhone way of doing things). Since it's Android which is telling you to do things that way, you'll find an explanation of it in the documentation for Android, not in the documentation for sqlite. > It would also be good to know how to test for the existence of the > database file before trying to open it as it is my understanding that > a new db will be created if the open method does not find an existing > one. First, it will be a file, so you can use normal file-handling routines to see whether a file with that name exists in that folder. You may find that sufficient, but if you want to check to see whether this is just a file full of gibberish or a proper sqlite database, you can open the file as text and read the beginning. It should begin with text SQLite format 3 If the first 15 bytes are anything else, it's not really a SQLite database. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users