Frage

I try to drop table programmatically nothing error show in logcat, but there has no any result :

Here my Database Helper class :

public class database1 extends SQLiteOpenHelper
{
    private static final String DB_Name="database";
    private static final int DB_Version=1;
    private static final String tbl_arrival1="arrival1";
    private static final String STRING_CREATE1 = "CREATE TABLE IF NOT EXISTS "+tbl_arrival1
            +" (_f_id INTEGER PRIMARY KEY AUTOINCREMENT, "
            +"f_date TEXT,"
            +"o_rder NUMERIC,"
            +"rem_com TEXT);";
    public database1 (Context ctx)
    {
        super(ctx,DB_Name,null,DB_Version);
    }
    @Override
    public void onCreate(SQLiteDatabase database) {
        databaseQuery.onCreate(database);
      }
    public static class databaseQuery 
    {
        public static void onCreate(SQLiteDatabase database)
        {   
            database.execSQL("DROP TABLE IF EXISTS "+tbl_arrival1);
            database.execSQL(STRING_CREATE1);
        }
    }
}

I use this database helper in content provider :

database1 DBHelper ;
public Uri insert(Uri uri, ContentValues values) 
    {
        long row_id;
        SQLiteDatabase sqlDB = DBHelper.getWritableDatabase();
        row_id=sqlDB.insert(tbl_arrival1, null, values);
        if(row_id>0)
        {
            Uri _uri = ContentUris.withAppendedId(CONTENT_URI, row_id);
            getContext().getContentResolver().notifyChange(_uri, null);
            return _uri;
        }
        throw new SQLException("Failed to insert into "+uri);
    }

The problem is that, the query drop table, is not working!

All suggestion and answer would be highly appreciated...

thanks

War es hilfreich?

Lösung

onCreate will work only once at time of creation once the database is created you should make use of onUpgrade() to drop table if any changes has been made to old version

EDIT http://www.vogella.com/articles/AndroidSQLite/article.html

Andere Tipps

I know I'm bit late but this question was relevant for me. In my case I tried to drop many tables in single a query, i. e.

drop table if exists table_name1;
drop table if exists table_name2;
drop table if exists table_name3;

so android's implementation of execSQL() executes only single sql statement

Your code seems to be fine. You are calling DROP TABLE and then creating again subsequently. How you checked the DROP TABLE is not working?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top