Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know your database class, but check <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insertWithOnConflict%28java.lang.String,%20java.lang.String,%20android.content.ContentValues,%20int%29" rel="nofollow">this method</a>:</p> <pre><code>return this.sqliteDBInstance.insertWithOnConflict(DB_TABLE_NAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE); </code></pre> <p>If you are creating your column correctly, if there is a conflict, the new entry will replace the old one.</p> <p>EDIT: after your last comment, all you need is an <strong>update</strong>: first query your database with the name of your item (check carefully if parameters are ok):</p> <pre><code>return this.sqliteDBInstance.query(DB_TABLE_NAME, null, DB_COLUMN_1_NAME + "=?", new String[] {productName}, null, null, null); </code></pre> <p>This will return a Cursor with 0 or 1 row. If there aren't row, you can proceed inserting data normally (don't forget to add your counter: is 1 on first insert):</p> <pre><code>public void insertCountry(String countryName, String countryPrice) { sqliteDBInstance.execSQL("INSERT INTO " + DB_TABLE_NAME + "(country_name, country_price) VALUES('" + countryName + "', '" + countryPrice + "', '" + countryCounter + "')"); } </code></pre> <p>if there is 1 row, your product is already on your database, so just iterate the Cursor, take the value on counter, add +1 on it and update your database with <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#update%28java.lang.String,%20android.content.ContentValues,%20java.lang.String,%20java.lang.String%5B%5D%29" rel="nofollow">this method</a>:</p> <pre><code>public int update (String table, ContentValues values, String whereClause, String[] whereArgs) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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