Where are SQLite3 databases created?

Chris Trout

Greenhorn

Posts: 16

posted 6 years ago

My apology in advance if I am posting this question in the wrong forum. I looked but did not find a better place.

My question is this - I am working thru the Hello, Android book examples and have successfully run and understand the Events database example on pages 170-180.
[ although I don't understand where the events.db file is being created.] So, I decided to use the sqlite3 cmd line interface to create a different database, some tables, and write a small Android program to manipulate it.
I can invoke sqlite3 just fine from the cmd prompt, the db gets created and can create new tables, etc.
When I close sqlite3 I can see my new database.

What folder in my new Android program project should I copy my new datase to and how do I tell my code where to find it?

Thank you very much in advance to anyone who would like to offer some help.

I believe it's "/data", although I seem to recall a possibility that apps may have their own directories that contain SQLite.

In actual practice, however, it's not common to define a SQLite database externally, but rather to have the Android app do the creation. That way the app is self-installing.

An IDE is no substitute for an Intelligent Developer.

Chris Trout

Greenhorn

Posts: 16

posted 6 years ago

Hi Tim,
Thanks very much for your reply.
As I was waiting for a reply I was thinking that I probably didn't do a very good job of explaining my problem, so I'm going to elaborate.

I am working exclusively in Eclipse currently as I don't have a phone.
I would like to use a SQLite look-up table in my app.
There is a database example in the Hello, Android book (starts on p. 170 as I recall).
It creates a sqlite db from within the app. That is interesting and I will use that technique in the future on some app I'm sure.
Although it doesn't seem to work exactly as advertised. It creates the db and tbl the first time thru but doesn't drop the tbl when it run it again. It just keeps adding
records to the table. Here is the relevant db code:

* The tbl is never being dropped. I have set debuggable to try in my manifest file and set a breakpoint in this method to see if it is being invoked but it doesn't stop at that breakpoint or any other breakpoint I set in the app. I don't understand why?

I have looked all over for the events.db file but can't find it anywhere.
In actuality, I would like to have it be created under the "assets" folder in the Eclipse project structure for my Android project, but don't know how to tell to do that.
Would you be able to help me understand how to do that?
Once I understand that I can go onto my next little learning app where I put a look-up db into that same place and open it from there. Not exactly sure how to do an open on an existing db but will try and figure that out once this problem is solved.

Thanks again for your assistance as I am looking forward to hearing back from you.
-Chris

Hint: use the "Code" button when including code or XML samples. It makes things more readable.

No, it would be extremely rude for the emulator to destroy the database every time it started the app. I'd have a lot of grief if all my test data got wiped out every time I deployed a new version of an app. If you want to erase the database, you can do that easily from an Android Activity. You'll also find Android code samples available where a database adds/drops tables as part of a schema version upgrade process. For real-world apps, it would often be the case that an uninstaller would remove the database, as well as destroying any other persistent artefacts that the app might have created.

I don't know that the tables in SQLite are discrete files. I think maybe they're in a single "db" file. But then again, I don't care, since the Android OS/SQLite DBMS are taking care of the grungy implementation details for me, and I'm not (currently) doing anything that requires mucking around in the database internals.

An IDE is no substitute for an Intelligent Developer.

Chris Trout

Greenhorn

Posts: 16

posted 6 years ago

My apology for not attaching the code examples.
I'll blame that one on being new to the ranch...

I tried changing the version number of the db and that caused the tbl (not the db) to be dropped. That's good, so that problem is solved.

You mentioned that there are Android db code samples available.
I need to be able to state somewhere in the code where I want the db created initially. In my case I think it should be under that assets folder in the Eclipse Android project structure. Is that where db files should reside in the dev env? Or do people usually specify another folder under it called "databases"?

Finally, if you could point me to some relevant code example I would greatly appreciate it.