| 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>Command Line Shell For SQLite</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 |
Command Line Shell For SQLite |
| 122 |
</div> |
| 123 |
<div class="fancy_toc"> |
| 124 |
<a onclick="toggle_toc()"> |
| 125 |
<span class="fancy_toc_mark" id="toc_mk">►</span> |
| 126 |
Table Of Contents |
| 127 |
</a> |
| 128 |
<div id="toc_sub"><div class="fancy-toc1"><a href="#getting_started">1. Getting Started</a></div> |
| 129 |
<div class="fancy-toc1"><a href="#double_click_startup_on_windows">2. Double-click Startup On Windows</a></div> |
| 130 |
<div class="fancy-toc1"><a href="#special_commands_to_sqlite3_dot_commands_">3. Special commands to sqlite3 (dot-commands)</a></div> |
| 131 |
<div class="fancy-toc1"><a href="#rules_for_dot_commands_sql_and_more">4. Rules for "dot-commands", SQL and More</a></div> |
| 132 |
<div class="fancy-toc2"><a href="#line_structure">4.1. Line Structure</a></div> |
| 133 |
<div class="fancy-toc2"><a href="#dot_command_arguments">4.2. Dot-command arguments</a></div> |
| 134 |
<div class="fancy-toc2"><a href="#dot_command_execution">4.3. Dot-command execution</a></div> |
| 135 |
<div class="fancy-toc1"><a href="#changing_output_formats">5. Changing Output Formats</a></div> |
| 136 |
<div class="fancy-toc1"><a href="#querying_the_database_schema">6. Querying the database schema</a></div> |
| 137 |
<div class="fancy-toc1"><a href="#opening_database_files">7. Opening Database Files</a></div> |
| 138 |
<div class="fancy-toc1"><a href="#redirecting_i_o">8. Redirecting I/O</a></div> |
| 139 |
<div class="fancy-toc2"><a href="#writing_results_to_a_file">8.1. Writing results to a file</a></div> |
| 140 |
<div class="fancy-toc2"><a href="#reading_sql_from_a_file">8.2. Reading SQL from a file</a></div> |
| 141 |
<div class="fancy-toc2"><a href="#file_i_o_functions">8.3. File I/O Functions</a></div> |
| 142 |
<div class="fancy-toc2"><a href="#the_edit_sql_function">8.4. The edit() SQL function</a></div> |
| 143 |
<div class="fancy-toc2"><a href="#importing_files_as_csv_or_other_formats">8.5. Importing files as CSV or other formats</a></div> |
| 144 |
<div class="fancy-toc2"><a href="#export_to_csv">8.6. Export to CSV</a></div> |
| 145 |
<div class="fancy-toc3"><a href="#_export_to_excel_">8.6.1. Export to Excel </a></div> |
| 146 |
<div class="fancy-toc3"><a href="#_export_to_tsv_tab_separated_values_">8.6.2. Export to TSV (tab separated values)</a></div> |
| 147 |
<div class="fancy-toc1"><a href="#accessing_zip_archives_as_database_files">9. Accessing ZIP Archives As Database Files</a></div> |
| 148 |
<div class="fancy-toc2"><a href="#how_zip_archive_access_is_implemented">9.1. How ZIP archive access is implemented</a></div> |
| 149 |
<div class="fancy-toc1"><a href="#converting_an_entire_database_to_a_text_file">10. Converting An Entire Database To A Text File</a></div> |
| 150 |
<div class="fancy-toc1"><a href="#recover_data_from_a_corrupted_database">11. Recover Data From a Corrupted Database</a></div> |
| 151 |
<div class="fancy-toc1"><a href="#loading_extensions">12. Loading Extensions</a></div> |
| 152 |
<div class="fancy-toc1"><a href="#cryptographic_hashes_of_database_content">13. Cryptographic Hashes Of Database Content</a></div> |
| 153 |
<div class="fancy-toc1"><a href="#database_content_self_tests">14. Database Content Self-Tests</a></div> |
| 154 |
<div class="fancy-toc1"><a href="#sqlite_archive_support">15. SQLite Archive Support</a></div> |
| 155 |
<div class="fancy-toc2"><a href="#_sqlite_archive_create_command_">15.1. SQLite Archive Create Command </a></div> |
| 156 |
<div class="fancy-toc2"><a href="#_sqlite_archive_extract_command_">15.2. SQLite Archive Extract Command </a></div> |
| 157 |
<div class="fancy-toc2"><a href="#_sqlite_archive_list_command_">15.3. SQLite Archive List Command </a></div> |
| 158 |
<div class="fancy-toc2"><a href="#_sqlite_archive_insert_and_update_commands_">15.4. SQLite Archive Insert And Update Commands </a></div> |
| 159 |
<div class="fancy-toc2"><a href="#_sqlite_archive_remove_command_">15.5. SQLite Archive Remove Command </a></div> |
| 160 |
<div class="fancy-toc2"><a href="#_operations_on_zip_archives_">15.6. Operations On ZIP Archives </a></div> |
| 161 |
<div class="fancy-toc2"><a href="#_sql_used_to_implement_sqlite_archive_operations_">15.7. SQL Used To Implement SQLite Archive Operations </a></div> |
| 162 |
<div class="fancy-toc1"><a href="#sql_parameters">16. SQL Parameters</a></div> |
| 163 |
<div class="fancy-toc1"><a href="#index_recommendations_sqlite_expert_">17. Index Recommendations (SQLite Expert)</a></div> |
| 164 |
<div class="fancy-toc1"><a href="#working_with_multiple_database_connections">18. Working With Multiple Database Connections</a></div> |
| 165 |
<div class="fancy-toc1"><a href="#miscellaneous_extension_features">19. Miscellaneous Extension Features</a></div> |
| 166 |
<div class="fancy-toc1"><a href="#other_dot_commands">20. Other Dot Commands</a></div> |
| 167 |
<div class="fancy-toc1"><a href="#using_sqlite3_in_a_shell_script">21. Using sqlite3 in a shell script</a></div> |
| 168 |
<div class="fancy-toc1"><a href="#marking_the_end_of_an_sql_statement">22. Marking The End Of An SQL Statement</a></div> |
| 169 |
<div class="fancy-toc1"><a href="#command_line_options">23. Command-line Options</a></div> |
| 170 |
<div class="fancy-toc2"><a href="#the_safe_command_line_option">23.1. The --safe command-line option</a></div> |
| 171 |
<div class="fancy-toc3"><a href="#bypassing_safe_restrictions_for_specific_commands">23.1.1. Bypassing --safe restrictions for specific commands</a></div> |
| 172 |
<div class="fancy-toc2"><a href="#the_unsafe_testing_command_line_option">23.2. The --unsafe-testing command-line option</a></div> |
| 173 |
<div class="fancy-toc2"><a href="#the_no_utf8_and_utf8_command_line_options">23.3. The --no-utf8 and --utf8 command-line options</a></div> |
| 174 |
<div class="fancy-toc1"><a href="#compiling_the_sqlite3_program_from_sources">24. Compiling the sqlite3 program from sources</a></div> |
| 175 |
<div class="fancy-toc2"><a href="#_do_it_yourself_builds_">24.1. Do-It-Yourself Builds </a></div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
<script> |
| 179 |
function toggle_toc(){ |
| 180 |
var sub = document.getElementById("toc_sub") |
| 181 |
var mk = document.getElementById("toc_mk") |
| 182 |
if( sub.style.display!="block" ){ |
| 183 |
sub.style.display = "block"; |
| 184 |
mk.innerHTML = "▼"; |
| 185 |
} else { |
| 186 |
sub.style.display = "none"; |
| 187 |
mk.innerHTML = "►"; |
| 188 |
} |
| 189 |
} |
| 190 |
</script> |
| 191 |
</div> |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
<a name="intro"></a> |
| 197 |
|
| 198 |
<h1 id="getting_started"><span>1. </span>Getting Started</h1> |
| 199 |
|
| 200 |
<p>The SQLite project provides a simple command-line program named |
| 201 |
<b>sqlite3</b> (or <b>sqlite3.exe</b> on Windows) |
| 202 |
that allows the user to manually enter and execute SQL |
| 203 |
statements against an SQLite database or against a |
| 204 |
<a href="#zipdb">ZIP archive</a>. This document provides a brief |
| 205 |
introduction on how to use the <b>sqlite3</b> program. |
| 206 |
|
| 207 |
</p><p>Start the <b>sqlite3</b> program by typing "sqlite3" at the |
| 208 |
command prompt, optionally followed |
| 209 |
by the name of the file that holds the SQLite database |
| 210 |
(or <a href="#zipdb">ZIP archive</a>). If the named |
| 211 |
file does not exist, a new database file with the given name will be |
| 212 |
created automatically. If no database file is specified on the |
| 213 |
command-line, a temporary database is created and automatically deleted when |
| 214 |
the "sqlite3" program exits. |
| 215 |
|
| 216 |
</p><p>On startup, the <b>sqlite3</b> program will show a brief banner |
| 217 |
message then prompt you to enter SQL. Type in SQL statements (terminated |
| 218 |
by a semicolon), press "Enter" and the SQL will be executed.</p> |
| 219 |
|
| 220 |
<p>For example, to create a new SQLite database named "ex1" |
| 221 |
with a single table named "tbl1", you might do this:</p> |
| 222 |
|
| 223 |
<div class="codeblock"><pre>$ <b>sqlite3 ex1</b> |
| 224 |
SQLite version 3.36.0 2021-06-18 18:36:39 |
| 225 |
Enter ".help" for usage hints. |
| 226 |
sqlite> <b>create table tbl1(one text, two int);</b> |
| 227 |
sqlite> <b>insert into tbl1 values('hello!',10);</b> |
| 228 |
sqlite> <b>insert into tbl1 values('goodbye', 20);</b> |
| 229 |
sqlite> <b>select * from tbl1;</b> |
| 230 |
hello!|10 |
| 231 |
goodbye|20 |
| 232 |
sqlite> |
| 233 |
</pre></div> |
| 234 |
|
| 235 |
<p>Terminate the sqlite3 program by typing your system |
| 236 |
End-Of-File character (usually a Control-D). Use the interrupt |
| 237 |
character (usually a Control-C) to stop a long-running SQL statement.</p> |
| 238 |
|
| 239 |
<p>Make sure you type a semicolon at the end of each SQL command! |
| 240 |
The sqlite3 program looks for a semicolon to know when your SQL command is |
| 241 |
complete. If you omit the semicolon, sqlite3 will give you a |
| 242 |
continuation prompt and wait for you to enter more text to |
| 243 |
complete the SQL command. This feature allows you to |
| 244 |
enter SQL commands that span multiple lines. For example:</p> |
| 245 |
|
| 246 |
|
| 247 |
<div class="codeblock"><pre>sqlite> <b>CREATE TABLE tbl2 (</b> |
| 248 |
...> <b> f1 varchar(30) primary key,</b> |
| 249 |
...> <b> f2 text,</b> |
| 250 |
...> <b> f3 real</b> |
| 251 |
...> <b>);</b> |
| 252 |
sqlite> |
| 253 |
</pre></div> |
| 254 |
|
| 255 |
<a name="dblclick"></a> |
| 256 |
|
| 257 |
<h1 id="double_click_startup_on_windows"><span>2. </span>Double-click Startup On Windows</h1> |
| 258 |
|
| 259 |
<p>Windows users can double-click on the <b>sqlite3.exe</b> icon to cause |
| 260 |
the command-line shell to pop-up a terminal window running SQLite. However, |
| 261 |
because double-clicking starts the sqlite3.exe without command-line arguments, |
| 262 |
no database file will have been specified, so SQLite will use a temporary |
| 263 |
database that is deleted when the session exits. |
| 264 |
To use a persistent disk file as the database, enter the ".open" command |
| 265 |
immediately after the terminal window starts up: |
| 266 |
|
| 267 |
</p><div class="codeblock"><pre>SQLite version 3.36.0 2021-06-18 18:36:39 |
| 268 |
Enter ".help" for usage hints. |
| 269 |
Connected to a transient in-memory database. |
| 270 |
Use ".open FILENAME" to reopen on a persistent database. |
| 271 |
sqlite> <b>.open ex1.db</b> |
| 272 |
sqlite> |
| 273 |
</pre></div> |
| 274 |
|
| 275 |
<p>The example above causes the database file named "ex1.db" to be opened |
| 276 |
and used. The "ex1.db" file is created if it does not previously exist. |
| 277 |
You might want to |
| 278 |
use a full pathname to ensure that the file is in the directory that you |
| 279 |
think it is in. Use forward-slashes as the directory separator character. |
| 280 |
In other words use "c:/work/ex1.db", not "c:\work\ex1.db".</p> |
| 281 |
|
| 282 |
<p>Alternatively, you can create a new database using the default temporary |
| 283 |
storage, then save that database into a disk file using the ".save" command: |
| 284 |
|
| 285 |
</p><div class="codeblock"><pre>SQLite version 3.36.0 2021-06-18 18:36:39 |
| 286 |
Enter ".help" for usage hints. |
| 287 |
Connected to a transient in-memory database. |
| 288 |
Use ".open FILENAME" to reopen on a persistent database. |
| 289 |
sqlite> <i>... many SQL commands omitted ...</i> |
| 290 |
sqlite> <b>.save ex1.db</b> |
| 291 |
sqlite> |
| 292 |
</pre></div> |
| 293 |
|
| 294 |
<p>Be careful when using the ".save" command as it will overwrite any |
| 295 |
preexisting database files having the same name without prompting for |
| 296 |
confirmation. As with the ".open" command, you might want to use a |
| 297 |
full pathname with forward-slash directory separators to avoid ambiguity. |
| 298 |
|
| 299 |
<a name="dotcmd"></a> |
| 300 |
|
| 301 |
</p><h1 id="special_commands_to_sqlite3_dot_commands_"><span>3. </span>Special commands to sqlite3 (dot-commands)</h1> |
| 302 |
|
| 303 |
<p> |
| 304 |
Most of the time, sqlite3 just reads lines of input and passes them |
| 305 |
on to the SQLite library for execution. |
| 306 |
But input lines that begin with a dot (".") |
| 307 |
are intercepted and interpreted by the sqlite3 program itself. |
| 308 |
These "dot commands" are typically used to change the output format |
| 309 |
of queries, or to execute certain prepackaged query statements. |
| 310 |
There were originally just a few dot commands, but over the years |
| 311 |
many new features have accumulated so that today there are over 60. |
| 312 |
</p> |
| 313 |
|
| 314 |
<p> |
| 315 |
For a listing of the available dot commands, you can enter ".help" with |
| 316 |
no arguments. Or enter ".help TOPIC" for detailed information about TOPIC. |
| 317 |
The list of available dot-commands follows: |
| 318 |
</p> |
| 319 |
|
| 320 |
<div class="codeblock"><pre>sqlite> <b>.help</b> |
| 321 |
.archive ... Manage SQL archives |
| 322 |
.auth ON|OFF Show authorizer callbacks |
| 323 |
.backup ?DB? FILE Backup DB (default "main") to FILE |
| 324 |
.bail on|off Stop after hitting an error. Default OFF |
| 325 |
.cd DIRECTORY Change the working directory to DIRECTORY |
| 326 |
.changes on|off Show number of rows changed by SQL |
| 327 |
.check GLOB Fail if output since .testcase does not match |
| 328 |
.clone NEWDB Clone data into NEWDB from the existing database |
| 329 |
.connection [close] [#] Open or close an auxiliary database connection |
| 330 |
.crnl on|off Translate \n to \r\n. Default ON |
| 331 |
.databases List names and files of attached databases |
| 332 |
.dbconfig ?op? ?val? List or change sqlite3_db_config() options |
| 333 |
.dbinfo ?DB? Show status information about the database |
| 334 |
.dump ?OBJECTS? Render database content as SQL |
| 335 |
.echo on|off Turn command echo on or off |
| 336 |
.eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN |
| 337 |
.excel Display the output of next command in spreadsheet |
| 338 |
.exit ?CODE? Exit this program with return-code CODE |
| 339 |
.expert EXPERIMENTAL. Suggest indexes for queries |
| 340 |
.explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto |
| 341 |
.filectrl CMD ... Run various sqlite3_file_control() operations |
| 342 |
.fullschema ?--indent? Show schema and the content of sqlite_stat tables |
| 343 |
.headers on|off Turn display of headers on or off |
| 344 |
.help ?-all? ?PATTERN? Show help text for PATTERN |
| 345 |
.import FILE TABLE Import data from FILE into TABLE |
| 346 |
.indexes ?TABLE? Show names of indexes |
| 347 |
.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT |
| 348 |
.lint OPTIONS Report potential schema issues. |
| 349 |
.load FILE ?ENTRY? Load an extension library |
| 350 |
.log FILE|on|off Turn logging on or off. FILE can be stderr/stdout |
| 351 |
.mode MODE ?OPTIONS? Set output mode |
| 352 |
.nonce STRING Suspend safe mode for one command if nonce matches |
| 353 |
.nullvalue STRING Use STRING in place of NULL values |
| 354 |
.once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE |
| 355 |
.open ?OPTIONS? ?FILE? Close existing database and reopen FILE |
| 356 |
.output ?FILE? Send output to FILE or stdout if FILE is omitted |
| 357 |
.parameter CMD ... Manage SQL parameter bindings |
| 358 |
.print STRING... Print literal STRING |
| 359 |
.progress N Invoke progress handler after every N opcodes |
| 360 |
.prompt MAIN CONTINUE Replace the standard prompts |
| 361 |
.quit Stop interpreting input stream, exit if primary. |
| 362 |
.read FILE Read input from FILE or command output |
| 363 |
.recover Recover as much data as possible from corrupt db. |
| 364 |
.restore ?DB? FILE Restore content of DB (default "main") from FILE |
| 365 |
.save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...) |
| 366 |
.scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off |
| 367 |
.schema ?PATTERN? Show the CREATE statements matching PATTERN |
| 368 |
.separator COL ?ROW? Change the column and row separators |
| 369 |
.session ?NAME? CMD ... Create or control sessions |
| 370 |
.sha3sum ... Compute a SHA3 hash of database content |
| 371 |
.shell CMD ARGS... Run CMD ARGS... in a system shell |
| 372 |
.show Show the current values for various settings |
| 373 |
.stats ?ARG? Show stats or turn stats on or off |
| 374 |
.system CMD ARGS... Run CMD ARGS... in a system shell |
| 375 |
.tables ?TABLE? List names of tables matching LIKE pattern TABLE |
| 376 |
.timeout MS Try opening locked tables for MS milliseconds |
| 377 |
.timer on|off Turn SQL timer on or off |
| 378 |
.trace ?OPTIONS? Output each SQL statement as it is run |
| 379 |
.version Show source, library and compiler versions |
| 380 |
.vfsinfo ?AUX? Information about the top-level VFS |
| 381 |
.vfslist List all available VFSes |
| 382 |
.vfsname ?AUX? Print the name of the VFS stack |
| 383 |
.width NUM1 NUM2 ... Set minimum column widths for columnar output |
| 384 |
sqlite> |
| 385 |
</pre></div> |
| 386 |
|
| 387 |
<a name="dotrules"></a> |
| 388 |
|
| 389 |
<h1 id="rules_for_dot_commands_sql_and_more"><span>4. </span>Rules for "dot-commands", SQL and More</h1> |
| 390 |
|
| 391 |
<h2 id="line_structure"><span>4.1. </span>Line Structure</h2> |
| 392 |
|
| 393 |
<p>The CLI's input is parsed into a sequence consisting of: |
| 394 |
</p><ul> |
| 395 |
<li>SQL statements;</li> |
| 396 |
<li>dot-commands; or</li> |
| 397 |
<li>CLI comments</li> |
| 398 |
</ul> |
| 399 |
<p>SQL statements are free-form, and can be spread across multiple lines, |
| 400 |
with whitespace or SQL comments embedded anywhere. |
| 401 |
They are terminated by either a ';' character at the end of an input line, |
| 402 |
or a '/' character or the word "go" on a line by itself. |
| 403 |
When not at the end of an input line, the ';' character |
| 404 |
acts to separate SQL statements. |
| 405 |
Trailing whitespace is ignored for purposes of termination. |
| 406 |
</p><p>A dot-command has a more restrictive structure: |
| 407 |
</p><ul> |
| 408 |
<li>It must begin with its "." at the left margin |
| 409 |
with no preceding whitespace.</li> |
| 410 |
<li>It must be entirely contained on a single input line.</li> |
| 411 |
<li>It cannot occur in the middle of an ordinary SQL |
| 412 |
statement. In other words, it cannot occur at a |
| 413 |
continuation prompt.</li> |
| 414 |
<li>There is no comment syntax for dot-commands.</li> |
| 415 |
</ul> |
| 416 |
<p>The CLI also accepts whole-line comments that |
| 417 |
begin with a '#' character and extend to the end of the line. |
| 418 |
There can be no with whitespace prior to the '#'. |
| 419 |
|
| 420 |
</p><h2 id="dot_command_arguments"><span>4.2. </span>Dot-command arguments</h2> |
| 421 |
<p>The arguments passed to dot-commands are parsed from the command tail, |
| 422 |
per these rules: |
| 423 |
</p><ol> |
| 424 |
<li>The trailing newline and any other trailing whitespace is discarded;</li> |
| 425 |
<li>Whitespace immediately following the dot-command name, or any argument |
| 426 |
input end bound is discarded;</li> |
| 427 |
<li>An argument input begins with any non-whitespace character;</li> |
| 428 |
<li>An argument input ends with a character which |
| 429 |
depends upon its leading character thusly:</li> |
| 430 |
<ul> |
| 431 |
<li>for a leading single-quote ('), a single-quote acts |
| 432 |
as the end delimiter;</li> |
| 433 |
<li>for a leading double-quote ("), an unescaped double-quote |
| 434 |
acts as the end delimiter;</li> |
| 435 |
<li>for any other leading character, the end delimiter is |
| 436 |
any whitespace; and</li> |
| 437 |
<li>the command tail end acts as the end delimiter for any argument;</li> |
| 438 |
</ul> |
| 439 |
<li>Within a double-quoted argument input, a backslash-escaped double-quote |
| 440 |
is part of the argument rather than its terminating quote;</li> |
| 441 |
<li>Within a double-quoted argument, traditional C-string literal, backslash |
| 442 |
escape sequence translation is done; and</li> |
| 443 |
<li>Argument input delimiters (the bounding quotes or whitespace) |
| 444 |
are discarded to yield the passed argument.</li> |
| 445 |
</ol> |
| 446 |
|
| 447 |
<h2 id="dot_command_execution"><span>4.3. </span>Dot-command execution</h2> |
| 448 |
<p>The dot-commands |
| 449 |
are interpreted by the sqlite3.exe command-line program, not by |
| 450 |
SQLite itself. So none of the dot-commands will work as an argument |
| 451 |
to SQLite interfaces such as <a href="c3ref/prepare.html">sqlite3_prepare()</a> or <a href="c3ref/exec.html">sqlite3_exec()</a>. |
| 452 |
|
| 453 |
<a name="dotmode"></a> |
| 454 |
|
| 455 |
</p><h1 id="changing_output_formats"><span>5. </span>Changing Output Formats</h1> |
| 456 |
|
| 457 |
<p>The sqlite3 program is able to show the results of a query |
| 458 |
in 14 different output formats: |
| 459 |
</p><div class="columns" style="columns:8em auto;"> |
| 460 |
<ul style="padding-top:0;padding-left:4em;"> |
| 461 |
<li> ascii |
| 462 |
</li><li> box |
| 463 |
</li><li> csv |
| 464 |
</li><li> column |
| 465 |
</li><li> html |
| 466 |
</li><li> insert |
| 467 |
</li><li> json |
| 468 |
</li><li> line |
| 469 |
</li><li> list |
| 470 |
</li><li> markdown |
| 471 |
</li><li> quote |
| 472 |
</li><li> table |
| 473 |
</li><li> tabs |
| 474 |
</li><li> tcl |
| 475 |
</li></ul></div> |
| 476 |
|
| 477 |
<p>You can use the ".mode" dot command to switch between these output |
| 478 |
formats. |
| 479 |
The default output mode is "list". In |
| 480 |
list mode, each row of a query result is written on one line of |
| 481 |
output and each column within that row is separated by a specific |
| 482 |
separator string. The default separator is a pipe symbol ("|"). |
| 483 |
List mode is especially useful when you are going to send the output |
| 484 |
of a query to another program (such as AWK) for additional processing.</p> |
| 485 |
|
| 486 |
<div class="codeblock"><pre>sqlite> <b>.mode list</b> |
| 487 |
sqlite> <b>select * from tbl1;</b> |
| 488 |
hello!|10 |
| 489 |
goodbye|20 |
| 490 |
sqlite> |
| 491 |
</pre></div> |
| 492 |
|
| 493 |
<p>Type ".mode" with no arguments to show the current mode: |
| 494 |
|
| 495 |
</p><div class="codeblock"><pre>sqlite> <b>.mode</b> |
| 496 |
current output mode: list |
| 497 |
sqlite> |
| 498 |
</pre></div> |
| 499 |
|
| 500 |
<p>Use the ".separator" dot command to change the separator. |
| 501 |
For example, to change the separator to a comma and |
| 502 |
a space, you could do this:</p> |
| 503 |
|
| 504 |
<div class="codeblock"><pre>sqlite> <b>.separator ", "</b> |
| 505 |
sqlite> <b>select * from tbl1;</b> |
| 506 |
hello!, 10 |
| 507 |
goodbye, 20 |
| 508 |
sqlite> |
| 509 |
</pre></div> |
| 510 |
|
| 511 |
<p>The next ".mode" command might reset the ".separator" back to some |
| 512 |
default value (depending on its arguments). |
| 513 |
So you will likely need to repeat the ".separator" command whenever you |
| 514 |
change modes if you want to continue using a non-standard separator. |
| 515 |
|
| 516 |
<a name="dotmodequote"></a> |
| 517 |
|
| 518 |
</p><p>In "quote" mode, the output is formatted as SQL literals. Strings are |
| 519 |
enclosed in single-quotes and internal single-quotes are escaped by doubling. |
| 520 |
Blobs are displayed in hexadecimal blob literal notation (Ex: x'abcd'). |
| 521 |
Numbers are displayed as ASCII text and NULL values are shown as "NULL". |
| 522 |
All columns are separated from each other by a comma (or whatever alternative |
| 523 |
character is selected using ".separator"). |
| 524 |
|
| 525 |
</p><div class="codeblock"><pre>sqlite> <b>.mode quote</b> |
| 526 |
sqlite> <b>select * from tbl1;</b> |
| 527 |
'hello!',10 |
| 528 |
'goodbye',20 |
| 529 |
sqlite> |
| 530 |
</pre></div> |
| 531 |
|
| 532 |
<p>In "line" mode, each column in a row of the database |
| 533 |
is shown on a line by itself. Each line consists of the column |
| 534 |
name, an equal sign and the column data. Successive records are |
| 535 |
separated by a blank line. Here is an example of line mode |
| 536 |
output:</p> |
| 537 |
|
| 538 |
<div class="codeblock"><pre>sqlite> <b>.mode line</b> |
| 539 |
sqlite> <b>select * from tbl1;</b> |
| 540 |
one = hello! |
| 541 |
two = 10 |
| 542 |
|
| 543 |
one = goodbye |
| 544 |
two = 20 |
| 545 |
sqlite> |
| 546 |
</pre></div> |
| 547 |
|
| 548 |
<a name="clmnr"></a> |
| 549 |
|
| 550 |
|
| 551 |
<p>In column mode, each record is shown on a separate line with the |
| 552 |
data aligned in columns. For example:</p> |
| 553 |
|
| 554 |
<div class="codeblock"><pre>sqlite> <b>.mode column</b> |
| 555 |
sqlite> <b>select * from tbl1;</b> |
| 556 |
one two |
| 557 |
-------- --- |
| 558 |
hello! 10 |
| 559 |
goodbye 20 |
| 560 |
sqlite> |
| 561 |
</pre></div> |
| 562 |
|
| 563 |
<p>In "column" mode (and also in "box", "table", and "markdown" modes) |
| 564 |
the width of columns adjusts automatically. But you can override this, |
| 565 |
providing a specified width for each column using the ".width" command. |
| 566 |
The arguments to ".width" are integers which are the number of |
| 567 |
characters to devote to each column. Negative numbers mean right-justify. |
| 568 |
Thus:</p> |
| 569 |
|
| 570 |
<div class="codeblock"><pre>sqlite> <b>.width 12 -6</b> |
| 571 |
sqlite> <b>select * from tbl1;</b> |
| 572 |
one two |
| 573 |
------------ ------ |
| 574 |
hello! 10 |
| 575 |
goodbye 20 |
| 576 |
sqlite> |
| 577 |
</pre></div> |
| 578 |
|
| 579 |
<p>A width of 0 means the column width is chosen automatically. |
| 580 |
Unspecified column widths become zero. Hence, the command |
| 581 |
".width" with no arguments resets all column widths to zero and |
| 582 |
hence causes all column widths to be determined automatically. |
| 583 |
|
| 584 |
</p><p>The "column" mode is a tabular output format. Other |
| 585 |
tabular output formats are "box", "markdown", and "table": |
| 586 |
|
| 587 |
</p><div class="codeblock"><pre>sqlite> <b>.width</b> |
| 588 |
sqlite> <b>.mode markdown</b> |
| 589 |
sqlite> <b>select * from tbl1;</b> |
| 590 |
| one | two | |
| 591 |
|---------|-----| |
| 592 |
| hello! | 10 | |
| 593 |
| goodbye | 20 | |
| 594 |
sqlite> <b>.mode table</b> |
| 595 |
sqlite> <b>select * from tbl1;</b> |
| 596 |
+---------+-----+ |
| 597 |
| one | two | |
| 598 |
+---------+-----+ |
| 599 |
| hello! | 10 | |
| 600 |
| goodbye | 20 | |
| 601 |
+---------+-----+ |
| 602 |
sqlite> <b>.mode box</b> |
| 603 |
sqlite> <b>select * from tbl1;</b> |
| 604 |
┌─────────┬─────┐ |
| 605 |
│ one │ two │ |
| 606 |
├─────────┼─────┤ |
| 607 |
│ hello! │ 10 │ |
| 608 |
│ goodbye │ 20 │ |
| 609 |
└─────────┴─────┘ |
| 610 |
sqlite> |
| 611 |
</pre></div> |
| 612 |
|
| 613 |
<a name="wrap1"></a> |
| 614 |
|
| 615 |
|
| 616 |
<p>The columnar modes accept some addition options to control formatting. |
| 617 |
The "--wrap <i>N</i>" option (where <i>N</i> is an integer) causes columns |
| 618 |
to wrap text that is longer than N characters. Wrapping is disabled if |
| 619 |
N is zero. |
| 620 |
|
| 621 |
</p><div class="codeblock"><pre>sqlite> <b>insert into tbl1 values('The quick fox jumps over a lazy brown dog.',90);</b> |
| 622 |
sqlite> <b>.mode box --wrap 30</b> |
| 623 |
sqlite> <b>select * from tbl1 where two>50;</b> |
| 624 |
┌────────────────────────────────┬─────┐ |
| 625 |
│ one │ two │ |
| 626 |
├────────────────────────────────┼─────┤ |
| 627 |
│ The quick fox jumps over a laz │ 90 │ |
| 628 |
│ y brown dog. │ │ |
| 629 |
└────────────────────────────────┴─────┘ |
| 630 |
sqlite> |
| 631 |
</pre></div> |
| 632 |
|
| 633 |
<p>Wrapping happens after exactly <i>N</i> characters, |
| 634 |
which might be in the middle of a word. |
| 635 |
To wrap at a word boundary, add the "--wordwrap on" option |
| 636 |
(or just "-ww" for short): |
| 637 |
|
| 638 |
</p><div class="codeblock"><pre>sqlite> <b>.mode box --wrap 30 -ww</b> |
| 639 |
sqlite> <b>select * from tbl1 where two>50;</b> |
| 640 |
┌─────────────────────────────┬─────┐ |
| 641 |
│ one │ two │ |
| 642 |
├─────────────────────────────┼─────┤ |
| 643 |
│ The quick fox jumps over a │ 90 │ |
| 644 |
│ lazy brown dog. │ │ |
| 645 |
└─────────────────────────────┴─────┘ |
| 646 |
sqlite> |
| 647 |
</pre></div> |
| 648 |
|
| 649 |
<p>The "--quote" option causes the results in each column to be |
| 650 |
quoted like an SQL literal, as in the "quote" mode. See the on-line |
| 651 |
help for additional options. |
| 652 |
|
| 653 |
<a name="qbox"></a> |
| 654 |
|
| 655 |
</p><p>The command ".mode box --wrap 60 --quote" is so useful for general-purpose |
| 656 |
database queries that it is given its own alias. Instead of typing out |
| 657 |
that whole 27-character command, you can just say ".mode qbox". |
| 658 |
|
| 659 |
</p><p>Another useful output mode is "insert". In insert mode, the output |
| 660 |
is formatted to look like SQL INSERT statements. Use insert |
| 661 |
mode to generate text that can later be used to input data into a |
| 662 |
different database.</p> |
| 663 |
|
| 664 |
<p>When specifying insert mode, you have to give an extra argument |
| 665 |
which is the name of the table to be inserted into. For example:</p> |
| 666 |
|
| 667 |
<div class="codeblock"><pre>sqlite> <b>.mode insert new_table</b> |
| 668 |
sqlite> <b>select * from tbl1 where two<50;</b> |
| 669 |
INSERT INTO "new_table" VALUES('hello',10); |
| 670 |
INSERT INTO "new_table" VALUES('goodbye',20); |
| 671 |
sqlite> |
| 672 |
</pre></div> |
| 673 |
|
| 674 |
|
| 675 |
<p>Other output modes include "csv", "json", and "tcl". Try these |
| 676 |
yourself to see what they do. |
| 677 |
</p> |
| 678 |
|
| 679 |
<a name="schema"></a> |
| 680 |
|
| 681 |
<h1 id="querying_the_database_schema"><span>6. </span>Querying the database schema</h1> |
| 682 |
|
| 683 |
<p>The sqlite3 program provides several convenience commands that |
| 684 |
are useful for looking at the schema of the database. There is |
| 685 |
nothing that these commands do that cannot be done by some other |
| 686 |
means. These commands are provided purely as a shortcut.</p> |
| 687 |
|
| 688 |
<a name="dtables"></a> |
| 689 |
|
| 690 |
<p>For example, to see a list of the tables in the database, you |
| 691 |
can enter ".tables".</p> |
| 692 |
|
| 693 |
|
| 694 |
<div class="codeblock"><pre>sqlite> <b>.tables</b> |
| 695 |
tbl1 tbl2 |
| 696 |
sqlite> |
| 697 |
</pre></div> |
| 698 |
|
| 699 |
|
| 700 |
<p>The ".tables" command is similar to setting list mode then |
| 701 |
executing the following query:</p> |
| 702 |
|
| 703 |
<div class="codeblock"><pre>SELECT name FROM sqlite_schema |
| 704 |
WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' |
| 705 |
ORDER BY 1 |
| 706 |
</pre></div> |
| 707 |
|
| 708 |
<p>But the ".tables" command does more. It queries the <a href="schematab.html">sqlite_schema</a> table |
| 709 |
for all <a href="lang_attach.html">attached</a> databases, not just the primary database. And it arranges |
| 710 |
its output into neat columns. |
| 711 |
|
| 712 |
</p><p>The ".indexes" command works in a similar way to list all of |
| 713 |
the indexes. If the ".indexes" command is given an argument which is |
| 714 |
the name of a table, then it shows just indexes on that table. |
| 715 |
|
| 716 |
<a name="dschema"></a> |
| 717 |
|
| 718 |
</p><p>The ".schema" command shows the complete schema for the database, |
| 719 |
or for a single table if an optional tablename argument is provided: |
| 720 |
|
| 721 |
</p><div class="codeblock"><pre>sqlite> <b>.schema</b> |
| 722 |
create table tbl1(one varchar(10), two smallint) |
| 723 |
CREATE TABLE tbl2 ( |
| 724 |
f1 varchar(30) primary key, |
| 725 |
f2 text, |
| 726 |
f3 real |
| 727 |
); |
| 728 |
sqlite> <b>.schema tbl2</b> |
| 729 |
CREATE TABLE tbl2 ( |
| 730 |
f1 varchar(30) primary key, |
| 731 |
f2 text, |
| 732 |
f3 real |
| 733 |
); |
| 734 |
sqlite> |
| 735 |
</pre></div> |
| 736 |
|
| 737 |
|
| 738 |
<p>The ".schema" command is roughly the same as setting |
| 739 |
list mode, then entering the following query:</p> |
| 740 |
|
| 741 |
<div class="codeblock"><pre>SELECT sql FROM sqlite_schema |
| 742 |
ORDER BY tbl_name, type DESC, name |
| 743 |
</pre></div> |
| 744 |
|
| 745 |
<p>As with ".tables", the ".schema" command shows the schema for |
| 746 |
all <a href="lang_attach.html">attached</a> databases. If you only want to see the schema for |
| 747 |
a single database (perhaps "main") then you can add an argument |
| 748 |
to ".schema" to restrict its output: |
| 749 |
|
| 750 |
</p><div class="codeblock"><pre>sqlite> <b>.schema main.*</b> |
| 751 |
</pre></div> |
| 752 |
|
| 753 |
<p>The ".schema" command can be augmented with the "--indent" option, |
| 754 |
in which case it tries to reformat the various CREATE statements of |
| 755 |
the schema so that they are more easily readable by humans. |
| 756 |
|
| 757 |
<a name="dotdatabases"></a> |
| 758 |
|
| 759 |
</p><p>The ".databases" command shows a list of all databases open in |
| 760 |
the current connection. There will always be at least 2. The first |
| 761 |
one is "main", the original database opened. The second is "temp", |
| 762 |
the database used for temporary tables. There may be additional |
| 763 |
databases listed for databases attached using the ATTACH statement. |
| 764 |
The first output column is the name the database is attached with, |
| 765 |
and the second result column is the filename of the external file. |
| 766 |
There may be a third result column which will be either "'r/o'" or |
| 767 |
"'r/w'" depending on whether the database file is read-only or read-write. |
| 768 |
And there might be a fourth result column showing the result of |
| 769 |
<a href="c3ref/txn_state.html">sqlite3_txn_state()</a> for that database file. |
| 770 |
|
| 771 |
</p><div class="codeblock"><pre>sqlite> <b>.databases</b> |
| 772 |
</pre></div> |
| 773 |
|
| 774 |
<a name="fullschema"></a> |
| 775 |
|
| 776 |
<p>The ".fullschema" dot-command works like the ".schema" command in |
| 777 |
that it displays the entire database schema. But ".fullschema" also |
| 778 |
includes dumps of the statistics tables "sqlite_stat1", "sqlite_stat3", |
| 779 |
and "sqlite_stat4", if they exist. The ".fullschema" command normally |
| 780 |
provides all of the information needed to exactly recreate a query |
| 781 |
plan for a specific query. When reporting suspected problems with |
| 782 |
the SQLite query planner to the SQLite development team, developers |
| 783 |
are requested to provide the complete ".fullschema" output as part |
| 784 |
of the trouble report. Note that the sqlite_stat3 and sqlite_stat4 |
| 785 |
tables contain samples of index entries and so might contain sensitive |
| 786 |
data, so do not send the ".fullschema" output of a proprietary database |
| 787 |
over a public channel.</p> |
| 788 |
|
| 789 |
<a name="dotopen"></a> |
| 790 |
|
| 791 |
<h1 id="opening_database_files"><span>7. </span>Opening Database Files</h1> |
| 792 |
|
| 793 |
<p>The ".open" command opens a new database connection, after first closing the |
| 794 |
previously opened database command. In its simplest form, the ".open" command merely |
| 795 |
invokes <a href="c3ref/open.html">sqlite3_open()</a> on the file named as its argument. Use the name ":memory:" |
| 796 |
to open a new in-memory database that disappears when the CLI exits or when the |
| 797 |
".open" command is run again. |
| 798 |
Or use no name to open a private, temporary on-disk database which |
| 799 |
will also disappear upon exit or use of ".open". |
| 800 |
|
| 801 |
</p><p>If the --new option is included with ".open", then the database is reset prior |
| 802 |
to being opened. Any prior data is destroyed. This is a destructive overwrite of |
| 803 |
prior data and no confirmation is requested, so use this option carefully. |
| 804 |
|
| 805 |
</p><p>The --readonly option opens the database in read-only mode. Write will be |
| 806 |
prohibited. |
| 807 |
|
| 808 |
</p><p>The --deserialize option causes the entire content of the on-disk file to be |
| 809 |
read into memory and then opened as an in-memory database using the |
| 810 |
<a href="c3ref/deserialize.html">sqlite3_deserialize()</a> interface. This will, of course, require a lot of memory |
| 811 |
if you have a large database. Also, any changes you make to the database will not |
| 812 |
be saved back to disk unless you explicitly save them using the ".save" or ".backup" |
| 813 |
commands. |
| 814 |
|
| 815 |
</p><p>The --append option causes the SQLite database to be appended to an existing |
| 816 |
file rather than working as a stand-alone file. See the |
| 817 |
<a href="https://www.sqlite.org/src/file/ext/misc/appendvfs.c">appendvfs extension</a> for |
| 818 |
more information. |
| 819 |
|
| 820 |
</p><p>The --zip option causes the specified input file to be interpreted as a ZIP archive |
| 821 |
instead of as an SQLite database file. |
| 822 |
|
| 823 |
</p><p>The --hexdb option causes the database content to be to be read from subsequent |
| 824 |
lines of input in a hex format, rather than from a separate file on disk. |
| 825 |
The "dbtotxt" command-line tool can be used to generate |
| 826 |
the appropriate text for a database. The --hexdb option is intended for use by the |
| 827 |
SQLite developers for testing purposes. We do not know of any use cases for this |
| 828 |
option outside of internal SQLite testing and development. |
| 829 |
|
| 830 |
</p><h1 id="redirecting_i_o"><span>8. </span>Redirecting I/O</h1> |
| 831 |
|
| 832 |
<a name="dotoutput"></a> |
| 833 |
|
| 834 |
<h2 id="writing_results_to_a_file"><span>8.1. </span>Writing results to a file</h2> |
| 835 |
|
| 836 |
<p>By default, sqlite3 sends query results to standard output. You |
| 837 |
can change this using the ".output" and ".once" commands. Just put |
| 838 |
the name of an output file as an argument to .output and all subsequent |
| 839 |
query results will be written to that file. Or use the .once command |
| 840 |
instead of .output and output will only be redirected for the single next |
| 841 |
command before reverting to the console. Use .output with no arguments to |
| 842 |
begin writing to standard output again. For example:</p> |
| 843 |
|
| 844 |
<div class="codeblock"><pre>sqlite> <b>.mode list</b> |
| 845 |
sqlite> <b>.separator |</b> |
| 846 |
sqlite> <b>.output test_file_1.txt</b> |
| 847 |
sqlite> <b>select * from tbl1;</b> |
| 848 |
sqlite> <b>.exit</b> |
| 849 |
$ <b>cat test_file_1.txt</b> |
| 850 |
hello|10 |
| 851 |
goodbye|20 |
| 852 |
$ |
| 853 |
</pre></div> |
| 854 |
|
| 855 |
<p>If the first character of the ".output" or ".once" filename is a pipe |
| 856 |
symbol ("|") then the remaining characters are treated as a command and the |
| 857 |
output is sent to that command. This makes it easy to pipe the results |
| 858 |
of a query into some other process. For example, the |
| 859 |
"open -f" command on a Mac opens a text editor to display the content that |
| 860 |
it reads from standard input. So to see the results of a query |
| 861 |
in a text editor, one could type:</p> |
| 862 |
|
| 863 |
<div class="codeblock"><pre>sqlite> <b>.once | open -f</b> |
| 864 |
sqlite> <b>SELECT * FROM bigTable;</b> |
| 865 |
</pre></div> |
| 866 |
|
| 867 |
<p>If the ".output" or ".once" commands have an argument of "-e" then |
| 868 |
output is collected into a temporary file and the system text editor is |
| 869 |
invoked on that text file. Thus, the command ".once -e" achieves the |
| 870 |
same result as ".once '|open -f'" but with the benefit of being portable |
| 871 |
across all systems. |
| 872 |
|
| 873 |
</p><p>If the ".output" or ".once" commands have a "-x" argument, that causes |
| 874 |
them to accumulate output as Comma-Separated-Values (CSV) in a temporary |
| 875 |
file, then invoke the default system utility for viewing CSV files |
| 876 |
(usually a spreadsheet program) on the result. This is a quick way of |
| 877 |
sending the result of a query to a spreadsheet for easy viewing: |
| 878 |
|
| 879 |
</p><div class="codeblock"><pre>sqlite> <b>.once -x</b> |
| 880 |
sqlite> <b>SELECT * FROM bigTable;</b> |
| 881 |
</pre></div> |
| 882 |
|
| 883 |
<a name="dotexcel"></a> |
| 884 |
|
| 885 |
<p>The ".excel" command is an alias for ".once -x". It does exactly the same |
| 886 |
thing. |
| 887 |
|
| 888 |
<a name="dotread"></a> |
| 889 |
|
| 890 |
</p><h2 id="reading_sql_from_a_file"><span>8.2. </span>Reading SQL from a file</h2> |
| 891 |
|
| 892 |
<p>In interactive mode, sqlite3 reads input text (either SQL statements |
| 893 |
or <a href="cli.html#dotcmd">dot-commands</a>) from the keyboard. You can also redirect input from |
| 894 |
a file when you launch sqlite3, of course, but then you do not have the |
| 895 |
ability to interact with the program. Sometimes it is useful to run an |
| 896 |
SQL script contained in a file entering other commands from the command-line. |
| 897 |
For this, the ".read" dot-command is provided. |
| 898 |
|
| 899 |
</p><p>The ".read" command takes a single argument which is (usually) the name |
| 900 |
of a file from which to read input text. |
| 901 |
|
| 902 |
</p><div class="codeblock"><pre>sqlite> <b>.read myscript.sql</b> |
| 903 |
</pre></div> |
| 904 |
|
| 905 |
<p>The ".read" command temporarily stops reading from the keyboard and instead |
| 906 |
takes its input from the file named. Upon reaching the end of the file, |
| 907 |
input reverts back to the keyboard. The script file may contain dot-commands, |
| 908 |
just like ordinary interactive input. |
| 909 |
|
| 910 |
</p><p>If the argument to ".read" begins with the "|" character, then instead of |
| 911 |
opening the argument as a file, it runs the argument (without the leading "|") |
| 912 |
as a command, then uses the output of that command as its input. Thus, if you |
| 913 |
have a script that generates SQL, you can execute that SQL directly using |
| 914 |
a command similar to the following: |
| 915 |
|
| 916 |
</p><div class="codeblock"><pre>sqlite> <b>.read |myscript.bat</b> |
| 917 |
</pre></div> |
| 918 |
|
| 919 |
|
| 920 |
<a name="fileio"></a> |
| 921 |
|
| 922 |
<h2 id="file_i_o_functions"><span>8.3. </span>File I/O Functions</h2> |
| 923 |
|
| 924 |
<p>The command-line shell adds two <a href="appfunc.html">application-defined SQL functions</a> that |
| 925 |
facilitate reading content from a file into a table column, and writing the |
| 926 |
content of a column into a file, respectively. |
| 927 |
|
| 928 |
</p><p>The readfile(X) SQL function reads the entire content of the file named |
| 929 |
X and returns that content as a BLOB. This can be used to load content into |
| 930 |
a table. For example: |
| 931 |
|
| 932 |
</p><div class="codeblock"><pre>sqlite> <b>CREATE TABLE images(name TEXT, type TEXT, img BLOB);</b> |
| 933 |
sqlite> <b>INSERT INTO images(name,type,img</b>) |
| 934 |
...> <b> VALUES('icon','jpeg',readfile('icon.jpg'));</b> |
| 935 |
</pre></div> |
| 936 |
|
| 937 |
<p>The writefile(X,Y) SQL function write the blob Y into the file named X |
| 938 |
and returns the number of bytes written. Use this function to extract |
| 939 |
the content of a single table column into a file. For example: |
| 940 |
|
| 941 |
</p><div class="codeblock"><pre>sqlite> <b>SELECT writefile('icon.jpg',img) FROM images WHERE name='icon';</b> |
| 942 |
</pre></div> |
| 943 |
|
| 944 |
<p>Note that the readfile(X) and writefile(X,Y) functions are extension |
| 945 |
functions and are not built into the core SQLite library. These routines |
| 946 |
are available as a <a href="loadext.html">loadable extension</a> in the |
| 947 |
<a href="https://www.sqlite.org/src/artifact?ci=trunk&filename=ext/misc/fileio.c">ext/misc/fileio.c</a> |
| 948 |
source file in the <a href="download.html#srctree">SQLite source code repositories</a>. |
| 949 |
|
| 950 |
<a name="editfunc"></a> |
| 951 |
|
| 952 |
</p><h2 id="the_edit_sql_function"><span>8.4. </span>The edit() SQL function</h2> |
| 953 |
|
| 954 |
<p>The CLI has another built-in SQL function named edit(). Edit() takes |
| 955 |
one or two arguments. The first argument is a value - often a large |
| 956 |
multi-line string to be edited. The second argument is the invocation |
| 957 |
for a text editor. (It may include options to affect the editor's |
| 958 |
behavior.) If the second argument is omitted, the VISUAL environment |
| 959 |
variable is used. The edit() function writes its first argument into a |
| 960 |
temporary file, invokes the editor on the temporary file, rereads the file |
| 961 |
back into memory after the editor is done, then returns the edited text. |
| 962 |
|
| 963 |
</p><p>The edit() function can be used to make changes to large text |
| 964 |
values. For example: |
| 965 |
|
| 966 |
</p><div class="codeblock"><pre>sqlite> <b>UPDATE docs SET body=edit(body) WHERE name='report-15';</b> |
| 967 |
</pre></div> |
| 968 |
|
| 969 |
<p>In this example, the content of the docs.body field for the entry where |
| 970 |
docs.name is "report-15" will be sent to the editor. After the editor returns, |
| 971 |
the result will be written back into the docs.body field. |
| 972 |
|
| 973 |
</p><p>The default operation of edit() is to invoke a text editor. But by using |
| 974 |
an alternative edit program in the second argument, you can also get it to edit |
| 975 |
images or other non-text resources. For example, if you want to modify a JPEG |
| 976 |
image that happens to be stored in a field of a table, you could run: |
| 977 |
|
| 978 |
</p><div class="codeblock"><pre>sqlite> <b>UPDATE pics SET img=edit(img,'gimp') WHERE id='pic-1542';</b> |
| 979 |
</pre></div> |
| 980 |
|
| 981 |
<p>The edit program can also be used as a viewer, by simply ignoring the |
| 982 |
return value. For example, to merely look at the image above, you might run: |
| 983 |
|
| 984 |
</p><div class="codeblock"><pre>sqlite> <b>SELECT length(edit(img,'gimp')) WHERE id='pic-1542';</b> |
| 985 |
</pre></div> |
| 986 |
|
| 987 |
<a name="csv"></a> |
| 988 |
|
| 989 |
<h2 id="importing_files_as_csv_or_other_formats"><span>8.5. </span>Importing files as CSV or other formats</h2> |
| 990 |
|
| 991 |
<p>Use the ".import" command to import CSV (comma separated value) |
| 992 |
or similarly delimited data into an SQLite table. |
| 993 |
The ".import" command takes two arguments which are the |
| 994 |
source from which data is to be read and the name of the |
| 995 |
SQLite table into which the data is to be inserted. The source argument |
| 996 |
is the name of a file to be read or, if it begins with a "|" character, |
| 997 |
it specifies a command which will be run to produce the input data. |
| 998 |
|
| 999 |
</p><p>Note that it may be important to set the "mode" before running the |
| 1000 |
".import" command. This is prudent to prevent the command-line shell |
| 1001 |
from trying to interpret the input file text as some format other than |
| 1002 |
how the file is structured. If the --csv or --ascii options are used, |
| 1003 |
they control import input delimiters. Otherwise, the delimiters are |
| 1004 |
those in effect for the current output mode. |
| 1005 |
|
| 1006 |
</p><p>To import into a table not in the "main" schema, the --schema option |
| 1007 |
may be used to specify that the table is in some other schema. This can |
| 1008 |
be useful for ATTACH'ed databases or to import into a TEMP table. |
| 1009 |
|
| 1010 |
</p><p>When .import is run, its treatment of the first input row depends |
| 1011 |
upon whether the target table already exists. If it does not exist, |
| 1012 |
the table is automatically created and the content of the first input |
| 1013 |
row is used to set the name of all the columns in the table. In this |
| 1014 |
case, the table data content is taken from the second and subsequent |
| 1015 |
input rows. If the target table already exists, every row of the |
| 1016 |
input, including the first, is taken to be actual data content. If |
| 1017 |
the input file contains an initial row of column labels, you can make |
| 1018 |
the .import command skip that initial row using the "--skip 1" option. |
| 1019 |
|
| 1020 |
</p><p>Here is an example usage, loading a pre-existing temporary table |
| 1021 |
from a CSV file which has column names in its first row: |
| 1022 |
|
| 1023 |
</p><div class="codeblock"><pre>sqlite> <b>.import --csv --skip 1 --schema temp C:/work/somedata.csv tab1</b> |
| 1024 |
</pre></div> |
| 1025 |
|
| 1026 |
<p>While reading input data in modes other than 'ascii', ".import" |
| 1027 |
interprets input as records composed of fields according to the RFC 4180 |
| 1028 |
specification with this exception: The input record and field separators |
| 1029 |
are as set by the mode or by use of the .separator command. Fields are |
| 1030 |
always subject to quote removal to reverse quoting done per RFC 4180, |
| 1031 |
except in ascii mode. |
| 1032 |
|
| 1033 |
</p><p>To import data with arbitrary delimiters and no quoting, |
| 1034 |
first set ascii mode (".mode ascii"), then set the field |
| 1035 |
and record delimiters using the ".separator" command. This |
| 1036 |
will suppress dequoting. Upon ".import", the data will be split |
| 1037 |
into fields and records according to the delimiters so specified. |
| 1038 |
|
| 1039 |
<a name="csvout"></a> |
| 1040 |
|
| 1041 |
</p><h2 id="export_to_csv"><span>8.6. </span>Export to CSV</h2> |
| 1042 |
|
| 1043 |
<p>To export an SQLite table (or part of a table) as CSV, simply set |
| 1044 |
the "mode" to "csv" and then run a query to extract the desired rows |
| 1045 |
of the table. The output will formatted as CSV per RFC 4180. |
| 1046 |
|
| 1047 |
</p><div class="codeblock"><pre>sqlite> <b>.headers on</b> |
| 1048 |
sqlite> <b>.mode csv</b> |
| 1049 |
sqlite> <b>.once c:/work/dataout.csv</b> |
| 1050 |
sqlite> <b>SELECT * FROM tab1;</b> |
| 1051 |
sqlite> <b>.system c:/work/dataout.csv</b> |
| 1052 |
</pre></div> |
| 1053 |
|
| 1054 |
<p>In the example above, the ".headers on" line causes column labels to |
| 1055 |
be printed as the first row of output. This means that the first row of |
| 1056 |
the resulting CSV file will contain column labels. If column labels are |
| 1057 |
not desired, set ".headers off" instead. (The ".headers off" setting is |
| 1058 |
the default and can be omitted if the headers have not been previously |
| 1059 |
turned on.) |
| 1060 |
|
| 1061 |
</p><p>The line ".once <i>FILENAME</i>" causes all query output to go into |
| 1062 |
the named file instead of being printed on the console. In the example |
| 1063 |
above, that line causes the CSV content to be written into a file named |
| 1064 |
"C:/work/dataout.csv". |
| 1065 |
|
| 1066 |
</p><p>The final line of the example (the ".system c:/work/dataout.csv") |
| 1067 |
has the same effect as double-clicking on the c:/work/dataout.csv file |
| 1068 |
in windows. This will typically bring up a spreadsheet program to display |
| 1069 |
the CSV file. |
| 1070 |
|
| 1071 |
</p><p>That command only works as written on Windows. |
| 1072 |
The equivalent line on a Mac would be: |
| 1073 |
|
| 1074 |
</p><div class="codeblock"><pre>sqlite> <b>.system open dataout.csv</b> |
| 1075 |
</pre></div> |
| 1076 |
|
| 1077 |
<p>On Linux and other unix systems you will need to enter something like: |
| 1078 |
|
| 1079 |
|
| 1080 |
</p><div class="codeblock"><pre>sqlite> <b>.system xdg-open dataout.csv</b> |
| 1081 |
</pre></div> |
| 1082 |
|
| 1083 |
<a name="exexcel*"></a> |
| 1084 |
|
| 1085 |
<h3 id="_export_to_excel_"><span>8.6.1. </span> Export to Excel </h3> |
| 1086 |
|
| 1087 |
<p>To simplify export to a spreadsheet, the CLI provides the |
| 1088 |
".excel" command which captures the output of a single query and sends |
| 1089 |
that output to the default spreadsheet program on the host computer. |
| 1090 |
Use it like this: |
| 1091 |
|
| 1092 |
</p><div class="codeblock"><pre>sqlite> <b>.excel</b> |
| 1093 |
sqlite> <b>SELECT * FROM tab;</b> |
| 1094 |
</pre></div> |
| 1095 |
|
| 1096 |
<p> |
| 1097 |
The command above writes the output of the query as CSV into a temporary |
| 1098 |
file, invokes the default handler for CSV files (usually the preferred |
| 1099 |
spreadsheet program such as Excel or LibreOffice), then deletes the |
| 1100 |
temporary file. This is essentially a short-hand method of doing |
| 1101 |
the sequence of ".csv", ".once", and ".system" commands described above. |
| 1102 |
|
| 1103 |
</p><p> |
| 1104 |
The ".excel" command is really an alias for ".once -x". The -x option |
| 1105 |
to .once causes it to writes results as CSV into a temporary file that |
| 1106 |
is named with a ".csv" suffix, then invoke the systems default handler |
| 1107 |
for CSV files. |
| 1108 |
|
| 1109 |
</p><p> |
| 1110 |
There is also a ".once -e" command which works similarly, except that |
| 1111 |
it names the temporary file with a ".txt" suffix so that the default |
| 1112 |
text editor for the system will be invoked, instead of the default |
| 1113 |
spreadsheet. |
| 1114 |
|
| 1115 |
<a name="extsv*"></a> |
| 1116 |
|
| 1117 |
</p><h3 id="_export_to_tsv_tab_separated_values_"><span>8.6.2. </span> Export to TSV (tab separated values)</h3> |
| 1118 |
|
| 1119 |
<p> |
| 1120 |
Exporting to pure TSV, without any field quoting, can be done by |
| 1121 |
entering ".mode tabs" before running a query. However, the output |
| 1122 |
will not be read correctly in tabs mode by the ".import" command |
| 1123 |
if it contains doublequote characters. To get TSV quoted per |
| 1124 |
RFC 4180 so that it can be input in tabs mode with ".import", |
| 1125 |
first enter ".mode csv", then enter '.separator "\t"' |
| 1126 |
before running a query. |
| 1127 |
|
| 1128 |
<a name="zipdb"></a> |
| 1129 |
|
| 1130 |
</p><h1 id="accessing_zip_archives_as_database_files"><span>9. </span>Accessing ZIP Archives As Database Files</h1> |
| 1131 |
|
| 1132 |
<p>In addition to reading and writing SQLite database files, |
| 1133 |
the <b>sqlite3</b> program will also read and write ZIP archives. |
| 1134 |
Simply specify a ZIP archive filename in place of an SQLite database |
| 1135 |
filename on the initial command line, or in the ".open" command, |
| 1136 |
and <b>sqlite3</b> will automatically detect that the file is a |
| 1137 |
ZIP archive instead of an SQLite database and will open it as such. |
| 1138 |
This works regardless of file suffix. So you can open JAR, DOCX, |
| 1139 |
and ODP files and any other file format that is really a ZIP |
| 1140 |
archive and SQLite will read it for you. |
| 1141 |
|
| 1142 |
</p><p>A ZIP archive appears to be a database containing a single table |
| 1143 |
with the following schema: |
| 1144 |
|
| 1145 |
</p><div class="codeblock"><pre>CREATE TABLE zip( |
| 1146 |
name, // Name of the file |
| 1147 |
mode, // Unix-style file permissions |
| 1148 |
mtime, // Timestamp, seconds since 1970 |
| 1149 |
sz, // File size after decompression |
| 1150 |
rawdata, // Raw compressed file data |
| 1151 |
data, // Uncompressed file content |
| 1152 |
method // ZIP compression method code |
| 1153 |
); |
| 1154 |
</pre></div> |
| 1155 |
|
| 1156 |
<p>So, for example, if you wanted to see the compression efficiency |
| 1157 |
(expressed as the size of the compressed content relative to the |
| 1158 |
original uncompressed file size) for all files in the ZIP archive, |
| 1159 |
sorted from most compressed to least compressed, you could run a |
| 1160 |
query like this: |
| 1161 |
|
| 1162 |
</p><div class="codeblock"><pre>sqlite> SELECT name, (100.0*length(rawdata))/sz FROM zip ORDER BY 2; |
| 1163 |
</pre></div> |
| 1164 |
|
| 1165 |
<p>Or using <a href="cli.html#fileio">file I/O functions</a>, you can extract elements of the |
| 1166 |
ZIP archive: |
| 1167 |
|
| 1168 |
</p><div class="codeblock"><pre>sqlite> SELECT writefile(name,content) FROM zip |
| 1169 |
...> WHERE name LIKE 'docProps/%'; |
| 1170 |
</pre></div> |
| 1171 |
|
| 1172 |
<h2 id="how_zip_archive_access_is_implemented"><span>9.1. </span>How ZIP archive access is implemented</h2> |
| 1173 |
|
| 1174 |
<p>The command-line shell uses the <a href="zipfile.html">Zipfile virtual table</a> to |
| 1175 |
access ZIP archives. You can see this by running the ".schema" |
| 1176 |
command when a ZIP archive is open: |
| 1177 |
|
| 1178 |
</p><div class="codeblock"><pre>sqlite> .schema |
| 1179 |
CREATE VIRTUAL TABLE zip USING zipfile('document.docx') |
| 1180 |
/* zip(name,mode,mtime,sz,rawdata,data,method) */; |
| 1181 |
</pre></div> |
| 1182 |
|
| 1183 |
<p>When opening a file, if the command-line client discovers that the |
| 1184 |
file is ZIP archive instead of an SQLite database, it actually opens |
| 1185 |
an <a href="inmemorydb.html">in-memory database</a> and then in that in-memory database it creates |
| 1186 |
an instance of the <a href="zipfile.html">Zipfile virtual table</a> that is attached to the |
| 1187 |
ZIP archive. |
| 1188 |
|
| 1189 |
</p><p>The special processing for opening ZIP archives is a trick of the |
| 1190 |
command-line shell, not the core SQLite library. So if you want to |
| 1191 |
open a ZIP archive as a database in your application, you will need to |
| 1192 |
activate the <a href="zipfile.html">Zipfile virtual table</a> module then run an appropriate |
| 1193 |
<a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement. |
| 1194 |
|
| 1195 |
|
| 1196 |
<a name="dump"></a> |
| 1197 |
|
| 1198 |
</p><h1 id="converting_an_entire_database_to_a_text_file"><span>10. </span>Converting An Entire Database To A Text File</h1> |
| 1199 |
|
| 1200 |
<p>Use the ".dump" command to convert the entire contents of a |
| 1201 |
database into a single UTF-8 text file. This file can be converted |
| 1202 |
back into a database by piping it back into <b>sqlite3</b>.</p> |
| 1203 |
|
| 1204 |
<p>A good way to make an archival copy of a database is this:</p> |
| 1205 |
|
| 1206 |
|
| 1207 |
<div class="codeblock"><pre>$ <b>sqlite3 ex1 .dump | gzip -c >ex1.dump.gz</b> |
| 1208 |
</pre></div> |
| 1209 |
|
| 1210 |
|
| 1211 |
<p>This generates a file named <b>ex1.dump.gz</b> that contains everything |
| 1212 |
you need to reconstruct the database at a later time, or on another |
| 1213 |
machine. To reconstruct the database, just type:</p> |
| 1214 |
|
| 1215 |
|
| 1216 |
<div class="codeblock"><pre>$ <b>zcat ex1.dump.gz | sqlite3 ex2</b> |
| 1217 |
</pre></div> |
| 1218 |
|
| 1219 |
|
| 1220 |
<p>The text format is pure SQL so you |
| 1221 |
can also use the .dump command to export an SQLite database |
| 1222 |
into other popular SQL database engines. Like this:</p> |
| 1223 |
|
| 1224 |
|
| 1225 |
<div class="codeblock"><pre>$ <b>createdb ex2</b> |
| 1226 |
$ <b>sqlite3 ex1 .dump | psql ex2</b> |
| 1227 |
</pre></div> |
| 1228 |
|
| 1229 |
<a name="recover"></a> |
| 1230 |
|
| 1231 |
<h1 id="recover_data_from_a_corrupted_database"><span>11. </span>Recover Data From a Corrupted Database</h1> |
| 1232 |
|
| 1233 |
<p>Like the ".dump" command, ".recover" attempts to convert the entire |
| 1234 |
contents of a database file to text. The difference is that instead of |
| 1235 |
reading data using the normal SQL database interface, ".recover" |
| 1236 |
attempts to reassemble the database based on data extracted directly from |
| 1237 |
as many database pages as possible. If the database is corrupt, ".recover" |
| 1238 |
is usually able to recover data from all uncorrupted parts of the database, |
| 1239 |
whereas ".dump" stops when the first sign of corruption is encountered. |
| 1240 |
|
| 1241 |
</p><p>If the ".recover" command recovers one or more rows that it cannot |
| 1242 |
attribute to any database table, the output script creates a "lost_and_found" |
| 1243 |
table to store the orphaned rows. The schema of the lost_and_found |
| 1244 |
table is as follows: |
| 1245 |
|
| 1246 |
</p><div class="codeblock"><pre>CREATE TABLE lost_and_found( |
| 1247 |
rootpgno INTEGER, -- root page of tree pgno is a part of |
| 1248 |
pgno INTEGER, -- page number row was found on |
| 1249 |
nfield INTEGER, -- number of fields in row |
| 1250 |
id INTEGER, -- value of rowid field, or NULL |
| 1251 |
c0, c1, c2, c3... -- columns for fields of row |
| 1252 |
); |
| 1253 |
</pre></div> |
| 1254 |
|
| 1255 |
<p>The "lost_and_found" table contains one row for each orphaned row recovered |
| 1256 |
from the database. Additionally, there is one row for each recovered index |
| 1257 |
entry that cannot be attributed to any SQL index. This is because, in an |
| 1258 |
SQLite database, the same format is used to store SQL index entries and |
| 1259 |
WITHOUT ROWID table entries. |
| 1260 |
|
| 1261 |
</p><table striped="1" style="margin:1em auto; width:80%; border-spacing:0"> |
| 1262 |
<tr style="text-align:left"><th style="width:15ex">Column</th><th>Contents |
| 1263 |
</th></tr><tr style="text-align:left;background-color:#DDDDDD"><td>rootpgno</td><td> Even though it may not be possible to attribute the |
| 1264 |
row to a specific database table, it may be part of a tree structure |
| 1265 |
within the database file. In this case, the root page number of that |
| 1266 |
tree structure is stored in this column. Or, if the page the row was |
| 1267 |
found on is not part of a tree structure, this column stores a copy of |
| 1268 |
the value in column "pgno" - the page number of the page the row was |
| 1269 |
found on. In many, although not all, cases, all rows in the |
| 1270 |
lost_and_found table with the same value in this column belong to the |
| 1271 |
same table. |
| 1272 |
|
| 1273 |
</td></tr><tr style="text-align:left"><td>pgno</td><td> The page number of the page on which this row was found. |
| 1274 |
|
| 1275 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>nfield</td><td> The number of fields in this row. |
| 1276 |
|
| 1277 |
</td></tr><tr style="text-align:left"><td>id</td><td> If the row comes from a WITHOUT ROWID table, this column |
| 1278 |
contains NULL. Otherwise, it contains the 64-bit integer rowid value for |
| 1279 |
the row. |
| 1280 |
|
| 1281 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>c0, c1, c2...</td><td> The values for each column of the row |
| 1282 |
are stored in these columns. The ".recover" command creates the |
| 1283 |
lost_and_found table with as many columns as required by the longest |
| 1284 |
orphaned row. |
| 1285 |
</td></tr></table> |
| 1286 |
|
| 1287 |
<p>If the recovered database schema already contains a table named |
| 1288 |
"lost_and_found", the ".recover" command uses the name "lost_and_found0". If |
| 1289 |
the name "lost_and_found0" is also already taken, "lost_and_found1", and so |
| 1290 |
on. The default name "lost_and_found" may be overridden by invoking ".recover" |
| 1291 |
with the --lost-and-found switch. For example, to have the output script call |
| 1292 |
the table "orphaned_rows": |
| 1293 |
|
| 1294 |
</p><div class="codeblock"><pre>sqlite> .recover --lost-and-found orphaned_rows |
| 1295 |
</pre></div> |
| 1296 |
|
| 1297 |
<a name="dotload"></a> |
| 1298 |
|
| 1299 |
<h1 id="loading_extensions"><span>12. </span>Loading Extensions</h1> |
| 1300 |
|
| 1301 |
<p>You can add new custom <a href="appfunc.html">application-defined SQL functions</a>, |
| 1302 |
<a href="datatype3.html#collation">collating sequences</a>, <a href="vtab.html">virtual tables</a>, and <a href="vfs.html">VFSes</a> to the command-line |
| 1303 |
shell at run-time using the ".load" command. First, build the |
| 1304 |
extension as a DLL or shared library (as described in the |
| 1305 |
<a href="loadext.html">Run-Time Loadable Extensions</a> document) then type: |
| 1306 |
|
| 1307 |
</p><div class="codeblock"><pre>sqlite> .load /path/to/my_extension |
| 1308 |
</pre></div> |
| 1309 |
|
| 1310 |
<p>Note that SQLite automatically adds the appropriate extension suffix |
| 1311 |
(".dll" on windows, ".dylib" on Mac, ".so" on most other unixes) to the |
| 1312 |
extension filename. It is generally a good idea to specify the full |
| 1313 |
pathname of the extension. |
| 1314 |
|
| 1315 |
</p><p>SQLite computes the entry point for the extension based on the extension |
| 1316 |
filename. To override this choice, simply add the name of the extension |
| 1317 |
as a second argument to the ".load" command. |
| 1318 |
|
| 1319 |
</p><p>Source code for several useful extensions can be found in the |
| 1320 |
<a href="https://www.sqlite.org/src/tree?name=ext/misc&ci=trunk">ext/misc</a> |
| 1321 |
subdirectory of the SQLite source tree. You can use these extensions |
| 1322 |
as-is, or as a basis for creating your own custom extensions to address |
| 1323 |
your own particular needs. |
| 1324 |
|
| 1325 |
|
| 1326 |
<a name="sha3sum"></a> |
| 1327 |
|
| 1328 |
</p><h1 id="cryptographic_hashes_of_database_content"><span>13. </span>Cryptographic Hashes Of Database Content</h1> |
| 1329 |
|
| 1330 |
<p>The ".sha3sum" dot-command computes a |
| 1331 |
<a href="https://en.wikipedia.org/wiki/SHA-3">SHA3</a> hash of the <em>content</em> |
| 1332 |
of the database. To be clear, the hash is computed over the database content, |
| 1333 |
not its representation on disk. This means, for example, that a <a href="lang_vacuum.html">VACUUM</a> |
| 1334 |
or similar data-preserving transformation does not change the hash. |
| 1335 |
|
| 1336 |
</p><p>The ".sha3sum" command supports options "--sha3-224", "--sha3-256", |
| 1337 |
"--sha3-384", and "--sha3-512" to define which variety of SHA3 to use |
| 1338 |
for the hash. The default is SHA3-256. |
| 1339 |
|
| 1340 |
</p><p>The database schema (in the <a href="schematab.html">sqlite_schema</a> table) is not normally |
| 1341 |
included in the hash, but can be added by the "--schema" option. |
| 1342 |
|
| 1343 |
</p><p>The ".sha3sum" command takes a single optional argument which is a |
| 1344 |
<a href="lang_expr.html#like">LIKE</a> pattern. If this option is present, only tables whose names match |
| 1345 |
the <a href="lang_expr.html#like">LIKE</a> pattern will be hashed. |
| 1346 |
|
| 1347 |
</p><p>The ".sha3sum" command is implemented with the help of the |
| 1348 |
<a href="https://www.sqlite.org/src/file/ext/misc/shathree.c">extension function "sha3_query()"</a> |
| 1349 |
that is included with the command-line shell. |
| 1350 |
|
| 1351 |
<a name="selftest"></a> |
| 1352 |
|
| 1353 |
</p><h1 id="database_content_self_tests"><span>14. </span>Database Content Self-Tests</h1> |
| 1354 |
|
| 1355 |
<p>The ".selftest" command attempts to verify that a database is |
| 1356 |
intact and is not corrupt. |
| 1357 |
The .selftest command looks for a table in schema named "selftest" |
| 1358 |
and defined as follows: |
| 1359 |
|
| 1360 |
</p><div class="codeblock"><pre>CREATE TABLE selftest( |
| 1361 |
tno INTEGER PRIMARY KEY, -- Test number |
| 1362 |
op TEXT, -- 'run' or 'memo' |
| 1363 |
cmd TEXT, -- SQL command to run, or text of "memo" |
| 1364 |
ans TEXT -- Expected result of the SQL command |
| 1365 |
); |
| 1366 |
</pre></div> |
| 1367 |
|
| 1368 |
<p>The .selftest command reads the rows of the selftest table in |
| 1369 |
selftest.tno order. |
| 1370 |
For each 'memo' row, it writes the text in 'cmd' to the output. For |
| 1371 |
each 'run' row, it runs the 'cmd' text as SQL and compares the result |
| 1372 |
to the value in 'ans', and shows an error message if the results differ. |
| 1373 |
|
| 1374 |
</p><p>If there is no selftest table, the ".selftest" command runs |
| 1375 |
<a href="pragma.html#pragma_integrity_check">PRAGMA integrity_check</a>. |
| 1376 |
|
| 1377 |
</p><p>The ".selftest --init" command creates the selftest table if it |
| 1378 |
does not already exists, then appends entries that check the SHA3 |
| 1379 |
hash of the content of all tables. Subsequent runs of ".selftest" |
| 1380 |
will verify that the database has not been changed in any way. To |
| 1381 |
generate tests to verify that a subset of the tables is unchanged, |
| 1382 |
simply run ".selftest --init" then <a href="lang_delete.html">DELETE</a> the selftest rows that |
| 1383 |
refer to tables that are not constant. |
| 1384 |
|
| 1385 |
<a name="sqlar"></a> |
| 1386 |
|
| 1387 |
</p><h1 id="sqlite_archive_support"><span>15. </span>SQLite Archive Support</h1> |
| 1388 |
|
| 1389 |
<p>The ".archive" dot-command and the "-A" command-line option |
| 1390 |
provide built-in support for the |
| 1391 |
<a href="sqlar.html">SQLite Archive format</a>. The interface is similar to |
| 1392 |
that of the "tar" command on unix systems. Each invocation of the ".ar" |
| 1393 |
command must specify a single command option. The following commands |
| 1394 |
are available for ".archive": |
| 1395 |
|
| 1396 |
</p><table striped="1" style="margin:1em auto; width:80%; border-spacing:0"> |
| 1397 |
<tr style="text-align:left"><th style="width:15ex">Option</th><th style="width:17ex">Long Option</th><th>Purpose |
| 1398 |
</th></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-c</td><td>--create</td><td>Create a new archive containing specified files. |
| 1399 |
</td></tr><tr style="text-align:left"><td>-x</td><td>--extract</td><td>Extract specified files from archive. |
| 1400 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-i</td><td>--insert</td><td>Add files to existing archive. |
| 1401 |
</td></tr><tr style="text-align:left"><td>-r</td><td>--remove</td><td>Remove files from the archive. |
| 1402 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-t</td><td>--list</td><td>List the files in the archive. |
| 1403 |
</td></tr><tr style="text-align:left"><td>-u</td><td>--update</td><td>Add files to existing archive <em>if</em> they have changed. |
| 1404 |
</td></tr></table> |
| 1405 |
|
| 1406 |
<p>As well as the command option, each invocation of ".ar" may specify |
| 1407 |
one or more modifier options. Some modifier options require an argument, |
| 1408 |
some do not. The following modifier options are available: |
| 1409 |
|
| 1410 |
</p><table striped="1" style="margin:1em auto; width:80%; border-spacing:0"> |
| 1411 |
<tr style="text-align:left"><th style="width:15ex">Option</th><th style="width:17ex">Long Option</th><th>Purpose |
| 1412 |
</th></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-v</td><td>--verbose</td><td>List each file as it is processed. |
| 1413 |
</td></tr><tr style="text-align:left"><td>-f FILE</td><td>--file FILE</td><td>If specified, use file FILE as the |
| 1414 |
archive. Otherwise, assume that the current "main" database is the |
| 1415 |
archive to be operated on. |
| 1416 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-a FILE</td><td>--append FILE</td><td>Like --file, use file FILE as the |
| 1417 |
archive, but open the file using the |
| 1418 |
<a href="https://sqlite.org/src/file/ext/misc/appendvfs.c">apndvfs VFS</a> so that |
| 1419 |
the archive will be appended to the end of FILE if FILE already exists. |
| 1420 |
</td></tr><tr style="text-align:left"><td>-C DIR</td><td>--directory DIR</td><td>If specified, interpret all relative |
| 1421 |
paths as relative to DIR, instead of the current working directory. |
| 1422 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>-g</td><td>--glob</td><td>Use <a href="lang_corefunc.html#glob">glob(<i>Y</i>,<i>X</i>)</a> to match arguments |
| 1423 |
against names in the archive. |
| 1424 |
</td></tr><tr style="text-align:left"><td>-n</td><td>--dryrun</td><td>Show the SQL that would be run to carry out the |
| 1425 |
archive operation, but do not actually change anything. |
| 1426 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>--</td><td>--</td><td>All subsequent command line words are command arguments, |
| 1427 |
not options. |
| 1428 |
</td></tr></table> |
| 1429 |
|
| 1430 |
<p> |
| 1431 |
For command-line usage, add the short style command-line options immediately |
| 1432 |
following the "-A", without an intervening space. All subsequent arguments |
| 1433 |
are considered to be part of the .archive command. For example, the following |
| 1434 |
commands are equivalent: |
| 1435 |
|
| 1436 |
</p><div class="codeblock"><pre>sqlite3 new_archive.db -Acv file1 file2 file3 |
| 1437 |
sqlite3 new_archive.db ".ar -cv file1 file2 file3" |
| 1438 |
</pre></div> |
| 1439 |
|
| 1440 |
<p> |
| 1441 |
Long and short style options may be mixed. For example, the following are |
| 1442 |
equivalent: |
| 1443 |
|
| 1444 |
</p><div class="codeblock"><pre><i>-- Two ways to create a new archive named "new_archive.db" containing</i> |
| 1445 |
<i>-- files "file1", "file2" and "file3".</i> |
| 1446 |
.ar -c --file new_archive.db file1 file2 file3 |
| 1447 |
.ar -f new_archive.db --create file1 file2 file3 |
| 1448 |
</pre></div> |
| 1449 |
|
| 1450 |
<p>Alternatively, the first argument following to ".ar" may be the concatenation |
| 1451 |
of the short form of all required options (without the "-" characters). In |
| 1452 |
this case arguments for options requiring them are read from the command line |
| 1453 |
next, and any remaining words are considered command arguments. For example: |
| 1454 |
|
| 1455 |
</p><div class="codeblock"><pre><i>-- Create a new archive "new_archive.db" containing files "file1" and</i> |
| 1456 |
<i>-- "file2" from directory "dir1".</i> |
| 1457 |
.ar cCf dir1 new_archive.db file1 file2 file3 |
| 1458 |
</pre></div> |
| 1459 |
|
| 1460 |
<h2 id="_sqlite_archive_create_command_"><span>15.1. </span> SQLite Archive Create Command </h2> |
| 1461 |
|
| 1462 |
<p>Create a new archive, overwriting any existing archive (either in the current |
| 1463 |
"main" db or in the file specified by a --file option). Each argument following |
| 1464 |
the options is a file to add to the archive. Directories are imported |
| 1465 |
recursively. See above for examples. |
| 1466 |
|
| 1467 |
</p><h2 id="_sqlite_archive_extract_command_"><span>15.2. </span> SQLite Archive Extract Command </h2> |
| 1468 |
|
| 1469 |
<p>Extract files from the archive (either to the current working directory or |
| 1470 |
to the directory specified by a --directory option). |
| 1471 |
Files or directories whose names match the arguments, |
| 1472 |
as affected by the --glob option, are extracted. |
| 1473 |
Or, if no arguments follow the options, all files and directories are extracted. |
| 1474 |
Any specified directories are extracted recursively. It is an error if any |
| 1475 |
specified names or match patterns cannot be found in the archive. |
| 1476 |
|
| 1477 |
</p><div class="codeblock"><pre><i>-- Extract all files from the archive in the current "main" db to the</i> |
| 1478 |
<i>-- current working directory. List files as they are extracted. </i> |
| 1479 |
.ar --extract --verbose |
| 1480 |
|
| 1481 |
<i>-- Extract file "file1" from archive "ar.db" to directory "dir1".</i> |
| 1482 |
.ar fCx ar.db dir1 file1 |
| 1483 |
|
| 1484 |
<i>-- Extract files with ".h" extension to directory "headers".</i> |
| 1485 |
.ar -gCx headers *.h |
| 1486 |
</pre></div> |
| 1487 |
|
| 1488 |
<h2 id="_sqlite_archive_list_command_"><span>15.3. </span> SQLite Archive List Command </h2> |
| 1489 |
|
| 1490 |
<p>List the contents of the archive. If no arguments are specified, then all |
| 1491 |
files are listed. Otherwise, only those which match the arguments, |
| 1492 |
as affected by the --glob option, are listed. Currently, |
| 1493 |
the --verbose option does not change the behaviour of this command. That may |
| 1494 |
change in the future. |
| 1495 |
|
| 1496 |
</p><div class="codeblock"><pre><i>-- List contents of archive in current "main" db.</i>. |
| 1497 |
.ar --list |
| 1498 |
</pre></div> |
| 1499 |
|
| 1500 |
<a name="arinsup"></a> |
| 1501 |
|
| 1502 |
<h2 id="_sqlite_archive_insert_and_update_commands_"><span>15.4. </span> SQLite Archive Insert And Update Commands </h2> |
| 1503 |
|
| 1504 |
<p> The --update and --insert commands work like --create command, except that |
| 1505 |
they do not delete the current archive before commencing. New versions of |
| 1506 |
files silently replace existing files with the same names, but otherwise |
| 1507 |
the initial contents of the archive (if any) remain intact. |
| 1508 |
|
| 1509 |
</p><p> For the --insert command, all files listed are inserted into the archive. |
| 1510 |
For the --update command, files are only inserted if they do not previously |
| 1511 |
exist in the archive, or if their "mtime" or "mode" is different from what |
| 1512 |
is currently in the archive. |
| 1513 |
|
| 1514 |
</p><p> Compatibility node: Prior to SQLite version 3.28.0 (2019-04-16) only |
| 1515 |
the --update option was supported but that option worked like --insert in that |
| 1516 |
it always reinserted every file regardless of whether or not it had changed. |
| 1517 |
|
| 1518 |
</p><h2 id="_sqlite_archive_remove_command_"><span>15.5. </span> SQLite Archive Remove Command </h2> |
| 1519 |
|
| 1520 |
<p> The --remove command deletes files and directories which match the |
| 1521 |
provided arguments (if any) as affected by the --glob option. |
| 1522 |
It is an error to provide arguments which match nothing in the archive. |
| 1523 |
|
| 1524 |
</p><h2 id="_operations_on_zip_archives_"><span>15.6. </span> Operations On ZIP Archives </h2> |
| 1525 |
|
| 1526 |
<p>If FILE is a ZIP archive rather than an SQLite Archive, the ".archive" |
| 1527 |
command and the "-A" command-line option still work. This is accomplished |
| 1528 |
using of the <a href="zipfile.html">zipfile</a> extension. |
| 1529 |
Hence, the following commands are roughly equivalent, |
| 1530 |
differing only in output formatting: |
| 1531 |
|
| 1532 |
</p><table striped="1" style="margin:1em auto; width:80%; border-spacing:0"> |
| 1533 |
<tr style="text-align:left"><th>Traditional Command</th><th>Equivalent sqlite3.exe Command |
| 1534 |
</th></tr><tr style="text-align:left;background-color:#DDDDDD"><td>unzip archive.zip</td><td>sqlite3 -Axf archive.zip |
| 1535 |
</td></tr><tr style="text-align:left"><td>unzip -l archive.zip</td><td>sqlite3 -Atvf archive.zip |
| 1536 |
</td></tr><tr style="text-align:left;background-color:#DDDDDD"><td>zip -r archive2.zip dir</td><td>sqlite3 -Acf archive2.zip dir |
| 1537 |
</td></tr></table> |
| 1538 |
|
| 1539 |
<h2 id="_sql_used_to_implement_sqlite_archive_operations_"><span>15.7. </span> SQL Used To Implement SQLite Archive Operations </h2> |
| 1540 |
|
| 1541 |
<p>The various SQLite Archive Archive commands are implemented using SQL statements. |
| 1542 |
Application developers can easily add SQLite Archive Archive reading and writing |
| 1543 |
support to their own projects by running the appropriate SQL. |
| 1544 |
|
| 1545 |
</p><p>To see what SQL statements are used to implement an SQLite Archive |
| 1546 |
operation, add the --dryrun or -n option. This causes the SQL to be |
| 1547 |
displayed but inhibits the execution of the SQL. |
| 1548 |
|
| 1549 |
</p><p>The SQL statements used to implement SQLite Archive operations make use of |
| 1550 |
various <a href="loadext.html">loadable extensions</a>. These extensions are all available in |
| 1551 |
the <a href="https://sqlite.org/src">SQLite source tree</a> in the |
| 1552 |
<a href="https://sqlite.org/src/file/ext/misc">ext/misc/ subfolder</a>. |
| 1553 |
The extensions needed for full SQLite Archive support include: |
| 1554 |
|
| 1555 |
</p><ol> |
| 1556 |
<li><p> |
| 1557 |
<a href="https://sqlite.org/src/file/ext/misc/fileio.c">fileio.c</a> — |
| 1558 |
This extension adds SQL functions readfile() and writefile() for |
| 1559 |
reading and writing content from files on disk. The fileio.c |
| 1560 |
extension also includes fsdir() table-valued function for listing |
| 1561 |
the contents of a directory and the lsmode() function for converting |
| 1562 |
numeric st_mode integers from the stat() system call into human-readable |
| 1563 |
strings after the fashion of the "ls -l" command. |
| 1564 |
|
| 1565 |
</p></li><li><p> |
| 1566 |
<a href="https://sqlite.org/src/file/ext/misc/sqlar.c">sqlar.c</a> — |
| 1567 |
This extension adds the sqlar_compress() and sqlar_uncompress() |
| 1568 |
functions that are needed to compress and uncompress file content |
| 1569 |
as it is inserted and extracted from an SQLite Archive. |
| 1570 |
|
| 1571 |
</p></li><li><p> |
| 1572 |
<a href="zipfile.html">zipfile.c</a> — |
| 1573 |
This extension implements the "zipfile(FILE)" table-valued function |
| 1574 |
which is used to read ZIP archives. This extension is only needed |
| 1575 |
when reading ZIP archives instead of SQLite archives. |
| 1576 |
|
| 1577 |
</p></li><li><p> |
| 1578 |
<a href="https://sqlite.org/src/file/ext/misc/appendvfs.c">appendvfs.c</a> — |
| 1579 |
This extension implements a new <a href="vfs.html">VFS</a> that allows an SQLite database |
| 1580 |
to be appended to some other file, such as an executable. This |
| 1581 |
extension is only needed if the --append option to the .archive |
| 1582 |
command is used. |
| 1583 |
</p></li></ol> |
| 1584 |
|
| 1585 |
<a name="param"></a> |
| 1586 |
|
| 1587 |
<h1 id="sql_parameters"><span>16. </span>SQL Parameters</h1> |
| 1588 |
|
| 1589 |
<p>SQLite allows <a href="lang_expr.html#varparam">bound parameters</a> to appear in an SQL statement anywhere |
| 1590 |
that a literal value is allowed. The values for these parameters are set |
| 1591 |
using the <a href="c3ref/bind_blob.html">sqlite3_bind_...()</a> family of APIs. |
| 1592 |
|
| 1593 |
</p><p>Parameters can be either named or unnamed. An unnamed parameter is a single |
| 1594 |
question mark ("?"). Named parameters are a "?" followed immediately by a number |
| 1595 |
(ex: "?15" or "?123") or one of the characters "$", ":", or "@" followed by an |
| 1596 |
alphanumeric name (ex: "$var1", ":xyz", "@bingo"). |
| 1597 |
|
| 1598 |
</p><p>This command-line shell leaves unnamed parameters unbound, meaning that they |
| 1599 |
will have a value of an SQL NULL, but named parameters might be assigned values. |
| 1600 |
If there exists a TEMP table named "sqlite_parameters" with a schema like this: |
| 1601 |
|
| 1602 |
</p><div class="codeblock"><pre>CREATE TEMP TABLE sqlite_parameters( |
| 1603 |
key TEXT PRIMARY KEY, |
| 1604 |
value |
| 1605 |
) WITHOUT ROWID; |
| 1606 |
</pre></div> |
| 1607 |
|
| 1608 |
<p>And if there is an entry in that table where the key column exactly matches |
| 1609 |
the name of parameter (including the initial "?", "$", ":", or "@" character) |
| 1610 |
then the parameter is assigned the value of the value column. If no entry exists, |
| 1611 |
the parameter defaults to NULL. |
| 1612 |
|
| 1613 |
</p><p>The ".parameter" command exists to simplify managing this table. The |
| 1614 |
".parameter init" command (often abbreviated as just ".param init") creates |
| 1615 |
the temp.sqlite_parameters table if it does not already exist. The ".param list" |
| 1616 |
command shows all entries in the temp.sqlite_parameters table. The ".param clear" |
| 1617 |
command drops the temp.sqlite_parameters table. The ".param set KEY VALUE" and |
| 1618 |
".param unset KEY" commands create or delete entries from the |
| 1619 |
temp.sqlite_parameters table. |
| 1620 |
|
| 1621 |
</p><p>The VALUE passed to ".param set KEY VALUE" can be either a SQL literal |
| 1622 |
or any other SQL expression or query which can be evaluated to yield a value. |
| 1623 |
This allows values of differing types to be set. |
| 1624 |
If such evaluation fails, the provided VALUE is instead quoted and inserted |
| 1625 |
as text. |
| 1626 |
Because such initial evaluation may or may not fail depending upon |
| 1627 |
the VALUE content, the reliable way to get a text value is to enclose it |
| 1628 |
with single-quotes protected from the above-described command-tail parsing. |
| 1629 |
For example, (unless one intends a value of -1365):<br> |
| 1630 |
</p><div class="codeblock"><pre>.parameter init |
| 1631 |
.parameter set @phoneNumber "'202-456-1111'" |
| 1632 |
</pre></div> |
| 1633 |
<p>Note that the double-quotes serve to protect the single-quotes |
| 1634 |
and ensure that the quoted text is parsed as one argument. |
| 1635 |
|
| 1636 |
</p><p>The temp.sqlite_parameters table only provides values for parameters in the |
| 1637 |
command-line shell. The temp.sqlite_parameter table has no effect on queries |
| 1638 |
that are run directly using the SQLite C-language API. Individual applications |
| 1639 |
are expected to implement their own parameter binding. You can search for |
| 1640 |
"sqlite_parameters" in the |
| 1641 |
<a href="https://sqlite.org/src/file/src/shell.c.in">command-line shell source code</a> |
| 1642 |
to see how the command-line shell does parameter binding, and use that as |
| 1643 |
a hint for how to implement it yourself. |
| 1644 |
|
| 1645 |
<a name="expert"></a> |
| 1646 |
|
| 1647 |
</p><h1 id="index_recommendations_sqlite_expert_"><span>17. </span>Index Recommendations (SQLite Expert)</h1> |
| 1648 |
|
| 1649 |
<p><b>Note: This command is experimental. It may be removed or the |
| 1650 |
interface modified in incompatible ways at some point in the future. |
| 1651 |
|
| 1652 |
</b></p><p>For most non-trivial SQL databases, the key to performance is creating |
| 1653 |
the right SQL indexes. In this context "the right SQL indexes" means those |
| 1654 |
that cause the queries that an application needs to optimize run fast. The |
| 1655 |
".expert" command can assist with this by proposing indexes that might |
| 1656 |
assist with specific queries, were they present in the database. |
| 1657 |
|
| 1658 |
</p><p>The ".expert" command is issued first, followed by the SQL query |
| 1659 |
on a separate line. For example, consider the following session: |
| 1660 |
|
| 1661 |
</p><div class="codeblock"><pre>sqlite> CREATE TABLE x1(a, b, c); <i>-- Create table in database </i> |
| 1662 |
sqlite> .expert |
| 1663 |
sqlite> SELECT * FROM x1 WHERE a=? AND b>?; <i>-- Analyze this SELECT </i> |
| 1664 |
CREATE INDEX x1_idx_000123a7 ON x1(a, b); |
| 1665 |
|
| 1666 |
0|0|0|SEARCH TABLE x1 USING INDEX x1_idx_000123a7 (a=? AND b>?) |
| 1667 |
|
| 1668 |
sqlite> CREATE INDEX x1ab ON x1(a, b); <i>-- Create the recommended index </i> |
| 1669 |
sqlite> .expert |
| 1670 |
sqlite> SELECT * FROM x1 WHERE a=? AND b>?; <i>-- Re-analyze the same SELECT </i> |
| 1671 |
(no new indexes) |
| 1672 |
|
| 1673 |
0|0|0|SEARCH TABLE x1 USING INDEX x1ab (a=? AND b>?) |
| 1674 |
</pre></div> |
| 1675 |
|
| 1676 |
<p>In the above, the user creates the database schema (a single table - "x1"), |
| 1677 |
and then uses the ".expert" command to analyze a query, in this case |
| 1678 |
"SELECT * FROM x1 WHERE a=? AND b>?". The shell tool recommends that the |
| 1679 |
user create a new index (index "x1_idx_000123a7") and outputs the plan |
| 1680 |
that the query would use in <a href="eqp.html">EXPLAIN QUERY PLAN</a> format. The user then creates |
| 1681 |
an index with an equivalent schema and runs the analysis on the same query |
| 1682 |
again. This time the shell tool does not recommend any new indexes, and |
| 1683 |
outputs the plan that SQLite will use for the query given the existing |
| 1684 |
indexes. |
| 1685 |
|
| 1686 |
</p><p>The ".expert" command accepts the following options: |
| 1687 |
|
| 1688 |
</p><table striped="1" style="margin:1em auto; width:80%; border-spacing:0"> |
| 1689 |
<tr style="text-align:left"><th> Option </th><th> Purpose |
| 1690 |
</th></tr><tr style="text-align:left;background-color:#DDDDDD"><td> ‑‑verbose |
| 1691 |
</td><td> If present, output a more verbose report for each query analyzed. |
| 1692 |
</td></tr><tr style="text-align:left"><td> ‑‑sample PERCENT |
| 1693 |
</td><td> This parameter defaults to 0, causing the ".expert" command to |
| 1694 |
recommend indexes based on the query and database schema alone. |
| 1695 |
This is similar to the way the <a href="optoverview.html">SQLite query planner</a> selects |
| 1696 |
indexes for queries if the user has not run the <a href="lang_analyze.html">ANALYZE</a> command |
| 1697 |
on the database to generate data distribution statistics. |
| 1698 |
<div style="margin-top:1ex"> |
| 1699 |
If this option is passed a non-zero argument, the ".expert" command |
| 1700 |
generates similar data distribution statistics for all indexes |
| 1701 |
considered based on PERCENT percent of the rows currently stored in |
| 1702 |
each database table. For databases with unusual data distributions, |
| 1703 |
this may lead to better index recommendations, particularly if the |
| 1704 |
application intends to run ANALYZE. |
| 1705 |
<div style="margin-top:1ex"> |
| 1706 |
For small databases and modern CPUs, there is usually no reason not |
| 1707 |
to pass "--sample 100". However, gathering data distribution |
| 1708 |
statistics can be expensive for large database tables. If the |
| 1709 |
operation is too slow, try passing a smaller value for the --sample |
| 1710 |
option. |
| 1711 |
</div></div></td></tr></table> |
| 1712 |
|
| 1713 |
<p>The functionality described in this section may be integrated into other |
| 1714 |
applications or tools using the |
| 1715 |
<a href="https://www.sqlite.org/src/dir?ci=trunk&name=ext/expert"> |
| 1716 |
SQLite expert extension</a> code. |
| 1717 |
|
| 1718 |
</p><p>A database schema which incorporate SQL custom functions made available |
| 1719 |
via the extension load mechanism may need special provision to work with |
| 1720 |
the .expert feature. Because the feature uses additional connections to |
| 1721 |
implement its functionality, those custom functions must be made available |
| 1722 |
to those additional connections. This can be done by means of the extension |
| 1723 |
load/usage options described at |
| 1724 |
<a href="c3ref/auto_extension.html"> |
| 1725 |
Automatically Load Statically Linked Extensions</a> |
| 1726 |
and <a href="loadext.html#persist"> |
| 1727 |
Persistent Loadable Extensions</a>. |
| 1728 |
|
| 1729 |
<a name="dotconn"></a> |
| 1730 |
|
| 1731 |
</p><h1 id="working_with_multiple_database_connections"><span>18. </span>Working With Multiple Database Connections</h1> |
| 1732 |
|
| 1733 |
<p> |
| 1734 |
Beginning with version 3.37.0 (2021-11-27), the CLI has the ability to |
| 1735 |
hold multiple <a href="c3ref/sqlite3.html">database connections</a> open at once. Only one database connection |
| 1736 |
is active at a time. The inactive connections are still open but are idle. |
| 1737 |
|
| 1738 |
</p><p> |
| 1739 |
Use the ".connection" dot-command (often abbreviated as just ".conn") to see a |
| 1740 |
list of database connections and an indication of which one is currently active. |
| 1741 |
Each database connection is identified by an integer between 0 and 9. (There |
| 1742 |
can be at most 10 simultaneously open connections.) Change to another database |
| 1743 |
connection, creating it if it does not already exist, by typing the ".conn" |
| 1744 |
command followed by its number. Close a database connection by typing |
| 1745 |
".conn close N" where N is the connection number. |
| 1746 |
|
| 1747 |
</p><p> |
| 1748 |
Though the underlying SQLite database connections are completely independent |
| 1749 |
of one another, many of the CLI settings, such as the output format, are |
| 1750 |
shared across all database connections. Thus, changing the <a href="cli.html#dotmode">output mode</a> in |
| 1751 |
one connection will change it in them all. On the other hand, some |
| 1752 |
<a href="cli.html#dotcmd">dot-commands</a> such as <a href="cli.html#dotopen">.open</a> only affect the current connection. |
| 1753 |
|
| 1754 |
<a name="miscfeatures"></a> |
| 1755 |
|
| 1756 |
</p><h1 id="miscellaneous_extension_features"><span>19. </span>Miscellaneous Extension Features</h1> |
| 1757 |
|
| 1758 |
<p> |
| 1759 |
The CLI is built with several SQLite extensions that are not |
| 1760 |
included with the SQLite library. A few add features |
| 1761 |
not described in the preceding sections, namely: |
| 1762 |
</p><ul> |
| 1763 |
<li>the UINT collating sequence which treats |
| 1764 |
unsigned integers embedded in text according to |
| 1765 |
their value, along with other text, for ordering; |
| 1766 |
</li><li>decimal arithmetic as provided by the <a href="floatingpoint.html#decext">decimal extension</a>; |
| 1767 |
</li><li>the <a href="series.html">generate_series</a>() table-valued function; |
| 1768 |
<a name="base64"></a> |
| 1769 |
|
| 1770 |
<a name="base85"></a> |
| 1771 |
|
| 1772 |
</li><li>the base64() and base85() functions which encode a |
| 1773 |
blob to base64 or base85 text or decode the same to a blob; and |
| 1774 |
</li><li>support for POSIX extended regular expressions |
| 1775 |
bound to the <a href="lang_expr.html#regexp">REGEXP</a> operator. |
| 1776 |
</li></ul> |
| 1777 |
|
| 1778 |
<a name="dotother"></a> |
| 1779 |
|
| 1780 |
<h1 id="other_dot_commands"><span>20. </span>Other Dot Commands</h1> |
| 1781 |
|
| 1782 |
<p>There are many other dot-commands available in the command-line |
| 1783 |
shell. See the ".help" command for a complete list for any particular |
| 1784 |
version and build of SQLite. |
| 1785 |
|
| 1786 |
<a name="insh"></a> |
| 1787 |
|
| 1788 |
</p><h1 id="using_sqlite3_in_a_shell_script"><span>21. </span>Using sqlite3 in a shell script</h1> |
| 1789 |
|
| 1790 |
<p> |
| 1791 |
One way to use sqlite3 in a shell script is to use "echo" or |
| 1792 |
"cat" to generate a sequence of commands in a file, then invoke sqlite3 |
| 1793 |
while redirecting input from the generated command file. This |
| 1794 |
works fine and is appropriate in many circumstances. But as |
| 1795 |
an added convenience, sqlite3 allows a single SQL command to be |
| 1796 |
entered on the command line as a second argument after the |
| 1797 |
database name. When the sqlite3 program is launched with two |
| 1798 |
arguments, the second argument is passed to the SQLite library |
| 1799 |
for processing, the query results are printed on standard output |
| 1800 |
in list mode, and the program exits. This mechanism is designed |
| 1801 |
to make sqlite3 easy to use in conjunction with programs like |
| 1802 |
"awk". For example:</p> |
| 1803 |
|
| 1804 |
<div class="codeblock"><pre>$ <b>sqlite3 ex1 'select * from tbl1' \</b> |
| 1805 |
> <b> | awk '{printf "<tr><td>%s<td>%s\n",$1,$2 }'</b> |
| 1806 |
<tr><td>hello<td>10 |
| 1807 |
<tr><td>goodbye<td>20 |
| 1808 |
$ |
| 1809 |
</pre></div> |
| 1810 |
|
| 1811 |
<a name="endsh"></a> |
| 1812 |
|
| 1813 |
<h1 id="marking_the_end_of_an_sql_statement"><span>22. </span>Marking The End Of An SQL Statement</h1> |
| 1814 |
|
| 1815 |
<p> |
| 1816 |
SQLite commands are normally terminated by a semicolon. In the CLI |
| 1817 |
you can also use the word "GO" (case-insensitive) or a slash character |
| 1818 |
"/" on a line by itself to end a command. These are used by SQL Server |
| 1819 |
and Oracle, respectively, and are supported by the SQLite CLI for |
| 1820 |
compatibility. These won't work in <b>sqlite3_exec()</b>, |
| 1821 |
because the CLI translates these inputs into a semicolon before passing |
| 1822 |
them down into the SQLite core.</p> |
| 1823 |
|
| 1824 |
<a name="clopts"></a> |
| 1825 |
|
| 1826 |
<h1 id="command_line_options"><span>23. </span>Command-line Options</h1> |
| 1827 |
|
| 1828 |
<p> |
| 1829 |
There are many command-line options available to the CLI. Use the --help |
| 1830 |
command-line option to see a list: |
| 1831 |
|
| 1832 |
</p><div class="codeblock"><pre>$ <b>sqlite3 --help</b> |
| 1833 |
Usage: ./sqlite3 [OPTIONS] FILENAME [SQL] |
| 1834 |
FILENAME is the name of an SQLite database. A new database is created |
| 1835 |
if the file does not previously exist. Defaults to :memory:. |
| 1836 |
OPTIONS include: |
| 1837 |
-- treat no subsequent arguments as options |
| 1838 |
-A ARGS... run ".archive ARGS" and exit |
| 1839 |
-append append the database to the end of the file |
| 1840 |
-ascii set output mode to 'ascii' |
| 1841 |
-bail stop after hitting an error |
| 1842 |
-batch force batch I/O |
| 1843 |
-box set output mode to 'box' |
| 1844 |
-column set output mode to 'column' |
| 1845 |
-cmd COMMAND run "COMMAND" before reading stdin |
| 1846 |
-csv set output mode to 'csv' |
| 1847 |
-deserialize open the database using sqlite3_deserialize() |
| 1848 |
-echo print inputs before execution |
| 1849 |
-init FILENAME read/process named file |
| 1850 |
-[no]header turn headers on or off |
| 1851 |
-help show this message |
| 1852 |
-html set output mode to HTML |
| 1853 |
-interactive force interactive I/O |
| 1854 |
-json set output mode to 'json' |
| 1855 |
-line set output mode to 'line' |
| 1856 |
-list set output mode to 'list' |
| 1857 |
-lookaside SIZE N use N entries of SZ bytes for lookaside memory |
| 1858 |
-markdown set output mode to 'markdown' |
| 1859 |
-maxsize N maximum size for a --deserialize database |
| 1860 |
-memtrace trace all memory allocations and deallocations |
| 1861 |
-mmap N default mmap size set to N |
| 1862 |
-newline SEP set output row separator. Default: '\n' |
| 1863 |
-nofollow refuse to open symbolic links to database files |
| 1864 |
-nonce STRING set the safe-mode escape nonce |
| 1865 |
-nullvalue TEXT set text string for NULL values. Default '' |
| 1866 |
-pagecache SIZE N use N slots of SZ bytes each for page cache memory |
| 1867 |
-pcachetrace trace all page cache operations |
| 1868 |
-quote set output mode to 'quote' |
| 1869 |
-readonly open the database read-only |
| 1870 |
-safe enable safe-mode |
| 1871 |
-separator SEP set output column separator. Default: '|' |
| 1872 |
-stats print memory stats before each finalize |
| 1873 |
-table set output mode to 'table' |
| 1874 |
-tabs set output mode to 'tabs' |
| 1875 |
-unsafe-testing allow unsafe commands and modes for testing |
| 1876 |
-version show SQLite version |
| 1877 |
-vfs NAME use NAME as the default VFS |
| 1878 |
-zip open the file as a ZIP Archive |
| 1879 |
</pre></div> |
| 1880 |
|
| 1881 |
<p>The CLI is flexible regarding command-line option formatting. |
| 1882 |
Either one or two leading "-" characters are permitted. |
| 1883 |
Thus "-box" and "--box" mean the same thing. |
| 1884 |
Command-line options are processed from left to right. |
| 1885 |
Hence a "--box" option will override a prior "--quote" option. |
| 1886 |
|
| 1887 |
</p><p> |
| 1888 |
Most of the command-line options are self-explanatory, but a few merit additional |
| 1889 |
discussion below. |
| 1890 |
|
| 1891 |
<a name="safemode"></a> |
| 1892 |
|
| 1893 |
</p><h2 id="the_safe_command_line_option"><span>23.1. </span>The --safe command-line option</h2> |
| 1894 |
|
| 1895 |
<p>The --safe command-line option attempts to disable all features of the CLI that |
| 1896 |
might cause any changes to the host computer other than changes to the specific database |
| 1897 |
file named on the command-line. The idea is that if you receive a large SQL script |
| 1898 |
from an unknown or untrusted source, you can run that script to see what it does without |
| 1899 |
risking an exploit by using the --safe option. The --safe option disables (among other |
| 1900 |
things): |
| 1901 |
|
| 1902 |
</p><ul> |
| 1903 |
<li> The <a href="cli.html#dotopen">.open command</a>, unless the --hexdb option is used or the filename is ":memory:". |
| 1904 |
This prevents the script from reading or writing any database files not named on |
| 1905 |
the original command-line. |
| 1906 |
</li><li> The <a href="lang_attach.html">ATTACH</a> SQL command. |
| 1907 |
</li><li> SQL functions that have potentially harmful side-effects, such as |
| 1908 |
edit(), fts3_tokenizer(), load_extension(), readfile() and writefile(). |
| 1909 |
</li><li> The <a href="cli.html#sqlar">.archive command</a>. |
| 1910 |
</li><li> The .backup and .save commands. |
| 1911 |
</li><li> The <a href="cli.html#csv">.import command</a>. |
| 1912 |
</li><li> The <a href="cli.html#dotload">.load command</a>. |
| 1913 |
</li><li> The .log command. |
| 1914 |
</li><li> The .shell and .system commands. |
| 1915 |
</li><li> The .excel, .once and .output commands. |
| 1916 |
</li><li> Other commands that can have deleterious side effects. |
| 1917 |
|
| 1918 |
</li></ul> |
| 1919 |
|
| 1920 |
<p>Basically, any feature of the CLI that reads or writes from a file on disk other |
| 1921 |
than the main database file is disabled. |
| 1922 |
|
| 1923 |
</p><h3 id="bypassing_safe_restrictions_for_specific_commands"><span>23.1.1. </span>Bypassing --safe restrictions for specific commands</h3> |
| 1924 |
|
| 1925 |
<p>If the "--nonce NONCE" option is also included on the command-line, for some |
| 1926 |
large and arbitrary NONCE string, then the ".nonce NONCE" command (with the |
| 1927 |
same large nonce string) will permit the next SQL statement or dot-command |
| 1928 |
to bypass the --safe restrictions. |
| 1929 |
|
| 1930 |
</p><p>Suppose you want to run a suspicious script and the script requires one or |
| 1931 |
two of the features that --safe normally disables. For example, suppose it |
| 1932 |
needs to ATTACH one additional database. Or suppose the script needs to load |
| 1933 |
a specific extension. This can be accomplished by preceding the (carefully |
| 1934 |
audited) ATTACH statement or the ".load" command with an appropriate ".nonce" |
| 1935 |
command and supplying the same nonce value using the "--nonce" command-line |
| 1936 |
option. Those specific commands will then be allowed to execute normally, |
| 1937 |
but all other unsafe commands will still be restricted. |
| 1938 |
|
| 1939 |
</p><p>The use of ".nonce" is dangerous in the sense that a mistake can allow a |
| 1940 |
hostile script to damage your system. Therefore, use ".nonce" carefully, |
| 1941 |
sparingly, and as a last resort when there are no other ways to get a |
| 1942 |
script to run under --safe mode. |
| 1943 |
|
| 1944 |
<a name="testing_mode"></a> |
| 1945 |
|
| 1946 |
</p><h2 id="the_unsafe_testing_command_line_option"><span>23.2. </span>The --unsafe-testing command-line option</h2> |
| 1947 |
|
| 1948 |
<p>The --unsafe-testing command-line option enables features of the CLI |
| 1949 |
that are intended for internal testing only. The --unsafe-testing option |
| 1950 |
disables defenses that are built into SQLite. Examples of |
| 1951 |
that are disabled defenses include <a href="c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive">SQLITE_DBCONFIG_DEFENSIVE</a> and |
| 1952 |
<a href="c3ref/c_dbconfig_defensive.html#sqlitedbconfigtrustedschema">SQLITE_DBCONFIG_TRUSTED_SCHEMA</a>. |
| 1953 |
The --unsafe-testing option also enables features that, if misused, might |
| 1954 |
cause database corruption, memory errors, or |
| 1955 |
similar problems in the CLI itself or in the SQLite library. |
| 1956 |
Example of features that --unsafe-testing enables include |
| 1957 |
the <a href="imposter.html#dotimposter">.imposter dot-command</a> and <a href="c3ref/c_testctrl_always.html">SQLITE_TESTCTRL_ASSERT</a>. |
| 1958 |
</p><p> |
| 1959 |
Misbehavior which requires use of the --unsafe-testing option |
| 1960 |
will generally not be considered a bug. |
| 1961 |
|
| 1962 |
</p><h2 id="the_no_utf8_and_utf8_command_line_options"><span>23.3. </span>The --no-utf8 and --utf8 command-line options</h2> |
| 1963 |
|
| 1964 |
<p>On the Windows platform, when the console is used for input or output, |
| 1965 |
translation is required between character encoding available from or sent to |
| 1966 |
the console and the CLI's internal, UTF-8 text representation. Past versions |
| 1967 |
of the CLI accepted these options to enable or disable use of a translation |
| 1968 |
that relied upon a Windows console feature whereby it could be made to |
| 1969 |
produce or accept UTF-8 on modern versions of the OS.</p> |
| 1970 |
|
| 1971 |
<p>Present CLI versions (3.44.1 or later) do console I/O by reading or writing |
| 1972 |
UTF-16 from/to the Windows console APIs. Because this operates correctly even |
| 1973 |
on Windows versions going back to Window 2000, there is no longer any need |
| 1974 |
for these options. They are still accepted, but without effect.</p> |
| 1975 |
|
| 1976 |
<p>In all cases, non-console text I/O is UTF-8 encoded.</p> |
| 1977 |
|
| 1978 |
<p>On non-Windows platforms, these options are also ignored.</p> |
| 1979 |
|
| 1980 |
<a name="compiling"></a> |
| 1981 |
|
| 1982 |
<h1 id="compiling_the_sqlite3_program_from_sources"><span>24. </span>Compiling the sqlite3 program from sources</h1> |
| 1983 |
|
| 1984 |
<p> |
| 1985 |
To compile the command-line shell on unix systems and on Windows with MinGW, |
| 1986 |
the usual configure-make command works: |
| 1987 |
|
| 1988 |
</p><div class="codeblock"><pre>sh configure; make |
| 1989 |
</pre></div> |
| 1990 |
|
| 1991 |
<p> |
| 1992 |
The configure-make works whether you are building from the canonical sources |
| 1993 |
from the source tree, or from an amalgamated bundle. There are few |
| 1994 |
dependencies. When building from canonical sources, a working |
| 1995 |
<a href="https://www.tcl.tk/man/tcl8.3/UserCmd/tclsh.htm">tclsh</a> is required. |
| 1996 |
If using an amalgamation bundle, all the preprocessing work normally |
| 1997 |
done by tclsh will have already been carried out and only normal build |
| 1998 |
tools are required. |
| 1999 |
|
| 2000 |
</p><p> |
| 2001 |
A working <a href="https://zlib.net">zlib compression library</a> is |
| 2002 |
needed in order for the <a href="cli.html#sqlar">.archive command</a> to operate. |
| 2003 |
|
| 2004 |
</p><p> |
| 2005 |
On Windows with MSVC, use nmake with the Makefile.msc: |
| 2006 |
|
| 2007 |
</p><div class="codeblock"><pre>nmake /f Makefile.msc |
| 2008 |
</pre></div> |
| 2009 |
|
| 2010 |
<p> |
| 2011 |
For correct operation of the <a href="cli.html#sqlar">.archive command</a>, make a copy of the |
| 2012 |
<a href="https://zlib.net">zlib source code</a> into the compat/zlib subdirectory |
| 2013 |
of the source tree and compile this way: |
| 2014 |
|
| 2015 |
</p><div class="codeblock"><pre>nmake /f Makefile.msc USE_ZLIB=1 |
| 2016 |
</pre></div> |
| 2017 |
|
| 2018 |
<h2 id="_do_it_yourself_builds_"><span>24.1. </span> Do-It-Yourself Builds </h2> |
| 2019 |
|
| 2020 |
<p> |
| 2021 |
The source code to the sqlite3 command line interface is in a single |
| 2022 |
file named "shell.c". The shell.c source file is generated from other |
| 2023 |
sources, but most of the code for shell.c can be found in |
| 2024 |
<a href="https://sqlite.org/src/file/src/shell.c.in">src/shell.c.in</a>. |
| 2025 |
(Regenerate shell.c by typing "make shell.c" from the canonical source tree.) |
| 2026 |
<a href="howtocompile.html">Compile</a> the shell.c file (together |
| 2027 |
with the <a href="amalgamation.html">sqlite3 library source code</a>) to generate |
| 2028 |
the executable. For example:</p> |
| 2029 |
|
| 2030 |
<div class="codeblock"><pre>gcc -o sqlite3 shell.c sqlite3.c -ldl -lpthread -lz -lm |
| 2031 |
</pre></div> |
| 2032 |
|
| 2033 |
<p> |
| 2034 |
The following additional compile-time options are recommended in order to |
| 2035 |
provide a full-featured command-line shell: |
| 2036 |
|
| 2037 |
</p><ul> |
| 2038 |
<li> <a href="compile.html#threadsafe">-DSQLITE_THREADSAFE=0</a> |
| 2039 |
</li><li> <a href="compile.html#enable_explain_comments">-DSQLITE_ENABLE_EXPLAIN_COMMENTS</a> |
| 2040 |
</li><li> <a href="compile.html#have_zlib">-DSQLITE_HAVE_ZLIB</a> |
| 2041 |
</li><li> <a href="compile.html#introspection_pragmas">-DSQLITE_INTROSPECTION_PRAGMAS</a> |
| 2042 |
</li><li> <a href="compile.html#enable_unknown_sql_function">-DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION</a> |
| 2043 |
</li><li> <a href="compile.html#enable_stmtvtab">-DSQLITE_ENABLE_STMTVTAB</a> |
| 2044 |
</li><li> <a href="compile.html#enable_dbpage_vtab">-DSQLITE_ENABLE_DBPAGE_VTAB</a> |
| 2045 |
</li><li> <a href="compile.html#enable_dbstat_vtab">-DSQLITE_ENABLE_DBSTAT_VTAB</a> |
| 2046 |
</li><li> <a href="compile.html#enable_offset_sql_func">-DSQLITE_ENABLE_OFFSET_SQL_FUNC</a> |
| 2047 |
</li><li> <a href="compile.html#enable_json1">-DSQLITE_ENABLE_JSON1</a> |
| 2048 |
</li><li> <a href="compile.html#enable_rtree">-DSQLITE_ENABLE_RTREE</a> |
| 2049 |
</li><li> <a href="compile.html#enable_fts4">-DSQLITE_ENABLE_FTS4</a> |
| 2050 |
</li><li> <a href="compile.html#enable_fts5">-DSQLITE_ENABLE_FTS5</a> |
| 2051 |
</li></ul> |
| 2052 |
|
| 2053 |
|