mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add the sqlite3session_table_filter API to the sessions extension.
FossilOrigin-Name: b7e4dd889d37c8f57c2d3c7900e802f644aac3ea
This commit is contained in:
@ -23,6 +23,8 @@ struct sqlite3_session {
|
||||
int bIndirect; /* True if all changes are indirect */
|
||||
int bAutoAttach; /* True to auto-attach tables */
|
||||
int rc; /* Non-zero if an error has occurred */
|
||||
void *pFilterCtx; /* First argument to pass to xTableFilter */
|
||||
int (*xTableFilter)(void *pCtx, const char *zTab);
|
||||
sqlite3_session *pNext; /* Next session object on same db. */
|
||||
SessionTable *pTable; /* List of attached tables */
|
||||
};
|
||||
@ -1066,6 +1068,16 @@ static void xPreUpdate(
|
||||
if( !pTab ){
|
||||
/* This branch is taken if table zName has not yet been attached to
|
||||
** this session and the auto-attach flag is set. */
|
||||
|
||||
/* If there is a table-filter configured, invoke it. If it returns 0,
|
||||
** this change will not be recorded. Break out of the loop early in
|
||||
** this case. */
|
||||
if( pSession->xTableFilter
|
||||
&& pSession->xTableFilter(pSession->pFilterCtx, zName)==0
|
||||
){
|
||||
break;
|
||||
}
|
||||
|
||||
pSession->rc = sqlite3session_attach(pSession,zName);
|
||||
if( pSession->rc ) break;
|
||||
pTab = pSession->pTable;
|
||||
@ -1170,6 +1182,19 @@ void sqlite3session_delete(sqlite3_session *pSession){
|
||||
sqlite3_free(pSession);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set a table filter on a Session Object.
|
||||
*/
|
||||
void sqlite3session_table_filter(
|
||||
sqlite3_session *pSession,
|
||||
int(*xFilter)(void*, const char*),
|
||||
void *pCtx /* First argument passed to xFilter */
|
||||
){
|
||||
pSession->bAutoAttach = 1;
|
||||
pSession->pFilterCtx = pCtx;
|
||||
pSession->xTableFilter = xFilter;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attach a table to a session. All subsequent changes made to the table
|
||||
** while the session object is enabled will be recorded.
|
||||
|
Reference in New Issue
Block a user