sqlite3-static 3.12.2 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cb1eac344f86c7f00a38e165d917a7b33fc6d8d
4
- data.tar.gz: c4f6e363c482f6785d451f9ed99de61de026d189
3
+ metadata.gz: aea0fbcb75b44b516a0b983f98ed8add4ebac081
4
+ data.tar.gz: cd47e7d7ca712d74c12c8a628bec9b6a5664dad1
5
5
  SHA512:
6
- metadata.gz: daefe73909d8a24d209f5971d290b302d9077bb2a8131f26c0d6ce79a04b91d6326ffd2a80229e5efbc9e59eb034756fd3fa1e5537391304a494be1598b496dd
7
- data.tar.gz: c1b44f636a7577bf3afedb1bedb4ac7cafa22b293caa89d978a9a7fa7cff978ae06f4bdd3f7f21c3af1a08a14475d02aeaf6c16553fac67d261708fbbae14619
6
+ metadata.gz: 02bd4b1a14c4b662547bf5cd9e2997af785e11a52d4cea36a433119520d71209e26b2ad63e800e8aa1254d01fd2bd4387e126b996c808c6df0182750dac6d638
7
+ data.tar.gz: b87975fb5a43e20dfd3e7b78ed05a4601b882cc18d6cb07ccaaf926b471c2c3eebf6b53103ff28e00b8ed46b8bb8499a15a57628c68c08cd5e852f89ad6831b2
data/README.rdoc CHANGED
@@ -62,9 +62,8 @@ amalgamation, so it doesn't have any external dependencies
62
62
 
63
63
  Do the following:
64
64
 
65
- ruby setup.rb config
66
- ruby setup.rb setup
67
- ruby setup.rb install
65
+ gem build sqlite3-static.gemspec
66
+ gem install sqlite3-static-*.gem
68
67
 
69
68
  = SUPPORT!!!
70
69
 
@@ -111,9 +111,9 @@ extern "C" {
111
111
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112
112
  ** [sqlite_version()] and [sqlite_source_id()].
113
113
  */
114
- #define SQLITE_VERSION "3.12.2"
115
- #define SQLITE_VERSION_NUMBER 3012002
116
- #define SQLITE_SOURCE_ID "2016-04-18 17:30:31 92dc59fd5ad66f646666042eb04195e3a61a9e8e"
114
+ #define SQLITE_VERSION "3.13.0"
115
+ #define SQLITE_VERSION_NUMBER 3013000
116
+ #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
117
117
 
118
118
  /*
119
119
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -1932,12 +1932,30 @@ struct sqlite3_mem_methods {
1932
1932
  ** following this call. The second parameter may be a NULL pointer, in
1933
1933
  ** which case the new setting is not reported back. </dd>
1934
1934
  **
1935
+ ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
1936
+ ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
1937
+ ** interface independently of the [load_extension()] SQL function.
1938
+ ** The [sqlite3_enable_load_extension()] API enables or disables both the
1939
+ ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
1940
+ ** There should be two additional arguments.
1941
+ ** When the first argument to this interface is 1, then only the C-API is
1942
+ ** enabled and the SQL function remains disabled. If the first argment to
1943
+ ** this interface is 0, then both the C-API and the SQL function are disabled.
1944
+ ** If the first argument is -1, then no changes are made to state of either the
1945
+ ** C-API or the SQL function.
1946
+ ** The second parameter is a pointer to an integer into which
1947
+ ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1948
+ ** is disabled or enabled following this call. The second parameter may
1949
+ ** be a NULL pointer, in which case the new setting is not reported back.
1950
+ ** </dd>
1951
+ **
1935
1952
  ** </dl>
1936
1953
  */
1937
1954
  #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1938
1955
  #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1939
1956
  #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1940
1957
  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1958
+ #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1941
1959
 
1942
1960
 
1943
1961
  /*
@@ -5187,7 +5205,7 @@ SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *),
5187
5205
  ** ^The sqlite3_update_hook() interface registers a callback function
5188
5206
  ** with the [database connection] identified by the first argument
5189
5207
  ** to be invoked whenever a row is updated, inserted or deleted in
5190
- ** a rowid table.
5208
+ ** a [rowid table].
5191
5209
  ** ^Any callback set by a previous call to this function
5192
5210
  ** for the same database connection is overridden.
5193
5211
  **
@@ -5226,8 +5244,8 @@ SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *),
5226
5244
  ** on the same [database connection] D, or NULL for
5227
5245
  ** the first call on D.
5228
5246
  **
5229
- ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
5230
- ** interfaces.
5247
+ ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
5248
+ ** and [sqlite3_preupdate_hook()] interfaces.
5231
5249
  */
5232
5250
  SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
5233
5251
  sqlite3*,
@@ -5474,9 +5492,18 @@ SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
5474
5492
  ** should free this memory by calling [sqlite3_free()].
5475
5493
  **
5476
5494
  ** ^Extension loading must be enabled using
5477
- ** [sqlite3_enable_load_extension()] prior to calling this API,
5495
+ ** [sqlite3_enable_load_extension()] or
5496
+ ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5497
+ ** prior to calling this API,
5478
5498
  ** otherwise an error will be returned.
5479
5499
  **
5500
+ ** <b>Security warning:</b> It is recommended that the
5501
+ ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5502
+ ** interface. The use of the [sqlite3_enable_load_extension()] interface
5503
+ ** should be avoided. This will keep the SQL function [load_extension()]
5504
+ ** disabled and prevent SQL injections from giving attackers
5505
+ ** access to extension loading capabilities.
5506
+ **
5480
5507
  ** See also the [load_extension() SQL function].
5481
5508
  */
5482
5509
  SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
@@ -5499,6 +5526,17 @@ SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5499
5526
  ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5500
5527
  ** to turn extension loading on and call it with onoff==0 to turn
5501
5528
  ** it back off again.
5529
+ **
5530
+ ** ^This interface enables or disables both the C-API
5531
+ ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5532
+ ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5533
+ ** to enable or disable only the C-API.
5534
+ **
5535
+ ** <b>Security warning:</b> It is recommended that extension loading
5536
+ ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5537
+ ** rather than this interface, so the [load_extension()] SQL function
5538
+ ** remains disabled. This will prevent SQL injections from giving attackers
5539
+ ** access to extension loading capabilities.
5502
5540
  */
5503
5541
  SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5504
5542
 
@@ -7137,7 +7175,7 @@ typedef struct sqlite3_backup sqlite3_backup;
7137
7175
  ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
7138
7176
  ** an error.
7139
7177
  **
7140
- ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
7178
+ ** ^A call to sqlite3_backup_init() will fail, returning NULL, if
7141
7179
  ** there is already a read or read-write transaction open on the
7142
7180
  ** destination database.
7143
7181
  **
@@ -7915,11 +7953,107 @@ SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
7915
7953
  */
7916
7954
  SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*);
7917
7955
 
