For the record, removing the update hook from the update hook works as expected in both SQLite 3.19.3 and 3.21, with a connection which is opened with the SQLITE_OPEN_NOMUTEX flag, and the guarantee that no two threads use the same connection at the same time.
But I'm just not sure if this is a guaranteed behavior? Gwendal > Le 14 janv. 2018 à 18:05, Gwendal Roué <gwendal.r...@gmail.com> a écrit : > > Hello, > > Is it valid to change the update hook from the update hook itself? > > The reason for this question is the following: when a notified database > change makes it useless to perform further observation, one may want to > remove the update hook alltogether. Can it be done from the update hook > itself? > > Here is a quick and dirty sample code, for the context: it installs an update > hook that tracks any modification to the "players" table, and attempts to > remove the update hook as soon as the "players" table is modified: > > typedef struct { > sqlite3 *conn; > int players_table_was_modified; > } info; > > void update_hook(info *info, int change, char const *db, char const > *table, sqlite3_int64 rowed) { > if (strcmp(table, "players") == 0) { > info->players_table_was_modified = 1; > > // Is it valid? > sqlite3_update_hook(info->conn, NULL, NULL); > } > } > > sqlite3 *conn = ...; > info info = { conn, 0 }; > sqlite3_update_hook(conn, update_hook, &info); > > Quoting https://sqlite.org/c3ref/update_hook.html: > <https://sqlite.org/c3ref/update_hook.html:> > >> The update hook implementation must not do anything that will modify the >> database connection that invoked the update hook. Any actions to modify the >> database connection must be deferred until after the completion of the >> sqlite3_step() call that triggered the update hook. Note that >> sqlite3_prepare_v2() and sqlite3_step() both modify their database >> connections for the meaning of "modify" in this paragraph. > > According to this documentation, I'm note sure if sqlite3_update_hook itself > modifies the database connection for the meaning of "modify" in the quoted > documentation paragraph, and is thus forbidden, or not. > > Can anyone lift this doubt? > > Thanks in advance, > Gwendal Roué > _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users