I believe with the following code, I am able to create a database, create a table, and insert the sensor values inside.
This line create a db -> super(context, "sensor.sqlite", null, 1); in data/data/example.com.sensor/databases/sensor.sqlite
In the oncreate method, a table is created. In the insert method, a record will be inserted.
However when I check in ddms, the db is not even created. I found a data folder but there is no data/data folder.
Any idea why this happens?
package example.com.sensor;
import java.io.File;
import java.util.HashMap;
import java.util.Date;
import android.util.Log;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SqlController extends SQLiteOpenHelper {
private static final String LOGCAT = null;
public SqlController(Context context) {
super(context, "sensor.sqlite", null, 1);
Log.d(LOGCAT, "Created");
this.onCreate(super.getReadableDatabase());
}
@Override
public void onCreate(SQLiteDatabase database) {
String x = "CREATE TABLE [sport] ([id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,";
x+=" [accx] REAL,";
x+=" [accy] REAL,";
x+=" [accz] REAL,";
x+=" [geox] REAL,";
x+=" [geoy] REAL,";
x+=" [geoz] REAL,";
x+=" [activity] TEXT,";
x+=" [datetime] TIMESTAMP)";
database.execSQL(x);
}
@Override
public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
onCreate(database);
}
public void insert(HashMap<String, String> queryValues) {
SQLiteDatabase database = this.getWritableDatabase();
System.out.println(database.getPath());
ContentValues values = new ContentValues();
values.put("accx", queryValues.get("accx"));
values.put("accy", queryValues.get("accy"));
values.put("accz", queryValues.get("accz"));
values.put("geox", queryValues.get("geox"));
values.put("geoy", queryValues.get("geoy"));
values.put("geoz", queryValues.get("geoz"));
values.put("activity", queryValues.get("activity"));
values.put("datetime", new Date().toString());
database.insert("sport", null, values);
database.close();
}
}