The Below Is my DataBase Activity.The function getAllRecords() never returns any record any idea why?The History_Column_NAME when compiling reads as name.is this normal.Value Stored as SharedPreference works i have checked Any help will be much appriciated
package com.sset.jibin.wakemethere;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseOperations2 extends SQLiteOpenHelper {
static int DATABASE_VERSION = 1;
static String DATABASE_NAME = "data";
static String TABLE_NAME = "history";
static String HISTORY_COLUMN_LNG = "lng";
static String HISTORY_COLUMN_LAT = "lat";
static String HISTORY_COLUMN_ID = "_id";
static String HISTORY_COLUMN_NAME = "name";
private Context mContext;
public DatabaseOperations2(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Log.d("DatabaseHelper", "Database2 constructor");
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase database) {
Log.d("DatabaseOP2", "onCreate");
database.execSQL("CREATE TABLE " + TABLE_NAME +
"( " + HISTORY_COLUMN_ID + " integer primary key, " + HISTORY_COLUMN_LNG + " text, " +
HISTORY_COLUMN_LAT + " text, " + HISTORY_COLUMN_NAME + " text)");
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVer, int newVer) {
Log.d("DatabaseHelper", "onUpgrade");
database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(database);
}
public void saveRecord(String lat, String lng, String name) {
Log.d("DatabaseHelper", "saveRecord");
SQLiteDatabase database = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(HISTORY_COLUMN_LAT, lat);
contentValues.put(HISTORY_COLUMN_LNG, lng);
contentValues.put(HISTORY_COLUMN_NAME, name);
database.insert(TABLE_NAME, null, contentValues);
close();
}
public Cursor getAllRecords() {
SharedPreferences pref = mContext.getSharedPreferences("lin", 0);
SharedPreferences.Editor editor = pref.edit();
String a = pref.getString("KEY", null); // getting String
Log.d("test=====>", a);
SQLiteDatabase database = this.getReadableDatabase();
return database.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + HISTORY_COLUMN_NAME + " = '" + pref.getString("KEY", null) + "'", null);
}
}
Aucun commentaire:
Enregistrer un commentaire