Updating a query in sqlite

前端 未结 1 1198
情话喂你
情话喂你 2021-01-23 17:07

Activity Code

String MMS = \"(SELECT Name FROM UserData WHERE MessagesSent=(SELECT max(MessagesSent) FROM UserData))\";
db.execSQL(\"UPDATE MainData SET MostMess         


        
相关标签:
1条回答
  • 2021-01-23 17:43

    If db is properly initialized, with this line:

    db.execSQL("UPDATE MainData SET MostMessagesSent = "+ MMS + "+ WHERE Data = MyData");
    

    you want to execute an UPDATE statement that will update the column MostMessagesSent of table MainData with a value fetched from the query strored in the variable MMS:

    String MMS = "(SELECT Name FROM UserData WHERE MessagesSent=(SELECT max(MessagesSent) FROM UserData))";
    

    In order for this to work you must have initialized properly the db object.
    I suppose you have a class extending SQLiteOpenHelper which provides the initialization of db.
    Also the names of the tables and columns must match the intended behavior.
    The problem is that execSQL() does not return a value indicating that the update was successful or not.
    You have to check it yourself.

    0 讨论(0)
提交回复
热议问题