G GaryK4 Member Licensed User Longtime User Jul 2, 2015 #1 Is there any way to get the affected rows count for an update command?
walterf25 Expert Licensed User Longtime User Jul 2, 2015 #2 GaryK4 said: Is there any way to get the affected rows count for an update command? Click to expand... 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 Upvote 0
GaryK4 said: Is there any way to get the affected rows count for an update command? Click to expand... 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
imbault Well-Known Member Licensed User Longtime User Jul 2, 2015 #3 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: Copy 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 Upvote 0
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: Copy 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
G GaryK4 Member Licensed User Longtime User Jul 2, 2015 #4 imbault said: 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: Copy 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 Click to expand... I saw the function, but did not know how to use it. This worked! Thanks a lot!! Upvote 0
imbault said: 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: Copy 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 Click to expand... I saw the function, but did not know how to use it. This worked! Thanks a lot!!