Android Sqlite Onupgrade Delete Table From Database
Solution 1:
The following is the code as used for the answer to a previous question (link below) amended to include a new method, namely restoreTable in DatabaseAssetHandler.java
The method will copy any table, as passed, from the backed-up database (made when copying a new database form the asset folder (as per the previous answer)). It does not include the complications of checking to see if the passed table exists.
It opens two SQLiteDatabase instances the new database and the old backed up database. Extracts all rows from the old database and inserts them into table with the same name in the new database.
This method, on it's own is :-
/**
*
* @param context The context so that the respective package is used
* @param dbname The name of the database (the old will have -backup appended)
* @param table The table from which to copy the data
*/publicstaticvoidrestoreTable(Context context, String dbname, String table) {
ContentValuescv=newContentValues();
SQLiteDatabasedbnew= SQLiteDatabase.openDatabase(context.getDatabasePath(dbname).toString(), null,SQLiteDatabase.OPEN_READWRITE);
SQLiteDatabasedbold= SQLiteDatabase.openDatabase(context.getDatabasePath(dbname + backup).toString(),null,SQLiteDatabase.OPEN_READONLY);
Cursorcsr= dbold.query(table,null,null,null,null,null,null);
dbnew.beginTransaction();
while (csr.moveToNext()) {
cv.clear();
intoffset=0;
for (String column: csr.getColumnNames()) {
switch (csr.getType(offset++)){
case Cursor.FIELD_TYPE_NULL:
break;
case Cursor.FIELD_TYPE_INTEGER:
cv.put(column,csr.getLong(csr.getColumnIndex(column)));
break;
case Cursor.FIELD_TYPE_FLOAT:
cv.put(column,csr.getFloat(csr.getColumnIndex(column)));
break;
case Cursor.FIELD_TYPE_STRING:
cv.put(column,csr.getString(csr.getColumnIndex(column)));
break;
case Cursor.FIELD_TYPE_BLOB:
cv.put(column,csr.getBlob(csr.getColumnIndex(column)));
}
}
dbnew.insert(DatabaseHelper.TABLE_BOOKMARK,null,cv);
}
dbnew.setTransactionSuccessful();
dbnew.endTransaction();
csr.close();
dbnew.close();
dbold.close();
}
- This method would need to be added to the DatabaseAssetHandler code from the previous answer.
To facilitate testing of the above a few changes have been made to DatabaseHelper.java, this is now :-
publicclassDatabaseHelperextendsSQLiteOpenHelper {
privatestaticfinalStringDB_NAME="dictionary.db";
privatestaticfinalintDB_VERSION=2;
publicstaticfinalStringTABLE_DICTIONARY="dictionary";
publicstaticfinal String TABLE_BOOKMARK= "bookmark";
publicstaticfinalStringCOL_ID="id";
publicstaticfinalStringCOL_WORD="word";
publicstaticfinalStringCOL_DEFINITION="definition";
publicstaticfinalStringCOL_WORID="wordid"; //<<<<<<<<<< ADDEDpublic Context mcontext;
public SQLiteDatabase mDatabase;
publicDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.mcontext = context;
Log.d("DBVERSION","The Database Version (as hard coded) is " + String.valueOf(DB_VERSION));
intdbversion= DatabaseAssetHandler.getVersionFromDBFile(context,DB_NAME);
Log.d("DBVERSION","The Database Version (as per the database file) is " + String.valueOf(dbversion));
// Copy the Database if no database existsif (!DatabaseAssetHandler.checkDataBase(context,DB_NAME)) {
DatabaseAssetHandler.copyDataBase(context,DB_NAME,true,DB_VERSION);
} else {
if (DB_VERSION > dbversion && DatabaseAssetHandler.checkDataBase(context, DB_NAME)) {
DatabaseAssetHandler.copyDataBase(context, DB_NAME, true, DB_VERSION);
DatabaseAssetHandler.restoreTable(context,DB_NAME,TABLE_BOOKMARK); //<<<<<<<<<< ADDED for keeping the BOOKMARKS
DatabaseAssetHandler.clearForceBackups(context, DB_NAME); // Clear the backups
}
}
mDatabase = this.getWritableDatabase();
}
@OverridepublicvoidonCreate(SQLiteDatabase db) {
}
@OverridepublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
publicvoidopenDatabase()throws SQLException {
mDatabase = this.getWritableDatabase();
}
//<<<<<<<<<< ADDED to allow some bookmarks to be addedpubliclongaddBookMark(long wordid) {
ContentValuescv=newContentValues();
cv.put(DatabaseHelper.COL_WORID,wordid);
return mDatabase.insert(DatabaseHelper.TABLE_BOOKMARK,null,cv);
}
// Added to retrieve the database name (could make DB_NAME public)public String getDBNAME() {
returnthis.DB_NAME;
}
//ADDED to dump the bookmarks along with the related word and definitionpublicvoidlogBookmarksWithWord() {
Stringtable_part= TABLE_BOOKMARK +
" JOIN " + TABLE_DICTIONARY +
" ON " + COL_WORID +
" = " + TABLE_DICTIONARY + "." + COL_ID;
String[] columns = newString[]{TABLE_BOOKMARK + "." + COL_ID, COL_WORID, COL_WORD, COL_DEFINITION};
Cursorcsr= mDatabase.query(table_part,columns,null,null,null,null,COL_WORD);
DatabaseUtils.dumpCursor(csr);
csr.close();
}
@Overridepublicsynchronizedvoidclose() {
if (mDatabase != null)
mDatabase.close();
super.close();
}
}
The same 2 versions of databases were used as per the previous answer. However, the invoking activity had additional code added to a) add some bookmarks when the the DB is copied from the assets folder, and to b) always output the bookmarks to the log (to show they are retained).
The invoking activity used is :-
publicclassMainActivityextendsAppCompatActivity {
DatabaseHelper mDBHlpr;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDBHlpr = newDatabaseHelper(this);
Cursorcsr= mDBHlpr.getWritableDatabase().query(
DatabaseHelper.TABLE_DICTIONARY,
null,null,null,null,null,null
);
DatabaseUtils.dumpCursor(csr);
//<<<<<<<<<< ADDED CODE// Add a couple of bookmarks only if database is copied for testingif (DatabaseUtils.queryNumEntries(mDBHlpr.mDatabase,DatabaseHelper.TABLE_BOOKMARK) < 1) {
mDBHlpr.addBookMark(1);
mDBHlpr.addBookMark(3);
}
// Always dump the bookmarks to the log
mDBHlpr.logBookmarksWithWord();
//<<<<<<<<<< END OF ADDED CODE
csr.close();
}
}
- Note the assumption has been made that the bookmarks table, albeit it empty (it needn't be) exists in the pre-existing database. If it doesn't exist then this would fail.
Testing/Results
Run 1
This run is for a new installation of the App and DB_VERSION is 1 (so the pre-exisiting database (initial version) is copied from the assets folder).
04-2218:06:17.6038734-8734/?D/DBVERSION:TheDatabaseVersion(ashardcoded)is104-2218:06:17.6038734-8734/?D/DBVERSION:TheDatabaseVersion(asperthedatabasefile)is-66666666604-2218:06:17.6038734-8734/?D/DBPATH:DBPathis/data/user/0/m.example.so55711282dictionary/databases/dictionary.db04-2218:06:17.6038734-8734/?D/COPYDATABASE:InitiatedCopyofthedatabasefiledictionary.dbfromtheassetsfolder.04-2218:06:17.6038734-8734/?D/COPYDATABASE:Assetfiledictionary.dbfoundsoattmeptingtocopyto/data/user/0/m.example.so55711282dictionary/databases/dictionary.db04-2218:06:17.6048734-8734/?D/COPYDATABASE:Attemptingcopyofblock1whichhas4096 bytes.04-2218:06:17.6048734-8734/?D/COPYDATABASE:Attemptingcopyofblock2whichhas4096 bytes.04-2218:06:17.6048734-8734/?D/COPYDATABASE:Attemptingcopyofblock3whichhas4096 bytes.04-2218:06:17.6048734-8734/?D/COPYDATABASE:FinishedcopyingDatabasedictionary.dbfromtheassetsfolder,to/data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288werecopied,in3blocksofsize4096.04-2218:06:17.6048734-8734/?D/COPYDATABASE:AllStreamshavebeenflushedandclosed.04-2218:06:17.6258734-8734/?I/System.out:>>>>>Dumpingcursorandroid.database.sqlite.SQLiteCursor@3396ef04-2218:06:17.6258734-8734/?I/System.out:0 {
04-2218:06:17.6258734-8734/?I/System.out:id=104-2218:06:17.6258734-8734/?I/System.out:word=Apple04-2218:06:17.6258734-8734/?I/System.out:definition=ThingthatdropsfromanAppleTree.04-2218:06:17.6258734-8734/?I/System.out: }
04-2218:06:17.6258734-8734/?I/System.out:1 {
04-2218:06:17.6258734-8734/?I/System.out:id=204-2218:06:17.6258734-8734/?I/System.out:word=Bucket04-2218:06:17.6258734-8734/?I/System.out:definition=Handheldcontainerwithcarryinghanlde.04-2218:06:17.6258734-8734/?I/System.out: }
04-2218:06:17.6258734-8734/?I/System.out:<<<<<04-2218:06:17.6318734-8734/?D/BOOKMARKDUMP:Dumpingthebookmarkstabletothelog.04-2218:06:17.6318734-8734/?I/System.out:>>>>>Dumpingcursorandroid.database.sqlite.SQLiteCursor@9ce45fc04-2218:06:17.6318734-8734/?I/System.out:0 {
04-2218:06:17.6318734-8734/?I/System.out:id=104-2218:06:17.6318734-8734/?I/System.out:wordid=104-2218:06:17.6318734-8734/?I/System.out:word=Apple04-2218:06:17.6318734-8734/?I/System.out:definition=ThingthatdropsfromanAppleTree.04-2218:06:17.6318734-8734/?I/System.out: }
04-2218:06:17.6318734-8734/?I/System.out:<<<<<
Run 2
Simply run again no changes, so no copy bookmark exists.
04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 1
04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is 1
04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@11697ce
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: id=1
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: }
04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: 1 {
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: id=2
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: word=Bucket
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: definition=Hand held container with carrying hanlde.
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: }
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: <<<<<
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: id=1
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: wordid=1
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: }
04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: <<<<<
Run 3
New version of database introduced DB_VERSION changed to 2 (some more words so the bookmark for word with the id 3 has a related word). New version of DB copied. The two bookmarks have been retained.
04-2218:44:58.7498975-8975/?D/DBVERSION:TheDatabaseVersion(ashardcoded)is204-2218:44:58.7498975-8975/?D/DBVERSION:TheDatabaseVersion(asperthedatabasefile)is104-2218:44:58.7498975-8975/?D/DBPATH:DBPathis/data/user/0/m.example.so55711282dictionary/databases/dictionary.db04-2218:44:58.7498975-8975/?D/DBPATH:DBPathis/data/user/0/m.example.so55711282dictionary/databases/dictionary.db04-2218:44:58.7508975-8975/?D/COPYDATABASE:InitiatedCopyofthedatabasefiledictionary.dbfromtheassetsfolder.04-2218:44:58.7508975-8975/?D/COPYDATABASE:Assetfiledictionary.dbfoundsoattmeptingtocopyto/data/user/0/m.example.so55711282dictionary/databases/dictionary.db04-2218:44:58.7508975-8975/?D/COPYDATABASE:Attemptingcopyofblock1whichhas4096 bytes.04-2218:44:58.7508975-8975/?D/COPYDATABASE:Attemptingcopyofblock2whichhas4096 bytes.04-2218:44:58.7508975-8975/?D/COPYDATABASE:Attemptingcopyofblock3whichhas4096 bytes.04-2218:44:58.7508975-8975/?D/COPYDATABASE:FinishedcopyingDatabasedictionary.dbfromtheassetsfolder,to/data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288werecopied,in3blocksofsize4096.04-2218:44:58.7508975-8975/?D/COPYDATABASE:AllStreamshavebeenflushedandclosed.04-2218:44:58.7838975-8975/?I/System.out:>>>>>Dumpingcursorandroid.database.sqlite.SQLiteCursor@10862da04-2218:44:58.7848975-8975/?I/System.out:0 {
04-2218:44:58.7848975-8975/?I/System.out:id=104-2218:44:58.7848975-8975/?I/System.out:word=Apple04-2218:44:58.7848975-8975/?I/System.out:definition=ThingthatdropsfromanAppleTree.04-2218:44:58.7848975-8975/?I/System.out: }
04-2218:44:58.7848975-8975/?I/System.out:1 {
04-2218:44:58.7848975-8975/?I/System.out:id=204-2218:44:58.7848975-8975/?I/System.out:word=Bucket04-2218:44:58.7848975-8975/?I/System.out:definition=Handheldcontainerwithcarryinghanlde.04-2218:44:58.7848975-8975/?I/System.out: }
04-2218:44:58.7848975-8975/?I/System.out:2 {
04-2218:44:58.7848975-8975/?I/System.out:id=304-2218:44:58.7848975-8975/?I/System.out:word=Yelllow04-2218:44:58.7848975-8975/?I/System.out:definition=Acolour.04-2218:44:58.7848975-8975/?I/System.out: }
04-2218:44:58.7848975-8975/?I/System.out:3 {
04-2218:44:58.7848975-8975/?I/System.out:id=404-2218:44:58.7848975-8975/?I/System.out:word=Zebra04-2218:44:58.7848975-8975/?I/System.out:definition=Abalckandwhite, horse-likeanimal.04-2218:44:58.7848975-8975/?I/System.out: }
04-2218:44:58.7848975-8975/?I/System.out:<<<<<04-2218:44:58.7848975-8975/?D/BOOKMARKDUMP:Dumpingthebookmarkstabletothelog.04-2218:44:58.7858975-8975/?I/System.out:>>>>>Dumpingcursorandroid.database.sqlite.SQLiteCursor@d4cb30b04-2218:44:58.7858975-8975/?I/System.out:0 {
04-2218:44:58.7858975-8975/?I/System.out:id=104-2218:44:58.7858975-8975/?I/System.out:wordid=104-2218:44:58.7858975-8975/?I/System.out:word=Apple04-2218:44:58.7858975-8975/?I/System.out:definition=ThingthatdropsfromanAppleTree.04-2218:44:58.7858975-8975/?I/System.out: }
04-2218:44:58.7858975-8975/?I/System.out:1 {
04-2218:44:58.7858975-8975/?I/System.out:id=204-2218:44:58.7858975-8975/?I/System.out:wordid=304-2218:44:58.7858975-8975/?I/System.out:word=Yelllow04-2218:44:58.7858975-8975/?I/System.out:definition=Acolour.04-2218:44:58.7858975-8975/?I/System.out: }
04-2218:44:58.7858975-8975/?I/System.out:<<<<<
RUN 4
Nothing changed, so no DB copy bookmarks still retained.
04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 2
04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is 2
04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@11697ce
04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: id=1
04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 1 {
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: id=2
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: word=Bucket
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: definition=Hand held container with carrying hanlde.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 2 {
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: id=3
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: word=Yelllow
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: definition=A colour.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 3 {
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: id=4
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: word=Zebra
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: definition=A balck and white, horse-like animal.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: <<<<<
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: id=1
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: wordid=1
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 1 {
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: id=2
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: wordid=3
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: word=Yelllow
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: definition=A colour.
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: <<<<<
RUN 5
App uninstalled. New version used.Bookmarks added as new DB BUT version is latest i.e. 2
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 2
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is -666666666
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Initiated Copy of the database file dictionary.db from the assets folder.
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Asset file dictionary.db found so attmepting to copy to /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 1 which has 4096 bytes.
04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 2 which has 4096 bytes.
04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 3 which has 4096 bytes.
04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Finished copying Database dictionary.db from the assets folder, to /data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288were copied, in 3 blocks of size 4096.
04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: All Streams have been flushed and closed.
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: id=1
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: 1 {
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: id=2
04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: word=Bucket
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: definition=Hand held container with carrying hanlde.
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: 2 {
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: id=3
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: word=Yelllow
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: definition=A colour.
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: 3 {
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: id=4
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: word=Zebra
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: definition=A balck and white, horse-like animal.
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: <<<<<
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@9ce45fc
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: 0 {
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: id=1
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: wordid=1
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: word=Apple
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: definition=Thing that drops from an Apple Tree.
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: 1 {
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: id=2
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: wordid=3
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: word=Yelllow
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: definition=A colour.
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: }
04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: <<<<<
Solution 2:
put your task you have to do in onUpgrade(). This method will be called only when you upgrades your app. (ie. upgrading version number with the upgrading database version.)
Post a Comment for "Android Sqlite Onupgrade Delete Table From Database"