| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 4 |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| 5 |
<link href="sqlite.css" rel="stylesheet"> |
| 6 |
<title>SQLite Session Module C/C++ Interface</title> |
| 7 |
<!-- path= --> |
| 8 |
</head> |
| 9 |
<body> |
| 10 |
<div class=nosearch> |
| 11 |
<a href="index.html"> |
| 12 |
<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0"> |
| 13 |
</a> |
| 14 |
<div><!-- IE hack to prevent disappearing logo --></div> |
| 15 |
<div class="tagline desktoponly"> |
| 16 |
Small. Fast. Reliable.<br>Choose any three. |
| 17 |
</div> |
| 18 |
<div class="menu mainmenu"> |
| 19 |
<ul> |
| 20 |
<li><a href="index.html">Home</a> |
| 21 |
<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a> |
| 22 |
<li class='wideonly'><a href='about.html'>About</a> |
| 23 |
<li class='desktoponly'><a href="docs.html">Documentation</a> |
| 24 |
<li class='desktoponly'><a href="download.html">Download</a> |
| 25 |
<li class='wideonly'><a href='copyright.html'>License</a> |
| 26 |
<li class='desktoponly'><a href="support.html">Support</a> |
| 27 |
<li class='desktoponly'><a href="prosupport.html">Purchase</a> |
| 28 |
<li class='search' id='search_menubutton'> |
| 29 |
<a href="javascript:void(0)" onclick='toggle_search()'>Search</a> |
| 30 |
</ul> |
| 31 |
</div> |
| 32 |
<div class="menu submenu" id="submenu"> |
| 33 |
<ul> |
| 34 |
<li><a href='about.html'>About</a> |
| 35 |
<li><a href='docs.html'>Documentation</a> |
| 36 |
<li><a href='download.html'>Download</a> |
| 37 |
<li><a href='support.html'>Support</a> |
| 38 |
<li><a href='prosupport.html'>Purchase</a> |
| 39 |
</ul> |
| 40 |
</div> |
| 41 |
<div class="searchmenu" id="searchmenu"> |
| 42 |
<form method="GET" action="search"> |
| 43 |
<select name="s" id="searchtype"> |
| 44 |
<option value="d">Search Documentation</option> |
| 45 |
<option value="c">Search Changelog</option> |
| 46 |
</select> |
| 47 |
<input type="text" name="q" id="searchbox" value=""> |
| 48 |
<input type="submit" value="Go"> |
| 49 |
</form> |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
<script> |
| 53 |
function toggle_div(nm) { |
| 54 |
var w = document.getElementById(nm); |
| 55 |
if( w.style.display=="block" ){ |
| 56 |
w.style.display = "none"; |
| 57 |
}else{ |
| 58 |
w.style.display = "block"; |
| 59 |
} |
| 60 |
} |
| 61 |
function toggle_search() { |
| 62 |
var w = document.getElementById("searchmenu"); |
| 63 |
if( w.style.display=="block" ){ |
| 64 |
w.style.display = "none"; |
| 65 |
} else { |
| 66 |
w.style.display = "block"; |
| 67 |
setTimeout(function(){ |
| 68 |
document.getElementById("searchbox").focus() |
| 69 |
}, 30); |
| 70 |
} |
| 71 |
} |
| 72 |
function div_off(nm){document.getElementById(nm).style.display="none";} |
| 73 |
window.onbeforeunload = function(e){div_off("submenu");} |
| 74 |
/* Disable the Search feature if we are not operating from CGI, since */ |
| 75 |
/* Search is accomplished using CGI and will not work without it. */ |
| 76 |
if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){ |
| 77 |
document.getElementById("search_menubutton").style.display = "none"; |
| 78 |
} |
| 79 |
/* Used by the Hide/Show button beside syntax diagrams, to toggle the */ |
| 80 |
function hideorshow(btn,obj){ |
| 81 |
var x = document.getElementById(obj); |
| 82 |
var b = document.getElementById(btn); |
| 83 |
if( x.style.display!='none' ){ |
| 84 |
x.style.display = 'none'; |
| 85 |
b.innerHTML='show'; |
| 86 |
}else{ |
| 87 |
x.style.display = ''; |
| 88 |
b.innerHTML='hide'; |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
var antiRobot = 0; |
| 93 |
function antiRobotGo(){ |
| 94 |
if( antiRobot!=3 ) return; |
| 95 |
antiRobot = 7; |
| 96 |
var j = document.getElementById("mtimelink"); |
| 97 |
if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href"); |
| 98 |
} |
| 99 |
function antiRobotDefense(){ |
| 100 |
document.body.onmousedown=function(){ |
| 101 |
antiRobot |= 2; |
| 102 |
antiRobotGo(); |
| 103 |
document.body.onmousedown=null; |
| 104 |
} |
| 105 |
document.body.onmousemove=function(){ |
| 106 |
antiRobot |= 2; |
| 107 |
antiRobotGo(); |
| 108 |
document.body.onmousemove=null; |
| 109 |
} |
| 110 |
setTimeout(function(){ |
| 111 |
antiRobot |= 1; |
| 112 |
antiRobotGo(); |
| 113 |
}, 100) |
| 114 |
antiRobotGo(); |
| 115 |
} |
| 116 |
antiRobotDefense(); |
| 117 |
</script> |
| 118 |
|
| 119 |
|
| 120 |
<h2>SQLite Session Module C/C++ Interface</h2> |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
<p>This page defines the C-language interface to the SQLite |
| 125 |
<a href="sessionintro.html">session extension</a>. |
| 126 |
This is not a tutorial. These pages are designed to be precise, not easy |
| 127 |
to read. A tutorial is <a href="sessionintro.html">available separately</a>. |
| 128 |
|
| 129 |
<p>This page contains all C-language interface information |
| 130 |
in a single HTML file. The same information is also available |
| 131 |
broken out into <a href="../session/intro.html">some smaller pages</a> |
| 132 |
for easier viewing, if you prefer.</p> |
| 133 |
|
| 134 |
<p>This document is created by a script which scans comments in the source |
| 135 |
code file sqlite3session.h.</p> |
| 136 |
|
| 137 |
<hr> |
| 138 |
|
| 139 |
|
| 140 |
<h2>Objects:</h2> |
| 141 |
<div class='columns' style='columns: 15em auto;'> |
| 142 |
<ul style='padding-top:0;'> |
| 143 |
<li><a href='#sqlite3_changegroup'>sqlite3_changegroup</a></li> |
| 144 |
<li><a href='#sqlite3_changeset_iter'>sqlite3_changeset_iter</a></li> |
| 145 |
<li><a href='#sqlite3_rebaser'>sqlite3_rebaser<small><i>(exp)</i></small></a></li> |
| 146 |
<li><a href='#sqlite3_session'>sqlite3_session</a></li> |
| 147 |
</ul> |
| 148 |
</div> |
| 149 |
<hr> |
| 150 |
|
| 151 |
<h2>Constants:</h2> |
| 152 |
<div class='columns' style='columns: 20em auto;'> |
| 153 |
<ul style='padding-top:0;'> |
| 154 |
<li><a href='#SQLITE_CHANGESETAPPLY_FKNOACTION'>SQLITE_CHANGESETAPPLY_FKNOACTION</a></li> |
| 155 |
<li><a href='#SQLITE_CHANGESETAPPLY_FKNOACTION'>SQLITE_CHANGESETAPPLY_IGNORENOOP</a></li> |
| 156 |
<li><a href='#SQLITE_CHANGESETAPPLY_FKNOACTION'>SQLITE_CHANGESETAPPLY_INVERT</a></li> |
| 157 |
<li><a href='#SQLITE_CHANGESETAPPLY_FKNOACTION'>SQLITE_CHANGESETAPPLY_NOSAVEPOINT</a></li> |
| 158 |
<li><a href='#SQLITE_CHANGESETSTART_INVERT'>SQLITE_CHANGESETSTART_INVERT</a></li> |
| 159 |
<li><a href='#SQLITE_CHANGESET_ABORT'>SQLITE_CHANGESET_ABORT</a></li> |
| 160 |
<li><a href='#SQLITE_CHANGESET_CONFLICT'>SQLITE_CHANGESET_CONFLICT</a></li> |
| 161 |
<li><a href='#SQLITE_CHANGESET_CONFLICT'>SQLITE_CHANGESET_CONSTRAINT</a></li> |
| 162 |
<li><a href='#SQLITE_CHANGESET_CONFLICT'>SQLITE_CHANGESET_DATA</a></li> |
| 163 |
<li><a href='#SQLITE_CHANGESET_CONFLICT'>SQLITE_CHANGESET_FOREIGN_KEY</a></li> |
| 164 |
<li><a href='#SQLITE_CHANGESET_CONFLICT'>SQLITE_CHANGESET_NOTFOUND</a></li> |
| 165 |
<li><a href='#SQLITE_CHANGESET_ABORT'>SQLITE_CHANGESET_OMIT</a></li> |
| 166 |
<li><a href='#SQLITE_CHANGESET_ABORT'>SQLITE_CHANGESET_REPLACE</a></li> |
| 167 |
<li><a href='#SQLITE_SESSION_CONFIG_STRMSIZE'>SQLITE_SESSION_CONFIG_STRMSIZE</a></li> |
| 168 |
<li><a href='#SQLITE_SESSION_OBJCONFIG_ROWID'>SQLITE_SESSION_OBJCONFIG_ROWID</a></li> |
| 169 |
<li><a href='#SQLITE_SESSION_OBJCONFIG_ROWID'>SQLITE_SESSION_OBJCONFIG_SIZE</a></li> |
| 170 |
</ul> |
| 171 |
</div> |
| 172 |
<hr> |
| 173 |
|
| 174 |
<h2>Functions:</h2> |
| 175 |
<div class='columns' style='columns: 15em auto;'> |
| 176 |
<ul style='padding-top:0;'> |
| 177 |
<li><a href='#sqlite3changegroup_add'>sqlite3changegroup_add</a></li> |
| 178 |
<li><a href='#sqlite3changegroup_add_change'>sqlite3changegroup_add_change</a></li> |
| 179 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changegroup_add_strm</a></li> |
| 180 |
<li><a href='#sqlite3changegroup_delete'>sqlite3changegroup_delete</a></li> |
| 181 |
<li><a href='#sqlite3changegroup_new'>sqlite3changegroup_new</a></li> |
| 182 |
<li><a href='#sqlite3changegroup_output'>sqlite3changegroup_output</a></li> |
| 183 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changegroup_output_strm</a></li> |
| 184 |
<li><a href='#sqlite3changegroup_schema'>sqlite3changegroup_schema</a></li> |
| 185 |
<li><a href='#sqlite3changeset_apply'>sqlite3changeset_apply</a></li> |
| 186 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_apply_strm</a></li> |
| 187 |
<li><a href='#sqlite3changeset_apply'>sqlite3changeset_apply_v2</a></li> |
| 188 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_apply_v2_strm</a></li> |
| 189 |
<li><a href='#sqlite3changeset_concat'>sqlite3changeset_concat</a></li> |
| 190 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_concat_strm</a></li> |
| 191 |
<li><a href='#sqlite3changeset_conflict'>sqlite3changeset_conflict</a></li> |
| 192 |
<li><a href='#sqlite3changeset_finalize'>sqlite3changeset_finalize</a></li> |
| 193 |
<li><a href='#sqlite3changeset_fk_conflicts'>sqlite3changeset_fk_conflicts</a></li> |
| 194 |
<li><a href='#sqlite3changeset_invert'>sqlite3changeset_invert</a></li> |
| 195 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_invert_strm</a></li> |
| 196 |
<li><a href='#sqlite3changeset_new'>sqlite3changeset_new</a></li> |
| 197 |
<li><a href='#sqlite3changeset_next'>sqlite3changeset_next</a></li> |
| 198 |
<li><a href='#sqlite3changeset_old'>sqlite3changeset_old</a></li> |
| 199 |
<li><a href='#sqlite3changeset_op'>sqlite3changeset_op</a></li> |
| 200 |
<li><a href='#sqlite3changeset_pk'>sqlite3changeset_pk</a></li> |
| 201 |
<li><a href='#sqlite3changeset_start'>sqlite3changeset_start</a></li> |
| 202 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_start_strm</a></li> |
| 203 |
<li><a href='#sqlite3changeset_start'>sqlite3changeset_start_v2</a></li> |
| 204 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3changeset_start_v2_strm</a></li> |
| 205 |
<li><a href='#sqlite3changeset_upgrade'>sqlite3changeset_upgrade</a></li> |
| 206 |
<li><a href='#sqlite3rebaser_configure'>sqlite3rebaser_configure<small><i>(exp)</i></small></a></li> |
| 207 |
<li><a href='#sqlite3rebaser_create'>sqlite3rebaser_create<small><i>(exp)</i></small></a></li> |
| 208 |
<li><a href='#sqlite3rebaser_delete'>sqlite3rebaser_delete<small><i>(exp)</i></small></a></li> |
| 209 |
<li><a href='#sqlite3rebaser_rebase'>sqlite3rebaser_rebase<small><i>(exp)</i></small></a></li> |
| 210 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3rebaser_rebase_strm</a></li> |
| 211 |
<li><a href='#sqlite3session_attach'>sqlite3session_attach</a></li> |
| 212 |
<li><a href='#sqlite3session_changeset'>sqlite3session_changeset</a></li> |
| 213 |
<li><a href='#sqlite3session_changeset_size'>sqlite3session_changeset_size</a></li> |
| 214 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3session_changeset_strm</a></li> |
| 215 |
<li><a href='#sqlite3session_config'>sqlite3session_config</a></li> |
| 216 |
<li><a href='#sqlite3session_create'>sqlite3session_create</a></li> |
| 217 |
<li><a href='#sqlite3session_delete'>sqlite3session_delete</a></li> |
| 218 |
<li><a href='#sqlite3session_diff'>sqlite3session_diff</a></li> |
| 219 |
<li><a href='#sqlite3session_enable'>sqlite3session_enable</a></li> |
| 220 |
<li><a href='#sqlite3session_indirect'>sqlite3session_indirect</a></li> |
| 221 |
<li><a href='#sqlite3session_isempty'>sqlite3session_isempty</a></li> |
| 222 |
<li><a href='#sqlite3session_memory_used'>sqlite3session_memory_used</a></li> |
| 223 |
<li><a href='#sqlite3session_object_config'>sqlite3session_object_config</a></li> |
| 224 |
<li><a href='#sqlite3session_patchset'>sqlite3session_patchset</a></li> |
| 225 |
<li><a href='#sqlite3changegroup_add_strm'>sqlite3session_patchset_strm</a></li> |
| 226 |
<li><a href='#sqlite3session_table_filter'>sqlite3session_table_filter</a></li> |
| 227 |
</ul> |
| 228 |
</div> |
| 229 |
<hr> |
| 230 |
<a name="SQLITE_CHANGESETSTART_INVERT"></a> |
| 231 |
<h2>Flags for sqlite3changeset_start_v2</h2><blockquote><pre>#define SQLITE_CHANGESETSTART_INVERT 0x0002 |
| 232 |
</pre></blockquote><p> |
| 233 |
The following flags may passed via the 4th parameter to |
| 234 |
<a href="#sqlite3changeset_start">sqlite3changeset_start_v2</a> and <a href="#sqlite3changegroup_add_strm">sqlite3changeset_start_v2_strm</a>:</p> |
| 235 |
|
| 236 |
<p><dt>SQLITE_CHANGESETAPPLY_INVERT <dd> |
| 237 |
Invert the changeset while iterating through it. This is equivalent to |
| 238 |
inverting a changeset using sqlite3changeset_invert() before applying it. |
| 239 |
It is an error to specify this flag with a patchset. |
| 240 |
</p><hr><a name="SQLITE_SESSION_CONFIG_STRMSIZE"></a> |
| 241 |
<h2>Values for sqlite3session_config().</h2><blockquote><pre>#define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 242 |
</pre></blockquote><p></p><hr><a name="sqlite3_changegroup"></a> |
| 243 |
<h2>Changegroup Handle</h2><blockquote><pre>typedef struct sqlite3_changegroup sqlite3_changegroup; |
| 244 |
</pre></blockquote><p> |
| 245 |
A changegroup is an object used to combine two or more |
| 246 |
<a href="sessionintro.html#changeset">changesets</a> or <a href="sessionintro.html#changeset">patchsets</a> |
| 247 |
</p><p>Constructor: <a href="#sqlite3changegroup_new">sqlite3changegroup_new()</a></p> |
| 248 |
<p>Destructor: <a href="#sqlite3changegroup_delete">sqlite3changegroup_delete()</a></p> |
| 249 |
<p>Methods: |
| 250 |
<a href="#sqlite3changegroup_add">sqlite3changegroup_add()</a>, |
| 251 |
<a href="#sqlite3changegroup_add_change">sqlite3changegroup_add_change()</a>, |
| 252 |
<a href="#sqlite3changegroup_output">sqlite3changegroup_output()</a></p> |
| 253 |
<hr><a name="sqlite3_changeset_iter"></a> |
| 254 |
<h2>Changeset Iterator Handle</h2><blockquote><pre>typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; |
| 255 |
</pre></blockquote><p> |
| 256 |
An instance of this object acts as a cursor for iterating |
| 257 |
over the elements of a <a href="sessionintro.html#changeset">changeset</a> or <a href="sessionintro.html#changeset">patchset</a>. |
| 258 |
</p><p>Constructors: |
| 259 |
<a href="#sqlite3changeset_start">sqlite3changeset_start()</a>, |
| 260 |
<a href="#sqlite3changeset_start">sqlite3changeset_start_v2()</a></p> |
| 261 |
<div class='columns' style='columns: 17em auto;'> |
| 262 |
<ul style='padding-top:0;'> |
| 263 |
<li><a href='#sqlite3changeset_conflict'>sqlite3changeset_conflict</a></li> |
| 264 |
<li><a href='#sqlite3changeset_finalize'>sqlite3changeset_finalize</a></li> |
| 265 |
<li><a href='#sqlite3changeset_fk_conflicts'>sqlite3changeset_fk_conflicts</a></li> |
| 266 |
<li><a href='#sqlite3changeset_new'>sqlite3changeset_new</a></li> |
| 267 |
<li><a href='#sqlite3changeset_next'>sqlite3changeset_next</a></li> |
| 268 |
<li><a href='#sqlite3changeset_old'>sqlite3changeset_old</a></li> |
| 269 |
<li><a href='#sqlite3changeset_op'>sqlite3changeset_op</a></li> |
| 270 |
<li><a href='#sqlite3changeset_pk'>sqlite3changeset_pk</a></li> |
| 271 |
</ul> |
| 272 |
</div> |
| 273 |
</p> |
| 274 |
<hr><a name="sqlite3_rebaser"></a> |
| 275 |
<h2>Rebasing changesets</h2><blockquote><pre>typedef struct sqlite3_rebaser sqlite3_rebaser; |
| 276 |
</pre></blockquote><p><b>Important:</b> This interface is <a href="c3ref/experimental.html">experimental</a> and is subject to change without notice.</p><p> |
| 277 |
Suppose there is a site hosting a database in state S0. And that |
| 278 |
modifications are made that move that database to state S1 and a |
| 279 |
changeset recorded (the "local" changeset). Then, a changeset based |
| 280 |
on S0 is received from another site (the "remote" changeset) and |
| 281 |
applied to the database. The database is then in state |
| 282 |
(S1+"remote"), where the exact state depends on any conflict |
| 283 |
resolution decisions (OMIT or REPLACE) made while applying "remote". |
| 284 |
Rebasing a changeset is to update it to take those conflict |
| 285 |
resolution decisions into account, so that the same conflicts |
| 286 |
do not have to be resolved elsewhere in the network. </p> |
| 287 |
|
| 288 |
<p>For example, if both the local and remote changesets contain an |
| 289 |
INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":</p> |
| 290 |
|
| 291 |
<p> local: INSERT INTO t1 VALUES(1, 'v1'); |
| 292 |
remote: INSERT INTO t1 VALUES(1, 'v2');</p> |
| 293 |
|
| 294 |
<p>and the conflict resolution is REPLACE, then the INSERT change is |
| 295 |
removed from the local changeset (it was overridden). Or, if the |
| 296 |
conflict resolution was "OMIT", then the local changeset is modified |
| 297 |
to instead contain:</p> |
| 298 |
|
| 299 |
<p> UPDATE t1 SET b = 'v2' WHERE a=1;</p> |
| 300 |
|
| 301 |
<p>Changes within the local changeset are rebased as follows:</p> |
| 302 |
|
| 303 |
<p><dl> |
| 304 |
<dt>Local INSERT<dd> |
| 305 |
This may only conflict with a remote INSERT. If the conflict |
| 306 |
resolution was OMIT, then add an UPDATE change to the rebased |
| 307 |
changeset. Or, if the conflict resolution was REPLACE, add |
| 308 |
nothing to the rebased changeset.</p> |
| 309 |
|
| 310 |
<p><dt>Local DELETE<dd> |
| 311 |
This may conflict with a remote UPDATE or DELETE. In both cases the |
| 312 |
only possible resolution is OMIT. If the remote operation was a |
| 313 |
DELETE, then add no change to the rebased changeset. If the remote |
| 314 |
operation was an UPDATE, then the old.* fields of change are updated |
| 315 |
to reflect the new.* values in the UPDATE.</p> |
| 316 |
|
| 317 |
<p><dt>Local UPDATE<dd> |
| 318 |
This may conflict with a remote UPDATE or DELETE. If it conflicts |
| 319 |
with a DELETE, and the conflict resolution was OMIT, then the update |
| 320 |
is changed into an INSERT. Any undefined values in the new.* record |
| 321 |
from the update change are filled in using the old.* values from |
| 322 |
the conflicting DELETE. Or, if the conflict resolution was REPLACE, |
| 323 |
the UPDATE change is simply omitted from the rebased changeset.</p> |
| 324 |
|
| 325 |
<p> If conflict is with a remote UPDATE and the resolution is OMIT, then |
| 326 |
the old.* values are rebased using the new.* values in the remote |
| 327 |
change. Or, if the resolution is REPLACE, then the change is copied |
| 328 |
into the rebased changeset with updates to columns also updated by |
| 329 |
the conflicting remote UPDATE removed. If this means no columns would |
| 330 |
be updated, the change is omitted. |
| 331 |
</dl></p> |
| 332 |
|
| 333 |
<p>A local change may be rebased against multiple remote changes |
| 334 |
simultaneously. If a single key is modified by multiple remote |
| 335 |
changesets, they are combined as follows before the local changeset |
| 336 |
is rebased:</p> |
| 337 |
|
| 338 |
<p><ul> |
| 339 |
<li> If there has been one or more REPLACE resolutions on a |
| 340 |
key, it is rebased according to a REPLACE.</p> |
| 341 |
|
| 342 |
<p> <li> If there have been no REPLACE resolutions on a key, then |
| 343 |
the local changeset is rebased according to the most recent |
| 344 |
of the OMIT resolutions. |
| 345 |
</ul></p> |
| 346 |
|
| 347 |
<p>Note that conflict resolutions from multiple remote changesets are |
| 348 |
combined on a per-field basis, not per-row. This means that in the |
| 349 |
case of multiple remote UPDATE operations, some fields of a single |
| 350 |
local change may be rebased for REPLACE while others are rebased for |
| 351 |
OMIT.</p> |
| 352 |
|
| 353 |
<p>In order to rebase a local changeset, the remote changeset must first |
| 354 |
be applied to the local database using sqlite3changeset_apply_v2() and |
| 355 |
the buffer of rebase information captured. Then:</p> |
| 356 |
|
| 357 |
<p><ol> |
| 358 |
<li> An sqlite3_rebaser object is created by calling |
| 359 |
sqlite3rebaser_create(). |
| 360 |
<li> The new object is configured with the rebase buffer obtained from |
| 361 |
sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure(). |
| 362 |
If the local changeset is to be rebased against multiple remote |
| 363 |
changesets, then sqlite3rebaser_configure() should be called |
| 364 |
multiple times, in the same order that the multiple |
| 365 |
sqlite3changeset_apply_v2() calls were made. |
| 366 |
<li> Each local changeset is rebased by calling sqlite3rebaser_rebase(). |
| 367 |
<li> The sqlite3_rebaser object is deleted by calling |
| 368 |
sqlite3rebaser_delete(). |
| 369 |
</ol> |
| 370 |
</p><hr><a name="sqlite3_session"></a> |
| 371 |
<h2>Session Object Handle</h2><blockquote><pre>typedef struct sqlite3_session sqlite3_session; |
| 372 |
</pre></blockquote><p> |
| 373 |
An instance of this object is a <a href="sessionintro.html">session</a> that can be used to |
| 374 |
record changes to a database. |
| 375 |
</p><p>Constructor: <a href="#sqlite3session_create">sqlite3session_create()</a></p> |
| 376 |
<p>Destructor: <a href="#sqlite3session_delete">sqlite3session_delete()</a></p> |
| 377 |
<div class='columns' style='columns: 17em auto;'> |
| 378 |
<ul style='padding-top:0;'> |
| 379 |
<li><a href='#sqlite3session_attach'>sqlite3session_attach</a></li> |
| 380 |
<li><a href='#sqlite3session_changeset'>sqlite3session_changeset</a></li> |
| 381 |
<li><a href='#sqlite3session_changeset_size'>sqlite3session_changeset_size</a></li> |
| 382 |
<li><a href='#sqlite3session_diff'>sqlite3session_diff</a></li> |
| 383 |
<li><a href='#sqlite3session_enable'>sqlite3session_enable</a></li> |
| 384 |
<li><a href='#sqlite3session_indirect'>sqlite3session_indirect</a></li> |
| 385 |
<li><a href='#sqlite3session_object_config'>sqlite3session_object_config</a></li> |
| 386 |
<li><a href='#sqlite3session_patchset'>sqlite3session_patchset</a></li> |
| 387 |
<li><a href='#sqlite3session_table_filter'>sqlite3session_table_filter</a></li> |
| 388 |
</ul> |
| 389 |
</div> |
| 390 |
</p> |
| 391 |
<hr><a name="sqlite3changegroup_add"></a> |
| 392 |
<h2>Add A Changeset To A Changegroup</h2><blockquote><pre>int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); |
| 393 |
</pre></blockquote><p> |
| 394 |
Add all changes within the changeset (or patchset) in buffer pData (size |
| 395 |
nData bytes) to the changegroup. </p> |
| 396 |
|
| 397 |
<p>If the buffer contains a patchset, then all prior calls to this function |
| 398 |
on the same changegroup object must also have specified patchsets. Or, if |
| 399 |
the buffer contains a changeset, so must have the earlier calls to this |
| 400 |
function. Otherwise, SQLITE_ERROR is returned and no changes are added |
| 401 |
to the changegroup.</p> |
| 402 |
|
| 403 |
<p>Rows within the changeset and changegroup are identified by the values in |
| 404 |
their PRIMARY KEY columns. A change in the changeset is considered to |
| 405 |
apply to the same row as a change already present in the changegroup if |
| 406 |
the two rows have the same primary key.</p> |
| 407 |
|
| 408 |
<p>Changes to rows that do not already appear in the changegroup are |
| 409 |
simply copied into it. Or, if both the new changeset and the changegroup |
| 410 |
contain changes that apply to a single row, the final contents of the |
| 411 |
changegroup depends on the type of each change, as follows:</p> |
| 412 |
|
| 413 |
<p><table border=1 style="margin-left:8ex;margin-right:8ex"> |
| 414 |
<tr><th style="white-space:pre">Existing Change </th> |
| 415 |
<th style="white-space:pre">New Change </th> |
| 416 |
<th>Output Change |
| 417 |
<tr><td>INSERT <td>INSERT <td> |
| 418 |
The new change is ignored. This case does not occur if the new |
| 419 |
changeset was recorded immediately after the changesets already |
| 420 |
added to the changegroup. |
| 421 |
<tr><td>INSERT <td>UPDATE <td> |
| 422 |
The INSERT change remains in the changegroup. The values in the |
| 423 |
INSERT change are modified as if the row was inserted by the |
| 424 |
existing change and then updated according to the new change. |
| 425 |
<tr><td>INSERT <td>DELETE <td> |
| 426 |
The existing INSERT is removed from the changegroup. The DELETE is |
| 427 |
not added. |
| 428 |
<tr><td>UPDATE <td>INSERT <td> |
| 429 |
The new change is ignored. This case does not occur if the new |
| 430 |
changeset was recorded immediately after the changesets already |
| 431 |
added to the changegroup. |
| 432 |
<tr><td>UPDATE <td>UPDATE <td> |
| 433 |
The existing UPDATE remains within the changegroup. It is amended |
| 434 |
so that the accompanying values are as if the row was updated once |
| 435 |
by the existing change and then again by the new change. |
| 436 |
<tr><td>UPDATE <td>DELETE <td> |
| 437 |
The existing UPDATE is replaced by the new DELETE within the |
| 438 |
changegroup. |
| 439 |
<tr><td>DELETE <td>INSERT <td> |
| 440 |
If one or more of the column values in the row inserted by the |
| 441 |
new change differ from those in the row deleted by the existing |
| 442 |
change, the existing DELETE is replaced by an UPDATE within the |
| 443 |
changegroup. Otherwise, if the inserted row is exactly the same |
| 444 |
as the deleted row, the existing DELETE is simply discarded. |
| 445 |
<tr><td>DELETE <td>UPDATE <td> |
| 446 |
The new change is ignored. This case does not occur if the new |
| 447 |
changeset was recorded immediately after the changesets already |
| 448 |
added to the changegroup. |
| 449 |
<tr><td>DELETE <td>DELETE <td> |
| 450 |
The new change is ignored. This case does not occur if the new |
| 451 |
changeset was recorded immediately after the changesets already |
| 452 |
added to the changegroup. |
| 453 |
</table></p> |
| 454 |
|
| 455 |
<p>If the new changeset contains changes to a table that is already present |
| 456 |
in the changegroup, then the number of columns and the position of the |
| 457 |
primary key columns for the table must be consistent. If this is not the |
| 458 |
case, this function fails with SQLITE_SCHEMA. Except, if the changegroup |
| 459 |
object has been configured with a database schema using the |
| 460 |
sqlite3changegroup_schema() API, then it is possible to combine changesets |
| 461 |
with different numbers of columns for a single table, provided that |
| 462 |
they are otherwise compatible.</p> |
| 463 |
|
| 464 |
<p>If the input changeset appears to be corrupt and the corruption is |
| 465 |
detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition |
| 466 |
occurs during processing, this function returns SQLITE_NOMEM. </p> |
| 467 |
|
| 468 |
<p>In all cases, if an error occurs the state of the final contents of the |
| 469 |
changegroup is undefined. If no error occurs, SQLITE_OK is returned. |
| 470 |
</p><hr><a name="sqlite3changegroup_add_change"></a> |
| 471 |
<h2>Add A Single Change To A Changegroup</h2><blockquote><pre>int sqlite3changegroup_add_change( |
| 472 |
sqlite3_changegroup*, |
| 473 |
sqlite3_changeset_iter* |
| 474 |
); |
| 475 |
</pre></blockquote><p> |
| 476 |
This function adds the single change currently indicated by the iterator |
| 477 |
passed as the second argument to the changegroup object. The rules for |
| 478 |
adding the change are just as described for <a href="#sqlite3changegroup_add">sqlite3changegroup_add()</a>.</p> |
| 479 |
|
| 480 |
<p>If the change is successfully added to the changegroup, SQLITE_OK is |
| 481 |
returned. Otherwise, an SQLite error code is returned.</p> |
| 482 |
|
| 483 |
<p>The iterator must point to a valid entry when this function is called. |
| 484 |
If it does not, SQLITE_ERROR is returned and no change is added to the |
| 485 |
changegroup. Additionally, the iterator must not have been opened with |
| 486 |
the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also |
| 487 |
returned. |
| 488 |
</p><hr><a name="sqlite3changegroup_delete"></a> |
| 489 |
<h2>Delete A Changegroup Object</h2><blockquote><pre>void sqlite3changegroup_delete(sqlite3_changegroup*); |
| 490 |
</pre></blockquote><p></p><hr><a name="sqlite3changegroup_new"></a> |
| 491 |
<h2>Create A New Changegroup Object</h2><blockquote><pre>int sqlite3changegroup_new(sqlite3_changegroup **pp); |
| 492 |
</pre></blockquote><p> |
| 493 |
An sqlite3_changegroup object is used to combine two or more changesets |
| 494 |
(or patchsets) into a single changeset (or patchset). A single changegroup |
| 495 |
object may combine changesets or patchsets, but not both. The output is |
| 496 |
always in the same format as the input.</p> |
| 497 |
|
| 498 |
<p>If successful, this function returns SQLITE_OK and populates (*pp) with |
| 499 |
a pointer to a new sqlite3_changegroup object before returning. The caller |
| 500 |
should eventually free the returned object using a call to |
| 501 |
sqlite3changegroup_delete(). If an error occurs, an SQLite error code |
| 502 |
(i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.</p> |
| 503 |
|
| 504 |
<p>The usual usage pattern for an sqlite3_changegroup object is as follows:</p> |
| 505 |
|
| 506 |
<p><ul> |
| 507 |
<li> It is created using a call to sqlite3changegroup_new().</p> |
| 508 |
|
| 509 |
<p> <li> Zero or more changesets (or patchsets) are added to the object |
| 510 |
by calling sqlite3changegroup_add().</p> |
| 511 |
|
| 512 |
<p> <li> The result of combining all input changesets together is obtained |
| 513 |
by the application via a call to sqlite3changegroup_output().</p> |
| 514 |
|
| 515 |
<p> <li> The object is deleted using a call to sqlite3changegroup_delete(). |
| 516 |
</ul></p> |
| 517 |
|
| 518 |
<p>Any number of calls to add() and output() may be made between the calls to |
| 519 |
new() and delete(), and in any order.</p> |
| 520 |
|
| 521 |
<p>As well as the regular sqlite3changegroup_add() and |
| 522 |
sqlite3changegroup_output() functions, also available are the streaming |
| 523 |
versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm(). |
| 524 |
</p><hr><a name="sqlite3changegroup_output"></a> |
| 525 |
<h2>Obtain A Composite Changeset From A Changegroup</h2><blockquote><pre>int sqlite3changegroup_output( |
| 526 |
sqlite3_changegroup*, |
| 527 |
int *pnData, /* OUT: Size of output buffer in bytes */ |
| 528 |
void **ppData /* OUT: Pointer to output buffer */ |
| 529 |
); |
| 530 |
</pre></blockquote><p> |
| 531 |
Obtain a buffer containing a changeset (or patchset) representing the |
| 532 |
current contents of the changegroup. If the inputs to the changegroup |
| 533 |
were themselves changesets, the output is a changeset. Or, if the |
| 534 |
inputs were patchsets, the output is also a patchset.</p> |
| 535 |
|
| 536 |
<p>As with the output of the sqlite3session_changeset() and |
| 537 |
sqlite3session_patchset() functions, all changes related to a single |
| 538 |
table are grouped together in the output of this function. Tables appear |
| 539 |
in the same order as for the very first changeset added to the changegroup. |
| 540 |
If the second or subsequent changesets added to the changegroup contain |
| 541 |
changes for tables that do not appear in the first changeset, they are |
| 542 |
appended onto the end of the output changeset, again in the order in |
| 543 |
which they are first encountered.</p> |
| 544 |
|
| 545 |
<p>If an error occurs, an SQLite error code is returned and the output |
| 546 |
variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK |
| 547 |
is returned and the output variables are set to the size of and a |
| 548 |
pointer to the output buffer, respectively. In this case it is the |
| 549 |
responsibility of the caller to eventually free the buffer using a |
| 550 |
call to sqlite3_free(). |
| 551 |
</p><hr><a name="sqlite3changegroup_schema"></a> |
| 552 |
<h2>Add a Schema to a Changegroup</h2><blockquote><pre>int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb); |
| 553 |
</pre></blockquote><p> |
| 554 |
This method may be used to optionally enforce the rule that the changesets |
| 555 |
added to the changegroup handle must match the schema of database zDb |
| 556 |
("main", "temp", or the name of an attached database). If |
| 557 |
sqlite3changegroup_add() is called to add a changeset that is not compatible |
| 558 |
with the configured schema, SQLITE_SCHEMA is returned and the changegroup |
| 559 |
object is left in an undefined state.</p> |
| 560 |
|
| 561 |
<p>A changeset schema is considered compatible with the database schema in |
| 562 |
the same way as for sqlite3changeset_apply(). Specifically, for each |
| 563 |
table in the changeset, there exists a database table with:</p> |
| 564 |
|
| 565 |
<p><ul> |
| 566 |
<li> The name identified by the changeset, and |
| 567 |
<li> at least as many columns as recorded in the changeset, and |
| 568 |
<li> the primary key columns in the same position as recorded in |
| 569 |
the changeset. |
| 570 |
</ul></p> |
| 571 |
|
| 572 |
<p>The output of the changegroup object always has the same schema as the |
| 573 |
database nominated using this function. In cases where changesets passed |
| 574 |
to sqlite3changegroup_add() have fewer columns than the corresponding table |
| 575 |
in the database schema, these are filled in using the default column |
| 576 |
values from the database schema. This makes it possible to combined |
| 577 |
changesets that have different numbers of columns for a single table |
| 578 |
within a changegroup, provided that they are otherwise compatible. |
| 579 |
</p><hr><a name="sqlite3changeset_concat"></a> |
| 580 |
<h2>Concatenate Two Changeset Objects</h2><blockquote><pre>int sqlite3changeset_concat( |
| 581 |
int nA, /* Number of bytes in buffer pA */ |
| 582 |
void *pA, /* Pointer to buffer containing changeset A */ |
| 583 |
int nB, /* Number of bytes in buffer pB */ |
| 584 |
void *pB, /* Pointer to buffer containing changeset B */ |
| 585 |
int *pnOut, /* OUT: Number of bytes in output changeset */ |
| 586 |
void **ppOut /* OUT: Buffer containing output changeset */ |
| 587 |
); |
| 588 |
</pre></blockquote><p> |
| 589 |
This function is used to concatenate two changesets, A and B, into a |
| 590 |
single changeset. The result is a changeset equivalent to applying |
| 591 |
changeset A followed by changeset B. </p> |
| 592 |
|
| 593 |
<p>This function combines the two input changesets using an |
| 594 |
sqlite3_changegroup object. Calling it produces similar results as the |
| 595 |
following code fragment:</p> |
| 596 |
|
| 597 |
<p><pre> |
| 598 |
sqlite3_changegroup *pGrp; |
| 599 |
rc = sqlite3_changegroup_new(&pGrp); |
| 600 |
if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA); |
| 601 |
if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB); |
| 602 |
if( rc==SQLITE_OK ){ |
| 603 |
rc = sqlite3changegroup_output(pGrp, pnOut, ppOut); |
| 604 |
}else{ |
| 605 |
*ppOut = 0; |
| 606 |
*pnOut = 0; |
| 607 |
} |
| 608 |
</pre></p> |
| 609 |
|
| 610 |
<p>Refer to the sqlite3_changegroup documentation below for details. |
| 611 |
</p><hr><a name="sqlite3changeset_conflict"></a> |
| 612 |
<h2>Obtain Conflicting Row Values From A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_conflict( |
| 613 |
sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 614 |
int iVal, /* Column number */ |
| 615 |
sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 616 |
); |
| 617 |
</pre></blockquote><p> |
| 618 |
This function should only be used with iterator objects passed to a |
| 619 |
conflict-handler callback by <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a> with either |
| 620 |
<a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_DATA</a> or <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_CONFLICT</a>. If this function |
| 621 |
is called on any other iterator, <a href="rescode.html#misuse">SQLITE_MISUSE</a> is returned and *ppValue |
| 622 |
is set to NULL.</p> |
| 623 |
|
| 624 |
<p>Argument iVal must be greater than or equal to 0, and less than the number |
| 625 |
of columns in the table affected by the current change. Otherwise, |
| 626 |
<a href="rescode.html#range">SQLITE_RANGE</a> is returned and *ppValue is set to NULL.</p> |
| 627 |
|
| 628 |
<p>If successful, this function sets *ppValue to point to a protected |
| 629 |
sqlite3_value object containing the iVal'th value from the |
| 630 |
"conflicting row" associated with the current conflict-handler callback |
| 631 |
and returns SQLITE_OK.</p> |
| 632 |
|
| 633 |
<p>If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 634 |
is returned and *ppValue is set to NULL. |
| 635 |
</p><hr><a name="sqlite3changeset_finalize"></a> |
| 636 |
<h2>Finalize A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); |
| 637 |
</pre></blockquote><p> |
| 638 |
This function is used to finalize an iterator allocated with |
| 639 |
<a href="#sqlite3changeset_start">sqlite3changeset_start()</a>.</p> |
| 640 |
|
| 641 |
<p>This function should only be called on iterators created using the |
| 642 |
<a href="#sqlite3changeset_start">sqlite3changeset_start()</a> function. If an application calls this |
| 643 |
function with an iterator passed to a conflict-handler by |
| 644 |
<a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a>, <a href="rescode.html#misuse">SQLITE_MISUSE</a> is immediately returned and the |
| 645 |
call has no effect.</p> |
| 646 |
|
| 647 |
<p>If an error was encountered within a call to an sqlite3changeset_xxx() |
| 648 |
function (for example an <a href="rescode.html#corrupt">SQLITE_CORRUPT</a> in <a href="#sqlite3changeset_next">sqlite3changeset_next()</a> or an |
| 649 |
<a href="rescode.html#nomem">SQLITE_NOMEM</a> in <a href="#sqlite3changeset_new">sqlite3changeset_new()</a>) then an error code corresponding |
| 650 |
to that error is returned by this function. Otherwise, SQLITE_OK is |
| 651 |
returned. This is to allow the following pattern (pseudo-code):</p> |
| 652 |
|
| 653 |
<p><pre> |
| 654 |
sqlite3changeset_start(); |
| 655 |
while( SQLITE_ROW==sqlite3changeset_next() ){ |
| 656 |
// Do something with change. |
| 657 |
} |
| 658 |
rc = sqlite3changeset_finalize(); |
| 659 |
if( rc!=SQLITE_OK ){ |
| 660 |
// An error has occurred |
| 661 |
} |
| 662 |
</pre> |
| 663 |
</p><hr><a name="sqlite3changeset_fk_conflicts"></a> |
| 664 |
<h2>Determine The Number Of Foreign Key Constraint Violations</h2><blockquote><pre>int sqlite3changeset_fk_conflicts( |
| 665 |
sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 666 |
int *pnOut /* OUT: Number of FK violations */ |
| 667 |
); |
| 668 |
</pre></blockquote><p> |
| 669 |
This function may only be called with an iterator passed to an |
| 670 |
SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case |
| 671 |
it sets the output variable to the total number of known foreign key |
| 672 |
violations in the destination database and returns SQLITE_OK.</p> |
| 673 |
|
| 674 |
<p>In all other cases this function returns SQLITE_MISUSE. |
| 675 |
</p><hr><a name="sqlite3changeset_invert"></a> |
| 676 |
<h2>Invert A Changeset</h2><blockquote><pre>int sqlite3changeset_invert( |
| 677 |
int nIn, const void *pIn, /* Input changeset */ |
| 678 |
int *pnOut, void **ppOut /* OUT: Inverse of input */ |
| 679 |
); |
| 680 |
</pre></blockquote><p> |
| 681 |
This function is used to "invert" a changeset object. Applying an inverted |
| 682 |
changeset to a database reverses the effects of applying the uninverted |
| 683 |
changeset. Specifically:</p> |
| 684 |
|
| 685 |
<p><ul> |
| 686 |
<li> Each DELETE change is changed to an INSERT, and |
| 687 |
<li> Each INSERT change is changed to a DELETE, and |
| 688 |
<li> For each UPDATE change, the old.* and new.* values are exchanged. |
| 689 |
</ul></p> |
| 690 |
|
| 691 |
<p>This function does not change the order in which changes appear within |
| 692 |
the changeset. It merely reverses the sense of each individual change.</p> |
| 693 |
|
| 694 |
<p>If successful, a pointer to a buffer containing the inverted changeset |
| 695 |
is stored in *ppOut, the size of the same buffer is stored in *pnOut, and |
| 696 |
SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are |
| 697 |
zeroed and an SQLite error code returned.</p> |
| 698 |
|
| 699 |
<p>It is the responsibility of the caller to eventually call sqlite3_free() |
| 700 |
on the *ppOut pointer to free the buffer allocation following a successful |
| 701 |
call to this function.</p> |
| 702 |
|
| 703 |
<p>WARNING/TODO: This function currently assumes that the input is a valid |
| 704 |
changeset. If it is not, the results are undefined. |
| 705 |
</p><hr><a name="sqlite3changeset_new"></a> |
| 706 |
<h2>Obtain new.* Values From A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_new( |
| 707 |
sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 708 |
int iVal, /* Column number */ |
| 709 |
sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ |
| 710 |
); |
| 711 |
</pre></blockquote><p> |
| 712 |
The pIter argument passed to this function may either be an iterator |
| 713 |
passed to a conflict-handler by <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a>, or an iterator |
| 714 |
created by <a href="#sqlite3changeset_start">sqlite3changeset_start()</a>. In the latter case, the most recent |
| 715 |
call to <a href="#sqlite3changeset_next">sqlite3changeset_next()</a> must have returned SQLITE_ROW. |
| 716 |
Furthermore, it may only be called if the type of change that the iterator |
| 717 |
currently points to is either <a href="c3ref/c_alter_table.html">SQLITE_UPDATE</a> or <a href="c3ref/c_alter_table.html">SQLITE_INSERT</a>. Otherwise, |
| 718 |
this function returns <a href="rescode.html#misuse">SQLITE_MISUSE</a> and sets *ppValue to NULL.</p> |
| 719 |
|
| 720 |
<p>Argument iVal must be greater than or equal to 0, and less than the number |
| 721 |
of columns in the table affected by the current change. Otherwise, |
| 722 |
<a href="rescode.html#range">SQLITE_RANGE</a> is returned and *ppValue is set to NULL.</p> |
| 723 |
|
| 724 |
<p>If successful, this function sets *ppValue to point to a protected |
| 725 |
sqlite3_value object containing the iVal'th value from the vector of |
| 726 |
new row values stored as part of the UPDATE or INSERT change and |
| 727 |
returns SQLITE_OK. If the change is an UPDATE and does not include |
| 728 |
a new value for the requested column, *ppValue is set to NULL and |
| 729 |
SQLITE_OK returned. The name of the function comes from the fact that |
| 730 |
this is similar to the "new.*" columns available to update or delete |
| 731 |
triggers.</p> |
| 732 |
|
| 733 |
<p>If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 734 |
is returned and *ppValue is set to NULL. |
| 735 |
</p><hr><a name="sqlite3changeset_next"></a> |
| 736 |
<h2>Advance A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_next(sqlite3_changeset_iter *pIter); |
| 737 |
</pre></blockquote><p> |
| 738 |
This function may only be used with iterators created by the function |
| 739 |
<a href="#sqlite3changeset_start">sqlite3changeset_start()</a>. If it is called on an iterator passed to |
| 740 |
a conflict-handler callback by <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a>, SQLITE_MISUSE |
| 741 |
is returned and the call has no effect.</p> |
| 742 |
|
| 743 |
<p>Immediately after an iterator is created by sqlite3changeset_start(), it |
| 744 |
does not point to any change in the changeset. Assuming the changeset |
| 745 |
is not empty, the first call to this function advances the iterator to |
| 746 |
point to the first change in the changeset. Each subsequent call advances |
| 747 |
the iterator to point to the next change in the changeset (if any). If |
| 748 |
no error occurs and the iterator points to a valid change after a call |
| 749 |
to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned. |
| 750 |
Otherwise, if all changes in the changeset have already been visited, |
| 751 |
SQLITE_DONE is returned.</p> |
| 752 |
|
| 753 |
<p>If an error occurs, an SQLite error code is returned. Possible error |
| 754 |
codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or |
| 755 |
SQLITE_NOMEM. |
| 756 |
</p><hr><a name="sqlite3changeset_old"></a> |
| 757 |
<h2>Obtain old.* Values From A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_old( |
| 758 |
sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 759 |
int iVal, /* Column number */ |
| 760 |
sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ |
| 761 |
); |
| 762 |
</pre></blockquote><p> |
| 763 |
The pIter argument passed to this function may either be an iterator |
| 764 |
passed to a conflict-handler by <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a>, or an iterator |
| 765 |
created by <a href="#sqlite3changeset_start">sqlite3changeset_start()</a>. In the latter case, the most recent |
| 766 |
call to <a href="#sqlite3changeset_next">sqlite3changeset_next()</a> must have returned SQLITE_ROW. |
| 767 |
Furthermore, it may only be called if the type of change that the iterator |
| 768 |
currently points to is either <a href="c3ref/c_alter_table.html">SQLITE_DELETE</a> or <a href="c3ref/c_alter_table.html">SQLITE_UPDATE</a>. Otherwise, |
| 769 |
this function returns <a href="rescode.html#misuse">SQLITE_MISUSE</a> and sets *ppValue to NULL.</p> |
| 770 |
|
| 771 |
<p>Argument iVal must be greater than or equal to 0, and less than the number |
| 772 |
of columns in the table affected by the current change. Otherwise, |
| 773 |
<a href="rescode.html#range">SQLITE_RANGE</a> is returned and *ppValue is set to NULL.</p> |
| 774 |
|
| 775 |
<p>If successful, this function sets *ppValue to point to a protected |
| 776 |
sqlite3_value object containing the iVal'th value from the vector of |
| 777 |
original row values stored as part of the UPDATE or DELETE change and |
| 778 |
returns SQLITE_OK. The name of the function comes from the fact that this |
| 779 |
is similar to the "old.*" columns available to update or delete triggers.</p> |
| 780 |
|
| 781 |
<p>If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 782 |
is returned and *ppValue is set to NULL. |
| 783 |
</p><hr><a name="sqlite3changeset_op"></a> |
| 784 |
<h2>Obtain The Current Operation From A Changeset Iterator</h2><blockquote><pre>int sqlite3changeset_op( |
| 785 |
sqlite3_changeset_iter *pIter, /* Iterator object */ |
| 786 |
const char **pzTab, /* OUT: Pointer to table name */ |
| 787 |
int *pnCol, /* OUT: Number of columns in table */ |
| 788 |
int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ |
| 789 |
int *pbIndirect /* OUT: True for an 'indirect' change */ |
| 790 |
); |
| 791 |
</pre></blockquote><p> |
| 792 |
The pIter argument passed to this function may either be an iterator |
| 793 |
passed to a conflict-handler by <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a>, or an iterator |
| 794 |
created by <a href="#sqlite3changeset_start">sqlite3changeset_start()</a>. In the latter case, the most recent |
| 795 |
call to <a href="#sqlite3changeset_next">sqlite3changeset_next()</a> must have returned <a href="rescode.html#row">SQLITE_ROW</a>. If this |
| 796 |
is not the case, this function returns <a href="rescode.html#misuse">SQLITE_MISUSE</a>.</p> |
| 797 |
|
| 798 |
<p>Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three |
| 799 |
outputs are set through these pointers: </p> |
| 800 |
|
| 801 |
<p>*pOp is set to one of <a href="c3ref/c_alter_table.html">SQLITE_INSERT</a>, <a href="c3ref/c_alter_table.html">SQLITE_DELETE</a> or <a href="c3ref/c_alter_table.html">SQLITE_UPDATE</a>, |
| 802 |
depending on the type of change that the iterator currently points to;</p> |
| 803 |
|
| 804 |
<p>*pnCol is set to the number of columns in the table affected by the change; and</p> |
| 805 |
|
| 806 |
<p>*pzTab is set to point to a nul-terminated utf-8 encoded string containing |
| 807 |
the name of the table affected by the current change. The buffer remains |
| 808 |
valid until either sqlite3changeset_next() is called on the iterator |
| 809 |
or until the conflict-handler function returns.</p> |
| 810 |
|
| 811 |
<p>If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change |
| 812 |
is an indirect change, or false (0) otherwise. See the documentation for |
| 813 |
<a href="#sqlite3session_indirect">sqlite3session_indirect()</a> for a description of direct and indirect |
| 814 |
changes.</p> |
| 815 |
|
| 816 |
<p>If no error occurs, SQLITE_OK is returned. If an error does occur, an |
| 817 |
SQLite error code is returned. The values of the output variables may not |
| 818 |
be trusted in this case. |
| 819 |
</p><hr><a name="sqlite3changeset_pk"></a> |
| 820 |
<h2>Obtain The Primary Key Definition Of A Table</h2><blockquote><pre>int sqlite3changeset_pk( |
| 821 |
sqlite3_changeset_iter *pIter, /* Iterator object */ |
| 822 |
unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ |
| 823 |
int *pnCol /* OUT: Number of entries in output array */ |
| 824 |
); |
| 825 |
</pre></blockquote><p> |
| 826 |
For each modified table, a changeset includes the following:</p> |
| 827 |
|
| 828 |
<p><ul> |
| 829 |
<li> The number of columns in the table, and |
| 830 |
<li> Which of those columns make up the tables PRIMARY KEY. |
| 831 |
</ul></p> |
| 832 |
|
| 833 |
<p>This function is used to find which columns comprise the PRIMARY KEY of |
| 834 |
the table modified by the change that iterator pIter currently points to. |
| 835 |
If successful, *pabPK is set to point to an array of nCol entries, where |
| 836 |
nCol is the number of columns in the table. Elements of *pabPK are set to |
| 837 |
0x01 if the corresponding column is part of the tables primary key, or |
| 838 |
0x00 if it is not.</p> |
| 839 |
|
| 840 |
<p>If argument pnCol is not NULL, then *pnCol is set to the number of columns |
| 841 |
in the table.</p> |
| 842 |
|
| 843 |
<p>If this function is called when the iterator does not point to a valid |
| 844 |
entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise, |
| 845 |
SQLITE_OK is returned and the output variables populated as described |
| 846 |
above. |
| 847 |
</p><hr><a name="sqlite3changeset_upgrade"></a> |
| 848 |
<h2>Upgrade the Schema of a Changeset/Patchset</h2><blockquote><pre>int sqlite3changeset_upgrade( |
| 849 |
sqlite3 *db, |
| 850 |
const char *zDb, |
| 851 |
int nIn, const void *pIn, /* Input changeset */ |
| 852 |
int *pnOut, void **ppOut /* OUT: Inverse of input */ |
| 853 |
); |
| 854 |
</pre></blockquote><p></p><hr><a name="sqlite3rebaser_configure"></a> |
| 855 |
<h2>Configure a changeset rebaser object.</h2><blockquote><pre>int sqlite3rebaser_configure( |
| 856 |
sqlite3_rebaser*, |
| 857 |
int nRebase, const void *pRebase |
| 858 |
); |
| 859 |
</pre></blockquote><p><b>Important:</b> This interface is <a href="c3ref/experimental.html">experimental</a> and is subject to change without notice.</p><p> |
| 860 |
Configure the changeset rebaser object to rebase changesets according |
| 861 |
to the conflict resolutions described by buffer pRebase (size nRebase |
| 862 |
bytes), which must have been obtained from a previous call to |
| 863 |
sqlite3changeset_apply_v2(). |
| 864 |
</p><hr><a name="sqlite3rebaser_create"></a> |
| 865 |
<h2>Create a changeset rebaser object.</h2><blockquote><pre>int sqlite3rebaser_create(sqlite3_rebaser **ppNew); |
| 866 |
</pre></blockquote><p><b>Important:</b> This interface is <a href="c3ref/experimental.html">experimental</a> and is subject to change without notice.</p><p> |
| 867 |
Allocate a new changeset rebaser object. If successful, set (*ppNew) to |
| 868 |
point to the new object and return SQLITE_OK. Otherwise, if an error |
| 869 |
occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) |
| 870 |
to NULL. |
| 871 |
</p><hr><a name="sqlite3rebaser_delete"></a> |
| 872 |
<h2>Delete a changeset rebaser object.</h2><blockquote><pre>void sqlite3rebaser_delete(sqlite3_rebaser *p); |
| 873 |
</pre></blockquote><p><b>Important:</b> This interface is <a href="c3ref/experimental.html">experimental</a> and is subject to change without notice.</p><p> |
| 874 |
Delete the changeset rebaser object and all associated resources. There |
| 875 |
should be one call to this function for each successful invocation |
| 876 |
of sqlite3rebaser_create(). |
| 877 |
</p><hr><a name="sqlite3rebaser_rebase"></a> |
| 878 |
<h2>Rebase a changeset</h2><blockquote><pre>int sqlite3rebaser_rebase( |
| 879 |
sqlite3_rebaser*, |
| 880 |
int nIn, const void *pIn, |
| 881 |
int *pnOut, void **ppOut |
| 882 |
); |
| 883 |
</pre></blockquote><p><b>Important:</b> This interface is <a href="c3ref/experimental.html">experimental</a> and is subject to change without notice.</p><p> |
| 884 |
Argument pIn must point to a buffer containing a changeset nIn bytes |
| 885 |
in size. This function allocates and populates a buffer with a copy |
| 886 |
of the changeset rebased according to the configuration of the |
| 887 |
rebaser object passed as the first argument. If successful, (*ppOut) |
| 888 |
is set to point to the new buffer containing the rebased changeset and |
| 889 |
(*pnOut) to its size in bytes and SQLITE_OK returned. It is the |
| 890 |
responsibility of the caller to eventually free the new buffer using |
| 891 |
sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) |
| 892 |
are set to zero and an SQLite error code returned. |
| 893 |
</p><hr><a name="sqlite3session_attach"></a> |
| 894 |
<h2>Attach A Table To A Session Object</h2><blockquote><pre>int sqlite3session_attach( |
| 895 |
sqlite3_session *pSession, /* Session object */ |
| 896 |
const char *zTab /* Table name */ |
| 897 |
); |
| 898 |
</pre></blockquote><p> |
| 899 |
If argument zTab is not NULL, then it is the name of a table to attach |
| 900 |
to the session object passed as the first argument. All subsequent changes |
| 901 |
made to the table while the session object is enabled will be recorded. See |
| 902 |
documentation for <a href="#sqlite3session_changeset">sqlite3session_changeset()</a> for further details.</p> |
| 903 |
|
| 904 |
<p>Or, if argument zTab is NULL, then changes are recorded for all tables |
| 905 |
in the database. If additional tables are added to the database (by |
| 906 |
executing "CREATE TABLE" statements) after this call is made, changes for |
| 907 |
the new tables are also recorded.</p> |
| 908 |
|
| 909 |
<p>Changes can only be recorded for tables that have a PRIMARY KEY explicitly |
| 910 |
defined as part of their CREATE TABLE statement. It does not matter if the |
| 911 |
PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY |
| 912 |
KEY may consist of a single column, or may be a composite key.</p> |
| 913 |
|
| 914 |
<p>It is not an error if the named table does not exist in the database. Nor |
| 915 |
is it an error if the named table does not have a PRIMARY KEY. However, |
| 916 |
no changes will be recorded in either of these scenarios.</p> |
| 917 |
|
| 918 |
<p>Changes are not recorded for individual rows that have NULL values stored |
| 919 |
in one or more of their PRIMARY KEY columns.</p> |
| 920 |
|
| 921 |
<p>SQLITE_OK is returned if the call completes without error. Or, if an error |
| 922 |
occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.</p> |
| 923 |
|
| 924 |
<p><h3>Special sqlite_stat1 Handling</h3></p> |
| 925 |
|
| 926 |
<p>As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to |
| 927 |
some of the rules above. In SQLite, the schema of sqlite_stat1 is: |
| 928 |
<pre> |
| 929 |
CREATE TABLE sqlite_stat1(tbl,idx,stat) |
| 930 |
</pre></p> |
| 931 |
|
| 932 |
<p>Even though sqlite_stat1 does not have a PRIMARY KEY, changes are |
| 933 |
recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes |
| 934 |
are recorded for rows for which (idx IS NULL) is true. However, for such |
| 935 |
rows a zero-length blob (SQL value X'') is stored in the changeset or |
| 936 |
patchset instead of a NULL value. This allows such changesets to be |
| 937 |
manipulated by legacy implementations of sqlite3changeset_invert(), |
| 938 |
concat() and similar.</p> |
| 939 |
|
| 940 |
<p>The sqlite3changeset_apply() function automatically converts the |
| 941 |
zero-length blob back to a NULL value when updating the sqlite_stat1 |
| 942 |
table. However, if the application calls sqlite3changeset_new(), |
| 943 |
sqlite3changeset_old() or sqlite3changeset_conflict on a changeset |
| 944 |
iterator directly (including on a changeset iterator passed to a |
| 945 |
conflict-handler callback) then the X'' value is returned. The application |
| 946 |
must translate X'' to NULL itself if required.</p> |
| 947 |
|
| 948 |
<p>Legacy (older than 3.22.0) versions of the sessions module cannot capture |
| 949 |
changes made to the sqlite_stat1 table. Legacy versions of the |
| 950 |
sqlite3changeset_apply() function silently ignore any modifications to the |
| 951 |
sqlite_stat1 table that are part of a changeset or patchset. |
| 952 |
</p><hr><a name="sqlite3session_changeset"></a> |
| 953 |
<h2>Generate A Changeset From A Session Object</h2><blockquote><pre>int sqlite3session_changeset( |
| 954 |
sqlite3_session *pSession, /* Session object */ |
| 955 |
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 956 |
void **ppChangeset /* OUT: Buffer containing changeset */ |
| 957 |
); |
| 958 |
</pre></blockquote><p> |
| 959 |
Obtain a changeset containing changes to the tables attached to the |
| 960 |
session object passed as the first argument. If successful, |
| 961 |
set *ppChangeset to point to a buffer containing the changeset |
| 962 |
and *pnChangeset to the size of the changeset in bytes before returning |
| 963 |
SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to |
| 964 |
zero and return an SQLite error code.</p> |
| 965 |
|
| 966 |
<p>A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes, |
| 967 |
each representing a change to a single row of an attached table. An INSERT |
| 968 |
change contains the values of each field of a new database row. A DELETE |
| 969 |
contains the original values of each field of a deleted database row. An |
| 970 |
UPDATE change contains the original values of each field of an updated |
| 971 |
database row along with the updated values for each updated non-primary-key |
| 972 |
column. It is not possible for an UPDATE change to represent a change that |
| 973 |
modifies the values of primary key columns. If such a change is made, it |
| 974 |
is represented in a changeset as a DELETE followed by an INSERT.</p> |
| 975 |
|
| 976 |
<p>Changes are not recorded for rows that have NULL values stored in one or |
| 977 |
more of their PRIMARY KEY columns. If such a row is inserted or deleted, |
| 978 |
no corresponding change is present in the changesets returned by this |
| 979 |
function. If an existing row with one or more NULL values stored in |
| 980 |
PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL, |
| 981 |
only an INSERT is appears in the changeset. Similarly, if an existing row |
| 982 |
with non-NULL PRIMARY KEY values is updated so that one or more of its |
| 983 |
PRIMARY KEY columns are set to NULL, the resulting changeset contains a |
| 984 |
DELETE change only.</p> |
| 985 |
|
| 986 |
<p>The contents of a changeset may be traversed using an iterator created |
| 987 |
using the <a href="#sqlite3changeset_start">sqlite3changeset_start()</a> API. A changeset may be applied to |
| 988 |
a database with a compatible schema using the <a href="#sqlite3changeset_apply">sqlite3changeset_apply()</a> |
| 989 |
API.</p> |
| 990 |
|
| 991 |
<p>Within a changeset generated by this function, all changes related to a |
| 992 |
single table are grouped together. In other words, when iterating through |
| 993 |
a changeset or when applying a changeset to a database, all changes related |
| 994 |
to a single table are processed before moving on to the next table. Tables |
| 995 |
are sorted in the same order in which they were attached (or auto-attached) |
| 996 |
to the sqlite3_session object. The order in which the changes related to |
| 997 |
a single table are stored is undefined.</p> |
| 998 |
|
| 999 |
<p>Following a successful call to this function, it is the responsibility of |
| 1000 |
the caller to eventually free the buffer that *ppChangeset points to using |
| 1001 |
<a href="c3ref/free.html">sqlite3_free()</a>.</p> |
| 1002 |
|
| 1003 |
<p><h3>Changeset Generation</h3></p> |
| 1004 |
|
| 1005 |
<p>Once a table has been attached to a session object, the session object |
| 1006 |
records the primary key values of all new rows inserted into the table. |
| 1007 |
It also records the original primary key and other column values of any |
| 1008 |
deleted or updated rows. For each unique primary key value, data is only |
| 1009 |
recorded once - the first time a row with said primary key is inserted, |
| 1010 |
updated or deleted in the lifetime of the session.</p> |
| 1011 |
|
| 1012 |
<p>There is one exception to the previous paragraph: when a row is inserted, |
| 1013 |
updated or deleted, if one or more of its primary key columns contain a |
| 1014 |
NULL value, no record of the change is made.</p> |
| 1015 |
|
| 1016 |
<p>The session object therefore accumulates two types of records - those |
| 1017 |
that consist of primary key values only (created when the user inserts |
| 1018 |
a new record) and those that consist of the primary key values and the |
| 1019 |
original values of other table columns (created when the users deletes |
| 1020 |
or updates a record).</p> |
| 1021 |
|
| 1022 |
<p>When this function is called, the requested changeset is created using |
| 1023 |
both the accumulated records and the current contents of the database |
| 1024 |
file. Specifically:</p> |
| 1025 |
|
| 1026 |
<p><ul> |
| 1027 |
<li> For each record generated by an insert, the database is queried |
| 1028 |
for a row with a matching primary key. If one is found, an INSERT |
| 1029 |
change is added to the changeset. If no such row is found, no change |
| 1030 |
is added to the changeset.</p> |
| 1031 |
|
| 1032 |
<p> <li> For each record generated by an update or delete, the database is |
| 1033 |
queried for a row with a matching primary key. If such a row is |
| 1034 |
found and one or more of the non-primary key fields have been |
| 1035 |
modified from their original values, an UPDATE change is added to |
| 1036 |
the changeset. Or, if no such row is found in the table, a DELETE |
| 1037 |
change is added to the changeset. If there is a row with a matching |
| 1038 |
primary key in the database, but all fields contain their original |
| 1039 |
values, no change is added to the changeset. |
| 1040 |
</ul></p> |
| 1041 |
|
| 1042 |
<p>This means, amongst other things, that if a row is inserted and then later |
| 1043 |
deleted while a session object is active, neither the insert nor the delete |
| 1044 |
will be present in the changeset. Or if a row is deleted and then later a |
| 1045 |
row with the same primary key values inserted while a session object is |
| 1046 |
active, the resulting changeset will contain an UPDATE change instead of |
| 1047 |
a DELETE and an INSERT.</p> |
| 1048 |
|
| 1049 |
<p>When a session object is disabled (see the <a href="#sqlite3session_enable">sqlite3session_enable()</a> API), |
| 1050 |
it does not accumulate records when rows are inserted, updated or deleted. |
| 1051 |
This may appear to have some counter-intuitive effects if a single row |
| 1052 |
is written to more than once during a session. For example, if a row |
| 1053 |
is inserted while a session object is enabled, then later deleted while |
| 1054 |
the same session object is disabled, no INSERT record will appear in the |
| 1055 |
changeset, even though the delete took place while the session was disabled. |
| 1056 |
Or, if one field of a row is updated while a session is disabled, and |
| 1057 |
another field of the same row is updated while the session is enabled, the |
| 1058 |
resulting changeset will contain an UPDATE change that updates both fields. |
| 1059 |
</p><hr><a name="sqlite3session_changeset_size"></a> |
| 1060 |
<h2>Return An Upper-limit For The Size Of The Changeset</h2><blockquote><pre>sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession); |
| 1061 |
</pre></blockquote><p> |
| 1062 |
By default, this function always returns 0. For it to return |
| 1063 |
a useful result, the sqlite3_session object must have been configured |
| 1064 |
to enable this API using sqlite3session_object_config() with the |
| 1065 |
SQLITE_SESSION_OBJCONFIG_SIZE verb.</p> |
| 1066 |
|
| 1067 |
<p>When enabled, this function returns an upper limit, in bytes, for the size |
| 1068 |
of the changeset that might be produced if sqlite3session_changeset() were |
| 1069 |
called. The final changeset size might be equal to or smaller than the |
| 1070 |
size in bytes returned by this function. |
| 1071 |
</p><hr><a name="sqlite3session_config"></a> |
| 1072 |
<h2>Configure global parameters</h2><blockquote><pre>int sqlite3session_config(int op, void *pArg); |
| 1073 |
</pre></blockquote><p> |
| 1074 |
The sqlite3session_config() interface is used to make global configuration |
| 1075 |
changes to the sessions module in order to tune it to the specific needs |
| 1076 |
of the application.</p> |
| 1077 |
|
| 1078 |
<p>The sqlite3session_config() interface is not threadsafe. If it is invoked |
| 1079 |
while any other thread is inside any other sessions method then the |
| 1080 |
results are undefined. Furthermore, if it is invoked after any sessions |
| 1081 |
related objects have been created, the results are also undefined. </p> |
| 1082 |
|
| 1083 |
<p>The first argument to the sqlite3session_config() function must be one |
| 1084 |
of the SQLITE_SESSION_CONFIG_XXX constants defined below. The |
| 1085 |
interpretation of the (void*) value passed as the second parameter and |
| 1086 |
the effect of calling this function depends on the value of the first |
| 1087 |
parameter.</p> |
| 1088 |
|
| 1089 |
<p><dl> |
| 1090 |
<dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd> |
| 1091 |
By default, the sessions module streaming interfaces attempt to input |
| 1092 |
and output data in approximately 1 KiB chunks. This operand may be used |
| 1093 |
to set and query the value of this configuration setting. The pointer |
| 1094 |
passed as the second argument must point to a value of type (int). |
| 1095 |
If this value is greater than 0, it is used as the new streaming data |
| 1096 |
chunk size for both input and output. Before returning, the (int) value |
| 1097 |
pointed to by pArg is set to the final value of the streaming interface |
| 1098 |
chunk size. |
| 1099 |
</dl></p> |
| 1100 |
|
| 1101 |
<p>This function returns SQLITE_OK if successful, or an SQLite error code |
| 1102 |
otherwise. |
| 1103 |
</p><hr><a name="sqlite3session_create"></a> |
| 1104 |
<h2>Create A New Session Object</h2><blockquote><pre>int sqlite3session_create( |
| 1105 |
sqlite3 *db, /* Database handle */ |
| 1106 |
const char *zDb, /* Name of db (e.g. "main") */ |
| 1107 |
sqlite3_session **ppSession /* OUT: New session object */ |
| 1108 |
); |
| 1109 |
</pre></blockquote><p> |
| 1110 |
Create a new session object attached to database handle db. If successful, |
| 1111 |
a pointer to the new object is written to *ppSession and SQLITE_OK is |
| 1112 |
returned. If an error occurs, *ppSession is set to NULL and an SQLite |
| 1113 |
error code (e.g. SQLITE_NOMEM) is returned.</p> |
| 1114 |
|
| 1115 |
<p>It is possible to create multiple session objects attached to a single |
| 1116 |
database handle.</p> |
| 1117 |
|
| 1118 |
<p>Session objects created using this function should be deleted using the |
| 1119 |
<a href="#sqlite3session_delete">sqlite3session_delete()</a> function before the database handle that they |
| 1120 |
are attached to is itself closed. If the database handle is closed before |
| 1121 |
the session object is deleted, then the results of calling any session |
| 1122 |
module function, including <a href="#sqlite3session_delete">sqlite3session_delete()</a> on the session object |
| 1123 |
are undefined.</p> |
| 1124 |
|
| 1125 |
<p>Because the session module uses the <a href="c3ref/preupdate_blobwrite.html">sqlite3_preupdate_hook()</a> API, it |
| 1126 |
is not possible for an application to register a pre-update hook on a |
| 1127 |
database handle that has one or more session objects attached. Nor is |
| 1128 |
it possible to create a session object attached to a database handle for |
| 1129 |
which a pre-update hook is already defined. The results of attempting |
| 1130 |
either of these things are undefined.</p> |
| 1131 |
|
| 1132 |
<p>The session object will be used to create changesets for tables in |
| 1133 |
database zDb, where zDb is either "main", or "temp", or the name of an |
| 1134 |
attached database. It is not an error if database zDb is not attached |
| 1135 |
to the database when the session object is created. |
| 1136 |
</p><hr><a name="sqlite3session_delete"></a> |
| 1137 |
<h2>Delete A Session Object</h2><blockquote><pre>void sqlite3session_delete(sqlite3_session *pSession); |
| 1138 |
</pre></blockquote><p> |
| 1139 |
Delete a session object previously allocated using |
| 1140 |
<a href="#sqlite3session_create">sqlite3session_create()</a>. Once a session object has been deleted, the |
| 1141 |
results of attempting to use pSession with any other session module |
| 1142 |
function are undefined.</p> |
| 1143 |
|
| 1144 |
<p>Session objects must be deleted before the database handle to which they |
| 1145 |
are attached is closed. Refer to the documentation for |
| 1146 |
<a href="#sqlite3session_create">sqlite3session_create()</a> for details. |
| 1147 |
</p><hr><a name="sqlite3session_diff"></a> |
| 1148 |
<h2>Load The Difference Between Tables Into A Session</h2><blockquote><pre>int sqlite3session_diff( |
| 1149 |
sqlite3_session *pSession, |
| 1150 |
const char *zFromDb, |
| 1151 |
const char *zTbl, |
| 1152 |
char **pzErrMsg |
| 1153 |
); |
| 1154 |
</pre></blockquote><p> |
| 1155 |
If it is not already attached to the session object passed as the first |
| 1156 |
argument, this function attaches table zTbl in the same manner as the |
| 1157 |
<a href="#sqlite3session_attach">sqlite3session_attach()</a> function. If zTbl does not exist, or if it |
| 1158 |
does not have a primary key, this function is a no-op (but does not return |
| 1159 |
an error).</p> |
| 1160 |
|
| 1161 |
<p>Argument zFromDb must be the name of a database ("main", "temp" etc.) |
| 1162 |
attached to the same database handle as the session object that contains |
| 1163 |
a table compatible with the table attached to the session by this function. |
| 1164 |
A table is considered compatible if it:</p> |
| 1165 |
|
| 1166 |
<p><ul> |
| 1167 |
<li> Has the same name, |
| 1168 |
<li> Has the same set of columns declared in the same order, and |
| 1169 |
<li> Has the same PRIMARY KEY definition. |
| 1170 |
</ul></p> |
| 1171 |
|
| 1172 |
<p>If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables |
| 1173 |
are compatible but do not have any PRIMARY KEY columns, it is not an error |
| 1174 |
but no changes are added to the session object. As with other session |
| 1175 |
APIs, tables without PRIMARY KEYs are simply ignored.</p> |
| 1176 |
|
| 1177 |
<p>This function adds a set of changes to the session object that could be |
| 1178 |
used to update the table in database zFrom (call this the "from-table") |
| 1179 |
so that its content is the same as the table attached to the session |
| 1180 |
object (call this the "to-table"). Specifically:</p> |
| 1181 |
|
| 1182 |
<p><ul> |
| 1183 |
<li> For each row (primary key) that exists in the to-table but not in |
| 1184 |
the from-table, an INSERT record is added to the session object.</p> |
| 1185 |
|
| 1186 |
<p> <li> For each row (primary key) that exists in the to-table but not in |
| 1187 |
the from-table, a DELETE record is added to the session object.</p> |
| 1188 |
|
| 1189 |
<p> <li> For each row (primary key) that exists in both tables, but features |
| 1190 |
different non-PK values in each, an UPDATE record is added to the |
| 1191 |
session. |
| 1192 |
</ul></p> |
| 1193 |
|
| 1194 |
<p>To clarify, if this function is called and then a changeset constructed |
| 1195 |
using <a href="#sqlite3session_changeset">sqlite3session_changeset()</a>, then after applying that changeset to |
| 1196 |
database zFrom the contents of the two compatible tables would be |
| 1197 |
identical.</p> |
| 1198 |
|
| 1199 |
<p>It an error if database zFrom does not exist or does not contain the |
| 1200 |
required compatible table.</p> |
| 1201 |
|
| 1202 |
<p>If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite |
| 1203 |
error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg |
| 1204 |
may be set to point to a buffer containing an English language error |
| 1205 |
message. It is the responsibility of the caller to free this buffer using |
| 1206 |
sqlite3_free(). |
| 1207 |
</p><hr><a name="sqlite3session_enable"></a> |
| 1208 |
<h2>Enable Or Disable A Session Object</h2><blockquote><pre>int sqlite3session_enable(sqlite3_session *pSession, int bEnable); |
| 1209 |
</pre></blockquote><p> |
| 1210 |
Enable or disable the recording of changes by a session object. When |
| 1211 |
enabled, a session object records changes made to the database. When |
| 1212 |
disabled - it does not. A newly created session object is enabled. |
| 1213 |
Refer to the documentation for <a href="#sqlite3session_changeset">sqlite3session_changeset()</a> for further |
| 1214 |
details regarding how enabling and disabling a session object affects |
| 1215 |
the eventual changesets.</p> |
| 1216 |
|
| 1217 |
<p>Passing zero to this function disables the session. Passing a value |
| 1218 |
greater than zero enables it. Passing a value less than zero is a |
| 1219 |
no-op, and may be used to query the current state of the session.</p> |
| 1220 |
|
| 1221 |
<p>The return value indicates the final state of the session object: 0 if |
| 1222 |
the session is disabled, or 1 if it is enabled. |
| 1223 |
</p><hr><a name="sqlite3session_indirect"></a> |
| 1224 |
<h2>Set Or Clear the Indirect Change Flag</h2><blockquote><pre>int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect); |
| 1225 |
</pre></blockquote><p> |
| 1226 |
Each change recorded by a session object is marked as either direct or |
| 1227 |
indirect. A change is marked as indirect if either:</p> |
| 1228 |
|
| 1229 |
<p><ul> |
| 1230 |
<li> The session object "indirect" flag is set when the change is |
| 1231 |
made, or |
| 1232 |
<li> The change is made by an SQL trigger or foreign key action |
| 1233 |
instead of directly as a result of a users SQL statement. |
| 1234 |
</ul></p> |
| 1235 |
|
| 1236 |
<p>If a single row is affected by more than one operation within a session, |
| 1237 |
then the change is considered indirect if all operations meet the criteria |
| 1238 |
for an indirect change above, or direct otherwise.</p> |
| 1239 |
|
| 1240 |
<p>This function is used to set, clear or query the session object indirect |
| 1241 |
flag. If the second argument passed to this function is zero, then the |
| 1242 |
indirect flag is cleared. If it is greater than zero, the indirect flag |
| 1243 |
is set. Passing a value less than zero does not modify the current value |
| 1244 |
of the indirect flag, and may be used to query the current state of the |
| 1245 |
indirect flag for the specified session object.</p> |
| 1246 |
|
| 1247 |
<p>The return value indicates the final state of the indirect flag: 0 if |
| 1248 |
it is clear, or 1 if it is set. |
| 1249 |
</p><hr><a name="sqlite3session_isempty"></a> |
| 1250 |
<h2>Test if a changeset has recorded any changes.</h2><blockquote><pre>int sqlite3session_isempty(sqlite3_session *pSession); |
| 1251 |
</pre></blockquote><p> |
| 1252 |
Return non-zero if no changes to attached tables have been recorded by |
| 1253 |
the session object passed as the first argument. Otherwise, if one or |
| 1254 |
more changes have been recorded, return zero.</p> |
| 1255 |
|
| 1256 |
<p>Even if this function returns zero, it is possible that calling |
| 1257 |
<a href="#sqlite3session_changeset">sqlite3session_changeset()</a> on the session handle may still return a |
| 1258 |
changeset that contains no changes. This can happen when a row in |
| 1259 |
an attached table is modified and then later on the original values |
| 1260 |
are restored. However, if this function returns non-zero, then it is |
| 1261 |
guaranteed that a call to sqlite3session_changeset() will return a |
| 1262 |
changeset containing zero changes. |
| 1263 |
</p><hr><a name="sqlite3session_memory_used"></a> |
| 1264 |
<h2>Query for the amount of heap memory used by a session object.</h2><blockquote><pre>sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession); |
| 1265 |
</pre></blockquote><p> |
| 1266 |
This API returns the total amount of heap memory in bytes currently |
| 1267 |
used by the session object passed as the only argument. |
| 1268 |
</p><hr><a name="sqlite3session_object_config"></a> |
| 1269 |
<h2>Configure a Session Object</h2><blockquote><pre>int sqlite3session_object_config(sqlite3_session*, int op, void *pArg); |
| 1270 |
</pre></blockquote><p> |
| 1271 |
This method is used to configure a session object after it has been |
| 1272 |
created. At present the only valid values for the second parameter are |
| 1273 |
<a href="#SQLITE_SESSION_OBJCONFIG_ROWID">SQLITE_SESSION_OBJCONFIG_SIZE</a> and <a href="#SQLITE_SESSION_OBJCONFIG_ROWID">SQLITE_SESSION_OBJCONFIG_ROWID</a>.</p> |
| 1274 |
|
| 1275 |
<p></p><hr><a name="sqlite3session_patchset"></a> |
| 1276 |
<h2>Generate A Patchset From A Session Object</h2><blockquote><pre>int sqlite3session_patchset( |
| 1277 |
sqlite3_session *pSession, /* Session object */ |
| 1278 |
int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */ |
| 1279 |
void **ppPatchset /* OUT: Buffer containing patchset */ |
| 1280 |
); |
| 1281 |
</pre></blockquote><p> |
| 1282 |
The differences between a patchset and a changeset are that:</p> |
| 1283 |
|
| 1284 |
<p><ul> |
| 1285 |
<li> DELETE records consist of the primary key fields only. The |
| 1286 |
original values of other fields are omitted. |
| 1287 |
<li> The original values of any modified fields are omitted from |
| 1288 |
UPDATE records. |
| 1289 |
</ul></p> |
| 1290 |
|
| 1291 |
<p>A patchset blob may be used with up to date versions of all |
| 1292 |
sqlite3changeset_xxx API functions except for sqlite3changeset_invert(), |
| 1293 |
which returns SQLITE_CORRUPT if it is passed a patchset. Similarly, |
| 1294 |
attempting to use a patchset blob with old versions of the |
| 1295 |
sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error. </p> |
| 1296 |
|
| 1297 |
<p>Because the non-primary key "old.*" fields are omitted, no |
| 1298 |
SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset |
| 1299 |
is passed to the sqlite3changeset_apply() API. Other conflict types work |
| 1300 |
in the same way as for changesets.</p> |
| 1301 |
|
| 1302 |
<p>Changes within a patchset are ordered in the same way as for changesets |
| 1303 |
generated by the sqlite3session_changeset() function (i.e. all changes for |
| 1304 |
a single table are grouped together, tables appear in the order in which |
| 1305 |
they were attached to the session object). |
| 1306 |
</p><hr><a name="sqlite3session_table_filter"></a> |
| 1307 |
<h2>Set a table filter on a Session Object.</h2><blockquote><pre>void sqlite3session_table_filter( |
| 1308 |
sqlite3_session *pSession, /* Session object */ |
| 1309 |
int(*xFilter)( |
| 1310 |
void *pCtx, /* Copy of third arg to _filter_table() */ |
| 1311 |
const char *zTab /* Table name */ |
| 1312 |
), |
| 1313 |
void *pCtx /* First argument passed to xFilter */ |
| 1314 |
); |
| 1315 |
</pre></blockquote><p> |
| 1316 |
The second argument (xFilter) is the "filter callback". For changes to rows |
| 1317 |
in tables that are not attached to the Session object, the filter is called |
| 1318 |
to determine whether changes to the table's rows should be tracked or not. |
| 1319 |
If xFilter returns 0, changes are not tracked. Note that once a table is |
| 1320 |
attached, xFilter will not be called again. |
| 1321 |
</p><hr><a name="SQLITE_CHANGESETAPPLY_FKNOACTION"></a> |
| 1322 |
<h2>Flags for sqlite3changeset_apply_v2</h2><blockquote><pre>#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 1323 |
#define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 1324 |
#define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 1325 |
#define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 1326 |
</pre></blockquote><p> |
| 1327 |
The following flags may passed via the 9th parameter to |
| 1328 |
<a href="#sqlite3changeset_apply">sqlite3changeset_apply_v2</a> and <a href="#sqlite3changegroup_add_strm">sqlite3changeset_apply_v2_strm</a>:</p> |
| 1329 |
|
| 1330 |
<p><dl> |
| 1331 |
<dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd> |
| 1332 |
Usually, the sessions module encloses all operations performed by |
| 1333 |
a single call to apply_v2() or apply_v2_strm() in a <a href="lang_savepoint.html">SAVEPOINT</a>. The |
| 1334 |
SAVEPOINT is committed if the changeset or patchset is successfully |
| 1335 |
applied, or rolled back if an error occurs. Specifying this flag |
| 1336 |
causes the sessions module to omit this savepoint. In this case, if the |
| 1337 |
caller has an open transaction or savepoint when apply_v2() is called, |
| 1338 |
it may revert the partially applied changeset by rolling it back.</p> |
| 1339 |
|
| 1340 |
<p><dt>SQLITE_CHANGESETAPPLY_INVERT <dd> |
| 1341 |
Invert the changeset before applying it. This is equivalent to inverting |
| 1342 |
a changeset using sqlite3changeset_invert() before applying it. It is |
| 1343 |
an error to specify this flag with a patchset.</p> |
| 1344 |
|
| 1345 |
<p><dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd> |
| 1346 |
Do not invoke the conflict handler callback for any changes that |
| 1347 |
would not actually modify the database even if they were applied. |
| 1348 |
Specifically, this means that the conflict handler is not invoked |
| 1349 |
for: |
| 1350 |
<ul> |
| 1351 |
<li>a delete change if the row being deleted cannot be found, |
| 1352 |
<li>an update change if the modified fields are already set to |
| 1353 |
their new values in the conflicting row, or |
| 1354 |
<li>an insert change if all fields of the conflicting row match |
| 1355 |
the row being inserted. |
| 1356 |
</ul></p> |
| 1357 |
|
| 1358 |
<p><dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 1359 |
If this flag it set, then all foreign key constraints in the target |
| 1360 |
database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 1361 |
DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 1362 |
or SET DEFAULT. |
| 1363 |
</p><hr><a name="SQLITE_CHANGESET_ABORT"></a> |
| 1364 |
<h2>Constants Returned By The Conflict Handler</h2><blockquote><pre>#define SQLITE_CHANGESET_OMIT 0 |
| 1365 |
#define SQLITE_CHANGESET_REPLACE 1 |
| 1366 |
#define SQLITE_CHANGESET_ABORT 2 |
| 1367 |
</pre></blockquote><p> |
| 1368 |
A conflict handler callback must return one of the following three values.</p> |
| 1369 |
|
| 1370 |
<p><dl> |
| 1371 |
<dt>SQLITE_CHANGESET_OMIT<dd> |
| 1372 |
If a conflict handler returns this value no special action is taken. The |
| 1373 |
change that caused the conflict is not applied. The session module |
| 1374 |
continues to the next change in the changeset.</p> |
| 1375 |
|
| 1376 |
<p><dt>SQLITE_CHANGESET_REPLACE<dd> |
| 1377 |
This value may only be returned if the second argument to the conflict |
| 1378 |
handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this |
| 1379 |
is not the case, any changes applied so far are rolled back and the |
| 1380 |
call to sqlite3changeset_apply() returns SQLITE_MISUSE.</p> |
| 1381 |
|
| 1382 |
<p> If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict |
| 1383 |
handler, then the conflicting row is either updated or deleted, depending |
| 1384 |
on the type of change.</p> |
| 1385 |
|
| 1386 |
<p> If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict |
| 1387 |
handler, then the conflicting row is removed from the database and a |
| 1388 |
second attempt to apply the change is made. If this second attempt fails, |
| 1389 |
the original row is restored to the database before continuing.</p> |
| 1390 |
|
| 1391 |
<p><dt>SQLITE_CHANGESET_ABORT<dd> |
| 1392 |
If this value is returned, any changes applied so far are rolled back |
| 1393 |
and the call to sqlite3changeset_apply() returns SQLITE_ABORT. |
| 1394 |
</dl> |
| 1395 |
</p><hr><a name="SQLITE_CHANGESET_CONFLICT"></a> |
| 1396 |
<h2>Constants Passed To The Conflict Handler</h2><blockquote><pre>#define SQLITE_CHANGESET_DATA 1 |
| 1397 |
#define SQLITE_CHANGESET_NOTFOUND 2 |
| 1398 |
#define SQLITE_CHANGESET_CONFLICT 3 |
| 1399 |
#define SQLITE_CHANGESET_CONSTRAINT 4 |
| 1400 |
#define SQLITE_CHANGESET_FOREIGN_KEY 5 |
| 1401 |
</pre></blockquote><p> |
| 1402 |
Values that may be passed as the second argument to a conflict-handler.</p> |
| 1403 |
|
| 1404 |
<p><dl> |
| 1405 |
<dt>SQLITE_CHANGESET_DATA<dd> |
| 1406 |
The conflict handler is invoked with CHANGESET_DATA as the second argument |
| 1407 |
when processing a DELETE or UPDATE change if a row with the required |
| 1408 |
PRIMARY KEY fields is present in the database, but one or more other |
| 1409 |
(non primary-key) fields modified by the update do not contain the |
| 1410 |
expected "before" values.</p> |
| 1411 |
|
| 1412 |
<p> The conflicting row, in this case, is the database row with the matching |
| 1413 |
primary key.</p> |
| 1414 |
|
| 1415 |
<p><dt>SQLITE_CHANGESET_NOTFOUND<dd> |
| 1416 |
The conflict handler is invoked with CHANGESET_NOTFOUND as the second |
| 1417 |
argument when processing a DELETE or UPDATE change if a row with the |
| 1418 |
required PRIMARY KEY fields is not present in the database.</p> |
| 1419 |
|
| 1420 |
<p> There is no conflicting row in this case. The results of invoking the |
| 1421 |
sqlite3changeset_conflict() API are undefined.</p> |
| 1422 |
|
| 1423 |
<p><dt>SQLITE_CHANGESET_CONFLICT<dd> |
| 1424 |
CHANGESET_CONFLICT is passed as the second argument to the conflict |
| 1425 |
handler while processing an INSERT change if the operation would result |
| 1426 |
in duplicate primary key values.</p> |
| 1427 |
|
| 1428 |
<p> The conflicting row in this case is the database row with the matching |
| 1429 |
primary key.</p> |
| 1430 |
|
| 1431 |
<p><dt>SQLITE_CHANGESET_FOREIGN_KEY<dd> |
| 1432 |
If foreign key handling is enabled, and applying a changeset leaves the |
| 1433 |
database in a state containing foreign key violations, the conflict |
| 1434 |
handler is invoked with CHANGESET_FOREIGN_KEY as the second argument |
| 1435 |
exactly once before the changeset is committed. If the conflict handler |
| 1436 |
returns CHANGESET_OMIT, the changes, including those that caused the |
| 1437 |
foreign key constraint violation, are committed. Or, if it returns |
| 1438 |
CHANGESET_ABORT, the changeset is rolled back.</p> |
| 1439 |
|
| 1440 |
<p> No current or conflicting row information is provided. The only function |
| 1441 |
it is possible to call on the supplied sqlite3_changeset_iter handle |
| 1442 |
is sqlite3changeset_fk_conflicts().</p> |
| 1443 |
|
| 1444 |
<p><dt>SQLITE_CHANGESET_CONSTRAINT<dd> |
| 1445 |
If any other constraint violation occurs while applying a change (i.e. |
| 1446 |
a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is |
| 1447 |
invoked with CHANGESET_CONSTRAINT as the second argument.</p> |
| 1448 |
|
| 1449 |
<p> There is no conflicting row in this case. The results of invoking the |
| 1450 |
sqlite3changeset_conflict() API are undefined.</p> |
| 1451 |
|
| 1452 |
<p></dl> |
| 1453 |
</p><hr><a name="SQLITE_SESSION_OBJCONFIG_ROWID"></a> |
| 1454 |
<h2>Options for sqlite3session_object_config</h2><blockquote><pre>#define SQLITE_SESSION_OBJCONFIG_SIZE 1 |
| 1455 |
#define SQLITE_SESSION_OBJCONFIG_ROWID 2 |
| 1456 |
</pre></blockquote><p> |
| 1457 |
The following values may passed as the the 2nd parameter to |
| 1458 |
sqlite3session_object_config().</p> |
| 1459 |
|
| 1460 |
<p><dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd> |
| 1461 |
This option is used to set, clear or query the flag that enables |
| 1462 |
the <a href="#sqlite3session_changeset_size">sqlite3session_changeset_size()</a> API. Because it imposes some |
| 1463 |
computational overhead, this API is disabled by default. Argument |
| 1464 |
pArg must point to a value of type (int). If the value is initially |
| 1465 |
0, then the sqlite3session_changeset_size() API is disabled. If it |
| 1466 |
is greater than 0, then the same API is enabled. Or, if the initial |
| 1467 |
value is less than zero, no change is made. In all cases the (int) |
| 1468 |
variable is set to 1 if the sqlite3session_changeset_size() API is |
| 1469 |
enabled following the current call, or 0 otherwise.</p> |
| 1470 |
|
| 1471 |
<p> It is an error (SQLITE_MISUSE) to attempt to modify this setting after |
| 1472 |
the first table has been attached to the session object.</p> |
| 1473 |
|
| 1474 |
<p><dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd> |
| 1475 |
This option is used to set, clear or query the flag that enables |
| 1476 |
collection of data for tables with no explicit PRIMARY KEY.</p> |
| 1477 |
|
| 1478 |
<p> Normally, tables with no explicit PRIMARY KEY are simply ignored |
| 1479 |
by the sessions module. However, if this flag is set, it behaves |
| 1480 |
as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted |
| 1481 |
as their leftmost columns.</p> |
| 1482 |
|
| 1483 |
<p> It is an error (SQLITE_MISUSE) to attempt to modify this setting after |
| 1484 |
the first table has been attached to the session object. |
| 1485 |
</p><hr><a name="sqlite3changegroup_add_strm"></a> |
| 1486 |
<h2>Streaming Versions of API functions.</h2><blockquote><pre>int sqlite3changeset_apply_strm( |
| 1487 |
sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 1488 |
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ |
| 1489 |
void *pIn, /* First arg for xInput */ |
| 1490 |
int(*xFilter)( |
| 1491 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1492 |
const char *zTab /* Table name */ |
| 1493 |
), |
| 1494 |
int(*xConflict)( |
| 1495 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1496 |
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 1497 |
sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 1498 |
), |
| 1499 |
void *pCtx /* First argument passed to xConflict */ |
| 1500 |
); |
| 1501 |
int sqlite3changeset_apply_v2_strm( |
| 1502 |
sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 1503 |
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ |
| 1504 |
void *pIn, /* First arg for xInput */ |
| 1505 |
int(*xFilter)( |
| 1506 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1507 |
const char *zTab /* Table name */ |
| 1508 |
), |
| 1509 |
int(*xConflict)( |
| 1510 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1511 |
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 1512 |
sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 1513 |
), |
| 1514 |
void *pCtx, /* First argument passed to xConflict */ |
| 1515 |
void **ppRebase, int *pnRebase, |
| 1516 |
int flags |
| 1517 |
); |
| 1518 |
int sqlite3changeset_concat_strm( |
| 1519 |
int (*xInputA)(void *pIn, void *pData, int *pnData), |
| 1520 |
void *pInA, |
| 1521 |
int (*xInputB)(void *pIn, void *pData, int *pnData), |
| 1522 |
void *pInB, |
| 1523 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1524 |
void *pOut |
| 1525 |
); |
| 1526 |
int sqlite3changeset_invert_strm( |
| 1527 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1528 |
void *pIn, |
| 1529 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1530 |
void *pOut |
| 1531 |
); |
| 1532 |
int sqlite3changeset_start_strm( |
| 1533 |
sqlite3_changeset_iter **pp, |
| 1534 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1535 |
void *pIn |
| 1536 |
); |
| 1537 |
int sqlite3changeset_start_v2_strm( |
| 1538 |
sqlite3_changeset_iter **pp, |
| 1539 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1540 |
void *pIn, |
| 1541 |
int flags |
| 1542 |
); |
| 1543 |
int sqlite3session_changeset_strm( |
| 1544 |
sqlite3_session *pSession, |
| 1545 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1546 |
void *pOut |
| 1547 |
); |
| 1548 |
int sqlite3session_patchset_strm( |
| 1549 |
sqlite3_session *pSession, |
| 1550 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1551 |
void *pOut |
| 1552 |
); |
| 1553 |
int sqlite3changegroup_add_strm(sqlite3_changegroup*, |
| 1554 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1555 |
void *pIn |
| 1556 |
); |
| 1557 |
int sqlite3changegroup_output_strm(sqlite3_changegroup*, |
| 1558 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1559 |
void *pOut |
| 1560 |
); |
| 1561 |
int sqlite3rebaser_rebase_strm( |
| 1562 |
sqlite3_rebaser *pRebaser, |
| 1563 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1564 |
void *pIn, |
| 1565 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1566 |
void *pOut |
| 1567 |
); |
| 1568 |
</pre></blockquote><p> |
| 1569 |
The six streaming API xxx_strm() functions serve similar purposes to the |
| 1570 |
corresponding non-streaming API functions:</p> |
| 1571 |
|
| 1572 |
<p><table border=1 style="margin-left:8ex;margin-right:8ex"> |
| 1573 |
<tr><th>Streaming function<th>Non-streaming equivalent</th> |
| 1574 |
<tr><td>sqlite3changeset_apply_strm<td><a href="#sqlite3changeset_apply">sqlite3changeset_apply</a> |
| 1575 |
<tr><td>sqlite3changeset_apply_strm_v2<td><a href="#sqlite3changeset_apply">sqlite3changeset_apply_v2</a> |
| 1576 |
<tr><td>sqlite3changeset_concat_strm<td><a href="#sqlite3changeset_concat">sqlite3changeset_concat</a> |
| 1577 |
<tr><td>sqlite3changeset_invert_strm<td><a href="#sqlite3changeset_invert">sqlite3changeset_invert</a> |
| 1578 |
<tr><td>sqlite3changeset_start_strm<td><a href="#sqlite3changeset_start">sqlite3changeset_start</a> |
| 1579 |
<tr><td>sqlite3session_changeset_strm<td><a href="#sqlite3session_changeset">sqlite3session_changeset</a> |
| 1580 |
<tr><td>sqlite3session_patchset_strm<td><a href="#sqlite3session_patchset">sqlite3session_patchset</a> |
| 1581 |
</table></p> |
| 1582 |
|
| 1583 |
<p>Non-streaming functions that accept changesets (or patchsets) as input |
| 1584 |
require that the entire changeset be stored in a single buffer in memory. |
| 1585 |
Similarly, those that return a changeset or patchset do so by returning |
| 1586 |
a pointer to a single large buffer allocated using sqlite3_malloc(). |
| 1587 |
Normally this is convenient. However, if an application running in a |
| 1588 |
low-memory environment is required to handle very large changesets, the |
| 1589 |
large contiguous memory allocations required can become onerous.</p> |
| 1590 |
|
| 1591 |
<p>In order to avoid this problem, instead of a single large buffer, input |
| 1592 |
is passed to a streaming API functions by way of a callback function that |
| 1593 |
the sessions module invokes to incrementally request input data as it is |
| 1594 |
required. In all cases, a pair of API function parameters such as</p> |
| 1595 |
|
| 1596 |
<p> <pre> |
| 1597 |
int nChangeset, |
| 1598 |
void *pChangeset, |
| 1599 |
</pre></p> |
| 1600 |
|
| 1601 |
<p>Is replaced by:</p> |
| 1602 |
|
| 1603 |
<p> <pre> |
| 1604 |
int (*xInput)(void *pIn, void *pData, int *pnData), |
| 1605 |
void *pIn, |
| 1606 |
</pre></p> |
| 1607 |
|
| 1608 |
<p>Each time the xInput callback is invoked by the sessions module, the first |
| 1609 |
argument passed is a copy of the supplied pIn context pointer. The second |
| 1610 |
argument, pData, points to a buffer (*pnData) bytes in size. Assuming no |
| 1611 |
error occurs the xInput method should copy up to (*pnData) bytes of data |
| 1612 |
into the buffer and set (*pnData) to the actual number of bytes copied |
| 1613 |
before returning SQLITE_OK. If the input is completely exhausted, (*pnData) |
| 1614 |
should be set to zero to indicate this. Or, if an error occurs, an SQLite |
| 1615 |
error code should be returned. In all cases, if an xInput callback returns |
| 1616 |
an error, all processing is abandoned and the streaming API function |
| 1617 |
returns a copy of the error code to the caller.</p> |
| 1618 |
|
| 1619 |
<p>In the case of sqlite3changeset_start_strm(), the xInput callback may be |
| 1620 |
invoked by the sessions module at any point during the lifetime of the |
| 1621 |
iterator. If such an xInput callback returns an error, the iterator enters |
| 1622 |
an error state, whereby all subsequent calls to iterator functions |
| 1623 |
immediately fail with the same error code as returned by xInput.</p> |
| 1624 |
|
| 1625 |
<p>Similarly, streaming API functions that return changesets (or patchsets) |
| 1626 |
return them in chunks by way of a callback function instead of via a |
| 1627 |
pointer to a single large buffer. In this case, a pair of parameters such |
| 1628 |
as:</p> |
| 1629 |
|
| 1630 |
<p> <pre> |
| 1631 |
int *pnChangeset, |
| 1632 |
void **ppChangeset, |
| 1633 |
</pre></p> |
| 1634 |
|
| 1635 |
<p>Is replaced by:</p> |
| 1636 |
|
| 1637 |
<p> <pre> |
| 1638 |
int (*xOutput)(void *pOut, const void *pData, int nData), |
| 1639 |
void *pOut |
| 1640 |
</pre></p> |
| 1641 |
|
| 1642 |
<p>The xOutput callback is invoked zero or more times to return data to |
| 1643 |
the application. The first parameter passed to each call is a copy of the |
| 1644 |
pOut pointer supplied by the application. The second parameter, pData, |
| 1645 |
points to a buffer nData bytes in size containing the chunk of output |
| 1646 |
data being returned. If the xOutput callback successfully processes the |
| 1647 |
supplied data, it should return SQLITE_OK to indicate success. Otherwise, |
| 1648 |
it should return some other SQLite error code. In this case processing |
| 1649 |
is immediately abandoned and the streaming API function returns a copy |
| 1650 |
of the xOutput error code to the application.</p> |
| 1651 |
|
| 1652 |
<p>The sessions module never invokes an xOutput callback with the third |
| 1653 |
parameter set to a value less than or equal to zero. Other than this, |
| 1654 |
no guarantees are made as to the size of the chunks of data returned. |
| 1655 |
</p><hr><a name="sqlite3changeset_apply"></a> |
| 1656 |
<h2>Apply A Changeset To A Database</h2><blockquote><pre>int sqlite3changeset_apply( |
| 1657 |
sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 1658 |
int nChangeset, /* Size of changeset in bytes */ |
| 1659 |
void *pChangeset, /* Changeset blob */ |
| 1660 |
int(*xFilter)( |
| 1661 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1662 |
const char *zTab /* Table name */ |
| 1663 |
), |
| 1664 |
int(*xConflict)( |
| 1665 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1666 |
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 1667 |
sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 1668 |
), |
| 1669 |
void *pCtx /* First argument passed to xConflict */ |
| 1670 |
); |
| 1671 |
int sqlite3changeset_apply_v2( |
| 1672 |
sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 1673 |
int nChangeset, /* Size of changeset in bytes */ |
| 1674 |
void *pChangeset, /* Changeset blob */ |
| 1675 |
int(*xFilter)( |
| 1676 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1677 |
const char *zTab /* Table name */ |
| 1678 |
), |
| 1679 |
int(*xConflict)( |
| 1680 |
void *pCtx, /* Copy of sixth arg to _apply() */ |
| 1681 |
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 1682 |
sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 1683 |
), |
| 1684 |
void *pCtx, /* First argument passed to xConflict */ |
| 1685 |
void **ppRebase, int *pnRebase, /* OUT: Rebase data */ |
| 1686 |
int flags /* SESSION_CHANGESETAPPLY_* flags */ |
| 1687 |
); |
| 1688 |
</pre></blockquote><p> |
| 1689 |
Apply a changeset or patchset to a database. These functions attempt to |
| 1690 |
update the "main" database attached to handle db with the changes found in |
| 1691 |
the changeset passed via the second and third arguments. </p> |
| 1692 |
|
| 1693 |
<p>The fourth argument (xFilter) passed to these functions is the "filter |
| 1694 |
callback". If it is not NULL, then for each table affected by at least one |
| 1695 |
change in the changeset, the filter callback is invoked with |
| 1696 |
the table name as the second argument, and a copy of the context pointer |
| 1697 |
passed as the sixth argument as the first. If the "filter callback" |
| 1698 |
returns zero, then no attempt is made to apply any changes to the table. |
| 1699 |
Otherwise, if the return value is non-zero or the xFilter argument to |
| 1700 |
is NULL, all changes related to the table are attempted.</p> |
| 1701 |
|
| 1702 |
<p>For each table that is not excluded by the filter callback, this function |
| 1703 |
tests that the target database contains a compatible table. A table is |
| 1704 |
considered compatible if all of the following are true:</p> |
| 1705 |
|
| 1706 |
<p><ul> |
| 1707 |
<li> The table has the same name as the name recorded in the |
| 1708 |
changeset, and |
| 1709 |
<li> The table has at least as many columns as recorded in the |
| 1710 |
changeset, and |
| 1711 |
<li> The table has primary key columns in the same position as |
| 1712 |
recorded in the changeset. |
| 1713 |
</ul></p> |
| 1714 |
|
| 1715 |
<p>If there is no compatible table, it is not an error, but none of the |
| 1716 |
changes associated with the table are applied. A warning message is issued |
| 1717 |
via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most |
| 1718 |
one such warning is issued for each table in the changeset.</p> |
| 1719 |
|
| 1720 |
<p>For each change for which there is a compatible table, an attempt is made |
| 1721 |
to modify the table contents according to the UPDATE, INSERT or DELETE |
| 1722 |
change. If a change cannot be applied cleanly, the conflict handler |
| 1723 |
function passed as the fifth argument to sqlite3changeset_apply() may be |
| 1724 |
invoked. A description of exactly when the conflict handler is invoked for |
| 1725 |
each type of change is below.</p> |
| 1726 |
|
| 1727 |
<p>Unlike the xFilter argument, xConflict may not be passed NULL. The results |
| 1728 |
of passing anything other than a valid function pointer as the xConflict |
| 1729 |
argument are undefined.</p> |
| 1730 |
|
| 1731 |
<p>Each time the conflict handler function is invoked, it must return one |
| 1732 |
of <a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_OMIT</a>, <a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_ABORT</a> or |
| 1733 |
<a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_REPLACE</a>. SQLITE_CHANGESET_REPLACE may only be returned |
| 1734 |
if the second argument passed to the conflict handler is either |
| 1735 |
SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler |
| 1736 |
returns an illegal value, any changes already made are rolled back and |
| 1737 |
the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different |
| 1738 |
actions are taken by sqlite3changeset_apply() depending on the value |
| 1739 |
returned by each invocation of the conflict-handler function. Refer to |
| 1740 |
the documentation for the three |
| 1741 |
<a href="#SQLITE_CHANGESET_ABORT">available return values</a> for details.</p> |
| 1742 |
|
| 1743 |
<p><dl> |
| 1744 |
<dt>DELETE Changes<dd> |
| 1745 |
For each DELETE change, the function checks if the target database |
| 1746 |
contains a row with the same primary key value (or values) as the |
| 1747 |
original row values stored in the changeset. If it does, and the values |
| 1748 |
stored in all non-primary key columns also match the values stored in |
| 1749 |
the changeset the row is deleted from the target database.</p> |
| 1750 |
|
| 1751 |
<p> If a row with matching primary key values is found, but one or more of |
| 1752 |
the non-primary key fields contains a value different from the original |
| 1753 |
row value stored in the changeset, the conflict-handler function is |
| 1754 |
invoked with <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_DATA</a> as the second argument. If the |
| 1755 |
database table has more columns than are recorded in the changeset, |
| 1756 |
only the values of those non-primary key fields are compared against |
| 1757 |
the current database contents - any trailing database table columns |
| 1758 |
are ignored.</p> |
| 1759 |
|
| 1760 |
<p> If no row with matching primary key values is found in the database, |
| 1761 |
the conflict-handler function is invoked with <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_NOTFOUND</a> |
| 1762 |
passed as the second argument.</p> |
| 1763 |
|
| 1764 |
<p> If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT |
| 1765 |
(which can only happen if a foreign key constraint is violated), the |
| 1766 |
conflict-handler function is invoked with <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_CONSTRAINT</a> |
| 1767 |
passed as the second argument. This includes the case where the DELETE |
| 1768 |
operation is attempted because an earlier call to the conflict handler |
| 1769 |
function returned <a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_REPLACE</a>.</p> |
| 1770 |
|
| 1771 |
<p><dt>INSERT Changes<dd> |
| 1772 |
For each INSERT change, an attempt is made to insert the new row into |
| 1773 |
the database. If the changeset row contains fewer fields than the |
| 1774 |
database table, the trailing fields are populated with their default |
| 1775 |
values.</p> |
| 1776 |
|
| 1777 |
<p> If the attempt to insert the row fails because the database already |
| 1778 |
contains a row with the same primary key values, the conflict handler |
| 1779 |
function is invoked with the second argument set to |
| 1780 |
<a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_CONFLICT</a>.</p> |
| 1781 |
|
| 1782 |
<p> If the attempt to insert the row fails because of some other constraint |
| 1783 |
violation (e.g. NOT NULL or UNIQUE), the conflict handler function is |
| 1784 |
invoked with the second argument set to <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_CONSTRAINT</a>. |
| 1785 |
This includes the case where the INSERT operation is re-attempted because |
| 1786 |
an earlier call to the conflict handler function returned |
| 1787 |
<a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_REPLACE</a>.</p> |
| 1788 |
|
| 1789 |
<p><dt>UPDATE Changes<dd> |
| 1790 |
For each UPDATE change, the function checks if the target database |
| 1791 |
contains a row with the same primary key value (or values) as the |
| 1792 |
original row values stored in the changeset. If it does, and the values |
| 1793 |
stored in all modified non-primary key columns also match the values |
| 1794 |
stored in the changeset the row is updated within the target database.</p> |
| 1795 |
|
| 1796 |
<p> If a row with matching primary key values is found, but one or more of |
| 1797 |
the modified non-primary key fields contains a value different from an |
| 1798 |
original row value stored in the changeset, the conflict-handler function |
| 1799 |
is invoked with <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_DATA</a> as the second argument. Since |
| 1800 |
UPDATE changes only contain values for non-primary key fields that are |
| 1801 |
to be modified, only those fields need to match the original values to |
| 1802 |
avoid the SQLITE_CHANGESET_DATA conflict-handler callback.</p> |
| 1803 |
|
| 1804 |
<p> If no row with matching primary key values is found in the database, |
| 1805 |
the conflict-handler function is invoked with <a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_NOTFOUND</a> |
| 1806 |
passed as the second argument.</p> |
| 1807 |
|
| 1808 |
<p> If the UPDATE operation is attempted, but SQLite returns |
| 1809 |
SQLITE_CONSTRAINT, the conflict-handler function is invoked with |
| 1810 |
<a href="#SQLITE_CHANGESET_CONFLICT">SQLITE_CHANGESET_CONSTRAINT</a> passed as the second argument. |
| 1811 |
This includes the case where the UPDATE operation is attempted after |
| 1812 |
an earlier call to the conflict handler function returned |
| 1813 |
<a href="#SQLITE_CHANGESET_ABORT">SQLITE_CHANGESET_REPLACE</a>. |
| 1814 |
</dl></p> |
| 1815 |
|
| 1816 |
<p>It is safe to execute SQL statements, including those that write to the |
| 1817 |
table that the callback related to, from within the xConflict callback. |
| 1818 |
This can be used to further customize the application's conflict |
| 1819 |
resolution strategy.</p> |
| 1820 |
|
| 1821 |
<p>All changes made by these functions are enclosed in a savepoint transaction. |
| 1822 |
If any other error (aside from a constraint failure when attempting to |
| 1823 |
write to the target database) occurs, then the savepoint transaction is |
| 1824 |
rolled back, restoring the target database to its original state, and an |
| 1825 |
SQLite error code returned.</p> |
| 1826 |
|
| 1827 |
<p>If the output parameters (ppRebase) and (pnRebase) are non-NULL and |
| 1828 |
the input is a changeset (not a patchset), then sqlite3changeset_apply_v2() |
| 1829 |
may set (*ppRebase) to point to a "rebase" that may be used with the |
| 1830 |
sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase) |
| 1831 |
is set to the size of the buffer in bytes. It is the responsibility of the |
| 1832 |
caller to eventually free any such buffer using sqlite3_free(). The buffer |
| 1833 |
is only allocated and populated if one or more conflicts were encountered |
| 1834 |
while applying the patchset. See comments surrounding the sqlite3_rebaser |
| 1835 |
APIs for further details.</p> |
| 1836 |
|
| 1837 |
<p>The behavior of sqlite3changeset_apply_v2() and its streaming equivalent |
| 1838 |
may be modified by passing a combination of |
| 1839 |
<a href="#SQLITE_CHANGESETAPPLY_FKNOACTION">supported flags</a> as the 9th parameter.</p> |
| 1840 |
|
| 1841 |
<p>Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b> |
| 1842 |
and therefore subject to change. |
| 1843 |
</p><hr><a name="sqlite3changeset_start"></a> |
| 1844 |
<h2>Create An Iterator To Traverse A Changeset </h2><blockquote><pre>int sqlite3changeset_start( |
| 1845 |
sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ |
| 1846 |
int nChangeset, /* Size of changeset blob in bytes */ |
| 1847 |
void *pChangeset /* Pointer to blob containing changeset */ |
| 1848 |
); |
| 1849 |
int sqlite3changeset_start_v2( |
| 1850 |
sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ |
| 1851 |
int nChangeset, /* Size of changeset blob in bytes */ |
| 1852 |
void *pChangeset, /* Pointer to blob containing changeset */ |
| 1853 |
int flags /* SESSION_CHANGESETSTART_* flags */ |
| 1854 |
); |
| 1855 |
</pre></blockquote><p> |
| 1856 |
Create an iterator used to iterate through the contents of a changeset. |
| 1857 |
If successful, *pp is set to point to the iterator handle and SQLITE_OK |
| 1858 |
is returned. Otherwise, if an error occurs, *pp is set to zero and an |
| 1859 |
SQLite error code is returned.</p> |
| 1860 |
|
| 1861 |
<p>The following functions can be used to advance and query a changeset |
| 1862 |
iterator created by this function:</p> |
| 1863 |
|
| 1864 |
<p><ul> |
| 1865 |
<li> <a href="#sqlite3changeset_next">sqlite3changeset_next()</a> |
| 1866 |
<li> <a href="#sqlite3changeset_op">sqlite3changeset_op()</a> |
| 1867 |
<li> <a href="#sqlite3changeset_new">sqlite3changeset_new()</a> |
| 1868 |
<li> <a href="#sqlite3changeset_old">sqlite3changeset_old()</a> |
| 1869 |
</ul></p> |
| 1870 |
|
| 1871 |
<p>It is the responsibility of the caller to eventually destroy the iterator |
| 1872 |
by passing it to <a href="#sqlite3changeset_finalize">sqlite3changeset_finalize()</a>. The buffer containing the |
| 1873 |
changeset (pChangeset) must remain valid until after the iterator is |
| 1874 |
destroyed.</p> |
| 1875 |
|
| 1876 |
<p>Assuming the changeset blob was created by one of the |
| 1877 |
<a href="#sqlite3session_changeset">sqlite3session_changeset()</a>, <a href="#sqlite3changeset_concat">sqlite3changeset_concat()</a> or |
| 1878 |
<a href="#sqlite3changeset_invert">sqlite3changeset_invert()</a> functions, all changes within the changeset |
| 1879 |
that apply to a single table are grouped together. This means that when |
| 1880 |
an application iterates through a changeset using an iterator created by |
| 1881 |
this function, all changes that relate to a single table are visited |
| 1882 |
consecutively. There is no chance that the iterator will visit a change |
| 1883 |
the applies to table X, then one for table Y, and then later on visit |
| 1884 |
another change for table X.</p> |
| 1885 |
|
| 1886 |
<p>The behavior of sqlite3changeset_start_v2() and its streaming equivalent |
| 1887 |
may be modified by passing a combination of |
| 1888 |
<a href="#SQLITE_CHANGESETSTART_INVERT">supported flags</a> as the 4th parameter.</p> |
| 1889 |
|
| 1890 |
<p>Note that the sqlite3changeset_start_v2() API is still <b>experimental</b> |
| 1891 |
and therefore subject to change. |
| 1892 |
</p><hr> |
| 1893 |
|
| 1894 |
|