会话模块 C 接口

将变更集添加到变更组

int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);

将缓冲区 pData(大小为 nData 字节)中的变更集(或补丁集)内的所有更改添加到变更组。

如果缓冲区包含一个补丁集,那么在同一变更组对象上对该函数的所有先前调用也必须具有指定的补丁集。或者,如果缓冲区包含变更集,则必须更早地调用此函数。否则,将返回 SQLITE_ERROR 并且不会向变更组添加任何变更。

变更集和变更组中的行由其 PRIMARY KEY 列中的值标识。如果两行具有相同的主键,则认为变更集中的变更应用于与变更组中已存在的变更相同的行。

对尚未出现在更改组中的行所做的更改将简单地复制到其中。或者,如果新的变更集和变更组都包含应用于单个行的变更,则变更组的最终内容取决于每个变更的类型,如下所示:

Existing Change New Change Output Change
INSERT INSERT The new change is ignored. This case does not occur if the new changeset was recorded immediately after the changesets already added to the changegroup.
INSERT UPDATE The INSERT change remains in the changegroup. The values in the INSERT change are modified as if the row was inserted by the existing change and then updated according to the new change.
INSERT DELETE The existing INSERT is removed from the changegroup. The DELETE is not added.
UPDATE INSERT The new change is ignored. This case does not occur if the new changeset was recorded immediately after the changesets already added to the changegroup.
UPDATE UPDATE The existing UPDATE remains within the changegroup. It is amended so that the accompanying values are as if the row was updated once by the existing change and then again by the new change.
UPDATE DELETE The existing UPDATE is replaced by the new DELETE within the changegroup.
DELETE INSERT If one or more of the column values in the row inserted by the new change differ from those in the row deleted by the existing change, the existing DELETE is replaced by an UPDATE within the changegroup. Otherwise, if the inserted row is exactly the same as the deleted row, the existing DELETE is simply discarded.
DELETE UPDATE The new change is ignored. This case does not occur if the new changeset was recorded immediately after the changesets already added to the changegroup.
DELETE DELETE The new change is ignored. This case does not occur if the new changeset was recorded immediately after the changesets already added to the changegroup.

如果新的变更集包含对已存在于变更组中的表的更改,则该表的列数和主键列的位置必须一致。如果不是这种情况,则此函数将失败并返回 SQLITE_SCHEMA。如果输入变更集似乎已损坏并且检测到损坏,则返回 SQLITE_CORRUPT。或者,如果在处理过程中出现内存不足的情况,此函数将返回 SQLITE_NOMEM。在所有情况下,如果发生错误,则更改组的最终内容的状态是未定义的。

如果没有错误发生,则返回 SQLITE_OK。

另请参阅 对象常量函数的列表。