xref: /minix3/external/public-domain/sqlite/dist/sqlite3.1 (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc.\"	$NetBSD: sqlite3.1,v 1.5 2012/12/21 19:26:39 njoly Exp $
2*11be35a1SLionel Sambuc.Dd December 16, 2012
3*11be35a1SLionel Sambuc.Dt SQLITE3 1
4*11be35a1SLionel Sambuc.Os
5*11be35a1SLionel Sambuc.Sh NAME
6*11be35a1SLionel Sambuc.Nm sqlite3
7*11be35a1SLionel Sambuc.Nd A command line interface for SQLite version 3
8*11be35a1SLionel Sambuc.Sh SYNOPSIS
9*11be35a1SLionel Sambuc.Nm
10*11be35a1SLionel Sambuc.Op Ar options
11*11be35a1SLionel Sambuc.Op Ar databasefile
12*11be35a1SLionel Sambuc.Op Ar SQL
13*11be35a1SLionel Sambuc.Sh DESCRIPTION
14*11be35a1SLionel Sambuc.Nm
15*11be35a1SLionel Sambucis a terminal-based front-end to the SQLite library that can evaluate
16*11be35a1SLionel Sambucqueries interactively and display the results in multiple formats.
17*11be35a1SLionel Sambuc.Nm
18*11be35a1SLionel Sambuccan also be used within shell scripts and other applications to provide
19*11be35a1SLionel Sambucbatch processing features.
20*11be35a1SLionel Sambuc.Pp
21*11be35a1SLionel SambucTo start a
22*11be35a1SLionel Sambuc.Nm
23*11be35a1SLionel Sambucinteractive session, invoke the
24*11be35a1SLionel Sambuc.Nm
25*11be35a1SLionel Sambuccommand and optionally provide the name of a database file.
26*11be35a1SLionel SambucIf the database file does not exist, it will be created.
27*11be35a1SLionel SambucIf the database file does exist, it will be opened.
28*11be35a1SLionel Sambuc.Pp
29*11be35a1SLionel SambucFor example, to create a new database file named "mydata.db", create
30*11be35a1SLionel Sambuca table named "memos" and insert a couple of records into that table:
31*11be35a1SLionel Sambuc.Bd -literal -offset indent
32*11be35a1SLionel Sambuc$ sqlite3 mydata.db
33*11be35a1SLionel SambucSQLite version 3.1.3
34*11be35a1SLionel SambucEnter ".help" for instructions
35*11be35a1SLionel Sambucsqlite> create table memos(text, priority INTEGER);
36*11be35a1SLionel Sambucsqlite> insert into memos values('deliver project description', 10);
37*11be35a1SLionel Sambucsqlite> insert into memos values('lunch with Christine', 100);
38*11be35a1SLionel Sambucsqlite> select * from memos;
39*11be35a1SLionel Sambucdeliver project description|10
40*11be35a1SLionel Sambuclunch with Christine|100
41*11be35a1SLionel Sambucsqlite>
42*11be35a1SLionel Sambuc.Ed
43*11be35a1SLionel Sambuc.Pp
44*11be35a1SLionel SambucIf no database name is supplied, the
45*11be35a1SLionel Sambuc.Em ATTACH
46*11be35a1SLionel Sambucsql command can be used
47*11be35a1SLionel Sambucto attach to existing or create new database files.
48*11be35a1SLionel Sambuc.Em ATTACH
49*11be35a1SLionel Sambuccan also be used to attach to multiple databases within the same
50*11be35a1SLionel Sambucinteractive session.
51*11be35a1SLionel SambucThis is useful for migrating data between databases,
52*11be35a1SLionel Sambucpossibly changing the schema along the way.
53*11be35a1SLionel Sambuc.Pp
54*11be35a1SLionel SambucOptionally, a SQL statement or set of SQL statements can be supplied as
55*11be35a1SLionel Sambuca single argument.
56*11be35a1SLionel SambucMultiple statements should be separated by semi-colons.
57*11be35a1SLionel Sambuc.Pp
58*11be35a1SLionel SambucFor example:
59*11be35a1SLionel Sambuc.Bd -literal -offset indent
60*11be35a1SLionel Sambuc$ sqlite3 -line mydata.db 'select * from memos where priority > 20;'
61*11be35a1SLionel Sambuc    text = lunch with Christine
62*11be35a1SLionel Sambuc    priority = 100
63*11be35a1SLionel Sambuc.Ed
64*11be35a1SLionel Sambuc.Ss SQLITE META-COMMANDS
65*11be35a1SLionel SambucThe interactive interpreter offers a set of meta-commands that can be
66*11be35a1SLionel Sambucused to control the output format, examine the currently attached
67*11be35a1SLionel Sambucdatabase files, or perform administrative operations upon the
68*11be35a1SLionel Sambucattached databases (such as rebuilding indices).
69*11be35a1SLionel SambucMeta-commands are always prefixed with a dot
70*11be35a1SLionel Sambuc.Dq \&. .
71*11be35a1SLionel Sambuc.Pp
72*11be35a1SLionel SambucA list of available meta-commands can be viewed at any time by issuing
73*11be35a1SLionel Sambucthe '.help' command.
74*11be35a1SLionel SambucFor example:
75*11be35a1SLionel Sambuc.Bd -literal -offset indent
76*11be35a1SLionel Sambucsqlite> .help
77*11be35a1SLionel Sambuc\&.databases             List names and files of attached databases
78*11be35a1SLionel Sambuc\&.dump ?TABLE? ...      Dump the database in an SQL text format
79*11be35a1SLionel Sambuc\&.echo ON|OFF           Turn command echo on or off
80*11be35a1SLionel Sambuc\&.exit                  Exit this program
81*11be35a1SLionel Sambuc\&.explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
82*11be35a1SLionel Sambuc\&.header(s) ON|OFF      Turn display of headers on or off
83*11be35a1SLionel Sambuc\&.help                  Show this message
84*11be35a1SLionel Sambuc\&.import FILE TABLE     Import data from FILE into TABLE
85*11be35a1SLionel Sambuc\&.indices TABLE         Show names of all indices on TABLE
86*11be35a1SLionel Sambuc\&.mode MODE ?TABLE?     Set output mode where MODE is one of:
87*11be35a1SLionel Sambuc                         csv      Comma-separated values
88*11be35a1SLionel Sambuc                         column   Left-aligned columns.  (See .width)
89*11be35a1SLionel Sambuc                         html     HTML <table> code
90*11be35a1SLionel Sambuc                         insert   SQL insert statements for TABLE
91*11be35a1SLionel Sambuc                         line     One value per line
92*11be35a1SLionel Sambuc                         list     Values delimited by .separator string
93*11be35a1SLionel Sambuc                         tabs     Tab-separated values
94*11be35a1SLionel Sambuc                         tcl      TCL list elements
95*11be35a1SLionel Sambuc\&.nullvalue STRING      Print STRING in place of NULL values
96*11be35a1SLionel Sambuc\&.output FILENAME       Send output to FILENAME
97*11be35a1SLionel Sambuc\&.output stdout         Send output to the screen
98*11be35a1SLionel Sambuc\&.prompt MAIN CONTINUE  Replace the standard prompts
99*11be35a1SLionel Sambuc\&.quit                  Exit this program
100*11be35a1SLionel Sambuc\&.read FILENAME         Execute SQL in FILENAME
101*11be35a1SLionel Sambuc\&.schema ?TABLE?        Show the CREATE statements
102*11be35a1SLionel Sambuc\&.separator STRING      Change separator used by output mode and .import
103*11be35a1SLionel Sambuc\&.show                  Show the current values for various settings
104*11be35a1SLionel Sambuc\&.tables ?PATTERN?      List names of tables matching a LIKE pattern
105*11be35a1SLionel Sambuc\&.timeout MS            Try opening locked tables for MS milliseconds
106*11be35a1SLionel Sambuc\&.width NUM NUM ...     Set column widths for "column" mode
107*11be35a1SLionel Sambucsqlite>
108*11be35a1SLionel Sambuc.Ed
109*11be35a1SLionel Sambuc.Sh OPTIONS
110*11be35a1SLionel Sambuc.Nm
111*11be35a1SLionel Sambuchas the following options:
112*11be35a1SLionel Sambuc.Bl -tag -width abcdefghij
113*11be35a1SLionel Sambuc.It Fl init Ar file
114*11be35a1SLionel SambucRead and execute commands from
115*11be35a1SLionel Sambuc.Ar file ,
116*11be35a1SLionel Sambucwhich can contain a mix of SQL statements and meta-commands.
117*11be35a1SLionel Sambuc.It Fl echo
118*11be35a1SLionel SambucPrint commands before execution.
119*11be35a1SLionel Sambuc.It Fl header
120*11be35a1SLionel SambucTurn headers on.
121*11be35a1SLionel Sambuc.It Fl noheader
122*11be35a1SLionel SambucTurn headers off.
123*11be35a1SLionel Sambuc.It Fl column
124*11be35a1SLionel SambucQuery results will be displayed in a table like form, using
125*11be35a1SLionel Sambucwhitespace characters to separate the columns and align the
126*11be35a1SLionel Sambucoutput.
127*11be35a1SLionel Sambuc.It Fl html
128*11be35a1SLionel SambucQuery results will be output as simple HTML tables.
129*11be35a1SLionel Sambuc.It Fl line
130*11be35a1SLionel SambucQuery results will be displayed with one value per line, rows
131*11be35a1SLionel Sambucseparated by a blank line.
132*11be35a1SLionel SambucDesigned to be easily parsed by scripts or other programs
133*11be35a1SLionel Sambuc.It Fl list
134*11be35a1SLionel SambucQuery results will be displayed with the separator (|, by default)
135*11be35a1SLionel Sambuccharacter between each field value.
136*11be35a1SLionel Sambuc.It Fl separator Ar separator
137*11be35a1SLionel SambucSet output field separator.
138*11be35a1SLionel SambucDefault is
139*11be35a1SLionel Sambuc.Dq | .
140*11be35a1SLionel Sambuc.It Fl nullvalue Ar string
141*11be35a1SLionel SambucSet
142*11be35a1SLionel Sambuc.Ar string
143*11be35a1SLionel Sambucused to represent
144*11be35a1SLionel Sambuc.Dv NULL
145*11be35a1SLionel Sambucvalues.
146*11be35a1SLionel SambucDefault is
147*11be35a1SLionel Sambuc.Dq \e
148*11be35a1SLionel Sambuc(empty string).
149*11be35a1SLionel Sambuc.It Fl version
150*11be35a1SLionel SambucShow SQLite version.
151*11be35a1SLionel Sambuc.It Fl help
152*11be35a1SLionel SambucShow help on options and exit.
153*11be35a1SLionel Sambuc.El
154*11be35a1SLionel Sambuc.Ss INIT FILE
155*11be35a1SLionel Sambuc.Nm
156*11be35a1SLionel Sambucreads an initialization file to set the configuration of the
157*11be35a1SLionel Sambucinteractive environment.
158*11be35a1SLionel SambucThroughout initialization, any previously specified setting can be overridden.
159*11be35a1SLionel SambucThe sequence of initialization is as follows:
160*11be35a1SLionel Sambuc.Bl -enum
161*11be35a1SLionel Sambuc.It
162*11be35a1SLionel SambucThe default configuration is established as follows:
163*11be35a1SLionel Sambuc.Bd -literal -offset indent
164*11be35a1SLionel Sambucmode            = LIST
165*11be35a1SLionel Sambucseparator       = "|"
166*11be35a1SLionel Sambucmain prompt     = "sqlite> "
167*11be35a1SLionel Sambuccontinue prompt = "   ...> "
168*11be35a1SLionel Sambuc.Ed
169*11be35a1SLionel Sambuc.It
170*11be35a1SLionel SambucIf the file
171*11be35a1SLionel Sambuc.Pa ~/.sqliterc
172*11be35a1SLionel Sambucexists, it is processed first.
173*11be35a1SLionel Sambuccan be found in the user's home directory, it is
174*11be35a1SLionel Sambucread and processed.
175*11be35a1SLionel SambucIt should generally only contain meta-commands.
176*11be35a1SLionel Sambuc.It
177*11be35a1SLionel SambucIf the
178*11be35a1SLionel Sambuc.Fl init
179*11be35a1SLionel Sambucoption is present, the specified file is processed.
180*11be35a1SLionel Sambuc.It
181*11be35a1SLionel SambucAll other command line options are processed.
182*11be35a1SLionel Sambuc.El
183*11be35a1SLionel Sambuc.Sh SEE ALSO
184*11be35a1SLionel Sambuc.Lk http://www.sqlite.org/
185*11be35a1SLionel Sambuc.Sh AUTHORS
186*11be35a1SLionel SambucThis manual page was originally written by Andreas Rottmann
187*11be35a1SLionel Sambuc.Aq rotty@debian.org ,
188*11be35a1SLionel Sambucfor the Debian GNU/Linux system (but may be used by others).
189*11be35a1SLionel SambucIt was subsequently revised by Bill Bumgarner
190*11be35a1SLionel Sambuc.Aq bbum@mac.com .
191