Right now I want to save my setting data using SQLite but no matter what I do, the cursors always returning null. In case the database is empty i have put the code:
if (sqlHelper.getProfilesCount(MySQLHelper.TABLE_SETTING_NAME) == 0){
sqlHelper.insertSettingNote(Constants.STR_LANG,Constants.STR_LOC,Constants.STR_SENS);
}
but it doesn't help. Neither rawQuery nor query help me read the file. Can you help me, please? Here is the code in MySQLHelper:
public SettingNote getSettingNote(String sql) {
SettingNote stnote = null;
Cursor cursor = getAll(sql);
if (cursor != null) {
stnote = cursorToSettingNote(cursor);
cursor.close();
}
return stnote;
}
public Cursor getAll(String sql) { // It always returning null
Cursor cursor = null;
try {
//cursor = db.rawQuery("SELECT * FROM" + sql,null); // I try using both rawQuery and query
String selectQuery = sql;
String[] whereArgs = new String[] {"hn", "vi", "no"};
cursor = db.query(selectQuery, null, "loc = ? lang = ? sensitive = ?", whereArgs , null, null, null);
if (cursor != null && cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
//Looping cursor and fetching the value...
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return cursor;
}
and here is my SettingNote:
public class SettingNote {
int id;
String lang, loc, sensitive;
public SettingNote(int id, String lang, String loc, String sensitive) {
this.id = id;
this.lang = lang;
this.loc = loc;
this.sensitive = sensitive;
}
public SettingNote(){};
public void setSensitive(String sensitive) {this.sensitive = sensitive;}
public void setLoc(String loc) {this.loc = loc;}
public void setLang(String lang) {this.lang = lang;}
public int getId() {return id;}
public String getLang() {return lang;}
public String getLoc() {return loc;}
public String getSensitive() {return sensitive;}
public void setId(int id) {this.id = id;}
}