Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert row in database with checking if it exist
    text
    copied!<p>I have code in my database helper to check if a specific place exist or not, if this item exist it will show toast that the place already exist,and if not it will add this place to the table. It only check if it exist and show the toast message otherwise it do not insert the place name in the table if it not exist .. I don't know why my code for the insertion is right but when add if statement it only check if this exist.</p> <p>This is my query in database helper:</p> <pre><code> public boolean CheckBookmarks(String i) { // TODO Auto-generated method stub boolean booked; Cursor c = mDataBase.rawQuery("SELECT _id,facility_id from bookmark where facility_id ='"+i+"'", null); String result; int iId=c.getColumnIndex(DB_Facility_ID); c.moveToFirst(); result=c.getString(iId); if(c.isNull(iId)) booked=false; else booked=true; return booked ; } </code></pre> <p>I also tried this code in database helper and id didn't worked:</p> <pre><code>public boolean CheckBookmarks(String i) { // TODO Auto-generated method stub Cursor c = mDataBase.rawQuery("SELECT _id,facility_id from bookmark where facility_id ='"+i+"'", null); String result; int iId=c.getColumnIndex(DB_Facility_ID); c.moveToFirst(); result=c.getString(iId); return true ; </code></pre> <p>and this is the code in my activity:</p> <pre><code> if(dbhelper.CheckBookmarks(namee)) Toast.makeText(getApplicationContext(), "Place is already in Bookmarks ", Toast.LENGTH_LONG) .show(); //if(!dbhelper.CheckBookmarks(namee)){ else{ ContentValues cvalues = new ContentValues(); cvalues.put("facility_id", namee); long data =dbhelper.insertbookmark(cvalues); Toast.makeText(getApplicationContext(), "Place added to Bookmarks ", Toast.LENGTH_LONG) .show(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload