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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Training:  http://commonsware.com/training 

--


Sponsored Links


Creating databases

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


 Here's an example:

        @Override
        public void onCreate(SQLiteDatabase db) {
                Log.d(getClass().getName(), "Creating Database.");
                db.execSQL(VEHICLE_CREATE);
                db.execSQL(RUN_CREATE);
                db.execSQL(DATA_CREATE);
                db.execSQL(SETUP_CREATE);
                db.execSQL(ET_CREATE);
        }

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);";


Jeff
_______________________________
Trackaroo.com
Trackmaster - Motorsports Lap Timer  http://trackmaster.trackaroo.com 
Dynomaster - Performance Dyno  http://dynomaster.trackaroo.com 







--



Other Threads

1. Multiple activity instances launched by same intent. Bring one uniquely to foreground?

Hi,

I'm struggling with my app that launches multiple instances of the
same Activity using the same intent. My main activity is of class type
A and it does a startActivity() of two children that are of the same
class type B. So we have B1 and B2 launched. If B1 and B2 are both
paused (by pushing back button and making sure finish() is not invoked
on them so they are truly paused), how can A uniquely bring either B1
or B2 to the foreground again? I do want to launch a new B activity. I
want to uniquely bring B1 or B2 to the foreground.

so both B1 and B2 were created like this...
Intent intent = new Intent(context, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Now I want A to bring B1 (or B2) to the foreground/front so I use the
below code, but how do I distinguish B1 or B2 when starting the
activity? This only brings the last instance of B that was on top to
the foreground.

Intent intent = new Intent(context, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

I've tried keeping around references to B1 and B2 and doing something
like this, but this also only goes to the last instance of activity
class B that was on top...

Intent intent = new Intent(B1context, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
B1context.startActivity(intent);

I even tried this, but it still doesnt get me my unique B1 or B2...
Intent intent = B1.getIntent(); // i.e. the original intent that
started me
startActivity(intent); // still only brings to front the last B that
was on top.

Thanks in advance!

-- 

2. Swype for x10

Finally, I found swype apk that suitable for my x10 screen resolution in
landscape but it only has english language.

Tolong dong gimana caranya nambah bahasa di swype supaya bisa ketik
paragraph ini dengan cara geser2 layar seperti waktu ketik paragraph di atas
bukan notol-notol layar.

==meyNANTO==
Sent from Sony Ericsson Xperia X10i - an Android Smartphone.

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

3. Finish multiple tasks (stacks)

4. LG GW620 LinkMe - Softkeyboard Issues

5. wifi tether - can't initialize iptables table `filter': Table does not exist

6. Raw and wav format

7. redirecting printf