I used to insert 2 values/columns in my sqlite db(coordinates/markers to show them on map), today i wanted to add another column, i added it as usual but when wanting to launch map activity i have a logcat error as:
08-23 13:27:30.001: ERROR/Database(300): android.database.sqlite.SQLiteException: no such table: coord: , while compiling: INSERT INTO coord(longitude, latitude, description) VALUES(?, ?, ?);
To create the db+table i’m using this code:
public class MaBaseSQLite extends SQLiteOpenHelper {
private static final String TABLE_COORD = "coord";
private static final String COL_ID = "ID";
private static final String COL_LATI = "latitude";
private static final String COL_LONGI = "longitude";
private static final String COL_DESCRI = "description";
private static final String DATABASE_NAME = "coord.db";
private static final int DATABASE_VERSION = 1;
private static final String CREATE_BDD = "CREATE TABLE " + TABLE_COORD + " ("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_LATI + " TEXT NOT NULL, "
+ COL_LONGI + " TEXT NOT NULL, " + COL_DESCRI + "TEXT NOT NULL);";
MaBaseSQLite(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//on créé la table à partir de la requête écrite dans la variable CREATE_BDD
db.execSQL(CREATE_BDD);
}
To insert values i’m using this code in other class:
public long insertCoordo(Coordo coordo){
//Création d'un ContentValues (fonctionne comme une HashMap)
ContentValues values = new ContentValues();
values.put(COL_LATI, coordo.getlati());
values.put(COL_LONGI, coordo.getlongi());
values.put(COL_DESCRI, coordo.getdescri());
//on insère l'objet dans la BDD via le ContentValues
return bdd.insert(TABLE_COORD, null, values);
}
Example adding:
Coordo coordo = new Coordo(36.876673,10.325928, "TOTAL La Marsa");
CoordBd.insertCoordo(coordo);
And coordinates has 3 values as mentionned in this code in coordo() class:
public Coordo(Double lati, Double longi,String descri){
this.lati = lati;
this.longi = longi;
this.descri= descri;
}
What could be the problem with that?Why it can’t insert values on the table cause it dodn’t find it?
Thanks for helping.
Adding a column in SQLite is not just changing the SQL command to create it. You have to either
ALTERit orDROPit andCREATEit again in your onUpgrade.Then, you may have problems if you store doubles in
TEXT.REALis more adapted.