I have created a Database called location.db. After that, i tried to create a table LOCATIONS. When I do this, i don't get any error , but the table seems not be created at all. To verify the creation of table i´m using sqlite3 from command line, where i have seen that the code to create the table is ok but for any unknown reason is not in fact created. Thanks in advanced.
package com.carlos.googlemapstest.db;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
/**
* Created by Carlos on 07/08/2015.
*/
public class LocationsHelper extends SQLiteOpenHelper {
//base de datos
private static final String DATABASE_NAME="location.db";
//tabla
private static final String TABLE_NAME="LOCATIONS";
//columnas
private static final String UID="_id";
private static final String NOMBRE="Nombre";
private static final String LATITUD="Latitud";
private static final String LONGITUD="Longitud";
private static final String INFO="Info";
//database version
private static final int DATABASE_VERSION=1;
//create database query
private static final String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+"("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT,"
+NOMBRE+" VARCHAR(255),"
+LATITUD+" REAL,"
+LONGITUD+" REAL,"
+INFO+" VARCHAR(255)"+")";
//private static final String CREATE_TABLE1="CREATE TABLE PRUEBA (nombre TEXT);";
private static final String DROP_TABLE="DROP TABLE IF EXISTS "+TABLE_NAME;
private Context context;
public LocationsHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context=context;
Toast.makeText(context,"Constructor called",Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate(SQLiteDatabase db) {
Toast.makeText(context,"onCreate called",Toast.LENGTH_SHORT).show();
try {
db.execSQL(CREATE_TABLE);
} catch (SQLException e) {
Toast.makeText(context,"Error onCreate:"+e,Toast.LENGTH_SHORT).show();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Toast.makeText(context,"onUpgraded called",Toast.LENGTH_SHORT).show();
try {
db.execSQL(DROP_TABLE);
onCreate(db);
} catch (SQLException e) {
Toast.makeText(context,"Error onUpgrade:"+e,Toast.LENGTH_SHORT).show();
}
}
}