Debian Codegraph @

www/cintro.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>An Introduction To The SQLite 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 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 An Introduction To The SQLite C/C++ Interface
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="#summary">1. Summary</a></div>
129 <div class="fancy-toc1"><a href="#introduction">2. Introduction</a></div>
130 <div class="fancy-toc1"><a href="#core_objects_and_interfaces">3. Core Objects And Interfaces</a></div>
131 <div class="fancy-toc1"><a href="#typical_usage_of_core_routines_and_objects">4. Typical Usage Of Core Routines And Objects</a></div>
132 <div class="fancy-toc1"><a href="#convenience_wrappers_around_core_routines">5. Convenience Wrappers Around Core Routines</a></div>
133 <div class="fancy-toc1"><a href="#binding_parameters_and_reusing_prepared_statements">6. Binding Parameters and Reusing Prepared Statements</a></div>
134 <div class="fancy-toc1"><a href="#configuring_sqlite">7. Configuring SQLite</a></div>
135 <div class="fancy-toc1"><a href="#extending_sqlite">8. Extending SQLite</a></div>
136 <div class="fancy-toc1"><a href="#other_interfaces">9. Other Interfaces</a></div>
137 </div>
138 </div>
139 <script>
140 function toggle_toc(){
141 var sub = document.getElementById("toc_sub")
142 var mk = document.getElementById("toc_mk")
143 if( sub.style.display!="block" ){
144 sub.style.display = "block";
145 mk.innerHTML = "&#x25bc;";
146 } else {
147 sub.style.display = "none";
148 mk.innerHTML = "&#x25ba;";
149 }
150 }
151 </script>
152 </div>
153
154
155
156
157
158
159 <h1 id="summary"><span>1. </span>Summary</h1>
160
161 <p>The following two objects and eight methods comprise the essential
162 elements of the SQLite interface:
163
164 </p><ul>
165 <li><p><b><a href="c3ref/sqlite3.html">sqlite3</a></b> &rarr;
166 The database connection object. Created by
167 <a href="c3ref/open.html">sqlite3_open()</a> and destroyed by <a href="c3ref/close.html">sqlite3_close()</a>.
168
169 </p></li><li><p><b><a href="c3ref/stmt.html">sqlite3_stmt</a></b> &rarr;
170 The prepared statement object. Created by
171 <a href="c3ref/prepare.html">sqlite3_prepare()</a> and destroyed by <a href="c3ref/finalize.html">sqlite3_finalize()</a>.
172
173
174 </p></li><li><p><b><a href="c3ref/open.html">sqlite3_open()</a></b> &rarr;
175 Open a connection to a new or existing SQLite database.
176 The constructor for <a href="c3ref/sqlite3.html">sqlite3</a>.
177
178 </p></li><li><p><b><a href="c3ref/prepare.html">sqlite3_prepare()</a></b> &rarr;
179 Compile SQL text into
180 byte-code that will do the work of querying or updating the database.
181 The constructor for <a href="c3ref/stmt.html">sqlite3_stmt</a>.
182
183 </p></li><li><p><b><a href="c3ref/bind_blob.html">sqlite3_bind()</a></b> &rarr;
184 Store application data into
185 <a href="lang_expr.html#varparam">parameters</a> of the original SQL.
186
187
188 </p></li><li><p><b><a href="c3ref/step.html">sqlite3_step()</a></b> &rarr;
189 Advance an <a href="c3ref/stmt.html">sqlite3_stmt</a> to the next result row or to completion.
190
191 </p></li><li><p><b><a href="c3ref/column_blob.html">sqlite3_column()</a></b> &rarr;
192 Column values in the current result row for an <a href="c3ref/stmt.html">sqlite3_stmt</a>.
193
194 </p></li><li><p><b><a href="c3ref/finalize.html">sqlite3_finalize()</a></b> &rarr;
195 Destructor for <a href="c3ref/stmt.html">sqlite3_stmt</a>.
196
197 </p></li><li><p><b><a href="c3ref/close.html">sqlite3_close()</a></b> &rarr;
198 Destructor for <a href="c3ref/sqlite3.html">sqlite3</a>.
199
200 </p></li><li><p><b><a href="c3ref/exec.html">sqlite3_exec()</a></b> &rarr;
201 A wrapper function that does <a href="c3ref/prepare.html">sqlite3_prepare()</a>, <a href="c3ref/step.html">sqlite3_step()</a>,
202 <a href="c3ref/column_blob.html">sqlite3_column()</a>, and <a href="c3ref/finalize.html">sqlite3_finalize()</a> for
203 a string of one or more SQL statements.
204 </p></li></ul>
205
206 <h1 id="introduction"><span>2. </span>Introduction</h1>
207
208 <p>
209 SQLite has more than 225 APIs.
210 However, most of the APIs are optional and very specialized
211 and can be ignored by beginners.
212 The core API is small, simple, and easy to learn.
213 This article summarizes the core API.
214 </p>
215
216 <p>
217 A separate document, <a href="c3ref/intro.html">The SQLite C/C++ Interface</a>,
218 provides detailed
219 specifications for all C/C++ APIs for SQLite. Once
220 the reader
221 understands the basic principles of operation for SQLite,
222 <a href="c3ref/intro.html">that document</a> should be used as a reference
223 guide. This article is intended as introduction only and is neither a
224 complete nor authoritative reference for the SQLite API.
225 </p>
226
227 <h1 id="core_objects_and_interfaces"><span>3. </span>Core Objects And Interfaces</h1>
228
229 <p>
230 The principal task of an SQL database engine is to evaluate SQL statements
231 of SQL. To accomplish this, the developer needs two objects:
232 </p>
233
234 <p></p><ul>
235 <li> The <a href="c3ref/sqlite3.html">database connection</a> object: sqlite3 </li>
236 <li> The <a href="c3ref/stmt.html">prepared statement</a> object: sqlite3_stmt </li>
237 </ul>
238
239 <p>
240 Strictly speaking, the <a href="c3ref/stmt.html">prepared statement</a> object is not required since
241 the convenience wrapper interfaces, <a href="c3ref/exec.html">sqlite3_exec</a> or
242 <a href="c3ref/free_table.html">sqlite3_get_table</a>, can be used and these convenience wrappers
243 encapsulate and hide the <a href="c3ref/stmt.html">prepared statement</a> object.
244 Nevertheless, an understanding of
245 <a href="c3ref/stmt.html">prepared statements</a> is needed to make full use of SQLite.
246 </p>
247
248 <p>
249 The <a href="c3ref/sqlite3.html">database connection</a> and <a href="c3ref/stmt.html">prepared statement</a> objects are controlled
250 by a small set of C/C++ interface routine listed below.
251 </p>
252
253 <p></p><ul>
254 <li> <a href="c3ref/open.html">sqlite3_open()</a> </li>
255 <li> <a href="c3ref/prepare.html">sqlite3_prepare()</a> </li>
256 <li> <a href="c3ref/step.html">sqlite3_step()</a> </li>
257 <li> <a href="c3ref/column_blob.html">sqlite3_column()</a> </li>
258 <li> <a href="c3ref/finalize.html">sqlite3_finalize()</a> </li>
259 <li> <a href="c3ref/close.html">sqlite3_close()</a> </li>
260 </ul>
261
262 <p>
263 Note that the list of routines above is conceptual rather than actual.
264 Many of these routines come in multiple versions.
265 For example, the list above shows a single routine
266 named <a href="c3ref/open.html">sqlite3_open()</a> when in fact there are three separate routines
267 that accomplish the same thing in slightly different ways:
268 <a href="c3ref/open.html">sqlite3_open()</a>, <a href="c3ref/open.html">sqlite3_open16()</a> and <a href="c3ref/open.html">sqlite3_open_v2()</a>.
269 The list mentions <a href="c3ref/column_blob.html">sqlite3_column()</a>
270 when in fact no such routine exists.
271 The "sqlite3_column()" shown in the list is a placeholder for
272 an entire family of routines that extract column
273 data in various datatypes.
274 </p>
275
276 <p>
277 Here is a summary of what the core interfaces do:
278 </p>
279
280 <ul>
281
282 <li><p><b><a href="c3ref/open.html">sqlite3_open()</a></b>
283 </p><p>
284 This routine
285 opens a connection to an SQLite database file and returns a
286 <a href="c3ref/sqlite3.html">database connection</a> object. This is often the first SQLite API
287 call that an application makes and is a prerequisite for most other
288 SQLite APIs. Many SQLite interfaces require a pointer to
289 the <a href="c3ref/sqlite3.html">database connection</a> object as their first parameter and can
290 be thought of as methods on the <a href="c3ref/sqlite3.html">database connection</a> object.
291 This routine is the constructor for the <a href="c3ref/sqlite3.html">database connection</a> object.
292 </p>
293
294 </li><li><p><b><a href="c3ref/prepare.html">sqlite3_prepare()</a></b>
295 </p><p>
296 This routine
297 converts SQL text into a <a href="c3ref/stmt.html">prepared statement</a> object and returns a pointer
298 to that object. This interface requires a <a href="c3ref/sqlite3.html">database connection</a> pointer
299 created by a prior call to <a href="c3ref/open.html">sqlite3_open()</a> and a text string containing
300 the SQL statement to be prepared. This API does not actually evaluate
301 the SQL statement. It merely prepares the SQL statement for evaluation.
302
303 </p><p>Think of each SQL statement as a small computer program. The purpose
304 of <a href="c3ref/prepare.html">sqlite3_prepare()</a> is to compile that program into object code.
305 The <a href="c3ref/stmt.html">prepared statement</a> is the object code. The <a href="c3ref/step.html">sqlite3_step()</a> interface
306 then runs the object code to get a result.
307
308 </p><p>New applications should always invoke <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a> instead
309 of <a href="c3ref/prepare.html">sqlite3_prepare()</a>. The older <a href="c3ref/prepare.html">sqlite3_prepare()</a> is retained for
310 backwards compatibility. But <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a> provides a much
311 better interface.</p>
312
313 </li><li><p><b><a href="c3ref/step.html">sqlite3_step()</a></b>
314 </p><p>
315 This routine is used to evaluate a <a href="c3ref/stmt.html">prepared statement</a> that has been
316 previously created by the <a href="c3ref/prepare.html">sqlite3_prepare()</a> interface. The statement
317 is evaluated up to the point where the first row of results are available.
318 To advance to the second row of results, invoke <a href="c3ref/step.html">sqlite3_step()</a> again.
319 Continue invoking <a href="c3ref/step.html">sqlite3_step()</a> until the statement is complete.
320 Statements that do not return results (ex: INSERT, UPDATE, or DELETE
321 statements) run to completion on a single call to <a href="c3ref/step.html">sqlite3_step()</a>.
322
323 </p></li><li><p><b><a href="c3ref/column_blob.html">sqlite3_column()</a></b>
324 </p><p>
325 This routine returns a single column from the current row of a result
326 set for a <a href="c3ref/stmt.html">prepared statement</a> that is being evaluated by <a href="c3ref/step.html">sqlite3_step()</a>.
327 Each time <a href="c3ref/step.html">sqlite3_step()</a> stops with a new result set row, this routine
328 can be called multiple times to find the values of all columns in that row.
329
330 </p><p>As noted above, there really is no such thing as a "sqlite3_column()"
331 function in the SQLite API. Instead, what we here call "sqlite3_column()"
332 is a place-holder for an entire family of functions that return
333 a value from the result set in various data types. There are also routines
334 in this family that return the size of the result (if it is a string or
335 BLOB) and the number of columns in the result set.
336
337 </p><p></p><ul>
338 <li> <a href="c3ref/column_blob.html">sqlite3_column_blob()</a> </li>
339 <li> <a href="c3ref/column_blob.html">sqlite3_column_bytes()</a> </li>
340 <li> <a href="c3ref/column_blob.html">sqlite3_column_bytes16()</a> </li>
341 <li> <a href="c3ref/column_count.html">sqlite3_column_count()</a> </li>
342 <li> <a href="c3ref/column_blob.html">sqlite3_column_double()</a> </li>
343 <li> <a href="c3ref/column_blob.html">sqlite3_column_int()</a> </li>
344 <li> <a href="c3ref/column_blob.html">sqlite3_column_int64()</a> </li>
345 <li> <a href="c3ref/column_blob.html">sqlite3_column_text()</a> </li>
346 <li> <a href="c3ref/column_blob.html">sqlite3_column_text16()</a> </li>
347 <li> <a href="c3ref/column_blob.html">sqlite3_column_type()</a> </li>
348 <li> <a href="c3ref/column_blob.html">sqlite3_column_value()</a> </li>
349 </ul>
350
351
352 </li><li><p><b><a href="c3ref/finalize.html">sqlite3_finalize()</a></b>
353 </p><p>
354 This routine destroys a <a href="c3ref/stmt.html">prepared statement</a> created by a prior call
355 to <a href="c3ref/prepare.html">sqlite3_prepare()</a>. Every prepared statement must be destroyed using
356 a call to this routine in order to avoid memory leaks.
357
358 </p></li><li><p><b><a href="c3ref/close.html">sqlite3_close()</a></b>
359 </p><p>
360 This routine closes a <a href="c3ref/sqlite3.html">database connection</a> previously opened by a call
361 to <a href="c3ref/open.html">sqlite3_open()</a>. All <a href="c3ref/stmt.html">prepared statements</a> associated with the
362 connection should be <a href="c3ref/finalize.html">finalized</a> prior to closing the
363 connection.
364 </p></li></ul>
365
366 <h1 id="typical_usage_of_core_routines_and_objects"><span>4. </span>Typical Usage Of Core Routines And Objects</h1>
367
368 <p>
369 An application will typically use
370 <a href="c3ref/open.html">sqlite3_open()</a> to create a single <a href="c3ref/sqlite3.html">database connection</a>
371 during initialization.
372 Note that <a href="c3ref/open.html">sqlite3_open()</a> can be used to either open existing database
373 files or to create and open new database files.
374 While many applications use only a single <a href="c3ref/sqlite3.html">database connection</a>, there is
375 no reason why an application cannot call <a href="c3ref/open.html">sqlite3_open()</a> multiple times
376 in order to open multiple <a href="c3ref/sqlite3.html">database connections</a> - either to the same
377 database or to different databases. Sometimes a multi-threaded application
378 will create separate <a href="c3ref/sqlite3.html">database connections</a> for each thread.
379 Note that a single <a href="c3ref/sqlite3.html">database connection</a> can access two or more
380 databases using the <a href="lang_attach.html">ATTACH</a> SQL command, so it is not necessary to
381 have a separate database connection for each database file.
382 </p>
383
384 <p>
385 Many applications destroy their <a href="c3ref/sqlite3.html">database connections</a> using calls to
386 <a href="c3ref/close.html">sqlite3_close()</a> at shutdown. Or, for example, an application that
387 uses SQLite as its <a href="appfileformat.html">application file format</a> might
388 open <a href="c3ref/sqlite3.html">database connections</a> in response to a File/Open menu action
389 and then destroy the corresponding <a href="c3ref/sqlite3.html">database connection</a> in response
390 to the File/Close menu.
391 </p>
392
393 <p>
394 To run an SQL statement, the application follows these steps:
395 </p>
396
397 <p></p><ol>
398 <li> Create a <a href="c3ref/stmt.html">prepared statement</a> using <a href="c3ref/prepare.html">sqlite3_prepare()</a>. </li>
399 <li> Evaluate the <a href="c3ref/stmt.html">prepared statement</a> by calling <a href="c3ref/step.html">sqlite3_step()</a> one
400 or more times. </li>
401 <li> For queries, extract results by calling
402 <a href="c3ref/column_blob.html">sqlite3_column()</a> in between
403 two calls to <a href="c3ref/step.html">sqlite3_step()</a>. </li>
404 <li> Destroy the <a href="c3ref/stmt.html">prepared statement</a> using <a href="c3ref/finalize.html">sqlite3_finalize()</a>. </li>
405 </ol>
406
407 <p>
408 The foregoing is all one really needs to know in order to use SQLite
409 effectively. All the rest is optimization and detail.
410 </p>
411
412 <h1 id="convenience_wrappers_around_core_routines"><span>5. </span>Convenience Wrappers Around Core Routines</h1>
413
414 <p>
415 The <a href="c3ref/exec.html">sqlite3_exec()</a> interface is a convenience wrapper that carries out
416 all four of the above steps with a single function call. A callback
417 function passed into <a href="c3ref/exec.html">sqlite3_exec()</a> is used to process each row of
418 the result set. The <a href="c3ref/free_table.html">sqlite3_get_table()</a> is another convenience wrapper
419 that does all four of the above steps. The <a href="c3ref/free_table.html">sqlite3_get_table()</a> interface
420 differs from <a href="c3ref/exec.html">sqlite3_exec()</a> in that it stores the results of queries
421 in heap memory rather than invoking a callback.
422 </p>
423
424 <p>
425 It is important to realize that neither <a href="c3ref/exec.html">sqlite3_exec()</a> nor
426 <a href="c3ref/free_table.html">sqlite3_get_table()</a> do anything that cannot be accomplished using
427 the core routines. In fact, these wrappers are implemented purely in
428 terms of the core routines.
429 </p>
430
431
432 <h1 id="binding_parameters_and_reusing_prepared_statements"><span>6. </span>Binding Parameters and Reusing Prepared Statements</h1>
433
434 <p>
435 In prior discussion, it was assumed that each SQL statement is prepared
436 once, evaluated, then destroyed. However, SQLite allows the same
437 <a href="c3ref/stmt.html">prepared statement</a> to be evaluated multiple times. This is accomplished
438 using the following routines:
439 </p>
440
441 <p></p><ul>
442 <li> <a href="c3ref/reset.html">sqlite3_reset()</a> </li>
443 <li> <a href="c3ref/bind_blob.html">sqlite3_bind()</a> </li>
444 </ul>
445
446 <p>
447 After a <a href="c3ref/stmt.html">prepared statement</a> has been evaluated by one or more calls to
448 <a href="c3ref/step.html">sqlite3_step()</a>, it can be reset in order to be evaluated again by a
449 call to <a href="c3ref/reset.html">sqlite3_reset()</a>.
450 Think of <a href="c3ref/reset.html">sqlite3_reset()</a> as rewinding the <a href="c3ref/stmt.html">prepared statement</a> program
451 back to the beginning.
452 Using <a href="c3ref/reset.html">sqlite3_reset()</a> on an existing <a href="c3ref/stmt.html">prepared statement</a> rather than
453 creating a new <a href="c3ref/stmt.html">prepared statement</a> avoids unnecessary calls to
454 <a href="c3ref/prepare.html">sqlite3_prepare()</a>.
455 For many SQL statements, the time needed
456 to run <a href="c3ref/prepare.html">sqlite3_prepare()</a> equals or exceeds the time needed by
457 <a href="c3ref/step.html">sqlite3_step()</a>. So avoiding calls to <a href="c3ref/prepare.html">sqlite3_prepare()</a> can give
458 a significant performance improvement.
459 </p>
460
461 <p>
462 It is not commonly useful to evaluate the <em>exact</em> same SQL
463 statement more than once. More often, one wants to evaluate similar
464 statements. For example, you might want to evaluate an INSERT statement
465 multiple times with different values. Or you might want to evaluate
466 the same query multiple times using a different key in the WHERE clause.
467 To accommodate
468 this, SQLite allows SQL statements to contain <a href="lang_expr.html#varparam">parameters</a>
469 which are "bound" to values prior to being evaluated. These values can
470 later be changed and the same <a href="c3ref/stmt.html">prepared statement</a> can be evaluated
471 a second time using the new values.
472 </p>
473
474 <p>
475 SQLite allows a <a href="lang_expr.html#varparam">parameter</a> wherever a string literal,
476 blob literal, numeric constant, or NULL is allowed
477 in queries or data modification statements. (DQL or DML)
478 (Parameters may not be used for column or table names,
479 or as values for constraints or default values. (DDL))
480 A <a href="lang_expr.html#varparam">parameter</a> takes one of the following forms:
481 </p>
482
483 <p></p><ul>
484 <li> <b>?</b> </li>
485 <li> <b>?</b><i>NNN</i> </li>
486 <li> <b>:</b><i>AAA</i> </li>
487 <li> <b>$</b><i>AAA</i> </li>
488 <li> <b>@</b><i>AAA</i> </li>
489 </ul>
490
491 <p>
492 In the examples above, <i>NNN</i> is an integer value and
493 <i>AAA</i> is an identifier.
494 A parameter initially has a value of NULL.
495 Prior to calling <a href="c3ref/step.html">sqlite3_step()</a> for the first time or immediately
496 after <a href="c3ref/reset.html">sqlite3_reset()</a>, the application can invoke the
497 <a href="c3ref/bind_blob.html">sqlite3_bind()</a> interfaces to attach values
498 to the parameters. Each call to <a href="c3ref/bind_blob.html">sqlite3_bind()</a>
499 overrides prior bindings on the same parameter.
500 </p>
501
502 <p>
503 An application is allowed to prepare multiple SQL statements in advance
504 and evaluate them as needed.
505 There is no arbitrary limit to the number of outstanding
506 <a href="c3ref/stmt.html">prepared statements</a>.
507 Some applications call <a href="c3ref/prepare.html">sqlite3_prepare()</a> multiple times at start-up to
508 create all of the <a href="c3ref/stmt.html">prepared statements</a> they will ever need. Other
509 applications keep a cache of the most recently used <a href="c3ref/stmt.html">prepared statements</a>
510 and then reuse <a href="c3ref/stmt.html">prepared statements</a> out of the cache when available.
511 Another approach is to only reuse <a href="c3ref/stmt.html">prepared statements</a> when they are
512 inside of a loop.
513 </p>
514
515 <h1 id="configuring_sqlite"><span>7. </span>Configuring SQLite</h1>
516
517 <p>
518 The default configuration for SQLite works great for most applications.
519 But sometimes developers want to tweak the setup to try to squeeze out
520 a little more performance, or take advantage of some obscure feature.
521 </p><p>
522 The <a href="c3ref/config.html">sqlite3_config()</a> interface is used to make global, process-wide
523 configuration changes for SQLite. The <a href="c3ref/config.html">sqlite3_config()</a> interface must
524 be called before any <a href="c3ref/sqlite3.html">database connections</a> are created. The
525 <a href="c3ref/config.html">sqlite3_config()</a> interface allows the programmer to do things like:
526 </p><ul>
527 <li>Adjust how SQLite does <a href="malloc.html">memory allocation</a>, including setting up
528 alternative memory allocators appropriate for safety-critical
529 real-time embedded systems and application-defined memory allocators.
530 </li><li>Set up a process-wide <a href="errlog.html">error log</a>.
531 </li><li>Specify an application-defined page cache.
532 </li><li>Adjust the use of mutexes so that they are appropriate for various
533 <a href="threadsafe.html">threading models</a>, or substitute an
534 application-defined mutex system.
535 </li></ul>
536 <p>
537 After process-wide configuration is complete and <a href="c3ref/sqlite3.html">database connections</a>
538 have been created, individual database connections can be configured using
539 calls to <a href="c3ref/limit.html">sqlite3_limit()</a> and <a href="c3ref/db_config.html">sqlite3_db_config()</a>.
540
541 </p><h1 id="extending_sqlite"><span>8. </span>Extending SQLite</h1>
542
543 <p>
544 SQLite includes interfaces that can be used to extend its functionality.
545 Such routines include:
546 </p>
547
548 <p></p><ul>
549 <li> <a href="c3ref/create_collation.html">sqlite3_create_collation()</a> </li>
550 <li> <a href="c3ref/create_function.html">sqlite3_create_function()</a> </li>
551 <li> <a href="c3ref/create_module.html">sqlite3_create_module()</a> </li>
552 <li> <a href="c3ref/vfs_find.html">sqlite3_vfs_register()</a> </li>
553 </ul>
554
555 <p>
556 The <a href="c3ref/create_collation.html">sqlite3_create_collation()</a> interface is used to create new
557 <a href="datatype3.html#collation">collating sequences</a> for sorting text.
558 The <a href="c3ref/create_module.html">sqlite3_create_module()</a> interface is used to register new
559 <a href="vtab.html">virtual table</a> implementations.
560 The <a href="c3ref/vfs_find.html">sqlite3_vfs_register()</a> interface creates new <a href="vfs.html">VFSes</a>.
561 </p>
562
563 <p>
564 The <a href="c3ref/create_function.html">sqlite3_create_function()</a> interface creates new SQL functions -
565 either scalar or aggregate. The new function implementation typically
566 makes use of the following additional interfaces:
567 </p>
568
569 <p></p><ul>
570 <li> <a href="c3ref/aggregate_context.html">sqlite3_aggregate_context()</a> </li>
571 <li> <a href="c3ref/result_blob.html">sqlite3_result()</a> </li>
572 <li> <a href="c3ref/user_data.html">sqlite3_user_data()</a> </li>
573 <li> <a href="c3ref/value_blob.html">sqlite3_value()</a> </li>
574 </ul>
575
576 <p>
577 All of the built-in SQL functions of SQLite are created using exactly
578 these same interfaces. Refer to the SQLite source code, and in particular
579 the
580 <a href="https://www.sqlite.org/src/doc/trunk/src/date.c">date.c</a> and
581 <a href="https://www.sqlite.org/src/doc/trunk/src/func.c">func.c</a> source files
582 for examples.
583 </p>
584
585 <p>
586 Shared libraries or DLLs can be used as <a href="loadext.html">loadable extensions</a> to SQLite.
587
588 </p><h1 id="other_interfaces"><span>9. </span>Other Interfaces</h1>
589
590 <p>
591 This article only mentions the most important and most commonly
592 used SQLite interfaces.
593 The SQLite library includes many other APIs implementing useful
594 features that are not described here.
595 A <a href="c3ref/funclist.html">complete list of functions</a> that form the SQLite
596 application programming interface is found at the
597 <a href="c3ref/intro.html">C/C++ Interface Specification</a>.
598 Refer to that document for complete and authoritative information about
599 all SQLite interfaces.
600 </p>
601
602