|
1 2 3 4 5 |
final String CREATE_BASE_TABLE ="create table if not exists login (" + "id INTEGER PRIMARY KEY," + "email TEXT," + "password TEXT," + ");"; |
I have an android app that needs to check if there’s already a database available in the device, and if not, process some things and eventually create it.Then check if a particular table exists.
|
1 2 3 4 5 6 |
SQLiteDatabase db; db = openOrCreateDatabase( "TestData.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null ); |
If database exists and table exists simply read the data from the database if the data does exist.
Tip: For checking if a table Exists:
However, It is easy to find if a table exists or NOT,
Create a SQLiteDatabase object and have a call to query(…), the sql query string has select command. If the returned cursor is null then the table doesn’t exist.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
SQLiteDatabase tempDatabase; try { tempDatabase = SQLiteDatabase.openDatabase(DBPATH+DBNAME, null, SQLiteDatabase.OPEN_READONLY); try{ Cursor cur; cur=tempDatabase.rawQuery("select * from table where id='"+idvar+";",null); if(cur==null) { //our table doesn't exist, so we'll create one or take an action. } }catch (SQLiteException e) { //our table doesn't exist, so we'll create one or take an action. } } catch (SQLiteException e) { //our database doesn't exist, so we'll create one or take an action. } |
Incoming search terms:
- android sqlite check if table exists
- sqlite check if table exists
- html5 create sqlite database
- create table if not exists sqlite android
- windows phone check database exists or not
- phonegap check table exists
- phonegap db table exists
- phonegap sqlite cursor cur = db rawquery()
- selecting android sqlite from html5
- phonegap check if table exists or not
Tagged with: Android • Base Table • Cur • Cursor • Null • Object Query • Opendatabase • Query String • Sql Query • Text Password
Filed under: Android
Like this post? Subscribe to my RSS feed and get loads more!




Leave a Reply