xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3session_diff.3 (revision 022f005200bc25af02826a05c8d86d0ef18232dc)
1.Dd March 11, 2017
2.Dt SQLITE3SESSION_DIFF 3
3.Os
4.Sh NAME
5.Nm sqlite3session_diff
6.Nd Load The Difference Between Tables Into A Session
7.Sh SYNOPSIS
8.Ft int
9.Fo sqlite3session_diff
10.Fa "sqlite3_session *pSession"
11.Fa "const char *zFromDb"
12.Fa "const char *zTbl"
13.Fa "char **pzErrMsg "
14.Fc
15.Sh DESCRIPTION
16If it is not already attached to the session object passed as the first
17argument, this function attaches table zTbl in the same manner as the
18sqlite3session_attach() function.
19If zTbl does not exist, or if it does not have a primary key, this
20function is a no-op (but does not return an error).
21.Pp
22Argument zFromDb must be the name of a database ("main", "temp" etc.)
23attached to the same database handle as the session object that contains
24a table compatible with the table attached to the session by this function.
25A table is considered compatible if it:
26.Bl -bullet
27.It
28Has the same name,
29.It
30Has the same set of columns declared in the same order, and
31.It
32Has the same PRIMARY KEY definition.
33.El
34.Pp
35If the tables are not compatible, SQLITE_SCHEMA is returned.
36If the tables are compatible but do not have any PRIMARY KEY columns,
37it is not an error but no changes are added to the session object.
38As with other session APIs, tables without PRIMARY KEYs are simply
39ignored.
40.Pp
41This function adds a set of changes to the session object that could
42be used to update the table in database zFrom (call this the "from-table")
43so that its content is the same as the table attached to the session
44object (call this the "to-table").
45Specifically:
46.Bl -bullet
47.It
48For each row (primary key) that exists in the to-table but not in the
49from-table, an INSERT record is added to the session object.
50.It
51For each row (primary key) that exists in the to-table but not in the
52from-table, a DELETE record is added to the session object.
53.It
54For each row (primary key) that exists in both tables, but features
55different non-PK values in each, an UPDATE record is added to the session.
56.El
57.Pp
58To clarify, if this function is called and then a changeset constructed
59using sqlite3session_changeset(), then after
60applying that changeset to database zFrom the contents of the two compatible
61tables would be identical.
62.Pp
63It an error if database zFrom does not exist or does not contain the
64required compatible table.
65.Pp
66If the operation successful, SQLITE_OK is returned.
67Otherwise, an SQLite error code.
68In this case, if argument pzErrMsg is not NULL, *pzErrMsg may be set
69to point to a buffer containing an English language error message.
70It is the responsibility of the caller to free this buffer using sqlite3_free().
71.Sh SEE ALSO
72.Xr sqlite3session_attach 3 ,
73.Xr sqlite3session_changeset 3
74