Android Question SqlLite - affected rows

Discussion in 'Android Questions' started by GaryK4, Jul 2, 2015.

  1. GaryK4

    GaryK4 Member Licensed User

    Is there any way to get the affected rows count for an update command?
     
  2. walterf25

    walterf25 Well-Known Member Licensed User

    I'm not sure you can get a count of rows updated after the rows being updated, however you can see the numbers of rows that need to be updated (before the update) based on the "WHERE" statement.

    Cheers,
    Walter
     
  3. imbault

    imbault Well-Known Member Licensed User

    Hi,
    You can use changes() core function of SqLite : https://www.sqlite.org/lang_corefunc.html

    changes() The changes() function returns the number of database rows that were changed or inserted or deleted by the most recently completed INSERT, DELETE, or UPDATE statement, exclusive of statements in lower-level triggers. The changes() SQL function is a wrapper around the sqlite3_changes() C/C++ function and hence follows the same rules for counting changes.


    So code should be like this:

    Code:
    SQLpi.ExecNonQuery("UPDATE " & MyTable & " SET fieldnum=4 WHERE fieldnum=2"' Or whathever
    Dim nbChanged As Int
    nbChanged = SQLpi.ExecQuerySingleResult(
    "SELECT changes() FROM " & MyTable)
    Log(nbChanged)  ' how many records have been updated
    Patrick
     
    Last edited: Jul 2, 2015
    DonManfred and walterf25 like this.
  4. GaryK4

    GaryK4 Member Licensed User


    I saw the function, but did not know how to use it.
    This worked!

    Thanks a lot!!
     
Loading...