1.Dd January 24, 2024 2.Dt SQLITE3_CHANGES 3 3.Os 4.Sh NAME 5.Nm sqlite3_changes , 6.Nm sqlite3_changes64 7.Nd count the number of rows modified 8.Sh SYNOPSIS 9.In sqlite3.h 10.Ft int 11.Fo sqlite3_changes 12.Fa "sqlite3*" 13.Fc 14.Ft sqlite3_int64 15.Fo sqlite3_changes64 16.Fa "sqlite3*" 17.Fc 18.Sh DESCRIPTION 19These functions return the number of rows modified, inserted or deleted 20by the most recently completed INSERT, UPDATE or DELETE statement on 21the database connection specified by the only parameter. 22The two functions are identical except for the type of the return value 23and that if the number of rows modified by the most recent INSERT, 24UPDATE or DELETE is greater than the maximum value supported by type 25"int", then the return value of sqlite3_changes() is undefined. 26Executing any other type of SQL statement does not modify the value 27returned by these functions. 28.Pp 29Only changes made directly by the INSERT, UPDATE or DELETE statement 30are considered - auxiliary changes caused by triggers, foreign key actions 31or REPLACE constraint resolution are not counted. 32.Pp 33Changes to a view that are intercepted by INSTEAD OF triggers 34are not counted. 35The value returned by sqlite3_changes() immediately after an INSERT, 36UPDATE or DELETE statement run on a view is always zero. 37Only changes made to real tables are counted. 38.Pp 39Things are more complicated if the sqlite3_changes() function is executed 40while a trigger program is running. 41This may happen if the program uses the changes() SQL function, 42or if some other callback function invokes sqlite3_changes() directly. 43Essentially: 44.Bl -bullet 45.It 46Before entering a trigger program the value returned by sqlite3_changes() 47function is saved. 48After the trigger program has finished, the original value is restored. 49.It 50Within a trigger program each INSERT, UPDATE and DELETE statement sets 51the value returned by sqlite3_changes() upon completion as normal. 52Of course, this value will not include any changes performed by sub-triggers, 53as the sqlite3_changes() value will be saved and restored after each 54sub-trigger has run. 55.El 56.Pp 57This means that if the changes() SQL function (or similar) is used 58by the first INSERT, UPDATE or DELETE statement within a trigger, it 59returns the value as set when the calling statement began executing. 60If it is used by the second or subsequent such statement within a trigger 61program, the value returned reflects the number of rows modified by 62the previous INSERT, UPDATE or DELETE statement within the same trigger. 63.Pp 64If a separate thread makes changes on the same database connection 65while 66.Fn sqlite3_changes 67is running then the value returned is unpredictable and not meaningful. 68.Pp 69.Sh IMPLEMENTATION NOTES 70These declarations were extracted from the 71interface documentation at line 2599. 72.Bd -literal 73SQLITE_API int sqlite3_changes(sqlite3*); 74SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); 75.Ed 76.Sh SEE ALSO 77.Xr sqlite3_total_changes 3 78