7956
+ /*
7957
+ ** CAPI3REF: The pre-update hook.
7958
+ **
7959
+ ** ^These interfaces are only available if SQLite is compiled using the
7960
+ ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
7961
+ **
7962
+ ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
7963
+ ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
7964
+ ** on a [rowid table].
7965
+ ** ^At most one preupdate hook may be registered at a time on a single
7966
+ ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
7967
+ ** the previous setting.
7968
+ ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
7969
+ ** with a NULL pointer as the second parameter.
7970
+ ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
7971
+ ** the first parameter to callbacks.
7972
+ **
7973
+ ** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
7974
+ ** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
7975
+ ** tables.
7976
+ **
7977
+ ** ^The second parameter to the preupdate callback is a pointer to
7978
+ ** the [database connection] that registered the preupdate hook.
7979
+ ** ^The third parameter to the preupdate callback is one of the constants
7980
+ ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to indentify the
7981
+ ** kind of update operation that is about to occur.
7982
+ ** ^(The fourth parameter to the preupdate callback is the name of the
7983
+ ** database within the database connection that is being modified. This
7984
+ ** will be "main" for the main database or "temp" for TEMP tables or
7985
+ ** the name given after the AS keyword in the [ATTACH] statement for attached
7986
+ ** databases.)^
7987
+ ** ^The fifth parameter to the preupdate callback is the name of the
7988
+ ** table that is being modified.
7989
+ ** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
7990
+ ** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
7991
+ ** undefined for SQLITE_INSERT changes.
7992
+ ** ^The seventh parameter to the preupdate callback is the final [rowid] of
7993
+ ** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
7994
+ ** undefined for SQLITE_DELETE changes.
7995
+ **
7996
+ ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
7997
+ ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
7998
+ ** provide additional information about a preupdate event. These routines
7999
+ ** may only be called from within a preupdate callback. Invoking any of
8000
+ ** these routines from outside of a preupdate callback or with a
8001
+ ** [database connection] pointer that is different from the one supplied
8002
+ ** to the preupdate callback results in undefined and probably undesirable
8003
+ ** behavior.
8004
+ **
8005
+ ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
8006
+ ** in the row that is being inserted, updated, or deleted.
8007
+ **
8008
+ ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
8009
+ ** a [protected sqlite3_value] that contains the value of the Nth column of
8010
+ ** the table row before it is updated. The N parameter must be between 0
8011
+ ** and one less than the number of columns or the behavior will be
8012
+ ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
8013
+ ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
8014
+ ** behavior is undefined. The [sqlite3_value] that P points to
8015
+ ** will be destroyed when the preupdate callback returns.
8016
+ **
8017
+ ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
8018
+ ** a [protected sqlite3_value] that contains the value of the Nth column of
8019
+ ** the table row after it is updated. The N parameter must be between 0
8020
+ ** and one less than the number of columns or the behavior will be
8021
+ ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
8022
+ ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
8023
+ ** behavior is undefined. The [sqlite3_value] that P points to
8024
+ ** will be destroyed when the preupdate callback returns.
8025
+ **
8026
+ ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
8027
+ ** callback was invoked as a result of a direct insert, update, or delete
8028
+ ** operation; or 1 for inserts, updates, or deletes invoked by top-level
8029
+ ** triggers; or 2 for changes resulting from triggers called by top-level
8030
+ ** triggers; and so forth.
8031
+ **
8032
+ ** See also: [sqlite3_update_hook()]
8033
+ */
8034
+ SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_preupdate_hook(
8035
+ sqlite3 *db,
8036
+ void(*xPreUpdate)(
8037
+ void *pCtx, /* Copy of third arg to preupdate_hook() */
8038
+ sqlite3 *db, /* Database handle */
8039
+ int op, /* SQLITE_UPDATE, DELETE or INSERT */
8040
+ char const *zDb, /* Database name */
8041
+ char const *zName, /* Table name */
8042
+ sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
8043
+ sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
8044
+ ),
8045
+ void*
8046
+ );
8047
+ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8048
+ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *);
8049
+ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *);
8050
+ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8051
+
7918
8052
  /*
7919
8053
  ** CAPI3REF: Low-level system error code
7920
8054
  **
7921
8055
  ** ^Attempt to return the underlying operating system error code or error
7922
- ** number that caused the most reason I/O error or failure to open a file.
8056
+ ** number that caused the most recent I/O error or failure to open a file.
7923
8057
  ** The return value is OS-dependent. For example, on unix systems, after
7924
8058
  ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
7925
8059
  ** called to get back the underlying "errno" that caused the problem, such
@@ -7985,20 +8119,29 @@ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get(
7985
8119
  ** CAPI3REF: Start a read transaction on an historical snapshot
7986
8120
  ** EXPERIMENTAL
7987
8121
  **
7988
- ** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
7989
- ** read transaction that is currently open on schema S of
7990
- ** [database connection] D so that it refers to historical [snapshot] P.
8122
+ ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8123
+ ** read transaction for schema S of
8124
+ ** [database connection] D such that the read transaction
8125
+ ** refers to historical [snapshot] P, rather than the most
8126
+ ** recent change to the database.
7991
8127
  ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
7992
8128
  ** or an appropriate [error code] if it fails.
7993
8129
  **
7994
8130
  ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
7995
- ** the first operation, apart from other sqlite3_snapshot_open() calls,
7996
- ** following the [BEGIN] that starts a new read transaction.
7997
- ** ^A [snapshot] will fail to open if it has been overwritten by a
8131
+ ** the first operation following the [BEGIN] that takes the schema S
8132
+ ** out of [autocommit mode].
8133
+ ** ^In other words, schema S must not currently be in
8134
+ ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8135
+ ** database connection D must be out of [autocommit mode].
8136
+ ** ^A [snapshot] will fail to open if it has been overwritten by a
7998
8137
  ** [checkpoint].
7999
- ** ^A [snapshot] will fail to open if the database connection D has not
8000
- ** previously completed at least one read operation against the database
8001
- ** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
8138
+ ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8139
+ ** database connection D does not know that the database file for
8140
+ ** schema S is in [WAL mode]. A database connection might not know
8141
+ ** that the database file is in [WAL mode] if there has been no prior
8142
+ ** I/O on that database connection, or if the database entered [WAL mode]
8143
+ ** after the most recent I/O on the database connection.)^
8144
+ ** (Hint: Run "[PRAGMA application_id]" against a newly opened
8002
8145
  ** database connection in order to make it ready to use snapshots.)
8003
8146
  **
8004
8147
  ** The [sqlite3_snapshot_open()] interface is only available when the
@@ -8023,6 +8166,33 @@ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open(
8023
8166
  */
8024
8167
  SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8025
8168
 
8169
+ /*
8170
+ ** CAPI3REF: Compare the ages of two snapshot handles.
8171
+ ** EXPERIMENTAL
8172
+ **
8173
+ ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8174
+ ** of two valid snapshot handles.
8175
+ **
8176
+ ** If the two snapshot handles are not associated with the same database
8177
+ ** file, the result of the comparison is undefined.
8178
+ **
8179
+ ** Additionally, the result of the comparison is only valid if both of the
8180
+ ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8181
+ ** last time the wal file was deleted. The wal file is deleted when the
8182
+ ** database is changed back to rollback mode or when the number of database
8183
+ ** clients drops to zero. If either snapshot handle was obtained before the
8184
+ ** wal file was last deleted, the value returned by this function
8185
+ ** is undefined.
8186
+ **
8187
+ ** Otherwise, this API returns a negative value if P1 refers to an older
8188
+ ** snapshot than P2, zero if the two handles refer to the same database
8189
+ ** snapshot, and a positive value if P1 is a newer snapshot than P2.
8190
+ */
8191
+ SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8192
+ sqlite3_snapshot *p1,
8193
+ sqlite3_snapshot *p2
8194
+ );
8195
+
8026
8196
  /*
8027
8197
  ** Undo the hack that converts floating point types to integer for
8028
8198
  ** builds on processors without floating point support.
@@ -8036,6 +8206,7 @@ SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3
8036
8206
  #endif
8037
8207
  #endif /* _SQLITE3_H_ */
8038
8208
 
8209
+ /******** Begin file sqlite3rtree.h *********/
8039
8210
  /*
8040
8211
  ** 2010 August 30
8041
8212
  **
@@ -8153,6 +8324,1287 @@ struct sqlite3_rtree_query_info {
8153
8324
 
8154
8325
  #endif /* ifndef _SQLITE3RTREE_H_ */
8155
8326
 
