How to check if data queried from android sqlite
database is empty in a bindView method?
This is what I have done so far, but I think I am doing the wrong thing.
UPDATE
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
SQLiteDatabase db;
db = openOrCreateDatabase(
"no.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
//CREATE TABLES AND INSERT MESSAGES INTO THE TABLES
String CREATE_TABLE_NOTICES = "CREATE TABLE IF NOT EXISTS notices ("
+ "ID INTEGER primary key AUTOINCREMENT,"
+ "NOT TEXT,"
+ "DA TEXT)";
db.execSQL(CREATE_TABLE_NOTICES);
Cursor myCur = null;
// SQLiteDatabase db;
myCur = db.rawQuery("SELECT ID as _id,NOT,DA FROM notices order by ID desc", null);
mListAdapter = new MyAdapter(Page.this, myCur);
setListAdapter(mListAdapter);
}
@Override
public void bindView(View view, Context context, Cursor myCur) {
TextView firstLine=(TextView)view.findViewById(R.id.firstLine);
if(myCur==null){
String message="No Message";
firstLine.setText(message);
}
}
The keyword
NOT
is a reserved word in MySQL. I'd be very surprised if it's not a reserved word in SQLite.I think the problem is here:
It looks like the reserved word
NOT
is being used as a column name. To use that as an identifier, it will need to be "escaped", by enclosing it in backtick characters.That's the normative pattern in MySQL. For SQLite, you use the (MySQL compatible ) backtick characters, or you can use double quotes (more ANSI standard compliant.)
It's also possible to qualify the column name. (I'm certain this works in MySQL).
References:
MySQL Reference Manual: 9.3 Keywords and Reserved Words https://dev.mysql.com/doc/refman/5.5/en/keywords.html
SQLite: SQLite Keywords https://www.sqlite.org/lang_keywords.html
It may also be a problem in the
CREATE TABLE
statement. Since you are creating the table, you have the option of using a different name for the column, a name which is not a reserved word.