diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 67 | ||||
-rw-r--r-- | src/vtab.c | 17 |
2 files changed, 63 insertions, 21 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index c93922f9d..19b418b43 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -370,7 +370,8 @@ int sqlite3_exec( ** ** New error codes may be added in future versions of SQLite. ** -** See also: [SQLITE_IOERR_READ | extended result codes] +** See also: [SQLITE_IOERR_READ | extended result codes], +** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. */ #define SQLITE_OK 0 /* Successful result */ /* beginning-of-error-codes */ @@ -2198,6 +2199,9 @@ int sqlite3_set_authorizer( ** to signal SQLite whether or not the action is permitted. See the ** [sqlite3_set_authorizer | authorizer documentation] for additional ** information. +** +** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] +** from the [sqlite3_vtab_on_conflict()] interface. */ #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ @@ -6400,31 +6404,46 @@ int sqlite3_wal_checkpoint_v2( /* ** CAPI3REF: Virtual Table Interface Configuration ** -** This function is called by a virtual table implementation to configure -** various facets of the virtual table interface. At present, there is only -** one option that may be configured using this function. Further options +** This function may be called by either the [xConnect] or [xCreate] method +** of a [virtual table] implementation to configure +** various facets of the virtual table interface. +** +** If this interface is invoked outside the context of an xConnect or +** xCreate virtual table method then the behavior is undefined. +** +** At present, there is only one option that may be configured using +** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options ** may be added in the future. +*/ +int sqlite3_vtab_config(sqlite3*, int op, ...); + +/* +** CAPI3REF: Virtual Table Configuration Options +** +** These macros define the various options to the +** [sqlite3_vtab_config()] interface that [virtual table] implementations +** can use to customize and optimize their behavior. ** ** <dl> ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT -** <dd>If the second argument to sqlite3_vtab_config() is +** <dd>If the second argument to [sqlite3_vtab_config()] is ** SQLITE_VTAB_CONSTRAINT_SUPPORT, then SQLite expects this function to ** have been called with three arguments, the third of which being of ** type 'int'. If the third argument is zero, then the virtual table ** is indicating that it does not support constraints. In this case if -** a call to the xUpdate method returns SQLITE_CONSTRAINT, the entire +** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], the entire ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been ** specified as part of the users SQL statement, regardless of the actual ** ON CONFLICT mode specified. ** ** If the third argument passed is non-zero, then the virtual table -** implementation must guarantee that if xUpdate returns -** SQLITE_CONSTRAINT, it does so before any modifications to internal +** implementation must guarantee that if [xUpdate] returns +** [SQLITE_CONSTRAINT], it does so before any modifications to internal ** or persistent data structures have been made. If the [ON CONFLICT] ** mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite is able to roll back ** a statement or database transaction, and abandon or continue processing ** the current SQL statement as appropriate. If the ON CONFLICT mode is -** REPLACE and the xUpdate method returns SQLITE_CONSTRAINT, SQLite +** REPLACE and the [xUpdate] method returns [SQLITE_CONSTRAINT], SQLite ** handles this as if the ON CONFLICT mode had been ABORT. ** ** Virtual table implementations that are required to handle OR REPLACE @@ -6439,23 +6458,35 @@ int sqlite3_wal_checkpoint_v2( ** */ #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 -int sqlite3_vtab_config(sqlite3*, int op, ...); /* ** CAPI3REF: Determine The Virtual Table Conflict Policy ** -** This function may only be called from within a call to the xUpdate method -** of a virtual table implementation for an INSERT or UPDATE operation. The -** value returned is one of SQLITE_ROLLBACK, SQLITE_IGNORE, SQLITE_FAIL, -** SQLITE_ABORT or SQLITE_REPLACE, according to the [ON CONFLICT] mode of the -** SQL statement that triggered the callback. +** This function may only be called from within a call to the [xUpdate] method +** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The +** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], +** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode +** of the SQL statement that triggered the call to the [xUpdate] method of the +** [virtual table]. +*/ +int sqlite3_vtab_on_conflict(sqlite3 *); + +/* +** CAPI3REF: Conflict resolution modes +** +** These constants are returned by [sqlite3_vtab_on_conflict()] to +** inform a [virtual table] implementation what the [ON CONFLICT] mode +** is for the SQL statement being evaluated. +** +** Note that the [SQLITE_IGNORE] constant is also used as a potential +** return value from the [sqlite3_set_authorizer()] callback and that +** [SQLITE_ABORT] is also a [result code]. */ #define SQLITE_ROLLBACK 1 -/* #define SQLITE_IGNORE 2 */ +/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ #define SQLITE_FAIL 3 -/* #define SQLITE_ABORT 4 */ +/* #define SQLITE_ABORT 4 // Also an error code */ #define SQLITE_REPLACE 5 -int sqlite3_vtab_on_conflict(sqlite3 *); diff --git a/src/vtab.c b/src/vtab.c index 72775fa3c..cac9c9606 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -992,17 +992,28 @@ void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){ } } +/* +** Return the ON CONFLICT resolution mode in effect for the virtual +** table update operation currently in progress. +** +** The results of this routine are undefined unless it is called from +** within an xUpdate method. +*/ int sqlite3_vtab_on_conflict(sqlite3 *db){ - int aMap[] = { + static const unsigned char aMap[] = { SQLITE_ROLLBACK, SQLITE_IGNORE, SQLITE_ABORT, SQLITE_FAIL, SQLITE_REPLACE }; assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); assert( OE_Ignore==4 && OE_Replace==5 ); assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); - return aMap[db->vtabOnConflict-1]; + return (int)aMap[db->vtabOnConflict-1]; } - +/* +** Call from within the xCreate() or xConnect() methods to provide +** the SQLite core with additional information about the behavior +** of the virtual table being implemented. +*/ int sqlite3_vtab_config(sqlite3 *db, int op, ...){ va_list ap; int rc = SQLITE_OK; |