Updating row in database puts wrong value inside the columns

I have a working database in my android application. I can add rows without a problem. But when I try to update a row, the database puts the wrong values in the columns.

I have gone through the code plenty of times but I can't find the problem, I probably looked at it so much that I can't see the obvious problem. The problem is that when updating the database row. the values get put in the wrong column. Every column gets filled with the new data. but they are not in the correct column.

Here is an example:

// Inserting row into database gives this correct result
example: | id | column1 | column2 | column3 | column4 | column5 |
         | 1  | value1  | value2  | value3  | value4  | value5  |

// after updating the row i get this bad result:
example: | id | column1 | column2 | column3 | column4 | column5 |
         | 1  | value1  | value2  | value5  | value3  | value4  |

I have a listview shows the database column1´s value, then send the rest of the columns to another activity. think of it as a contact list in the listview and when clicking on a contact the rest of the information is show.

I send the data with this:

      EditContact.putExtra(MyContacts.ROW_ID, rowID);
      EditContact.putExtra("PHONE", phoneTextView.getText());
      EditContact.putExtra("EMAIL", emailTextView.getText());
      EditContact.putExtra("ADRESS", adressTextView.getText());          
      EditContact.putExtra("NAME", nameTextView.getText());
      EditContact.putExtra("COMMENT", commentTextView.getText());
      startActivity(EditContact); // start the Activity

in the EditContact activity i get the information like this and put the information in EditTexts.

    if (extras != null) {
        rowID = extras.getLong("row_id");
        phoneEditText.setText(extras.getString("PHONE"));
        emailEditText.setText(extras.getString("EMAIL"));
        adressEditText.setText(extras.getString("ADRESS"));
        nameEditText.setText(extras.getString("NAME"));
        commentEditText.setText(extras.getString("COMMENT"));
    }

I then save the information in the database like this:

         String phone   =   phoneEditText.getText().toString();
         String email   =   emailEditText.getText().toString();
         String adress  =   adressEditText.getText().toString(); 
         String name    =   nameEditText.getText().toString();
         String comment =   commentEditText.getText().toString();                 
     String spinner1 = (String) spinner1.getSelectedItem();
     String spinner2 = (String) spinner2.getSelectedItem();
     String spinner3 = (String) spinner3.getSelectedItem();

 databaseConnector.updateContact(rowID, spinner1, spinner2, spinner3, phone, email, adress, name, comment);

As you see I have three spinners here. I also have that when I add contact to database. and they gets inserted into the correct column even after update. these spinners gets translated to text in the viewcontact activity.

This is how I update the database in the DatabaseConnector

public void updateContact(long id, String spinner1, String spinner2, String spinner 3, String phone, String email, String adress, String name, String comment)
{
    ContentValues editContact = new ContentValues();
    editContact .put("SPINNER1", spinner1);
    editContact .put("SPINNER2", spinner2);
    editContact .put("SPINNER3", spinner3);
    editContact .put("PHONE", phone);
    editContact .put("EMAIL", email);
    editContact .put("ADRESS", adress);
    editContact .put("NAME", name);
    editContact .put("COMMENT", comment);

    open();
    database.update(DATABASE_TABLE, editContact , "_id=" + id, null);
    close();
} 

I would really appreciate if someone have any idea of what could be wrong. I simply can not see it. Although I'm new at this and still learning. Thank you

every value gets inserted into the correct row that I'm editing. but in the wrong column, and I get no errors.

Answers


Be sure that your order of columns is correct. Are you sure that your table layout goes _id, SPINNER1, SPINNER2, SPINNER3, phone, email, address, name comment? What is the code for database.update? The order will likely matter. The code can't just figure out the correct order of things based on magic ;)


Need Your Help

Placement new, objects placed over I/O registers and zeroed memory

c++ embedded reinterpret-cast placement-new ioports

I've been experimenting with placement new to "map" classes on top of I/O space to save some memory:

remove quotes from variable in javascript?

php javascript phpjs

I really don't understand Javascript.