Debian Codegraph @

www/sqldiff.html

raw
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>sqldiff.exe: Database Difference Utility</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 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 sqldiff.exe: Database Difference Utility
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#usage">1. Usage</a></div>
129 <div class="fancy-toc1"><a href="#how_it_works">2. How It Works</a></div>
130 <div class="fancy-toc1"><a href="#limitations">3. Limitations</a></div>
131 </div>
132 </div>
133 <script>
134 function toggle_toc(){
135 var sub = document.getElementById("toc_sub")
136 var mk = document.getElementById("toc_mk")
137 if( sub.style.display!="block" ){
138 sub.style.display = "block";
139 mk.innerHTML = "&#x25bc;";
140 } else {
141 sub.style.display = "none";
142 mk.innerHTML = "&#x25ba;";
143 }
144 }
145 </script>
146 </div>
147
148
149
150
151 <h1 id="usage"><span>1. </span>Usage</h1>
152
153 <p>
154 The <tt>sqldiff.exe</tt> binary is a command-line utility program that
155 displays content differences between SQLite databases. Example
156 usage:
157
158 </p><div class="codeblock"><pre>sqldiff &#91;options&#93; database1.sqlite database2.sqlite
159 </pre></div>
160
161 <p>
162 The usual output is an SQL script that will transform
163 database1.sqlite (the "source" database) into database2.sqlite
164 (the "destination" database). This behavior can be
165 altered using command-line switches:
166
167 </p><dl>
168 <dt><b>--changeset FILE</b></dt>
169 <dd><p>Do not write changes to standard output. Instead, write a (binary)
170 changeset file into FILE. The changeset can be interpreted using
171 the <a href="sessionintro.html">session extension</a> to SQLite.</p></dd>
172 <dt><b>--lib LIBRARY</b></dt>
173 <dt><b>-L LIBRARY</b></dt>
174 <dd><p>Load the shared library or DLL file LIBRARY into SQLite prior to
175 computing the differences. This can be used to add application-defined
176 <a href="datatype3.html#collation">collating sequences</a> that are required by the schema.
177 </p></dd><dt><b>--primarykey</b></dt>
178 <dd><p>Use the schema-defined <a href="lang_createtable.html#primkeyconst">PRIMARY KEY</a> instead of the <a href="lang_createtable.html#rowid">rowid</a> to
179 pair rows in the source and destination database. (See additional
180 explanation below.)</p></dd>
181 <dt><b>--schema</b></dt>
182 <dd><p>Show only column name and table differences in the schema,
183 not the table content</p></dd>
184 <dt><b>--summary</b></dt>
185 <dd><p>Show how many rows have changed on each table, but do not show
186 the actual changes</p></dd>
187 <dt><b>--table TABLE</b></dt>
188 <dd><p>Show only the differences in content for TABLE, not for the
189 entire database</p></dd>
190 <dt><b>--transaction</b></dt>
191 <dd><p>Wrap SQL output in a single large transaction</p></dd>
192 <dt><b>--vtab</b></dt>
193 <dd><p>Add support for handling <a href="fts3.html">FTS3</a>, <a href="fts5.html">FTS5</a> and <a href="rtree.html">rtree</a> virtual tables.
194 <a href="#sqldiff_vtab">See below</a> for details.
195 </p></dd>
196 </dl>
197
198 <h1 id="how_it_works"><span>2. </span>How It Works</h1>
199
200 <p>The sqldiff.exe utility works by finding rows in the source and
201 destination that are logical "pairs". The default behavior is to
202 treat two rows as pairs if they are in tables with the same name
203 and they have the same <a href="lang_createtable.html#rowid">rowid</a>, or in the case of a <a href="withoutrowid.html">WITHOUT ROWID</a>
204 table if they have the same <a href="lang_createtable.html#primkeyconst">PRIMARY KEY</a>. Any differences in the
205 content of paired rows are output as UPDATEs. Rows in the source
206 database that could not be paired are output as DELETEs. Rows in
207 the destination database that could not be paired are output as
208 INSERTs.
209
210 </p><p>The --primarykey flag changes the pairing algorithm slightly so
211 that the schema-declared <a href="lang_createtable.html#primkeyconst">PRIMARY KEY</a> is always used for pairing,
212 even on tables that have a <a href="lang_createtable.html#rowid">rowid</a>. This is often a better choice
213 for finding differences, however it can lead to missed differences in
214 the case of rows that have one or more PRIMARY KEY columns set to
215 NULL.</p>
216
217 <h1 id="limitations"><span>3. </span>Limitations</h1>
218
219 <ol>
220 <li>
221 <p>The sqldiff.exe utility does not compute changesets for
222 either: rowid tables for which the rowid is inaccessible;
223 or tables which have no explicit primary key.
224 Given the --changeset option, sqldiff omits them from the comparison.
225 Examples of such tables are:
226
227 </p><div class="codeblock"><pre>CREATE TABLE NilChangeset (
228 -- inaccessible rowid due to hiding its aliases
229 "rowid" TEXT,
230 "oid" TEXT,
231 "_rowid_" TEXT
232 );
233 </pre></div>
234
235 and
236
237 <div class="codeblock"><pre>CREATE TABLE NilChangeset (
238 -- no explicit primary key
239 "authorId" TEXT,
240 "bookId" TEXT
241 );
242 </pre></div>
243
244
245 When sqldiff is made to compare only such tables, no error occurs.
246 However, the result may be unexpected.
247 For example, the effect of this invocation:
248
249 <div class="codeblock"><pre>sqldiff --changeset CHANGESET_OUT --table NilChangeset db1.sdb db2.sdb
250 </pre></div>
251
252 will be to produce an empty file named "CHANGESET_OUT". See <a href="sessionintro.html#limitations">session limitations</a> for details.
253 </li><li><p>
254 The sqldiff.exe utility does not (currently) display differences in
255 <a href="lang_createtrigger.html">TRIGGERs</a> or <a href="lang_createview.html">VIEWs</a>.
256
257 </p></li><li><p>
258 The sqldiff utility is not designed to support schema migrations
259 and is forgiving with respect to differing column definitions.
260 Normally, only the column names and their order are compared
261 for like-named tables before content comparison proceeds.
262
263 </p><p>However, the single-table comparison option, with "sqlite_schema"
264 named, can be used to show or detect detailed schema differences
265 between a pair of databases.
266 When doing this, the output should not be used directly to modify a database.
267
268 <a name="sqldiff_vtab"></a>
269
270 </p></li><li><p id="vtab">
271 By default, differences in the schema or content of virtual tables are
272 not reported on.
273
274 </p><p>However, if a <a href="vtab.html">virtual table</a> implementation creates real tables (sometimes
275 referred to as "shadow" tables) within the database to store its data in, then
276 sqldiff.exe does calculate the difference between these. This can have
277 surprising effects if the resulting SQL script is then run on a database that
278 is not <i>exactly</i> the same as the source database. For several of SQLite's
279 bundled virtual tables (FTS3, FTS5, rtree and others), the surprising effects
280 may include corruption of the virtual table content.
281
282 </p><p> If the --vtab option is passed to sqldiff.exe, then it ignores all
283 underlying shadow tables belonging to an FTS3, FTS5 or rtree virtual table
284 and instead includes the virtual table differences directly.
285
286 </p></li></ol>
287 <p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/sqldiff.in?m=a0553bcc5b">2023-01-06 00:45:39</a> UTC </small></i></p>
288