Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd 2 column to sqlite db Android
    primarykey
    data
    text
    <p>i can't add 2 column in my existing db. i read any topic on the web but i can't fix my problem. may i have a complete personalized answer to my problem? naturally i don't wanna lose existing record, just alter it! i want to add 2 column (phone (integer), automex (text)) to my db created in this way..</p> <pre><code>package com.ozzem.mybirthdaylite; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class dbMyBirthday { SQLiteDatabase db; private Context mContext; private DbHelper mDbHelper; private static final String DB_NAME="dbmyBirthday"; private static final int DB_VERSION=1; //costruttore crea anche il DbHelper public dbMyBirthday(Context ctx){ mContext=ctx; mDbHelper=new DbHelper(ctx, DB_NAME, null, DB_VERSION); } public void open(){ //il database su cui agiamo è leggibile/scrivibile db=mDbHelper.getWritableDatabase(); } public void close(){ //chiudiamo il database su cui agiamo db.close(); } public void deletePerson(int idDel){ //metodo per inserire i dati String where = "id = " + idDel; db.delete(Person.PERSON_TABLE, where,null); // Log.d("db_call", "Record of id["+idDel+"] deleted"); } public void insertPerson(long l,String name,String birthday){ //metodo per inserire i dati ContentValues cv=new ContentValues(); cv.put(Person.UID, l); cv.put(Person.NAME, name); cv.put(Person.BIRTHDAY, birthday); db.insert(Person.PERSON_TABLE, null, cv); // Log.d("db_call", "Record of uid["+uid+"] insered"); } public boolean exist(long uid){ boolean ex = false; Cursor c= db.rawQuery("SELECT COUNT(*) FROM " + Person.PERSON_TABLE + " WHERE uid = "+ "'" + uid + "'", null); c.moveToFirst(); int jcount = c.getInt(0); if (jcount &gt;0){ ex=true; } return ex; } public void updatePersonFromId(int id,String name,String birthday){ ContentValues cv=new ContentValues(); // cv.put(Person.UID, id); cv.put(Person.NAME, name); cv.put(Person.BIRTHDAY, birthday); String where = "id = " + "'"+id+"'"; db.update(Person.PERSON_TABLE, cv, where, null); // Log.d("db_call", "Record of id["+id+"] updated"); } public void updatePersonFromUid(long l,String name,String birthday){ ContentValues cv=new ContentValues(); cv.put(Person.UID, l); cv.put(Person.NAME, name); cv.put(Person.BIRTHDAY, birthday); String where = "uid = " + "'"+l+"'"; db.update(Person.PERSON_TABLE, cv, where, null); // Log.d("db_call", "Record of uid["+uid+"] updated"); } public Cursor fetchAllBirthday(){ //metodo per fare la query di tutti i dati // Log.d("db_call", "Fetching all birthdays"); return db.query(Person.PERSON_TABLE, null,null,null,null,null,null); } public static class Person { // i metadati della tabella, accessibili ovunque static final String PERSON_TABLE = "person"; static final String ID = "id"; static final String UID = "uid"; static final String NAME = "name"; public static final String BIRTHDAY = "birthday"; } private static final String PERSON_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " //codice sql di creazione della tabella + Person.PERSON_TABLE + " (" + Person.ID + " integer primary key autoincrement, " + Person.NAME + " text not null, " + Person.UID + " integer not null, " + Person.BIRTHDAY + " text not null );"; private class DbHelper extends SQLiteOpenHelper { //classe che ci aiuta nella creazione del db public DbHelper(Context context, String name, CursorFactory factory,int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase _db) { // TODO Auto-generated method stub _db.execSQL(PERSON_TABLE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload