Home SQLite exception in Jelly bean but not in marshmallow
Reply: 1

SQLite exception in Jelly bean but not in marshmallow

Vignesh
1#
Vignesh Published in 2017-09-14 04:15:53Z

I upgraded my app to marshmallow and getting sqlite database full exception. The db code is,

package com.app;

import java.io.File;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.util.Log;

public class Sqlitedb extends SQLiteOpenHelper{

private static final String DATABASE="appname";
private static final int VERSION=8;
private static final String CREATE_TABLE_TODO = "CREATE TABLE user (" + "id" + " INTEGER," + "value" + " INTEGER" + ")";

private static final String CREATE_TABLE_TODO1 = "CREATE TABLE trend (id INTEGER,url TEXT,image TEXT,title TEXT,count INTEGER,height TEXT,width  TEXT,points  INTEGER,sourceavail TEXT)";

private static final String CREATE_TABLE_TODO2 = "CREATE TABLE random (id INTEGER,url TEXT,image TEXT,title TEXT,count INTEGER,height TEXT,width  TEXT,points  INTEGER,sourceavail TEXT)";

public Sqlitedb(final Context context) 
 {
        super(context, Environment.getExternalStorageDirectory()
                + File.separator + "Appname"
                + File.separator + DATABASE  , null, VERSION);

 }

public static SQLiteDatabase openOrCreateDatabase (String dbfile,SQLiteDatabase.CursorFactory factory) 
{
    return null;
}
@Override
public void onCreate(SQLiteDatabase db)
{
    db.execSQL(CREATE_TABLE_TODO1);
    db.execSQL(CREATE_TABLE_TODO2);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
{


    if(oldVersion < 7)
    {
        db.execSQL("DROP TABLE IF EXISTS user");
        onCreate(db);           
    }

    if(newVersion == 8){
        db.execSQL(CREATE_TABLE_TODO1);
        db.execSQL(CREATE_TABLE_TODO2);
    }

}

public Cursor getDetails(String table) {
    // TODO Auto-generated method stub
    String selectQuery = "SELECT  * FROM  "+table+" order by id desc";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);
    return c;
}
public Cursor getDetails(String table,Integer integer) {
    // TODO Auto-generated method stub
    String selectQuery = "SELECT  * FROM  "+table+" where id='"+integer+"'";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);
    return c;
}

public void deleteData(String table) {
    // TODO Auto-generated method stub
    SQLiteDatabase db=this.getWritableDatabase();
    db.delete(table, null, null);
}

}

From MainPage,

Sqlitedb db = new Sqlitedb(getActivity());
Cursor c = db.getDetails("trend");

The tables are created in Marshmallow but not in Jelly bean. The database is created as i can access sqlite_master and android_metadata tables. Tried by adding getWritableDatabase(); to the constructor of Sqlitedb. looks like onCreate is not executed.

Strack Trace:

09-14 08:44:53.890: E/AndroidRuntime(25054): FATAL EXCEPTION: main
09-14 08:44:53.890: E/AndroidRuntime(25054): android.database.sqlite.SQLiteFullException: database or disk is full (code 13)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:552)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:263)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at com.app.db.Sqlitedb.getDetails(Sqlitedb.java:188)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at com.app.TrendActivity.onCreateView(TrendActivity.java:119)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1016)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1197)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1562)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:535)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.view.View.measure(View.java:15635)
09-14 08:44:53.890: E/AndroidRuntime(25054):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)

It is working fine in Marshmallow added with realtime permission request. Please help.

Abhijit Chakra
2#
Abhijit Chakra Reply to 2017-09-14 04:26:20Z

From SQLite documentation

(13) SQLITE_FULL

The SQLITE_FULL result code indicates that a write could not complete because the disk is full. Note that this error can occur when trying to write information into the main database file, or it can also occur when writing into temporary disk files. Sometimes applications encounter this error even though there is an abundance of primary disk space because the error occurs when writing into temporary disk files on a system where temporary files are stored on a separate partition with much less space that the primary disk. https://www.sqlite.org/rescode.html#full

I guess application is installed on SDCARD or someth

If your disk is full. You ran out of disk space

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303688 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO