Documentation Source Text

Check-in [e540e313e6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make the "cintro.html" article more mobile-friendly.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e540e313e6c40c9072f05f4bfb734ef87c033b1e
User & Date: drh 2016-09-12 17:29:38
Context
2016-09-12
17:49
Minor wording improvements in the application file format document. check-in: 511e39cbb5 user: drh tags: trunk
17:29
Make the "cintro.html" article more mobile-friendly. check-in: e540e313e6 user: drh tags: trunk
16:22
Updates to the "docs.html" page so that it uses the same <ul>-style format on desktop as it does on mobile, except that the detailed document descriptions are shown on desktop while still omitted on mobile. check-in: 572767e60b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pages/cintro.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270
<title>An Introduction To The SQLite C/C++ Interface</title>
<table_of_contents>
<tcl>
set level(0) 0
set level(1) 0
proc HEADING {n name {tag {}}} {
  if {$tag!=""} {
    hd_fragment $tag
  }
  global level
  incr level($n)
  for {set i [expr {$n+1}]} {$i<10} {incr i} {
    set level($i) 0
  }
  if {$n==0} {
    hd_puts "<h1 align=center>$name</h1>"
    return
  } elseif {$n==1} {
    set num $level(1).0
  } else {
    set num $level(1)
    for {set i 2} {$i<=$n} {incr i} {
      append num .$level($i)
    }
  }
  incr n 1
  hd_puts "<h$n>$num $name</h$n>"
}

hd_keywords {*cintro}
</tcl>



<h1>Summary</h1>

<p>The following two objects and eight methods comprise the essential
elements of the SQLite interface:

<table border="0" cellpadding="0">
<tr>
<td valign="top"><b>[sqlite3]</b></td><td>&nbsp;&nbsp;&nbsp;</td>
<td>The database connection object.  Created by
[sqlite3_open()] and destroyed by [sqlite3_close()].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_stmt]</b></td><td>
<td>The prepared statement object.  Created by
[sqlite3_prepare()] and destroyed by [sqlite3_finalize()].</td>
</tr>

<tr>

<td valign="top"><b>[sqlite3_open()]</b></td><td>
<td>Open a connection to a new or existing SQLite database.
The constructor for [sqlite3].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_prepare()]</b></td><td>
<td>Compile SQL text into
byte-code that will do the work of querying or updating the database. 
The constructor for [sqlite3_stmt].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_bind_int|sqlite3_bind()]</td><td>
<td>Store application data into
[parameters] of the original SQL.</td>
</tr>

<tr>

<td valign="top"><b>[sqlite3_step()]</td><td>
<td>Advance an [sqlite3_stmt] to the next result row or to completion.</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_column_int|sqlite3_column()]</td><td>
<td>Column values in the current result row for an [sqlite3_stmt].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_finalize()]</td><td>
<td>Destructor for [sqlite3_stmt].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_close()]</td><td>
<td>Destructor for [sqlite3].</td>
</tr>

<tr>
<td valign="top"><b>[sqlite3_exec()]</td><td>
<td>A wrapper function that does [sqlite3_prepare()], [sqlite3_step()],
[sqlite3_column_int|sqlite3_column()], and [sqlite3_finalize()] for
a string of one or more SQL statements.</td>
</tr>
</table>

<h1>Introduction</h1>

<p>
  SQLite currently has over 200 distinct APIs.
  This can be overwhelming to a new programmer.
  Fortunately, most of the interfaces are very specialized
................................................................................
  data in various datatypes.
</p>

<p>
  Here is a summary of what the core interfaces do:
</p>

<table border="0" cellspacing="15">

<tr><td valign="top" align="right">[sqlite3_open()]</td>
<td valign="top">
  This routine 
  opens a connection to an SQLite database file and returns a
  [database connection] object.  This is often the first SQLite API
  call that an application makes and is a prerequisite for most other
  SQLite APIs.  Many SQLite interfaces require a pointer to
  the [database connection] object as their first parameter and can
  be thought of as methods on the [database connection] object.
  This routine is the constructor for the [database connection] object.
</td>

<tr><td valign="top" align="right">[sqlite3_prepare()]</td>
<td valign="top">
  This routine
  converts SQL text into a [prepared statement] object and returns a pointer
  to that object.  This interface requires a [database connection] pointer
  created by a prior call to [sqlite3_open()] and a text string containing
  the SQL statement to be prepared.  This API does not actually evaluate
  the SQL statement.  It merely prepares the SQL statement for evaluation.

