2015-05-04 16:51:40
0
Hey I am trying to query my database for the number of records which match the current date and also match the current time in the same record, however, I am getting a "Cannot resolve method "query(java.lang.string)"
What I need the query to do is check if a records date, and time match the current date and time.
Here is my DatabaseHandler class file
public class DatabaseHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "FoodTekTrakr",
DATABASE_TABLE = "AlarmManager",
KEY_ID = "id",
KEY_TITLE = "title",
KEY_DATE = "date",
KEY_TIME = "time",
KEY_SONG = "song";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_TITLE + " TEXT," + KEY_DATE + " TEXT," + KEY_TIME + " TEXT," + KEY_SONG + " TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
public void createAlarm(UserInputAlarmData AlarmData){
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TITLE, AlarmData.getTitle());
values.put(KEY_DATE, AlarmData.getDate());
values.put(KEY_TIME, AlarmData.getTime());
values.put(KEY_SONG, AlarmData.getSong());
db.insert(DATABASE_TABLE, null, values);
db.close();
}
public UserInputAlarmData getAlarmData(int id){
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_TITLE, KEY_DATE, KEY_TIME, KEY_SONG}, KEY_ID
+ "=?", new String[] {String.valueOf(id) }, null, null, null );
if (cursor != null)
cursor.moveToFirst();
UserInputAlarmData AlarmData = new UserInputAlarmData(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
db.close();
cursor.close();
return AlarmData;
}
public void deleteAlarm(UserInputAlarmData AlarmData){
SQLiteDatabase db = getWritableDatabase();
db.delete(DATABASE_TABLE, KEY_ID + "=?", new String[] { String.valueOf(AlarmData.getId()) });
db.close();
}
public int getAlarmDataCount() {
SQLiteDatabase db =getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE, null);
int count = cursor.getCount();
db.close();
cursor.close();
return count;
}
public int updateAlarmData(UserInputAlarmData AlarmData){
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TITLE, AlarmData.getTitle());
values.put(KEY_DATE, AlarmData.getDate());
values.put(KEY_TIME, AlarmData.getTime());
values.put(KEY_SONG, AlarmData.getSong());
return db.update(DATABASE_TABLE, values, KEY_ID + "=?", new String[] { String.valueOf(AlarmData.getId())});
}
public List getAllAlarmData() {
List AlarmDatas = new ArrayList();
SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE, null);
if (cursor.moveToFirst()) {
do {
UserInputAlarmData AlarmData = new UserInputAlarmData(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
AlarmDatas.add(AlarmData);
}
while (cursor.moveToNext());
}
return AlarmDatas;
}
public boolean DateAndTimeChecker() {
Date ThisDate = Calendar.getInstance().getTime();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String DateChecker = formatter.format(ThisDate);
Date ThisTime = Calendar.getInstance().getTime();
SimpleDateFormat timeformatter = new SimpleDateFormat("hh:mm");
String TimeChecker = formatter.format(ThisTime);
String DatabaseTime;
SQLiteDatabase db =getReadableDatabase();
Cursor c = db.query("SELECT " + KEY_DATE + "WHERE"+ KEY_TIME + "=" + DateChecker + "FROM" + DATABASE_TABLE);
if(c != null) {
return true;
}
else{
return false;
}
}
}
The method in which I am getting the error
public boolean DateAndTimeChecker() {
Date ThisDate = Calendar.getInstance().getTime();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String DateChecker = formatter.format(ThisDate);
Date ThisTime = Calendar.getInstance().getTime();
SimpleDateFormat timeformatter = new SimpleDateFormat("hh:mm");
String TimeChecker = formatter.format(ThisTime);
String DatabaseTime;
SQLiteDatabase db =getReadableDatabase();
Cursor c = db.query("SELECT " + KEY_DATE + "WHERE"+ KEY_TIME + "=" + DateChecker + "FROM" + DATABASE_TABLE);
if(c != null) {
return true;
}
else{
return false;
}
}
Thank you very much in advance for the help