1.Dd December 19, 2018 2.Dt SQLITE3_CHANGES 3 3.Os 4.Sh NAME 5.Nm sqlite3_changes 6.Nd Count The Number Of Rows Modified 7.Sh SYNOPSIS 8.Ft int 9.Fo sqlite3_changes 10.Fa "sqlite3*" 11.Fc 12.Sh DESCRIPTION 13This function returns the number of rows modified, inserted or deleted 14by the most recently completed INSERT, UPDATE or DELETE statement on 15the database connection specified by the only parameter. 16Executing any other type of SQL statement does not modify the value 17returned by this function. 18.Pp 19Only changes made directly by the INSERT, UPDATE or DELETE statement 20are considered - auxiliary changes caused by triggers, foreign key actions 21or REPLACE constraint resolution are not counted. 22.Pp 23Changes to a view that are intercepted by INSTEAD OF triggers 24are not counted. 25The value returned by sqlite3_changes() immediately after an INSERT, 26UPDATE or DELETE statement run on a view is always zero. 27Only changes made to real tables are counted. 28.Pp 29Things are more complicated if the sqlite3_changes() function is executed 30while a trigger program is running. 31This may happen if the program uses the changes() SQL function, 32or if some other callback function invokes sqlite3_changes() directly. 33Essentially: 34.Bl -bullet 35.It 36Before entering a trigger program the value returned by sqlite3_changes() 37function is saved. 38After the trigger program has finished, the original value is restored. 39.It 40Within a trigger program each INSERT, UPDATE and DELETE statement sets 41the value returned by sqlite3_changes() upon completion as normal. 42Of course, this value will not include any changes performed by sub-triggers, 43as the sqlite3_changes() value will be saved and restored after each 44sub-trigger has run. 45.El 46.Pp 47This means that if the changes() SQL function (or similar) is used 48by the first INSERT, UPDATE or DELETE statement within a trigger, it 49returns the value as set when the calling statement began executing. 50If it is used by the second or subsequent such statement within a trigger 51program, the value returned reflects the number of rows modified by 52the previous INSERT, UPDATE or DELETE statement within the same trigger. 53.Pp 54If a separate thread makes changes on the same database connection 55while sqlite3_changes() is running then the value 56returned is unpredictable and not meaningful. 57.Pp 58.Sh SEE ALSO 59.Xr sqlite3_changes 3 , 60.Xr sqlite3_total_changes 3 61