Hi,
On Aug 19, 2:50 am, Shanjaq <[email protected]> wrote:
> Is there a straightforward method of opening a SQLiteDatabase
> connection and executing raw queries?
What you could try is to create a class that extends the
SQLiteOpenHelper class.
Then you will need to implement the abstract methods onCreate and
onUpgrade (see below for snippets for a simple hack).
Inside your new class, you can then use neat methods like,
this.getWritableDatabase().execSQL(sql);
or
Cursor cursor = this.getWritableDatabase().query(...);
>
> Create DB
> Create Table
> Read Table
> Update Table
> Delete Table
> Delete DB
All of these should be covered, but I would suggest you have a look
around in SQLiteOpenHelper for some useful helper methods like update
(..) and delete(..).
Hope this helps,
Best Regards
Toby
As promised, a simple implementation of the abstract methods,
@Override
public void onCreate(SQLiteDatabase db) { //called whenever the
required db does not exist (eg. first time app is run)
db.execSQL("CREATE TABLE blah blah...");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("DROP TABLE IF EXISTS blah"); //not a nice hack because it
doesnt try to convert current data to new db version...
onCreate(db);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---