8327
+ /******** End of sqlite3rtree.h *********/
8328
+ /******** Begin file sqlite3session.h *********/
8329
+
8330
+ #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
8331
+ #define __SQLITESESSION_H_ 1
8332
+
8333
+ /*
8334
+ ** Make sure we can call this stuff from C++.
8335
+ */
8336
+ #ifdef __cplusplus
8337
+ extern "C" {
8338
+ #endif
8339
+
8340
+
8341
+ /*
8342
+ ** CAPI3REF: Session Object Handle
8343
+ */
8344
+ typedef struct sqlite3_session sqlite3_session;
8345
+
8346
+ /*
8347
+ ** CAPI3REF: Changeset Iterator Handle
8348
+ */
8349
+ typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
8350
+
8351
+ /*
8352
+ ** CAPI3REF: Create A New Session Object
8353
+ **
8354
+ ** Create a new session object attached to database handle db. If successful,
8355
+ ** a pointer to the new object is written to *ppSession and SQLITE_OK is
8356
+ ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
8357
+ ** error code (e.g. SQLITE_NOMEM) is returned.
8358
+ **
8359
+ ** It is possible to create multiple session objects attached to a single
8360
+ ** database handle.
8361
+ **
8362
+ ** Session objects created using this function should be deleted using the
8363
+ ** [sqlite3session_delete()] function before the database handle that they
8364
+ ** are attached to is itself closed. If the database handle is closed before
8365
+ ** the session object is deleted, then the results of calling any session
8366
+ ** module function, including [sqlite3session_delete()] on the session object
8367
+ ** are undefined.
8368
+ **
8369
+ ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
8370
+ ** is not possible for an application to register a pre-update hook on a
8371
+ ** database handle that has one or more session objects attached. Nor is
8372
+ ** it possible to create a session object attached to a database handle for
8373
+ ** which a pre-update hook is already defined. The results of attempting
8374
+ ** either of these things are undefined.
8375
+ **
8376
+ ** The session object will be used to create changesets for tables in
8377
+ ** database zDb, where zDb is either "main", or "temp", or the name of an
8378
+ ** attached database. It is not an error if database zDb is not attached
8379
+ ** to the database when the session object is created.
8380
+ */
8381
+ int sqlite3session_create(
8382
+ sqlite3 *db, /* Database handle */
8383
+ const char *zDb, /* Name of db (e.g. "main") */
8384
+ sqlite3_session **ppSession /* OUT: New session object */
8385
+ );
8386
+
8387
+ /*
8388
+ ** CAPI3REF: Delete A Session Object
8389
+ **
8390
+ ** Delete a session object previously allocated using
8391
+ ** [sqlite3session_create()]. Once a session object has been deleted, the
8392
+ ** results of attempting to use pSession with any other session module
8393
+ ** function are undefined.
8394
+ **
8395
+ ** Session objects must be deleted before the database handle to which they
8396
+ ** are attached is closed. Refer to the documentation for
8397
+ ** [sqlite3session_create()] for details.
8398
+ */
8399
+ void sqlite3session_delete(sqlite3_session *pSession);
8400
+
8401
+
8402
+ /*
8403
+ ** CAPI3REF: Enable Or Disable A Session Object
8404
+ **
8405
+ ** Enable or disable the recording of changes by a session object. When
8406
+ ** enabled, a session object records changes made to the database. When
8407
+ ** disabled - it does not. A newly created session object is enabled.
8408
+ ** Refer to the documentation for [sqlite3session_changeset()] for further
8409
+ ** details regarding how enabling and disabling a session object affects
8410
+ ** the eventual changesets.
8411
+ **
8412
+ ** Passing zero to this function disables the session. Passing a value
8413
+ ** greater than zero enables it. Passing a value less than zero is a
8414
+ ** no-op, and may be used to query the current state of the session.
8415
+ **
8416
+ ** The return value indicates the final state of the session object: 0 if
8417
+ ** the session is disabled, or 1 if it is enabled.
8418
+ */
8419
+ int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8420
+
8421
+ /*
8422
+ ** CAPI3REF: Set Or Clear the Indirect Change Flag
8423
+ **
8424
+ ** Each change recorded by a session object is marked as either direct or
8425
+ ** indirect. A change is marked as indirect if either:
8426
+ **
8427
+ ** <ul>
8428
+ ** <li> The session object "indirect" flag is set when the change is
8429
+ ** made, or
8430
+ ** <li> The change is made by an SQL trigger or foreign key action
8431
+ ** instead of directly as a result of a users SQL statement.
8432
+ ** </ul>
8433
+ **
8434
+ ** If a single row is affected by more than one operation within a session,
8435
+ ** then the change is considered indirect if all operations meet the criteria
8436
+ ** for an indirect change above, or direct otherwise.
8437
+ **
8438
+ ** This function is used to set, clear or query the session object indirect
8439
+ ** flag. If the second argument passed to this function is zero, then the
8440
+ ** indirect flag is cleared. If it is greater than zero, the indirect flag
8441
+ ** is set. Passing a value less than zero does not modify the current value
8442
+ ** of the indirect flag, and may be used to query the current state of the
8443
+ ** indirect flag for the specified session object.
8444
+ **
8445
+ ** The return value indicates the final state of the indirect flag: 0 if
8446
+ ** it is clear, or 1 if it is set.
8447
+ */
8448
+ int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8449
+
8450
+ /*
8451
+ ** CAPI3REF: Attach A Table To A Session Object
8452
+ **
8453
+ ** If argument zTab is not NULL, then it is the name of a table to attach
8454
+ ** to the session object passed as the first argument. All subsequent changes
8455
+ ** made to the table while the session object is enabled will be recorded. See
8456
+ ** documentation for [sqlite3session_changeset()] for further details.
8457
+ **
8458
+ ** Or, if argument zTab is NULL, then changes are recorded for all tables
8459
+ ** in the database. If additional tables are added to the database (by
8460
+ ** executing "CREATE TABLE" statements) after this call is made, changes for
8461
+ ** the new tables are also recorded.
8462
+ **
8463
+ ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
8464
+ ** defined as part of their CREATE TABLE statement. It does not matter if the
8465
+ ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
8466
+ ** KEY may consist of a single column, or may be a composite key.
8467
+ **
8468
+ ** It is not an error if the named table does not exist in the database. Nor
8469
+ ** is it an error if the named table does not have a PRIMARY KEY. However,
8470
+ ** no changes will be recorded in either of these scenarios.
8471
+ **
8472
+ ** Changes are not recorded for individual rows that have NULL values stored
8473
+ ** in one or more of their PRIMARY KEY columns.
8474
+ **
8475
+ ** SQLITE_OK is returned if the call completes without error. Or, if an error
8476
+ ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
8477
+ */
8478
+ int sqlite3session_attach(
8479
+ sqlite3_session *pSession, /* Session object */
8480
+ const char *zTab /* Table name */
8481
+ );
8482
+
8483
+ /*
8484
+ ** CAPI3REF: Set a table filter on a Session Object.
8485
+ **
8486
+ ** The second argument (xFilter) is the "filter callback". For changes to rows
8487
+ ** in tables that are not attached to the Session oject, the filter is called
8488
+ ** to determine whether changes to the table's rows should be tracked or not.
8489
+ ** If xFilter returns 0, changes is not tracked. Note that once a table is
8490
+ ** attached, xFilter will not be called again.
8491
+ */
8492
+ void sqlite3session_table_filter(
8493
+ sqlite3_session *pSession, /* Session object */
8494
+ int(*xFilter)(
8495
+ void *pCtx, /* Copy of third arg to _filter_table() */
8496
+ const char *zTab /* Table name */
8497
+ ),
8498
+ void *pCtx /* First argument passed to xFilter */
8499
+ );
8500
+
8501
+ /*
8502
+ ** CAPI3REF: Generate A Changeset From A Session Object
8503
+ **
8504
+ ** Obtain a changeset containing changes to the tables attached to the
8505
+ ** session object passed as the first argument. If successful,
8506
+ ** set *ppChangeset to point to a buffer containing the changeset
8507
+ ** and *pnChangeset to the size of the changeset in bytes before returning
8508
+ ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
8509
+ ** zero and return an SQLite error code.
8510
+ **
8511
+ ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
8512
+ ** each representing a change to a single row of an attached table. An INSERT
8513
+ ** change contains the values of each field of a new database row. A DELETE
8514
+ ** contains the original values of each field of a deleted database row. An
8515
+ ** UPDATE change contains the original values of each field of an updated
8516
+ ** database row along with the updated values for each updated non-primary-key
8517
+ ** column. It is not possible for an UPDATE change to represent a change that
8518
+ ** modifies the values of primary key columns. If such a change is made, it
8519
+ ** is represented in a changeset as a DELETE followed by an INSERT.
8520
+ **
8521
+ ** Changes are not recorded for rows that have NULL values stored in one or
8522
+ ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
8523
+ ** no corresponding change is present in the changesets returned by this
8524
+ ** function. If an existing row with one or more NULL values stored in
8525
+ ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
8526
+ ** only an INSERT is appears in the changeset. Similarly, if an existing row
8527
+ ** with non-NULL PRIMARY KEY values is updated so that one or more of its
8528
+ ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
8529
+ ** DELETE change only.
8530
+ **
8531
+ ** The contents of a changeset may be traversed using an iterator created
8532
+ ** using the [sqlite3changeset_start()] API. A changeset may be applied to
8533
+ ** a database with a compatible schema using the [sqlite3changeset_apply()]
8534
+ ** API.
8535
+ **
8536
+ ** Within a changeset generated by this function, all changes related to a
8537
+ ** single table are grouped together. In other words, when iterating through
8538
+ ** a changeset or when applying a changeset to a database, all changes related
8539
+ ** to a single table are processed before moving on to the next table. Tables
8540
+ ** are sorted in the same order in which they were attached (or auto-attached)
8541
+ ** to the sqlite3_session object. The order in which the changes related to
8542
+ ** a single table are stored is undefined.
8543
+ **
8544
+ ** Following a successful call to this function, it is the responsibility of
8545
+ ** the caller to eventually free the buffer that *ppChangeset points to using
8546
+ ** [sqlite3_free()].
8547
+ **
8548
+ ** <h3>Changeset Generation</h3>
8549
+ **
8550
+ ** Once a table has been attached to a session object, the session object
8551
+ ** records the primary key values of all new rows inserted into the table.
8552
+ ** It also records the original primary key and other column values of any
8553
+ ** deleted or updated rows. For each unique primary key value, data is only
8554
+ ** recorded once - the first time a row with said primary key is inserted,
8555
+ ** updated or deleted in the lifetime of the session.
8556
+ **
8557
+ ** There is one exception to the previous paragraph: when a row is inserted,
8558
+ ** updated or deleted, if one or more of its primary key columns contain a
8559
+ ** NULL value, no record of the change is made.
8560
+ **
8561
+ ** The session object therefore accumulates two types of records - those
8562
+ ** that consist of primary key values only (created when the user inserts
8563
+ ** a new record) and those that consist of the primary key values and the
8564
+ ** original values of other table columns (created when the users deletes
8565
+ ** or updates a record).
8566
+ **
8567
+ ** When this function is called, the requested changeset is created using
8568
+ ** both the accumulated records and the current contents of the database
8569
+ ** file. Specifically:
8570
+ **
8571
+ ** <ul>
8572
+ ** <li> For each record generated by an insert, the database is queried
8573
+ ** for a row with a matching primary key. If one is found, an INSERT
8574
+ ** change is added to the changeset. If no such row is found, no change
8575
+ ** is added to the changeset.
8576
+ **
8577
+ ** <li> For each record generated by an update or delete, the database is
8578
+ ** queried for a row with a matching primary key. If such a row is
8579
+ ** found and one or more of the non-primary key fields have been
8580
+ ** modified from their original values, an UPDATE change is added to
8581
+ ** the changeset. Or, if no such row is found in the table, a DELETE
8582
+ ** change is added to the changeset. If there is a row with a matching
8583
+ ** primary key in the database, but all fields contain their original
8584
+ ** values, no change is added to the changeset.
8585
+ ** </ul>
8586
+ **
8587
+ ** This means, amongst other things, that if a row is inserted and then later
8588
+ ** deleted while a session object is active, neither the insert nor the delete
8589
+ ** will be present in the changeset. Or if a row is deleted and then later a
8590
+ ** row with the same primary key values inserted while a session object is
8591
+ ** active, the resulting changeset will contain an UPDATE change instead of
8592
+ ** a DELETE and an INSERT.
8593
+ **
8594
+ ** When a session object is disabled (see the [sqlite3session_enable()] API),
8595
+ ** it does not accumulate records when rows are inserted, updated or deleted.
8596
+ ** This may appear to have some counter-intuitive effects if a single row
8597
+ ** is written to more than once during a session. For example, if a row
8598
+ ** is inserted while a session object is enabled, then later deleted while
8599
+ ** the same session object is disabled, no INSERT record will appear in the
8600
+ ** changeset, even though the delete took place while the session was disabled.
8601
+ ** Or, if one field of a row is updated while a session is disabled, and
8602
+ ** another field of the same row is updated while the session is enabled, the
8603
+ ** resulting changeset will contain an UPDATE change that updates both fields.
8604
+ */
8605
+ int sqlite3session_changeset(
8606
+ sqlite3_session *pSession, /* Session object */
8607
+ int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
8608
+ void **ppChangeset /* OUT: Buffer containing changeset */
8609
+ );
8610
+
8611
+ /*
8612
+ ** CAPI3REF: Load The Difference Between Tables Into A Session
8613
+ **
8614
+ ** If it is not already attached to the session object passed as the first
8615
+ ** argument, this function attaches table zTbl in the same manner as the
8616
+ ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
8617
+ ** does not have a primary key, this function is a no-op (but does not return
8618
+ ** an error).
8619
+ **
8620
+ ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
8621
+ ** attached to the same database handle as the session object that contains
8622
+ ** a table compatible with the table attached to the session by this function.
8623
+ ** A table is considered compatible if it:
8624
+ **
8625
+ ** <ul>
8626
+ ** <li> Has the same name,
8627
+ ** <li> Has the same set of columns declared in the same order, and
8628
+ ** <li> Has the same PRIMARY KEY definition.
8629
+ ** </ul>
8630
+ **
8631
+ ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
8632
+ ** are compatible but do not have any PRIMARY KEY columns, it is not an error
8633
+ ** but no changes are added to the session object. As with other session
8634
+ ** APIs, tables without PRIMARY KEYs are simply ignored.
8635
+ **
8636
+ ** This function adds a set of changes to the session object that could be
8637
+ ** used to update the table in database zFrom (call this the "from-table")
8638
+ ** so that its content is the same as the table attached to the session
8639
+ ** object (call this the "to-table"). Specifically:
8640
+ **
8641
+ ** <ul>
8642
+ ** <li> For each row (primary key) that exists in the to-table but not in
8643
+ ** the from-table, an INSERT record is added to the session object.
8644
+ **
8645
+ ** <li> For each row (primary key) that exists in the to-table but not in
8646
+ ** the from-table, a DELETE record is added to the session object.
8647
+ **
8648
+ ** <li> For each row (primary key) that exists in both tables, but features
8649
+ ** different in each, an UPDATE record is added to the session.
8650
+ ** </ul>
8651
+ **
8652
+ ** To clarify, if this function is called and then a changeset constructed
8653
+ ** using [sqlite3session_changeset()], then after applying that changeset to
8654
+ ** database zFrom the contents of the two compatible tables would be
8655
+ ** identical.
8656
+ **
8657
+ ** It an error if database zFrom does not exist or does not contain the
8658
+ ** required compatible table.
8659
+ **
8660
+ ** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
8661
+ ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
8662
+ ** may be set to point to a buffer containing an English language error
8663
+ ** message. It is the responsibility of the caller to free this buffer using
8664
+ ** sqlite3_free().
8665
+ */
8666
+ int sqlite3session_diff(
8667
+ sqlite3_session *pSession,
8668
+ const char *zFromDb,
8669
+ const char *zTbl,
8670
+ char **pzErrMsg
8671
+ );
8672
+
8673
+
8674
+ /*
8675
+ ** CAPI3REF: Generate A Patchset From A Session Object
8676
+ **
8677
+ ** The differences between a patchset and a changeset are that:
8678
+ **
8679
+ ** <ul>
8680
+ ** <li> DELETE records consist of the primary key fields only. The
8681
+ ** original values of other fields are omitted.
8682
+ ** <li> The original values of any modified fields are omitted from
8683
+ ** UPDATE records.
8684
+ ** </ul>
8685
+ **
8686
+ ** A patchset blob may be used with up to date versions of all
8687
+ ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
8688
+ ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
8689
+ ** attempting to use a patchset blob with old versions of the
8690
+ ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
8691
+ **
8692
+ ** Because the non-primary key "old.*" fields are omitted, no
8693
+ ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
8694
+ ** is passed to the sqlite3changeset_apply() API. Other conflict types work
8695
+ ** in the same way as for changesets.
8696
+ **
8697
+ ** Changes within a patchset are ordered in the same way as for changesets
8698
+ ** generated by the sqlite3session_changeset() function (i.e. all changes for
8699
+ ** a single table are grouped together, tables appear in the order in which
8700
+ ** they were attached to the session object).
8701
+ */
8702
+ int sqlite3session_patchset(
8703
+ sqlite3_session *pSession, /* Session object */
8704
+ int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
8705
+ void **ppPatchset /* OUT: Buffer containing changeset */
8706
+ );
8707
+
8708
+ /*
8709
+ ** CAPI3REF: Test if a changeset has recorded any changes.
8710
+ **
8711
+ ** Return non-zero if no changes to attached tables have been recorded by
8712
+ ** the session object passed as the first argument. Otherwise, if one or
8713
+ ** more changes have been recorded, return zero.
8714
+ **
8715
+ ** Even if this function returns zero, it is possible that calling
8716
+ ** [sqlite3session_changeset()] on the session handle may still return a
8717
+ ** changeset that contains no changes. This can happen when a row in
8718
+ ** an attached table is modified and then later on the original values
8719
+ ** are restored. However, if this function returns non-zero, then it is
8720
+ ** guaranteed that a call to sqlite3session_changeset() will return a
8721
+ ** changeset containing zero changes.
8722
+ */
8723
+ int sqlite3session_isempty(sqlite3_session *pSession);
8724
+
8725
+ /*
8726
+ ** CAPI3REF: Create An Iterator To Traverse A Changeset
8727
+ **
8728
+ ** Create an iterator used to iterate through the contents of a changeset.
8729
+ ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
8730
+ ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
8731
+ ** SQLite error code is returned.
8732
+ **
8733
+ ** The following functions can be used to advance and query a changeset
8734
+ ** iterator created by this function:
8735
+ **
8736
+ ** <ul>
8737
+ ** <li> [sqlite3changeset_next()]
8738
+ ** <li> [sqlite3changeset_op()]
8739
+ ** <li> [sqlite3changeset_new()]
8740
+ ** <li> [sqlite3changeset_old()]
8741
+ ** </ul>
8742
+ **
8743
+ ** It is the responsibility of the caller to eventually destroy the iterator
8744
+ ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
8745
+ ** changeset (pChangeset) must remain valid until after the iterator is
8746
+ ** destroyed.
8747
+ **
8748
+ ** Assuming the changeset blob was created by one of the
8749
+ ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
8750
+ ** [sqlite3changeset_invert()] functions, all changes within the changeset
8751
+ ** that apply to a single table are grouped together. This means that when
8752
+ ** an application iterates through a changeset using an iterator created by
8753
+ ** this function, all changes that relate to a single table are visted
8754
+ ** consecutively. There is no chance that the iterator will visit a change
8755
+ ** the applies to table X, then one for table Y, and then later on visit
8756
+ ** another change for table X.
8757
+ */
8758
+ int sqlite3changeset_start(
8759
+ sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
8760
+ int nChangeset, /* Size of changeset blob in bytes */
8761
+ void *pChangeset /* Pointer to blob containing changeset */
8762
+ );
8763
+
8764
+
8765
+ /*
8766
+ ** CAPI3REF: Advance A Changeset Iterator
8767
+ **
8768
+ ** This function may only be used with iterators created by function
8769
+ ** [sqlite3changeset_start()]. If it is called on an iterator passed to
8770
+ ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
8771
+ ** is returned and the call has no effect.
8772
+ **
8773
+ ** Immediately after an iterator is created by sqlite3changeset_start(), it
8774
+ ** does not point to any change in the changeset. Assuming the changeset
8775
+ ** is not empty, the first call to this function advances the iterator to
8776
+ ** point to the first change in the changeset. Each subsequent call advances
8777
+ ** the iterator to point to the next change in the changeset (if any). If
8778
+ ** no error occurs and the iterator points to a valid change after a call
8779
+ ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
8780
+ ** Otherwise, if all changes in the changeset have already been visited,
8781
+ ** SQLITE_DONE is returned.
8782
+ **
8783
+ ** If an error occurs, an SQLite error code is returned. Possible error
8784
+ ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
8785
+ ** SQLITE_NOMEM.
8786
+ */
8787
+ int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
8788
+
8789
+ /*
8790
+ ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
8791
+ **
8792
+ ** The pIter argument passed to this function may either be an iterator
8793
+ ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
8794
+ ** created by [sqlite3changeset_start()]. In the latter case, the most recent
8795
+ ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
8796
+ ** is not the case, this function returns [SQLITE_MISUSE].
8797
+ **
8798
+ ** If argument pzTab is not NULL, then *pzTab is set to point to a
8799
+ ** nul-terminated utf-8 encoded string containing the name of the table
8800
+ ** affected by the current change. The buffer remains valid until either
8801
+ ** sqlite3changeset_next() is called on the iterator or until the
8802
+ ** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
8803
+ ** set to the number of columns in the table affected by the change. If
8804
+ ** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change
8805
+ ** is an indirect change, or false (0) otherwise. See the documentation for
8806
+ ** [sqlite3session_indirect()] for a description of direct and indirect
8807
+ ** changes. Finally, if pOp is not NULL, then *pOp is set to one of
8808
+ ** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
8809
+ ** type of change that the iterator currently points to.
8810
+ **
8811
+ ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
8812
+ ** SQLite error code is returned. The values of the output variables may not
8813
+ ** be trusted in this case.
8814
+ */
8815
+ int sqlite3changeset_op(
8816
+ sqlite3_changeset_iter *pIter, /* Iterator object */
8817
+ const char **pzTab, /* OUT: Pointer to table name */
8818
+ int *pnCol, /* OUT: Number of columns in table */
8819
+ int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
8820
+ int *pbIndirect /* OUT: True for an 'indirect' change */
8821
+ );
8822
+
8823
+ /*
8824
+ ** CAPI3REF: Obtain The Primary Key Definition Of A Table
8825
+ **
8826
+ ** For each modified table, a changeset includes the following:
8827
+ **
8828
+ ** <ul>
8829
+ ** <li> The number of columns in the table, and
8830
+ ** <li> Which of those columns make up the tables PRIMARY KEY.
8831
+ ** </ul>
8832
+ **
8833
+ ** This function is used to find which columns comprise the PRIMARY KEY of
8834
+ ** the table modified by the change that iterator pIter currently points to.
8835
+ ** If successful, *pabPK is set to point to an array of nCol entries, where
8836
+ ** nCol is the number of columns in the table. Elements of *pabPK are set to
8837
+ ** 0x01 if the corresponding column is part of the tables primary key, or
8838
+ ** 0x00 if it is not.
8839
+ **
8840
+ ** If argumet pnCol is not NULL, then *pnCol is set to the number of columns
8841
+ ** in the table.
8842
+ **
8843
+ ** If this function is called when the iterator does not point to a valid
8844
+ ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
8845
+ ** SQLITE_OK is returned and the output variables populated as described
8846
+ ** above.
8847
+ */
8848
+ int sqlite3changeset_pk(
8849
+ sqlite3_changeset_iter *pIter, /* Iterator object */
8850
+ unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
8851
+ int *pnCol /* OUT: Number of entries in output array */
8852
+ );
8853
+
8854
+ /*
8855
+ ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
8856
+ **
8857
+ ** The pIter argument passed to this function may either be an iterator
8858
+ ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
8859
+ ** created by [sqlite3changeset_start()]. In the latter case, the most recent
8860
+ ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
8861
+ ** Furthermore, it may only be called if the type of change that the iterator
8862
+ ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
8863
+ ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
8864
+ **
8865
+ ** Argument iVal must be greater than or equal to 0, and less than the number
8866
+ ** of columns in the table affected by the current change. Otherwise,
8867
+ ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
8868
+ **
8869
+ ** If successful, this function sets *ppValue to point to a protected
8870
+ ** sqlite3_value object containing the iVal'th value from the vector of
8871
+ ** original row values stored as part of the UPDATE or DELETE change and
8872
+ ** returns SQLITE_OK. The name of the function comes from the fact that this
8873
+ ** is similar to the "old.*" columns available to update or delete triggers.
8874
+ **
8875
+ ** If some other error occurs (e.g. an OOM condition), an SQLite error code
8876
+ ** is returned and *ppValue is set to NULL.
8877
+ */
8878
+ int sqlite3changeset_old(
8879
+ sqlite3_changeset_iter *pIter, /* Changeset iterator */
8880
+ int iVal, /* Column number */
8881
+ sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
8882
+ );
8883
+
8884
+ /*
8885
+ ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
8886
+ **
8887
+ ** The pIter argument passed to this function may either be an iterator
8888
+ ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
8889
+ ** created by [sqlite3changeset_start()]. In the latter case, the most recent
8890
+ ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
8891
+ ** Furthermore, it may only be called if the type of change that the iterator
8892
+ ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
8893
+ ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
8894
+ **
8895
+ ** Argument iVal must be greater than or equal to 0, and less than the number
8896
+ ** of columns in the table affected by the current change. Otherwise,
8897
+ ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
8898
+ **
8899
+ ** If successful, this function sets *ppValue to point to a protected
8900
+ ** sqlite3_value object containing the iVal'th value from the vector of
8901
+ ** new row values stored as part of the UPDATE or INSERT change and
8902
+ ** returns SQLITE_OK. If the change is an UPDATE and does not include
8903
+ ** a new value for the requested column, *ppValue is set to NULL and
8904
+ ** SQLITE_OK returned. The name of the function comes from the fact that
8905
+ ** this is similar to the "new.*" columns available to update or delete
8906
+ ** triggers.
8907
+ **
8908
+ ** If some other error occurs (e.g. an OOM condition), an SQLite error code
8909
+ ** is returned and *ppValue is set to NULL.
8910
+ */
8911
+ int sqlite3changeset_new(
8912
+ sqlite3_changeset_iter *pIter, /* Changeset iterator */
8913
+ int iVal, /* Column number */
8914
+ sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
8915
+ );
8916
+
8917
+ /*
8918
+ ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
8919
+ **
8920
+ ** This function should only be used with iterator objects passed to a
8921
+ ** conflict-handler callback by [sqlite3changeset_apply()] with either
8922
+ ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
8923
+ ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
8924
+ ** is set to NULL.
8925
+ **
8926
+ ** Argument iVal must be greater than or equal to 0, and less than the number
8927
+ ** of columns in the table affected by the current change. Otherwise,
8928
+ ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
8929
+ **
8930
+ ** If successful, this function sets *ppValue to point to a protected
8931
+ ** sqlite3_value object containing the iVal'th value from the
8932
+ ** "conflicting row" associated with the current conflict-handler callback
8933
+ ** and returns SQLITE_OK.
8934
+ **
8935
+ ** If some other error occurs (e.g. an OOM condition), an SQLite error code
8936
+ ** is returned and *ppValue is set to NULL.
8937
+ */
8938
+ int sqlite3changeset_conflict(
8939
+ sqlite3_changeset_iter *pIter, /* Changeset iterator */
8940
+ int iVal, /* Column number */
8941
+ sqlite3_value **ppValue /* OUT: Value from conflicting row */
8942
+ );
8943
+
8944
+ /*
8945
+ ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
8946
+ **
8947
+ ** This function may only be called with an iterator passed to an
8948
+ ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
8949
+ ** it sets the output variable to the total number of known foreign key
8950
+ ** violations in the destination database and returns SQLITE_OK.
8951
+ **
8952
+ ** In all other cases this function returns SQLITE_MISUSE.
8953
+ */
8954
+ int sqlite3changeset_fk_conflicts(
8955
+ sqlite3_changeset_iter *pIter, /* Changeset iterator */
8956
+ int *pnOut /* OUT: Number of FK violations */
8957
+ );
8958
+
8959
+
8960
+ /*
8961
+ ** CAPI3REF: Finalize A Changeset Iterator
8962
+ **
8963
+ ** This function is used to finalize an iterator allocated with
8964
+ ** [sqlite3changeset_start()].
8965
+ **
8966
+ ** This function should only be called on iterators created using the
8967
+ ** [sqlite3changeset_start()] function. If an application calls this
8968
+ ** function with an iterator passed to a conflict-handler by
8969
+ ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
8970
+ ** call has no effect.
8971
+ **
8972
+ ** If an error was encountered within a call to an sqlite3changeset_xxx()
8973
+ ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
8974
+ ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
8975
+ ** to that error is returned by this function. Otherwise, SQLITE_OK is
8976
+ ** returned. This is to allow the following pattern (pseudo-code):
8977
+ **
8978
+ ** sqlite3changeset_start();
8979
+ ** while( SQLITE_ROW==sqlite3changeset_next() ){
8980
+ ** // Do something with change.
8981
+ ** }
8982
+ ** rc = sqlite3changeset_finalize();
8983
+ ** if( rc!=SQLITE_OK ){
8984
+ ** // An error has occurred
8985
+ ** }
8986
+ */
8987
+ int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
8988
+
8989
+ /*
8990
+ ** CAPI3REF: Invert A Changeset
8991
+ **
8992
+ ** This function is used to "invert" a changeset object. Applying an inverted
8993
+ ** changeset to a database reverses the effects of applying the uninverted
8994
+ ** changeset. Specifically:
8995
+ **
8996
+ ** <ul>
8997
+ ** <li> Each DELETE change is changed to an INSERT, and
8998
+ ** <li> Each INSERT change is changed to a DELETE, and
8999
+ ** <li> For each UPDATE change, the old.* and new.* values are exchanged.
9000
+ ** </ul>
9001
+ **
9002
+ ** This function does not change the order in which changes appear within
9003
+ ** the changeset. It merely reverses the sense of each individual change.
9004
+ **
9005
+ ** If successful, a pointer to a buffer containing the inverted changeset
9006
+ ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
9007
+ ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
9008
+ ** zeroed and an SQLite error code returned.
9009
+ **
9010
+ ** It is the responsibility of the caller to eventually call sqlite3_free()
9011
+ ** on the *ppOut pointer to free the buffer allocation following a successful
9012
+ ** call to this function.
9013
+ **
9014
+ ** WARNING/TODO: This function currently assumes that the input is a valid
9015
+ ** changeset. If it is not, the results are undefined.
9016
+ */
9017
+ int sqlite3changeset_invert(
9018
+ int nIn, const void *pIn, /* Input changeset */
9019
+ int *pnOut, void **ppOut /* OUT: Inverse of input */
9020
+ );
9021
+
9022
+ /*
9023
+ ** CAPI3REF: Concatenate Two Changeset Objects
9024
+ **
9025
+ ** This function is used to concatenate two changesets, A and B, into a
9026
+ ** single changeset. The result is a changeset equivalent to applying
9027
+ ** changeset A followed by changeset B.
9028
+ **
9029
+ ** This function combines the two input changesets using an
9030
+ ** sqlite3_changegroup object. Calling it produces similar results as the
9031
+ ** following code fragment:
9032
+ **
9033
+ ** sqlite3_changegroup *pGrp;
9034
+ ** rc = sqlite3_changegroup_new(&pGrp);
9035
+ ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
9036
+ ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
9037
+ ** if( rc==SQLITE_OK ){
9038
+ ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
9039
+ ** }else{
9040
+ ** *ppOut = 0;
9041
+ ** *pnOut = 0;
9042
+ ** }
9043
+ **
9044
+ ** Refer to the sqlite3_changegroup documentation below for details.
9045
+ */
9046
+ int sqlite3changeset_concat(
9047
+ int nA, /* Number of bytes in buffer pA */
9048
+ void *pA, /* Pointer to buffer containing changeset A */
9049
+ int nB, /* Number of bytes in buffer pB */
9050
+ void *pB, /* Pointer to buffer containing changeset B */
9051
+ int *pnOut, /* OUT: Number of bytes in output changeset */
9052
+ void **ppOut /* OUT: Buffer containing output changeset */
9053
+ );
9054
+
9055
+
9056
+ /*
9057
+ ** Changegroup handle.
9058
+ */
9059
+ typedef struct sqlite3_changegroup sqlite3_changegroup;
9060
+
9061
+ /*
9062
+ ** CAPI3REF: Combine two or more changesets into a single changeset.
9063
+ **
9064
+ ** An sqlite3_changegroup object is used to combine two or more changesets
9065
+ ** (or patchsets) into a single changeset (or patchset). A single changegroup
9066
+ ** object may combine changesets or patchsets, but not both. The output is
9067
+ ** always in the same format as the input.
9068
+ **
9069
+ ** If successful, this function returns SQLITE_OK and populates (*pp) with
9070
+ ** a pointer to a new sqlite3_changegroup object before returning. The caller
9071
+ ** should eventually free the returned object using a call to
9072
+ ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
9073
+ ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
9074
+ **
9075
+ ** The usual usage pattern for an sqlite3_changegroup object is as follows:
9076
+ **
9077
+ ** <ul>
9078
+ ** <li> It is created using a call to sqlite3changegroup_new().
9079
+ **
9080
+ ** <li> Zero or more changesets (or patchsets) are added to the object
9081
+ ** by calling sqlite3changegroup_add().
9082
+ **
9083
+ ** <li> The result of combining all input changesets together is obtained
9084
+ ** by the application via a call to sqlite3changegroup_output().
9085
+ **
9086
+ ** <li> The object is deleted using a call to sqlite3changegroup_delete().
9087
+ ** </ul>
9088
+ **
9089
+ ** Any number of calls to add() and output() may be made between the calls to
9090
+ ** new() and delete(), and in any order.
9091
+ **
9092
+ ** As well as the regular sqlite3changegroup_add() and
9093
+ ** sqlite3changegroup_output() functions, also available are the streaming
9094
+ ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
9095
+ */
9096
+ int sqlite3changegroup_new(sqlite3_changegroup **pp);
9097
+
9098
+ /*
9099
+ ** Add all changes within the changeset (or patchset) in buffer pData (size
9100
+ ** nData bytes) to the changegroup.
9101
+ **
9102
+ ** If the buffer contains a patchset, then all prior calls to this function
9103
+ ** on the same changegroup object must also have specified patchsets. Or, if
9104
+ ** the buffer contains a changeset, so must have the earlier calls to this
9105
+ ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
9106
+ ** to the changegroup.
9107
+ **
9108
+ ** Rows within the changeset and changegroup are identified by the values in
9109
+ ** their PRIMARY KEY columns. A change in the changeset is considered to
9110
+ ** apply to the same row as a change already present in the changegroup if
9111
+ ** the two rows have the same primary key.
9112
+ **
9113
+ ** Changes to rows that that do not already appear in the changegroup are
9114
+ ** simply copied into it. Or, if both the new changeset and the changegroup
9115
+ ** contain changes that apply to a single row, the final contents of the
9116
+ ** changegroup depends on the type of each change, as follows:
9117
+ **
9118
+ ** <table border=1 style="margin-left:8ex;margin-right:8ex">
9119
+ ** <tr><th style="white-space:pre">Existing Change </th>
9120
+ ** <th style="white-space:pre">New Change </th>
9121
+ ** <th>Output Change
9122
+ ** <tr><td>INSERT <td>INSERT <td>
9123
+ ** The new change is ignored. This case does not occur if the new
9124
+ ** changeset was recorded immediately after the changesets already
9125
+ ** added to the changegroup.
9126
+ ** <tr><td>INSERT <td>UPDATE <td>
9127
+ ** The INSERT change remains in the changegroup. The values in the
9128
+ ** INSERT change are modified as if the row was inserted by the
9129
+ ** existing change and then updated according to the new change.
9130
+ ** <tr><td>INSERT <td>DELETE <td>
9131
+ ** The existing INSERT is removed from the changegroup. The DELETE is
9132
+ ** not added.
9133
+ ** <tr><td>UPDATE <td>INSERT <td>
9134
+ ** The new change is ignored. This case does not occur if the new
9135
+ ** changeset was recorded immediately after the changesets already
9136
+ ** added to the changegroup.
9137
+ ** <tr><td>UPDATE <td>UPDATE <td>
9138
+ ** The existing UPDATE remains within the changegroup. It is amended
9139
+ ** so that the accompanying values are as if the row was updated once
9140
+ ** by the existing change and then again by the new change.
9141
+ ** <tr><td>UPDATE <td>DELETE <td>
9142
+ ** The existing UPDATE is replaced by the new DELETE within the
9143
+ ** changegroup.
9144
+ ** <tr><td>DELETE <td>INSERT <td>
9145
+ ** If one or more of the column values in the row inserted by the
9146
+ ** new change differ from those in the row deleted by the existing
9147
+ ** change, the existing DELETE is replaced by an UPDATE within the
9148
+ ** changegroup. Otherwise, if the inserted row is exactly the same
9149
+ ** as the deleted row, the existing DELETE is simply discarded.
9150
+ ** <tr><td>DELETE <td>UPDATE <td>
9151
+ ** The new change is ignored. This case does not occur if the new
9152
+ ** changeset was recorded immediately after the changesets already
9153
+ ** added to the changegroup.
9154
+ ** <tr><td>DELETE <td>DELETE <td>
9155
+ ** The new change is ignored. This case does not occur if the new
9156
+ ** changeset was recorded immediately after the changesets already
9157
+ ** added to the changegroup.
9158
+ ** </table>
9159
+ **
9160
+ ** If the new changeset contains changes to a table that is already present
9161
+ ** in the changegroup, then the number of columns and the position of the
9162
+ ** primary key columns for the table must be consistent. If this is not the
9163
+ ** case, this function fails with SQLITE_SCHEMA. If the input changeset
9164
+ ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
9165
+ ** returned. Or, if an out-of-memory condition occurs during processing, this
9166
+ ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9167
+ ** final contents of the changegroup is undefined.
9168
+ **
9169
+ ** If no error occurs, SQLITE_OK is returned.
9170
+ */
9171
+ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9172
+
9173
+ /*
9174
+ ** Obtain a buffer containing a changeset (or patchset) representing the
9175
+ ** current contents of the changegroup. If the inputs to the changegroup
9176
+ ** were themselves changesets, the output is a changeset. Or, if the
9177
+ ** inputs were patchsets, the output is also a patchset.
9178
+ **
9179
+ ** As with the output of the sqlite3session_changeset() and
9180
+ ** sqlite3session_patchset() functions, all changes related to a single
9181
+ ** table are grouped together in the output of this function. Tables appear
9182
+ ** in the same order as for the very first changeset added to the changegroup.
9183
+ ** If the second or subsequent changesets added to the changegroup contain
9184
+ ** changes for tables that do not appear in the first changeset, they are
9185
+ ** appended onto the end of the output changeset, again in the order in
9186
+ ** which they are first encountered.
9187
+ **
9188
+ ** If an error occurs, an SQLite error code is returned and the output
9189
+ ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
9190
+ ** is returned and the output variables are set to the size of and a
9191
+ ** pointer to the output buffer, respectively. In this case it is the
9192
+ ** responsibility of the caller to eventually free the buffer using a
9193
+ ** call to sqlite3_free().
9194
+ */
9195
+ int sqlite3changegroup_output(
9196
+ sqlite3_changegroup*,
9197
+ int *pnData, /* OUT: Size of output buffer in bytes */
9198
+ void **ppData /* OUT: Pointer to output buffer */
9199
+ );
9200
+
9201
+ /*
9202
+ ** Delete a changegroup object.
9203
+ */
9204
+ void sqlite3changegroup_delete(sqlite3_changegroup*);
9205
+
9206
+ /*
9207
+ ** CAPI3REF: Apply A Changeset To A Database
9208
+ **
9209
+ ** Apply a changeset to a database. This function attempts to update the
9210
+ ** "main" database attached to handle db with the changes found in the
9211
+ ** changeset passed via the second and third arguments.
9212
+ **
9213
+ ** The fourth argument (xFilter) passed to this function is the "filter
9214
+ ** callback". If it is not NULL, then for each table affected by at least one
9215
+ ** change in the changeset, the filter callback is invoked with
9216
+ ** the table name as the second argument, and a copy of the context pointer
9217
+ ** passed as the sixth argument to this function as the first. If the "filter
9218
+ ** callback" returns zero, then no attempt is made to apply any changes to
9219
+ ** the table. Otherwise, if the return value is non-zero or the xFilter
9220
+ ** argument to this function is NULL, all changes related to the table are
9221
+ ** attempted.
9222
+ **
9223
+ ** For each table that is not excluded by the filter callback, this function
9224
+ ** tests that the target database contains a compatible table. A table is
9225
+ ** considered compatible if all of the following are true:
9226
+ **
9227
+ ** <ul>
9228
+ ** <li> The table has the same name as the name recorded in the
9229
+ ** changeset, and
9230
+ ** <li> The table has the same number of columns as recorded in the
9231
+ ** changeset, and
9232
+ ** <li> The table has primary key columns in the same position as
9233
+ ** recorded in the changeset.
9234
+ ** </ul>
9235
+ **
9236
+ ** If there is no compatible table, it is not an error, but none of the
9237
+ ** changes associated with the table are applied. A warning message is issued
9238
+ ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
9239
+ ** one such warning is issued for each table in the changeset.
9240
+ **
9241
+ ** For each change for which there is a compatible table, an attempt is made
9242
+ ** to modify the table contents according to the UPDATE, INSERT or DELETE
9243
+ ** change. If a change cannot be applied cleanly, the conflict handler
9244
+ ** function passed as the fifth argument to sqlite3changeset_apply() may be
9245
+ ** invoked. A description of exactly when the conflict handler is invoked for
9246
+ ** each type of change is below.
9247
+ **
9248
+ ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
9249
+ ** of passing anything other than a valid function pointer as the xConflict
9250
+ ** argument are undefined.
9251
+ **
9252
+ ** Each time the conflict handler function is invoked, it must return one
9253
+ ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
9254
+ ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
9255
+ ** if the second argument passed to the conflict handler is either
9256
+ ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
9257
+ ** returns an illegal value, any changes already made are rolled back and
9258
+ ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
9259
+ ** actions are taken by sqlite3changeset_apply() depending on the value
9260
+ ** returned by each invocation of the conflict-handler function. Refer to
9261
+ ** the documentation for the three
9262
+ ** [SQLITE_CHANGESET_OMIT|available return values] for details.
9263
+ **
9264
+ ** <dl>
9265
+ ** <dt>DELETE Changes<dd>
9266
+ ** For each DELETE change, this function checks if the target database
9267
+ ** contains a row with the same primary key value (or values) as the
9268
+ ** original row values stored in the changeset. If it does, and the values
9269
+ ** stored in all non-primary key columns also match the values stored in
9270
+ ** the changeset the row is deleted from the target database.
9271
+ **
9272
+ ** If a row with matching primary key values is found, but one or more of
9273
+ ** the non-primary key fields contains a value different from the original
9274
+ ** row value stored in the changeset, the conflict-handler function is
9275
+ ** invoked with [SQLITE_CHANGESET_DATA] as the second argument.
9276
+ **
9277
+ ** If no row with matching primary key values is found in the database,
9278
+ ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9279
+ ** passed as the second argument.
9280
+ **
9281
+ ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
9282
+ ** (which can only happen if a foreign key constraint is violated), the
9283
+ ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
9284
+ ** passed as the second argument. This includes the case where the DELETE
9285
+ ** operation is attempted because an earlier call to the conflict handler
9286
+ ** function returned [SQLITE_CHANGESET_REPLACE].
9287
+ **
9288
+ ** <dt>INSERT Changes<dd>
9289
+ ** For each INSERT change, an attempt is made to insert the new row into
9290
+ ** the database.
9291
+ **
9292
+ ** If the attempt to insert the row fails because the database already
9293
+ ** contains a row with the same primary key values, the conflict handler
9294
+ ** function is invoked with the second argument set to
9295
+ ** [SQLITE_CHANGESET_CONFLICT].
9296
+ **
9297
+ ** If the attempt to insert the row fails because of some other constraint
9298
+ ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
9299
+ ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
9300
+ ** This includes the case where the INSERT operation is re-attempted because
9301
+ ** an earlier call to the conflict handler function returned
9302
+ ** [SQLITE_CHANGESET_REPLACE].
9303
+ **
9304
+ ** <dt>UPDATE Changes<dd>
9305
+ ** For each UPDATE change, this function checks if the target database
9306
+ ** contains a row with the same primary key value (or values) as the
9307
+ ** original row values stored in the changeset. If it does, and the values
9308
+ ** stored in all non-primary key columns also match the values stored in
9309
+ ** the changeset the row is updated within the target database.
9310
+ **
9311
+ ** If a row with matching primary key values is found, but one or more of
9312
+ ** the non-primary key fields contains a value different from an original
9313
+ ** row value stored in the changeset, the conflict-handler function is
9314
+ ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9315
+ ** UPDATE changes only contain values for non-primary key fields that are
9316
+ ** to be modified, only those fields need to match the original values to
9317
+ ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
9318
+ **
9319
+ ** If no row with matching primary key values is found in the database,
9320
+ ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9321
+ ** passed as the second argument.
9322
+ **
9323
+ ** If the UPDATE operation is attempted, but SQLite returns
9324
+ ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
9325
+ ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
9326
+ ** This includes the case where the UPDATE operation is attempted after
9327
+ ** an earlier call to the conflict handler function returned
9328
+ ** [SQLITE_CHANGESET_REPLACE].
9329
+ ** </dl>
9330
+ **
9331
+ ** It is safe to execute SQL statements, including those that write to the
9332
+ ** table that the callback related to, from within the xConflict callback.
9333
+ ** This can be used to further customize the applications conflict
9334
+ ** resolution strategy.
9335
+ **
9336
+ ** All changes made by this function are enclosed in a savepoint transaction.
9337
+ ** If any other error (aside from a constraint failure when attempting to
9338
+ ** write to the target database) occurs, then the savepoint transaction is
9339
+ ** rolled back, restoring the target database to its original state, and an
9340
+ ** SQLite error code returned.
9341
+ */
9342
+ int sqlite3changeset_apply(
9343
+ sqlite3 *db, /* Apply change to "main" db of this handle */
9344
+ int nChangeset, /* Size of changeset in bytes */
9345
+ void *pChangeset, /* Changeset blob */
9346
+ int(*xFilter)(
9347
+ void *pCtx, /* Copy of sixth arg to _apply() */
9348
+ const char *zTab /* Table name */
9349
+ ),
9350
+ int(*xConflict)(
9351
+ void *pCtx, /* Copy of sixth arg to _apply() */
9352
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
9353
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
9354
+ ),
9355
+ void *pCtx /* First argument passed to xConflict */
9356
+ );
9357
+
9358
+ /*
9359
+ ** CAPI3REF: Constants Passed To The Conflict Handler
9360
+ **
9361
+ ** Values that may be passed as the second argument to a conflict-handler.
9362
+ **
9363
+ ** <dl>
9364
+ ** <dt>SQLITE_CHANGESET_DATA<dd>
9365
+ ** The conflict handler is invoked with CHANGESET_DATA as the second argument
9366
+ ** when processing a DELETE or UPDATE change if a row with the required
9367
+ ** PRIMARY KEY fields is present in the database, but one or more other
9368
+ ** (non primary-key) fields modified by the update do not contain the
9369
+ ** expected "before" values.
9370
+ **
9371
+ ** The conflicting row, in this case, is the database row with the matching
9372
+ ** primary key.
9373
+ **
9374
+ ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
9375
+ ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
9376
+ ** argument when processing a DELETE or UPDATE change if a row with the
9377
+ ** required PRIMARY KEY fields is not present in the database.
9378
+ **
9379
+ ** There is no conflicting row in this case. The results of invoking the
9380
+ ** sqlite3changeset_conflict() API are undefined.
9381
+ **
9382
+ ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
9383
+ ** CHANGESET_CONFLICT is passed as the second argument to the conflict
9384
+ ** handler while processing an INSERT change if the operation would result
9385
+ ** in duplicate primary key values.
9386
+ **
9387
+ ** The conflicting row in this case is the database row with the matching
9388
+ ** primary key.
9389
+ **
9390
+ ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
9391
+ ** If foreign key handling is enabled, and applying a changeset leaves the
9392
+ ** database in a state containing foreign key violations, the conflict
9393
+ ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
9394
+ ** exactly once before the changeset is committed. If the conflict handler
9395
+ ** returns CHANGESET_OMIT, the changes, including those that caused the
9396
+ ** foreign key constraint violation, are committed. Or, if it returns
9397
+ ** CHANGESET_ABORT, the changeset is rolled back.
9398
+ **
9399
+ ** No current or conflicting row information is provided. The only function
9400
+ ** it is possible to call on the supplied sqlite3_changeset_iter handle
9401
+ ** is sqlite3changeset_fk_conflicts().
9402
+ **
9403
+ ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
9404
+ ** If any other constraint violation occurs while applying a change (i.e.
9405
+ ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
9406
+ ** invoked with CHANGESET_CONSTRAINT as the second argument.
9407
+ **
9408
+ ** There is no conflicting row in this case. The results of invoking the
9409
+ ** sqlite3changeset_conflict() API are undefined.
9410
+ **
9411
+ ** </dl>
9412
+ */
9413
+ #define SQLITE_CHANGESET_DATA 1
9414
+ #define SQLITE_CHANGESET_NOTFOUND 2
9415
+ #define SQLITE_CHANGESET_CONFLICT 3
9416
+ #define SQLITE_CHANGESET_CONSTRAINT 4
9417
+ #define SQLITE_CHANGESET_FOREIGN_KEY 5
9418
+
9419
+ /*
9420
+ ** CAPI3REF: Constants Returned By The Conflict Handler
9421
+ **
9422
+ ** A conflict handler callback must return one of the following three values.
9423
+ **
9424
+ ** <dl>
9425
+ ** <dt>SQLITE_CHANGESET_OMIT<dd>
9426
+ ** If a conflict handler returns this value no special action is taken. The
9427
+ ** change that caused the conflict is not applied. The session module
9428
+ ** continues to the next change in the changeset.
9429
+ **
9430
+ ** <dt>SQLITE_CHANGESET_REPLACE<dd>
9431
+ ** This value may only be returned if the second argument to the conflict
9432
+ ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
9433
+ ** is not the case, any changes applied so far are rolled back and the
9434
+ ** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
9435
+ **
9436
+ ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
9437
+ ** handler, then the conflicting row is either updated or deleted, depending
9438
+ ** on the type of change.
9439
+ **
9440
+ ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
9441
+ ** handler, then the conflicting row is removed from the database and a
9442
+ ** second attempt to apply the change is made. If this second attempt fails,
9443
+ ** the original row is restored to the database before continuing.
9444
+ **
9445
+ ** <dt>SQLITE_CHANGESET_ABORT<dd>
9446
+ ** If this value is returned, any changes applied so far are rolled back
9447
+ ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
9448
+ ** </dl>
9449
+ */
9450
+ #define SQLITE_CHANGESET_OMIT 0
9451
+ #define SQLITE_CHANGESET_REPLACE 1
9452
+ #define SQLITE_CHANGESET_ABORT 2
9453
+
9454
+ /*
9455
+ ** CAPI3REF: Streaming Versions of API functions.
9456
+ **
9457
+ ** The six streaming API xxx_strm() functions serve similar purposes to the
9458
+ ** corresponding non-streaming API functions:
9459
+ **
9460
+ ** <table border=1 style="margin-left:8ex;margin-right:8ex">
9461
+ ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
9462
+ ** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
9463
+ ** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
9464
+ ** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
9465
+ ** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
9466
+ ** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
9467
+ ** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
9468
+ ** </table>
9469
+ **
9470
+ ** Non-streaming functions that accept changesets (or patchsets) as input
9471
+ ** require that the entire changeset be stored in a single buffer in memory.
9472
+ ** Similarly, those that return a changeset or patchset do so by returning
9473
+ ** a pointer to a single large buffer allocated using sqlite3_malloc().
9474
+ ** Normally this is convenient. However, if an application running in a
9475
+ ** low-memory environment is required to handle very large changesets, the
9476
+ ** large contiguous memory allocations required can become onerous.
9477
+ **
9478
+ ** In order to avoid this problem, instead of a single large buffer, input
9479
+ ** is passed to a streaming API functions by way of a callback function that
9480
+ ** the sessions module invokes to incrementally request input data as it is
9481
+ ** required. In all cases, a pair of API function parameters such as
9482
+ **
9483
+ ** <pre>
9484
+ ** &nbsp; int nChangeset,
9485
+ ** &nbsp; void *pChangeset,
9486
+ ** </pre>
9487
+ **
9488
+ ** Is replaced by:
9489
+ **
9490
+ ** <pre>
9491
+ ** &nbsp; int (*xInput)(void *pIn, void *pData, int *pnData),
9492
+ ** &nbsp; void *pIn,
9493
+ ** </pre>
9494
+ **
9495
+ ** Each time the xInput callback is invoked by the sessions module, the first
9496
+ ** argument passed is a copy of the supplied pIn context pointer. The second
9497
+ ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
9498
+ ** error occurs the xInput method should copy up to (*pnData) bytes of data
9499
+ ** into the buffer and set (*pnData) to the actual number of bytes copied
9500
+ ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
9501
+ ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
9502
+ ** error code should be returned. In all cases, if an xInput callback returns
9503
+ ** an error, all processing is abandoned and the streaming API function
9504
+ ** returns a copy of the error code to the caller.
9505
+ **
9506
+ ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
9507
+ ** invoked by the sessions module at any point during the lifetime of the
9508
+ ** iterator. If such an xInput callback returns an error, the iterator enters
9509
+ ** an error state, whereby all subsequent calls to iterator functions
9510
+ ** immediately fail with the same error code as returned by xInput.
9511
+ **
9512
+ ** Similarly, streaming API functions that return changesets (or patchsets)
9513
+ ** return them in chunks by way of a callback function instead of via a
9514
+ ** pointer to a single large buffer. In this case, a pair of parameters such
9515
+ ** as:
9516
+ **
9517
+ ** <pre>
9518
+ ** &nbsp; int *pnChangeset,
9519
+ ** &nbsp; void **ppChangeset,
9520
+ ** </pre>
9521
+ **
9522
+ ** Is replaced by:
9523
+ **
9524
+ ** <pre>
9525
+ ** &nbsp; int (*xOutput)(void *pOut, const void *pData, int nData),
9526
+ ** &nbsp; void *pOut
9527
+ ** </pre>
9528
+ **
9529
+ ** The xOutput callback is invoked zero or more times to return data to
9530
+ ** the application. The first parameter passed to each call is a copy of the
9531
+ ** pOut pointer supplied by the application. The second parameter, pData,
9532
+ ** points to a buffer nData bytes in size containing the chunk of output
9533
+ ** data being returned. If the xOutput callback successfully processes the
9534
+ ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
9535
+ ** it should return some other SQLite error code. In this case processing
9536
+ ** is immediately abandoned and the streaming API function returns a copy
9537
+ ** of the xOutput error code to the application.
9538
+ **
9539
+ ** The sessions module never invokes an xOutput callback with the third
9540
+ ** parameter set to a value less than or equal to zero. Other than this,
9541
+ ** no guarantees are made as to the size of the chunks of data returned.
9542
+ */
9543
+ int sqlite3changeset_apply_strm(
9544
+ sqlite3 *db, /* Apply change to "main" db of this handle */
9545
+ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
9546
+ void *pIn, /* First arg for xInput */
9547
+ int(*xFilter)(
9548
+ void *pCtx, /* Copy of sixth arg to _apply() */
9549
+ const char *zTab /* Table name */
9550
+ ),
9551
+ int(*xConflict)(
9552
+ void *pCtx, /* Copy of sixth arg to _apply() */
9553
+ int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
9554
+ sqlite3_changeset_iter *p /* Handle describing change and conflict */
9555
+ ),
9556
+ void *pCtx /* First argument passed to xConflict */
9557
+ );
9558
+ int sqlite3changeset_concat_strm(
9559
+ int (*xInputA)(void *pIn, void *pData, int *pnData),
9560
+ void *pInA,
9561
+ int (*xInputB)(void *pIn, void *pData, int *pnData),
9562
+ void *pInB,
9563
+ int (*xOutput)(void *pOut, const void *pData, int nData),
9564
+ void *pOut
9565
+ );
9566
+ int sqlite3changeset_invert_strm(
9567
+ int (*xInput)(void *pIn, void *pData, int *pnData),
9568
+ void *pIn,
9569
+ int (*xOutput)(void *pOut, const void *pData, int nData),
9570
+ void *pOut
9571
+ );
9572
+ int sqlite3changeset_start_strm(
9573
+ sqlite3_changeset_iter **pp,
9574
+ int (*xInput)(void *pIn, void *pData, int *pnData),
9575
+ void *pIn
9576
+ );
9577
+ int sqlite3session_changeset_strm(
9578
+ sqlite3_session *pSession,
9579
+ int (*xOutput)(void *pOut, const void *pData, int nData),
9580
+ void *pOut
9581
+ );
9582
+ int sqlite3session_patchset_strm(
9583
+ sqlite3_session *pSession,
9584
+ int (*xOutput)(void *pOut, const void *pData, int nData),
9585
+ void *pOut
9586
+ );
9587
+ int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9588
+ int (*xInput)(void *pIn, void *pData, int *pnData),
9589
+ void *pIn
9590
+ );
9591
+ int sqlite3changegroup_output_strm(sqlite3_changegroup*,
9592
+ int (*xOutput)(void *pOut, const void *pData, int nData),
9593
+ void *pOut
9594
+ );
9595
+
9596
+
9597
+ /*
9598
+ ** Make sure we can call this stuff from C++.
9599
+ */
9600
+ #ifdef __cplusplus
9601
+ }
9602
+ #endif
9603
+
9604
+ #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
9605
+
9606
+ /******** End of sqlite3session.h *********/
9607
+ /******** Begin file fts5.h *********/
8156
9608
  /*
8157
9609
  ** 2014 May 31
8158
9610
  **
@@ -8297,11 +9749,13 @@ struct Fts5PhraseIter {
8297
9749
  ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
8298
9750
  **
8299
9751
  ** with $p set to a phrase equivalent to the phrase iPhrase of the
8300
- ** current query is executed. For each row visited, the callback function
8301
- ** passed as the fourth argument is invoked. The context and API objects
8302
- ** passed to the callback function may be used to access the properties of
8303
- ** each matched row. Invoking Api.xUserData() returns a copy of the pointer
8304
- ** passed as the third argument to pUserData.
9752
+ ** current query is executed. Any column filter that applies to
9753
+ ** phrase iPhrase of the current query is included in $p. For each
9754
+ ** row visited, the callback function passed as the fourth argument
9755
+ ** is invoked. The context and API objects passed to the callback
9756
+ ** function may be used to access the properties of each matched row.
9757
+ ** Invoking Api.xUserData() returns a copy of the pointer passed as
9758
+ ** the third argument to pUserData.
8305
9759
  **
8306
9760
  ** If the callback function returns any value other than SQLITE_OK, the
8307
9761
  ** query is abandoned and the xQueryPhrase function returns immediately.
@@ -8731,3 +10185,4 @@ struct fts5_api {
8731
10185
  #endif /* _FTS5_H */
8732
10186
 
8733
10187
 
10188
+ /******** End of fts5.h *********/