dimanche 21 juin 2015

SQLite Database does not add new entry

If the cursor does not move to first, so its the first entry to the Database the addLike does function great, but if it moves to first and goes into one of the if-statements the addLike does not work... what could be the reason?

if (cursor.moveToFirst()) {
                do {
                    Log.d("Debug", "LongItemClick on " + position);
                    Log.d("Database", "Content: " + cursor.getString(0) + cursor.getString(1) + cursor.getString(1));
                    if (cursor.getString(0).equals(markerID) && Integer.parseInt(cursor.getString(1)) == position && Integer.parseInt(cursor.getString(2)) == 1) {
                       //do some things
                    }
                    if (cursor.getString(0).equals(markerID) && Integer.parseInt(cursor.getString(1)) == position && Integer.parseInt(cursor.getString(2)) == 0) {
                        //do some things
                    } else if (!cursor.getString(0).equals(markerID)&& Integer.parseInt(cursor.getString(1)) != position){
                        Log.d("Debug", "New Like");
                        //it always goes to this statement even the entry was "liked" before
                     dbh.addLike(dbh, markerID, position, 1);
                     //this seems not to work
                    }
                } while (cursor.moveToNext());
            } else {
                Log.d("Debug", "First Entry");
                dbh.addLike(dbh, markerID, position, 1);
                //this works and is shown in the "Database content" log from above
                cursor.close();

Aucun commentaire:

Enregistrer un commentaire