................................................................................
  The [prepared statement] is the object code.  The [sqlite3_step()] interface
  then runs the object code to get a result.

  <p>New applications should always invoke [sqlite3_prepare_v2()] instead
  of [sqlite3_prepare()].  The older [sqlite3_prepare()] is retained for
  backwards compatibility.  But [sqlite3_prepare_v2()] provides a much
  better interface.</p>
</td>

<tr><td valign="top" align="right">[sqlite3_step()]</td>
<td valign="top">

  This routine is used to evaluate a [prepared statement] that has been
  previously created by the [sqlite3_prepare()] interface.  The statement
  is evaluated up to the point where the first row of results are available.
  To advance to the second row of results, invoke [sqlite3_step()] again.
  Continue invoking [sqlite3_step()] until the statement is complete.
  Statements that do not return results (ex: INSERT, UPDATE, or DELETE
  statements) run to completion on a single call to [sqlite3_step()].
</td>


<tr><td valign="top" align="right">[sqlite3_column_int | sqlite3_column()]</td>
<td valign="top">

  This routine returns a single column from the current row of a result
  set for a [prepared statement] that is being evaluated by [sqlite3_step()].
  Each time [sqlite3_step()] stops with a new result set row, this routine
  can be called multiple times to find the values of all columns in that row.
  
  <p>As noted above, there really is no such thing as a "sqlite3_column()"
  function in the SQLite API.  Instead, what we here call "sqlite3_column()"
................................................................................
    <li> [sqlite3_column_text()] </li>
    <li> [sqlite3_column_text16()] </li>
    <li> [sqlite3_column_type()] </li>
    <li> [sqlite3_column_value()] </li>
  </ul></p>
</td>

<tr><td valign="top" align="right">[sqlite3_finalize()]</td>
<td valign="top">
  This routine destroys a [prepared statement] created by a prior call
  to [sqlite3_prepare()].  Every prepared statement must be destroyed using
  a call to this routine in order to avoid memory leaks.
</td>

<tr><td valign="top" align="right">[sqlite3_close()]</td>
<td valign="top">

  This routine closes a [database connection] previously opened by a call
  to [sqlite3_open()].  All [prepared statements] associated with the
  connection should be [sqlite3_finalize | finalized] prior to closing the
  connection.
</td>

</table>

<h1>Typical Usage Of Core Routines And Objects</h1>

<p>
  An application will typically use
  [sqlite3_open()] to create a single [database connection]
  during initialization.



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


>
>






|
<
|
|
|
<

<
|
|
|
<

<
>
|
|
|
<

<
|
|

|
<

<
|
|
|
<

<
>
|
|
<

<
|
|
<

<
|
|
<

<
|
|
<

<
|
|

|
|
<







 







|

|
|








|

|
|







 







<

|
<
>







<

<
|
<
>







 







|
|



<

|
<
>




|
<
<







1
2
3


























4
5
6
7
8
9
10
11
12
13
14

15
16
17

18

19
20
21

22

23
24
25
26

27

28
29
30
31

32

33
34
35

36

37
38
39

40

41
42

43

44
45

46

47
48

49

50
51
52
53
54

55
56
57
58
59
60
61
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
156
157
158
159
160
161
162

163
164

165
166
167
168
169
170
171
172

173

174

175
176
177
178
179
180
181
182
...
196
197
198
199
200
201
202
203
204
205
206
207

208
209

210
211
212
213
214
215


216
217
218
219
220
221
222
<title>An Introduction To The SQLite C/C++ Interface</title>
<table_of_contents>
<tcl>


























hd_keywords {*cintro}
</tcl>

<table_of_contents>

<h1>Summary</h1>

<p>The following two objects and eight methods comprise the essential
elements of the SQLite interface:

<ul>

<li><p><b>[sqlite3]</b> &rarr;
The database connection object.  Created by
[sqlite3_open()] and destroyed by [sqlite3_close()].



<li><p><b>[sqlite3_stmt]</b> &rarr;
The prepared statement object.  Created by
[sqlite3_prepare()] and destroyed by [sqlite3_finalize()].




<li><p><b>[sqlite3_open()]</b> &rarr;
Open a connection to a new or existing SQLite database.
The constructor for [sqlite3].



<li><p><b>[sqlite3_prepare()]</b> &rarr;
Compile SQL text into
byte-code that will do the work of querying or updating the database. 
The constructor for [sqlite3_stmt].



<li><p><b>[sqlite3_bind_int|sqlite3_bind()]</b> &rarr;
Store application data into
[parameters] of the original SQL.




<li><p><b>[sqlite3_step()]</b> &rarr;
Advance an [sqlite3_stmt] to the next result row or to completion.



<li><p><b>[sqlite3_column_int|sqlite3_column()]</b> &rarr;
Column values in the current result row for an [sqlite3_stmt].



<li><p><b>[sqlite3_finalize()]</b> &rarr;
Destructor for [sqlite3_stmt].



<li><p><b>[sqlite3_close()]</b> &rarr;
Destructor for [sqlite3].



<li><p><b>[sqlite3_exec()]</b> &rarr;
A wrapper function that does [sqlite3_prepare()], [sqlite3_step()],
[sqlite3_column_int|sqlite3_column()], and [sqlite3_finalize()] for
a string of one or more SQL statements.
</ul>


<h1>Introduction</h1>

<p>
  SQLite currently has over 200 distinct APIs.
  This can be overwhelming to a new programmer.
  Fortunately, most of the interfaces are very specialized
................................................................................
  data in various datatypes.
</p>

<p>
  Here is a summary of what the core interfaces do:
</p>

<ul>

<li><p><b>[sqlite3_open()]</b>
<p>
  This routine 
  opens a connection to an SQLite database file and returns a
  [database connection] object.  This is often the first SQLite API
  call that an application makes and is a prerequisite for most other
  SQLite APIs.  Many SQLite interfaces require a pointer to
  the [database connection] object as their first parameter and can
  be thought of as methods on the [database connection] object.
  This routine is the constructor for the [database connection] object.
</p>

<li><p><b>[sqlite3_prepare()]</b>
<p>
  This routine
  converts SQL text into a [prepared statement] object and returns a pointer
  to that object.  This interface requires a [database connection] pointer
  created by a prior call to [sqlite3_open()] and a text string containing
  the SQL statement to be prepared.  This API does not actually evaluate
  the SQL statement.  It merely prepares the SQL statement for evaluation.

................................................................................
  The [prepared statement] is the object code.  The [sqlite3_step()] interface
  then runs the object code to get a result.

  <p>New applications should always invoke [sqlite3_prepare_v2()] instead
  of [sqlite3_prepare()].  The older [sqlite3_prepare()] is retained for
  backwards compatibility.  But [sqlite3_prepare_v2()] provides a much
  better interface.</p>


<li><p><b>[sqlite3_step()]</b>

<p>
  This routine is used to evaluate a [prepared statement] that has been
  previously created by the [sqlite3_prepare()] interface.  The statement
  is evaluated up to the point where the first row of results are available.
  To advance to the second row of results, invoke [sqlite3_step()] again.
  Continue invoking [sqlite3_step()] until the statement is complete.
  Statements that do not return results (ex: INSERT, UPDATE, or DELETE
  statements) run to completion on a single call to [sqlite3_step()].



<li><p><b>[sqlite3_column_int | sqlite3_column()]</b>

<p>
  This routine returns a single column from the current row of a result
  set for a [prepared statement] that is being evaluated by [sqlite3_step()].
  Each time [sqlite3_step()] stops with a new result set row, this routine
  can be called multiple times to find the values of all columns in that row.
  
  <p>As noted above, there really is no such thing as a "sqlite3_column()"
  function in the SQLite API.  Instead, what we here call "sqlite3_column()"
................................................................................
    <li> [sqlite3_column_text()] </li>
    <li> [sqlite3_column_text16()] </li>
    <li> [sqlite3_column_type()] </li>
    <li> [sqlite3_column_value()] </li>
  </ul></p>
</td>

<li><p><b>[sqlite3_finalize()]</b>
<p>
  This routine destroys a [prepared statement] created by a prior call
  to [sqlite3_prepare()].  Every prepared statement must be destroyed using
  a call to this routine in order to avoid memory leaks.


<li><p><b>[sqlite3_close()]</b>

<p>
  This routine closes a [database connection] previously opened by a call
  to [sqlite3_open()].  All [prepared statements] associated with the
  connection should be [sqlite3_finalize | finalized] prior to closing the
  connection.
</ul>



<h1>Typical Usage Of Core Routines And Objects</h1>

<p>
  An application will typically use
  [sqlite3_open()] to create a single [database connection]
  during initialization.