• 15
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I have two listviews which are exactly same. I am using one listview to update the containing string. I am using below query to update database.

myDatabase.update(TABLE_WORKSITEFOLDER, contentValues, KEY_LOCALID + " = ? ", new String[] { String.valueOf(increementedCurrentPosition)});

My database gets updated but the listview(s) row which contains this string doesn't get updated. Is this achieved by updating the list adapter. If so then How to do this?

Two problems.

1.String literals need to be quoted in single quotes as addressed by many other answers. Consider using ? placeholders and bind arguments, though.

2.Use execSQL() and not rawQuery() for SQL like this. rawQuery() just compiles the SQL but doesn't run it. It is only run when the cursor is moved. execSQL() both compiles and runs the SQL.

Example:

myDatabase.execSQL("UPDATE " + TABLE_WORKFLOW + " SET " + KEY_NAME + " = ? WHERE " + KEY_LOCALID + " = ?",
new Object[] { updatedName, increementedCurrentPosition });
  • 2
Reply Report
      • 1
    • I upvote this because I was convinced that rawQuery runs query, but it also returns result set. execSQL is exactly for insert or update. So you helped me to clarify this :)
      • 1
    • Your query runs perfectly and database is updated accordingly but the listview rows which contains these strings are not updated, i.e, they are showing without updated string. How to update my list view following an updation in the database.

The database field value is TEXT, need to add ' '

try :

myDatabase.rawQuery("UPDATE " + TABLE_WORKFLOW + " SET " + KEY_NAME + " = '" + updatedName + "' WHERE " + KEY_LOCALID + " = " + increementedCurrentPosition, null);
  • 0
Reply Report
      • 2
    • trying your answer would run my query smoothly but i dont get the updated string in the listview from where it was edited.
    • i don't understand you purpose ,maybe you need to update ListView adapter, call mAdapter.notifyDataSetChanged();
      • 2
    • try this code myDatabase.rawQuery("UPDATE ? SET ? = ? WHERE ? = ?", new String[]{TABLE_WORKFLOW,KEY_NAME,updatedName,KEY_LOCALID increementedCurrentPosition.toString()});

I think it should be:

myDatabase.rawQuery("UPDATE " + TABLE_WORKFLOW + " SET '" + KEY_NAME + "' = " + updatedName + " WHERE " + KEY_LOCALID + " = " + increementedCurrentPosition, null);

I.e. KEY_NAME is inside single quotes because it is TEXT type.

  • 0
Reply Report