Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to scan my SQLite Database. Android
    text
    copied!<p>I have a save button that should basically create a new entry in my SQLite database IF there isn't already one with the same 'name and number'(both are stored as strings). If there is already an entry with the same name and number, it should make a popup asking if they want to overwrite.</p> <p>What actually happens is it creates a new entry whether or not the entry already exists. Code that runs when you click save:</p> <pre><code>final String thename=TeamName.getText().toString() final String thenum=TeamNum.getText().toString(); if ((thename.length()!=0) &amp;&amp; (thenum.length()!=0)){ ScoutingFormData info1 = new ScoutingFormData(this); info1.open(); final long returnedId=info1.scanFor(thename,thenum); if (returnedId==-1){ info1.createEntry(thename,thenum); } else { final Dialog overw=new Dialog(this); ....//The code that goes here is unimportant to my question so I'm hiding it. overw.show(); } info1.close(); } </code></pre> <p>Code in ScoutingFormData.java:</p> <pre><code>public long scanFor(String thename, String thenum) { String[] columns=new String[]{KEY_ROWID,KEY_NAME,KEY_NUM}; Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); int iID = c.getColumnIndex(KEY_ROWID); int iName = c.getColumnIndex(KEY_NAME); int iNum = c.getColumnIndex(KEY_NUM); for (c.moveToFirst(); !c.isAfterLast();c.moveToNext()){ if ((c.getString(iName)==thename) &amp;&amp; (c.getString(iNum)==thenum)){ return Long.parseLong(c.getString(iID)); } } return -1; } </code></pre> <p>I don't see how it could possibly return -1 if an entry already exists with the same name+number.</p>
 

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