Hello, I have an application in android studio that connects to an external SQLite database and is stored in the Assets of my project. In order for me to be able to use this external database within Assets, I needed a class named SQLiteAssetHelper , where it configures the connection and returns those settings to be used normally by the SQLiteDatabase class, I am using SQLiteStudio to manage this database and until then it was working fine until I needed to use Inserts and Updates in this database.
It turns out that the insertion code performs, but insertion does not happen. It does not just happen, it does not make mistakes, it does not give a signal.
I tried to use the execSQL command, where I wrote the insert SQL (INSERT INTO table () VALUES ()), and the code normally executed without errors, but also did not insert the data .
So I decided to use the ContentValues , and the result was the same as the previous one.
I no longer do any ideas what to do so I can do these Inserts, does anyone know if this class SQLiteAssetHelper does not allow writing in the database? Thanks and follow the code for review:
Class that configures the connection:
public class DatabaseOpenHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "atividades.db";
private static final int DATABASE_VERSION = 1;
public DatabaseOpenHelper(Context context) {
super ( context, DATABASE_NAME, null, DATABASE_VERSION );
}
}
Connection class
public class DatabaseAccess {
private SQLiteOpenHelper openHelper;
private SQLiteDatabase database;
private static DatabaseAccess instance;
private Cursor cursorBanco = null;
public DatabaseAccess(Context context) {
this.openHelper = new DatabaseOpenHelper ( context );
}
public static DatabaseAccess getInstance(Context context) {
if (instance == null) {
instance = new DatabaseAccess ( context );
}
return instance;
}
public void open() {
this.database = openHelper.getWritableDatabase ();
}
public void close() {
if (database != null) {
this.database.close ();
}
}
Insertion method:
public boolean setPosLetras(int x, int y, char letra){
ContentValues cv = new ContentValues ( );
cv.put ( "pos_x", x );
cv.put ( "pos_y", y );
cv.put ( "letra", letra+"");
this.open ();
long insert = this.database.insert ( "posicoes", null, cv );
this.close ();
if(insert != -1){
return true;
} else {
return false;
}
}
Bank table
CREATE TABLE posicoes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pos_x INTEGER,
pos_y INTEGER,
letra VARCHAR (1)
);