Creating databases

by Neilz » Tue, 15 Dec 2009 07:42:36 GMT

Sponsored Links
 I've made a few apps now, which use an SQLite database, no problems.
In my latest app, I want two tables, and I just realised that every
example I can find only creates one table.

So, is this a limitation? Must I use only one table? Assuming I can
use two, how do I go about changing my create script? Here's a normal
one, as per the examples:

private static final String DATABASE_CREATE =
                "create table myTable (_id integer primary key autoincrement,
                        + "description text not null); " ;

If there's an example elsewhere, I'd be grateful for a link... thanks.


Creating databases

by Mark Murphy » Tue, 15 Dec 2009 07:46:49 GMT


In onCreate() of your SQLiteOpenHelper, you can call execSQL() as many
times as you like, to execute as many SQL statements as you like. You
can have as many tables, indices, triggers, and whatnot as SQLite
allows, certainly greater than one of each.

So, call execSQL() once to create one table and once to create another
table. Or, courtesy of that semicolon, you may be able to put both
CREATE TABLE statements in a single string -- I haven't tried that.

Mark Murphy (a Commons Guy)  | 

Android App Developer Training: 


Sponsored Links

Creating databases

by jeffro » Wed, 16 Dec 2009 00:49:14 GMT

 Here's an example:

        public void onCreate(SQLiteDatabase db) {
                Log.d(getClass().getName(), "Creating Database.");

and the I have final strings like the following that contain the SQL
to create the table:

    private static final String VEHICLE_CREATE =
        "create table vehicle (_id integer primary key autoincrement,
vehicle text not null,notes text, selected boolean not null default
false,vehicle_uri text,weight real default 0.0,drivetrain_loss integer
default 17);";

Trackmaster - Motorsports Lap Timer 
Dynomaster - Performance Dyno 


Other Threads

1. change background color on focus


i need to have the default selection color (orange), here is my code

<Button android:id="@+id/login"




 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">

    <item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/enter_button_pressed" />
<item android:state_focused="true" android:state_pressed="false"
         android:color="?"              // this should be default color


    <item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/enter_button_pressed" />

    <item android:drawable="@drawable/enter_button" />


can i set just color on focus or i must need to put another image in
focused section?

2. Managed filer query creates 'attempt to acquire a reference on a close SQLiteClosable'

I'm creating a managedQuery in the FilterQueryProvider.runQuery() of a
ResourceCursorAdapter. That works fine, but if I set up a filter, then
go to a different app, then go back to the app with the filter, the
app crashes with 'attempt to acquire a reference on a close
SQLiteClosable' in the performResumeActivity.

My guess is that the cursor manager is trying to call requery() on the
filter queries, but they have since been closed by the magic fairy (I
don't keep a pointer to the cursors).

The only way I can get this to work is by using a double-buffered
cursor for the filters that I maintain myself and close in onPause().
That seems pretty backwards.

What can cause a cursor to become invalid after the activity changes?
I only have this problem when using the filter.



3. Afterimage when using SURFACE_TYPE_PUSH_BUFFERS surface.

4. Google dev phone G1 activation problem

5. Injecting HTTP header into all requests issued by the emulator

6. Drawing ViewGroup content on a SurfaceView/SurfaceHolder Canvas

7. ADT Layout editor design question