Reputation: 9371
i am not able to get a reliable result to tell if the collumn of a database is null or not. i tried using a query checking to see if the the column of the database returns null or a string value of "" but no matter what i do the result of my check returns a result that there is something stored in that column, even if it is empty.
to make sure it is empty i delete all the data from the app and uninstall it from the device. that way i know the database column is empty
is there a better way to check if a particular column is empty?
if a column has never been used before on a newly created database, what is in that column? is it null or is there something put in by the system as a placeholder?
displayAll.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
textToShow.setText(DisplayAllFieldsObjectFromDB());
if (DisplayAllFieldsObjectFromDB() == null) {
Toast.makeText(DisplayTable.this, "TABLE NULL ", Toast.LENGTH_SHORT).show();
} else if (DisplayAllFieldsObjectFromDB() != null) {
Toast.makeText(DisplayTable.this, "TABLE HOLDS A VALUE ", Toast.LENGTH_SHORT).show();
} else if (DisplayAllFieldsObjectFromDB().equals("")) {
Toast.makeText(DisplayTable.this, "TABLE HOLDS EMPTY QUOTES VALUE ", Toast.LENGTH_SHORT).show();
}
}
});
code from the database table
// display all data from table
public String getAllFromDB() {
String tableString = "";
String result = "";
Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, null,
null, null, null, null, null);
if (cursor != null) {
// cursor.moveToFirst(); // use only this for getting one row
while (cursor.moveToNext()) { // use only this for getting multiple rows
tableString = cursor.getString(cursor.getColumnIndex(TABLE_STRING));
result += tableString + "\n";
}
}
return result;
}
Upvotes: 0
Views: 3919