Debian Codegraph @

www/lang_transaction.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>Transaction</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.svg" 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 Transaction
122 </div>
123 </div>
124
125
126
127
128 <h1 id="transaction_control_syntax"><span>1. </span>Transaction Control Syntax</h1>
129
130 <p><b><a href="syntax/begin-stmt.html">begin-stmt:</a></b>
131 <button id='xc6ccebc6' onclick='hideorshow("xc6ccebc6","x74ffd7aa")'>hide</button></p>
132 <div id='x74ffd7aa' class='imgcontainer'>
133 <div style="max-width:560px"><svg xmlns='http://www.w3.org/2000/svg' style='font-size:initial;' class="pikchr" viewBox="0 0 560.669 140.4" data-pikchr-date="20250319161943">
134 <circle cx="5.76" cy="17.28" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
135 <polygon points="32.4,17.28 20.88,21.6 20.88,12.96" style="fill:rgb(0,0,0)"/>
136 <path d="M9.36,17.28L26.64,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
137 <path d="M47.52,32.4L86.1696,32.4A15.12 15.12 0 0 0 101.29 17.28A15.12 15.12 0 0 0 86.1696 2.16L47.52,2.16A15.12 15.12 0 0 0 32.4 17.28A15.12 15.12 0 0 0 47.52 32.4Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
138 <text x="66.8448" y="17.28" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">BEGIN</text>
139 <polygon points="124.33,17.28 112.81,21.6 112.81,12.96" style="fill:rgb(0,0,0)"/>
140 <path d="M101.29,17.28L118.57,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
141 <polygon points="162.37,123.12 150.85,127.44 150.85,118.8" style="fill:rgb(0,0,0)"/>
142 <path d="M124.33,17.28 L 131.83,17.28 Q 139.33,17.28 139.33,32.28 L 139.33,108.12 Q 139.33,123.12 147.97,123.12 L 156.61,123.12" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
143 <path d="M177.49,138.24L261.067,138.24A15.12 15.12 0 0 0 276.187 123.12A15.12 15.12 0 0 0 261.067 108L177.49,108A15.12 15.12 0 0 0 162.37 123.12A15.12 15.12 0 0 0 177.49 138.24Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
144 <text x="219.278" y="123.12" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">EXCLUSIVE</text>
145 <polygon points="299.227,123.12 287.707,127.44 287.707,118.8" style="fill:rgb(0,0,0)"/>
146 <path d="M276.187,123.12L293.467,123.12" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
147 <polygon points="337.267,17.28 325.747,21.6 325.747,12.96" style="fill:rgb(0,0,0)"/>
148 <path d="M299.227,123.12 L 306.727,123.12 Q 314.227,123.12 314.227,108.12 L 314.227,32.28 Q 314.227,17.28 322.867,17.28 L 331.507,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
149 <polygon points="373.267,17.28 361.747,21.6 361.747,12.96" style="fill:rgb(0,0,0)"/>
150 <path d="M337.267,17.28L367.507,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
151 <path d="M388.387,32.4L500.189,32.4A15.12 15.12 0 0 0 515.309 17.28A15.12 15.12 0 0 0 500.189 2.16L388.387,2.16A15.12 15.12 0 0 0 373.267 17.28A15.12 15.12 0 0 0 388.387 32.4Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
152 <text x="444.288" y="17.28" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">TRANSACTION</text>
153 <polygon points="551.309,17.28 539.789,21.6 539.789,12.96" style="fill:rgb(0,0,0)"/>
154 <path d="M515.309,17.28L545.549,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
155 <circle cx="554.909" cy="17.28" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
156 <polygon points="444.288,47.52 432.768,51.84 432.768,43.2" style="fill:rgb(0,0,0)"/>
157 <path d="M337.267,17.28 L 344.767,17.28 Q 352.267,17.28 352.267,32.28 L 352.267,32.52 Q 352.267,47.52 367.267,47.52 L 423.528,47.52 L 438.528,47.52" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
158 <path d="M444.288,47.52 L 511.109,47.52 Q 526.109,47.52 526.109,32.52 L 526.109,32.28 Q 526.109,17.28 533.609,17.28 L 541.109,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
159 <path d="M124.33,17.28L325.747,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
160 <polygon points="162.37,47.52 150.85,51.84 150.85,43.2" style="fill:rgb(0,0,0)"/>
161 <path d="M139.33,32.28 L 139.33,39.9 Q 139.33,47.52 147.97,47.52 L 156.61,47.52" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
162 <path d="M177.49,62.64L257.496,62.64A15.12 15.12 0 0 0 272.616 47.52L272.616,47.52A15.12 15.12 0 0 0 257.496 32.4L177.49,32.4A15.12 15.12 0 0 0 162.37 47.52L162.37,47.52A15.12 15.12 0 0 0 177.49 62.64Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
163 <text x="217.493" y="47.52" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">DEFERRED</text>
164 <polygon points="295.656,47.52 284.136,51.84 284.136,43.2" style="fill:rgb(0,0,0)"/>
165 <path d="M272.616,47.52L289.896,47.52" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
166 <path d="M295.656,47.52 L 304.942,47.52 Q 314.227,47.52 314.227,40.02 L 314.227,32.52" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
167 <polygon points="162.37,85.32 150.85,89.64 150.85,81" style="fill:rgb(0,0,0)"/>
168 <path d="M139.33,32.28 L 139.33,70.32 Q 139.33,85.32 147.97,85.32 L 156.61,85.32" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
169 <path d="M177.49,100.44L265.906,100.44A15.12 15.12 0 0 0 281.026 85.32A15.12 15.12 0 0 0 265.906 70.2L177.49,70.2A15.12 15.12 0 0 0 162.37 85.32A15.12 15.12 0 0 0 177.49 100.44Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
170 <text x="221.698" y="85.32" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">IMMEDIATE</text>
171 <polygon points="304.066,85.32 292.546,89.64 292.546,81" style="fill:rgb(0,0,0)"/>
172 <path d="M281.026,85.32L298.306,85.32" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
173 <path d="M304.066,85.32 L 309.146,85.32 Q 314.227,85.32 314.227,77.82 L 314.227,70.32" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
174 </svg>
175 </div>
176 </div>
177 <p><b><a href="syntax/commit-stmt.html">commit-stmt:</a></b>
178 <button id='x55c3dea8' onclick='hideorshow("x55c3dea8","x05fabae0")'>hide</button></p>
179 <div id='x05fabae0' class='imgcontainer'>
180 <div style="max-width:434px"><svg xmlns='http://www.w3.org/2000/svg' style='font-size:initial;' class="pikchr" viewBox="0 0 434.506 72.36" data-pikchr-date="20250319161943">
181 <circle cx="5.76" cy="17.28" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
182 <polygon points="32.4,17.28 20.88,21.6 20.88,12.96" style="fill:rgb(0,0,0)"/>
183 <path d="M9.36,17.28L26.64,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
184 <polygon points="68.4,17.28 56.88,21.6 56.88,12.96" style="fill:rgb(0,0,0)"/>
185 <path d="M32.4,17.28L62.64,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
186 <path d="M83.52,32.4L141.984,32.4A15.12 15.12 0 0 0 157.104 17.28A15.12 15.12 0 0 0 141.984 2.16L83.52,2.16A15.12 15.12 0 0 0 68.4 17.28A15.12 15.12 0 0 0 83.52 32.4Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
187 <text x="112.752" y="17.28" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">COMMIT</text>
188 <polygon points="202.104,17.28 190.584,21.6 190.584,12.96" style="fill:rgb(0,0,0)"/>
189 <path d="M157.104,17.28L196.344,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
190 <path d="M202.104,17.28L238.104,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
191 <path d="M253.224,32.4L365.026,32.4A15.12 15.12 0 0 0 380.146 17.28A15.12 15.12 0 0 0 365.026 2.16L253.224,2.16A15.12 15.12 0 0 0 238.104 17.28A15.12 15.12 0 0 0 253.224 32.4Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
192 <text x="309.125" y="17.28" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">TRANSACTION</text>
193 <polygon points="425.146,17.28 413.626,21.6 413.626,12.96" style="fill:rgb(0,0,0)"/>
194 <path d="M380.146,17.28L419.386,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
195 <circle cx="428.746" cy="17.28" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
196 <path d="M83.52,70.2L104.544,70.2A15.12 15.12 0 0 0 119.664 55.08L119.664,55.08A15.12 15.12 0 0 0 104.544 39.96L83.52,39.96A15.12 15.12 0 0 0 68.4 55.08L68.4,55.08A15.12 15.12 0 0 0 83.52 70.2Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
197 <text x="94.032" y="55.08" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">END</text>
198 <polygon points="68.4,55.08 56.88,59.4 56.88,50.76" style="fill:rgb(0,0,0)"/>
199 <path d="M32.4,17.28 L 39.9,17.28 Q 47.4,17.28 47.4,32.28 L 47.4,40.08 Q 47.4,55.08 55.02,55.08 L 62.64,55.08" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
200 <polygon points="157.104,55.08 145.584,59.4 145.584,50.76" style="fill:rgb(0,0,0)"/>
201 <path d="M119.664,55.08L151.344,55.08" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
202 <path d="M157.104,55.08 L 164.604,55.08 Q 172.104,55.08 172.104,40.08 L 172.104,32.28 Q 172.104,17.28 179.604,17.28 L 187.104,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
203 <polygon points="309.125,47.52 297.605,51.84 297.605,43.2" style="fill:rgb(0,0,0)"/>
204 <path d="M202.104,17.28 L 209.604,17.28 Q 217.104,17.28 217.104,32.28 L 217.104,32.52 Q 217.104,47.52 232.104,47.52 L 288.365,47.52 L 303.365,47.52" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
205 <path d="M309.125,47.52 L 380.146,47.52 Q 395.146,47.52 395.146,32.52 L 395.146,32.28 Q 395.146,17.28 402.646,17.28 L 410.146,17.28" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
206 </svg>
207 </div>
208 </div>
209 <p><b><a href="syntax/rollback-stmt.html">rollback-stmt:</a></b>
210 <button id='x72f5b839' onclick='hideorshow("x72f5b839","x39b7bb25")'>hide</button></p>
211 <div id='x39b7bb25' class='imgcontainer'>
212 <div style="max-width:801px"><svg xmlns='http://www.w3.org/2000/svg' style='font-size:initial;' class="pikchr" viewBox="0 0 801.734 67.392" data-pikchr-date="20250319161943">
213 <circle cx="5.76" cy="33.696" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
214 <polygon points="32.4,33.696 20.88,38.016 20.88,29.376" style="fill:rgb(0,0,0)"/>
215 <path d="M9.36,33.696L26.64,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
216 <path d="M47.52,48.816L125.107,48.816A15.12 15.12 0 0 0 140.227 33.696A15.12 15.12 0 0 0 125.107 18.576L47.52,18.576A15.12 15.12 0 0 0 32.4 33.696A15.12 15.12 0 0 0 47.52 48.816Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
217 <text x="86.3136" y="33.696" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">ROLLBACK</text>
218 <polygon points="176.227,33.696 164.707,38.016 164.707,29.376" style="fill:rgb(0,0,0)"/>
219 <path d="M140.227,33.696L170.467,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
220 <path d="M191.347,48.816L303.149,48.816A15.12 15.12 0 0 0 318.269 33.696A15.12 15.12 0 0 0 303.149 18.576L191.347,18.576A15.12 15.12 0 0 0 176.227 33.696A15.12 15.12 0 0 0 191.347 48.816Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
221 <text x="247.248" y="33.696" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">TRANSACTION</text>
222 <polygon points="390.269,33.696 378.749,38.016 378.749,29.376" style="fill:rgb(0,0,0)"/>
223 <path d="M318.269,33.696L384.509,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
224 <path d="M405.389,48.816L411.091,48.816A15.12 15.12 0 0 0 426.211 33.696A15.12 15.12 0 0 0 411.091 18.576L405.389,18.576A15.12 15.12 0 0 0 390.269 33.696A15.12 15.12 0 0 0 405.389 48.816Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
225 <text x="408.24" y="33.696" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">TO</text>
226 <polygon points="462.211,33.696 450.691,38.016 450.691,29.376" style="fill:rgb(0,0,0)"/>
227 <path d="M426.211,33.696L456.451,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
228 <path d="M477.331,48.816L561.6,48.816A15.12 15.12 0 0 0 576.72 33.696A15.12 15.12 0 0 0 561.6 18.576L477.331,18.576A15.12 15.12 0 0 0 462.211 33.696A15.12 15.12 0 0 0 477.331 48.816Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
229 <text x="519.466" y="33.696" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">SAVEPOINT</text>
230 <polygon points="612.72,33.696 601.2,38.016 601.2,29.376" style="fill:rgb(0,0,0)"/>
231 <path d="M576.72,33.696L606.96,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
232 <path d="M627.84,48.816L741.254,48.816A15.12 15.12 0 0 0 756.374 33.696A15.12 15.12 0 0 0 741.254 18.576L627.84,18.576A15.12 15.12 0 0 0 612.72 33.696A15.12 15.12 0 0 0 627.84 48.816Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
233 <text x="684.547" y="33.696" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">savepoint-name</text>
234 <polygon points="792.374,33.696 780.854,38.016 780.854,29.376" style="fill:rgb(0,0,0)"/>
235 <path d="M756.374,33.696L786.614,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
236 <circle cx="795.974" cy="33.696" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
237 <polygon points="519.466,6.48 507.946,10.8 507.946,2.16" style="fill:rgb(0,0,0)"/>
238 <path d="M426.211,33.696 L 433.711,33.696 Q 441.211,33.696 441.211,20.088 Q 441.211,6.48 456.211,6.48 L 498.706,6.48 L 513.706,6.48" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
239 <path d="M519.466,6.48 L 576.72,6.48 Q 591.72,6.48 591.72,20.088 Q 591.72,33.696 599.22,33.696 L 606.72,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
240 <polygon points="519.466,60.912 507.946,65.232 507.946,56.592" style="fill:rgb(0,0,0)"/>
241 <path d="M352.229,33.696 L 359.729,33.696 Q 367.229,33.696 367.229,47.304 Q 367.229,60.912 382.229,60.912 L 498.706,60.912 L 513.706,60.912" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
242 <path d="M519.466,60.912 L 756.374,60.912 Q 771.374,60.912 771.374,47.304 Q 771.374,33.696 778.874,33.696 L 786.374,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
243 <polygon points="247.248,60.912 235.728,65.232 235.728,56.592" style="fill:rgb(0,0,0)"/>
244 <path d="M140.227,33.696 L 147.727,33.696 Q 155.227,33.696 155.227,47.304 Q 155.227,60.912 170.227,60.912 L 226.488,60.912 L 241.488,60.912" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
245 <path d="M247.248,60.912 L 318.269,60.912 Q 333.269,60.912 333.269,47.304 Q 333.269,33.696 340.769,33.696 L 348.269,33.696" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
246 </svg>
247 </div>
248 </div>
249
250
251 <h1 id="transactions"><span>2. </span>Transactions</h1>
252
253 <p>
254 No reads or writes occur except within a transaction.
255 Any command that accesses the database (basically, any SQL command,
256 except a few <a href="pragma.html#syntax">PRAGMA</a> statements)
257 will automatically start a transaction if
258 one is not already in effect. Automatically started transactions
259 are committed when the last SQL statement finishes.
260 </p>
261
262 <p>
263 Transactions can be started manually using the BEGIN
264 command. Such transactions usually persist until the next
265 COMMIT or ROLLBACK command. But a transaction will also
266 ROLLBACK if the database is closed or if an error occurs
267 and the ROLLBACK conflict resolution algorithm is specified.
268 See the documentation on the <a href="lang_conflict.html">ON CONFLICT</a>
269 clause for additional information about the ROLLBACK
270 conflict resolution algorithm.
271 </p>
272
273 <p>
274 END TRANSACTION is an alias for COMMIT.
275 </p>
276
277 <p> Transactions created using BEGIN...COMMIT do not nest.
278 For nested transactions, use the <a href="lang_savepoint.html">SAVEPOINT</a> and <a href="lang_savepoint.html">RELEASE</a> commands.
279 The "TO SAVEPOINT <span class='yyterm'>name</span>" clause of the ROLLBACK command shown
280 in the syntax diagram above is only applicable to <a href="lang_savepoint.html">SAVEPOINT</a>
281 transactions. An attempt to invoke the BEGIN command within
282 a transaction will fail with an error, regardless of whether
283 the transaction was started by <a href="lang_savepoint.html">SAVEPOINT</a> or a prior BEGIN.
284 The COMMIT command and the ROLLBACK command without the TO clause
285 work the same on <a href="lang_savepoint.html">SAVEPOINT</a> transactions as they do with transactions
286 started by BEGIN.</p>
287
288 <h2 id="read_transactions_versus_write_transactions"><span>2.1. </span>Read transactions versus write transactions</h2>
289
290 <p>SQLite supports multiple simultaneous read transactions
291 coming from separate database connections, possibly in separate
292 threads or processes, but only one simultaneous write transaction.
293 </p><p>
294
295 </p><p>A read transaction is used for reading only. A write transaction
296 allows both reading and writing. A read transaction is started
297 by a SELECT statement, and a write transaction is started by
298 statements like CREATE, DELETE, DROP, INSERT, or UPDATE (collectively
299 "write statements"). If a write statement occurs while
300 a read transaction is active, then the read transaction is upgraded
301 to a write transaction if possible. If some other database connection
302 has already modified the database or is already in the process of
303 modifying the database, then upgrading to a write transaction is
304 not possible and the write statement will fail with <a href="rescode.html#busy">SQLITE_BUSY</a>.
305 </p>
306
307 <p>
308 While a read transaction is active, any changes to the database that
309 are implemented by separate database connections will not be seen
310 by the database connection that started the read transaction. If database
311 connection X is holding a read transaction, it is possible that some
312 other database connection Y might change the content of the database
313 while X's transaction is still open, however X will not be able to see
314 those changes until after the transaction ends. While its read
315 transaction is active, X will continue to see an historic snapshot of
316 the database prior to the changes implemented by Y.
317 </p>
318
319
320 <a name="immediate"></a>
321
322 <h2 id="deferred_immediate_and_exclusive_transactions"><span>2.2. </span>DEFERRED, IMMEDIATE, and EXCLUSIVE transactions</h2>
323
324 <p>
325 Transactions can be DEFERRED, IMMEDIATE, or EXCLUSIVE.
326 The default transaction behavior is DEFERRED.
327 </p>
328
329 <p>
330 DEFERRED means that the transaction does not actually
331 start until the database is first accessed. Internally,
332 the BEGIN DEFERRED statement merely sets a flag on the database
333 connection that turns off the automatic commit that would normally
334 occur when the last statement finishes. This causes the transaction
335 that is automatically started to persist until an explicit
336 COMMIT or ROLLBACK or until a rollback is provoked by an error
337 or an ON CONFLICT ROLLBACK clause. If the first statement after
338 BEGIN DEFERRED is a SELECT, then a read transaction is started.
339 Subsequent write statements will upgrade the transaction to a
340 write transaction if possible, or return SQLITE_BUSY. If the
341 first statement after BEGIN DEFERRED is a write statement, then
342 a write transaction is started.
343 </p>
344
345 <p>
346 IMMEDIATE causes the database connection to start a new write
347 immediately, without waiting for a write statement. The
348 BEGIN IMMEDIATE might fail with <a href="rescode.html#busy">SQLITE_BUSY</a> if another write
349 transaction is already active on another database connection.
350 </p>
351
352 <p>
353 EXCLUSIVE is similar to IMMEDIATE in that a write transaction
354 is started immediately. EXCLUSIVE and IMMEDIATE are the same
355 in <a href="wal.html">WAL mode</a>, but in other journaling modes, EXCLUSIVE prevents
356 other database connections from reading the database while the
357 transaction is underway.
358 </p>
359
360 <h2 id="implicit_versus_explicit_transactions"><span>2.3. </span>Implicit versus explicit transactions</h2>
361
362 <p>
363 An implicit transaction (a transaction that is started automatically,
364 not a transaction started by BEGIN) is committed automatically when
365 the last active statement finishes. A statement finishes when its
366 last cursor closes, which is guaranteed to happen when the
367 prepared statement is <a href="c3ref/reset.html">reset</a> or
368 <a href="c3ref/finalize.html">finalized</a>. Some statements might "finish"
369 for the purpose of transaction control prior to being reset or finalized,
370 but there is no guarantee of this. The only way to ensure that a
371 statement has "finished" is to invoke <a href="c3ref/reset.html">sqlite3_reset()</a> or
372 <a href="c3ref/finalize.html">sqlite3_finalize()</a> on that statement. An open <a href="c3ref/blob.html">sqlite3_blob</a> used for
373 incremental BLOB I/O also counts as an unfinished statement.
374 The <a href="c3ref/blob.html">sqlite3_blob</a> finishes when it is <a href="c3ref/blob_close.html">closed</a>.
375 </p>
376
377 <p>
378 The explicit COMMIT command runs immediately, even if there are
379 pending <a href="lang_select.html">SELECT</a> statements. However, if there are pending
380 write operations, the COMMIT command
381 will fail with an error code <a href="rescode.html#busy">SQLITE_BUSY</a>.
382 </p>
383
384 <p>
385 An attempt to execute COMMIT might also result in an <a href="rescode.html#busy">SQLITE_BUSY</a> return code
386 if another thread or process has an open read connection.
387 When COMMIT fails in this
388 way, the transaction remains active and the COMMIT can be retried later
389 after the reader has had a chance to clear.
390 </p>
391
392 <p>
393 In very old versions of SQLite (before version 3.7.11 - 2012-03-20)
394 the ROLLBACK will fail with an error code
395 <a href="rescode.html#busy">SQLITE_BUSY</a> if there are any pending queries. In more recent
396 versions of SQLite, the ROLLBACK will proceed and pending statements
397 will often be aborted, causing them to return an <a href="rescode.html#abort">SQLITE_ABORT</a> or
398 <a href="rescode.html#abort_rollback">SQLITE_ABORT_ROLLBACK</a> error.
399 In SQLite version 3.8.8 (2015-01-16) and later,
400 a pending read will continue functioning
401 after the ROLLBACK as long as the ROLLBACK does not modify the database
402 schema.
403 </p>
404
405 <p>
406 If <a href="pragma.html#pragma_journal_mode">PRAGMA journal_mode</a> is set to OFF (thus disabling the rollback journal
407 file) then the behavior of the ROLLBACK command is undefined.
408 </p>
409
410 <h1 id="response_to_errors_within_a_transaction"><span>3. </span>Response To Errors Within A Transaction</h1>
411
412 <p> If certain kinds of errors occur within a transaction, the
413 transaction may or may not be rolled back automatically. The
414 errors that can cause an automatic rollback include:</p>
415
416 <ul>
417 <li> <a href="rescode.html#full">SQLITE_FULL</a>: database or disk full
418 </li><li> <a href="rescode.html#ioerr">SQLITE_IOERR</a>: disk I/O error
419 </li><li> <a href="rescode.html#interrupt">SQLITE_INTERRUPT</a>: operation interrupted by <a href="c3ref/interrupt.html">sqlite3_interrupt()</a>
420 or similar.
421 </li><li> <a href="rescode.html#nomem">SQLITE_NOMEM</a>: out of memory
422 </li></ul>
423
424 <p>
425 For all of these errors, SQLite attempts to undo just the one statement
426 it was working on and leave changes from prior statements within the
427 same transaction intact and continue with the transaction. However,
428 depending on the statement being evaluated and the point at which the
429 error occurs, it might be necessary for SQLite to rollback and
430 cancel the entire transaction. An application can tell which
431 course of action SQLite took by using the
432 <a href="c3ref/get_autocommit.html">sqlite3_get_autocommit()</a> or
433 <a href="c3ref/txn_state.html">sqlite3_txn_state()</a> C-language interfaces.</p>
434
435 <p>An application might want to respond to the errors
436 listed above by explicitly issuing a ROLLBACK command. In that way,
437 the transaction state will always be the same after one of the errors
438 above. If the transaction has already been rolled back automatically
439 by the error response, then the ROLLBACK command will fail with an
440 error, but no harm is caused by this.</p>
441
442 <p>Future versions of SQLite may extend the list of errors which
443 might cause automatic transaction rollback. Future versions of
444 SQLite might change the error response. In particular, we may
445 choose to simplify the interface in future versions of SQLite by
446 causing the errors above to force an unconditional rollback.</p>
447 <p align="center"><small><i>This page was last updated on 2026-02-18 11:56:50Z </small></i></p>
448