When starting my application, it should only create an SQLite database. However, according to the logcat, a database is created, one row is inserted, then the database is created again. It then says that;
A SQLiteConnection object for database '/data/data/com.example.wolfe_000.final_final_zeno/databases/User_Info' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
I have previously attempted closing the database after interacting with it, it did not seem to work for me. I would really appreciate some advice, I'm new to SQLite and I'm completely lost. Here is the code;
package com.example.wolfe_000.final_final_zeno;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
* Created by wolfe_000 on 19/04/2015.
*/
public class DatabaseOperations extends SQLiteOpenHelper {
public static int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + "(" + TableData.TableInfo.USER_NAME +" TEXT," + TableData.TableInfo.USER_WEIGHT +" TEXT," + TableData.TableInfo.USER_GOAL +" TEXT," + TableData.TableInfo.USER_PASS +" TEXT," + TableData.TableInfo.USER_EMAIL +" TEXT);";
public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
Log.d("Database Operations", "Database Created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_QUERY);
Log.d("Database Operations", "Database Created");
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public void putInformation(DatabaseOperations dop, String name, String pass, String email, String weight, String goal) {
SQLiteDatabase SQ = dop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_NAME, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
cv.put(TableData.TableInfo.USER_EMAIL, email);
cv.put(TableData.TableInfo.USER_WEIGHT, weight);
cv.put(TableData.TableInfo.USER_GOAL, goal);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
Log.d("Database Operations", "One Raw Inserted");
}
public Cursor getInformation(DatabaseOperations dop){
SQLiteDatabase SQ = dop.getReadableDatabase();
String[] columns = {TableData.TableInfo.USER_NAME, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL, TableData.TableInfo.USER_WEIGHT, TableData.TableInfo.USER_GOAL};
Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, columns, null, null, null, null, null);
return CR;
}
}
Aucun commentaire:
Enregistrer un commentaire