wasm minimal build: strip authorizers and JSON support (saves approx 35kb). Strip...
[sqlite.git] / ext / session / sqlite3session.h
blobf950d419b51ad0a7707f01847171831ac0da45b2
2 #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
3 #define __SQLITESESSION_H_ 1
5 /*
6 ** Make sure we can call this stuff from C++.
7 */
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
12 #include "sqlite3.h"
15 ** CAPI3REF: Session Object Handle
17 ** An instance of this object is a [session] that can be used to
18 ** record changes to a database.
20 typedef struct sqlite3_session sqlite3_session;
23 ** CAPI3REF: Changeset Iterator Handle
25 ** An instance of this object acts as a cursor for iterating
26 ** over the elements of a [changeset] or [patchset].
28 typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
31 ** CAPI3REF: Create A New Session Object
32 ** CONSTRUCTOR: sqlite3_session
34 ** Create a new session object attached to database handle db. If successful,
35 ** a pointer to the new object is written to *ppSession and SQLITE_OK is
36 ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
37 ** error code (e.g. SQLITE_NOMEM) is returned.
39 ** It is possible to create multiple session objects attached to a single
40 ** database handle.
42 ** Session objects created using this function should be deleted using the
43 ** [sqlite3session_delete()] function before the database handle that they
44 ** are attached to is itself closed. If the database handle is closed before
45 ** the session object is deleted, then the results of calling any session
46 ** module function, including [sqlite3session_delete()] on the session object
47 ** are undefined.
49 ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
50 ** is not possible for an application to register a pre-update hook on a
51 ** database handle that has one or more session objects attached. Nor is
52 ** it possible to create a session object attached to a database handle for
53 ** which a pre-update hook is already defined. The results of attempting
54 ** either of these things are undefined.
56 ** The session object will be used to create changesets for tables in
57 ** database zDb, where zDb is either "main", or "temp", or the name of an
58 ** attached database. It is not an error if database zDb is not attached
59 ** to the database when the session object is created.
61 int sqlite3session_create(
62 sqlite3 *db, /* Database handle */
63 const char *zDb, /* Name of db (e.g. "main") */
64 sqlite3_session **ppSession /* OUT: New session object */
68 ** CAPI3REF: Delete A Session Object
69 ** DESTRUCTOR: sqlite3_session
71 ** Delete a session object previously allocated using
72 ** [sqlite3session_create()]. Once a session object has been deleted, the
73 ** results of attempting to use pSession with any other session module
74 ** function are undefined.
76 ** Session objects must be deleted before the database handle to which they
77 ** are attached is closed. Refer to the documentation for
78 ** [sqlite3session_create()] for details.
80 void sqlite3session_delete(sqlite3_session *pSession);
83 ** CAPI3REF: Configure a Session Object
84 ** METHOD: sqlite3_session
86 ** This method is used to configure a session object after it has been
87 ** created. At present the only valid values for the second parameter are
88 ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
91 int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
94 ** CAPI3REF: Options for sqlite3session_object_config
96 ** The following values may passed as the the 2nd parameter to
97 ** sqlite3session_object_config().
99 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
100 ** This option is used to set, clear or query the flag that enables
101 ** the [sqlite3session_changeset_size()] API. Because it imposes some
102 ** computational overhead, this API is disabled by default. Argument
103 ** pArg must point to a value of type (int). If the value is initially
104 ** 0, then the sqlite3session_changeset_size() API is disabled. If it
105 ** is greater than 0, then the same API is enabled. Or, if the initial
106 ** value is less than zero, no change is made. In all cases the (int)
107 ** variable is set to 1 if the sqlite3session_changeset_size() API is
108 ** enabled following the current call, or 0 otherwise.
110 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
111 ** the first table has been attached to the session object.
113 ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
114 ** This option is used to set, clear or query the flag that enables
115 ** collection of data for tables with no explicit PRIMARY KEY.
117 ** Normally, tables with no explicit PRIMARY KEY are simply ignored
118 ** by the sessions module. However, if this flag is set, it behaves
119 ** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
120 ** as their leftmost columns.
122 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
123 ** the first table has been attached to the session object.
125 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
126 #define SQLITE_SESSION_OBJCONFIG_ROWID 2
129 ** CAPI3REF: Enable Or Disable A Session Object
130 ** METHOD: sqlite3_session
132 ** Enable or disable the recording of changes by a session object. When
133 ** enabled, a session object records changes made to the database. When
134 ** disabled - it does not. A newly created session object is enabled.
135 ** Refer to the documentation for [sqlite3session_changeset()] for further
136 ** details regarding how enabling and disabling a session object affects
137 ** the eventual changesets.
139 ** Passing zero to this function disables the session. Passing a value
140 ** greater than zero enables it. Passing a value less than zero is a
141 ** no-op, and may be used to query the current state of the session.
143 ** The return value indicates the final state of the session object: 0 if
144 ** the session is disabled, or 1 if it is enabled.
146 int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
149 ** CAPI3REF: Set Or Clear the Indirect Change Flag
150 ** METHOD: sqlite3_session
152 ** Each change recorded by a session object is marked as either direct or
153 ** indirect. A change is marked as indirect if either:
155 ** <ul>
156 ** <li> The session object "indirect" flag is set when the change is
157 ** made, or
158 ** <li> The change is made by an SQL trigger or foreign key action
159 ** instead of directly as a result of a users SQL statement.
160 ** </ul>
162 ** If a single row is affected by more than one operation within a session,
163 ** then the change is considered indirect if all operations meet the criteria
164 ** for an indirect change above, or direct otherwise.
166 ** This function is used to set, clear or query the session object indirect
167 ** flag. If the second argument passed to this function is zero, then the
168 ** indirect flag is cleared. If it is greater than zero, the indirect flag
169 ** is set. Passing a value less than zero does not modify the current value
170 ** of the indirect flag, and may be used to query the current state of the
171 ** indirect flag for the specified session object.
173 ** The return value indicates the final state of the indirect flag: 0 if
174 ** it is clear, or 1 if it is set.
176 int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
179 ** CAPI3REF: Attach A Table To A Session Object
180 ** METHOD: sqlite3_session
182 ** If argument zTab is not NULL, then it is the name of a table to attach
183 ** to the session object passed as the first argument. All subsequent changes
184 ** made to the table while the session object is enabled will be recorded. See
185 ** documentation for [sqlite3session_changeset()] for further details.
187 ** Or, if argument zTab is NULL, then changes are recorded for all tables
188 ** in the database. If additional tables are added to the database (by
189 ** executing "CREATE TABLE" statements) after this call is made, changes for
190 ** the new tables are also recorded.
192 ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
193 ** defined as part of their CREATE TABLE statement. It does not matter if the
194 ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
195 ** KEY may consist of a single column, or may be a composite key.
197 ** It is not an error if the named table does not exist in the database. Nor
198 ** is it an error if the named table does not have a PRIMARY KEY. However,
199 ** no changes will be recorded in either of these scenarios.
201 ** Changes are not recorded for individual rows that have NULL values stored
202 ** in one or more of their PRIMARY KEY columns.
204 ** SQLITE_OK is returned if the call completes without error. Or, if an error
205 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
207 ** <h3>Special sqlite_stat1 Handling</h3>
209 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
210 ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
211 ** <pre>
212 ** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
213 ** </pre>
215 ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
216 ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
217 ** are recorded for rows for which (idx IS NULL) is true. However, for such
218 ** rows a zero-length blob (SQL value X'') is stored in the changeset or
219 ** patchset instead of a NULL value. This allows such changesets to be
220 ** manipulated by legacy implementations of sqlite3changeset_invert(),
221 ** concat() and similar.
223 ** The sqlite3changeset_apply() function automatically converts the
224 ** zero-length blob back to a NULL value when updating the sqlite_stat1
225 ** table. However, if the application calls sqlite3changeset_new(),
226 ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
227 ** iterator directly (including on a changeset iterator passed to a
228 ** conflict-handler callback) then the X'' value is returned. The application
229 ** must translate X'' to NULL itself if required.
231 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
232 ** changes made to the sqlite_stat1 table. Legacy versions of the
233 ** sqlite3changeset_apply() function silently ignore any modifications to the
234 ** sqlite_stat1 table that are part of a changeset or patchset.
236 int sqlite3session_attach(
237 sqlite3_session *pSession, /* Session object */
238 const char *zTab /* Table name */
242 ** CAPI3REF: Set a table filter on a Session Object.
243 ** METHOD: sqlite3_session
245 ** The second argument (xFilter) is the "filter callback". For changes to rows
246 ** in tables that are not attached to the Session object, the filter is called
247 ** to determine whether changes to the table's rows should be tracked or not.
248 ** If xFilter returns 0, changes are not tracked. Note that once a table is
249 ** attached, xFilter will not be called again.
251 void sqlite3session_table_filter(
252 sqlite3_session *pSession, /* Session object */
253 int(*xFilter)(
254 void *pCtx, /* Copy of third arg to _filter_table() */
255 const char *zTab /* Table name */
257 void *pCtx /* First argument passed to xFilter */
261 ** CAPI3REF: Generate A Changeset From A Session Object
262 ** METHOD: sqlite3_session
264 ** Obtain a changeset containing changes to the tables attached to the
265 ** session object passed as the first argument. If successful,
266 ** set *ppChangeset to point to a buffer containing the changeset
267 ** and *pnChangeset to the size of the changeset in bytes before returning
268 ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
269 ** zero and return an SQLite error code.
271 ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
272 ** each representing a change to a single row of an attached table. An INSERT
273 ** change contains the values of each field of a new database row. A DELETE
274 ** contains the original values of each field of a deleted database row. An
275 ** UPDATE change contains the original values of each field of an updated
276 ** database row along with the updated values for each updated non-primary-key
277 ** column. It is not possible for an UPDATE change to represent a change that
278 ** modifies the values of primary key columns. If such a change is made, it
279 ** is represented in a changeset as a DELETE followed by an INSERT.
281 ** Changes are not recorded for rows that have NULL values stored in one or
282 ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
283 ** no corresponding change is present in the changesets returned by this
284 ** function. If an existing row with one or more NULL values stored in
285 ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
286 ** only an INSERT is appears in the changeset. Similarly, if an existing row
287 ** with non-NULL PRIMARY KEY values is updated so that one or more of its
288 ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
289 ** DELETE change only.
291 ** The contents of a changeset may be traversed using an iterator created
292 ** using the [sqlite3changeset_start()] API. A changeset may be applied to
293 ** a database with a compatible schema using the [sqlite3changeset_apply()]
294 ** API.
296 ** Within a changeset generated by this function, all changes related to a
297 ** single table are grouped together. In other words, when iterating through
298 ** a changeset or when applying a changeset to a database, all changes related
299 ** to a single table are processed before moving on to the next table. Tables
300 ** are sorted in the same order in which they were attached (or auto-attached)
301 ** to the sqlite3_session object. The order in which the changes related to
302 ** a single table are stored is undefined.
304 ** Following a successful call to this function, it is the responsibility of
305 ** the caller to eventually free the buffer that *ppChangeset points to using
306 ** [sqlite3_free()].
308 ** <h3>Changeset Generation</h3>
310 ** Once a table has been attached to a session object, the session object
311 ** records the primary key values of all new rows inserted into the table.
312 ** It also records the original primary key and other column values of any
313 ** deleted or updated rows. For each unique primary key value, data is only
314 ** recorded once - the first time a row with said primary key is inserted,
315 ** updated or deleted in the lifetime of the session.
317 ** There is one exception to the previous paragraph: when a row is inserted,
318 ** updated or deleted, if one or more of its primary key columns contain a
319 ** NULL value, no record of the change is made.
321 ** The session object therefore accumulates two types of records - those
322 ** that consist of primary key values only (created when the user inserts
323 ** a new record) and those that consist of the primary key values and the
324 ** original values of other table columns (created when the users deletes
325 ** or updates a record).
327 ** When this function is called, the requested changeset is created using
328 ** both the accumulated records and the current contents of the database
329 ** file. Specifically:
331 ** <ul>
332 ** <li> For each record generated by an insert, the database is queried
333 ** for a row with a matching primary key. If one is found, an INSERT
334 ** change is added to the changeset. If no such row is found, no change
335 ** is added to the changeset.
337 ** <li> For each record generated by an update or delete, the database is
338 ** queried for a row with a matching primary key. If such a row is
339 ** found and one or more of the non-primary key fields have been
340 ** modified from their original values, an UPDATE change is added to
341 ** the changeset. Or, if no such row is found in the table, a DELETE
342 ** change is added to the changeset. If there is a row with a matching
343 ** primary key in the database, but all fields contain their original
344 ** values, no change is added to the changeset.
345 ** </ul>
347 ** This means, amongst other things, that if a row is inserted and then later
348 ** deleted while a session object is active, neither the insert nor the delete
349 ** will be present in the changeset. Or if a row is deleted and then later a
350 ** row with the same primary key values inserted while a session object is
351 ** active, the resulting changeset will contain an UPDATE change instead of
352 ** a DELETE and an INSERT.
354 ** When a session object is disabled (see the [sqlite3session_enable()] API),
355 ** it does not accumulate records when rows are inserted, updated or deleted.
356 ** This may appear to have some counter-intuitive effects if a single row
357 ** is written to more than once during a session. For example, if a row
358 ** is inserted while a session object is enabled, then later deleted while
359 ** the same session object is disabled, no INSERT record will appear in the
360 ** changeset, even though the delete took place while the session was disabled.
361 ** Or, if one field of a row is updated while a session is disabled, and
362 ** another field of the same row is updated while the session is enabled, the
363 ** resulting changeset will contain an UPDATE change that updates both fields.
365 int sqlite3session_changeset(
366 sqlite3_session *pSession, /* Session object */
367 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
368 void **ppChangeset /* OUT: Buffer containing changeset */
372 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
373 ** METHOD: sqlite3_session
375 ** By default, this function always returns 0. For it to return
376 ** a useful result, the sqlite3_session object must have been configured
377 ** to enable this API using sqlite3session_object_config() with the
378 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
380 ** When enabled, this function returns an upper limit, in bytes, for the size
381 ** of the changeset that might be produced if sqlite3session_changeset() were
382 ** called. The final changeset size might be equal to or smaller than the
383 ** size in bytes returned by this function.
385 sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
388 ** CAPI3REF: Load The Difference Between Tables Into A Session
389 ** METHOD: sqlite3_session
391 ** If it is not already attached to the session object passed as the first
392 ** argument, this function attaches table zTbl in the same manner as the
393 ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
394 ** does not have a primary key, this function is a no-op (but does not return
395 ** an error).
397 ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
398 ** attached to the same database handle as the session object that contains
399 ** a table compatible with the table attached to the session by this function.
400 ** A table is considered compatible if it:
402 ** <ul>
403 ** <li> Has the same name,
404 ** <li> Has the same set of columns declared in the same order, and
405 ** <li> Has the same PRIMARY KEY definition.
406 ** </ul>
408 ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
409 ** are compatible but do not have any PRIMARY KEY columns, it is not an error
410 ** but no changes are added to the session object. As with other session
411 ** APIs, tables without PRIMARY KEYs are simply ignored.
413 ** This function adds a set of changes to the session object that could be
414 ** used to update the table in database zFrom (call this the "from-table")
415 ** so that its content is the same as the table attached to the session
416 ** object (call this the "to-table"). Specifically:
418 ** <ul>
419 ** <li> For each row (primary key) that exists in the to-table but not in
420 ** the from-table, an INSERT record is added to the session object.
422 ** <li> For each row (primary key) that exists in the to-table but not in
423 ** the from-table, a DELETE record is added to the session object.
425 ** <li> For each row (primary key) that exists in both tables, but features
426 ** different non-PK values in each, an UPDATE record is added to the
427 ** session.
428 ** </ul>
430 ** To clarify, if this function is called and then a changeset constructed
431 ** using [sqlite3session_changeset()], then after applying that changeset to
432 ** database zFrom the contents of the two compatible tables would be
433 ** identical.
435 ** It an error if database zFrom does not exist or does not contain the
436 ** required compatible table.
438 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
439 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
440 ** may be set to point to a buffer containing an English language error
441 ** message. It is the responsibility of the caller to free this buffer using
442 ** sqlite3_free().
444 int sqlite3session_diff(
445 sqlite3_session *pSession,
446 const char *zFromDb,
447 const char *zTbl,
448 char **pzErrMsg
453 ** CAPI3REF: Generate A Patchset From A Session Object
454 ** METHOD: sqlite3_session
456 ** The differences between a patchset and a changeset are that:
458 ** <ul>
459 ** <li> DELETE records consist of the primary key fields only. The
460 ** original values of other fields are omitted.
461 ** <li> The original values of any modified fields are omitted from
462 ** UPDATE records.
463 ** </ul>
465 ** A patchset blob may be used with up to date versions of all
466 ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
467 ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
468 ** attempting to use a patchset blob with old versions of the
469 ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
471 ** Because the non-primary key "old.*" fields are omitted, no
472 ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
473 ** is passed to the sqlite3changeset_apply() API. Other conflict types work
474 ** in the same way as for changesets.
476 ** Changes within a patchset are ordered in the same way as for changesets
477 ** generated by the sqlite3session_changeset() function (i.e. all changes for
478 ** a single table are grouped together, tables appear in the order in which
479 ** they were attached to the session object).
481 int sqlite3session_patchset(
482 sqlite3_session *pSession, /* Session object */
483 int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
484 void **ppPatchset /* OUT: Buffer containing patchset */
488 ** CAPI3REF: Test if a changeset has recorded any changes.
490 ** Return non-zero if no changes to attached tables have been recorded by
491 ** the session object passed as the first argument. Otherwise, if one or
492 ** more changes have been recorded, return zero.
494 ** Even if this function returns zero, it is possible that calling
495 ** [sqlite3session_changeset()] on the session handle may still return a
496 ** changeset that contains no changes. This can happen when a row in
497 ** an attached table is modified and then later on the original values
498 ** are restored. However, if this function returns non-zero, then it is
499 ** guaranteed that a call to sqlite3session_changeset() will return a
500 ** changeset containing zero changes.
502 int sqlite3session_isempty(sqlite3_session *pSession);
505 ** CAPI3REF: Query for the amount of heap memory used by a session object.
507 ** This API returns the total amount of heap memory in bytes currently
508 ** used by the session object passed as the only argument.
510 sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
513 ** CAPI3REF: Create An Iterator To Traverse A Changeset
514 ** CONSTRUCTOR: sqlite3_changeset_iter
516 ** Create an iterator used to iterate through the contents of a changeset.
517 ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
518 ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
519 ** SQLite error code is returned.
521 ** The following functions can be used to advance and query a changeset
522 ** iterator created by this function:
524 ** <ul>
525 ** <li> [sqlite3changeset_next()]
526 ** <li> [sqlite3changeset_op()]
527 ** <li> [sqlite3changeset_new()]
528 ** <li> [sqlite3changeset_old()]
529 ** </ul>
531 ** It is the responsibility of the caller to eventually destroy the iterator
532 ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
533 ** changeset (pChangeset) must remain valid until after the iterator is
534 ** destroyed.
536 ** Assuming the changeset blob was created by one of the
537 ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
538 ** [sqlite3changeset_invert()] functions, all changes within the changeset
539 ** that apply to a single table are grouped together. This means that when
540 ** an application iterates through a changeset using an iterator created by
541 ** this function, all changes that relate to a single table are visited
542 ** consecutively. There is no chance that the iterator will visit a change
543 ** the applies to table X, then one for table Y, and then later on visit
544 ** another change for table X.
546 ** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
547 ** may be modified by passing a combination of
548 ** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.
550 ** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>
551 ** and therefore subject to change.
553 int sqlite3changeset_start(
554 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
555 int nChangeset, /* Size of changeset blob in bytes */
556 void *pChangeset /* Pointer to blob containing changeset */
558 int sqlite3changeset_start_v2(
559 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
560 int nChangeset, /* Size of changeset blob in bytes */
561 void *pChangeset, /* Pointer to blob containing changeset */
562 int flags /* SESSION_CHANGESETSTART_* flags */
566 ** CAPI3REF: Flags for sqlite3changeset_start_v2
568 ** The following flags may passed via the 4th parameter to
569 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
571 ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
572 ** Invert the changeset while iterating through it. This is equivalent to
573 ** inverting a changeset using sqlite3changeset_invert() before applying it.
574 ** It is an error to specify this flag with a patchset.
576 #define SQLITE_CHANGESETSTART_INVERT 0x0002
580 ** CAPI3REF: Advance A Changeset Iterator
581 ** METHOD: sqlite3_changeset_iter
583 ** This function may only be used with iterators created by the function
584 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
585 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
586 ** is returned and the call has no effect.
588 ** Immediately after an iterator is created by sqlite3changeset_start(), it
589 ** does not point to any change in the changeset. Assuming the changeset
590 ** is not empty, the first call to this function advances the iterator to
591 ** point to the first change in the changeset. Each subsequent call advances
592 ** the iterator to point to the next change in the changeset (if any). If
593 ** no error occurs and the iterator points to a valid change after a call
594 ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
595 ** Otherwise, if all changes in the changeset have already been visited,
596 ** SQLITE_DONE is returned.
598 ** If an error occurs, an SQLite error code is returned. Possible error
599 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
600 ** SQLITE_NOMEM.
602 int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
605 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
606 ** METHOD: sqlite3_changeset_iter
608 ** The pIter argument passed to this function may either be an iterator
609 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
610 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
611 ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
612 ** is not the case, this function returns [SQLITE_MISUSE].
614 ** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
615 ** outputs are set through these pointers:
617 ** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
618 ** depending on the type of change that the iterator currently points to;
620 ** *pnCol is set to the number of columns in the table affected by the change; and
622 ** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
623 ** the name of the table affected by the current change. The buffer remains
624 ** valid until either sqlite3changeset_next() is called on the iterator
625 ** or until the conflict-handler function returns.
627 ** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
628 ** is an indirect change, or false (0) otherwise. See the documentation for
629 ** [sqlite3session_indirect()] for a description of direct and indirect
630 ** changes.
632 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
633 ** SQLite error code is returned. The values of the output variables may not
634 ** be trusted in this case.
636 int sqlite3changeset_op(
637 sqlite3_changeset_iter *pIter, /* Iterator object */
638 const char **pzTab, /* OUT: Pointer to table name */
639 int *pnCol, /* OUT: Number of columns in table */
640 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
641 int *pbIndirect /* OUT: True for an 'indirect' change */
645 ** CAPI3REF: Obtain The Primary Key Definition Of A Table
646 ** METHOD: sqlite3_changeset_iter
648 ** For each modified table, a changeset includes the following:
650 ** <ul>
651 ** <li> The number of columns in the table, and
652 ** <li> Which of those columns make up the tables PRIMARY KEY.
653 ** </ul>
655 ** This function is used to find which columns comprise the PRIMARY KEY of
656 ** the table modified by the change that iterator pIter currently points to.
657 ** If successful, *pabPK is set to point to an array of nCol entries, where
658 ** nCol is the number of columns in the table. Elements of *pabPK are set to
659 ** 0x01 if the corresponding column is part of the tables primary key, or
660 ** 0x00 if it is not.
662 ** If argument pnCol is not NULL, then *pnCol is set to the number of columns
663 ** in the table.
665 ** If this function is called when the iterator does not point to a valid
666 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
667 ** SQLITE_OK is returned and the output variables populated as described
668 ** above.
670 int sqlite3changeset_pk(
671 sqlite3_changeset_iter *pIter, /* Iterator object */
672 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
673 int *pnCol /* OUT: Number of entries in output array */
677 ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
678 ** METHOD: sqlite3_changeset_iter
680 ** The pIter argument passed to this function may either be an iterator
681 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
682 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
683 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
684 ** Furthermore, it may only be called if the type of change that the iterator
685 ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
686 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
688 ** Argument iVal must be greater than or equal to 0, and less than the number
689 ** of columns in the table affected by the current change. Otherwise,
690 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
692 ** If successful, this function sets *ppValue to point to a protected
693 ** sqlite3_value object containing the iVal'th value from the vector of
694 ** original row values stored as part of the UPDATE or DELETE change and
695 ** returns SQLITE_OK. The name of the function comes from the fact that this
696 ** is similar to the "old.*" columns available to update or delete triggers.
698 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
699 ** is returned and *ppValue is set to NULL.
701 int sqlite3changeset_old(
702 sqlite3_changeset_iter *pIter, /* Changeset iterator */
703 int iVal, /* Column number */
704 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
708 ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
709 ** METHOD: sqlite3_changeset_iter
711 ** The pIter argument passed to this function may either be an iterator
712 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
713 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
714 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
715 ** Furthermore, it may only be called if the type of change that the iterator
716 ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
717 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
719 ** Argument iVal must be greater than or equal to 0, and less than the number
720 ** of columns in the table affected by the current change. Otherwise,
721 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
723 ** If successful, this function sets *ppValue to point to a protected
724 ** sqlite3_value object containing the iVal'th value from the vector of
725 ** new row values stored as part of the UPDATE or INSERT change and
726 ** returns SQLITE_OK. If the change is an UPDATE and does not include
727 ** a new value for the requested column, *ppValue is set to NULL and
728 ** SQLITE_OK returned. The name of the function comes from the fact that
729 ** this is similar to the "new.*" columns available to update or delete
730 ** triggers.
732 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
733 ** is returned and *ppValue is set to NULL.
735 int sqlite3changeset_new(
736 sqlite3_changeset_iter *pIter, /* Changeset iterator */
737 int iVal, /* Column number */
738 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
742 ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
743 ** METHOD: sqlite3_changeset_iter
745 ** This function should only be used with iterator objects passed to a
746 ** conflict-handler callback by [sqlite3changeset_apply()] with either
747 ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
748 ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
749 ** is set to NULL.
751 ** Argument iVal must be greater than or equal to 0, and less than the number
752 ** of columns in the table affected by the current change. Otherwise,
753 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
755 ** If successful, this function sets *ppValue to point to a protected
756 ** sqlite3_value object containing the iVal'th value from the
757 ** "conflicting row" associated with the current conflict-handler callback
758 ** and returns SQLITE_OK.
760 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
761 ** is returned and *ppValue is set to NULL.
763 int sqlite3changeset_conflict(
764 sqlite3_changeset_iter *pIter, /* Changeset iterator */
765 int iVal, /* Column number */
766 sqlite3_value **ppValue /* OUT: Value from conflicting row */
770 ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
771 ** METHOD: sqlite3_changeset_iter
773 ** This function may only be called with an iterator passed to an
774 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
775 ** it sets the output variable to the total number of known foreign key
776 ** violations in the destination database and returns SQLITE_OK.
778 ** In all other cases this function returns SQLITE_MISUSE.
780 int sqlite3changeset_fk_conflicts(
781 sqlite3_changeset_iter *pIter, /* Changeset iterator */
782 int *pnOut /* OUT: Number of FK violations */
787 ** CAPI3REF: Finalize A Changeset Iterator
788 ** METHOD: sqlite3_changeset_iter
790 ** This function is used to finalize an iterator allocated with
791 ** [sqlite3changeset_start()].
793 ** This function should only be called on iterators created using the
794 ** [sqlite3changeset_start()] function. If an application calls this
795 ** function with an iterator passed to a conflict-handler by
796 ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
797 ** call has no effect.
799 ** If an error was encountered within a call to an sqlite3changeset_xxx()
800 ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
801 ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
802 ** to that error is returned by this function. Otherwise, SQLITE_OK is
803 ** returned. This is to allow the following pattern (pseudo-code):
805 ** <pre>
806 ** sqlite3changeset_start();
807 ** while( SQLITE_ROW==sqlite3changeset_next() ){
808 ** // Do something with change.
809 ** }
810 ** rc = sqlite3changeset_finalize();
811 ** if( rc!=SQLITE_OK ){
812 ** // An error has occurred
813 ** }
814 ** </pre>
816 int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
819 ** CAPI3REF: Invert A Changeset
821 ** This function is used to "invert" a changeset object. Applying an inverted
822 ** changeset to a database reverses the effects of applying the uninverted
823 ** changeset. Specifically:
825 ** <ul>
826 ** <li> Each DELETE change is changed to an INSERT, and
827 ** <li> Each INSERT change is changed to a DELETE, and
828 ** <li> For each UPDATE change, the old.* and new.* values are exchanged.
829 ** </ul>
831 ** This function does not change the order in which changes appear within
832 ** the changeset. It merely reverses the sense of each individual change.
834 ** If successful, a pointer to a buffer containing the inverted changeset
835 ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
836 ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
837 ** zeroed and an SQLite error code returned.
839 ** It is the responsibility of the caller to eventually call sqlite3_free()
840 ** on the *ppOut pointer to free the buffer allocation following a successful
841 ** call to this function.
843 ** WARNING/TODO: This function currently assumes that the input is a valid
844 ** changeset. If it is not, the results are undefined.
846 int sqlite3changeset_invert(
847 int nIn, const void *pIn, /* Input changeset */
848 int *pnOut, void **ppOut /* OUT: Inverse of input */
852 ** CAPI3REF: Concatenate Two Changeset Objects
854 ** This function is used to concatenate two changesets, A and B, into a
855 ** single changeset. The result is a changeset equivalent to applying
856 ** changeset A followed by changeset B.
858 ** This function combines the two input changesets using an
859 ** sqlite3_changegroup object. Calling it produces similar results as the
860 ** following code fragment:
862 ** <pre>
863 ** sqlite3_changegroup *pGrp;
864 ** rc = sqlite3_changegroup_new(&pGrp);
865 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
866 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
867 ** if( rc==SQLITE_OK ){
868 ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
869 ** }else{
870 ** *ppOut = 0;
871 ** *pnOut = 0;
872 ** }
873 ** </pre>
875 ** Refer to the sqlite3_changegroup documentation below for details.
877 int sqlite3changeset_concat(
878 int nA, /* Number of bytes in buffer pA */
879 void *pA, /* Pointer to buffer containing changeset A */
880 int nB, /* Number of bytes in buffer pB */
881 void *pB, /* Pointer to buffer containing changeset B */
882 int *pnOut, /* OUT: Number of bytes in output changeset */
883 void **ppOut /* OUT: Buffer containing output changeset */
888 ** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
890 int sqlite3changeset_upgrade(
891 sqlite3 *db,
892 const char *zDb,
893 int nIn, const void *pIn, /* Input changeset */
894 int *pnOut, void **ppOut /* OUT: Inverse of input */
900 ** CAPI3REF: Changegroup Handle
902 ** A changegroup is an object used to combine two or more
903 ** [changesets] or [patchsets]
905 typedef struct sqlite3_changegroup sqlite3_changegroup;
908 ** CAPI3REF: Create A New Changegroup Object
909 ** CONSTRUCTOR: sqlite3_changegroup
911 ** An sqlite3_changegroup object is used to combine two or more changesets
912 ** (or patchsets) into a single changeset (or patchset). A single changegroup
913 ** object may combine changesets or patchsets, but not both. The output is
914 ** always in the same format as the input.
916 ** If successful, this function returns SQLITE_OK and populates (*pp) with
917 ** a pointer to a new sqlite3_changegroup object before returning. The caller
918 ** should eventually free the returned object using a call to
919 ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
920 ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
922 ** The usual usage pattern for an sqlite3_changegroup object is as follows:
924 ** <ul>
925 ** <li> It is created using a call to sqlite3changegroup_new().
927 ** <li> Zero or more changesets (or patchsets) are added to the object
928 ** by calling sqlite3changegroup_add().
930 ** <li> The result of combining all input changesets together is obtained
931 ** by the application via a call to sqlite3changegroup_output().
933 ** <li> The object is deleted using a call to sqlite3changegroup_delete().
934 ** </ul>
936 ** Any number of calls to add() and output() may be made between the calls to
937 ** new() and delete(), and in any order.
939 ** As well as the regular sqlite3changegroup_add() and
940 ** sqlite3changegroup_output() functions, also available are the streaming
941 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
943 int sqlite3changegroup_new(sqlite3_changegroup **pp);
946 ** CAPI3REF: Add a Schema to a Changegroup
947 ** METHOD: sqlite3_changegroup_schema
949 ** This method may be used to optionally enforce the rule that the changesets
950 ** added to the changegroup handle must match the schema of database zDb
951 ** ("main", "temp", or the name of an attached database). If
952 ** sqlite3changegroup_add() is called to add a changeset that is not compatible
953 ** with the configured schema, SQLITE_SCHEMA is returned and the changegroup
954 ** object is left in an undefined state.
956 ** A changeset schema is considered compatible with the database schema in
957 ** the same way as for sqlite3changeset_apply(). Specifically, for each
958 ** table in the changeset, there exists a database table with:
960 ** <ul>
961 ** <li> The name identified by the changeset, and
962 ** <li> at least as many columns as recorded in the changeset, and
963 ** <li> the primary key columns in the same position as recorded in
964 ** the changeset.
965 ** </ul>
967 ** The output of the changegroup object always has the same schema as the
968 ** database nominated using this function. In cases where changesets passed
969 ** to sqlite3changegroup_add() have fewer columns than the corresponding table
970 ** in the database schema, these are filled in using the default column
971 ** values from the database schema. This makes it possible to combined
972 ** changesets that have different numbers of columns for a single table
973 ** within a changegroup, provided that they are otherwise compatible.
975 int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);
978 ** CAPI3REF: Add A Changeset To A Changegroup
979 ** METHOD: sqlite3_changegroup
981 ** Add all changes within the changeset (or patchset) in buffer pData (size
982 ** nData bytes) to the changegroup.
984 ** If the buffer contains a patchset, then all prior calls to this function
985 ** on the same changegroup object must also have specified patchsets. Or, if
986 ** the buffer contains a changeset, so must have the earlier calls to this
987 ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
988 ** to the changegroup.
990 ** Rows within the changeset and changegroup are identified by the values in
991 ** their PRIMARY KEY columns. A change in the changeset is considered to
992 ** apply to the same row as a change already present in the changegroup if
993 ** the two rows have the same primary key.
995 ** Changes to rows that do not already appear in the changegroup are
996 ** simply copied into it. Or, if both the new changeset and the changegroup
997 ** contain changes that apply to a single row, the final contents of the
998 ** changegroup depends on the type of each change, as follows:
1000 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
1001 ** <tr><th style="white-space:pre">Existing Change </th>
1002 ** <th style="white-space:pre">New Change </th>
1003 ** <th>Output Change
1004 ** <tr><td>INSERT <td>INSERT <td>
1005 ** The new change is ignored. This case does not occur if the new
1006 ** changeset was recorded immediately after the changesets already
1007 ** added to the changegroup.
1008 ** <tr><td>INSERT <td>UPDATE <td>
1009 ** The INSERT change remains in the changegroup. The values in the
1010 ** INSERT change are modified as if the row was inserted by the
1011 ** existing change and then updated according to the new change.
1012 ** <tr><td>INSERT <td>DELETE <td>
1013 ** The existing INSERT is removed from the changegroup. The DELETE is
1014 ** not added.
1015 ** <tr><td>UPDATE <td>INSERT <td>
1016 ** The new change is ignored. This case does not occur if the new
1017 ** changeset was recorded immediately after the changesets already
1018 ** added to the changegroup.
1019 ** <tr><td>UPDATE <td>UPDATE <td>
1020 ** The existing UPDATE remains within the changegroup. It is amended
1021 ** so that the accompanying values are as if the row was updated once
1022 ** by the existing change and then again by the new change.
1023 ** <tr><td>UPDATE <td>DELETE <td>
1024 ** The existing UPDATE is replaced by the new DELETE within the
1025 ** changegroup.
1026 ** <tr><td>DELETE <td>INSERT <td>
1027 ** If one or more of the column values in the row inserted by the
1028 ** new change differ from those in the row deleted by the existing
1029 ** change, the existing DELETE is replaced by an UPDATE within the
1030 ** changegroup. Otherwise, if the inserted row is exactly the same
1031 ** as the deleted row, the existing DELETE is simply discarded.
1032 ** <tr><td>DELETE <td>UPDATE <td>
1033 ** The new change is ignored. This case does not occur if the new
1034 ** changeset was recorded immediately after the changesets already
1035 ** added to the changegroup.
1036 ** <tr><td>DELETE <td>DELETE <td>
1037 ** The new change is ignored. This case does not occur if the new
1038 ** changeset was recorded immediately after the changesets already
1039 ** added to the changegroup.
1040 ** </table>
1042 ** If the new changeset contains changes to a table that is already present
1043 ** in the changegroup, then the number of columns and the position of the
1044 ** primary key columns for the table must be consistent. If this is not the
1045 ** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup
1046 ** object has been configured with a database schema using the
1047 ** sqlite3changegroup_schema() API, then it is possible to combine changesets
1048 ** with different numbers of columns for a single table, provided that
1049 ** they are otherwise compatible.
1051 ** If the input changeset appears to be corrupt and the corruption is
1052 ** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition
1053 ** occurs during processing, this function returns SQLITE_NOMEM.
1055 ** In all cases, if an error occurs the state of the final contents of the
1056 ** changegroup is undefined. If no error occurs, SQLITE_OK is returned.
1058 int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
1061 ** CAPI3REF: Add A Single Change To A Changegroup
1062 ** METHOD: sqlite3_changegroup
1064 ** This function adds the single change currently indicated by the iterator
1065 ** passed as the second argument to the changegroup object. The rules for
1066 ** adding the change are just as described for [sqlite3changegroup_add()].
1068 ** If the change is successfully added to the changegroup, SQLITE_OK is
1069 ** returned. Otherwise, an SQLite error code is returned.
1071 ** The iterator must point to a valid entry when this function is called.
1072 ** If it does not, SQLITE_ERROR is returned and no change is added to the
1073 ** changegroup. Additionally, the iterator must not have been opened with
1074 ** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also
1075 ** returned.
1077 int sqlite3changegroup_add_change(
1078 sqlite3_changegroup*,
1079 sqlite3_changeset_iter*
1085 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
1086 ** METHOD: sqlite3_changegroup
1088 ** Obtain a buffer containing a changeset (or patchset) representing the
1089 ** current contents of the changegroup. If the inputs to the changegroup
1090 ** were themselves changesets, the output is a changeset. Or, if the
1091 ** inputs were patchsets, the output is also a patchset.
1093 ** As with the output of the sqlite3session_changeset() and
1094 ** sqlite3session_patchset() functions, all changes related to a single
1095 ** table are grouped together in the output of this function. Tables appear
1096 ** in the same order as for the very first changeset added to the changegroup.
1097 ** If the second or subsequent changesets added to the changegroup contain
1098 ** changes for tables that do not appear in the first changeset, they are
1099 ** appended onto the end of the output changeset, again in the order in
1100 ** which they are first encountered.
1102 ** If an error occurs, an SQLite error code is returned and the output
1103 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
1104 ** is returned and the output variables are set to the size of and a
1105 ** pointer to the output buffer, respectively. In this case it is the
1106 ** responsibility of the caller to eventually free the buffer using a
1107 ** call to sqlite3_free().
1109 int sqlite3changegroup_output(
1110 sqlite3_changegroup*,
1111 int *pnData, /* OUT: Size of output buffer in bytes */
1112 void **ppData /* OUT: Pointer to output buffer */
1116 ** CAPI3REF: Delete A Changegroup Object
1117 ** DESTRUCTOR: sqlite3_changegroup
1119 void sqlite3changegroup_delete(sqlite3_changegroup*);
1122 ** CAPI3REF: Apply A Changeset To A Database
1124 ** Apply a changeset or patchset to a database. These functions attempt to
1125 ** update the "main" database attached to handle db with the changes found in
1126 ** the changeset passed via the second and third arguments.
1128 ** The fourth argument (xFilter) passed to these functions is the "filter
1129 ** callback". If it is not NULL, then for each table affected by at least one
1130 ** change in the changeset, the filter callback is invoked with
1131 ** the table name as the second argument, and a copy of the context pointer
1132 ** passed as the sixth argument as the first. If the "filter callback"
1133 ** returns zero, then no attempt is made to apply any changes to the table.
1134 ** Otherwise, if the return value is non-zero or the xFilter argument to
1135 ** is NULL, all changes related to the table are attempted.
1137 ** For each table that is not excluded by the filter callback, this function
1138 ** tests that the target database contains a compatible table. A table is
1139 ** considered compatible if all of the following are true:
1141 ** <ul>
1142 ** <li> The table has the same name as the name recorded in the
1143 ** changeset, and
1144 ** <li> The table has at least as many columns as recorded in the
1145 ** changeset, and
1146 ** <li> The table has primary key columns in the same position as
1147 ** recorded in the changeset.
1148 ** </ul>
1150 ** If there is no compatible table, it is not an error, but none of the
1151 ** changes associated with the table are applied. A warning message is issued
1152 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
1153 ** one such warning is issued for each table in the changeset.
1155 ** For each change for which there is a compatible table, an attempt is made
1156 ** to modify the table contents according to the UPDATE, INSERT or DELETE
1157 ** change. If a change cannot be applied cleanly, the conflict handler
1158 ** function passed as the fifth argument to sqlite3changeset_apply() may be
1159 ** invoked. A description of exactly when the conflict handler is invoked for
1160 ** each type of change is below.
1162 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
1163 ** of passing anything other than a valid function pointer as the xConflict
1164 ** argument are undefined.
1166 ** Each time the conflict handler function is invoked, it must return one
1167 ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
1168 ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
1169 ** if the second argument passed to the conflict handler is either
1170 ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
1171 ** returns an illegal value, any changes already made are rolled back and
1172 ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
1173 ** actions are taken by sqlite3changeset_apply() depending on the value
1174 ** returned by each invocation of the conflict-handler function. Refer to
1175 ** the documentation for the three
1176 ** [SQLITE_CHANGESET_OMIT|available return values] for details.
1178 ** <dl>
1179 ** <dt>DELETE Changes<dd>
1180 ** For each DELETE change, the function checks if the target database
1181 ** contains a row with the same primary key value (or values) as the
1182 ** original row values stored in the changeset. If it does, and the values
1183 ** stored in all non-primary key columns also match the values stored in
1184 ** the changeset the row is deleted from the target database.
1186 ** If a row with matching primary key values is found, but one or more of
1187 ** the non-primary key fields contains a value different from the original
1188 ** row value stored in the changeset, the conflict-handler function is
1189 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
1190 ** database table has more columns than are recorded in the changeset,
1191 ** only the values of those non-primary key fields are compared against
1192 ** the current database contents - any trailing database table columns
1193 ** are ignored.
1195 ** If no row with matching primary key values is found in the database,
1196 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
1197 ** passed as the second argument.
1199 ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
1200 ** (which can only happen if a foreign key constraint is violated), the
1201 ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
1202 ** passed as the second argument. This includes the case where the DELETE
1203 ** operation is attempted because an earlier call to the conflict handler
1204 ** function returned [SQLITE_CHANGESET_REPLACE].
1206 ** <dt>INSERT Changes<dd>
1207 ** For each INSERT change, an attempt is made to insert the new row into
1208 ** the database. If the changeset row contains fewer fields than the
1209 ** database table, the trailing fields are populated with their default
1210 ** values.
1212 ** If the attempt to insert the row fails because the database already
1213 ** contains a row with the same primary key values, the conflict handler
1214 ** function is invoked with the second argument set to
1215 ** [SQLITE_CHANGESET_CONFLICT].
1217 ** If the attempt to insert the row fails because of some other constraint
1218 ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
1219 ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
1220 ** This includes the case where the INSERT operation is re-attempted because
1221 ** an earlier call to the conflict handler function returned
1222 ** [SQLITE_CHANGESET_REPLACE].
1224 ** <dt>UPDATE Changes<dd>
1225 ** For each UPDATE change, the function checks if the target database
1226 ** contains a row with the same primary key value (or values) as the
1227 ** original row values stored in the changeset. If it does, and the values
1228 ** stored in all modified non-primary key columns also match the values
1229 ** stored in the changeset the row is updated within the target database.
1231 ** If a row with matching primary key values is found, but one or more of
1232 ** the modified non-primary key fields contains a value different from an
1233 ** original row value stored in the changeset, the conflict-handler function
1234 ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
1235 ** UPDATE changes only contain values for non-primary key fields that are
1236 ** to be modified, only those fields need to match the original values to
1237 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
1239 ** If no row with matching primary key values is found in the database,
1240 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
1241 ** passed as the second argument.
1243 ** If the UPDATE operation is attempted, but SQLite returns
1244 ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
1245 ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
1246 ** This includes the case where the UPDATE operation is attempted after
1247 ** an earlier call to the conflict handler function returned
1248 ** [SQLITE_CHANGESET_REPLACE].
1249 ** </dl>
1251 ** It is safe to execute SQL statements, including those that write to the
1252 ** table that the callback related to, from within the xConflict callback.
1253 ** This can be used to further customize the application's conflict
1254 ** resolution strategy.
1256 ** All changes made by these functions are enclosed in a savepoint transaction.
1257 ** If any other error (aside from a constraint failure when attempting to
1258 ** write to the target database) occurs, then the savepoint transaction is
1259 ** rolled back, restoring the target database to its original state, and an
1260 ** SQLite error code returned.
1262 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
1263 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
1264 ** may set (*ppRebase) to point to a "rebase" that may be used with the
1265 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
1266 ** is set to the size of the buffer in bytes. It is the responsibility of the
1267 ** caller to eventually free any such buffer using sqlite3_free(). The buffer
1268 ** is only allocated and populated if one or more conflicts were encountered
1269 ** while applying the patchset. See comments surrounding the sqlite3_rebaser
1270 ** APIs for further details.
1272 ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
1273 ** may be modified by passing a combination of
1274 ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
1276 ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
1277 ** and therefore subject to change.
1279 int sqlite3changeset_apply(
1280 sqlite3 *db, /* Apply change to "main" db of this handle */
1281 int nChangeset, /* Size of changeset in bytes */
1282 void *pChangeset, /* Changeset blob */
1283 int(*xFilter)(
1284 void *pCtx, /* Copy of sixth arg to _apply() */
1285 const char *zTab /* Table name */
1287 int(*xConflict)(
1288 void *pCtx, /* Copy of sixth arg to _apply() */
1289 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1290 sqlite3_changeset_iter *p /* Handle describing change and conflict */
1292 void *pCtx /* First argument passed to xConflict */
1294 int sqlite3changeset_apply_v2(
1295 sqlite3 *db, /* Apply change to "main" db of this handle */
1296 int nChangeset, /* Size of changeset in bytes */
1297 void *pChangeset, /* Changeset blob */
1298 int(*xFilter)(
1299 void *pCtx, /* Copy of sixth arg to _apply() */
1300 const char *zTab /* Table name */
1302 int(*xConflict)(
1303 void *pCtx, /* Copy of sixth arg to _apply() */
1304 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1305 sqlite3_changeset_iter *p /* Handle describing change and conflict */
1307 void *pCtx, /* First argument passed to xConflict */
1308 void **ppRebase, int *pnRebase, /* OUT: Rebase data */
1309 int flags /* SESSION_CHANGESETAPPLY_* flags */
1313 ** CAPI3REF: Flags for sqlite3changeset_apply_v2
1315 ** The following flags may passed via the 9th parameter to
1316 ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
1318 ** <dl>
1319 ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
1320 ** Usually, the sessions module encloses all operations performed by
1321 ** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
1322 ** SAVEPOINT is committed if the changeset or patchset is successfully
1323 ** applied, or rolled back if an error occurs. Specifying this flag
1324 ** causes the sessions module to omit this savepoint. In this case, if the
1325 ** caller has an open transaction or savepoint when apply_v2() is called,
1326 ** it may revert the partially applied changeset by rolling it back.
1328 ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
1329 ** Invert the changeset before applying it. This is equivalent to inverting
1330 ** a changeset using sqlite3changeset_invert() before applying it. It is
1331 ** an error to specify this flag with a patchset.
1333 ** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>
1334 ** Do not invoke the conflict handler callback for any changes that
1335 ** would not actually modify the database even if they were applied.
1336 ** Specifically, this means that the conflict handler is not invoked
1337 ** for:
1338 ** <ul>
1339 ** <li>a delete change if the row being deleted cannot be found,
1340 ** <li>an update change if the modified fields are already set to
1341 ** their new values in the conflicting row, or
1342 ** <li>an insert change if all fields of the conflicting row match
1343 ** the row being inserted.
1344 ** </ul>
1346 ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>
1347 ** If this flag it set, then all foreign key constraints in the target
1348 ** database behave as if they were declared with "ON UPDATE NO ACTION ON
1349 ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL
1350 ** or SET DEFAULT.
1352 #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
1353 #define SQLITE_CHANGESETAPPLY_INVERT 0x0002
1354 #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
1355 #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008
1358 ** CAPI3REF: Constants Passed To The Conflict Handler
1360 ** Values that may be passed as the second argument to a conflict-handler.
1362 ** <dl>
1363 ** <dt>SQLITE_CHANGESET_DATA<dd>
1364 ** The conflict handler is invoked with CHANGESET_DATA as the second argument
1365 ** when processing a DELETE or UPDATE change if a row with the required
1366 ** PRIMARY KEY fields is present in the database, but one or more other
1367 ** (non primary-key) fields modified by the update do not contain the
1368 ** expected "before" values.
1370 ** The conflicting row, in this case, is the database row with the matching
1371 ** primary key.
1373 ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
1374 ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
1375 ** argument when processing a DELETE or UPDATE change if a row with the
1376 ** required PRIMARY KEY fields is not present in the database.
1378 ** There is no conflicting row in this case. The results of invoking the
1379 ** sqlite3changeset_conflict() API are undefined.
1381 ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
1382 ** CHANGESET_CONFLICT is passed as the second argument to the conflict
1383 ** handler while processing an INSERT change if the operation would result
1384 ** in duplicate primary key values.
1386 ** The conflicting row in this case is the database row with the matching
1387 ** primary key.
1389 ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
1390 ** If foreign key handling is enabled, and applying a changeset leaves the
1391 ** database in a state containing foreign key violations, the conflict
1392 ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
1393 ** exactly once before the changeset is committed. If the conflict handler
1394 ** returns CHANGESET_OMIT, the changes, including those that caused the
1395 ** foreign key constraint violation, are committed. Or, if it returns
1396 ** CHANGESET_ABORT, the changeset is rolled back.
1398 ** No current or conflicting row information is provided. The only function
1399 ** it is possible to call on the supplied sqlite3_changeset_iter handle
1400 ** is sqlite3changeset_fk_conflicts().
1402 ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
1403 ** If any other constraint violation occurs while applying a change (i.e.
1404 ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
1405 ** invoked with CHANGESET_CONSTRAINT as the second argument.
1407 ** There is no conflicting row in this case. The results of invoking the
1408 ** sqlite3changeset_conflict() API are undefined.
1410 ** </dl>
1412 #define SQLITE_CHANGESET_DATA 1
1413 #define SQLITE_CHANGESET_NOTFOUND 2
1414 #define SQLITE_CHANGESET_CONFLICT 3
1415 #define SQLITE_CHANGESET_CONSTRAINT 4
1416 #define SQLITE_CHANGESET_FOREIGN_KEY 5
1419 ** CAPI3REF: Constants Returned By The Conflict Handler
1421 ** A conflict handler callback must return one of the following three values.
1423 ** <dl>
1424 ** <dt>SQLITE_CHANGESET_OMIT<dd>
1425 ** If a conflict handler returns this value no special action is taken. The
1426 ** change that caused the conflict is not applied. The session module
1427 ** continues to the next change in the changeset.
1429 ** <dt>SQLITE_CHANGESET_REPLACE<dd>
1430 ** This value may only be returned if the second argument to the conflict
1431 ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
1432 ** is not the case, any changes applied so far are rolled back and the
1433 ** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
1435 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
1436 ** handler, then the conflicting row is either updated or deleted, depending
1437 ** on the type of change.
1439 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
1440 ** handler, then the conflicting row is removed from the database and a
1441 ** second attempt to apply the change is made. If this second attempt fails,
1442 ** the original row is restored to the database before continuing.
1444 ** <dt>SQLITE_CHANGESET_ABORT<dd>
1445 ** If this value is returned, any changes applied so far are rolled back
1446 ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
1447 ** </dl>
1449 #define SQLITE_CHANGESET_OMIT 0
1450 #define SQLITE_CHANGESET_REPLACE 1
1451 #define SQLITE_CHANGESET_ABORT 2
1454 ** CAPI3REF: Rebasing changesets
1455 ** EXPERIMENTAL
1457 ** Suppose there is a site hosting a database in state S0. And that
1458 ** modifications are made that move that database to state S1 and a
1459 ** changeset recorded (the "local" changeset). Then, a changeset based
1460 ** on S0 is received from another site (the "remote" changeset) and
1461 ** applied to the database. The database is then in state
1462 ** (S1+"remote"), where the exact state depends on any conflict
1463 ** resolution decisions (OMIT or REPLACE) made while applying "remote".
1464 ** Rebasing a changeset is to update it to take those conflict
1465 ** resolution decisions into account, so that the same conflicts
1466 ** do not have to be resolved elsewhere in the network.
1468 ** For example, if both the local and remote changesets contain an
1469 ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
1471 ** local: INSERT INTO t1 VALUES(1, 'v1');
1472 ** remote: INSERT INTO t1 VALUES(1, 'v2');
1474 ** and the conflict resolution is REPLACE, then the INSERT change is
1475 ** removed from the local changeset (it was overridden). Or, if the
1476 ** conflict resolution was "OMIT", then the local changeset is modified
1477 ** to instead contain:
1479 ** UPDATE t1 SET b = 'v2' WHERE a=1;
1481 ** Changes within the local changeset are rebased as follows:
1483 ** <dl>
1484 ** <dt>Local INSERT<dd>
1485 ** This may only conflict with a remote INSERT. If the conflict
1486 ** resolution was OMIT, then add an UPDATE change to the rebased
1487 ** changeset. Or, if the conflict resolution was REPLACE, add
1488 ** nothing to the rebased changeset.
1490 ** <dt>Local DELETE<dd>
1491 ** This may conflict with a remote UPDATE or DELETE. In both cases the
1492 ** only possible resolution is OMIT. If the remote operation was a
1493 ** DELETE, then add no change to the rebased changeset. If the remote
1494 ** operation was an UPDATE, then the old.* fields of change are updated
1495 ** to reflect the new.* values in the UPDATE.
1497 ** <dt>Local UPDATE<dd>
1498 ** This may conflict with a remote UPDATE or DELETE. If it conflicts
1499 ** with a DELETE, and the conflict resolution was OMIT, then the update
1500 ** is changed into an INSERT. Any undefined values in the new.* record
1501 ** from the update change are filled in using the old.* values from
1502 ** the conflicting DELETE. Or, if the conflict resolution was REPLACE,
1503 ** the UPDATE change is simply omitted from the rebased changeset.
1505 ** If conflict is with a remote UPDATE and the resolution is OMIT, then
1506 ** the old.* values are rebased using the new.* values in the remote
1507 ** change. Or, if the resolution is REPLACE, then the change is copied
1508 ** into the rebased changeset with updates to columns also updated by
1509 ** the conflicting remote UPDATE removed. If this means no columns would
1510 ** be updated, the change is omitted.
1511 ** </dl>
1513 ** A local change may be rebased against multiple remote changes
1514 ** simultaneously. If a single key is modified by multiple remote
1515 ** changesets, they are combined as follows before the local changeset
1516 ** is rebased:
1518 ** <ul>
1519 ** <li> If there has been one or more REPLACE resolutions on a
1520 ** key, it is rebased according to a REPLACE.
1522 ** <li> If there have been no REPLACE resolutions on a key, then
1523 ** the local changeset is rebased according to the most recent
1524 ** of the OMIT resolutions.
1525 ** </ul>
1527 ** Note that conflict resolutions from multiple remote changesets are
1528 ** combined on a per-field basis, not per-row. This means that in the
1529 ** case of multiple remote UPDATE operations, some fields of a single
1530 ** local change may be rebased for REPLACE while others are rebased for
1531 ** OMIT.
1533 ** In order to rebase a local changeset, the remote changeset must first
1534 ** be applied to the local database using sqlite3changeset_apply_v2() and
1535 ** the buffer of rebase information captured. Then:
1537 ** <ol>
1538 ** <li> An sqlite3_rebaser object is created by calling
1539 ** sqlite3rebaser_create().
1540 ** <li> The new object is configured with the rebase buffer obtained from
1541 ** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
1542 ** If the local changeset is to be rebased against multiple remote
1543 ** changesets, then sqlite3rebaser_configure() should be called
1544 ** multiple times, in the same order that the multiple
1545 ** sqlite3changeset_apply_v2() calls were made.
1546 ** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
1547 ** <li> The sqlite3_rebaser object is deleted by calling
1548 ** sqlite3rebaser_delete().
1549 ** </ol>
1551 typedef struct sqlite3_rebaser sqlite3_rebaser;
1554 ** CAPI3REF: Create a changeset rebaser object.
1555 ** EXPERIMENTAL
1557 ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
1558 ** point to the new object and return SQLITE_OK. Otherwise, if an error
1559 ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
1560 ** to NULL.
1562 int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
1565 ** CAPI3REF: Configure a changeset rebaser object.
1566 ** EXPERIMENTAL
1568 ** Configure the changeset rebaser object to rebase changesets according
1569 ** to the conflict resolutions described by buffer pRebase (size nRebase
1570 ** bytes), which must have been obtained from a previous call to
1571 ** sqlite3changeset_apply_v2().
1573 int sqlite3rebaser_configure(
1574 sqlite3_rebaser*,
1575 int nRebase, const void *pRebase
1579 ** CAPI3REF: Rebase a changeset
1580 ** EXPERIMENTAL
1582 ** Argument pIn must point to a buffer containing a changeset nIn bytes
1583 ** in size. This function allocates and populates a buffer with a copy
1584 ** of the changeset rebased according to the configuration of the
1585 ** rebaser object passed as the first argument. If successful, (*ppOut)
1586 ** is set to point to the new buffer containing the rebased changeset and
1587 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1588 ** responsibility of the caller to eventually free the new buffer using
1589 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
1590 ** are set to zero and an SQLite error code returned.
1592 int sqlite3rebaser_rebase(
1593 sqlite3_rebaser*,
1594 int nIn, const void *pIn,
1595 int *pnOut, void **ppOut
1599 ** CAPI3REF: Delete a changeset rebaser object.
1600 ** EXPERIMENTAL
1602 ** Delete the changeset rebaser object and all associated resources. There
1603 ** should be one call to this function for each successful invocation
1604 ** of sqlite3rebaser_create().
1606 void sqlite3rebaser_delete(sqlite3_rebaser *p);
1609 ** CAPI3REF: Streaming Versions of API functions.
1611 ** The six streaming API xxx_strm() functions serve similar purposes to the
1612 ** corresponding non-streaming API functions:
1614 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
1615 ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
1616 ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
1617 ** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
1618 ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
1619 ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
1620 ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
1621 ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
1622 ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
1623 ** </table>
1625 ** Non-streaming functions that accept changesets (or patchsets) as input
1626 ** require that the entire changeset be stored in a single buffer in memory.
1627 ** Similarly, those that return a changeset or patchset do so by returning
1628 ** a pointer to a single large buffer allocated using sqlite3_malloc().
1629 ** Normally this is convenient. However, if an application running in a
1630 ** low-memory environment is required to handle very large changesets, the
1631 ** large contiguous memory allocations required can become onerous.
1633 ** In order to avoid this problem, instead of a single large buffer, input
1634 ** is passed to a streaming API functions by way of a callback function that
1635 ** the sessions module invokes to incrementally request input data as it is
1636 ** required. In all cases, a pair of API function parameters such as
1638 ** <pre>
1639 ** &nbsp; int nChangeset,
1640 ** &nbsp; void *pChangeset,
1641 ** </pre>
1643 ** Is replaced by:
1645 ** <pre>
1646 ** &nbsp; int (*xInput)(void *pIn, void *pData, int *pnData),
1647 ** &nbsp; void *pIn,
1648 ** </pre>
1650 ** Each time the xInput callback is invoked by the sessions module, the first
1651 ** argument passed is a copy of the supplied pIn context pointer. The second
1652 ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
1653 ** error occurs the xInput method should copy up to (*pnData) bytes of data
1654 ** into the buffer and set (*pnData) to the actual number of bytes copied
1655 ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
1656 ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
1657 ** error code should be returned. In all cases, if an xInput callback returns
1658 ** an error, all processing is abandoned and the streaming API function
1659 ** returns a copy of the error code to the caller.
1661 ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
1662 ** invoked by the sessions module at any point during the lifetime of the
1663 ** iterator. If such an xInput callback returns an error, the iterator enters
1664 ** an error state, whereby all subsequent calls to iterator functions
1665 ** immediately fail with the same error code as returned by xInput.
1667 ** Similarly, streaming API functions that return changesets (or patchsets)
1668 ** return them in chunks by way of a callback function instead of via a
1669 ** pointer to a single large buffer. In this case, a pair of parameters such
1670 ** as:
1672 ** <pre>
1673 ** &nbsp; int *pnChangeset,
1674 ** &nbsp; void **ppChangeset,
1675 ** </pre>
1677 ** Is replaced by:
1679 ** <pre>
1680 ** &nbsp; int (*xOutput)(void *pOut, const void *pData, int nData),
1681 ** &nbsp; void *pOut
1682 ** </pre>
1684 ** The xOutput callback is invoked zero or more times to return data to
1685 ** the application. The first parameter passed to each call is a copy of the
1686 ** pOut pointer supplied by the application. The second parameter, pData,
1687 ** points to a buffer nData bytes in size containing the chunk of output
1688 ** data being returned. If the xOutput callback successfully processes the
1689 ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
1690 ** it should return some other SQLite error code. In this case processing
1691 ** is immediately abandoned and the streaming API function returns a copy
1692 ** of the xOutput error code to the application.
1694 ** The sessions module never invokes an xOutput callback with the third
1695 ** parameter set to a value less than or equal to zero. Other than this,
1696 ** no guarantees are made as to the size of the chunks of data returned.
1698 int sqlite3changeset_apply_strm(
1699 sqlite3 *db, /* Apply change to "main" db of this handle */
1700 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
1701 void *pIn, /* First arg for xInput */
1702 int(*xFilter)(
1703 void *pCtx, /* Copy of sixth arg to _apply() */
1704 const char *zTab /* Table name */
1706 int(*xConflict)(
1707 void *pCtx, /* Copy of sixth arg to _apply() */
1708 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1709 sqlite3_changeset_iter *p /* Handle describing change and conflict */
1711 void *pCtx /* First argument passed to xConflict */
1713 int sqlite3changeset_apply_v2_strm(
1714 sqlite3 *db, /* Apply change to "main" db of this handle */
1715 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
1716 void *pIn, /* First arg for xInput */
1717 int(*xFilter)(
1718 void *pCtx, /* Copy of sixth arg to _apply() */
1719 const char *zTab /* Table name */
1721 int(*xConflict)(
1722 void *pCtx, /* Copy of sixth arg to _apply() */
1723 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1724 sqlite3_changeset_iter *p /* Handle describing change and conflict */
1726 void *pCtx, /* First argument passed to xConflict */
1727 void **ppRebase, int *pnRebase,
1728 int flags
1730 int sqlite3changeset_concat_strm(
1731 int (*xInputA)(void *pIn, void *pData, int *pnData),
1732 void *pInA,
1733 int (*xInputB)(void *pIn, void *pData, int *pnData),
1734 void *pInB,
1735 int (*xOutput)(void *pOut, const void *pData, int nData),
1736 void *pOut
1738 int sqlite3changeset_invert_strm(
1739 int (*xInput)(void *pIn, void *pData, int *pnData),
1740 void *pIn,
1741 int (*xOutput)(void *pOut, const void *pData, int nData),
1742 void *pOut
1744 int sqlite3changeset_start_strm(
1745 sqlite3_changeset_iter **pp,
1746 int (*xInput)(void *pIn, void *pData, int *pnData),
1747 void *pIn
1749 int sqlite3changeset_start_v2_strm(
1750 sqlite3_changeset_iter **pp,
1751 int (*xInput)(void *pIn, void *pData, int *pnData),
1752 void *pIn,
1753 int flags
1755 int sqlite3session_changeset_strm(
1756 sqlite3_session *pSession,
1757 int (*xOutput)(void *pOut, const void *pData, int nData),
1758 void *pOut
1760 int sqlite3session_patchset_strm(
1761 sqlite3_session *pSession,
1762 int (*xOutput)(void *pOut, const void *pData, int nData),
1763 void *pOut
1765 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
1766 int (*xInput)(void *pIn, void *pData, int *pnData),
1767 void *pIn
1769 int sqlite3changegroup_output_strm(sqlite3_changegroup*,
1770 int (*xOutput)(void *pOut, const void *pData, int nData),
1771 void *pOut
1773 int sqlite3rebaser_rebase_strm(
1774 sqlite3_rebaser *pRebaser,
1775 int (*xInput)(void *pIn, void *pData, int *pnData),
1776 void *pIn,
1777 int (*xOutput)(void *pOut, const void *pData, int nData),
1778 void *pOut
1782 ** CAPI3REF: Configure global parameters
1784 ** The sqlite3session_config() interface is used to make global configuration
1785 ** changes to the sessions module in order to tune it to the specific needs
1786 ** of the application.
1788 ** The sqlite3session_config() interface is not threadsafe. If it is invoked
1789 ** while any other thread is inside any other sessions method then the
1790 ** results are undefined. Furthermore, if it is invoked after any sessions
1791 ** related objects have been created, the results are also undefined.
1793 ** The first argument to the sqlite3session_config() function must be one
1794 ** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
1795 ** interpretation of the (void*) value passed as the second parameter and
1796 ** the effect of calling this function depends on the value of the first
1797 ** parameter.
1799 ** <dl>
1800 ** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>
1801 ** By default, the sessions module streaming interfaces attempt to input
1802 ** and output data in approximately 1 KiB chunks. This operand may be used
1803 ** to set and query the value of this configuration setting. The pointer
1804 ** passed as the second argument must point to a value of type (int).
1805 ** If this value is greater than 0, it is used as the new streaming data
1806 ** chunk size for both input and output. Before returning, the (int) value
1807 ** pointed to by pArg is set to the final value of the streaming interface
1808 ** chunk size.
1809 ** </dl>
1811 ** This function returns SQLITE_OK if successful, or an SQLite error code
1812 ** otherwise.
1814 int sqlite3session_config(int op, void *pArg);
1817 ** CAPI3REF: Values for sqlite3session_config().
1819 #define SQLITE_SESSION_CONFIG_STRMSIZE 1
1822 ** Make sure we can call this stuff from C++.
1824 #ifdef __cplusplus
1826 #endif
1828 #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */