diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl | 1006 |
1 files changed, 1006 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl b/libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl new file mode 100644 index 0000000..cb488e7 --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/www/34to35.tcl | |||
@@ -0,0 +1,1006 @@ | |||
1 | # | ||
2 | # Run this TCL script to generate HTML for the goals.html file. | ||
3 | # | ||
4 | set rcsid {$Id: 34to35.tcl,v 1.4 2007/10/01 13:54:11 drh Exp $} | ||
5 | source common.tcl | ||
6 | header {SQLite Changes From Version 3.4.2 To 3.5.0} | ||
7 | |||
8 | proc CODE {text} { | ||
9 | puts "<blockquote><pre>" | ||
10 | puts $text | ||
11 | puts "</pre></blockquote>" | ||
12 | } | ||
13 | proc SYNTAX {text} { | ||
14 | puts "<blockquote><pre>" | ||
15 | set t2 [string map {& & < < > >} $text] | ||
16 | regsub -all "/(\[^\n/\]+)/" $t2 {</b><i>\1</i><b>} t3 | ||
17 | puts "<b>$t3</b>" | ||
18 | puts "</pre></blockquote>" | ||
19 | } | ||
20 | proc IMAGE {name {caption {}}} { | ||
21 | puts "<center><img src=\"$name\">" | ||
22 | if {$caption!=""} { | ||
23 | puts "<br>$caption" | ||
24 | } | ||
25 | puts "</center>" | ||
26 | } | ||
27 | proc PARAGRAPH {text} { | ||
28 | # regsub -all "/(\[a-zA-Z0-9\]+)/" $text {<i>\1</i>} t2 | ||
29 | #regsub -all "\\*(\[^\n*\]+)\\*" $text {<tt><b><big>\1</big></b></tt>} t3 | ||
30 | regsub -all {\[([^]\n]+)\]} $text {[resolve_link \1]} t3 | ||
31 | puts "<p>[subst -novar -noback $t3]</p>\n" | ||
32 | } | ||
33 | proc resolve_link {args} { | ||
34 | set a2 [split $args |] | ||
35 | set id [string trim [lindex $a2 0]] | ||
36 | if {[lindex $a2 1]==""} { | ||
37 | set display [string trim [lindex $a2 0]] | ||
38 | } else { | ||
39 | set display [string trim [lrange $a2 1 end]] | ||
40 | } | ||
41 | regsub -all {[^a-zA-Z0-9_]} $id {} id | ||
42 | return "<a href=\"capi3ref.html#$id\">$display</a>" | ||
43 | } | ||
44 | set level(0) 0 | ||
45 | set level(1) 0 | ||
46 | proc HEADING {n name {tag {}}} { | ||
47 | if {$tag!=""} { | ||
48 | puts "<a name=\"$tag\">" | ||
49 | } | ||
50 | global level | ||
51 | incr level($n) | ||
52 | for {set i [expr {$n+1}]} {$i<10} {incr i} { | ||
53 | set level($i) 0 | ||
54 | } | ||
55 | if {$n==0} { | ||
56 | set num {} | ||
57 | } elseif {$n==1} { | ||
58 | set num $level(1).0 | ||
59 | } else { | ||
60 | set num $level(1) | ||
61 | for {set i 2} {$i<=$n} {incr i} { | ||
62 | append num .$level($i) | ||
63 | } | ||
64 | } | ||
65 | incr n 1 | ||
66 | puts "<h$n>$num $name</h$n>" | ||
67 | } | ||
68 | |||
69 | HEADING 0 {Moving From SQLite 3.4.2 to 3.5.0} | ||
70 | |||
71 | PARAGRAPH { | ||
72 | SQLite version 3.5.0 introduces a new OS interface layer that | ||
73 | is incompatible with all prior versions of SQLite. In addition, | ||
74 | a few existing interfaces have been generalized to work across all | ||
75 | database connections within a process rather than just all | ||
76 | connections within a thread. The purpose of this article | ||
77 | is to describe the changes to 3.5.0 in detail so that users | ||
78 | of prior versions of SQLite can judge what, if any, effort will | ||
79 | be required to upgrade to newer versions. | ||
80 | } | ||
81 | |||
82 | HEADING 1 {Overview Of Changes} | ||
83 | |||
84 | PARAGRAPH { | ||
85 | A quick enumeration of the changes in SQLite version 3.5.0 | ||
86 | is provide here. Subsequent sections will describe these | ||
87 | changes in more detail. | ||
88 | } | ||
89 | PARAGRAPH { | ||
90 | <ol> | ||
91 | <li>The OS interface layer has been completely reworked: | ||
92 | <ol type="a"> | ||
93 | <li>The undocumented <b>sqlite3_os_switch()</b> interface has | ||
94 | been removed.</li> | ||
95 | <li>The <b>SQLITE_ENABLE_REDEF_IO</b> compile-time flag no longer functions. | ||
96 | I/O procedures are now always redefinable.</li> | ||
97 | <li>Three new objects are defined for specifying I/O procedures: | ||
98 | [sqlite3_vfs], [sqlite3_file], and [sqlite3_io_methods].</li> | ||
99 | <li>Three new interfaces are used to create alternative OS interfaces: | ||
100 | [sqlite3_vfs_register()], [sqlite3_vfs_unregister()], and | ||
101 | [sqlite3_vfs_find()].</li> | ||
102 | <li>A new interface has been added to provided additional control over | ||
103 | the creation of new database connections: [sqlite3_open_v2()]. | ||
104 | The legacy interfaces of [sqlite3_open()] and | ||
105 | [sqlite3_open16()] continue to be fully supported.</li> | ||
106 | </ol></li> | ||
107 | <li>The optional shared cache and memory management features that | ||
108 | were introduced in version 3.3.0 can now be used across multiple | ||
109 | threads within the same process. Formerly, these extensions only | ||
110 | applied to database connections operating within a single thread. | ||
111 | <ol type="a"> | ||
112 | <li>The [sqlite3_enable_shared_cache()] interface now applies to all | ||
113 | threads within a process, not to just the one thread in which it | ||
114 | was run.</li> | ||
115 | <li>The [sqlite3_soft_heap_limit()] interface now applies to all threads | ||
116 | within a process, not to just the one thread in which it was run.</li> | ||
117 | <li>The [sqlite3_release_memory()] interface will now attempt to reduce | ||
118 | the memory usages across all database connections in all threads, not | ||
119 | just connections in the thread where the interface is called.</li> | ||
120 | <li>The [sqlite3_thread_cleanup()] interface has become a no-op.</li> | ||
121 | </ol></li> | ||
122 | <li>Restrictions on the use of the same database connection by multiple | ||
123 | threads have been dropped. It is now safe for | ||
124 | multiple threads to use the same database connection at the same | ||
125 | time.</li> | ||
126 | <li>There is now a compile-time option that allows an application to | ||
127 | define alternative malloc()/free() implementations without having | ||
128 | to modify any core SQLite code.</li> | ||
129 | <li>There is now a compile-time option that allows an application to | ||
130 | define alternative mutex implementations without having | ||
131 | to modify any core SQLite code.</li> | ||
132 | </ol> | ||
133 | } | ||
134 | PARAGRAPH { | ||
135 | Of these changes, only 1a and 2a through 2c are incompatibilities | ||
136 | in any formal sense. | ||
137 | But users who have previously made custom modifications to the | ||
138 | SQLite source (for example to add a custom OS layer for embedded | ||
139 | hardware) might find that these changes have a larger impact. | ||
140 | On the other hand, an important goal of these changes is to make | ||
141 | it much easier to customize SQLite for use on different operating | ||
142 | systems. | ||
143 | } | ||
144 | |||
145 | HEADING 1 {The OS Interface Layer} | ||
146 | |||
147 | PARAGRAPH { | ||
148 | If your system defines a custom OS interface for SQLite or if you | ||
149 | were using the undocumented <b>sqlite3_os_switch()</b> | ||
150 | interface, then you will need to make modifications in order to | ||
151 | upgrade to SQLite version 3.5.0. This may seem painful at first | ||
152 | glance. But as you look more closely, you will probably discover | ||
153 | that your changes are made smaller and easier to understand and manage | ||
154 | by the new SQLite interface. It is likely that your changes will | ||
155 | now also work seamlessly with the SQLite amalgamation. You will | ||
156 | no longer need to make any changes to the code SQLite source code. | ||
157 | All of your changes can be effected by application code and you can | ||
158 | link against a standard, unmodified version of the SQLite amalgamation. | ||
159 | Furthermore, the OS interface layer, which was formerly undocumented, | ||
160 | is now an officially support interface for SQLite. So you have | ||
161 | some assurance that this will be a one-time change and that your | ||
162 | new backend will continue to work in future versions of SQLite. | ||
163 | } | ||
164 | |||
165 | HEADING 2 {The Virtual File System Object} | ||
166 | |||
167 | PARAGRAPH { | ||
168 | The new OS interface for SQLite is built around an object named | ||
169 | [sqlite3_vfs]. The "vfs" standard for "Virtual File System". | ||
170 | The sqlite3_vfs object is basically a structure containing pointers | ||
171 | to functions that implement the primitive disk I/O operations that | ||
172 | SQLite needs to perform in order to read and write databases. | ||
173 | In this article, we will often refer a sqlite3_vfs objects as a "VFS". | ||
174 | } | ||
175 | |||
176 | PARAGRAPH { | ||
177 | SQLite is able to use multiple VFSes at the same time. Each | ||
178 | individual database connection is associated with just one VFS. | ||
179 | But if you have multiple database connections, each connection | ||
180 | can be associated with a different VFS. | ||
181 | } | ||
182 | |||
183 | PARAGRAPH { | ||
184 | There is always a default VFS. | ||
185 | The legacy interfaces [sqlite3_open()] and [sqlite3_open16()] always | ||
186 | use the default VFS. | ||
187 | The new interface for creating database connections, | ||
188 | [sqlite3_open_v2()], allows you to specify which VFS you want to | ||
189 | use by name. | ||
190 | } | ||
191 | |||
192 | HEADING 3 {Registering New VFS Objects} | ||
193 | |||
194 | PARAGRAPH { | ||
195 | Standard builds of SQLite for unix or windows come with a single | ||
196 | VFS named "unix" or "win32", as appropriate. This one VFS is also | ||
197 | the default. So if you are using the legacy open functions, everything | ||
198 | will continue to operate as it has before. The change is that an application | ||
199 | now has the flexibility of adding new VFS modules to implement a | ||
200 | customized OS layer. The [sqlite3_vfs_register()] API can be used | ||
201 | to tell SQLite about one or more application-defined VFS modules: | ||
202 | } | ||
203 | |||
204 | CODE { | ||
205 | int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); | ||
206 | } | ||
207 | |||
208 | PARAGRAPH { | ||
209 | Applications can call sqlite3_vfs_register at any time, though of course | ||
210 | a VFS needs to be registered before it can be used. The first argument | ||
211 | is a pointer to a customized VFS object that the application has prepared. | ||
212 | The second argument is true to make the new VFS the default VFS so that | ||
213 | it will be used by the legacy [sqlite3_open()] and [sqlite3_open16()] APIs. | ||
214 | If the new VFS is not the default, then you will probably have to use | ||
215 | the new [sqlite3_open_v2()] API to use it. Note, however, that if | ||
216 | a new VFS is the only VFS known to SQLite (if SQLite was compiled without | ||
217 | its usual default VFS or if the pre-compiled default VFS was removed | ||
218 | using [sqlite3_vfs_unregister()]) then the new VFS automatic becomes the | ||
219 | default VFS regardless of the makeDflt argument to [sqlite3_vfs_register()]. | ||
220 | } | ||
221 | |||
222 | PARAGRAPH { | ||
223 | Standard builds include the default "unix" or "win32" VFSes. | ||
224 | But if you use the -DOS_OTHER=1 compile-time option, then SQLite is | ||
225 | built without a default VFS. In that case, the application must | ||
226 | register at least one VFS prior to calling [sqlite3_open()]. | ||
227 | This is the approach that embedded applications should use. | ||
228 | Rather than modifying the SQLite source to to insert an alternative | ||
229 | OS layer as was done in prior releases of SQLite, instead compile | ||
230 | an unmodified SQLite source file (preferably the amalgamation) | ||
231 | with the -DOS_OTHER=1 option, then invoke [sqlite3_vfs_register()] | ||
232 | to define the interface to the underlying filesystem prior to | ||
233 | creating any database connections. | ||
234 | } | ||
235 | |||
236 | HEADING 3 {Additional Control Over VFS Objects} | ||
237 | |||
238 | PARAGRAPH { | ||
239 | The [sqlite3_vfs_unregister()] API is used to remove an existing | ||
240 | VFS from the system. | ||
241 | } | ||
242 | |||
243 | CODE { | ||
244 | int sqlite3_vfs_unregister(sqlite3_vfs*); | ||
245 | } | ||
246 | |||
247 | PARAGRAPH { | ||
248 | The [sqlite3_vfs_find()] API is used to locate a particular VFS | ||
249 | by name. Its prototype is as follows: | ||
250 | } | ||
251 | |||
252 | CODE { | ||
253 | sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); | ||
254 | } | ||
255 | |||
256 | PARAGRAPH { | ||
257 | The argument is the symbolic name for the desired VFS. If the | ||
258 | argument is a NULL pointer, then the default VFS is returned. | ||
259 | The function returns a pointer to the [sqlite3_vfs] object that | ||
260 | implements the VFS. Or it returns a NULL pointer if no object | ||
261 | could be found that matched the search criteria. | ||
262 | } | ||
263 | |||
264 | HEADING 3 {Modifications Of Existing VFSes} | ||
265 | |||
266 | PARAGRAPH { | ||
267 | Once a VFS has been registered, it should never be modified. If | ||
268 | a change in behavior is required, a new VFS should be registered. | ||
269 | The application could, perhaps, use [sqlite3_vfs_find()] to locate | ||
270 | the old VFS, make a copy of the old VFS into a new [sqlite3_vfs] | ||
271 | object, make the desired modifications to the new VFS, unregister | ||
272 | the old VFS, the register the new VFS in its place. Existing | ||
273 | database connections would continue to use the old VFS even after | ||
274 | it is unregistered, but new database connections would use the | ||
275 | new VFS. | ||
276 | } | ||
277 | |||
278 | HEADING 3 {The VFS Object} | ||
279 | |||
280 | PARAGRAPH { | ||
281 | A VFS object is an instance of the following structure: | ||
282 | } | ||
283 | |||
284 | CODE { | ||
285 | typedef struct sqlite3_vfs sqlite3_vfs; | ||
286 | struct sqlite3_vfs { | ||
287 | int iVersion; /* Structure version number */ | ||
288 | int szOsFile; /* Size of subclassed sqlite3_file */ | ||
289 | int mxPathname; /* Maximum file pathname length */ | ||
290 | sqlite3_vfs *pNext; /* Next registered VFS */ | ||
291 | const char *zName; /* Name of this virtual file system */ | ||
292 | void *pAppData; /* Pointer to application-specific data */ | ||
293 | int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, | ||
294 | int flags, int *pOutFlags); | ||
295 | int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); | ||
296 | int (*xAccess)(sqlite3_vfs*, const char *zName, int flags); | ||
297 | int (*xGetTempName)(sqlite3_vfs*, char *zOut); | ||
298 | int (*xFullPathname)(sqlite3_vfs*, const char *zName, char *zOut); | ||
299 | void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); | ||
300 | void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); | ||
301 | void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol); | ||
302 | void (*xDlClose)(sqlite3_vfs*, void*); | ||
303 | int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); | ||
304 | int (*xSleep)(sqlite3_vfs*, int microseconds); | ||
305 | int (*xCurrentTime)(sqlite3_vfs*, double*); | ||
306 | /* New fields may be appended in figure versions. The iVersion | ||
307 | ** value will increment whenever this happens. */ | ||
308 | }; | ||
309 | } | ||
310 | |||
311 | PARAGRAPH { | ||
312 | To create a new VFS, an application fills in an instance of this | ||
313 | structure with appropriate values and then calls [sqlite3_vfs_register()]. | ||
314 | } | ||
315 | |||
316 | PARAGRAPH { | ||
317 | The iVersion field of [sqlite3_vfs] should be 1 for SQLite version 3.5.0. | ||
318 | This number may increase in future versions of SQLite if we have to | ||
319 | modify the VFS object in some way. We hope that this never happens, | ||
320 | but the provision is made in case it does. | ||
321 | } | ||
322 | |||
323 | PARAGRAPH { | ||
324 | The szOsFile field is the size in bytes of the structure that defines | ||
325 | an open file: the [sqlite3_file] object. This object will be described | ||
326 | more fully below. The point here is that each VFS implementation can | ||
327 | define its own [sqlite3_file] object containing whatever information | ||
328 | the VFS implementation needs to store about an open file. SQLite needs | ||
329 | to know how big this object is, however, in order to preallocate enough | ||
330 | space to hold it. | ||
331 | } | ||
332 | |||
333 | PARAGRAPH { | ||
334 | The mxPathname field is the maximum length of a file pathname that | ||
335 | this VFS can use. SQLite sometimes has to preallocate buffers of | ||
336 | this size, so it should be as small as reasonably possible. Some | ||
337 | filesystems permit huge pathnames, but in practice pathnames rarely | ||
338 | extend beyond 100 bytes or so. You do not have to put the longest | ||
339 | pathname that the underlying filesystem can handle here. You only | ||
340 | have to put the longest pathname that you want SQLite to be able to | ||
341 | handle. A few hundred is a good value in most cases. | ||
342 | } | ||
343 | |||
344 | PARAGRAPH { | ||
345 | The pNext field is used internally by SQLite. Specifically, SQLite | ||
346 | uses this field to form a linked list of registered VFSes. | ||
347 | } | ||
348 | |||
349 | PARAGRAPH { | ||
350 | The zName field is the symbolic name of the VFS. This is the name | ||
351 | that the [sqlite3_vfs_find()] compares against when it is looking for | ||
352 | a VFS. | ||
353 | } | ||
354 | |||
355 | PARAGRAPH { | ||
356 | The pAppData pointer is unused by the SQLite core. The pointer is | ||
357 | available to store auxiliary information that a VFS information might | ||
358 | want to carry around. | ||
359 | } | ||
360 | |||
361 | PARAGRAPH { | ||
362 | The remaining fields of the [sqlite3_vfs] object all store pointer | ||
363 | to functions that implement primitive operations. We call these | ||
364 | "methods". The first methods, xOpen, is used to open files on | ||
365 | the underlying storage media. The result is an [sqlite3_file] | ||
366 | object. There are additional methods, defined by the [sqlite3_file] | ||
367 | object itself that are used to read and write and close the file. | ||
368 | The additional methods are detailed below. The filename is in UTF-8. | ||
369 | SQLite will guarantee that the zFilename string passed to | ||
370 | xOpen() is a full pathname as generated by xFullPathname() and | ||
371 | that the string will be valid and unchanged until xClose() is | ||
372 | called. So the [sqlite3_file] can store a pointer to the | ||
373 | filename if it needs to remember the filename for some reason. | ||
374 | The flags argument to xOpen() is a copy of the flags argument | ||
375 | to sqlite3_open_v2(). If sqlite3_open() or sqlite3_open16() | ||
376 | is used, then flags is [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. | ||
377 | If xOpen() opens a file read-only then it sets *pOutFlags to | ||
378 | include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be | ||
379 | set. | ||
380 | SQLite will also add one of the following flags to the xOpen() | ||
381 | call, depending on the object being opened: | ||
382 | <ul> | ||
383 | <li> [SQLITE_OPEN_MAIN_DB] | ||
384 | <li> [SQLITE_OPEN_MAIN_JOURNAL] | ||
385 | <li> [SQLITE_OPEN_TEMP_DB] | ||
386 | <li> [SQLITE_OPEN_TEMP_JOURNAL] | ||
387 | <li> [SQLITE_OPEN_TRANSIENT_DB] | ||
388 | <li> [SQLITE_OPEN_SUBJOURNAL] | ||
389 | <li> [SQLITE_OPEN_MASTER_JOURNAL] | ||
390 | </ul> | ||
391 | The file I/O implementation can use the object type flags to | ||
392 | changes the way it deals with files. For example, an application | ||
393 | that does not care about crash recovery or rollback, might make | ||
394 | the open of a journal file a no-op. Writes to this journal are | ||
395 | also a no-op. Any attempt to read the journal returns [SQLITE_IOERR]. | ||
396 | Or the implementation might recognize the a database file will | ||
397 | be doing page-aligned sector reads and writes in a random order | ||
398 | and set up its I/O subsystem accordingly. | ||
399 | SQLite might also add one of the following flags to the xOpen | ||
400 | method: | ||
401 | <ul> | ||
402 | <li> [SQLITE_OPEN_DELETEONCLOSE] | ||
403 | <li> [SQLITE_OPEN_EXCLUSIVE] | ||
404 | </ul> | ||
405 | The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be | ||
406 | deleted when it is closed. This will always be set for TEMP | ||
407 | databases and journals and for subjournals. The | ||
408 | [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened | ||
409 | for exclusive access. This flag is set for all files except | ||
410 | for the main database file. | ||
411 | The [sqlite3_file] structure passed as the third argument to | ||
412 | xOpen is allocated by the caller. xOpen just fills it in. The | ||
413 | caller allocates a minimum of szOsFile bytes for the [sqlite3_file] | ||
414 | structure. | ||
415 | } | ||
416 | |||
417 | PARAGRAPH { | ||
418 | The differences between an [SQLITE_OPEN_TEMP_DB] database and an | ||
419 | [SQLITE_OPEN_TRANSIENT_DB] database is this: The [SQLITE_OPEN_TEMP_DB] | ||
420 | is used for explicitly declared and named TEMP tables (using the | ||
421 | CREATE TEMP TABLE syntax) or for named tables in a temporary database | ||
422 | that is created by opening a database with a filename that is an empty | ||
423 | string. An [SQLITE_OPEN_TRANSIENT_DB] holds an database table that | ||
424 | SQLite creates automatically in order to evaluate a subquery or | ||
425 | ORDER BY or GROUP BY clause. Both TEMP_DB and TRANSIENT_DB databases | ||
426 | are private and are deleted automatically. TEMP_DB databases last | ||
427 | for the duration of the database connection. TRANSIENT_DB databases | ||
428 | last only for the duration of a single SQL statement. | ||
429 | } | ||
430 | |||
431 | PARAGRAPH { | ||
432 | The xDelete method is used delete a file. The name of the file is | ||
433 | given in the second parameter. The filename will be in UTF-8. | ||
434 | The VFS must convert the filename into whatever character representation | ||
435 | the underlying operating system expects. If the syncDir parameter is | ||
436 | true, then the xDelete method should not return until the change | ||
437 | to the directory contents for the directory containing the | ||
438 | deleted file have been synced to disk in order to insure that the | ||
439 | file does not "reappear" if a power failure occurs soon after. | ||
440 | } | ||
441 | |||
442 | PARAGRAPH { | ||
443 | The xAccess method is used to check for access permissions on a file. | ||
444 | The filename will be UTF-8 encoded. The flags argument will be | ||
445 | [SQLITE_ACCESS_EXISTS] to check for the existence of the file, | ||
446 | [SQLITE_ACCESS_READWRITE] to check to see if the file is both readable | ||
447 | and writable, or [SQLITE_ACCESS_READ] to check to see if the file is | ||
448 | at least readable. The "file" named by the second parameter might | ||
449 | be a directory or folder name. | ||
450 | } | ||
451 | |||
452 | PARAGRAPH { | ||
453 | The xGetTempName method computes the name of a temporary file that | ||
454 | SQLite can use. The name should be written into the buffer given | ||
455 | by the second parameter. SQLite will size that buffer to hold | ||
456 | at least mxPathname bytes. The generated filename should be in UTF-8. | ||
457 | To avoid security problems, the generated temporary filename should | ||
458 | contain enough randomness to prevent an attacker from guessing the | ||
459 | temporary filename in advance. | ||
460 | } | ||
461 | |||
462 | PARAGRAPH { | ||
463 | The xFullPathname method is used to convert a relative pathname | ||
464 | into a full pathname. The resulting full pathname is written into | ||
465 | the buffer provided by the third parameter. SQLite will size the | ||
466 | output buffer to at least mxPathname bytes. Both the input and | ||
467 | output names should be in UTF-8. | ||
468 | } | ||
469 | |||
470 | PARAGRAPH { | ||
471 | The xDlOpen, xDlError, xDlSym, and xDlClose methods are all used for | ||
472 | accessing shared libraries at run-time. These methods may be omitted | ||
473 | (and their pointers set to zero) if the library is compiled with | ||
474 | SQLITE_OMIT_LOAD_EXTENSION or if the [sqlite3_enable_load_extension()] | ||
475 | interface is never used to enable dynamic extension loading. The | ||
476 | xDlOpen method opens a shared library or DLL and returns a pointer to | ||
477 | a handle. NULL is returned if the open fails. If the open fails, | ||
478 | the xDlError method can be used to obtain a text error message. | ||
479 | The message is written into the zErrMsg buffer of the third parameter | ||
480 | which is at least nByte bytes in length. The xDlSym returns a pointer | ||
481 | to a symbol in the shared library. The name of the symbol is given | ||
482 | by the second parameter. UTF-8 encoding is assumed. If the symbol | ||
483 | is not found a NULL pointer is returned. The xDlClose routine closes | ||
484 | the shared library. | ||
485 | } | ||
486 | |||
487 | PARAGRAPH { | ||
488 | The xRandomness method is used exactly once to initialize the | ||
489 | pseudo-random number generator (PRNG) inside of SQLite. Only | ||
490 | the xRandomness method on the default VFS is used. The xRandomness | ||
491 | methods on other VFSes are never accessed by SQLite. | ||
492 | The xRandomness routine requests that nByte bytes of randomness | ||
493 | be written into zOut. The routine returns the actual number of | ||
494 | bytes of randomness obtained. The quality of the randomness so obtained | ||
495 | will determine the quality of the randomness generated by built-in | ||
496 | SQLite functions such as random() and randomblob(). SQLite also | ||
497 | uses its PRNG to generate temporary file names.. On some platforms | ||
498 | (ex: windows) SQLite assumes that temporary file names are unique | ||
499 | without actually testing for collisions, so it is important to have | ||
500 | good-quality randomness even if the random() and randomblob() | ||
501 | functions are never used. | ||
502 | } | ||
503 | |||
504 | PARAGRAPH { | ||
505 | The xSleep method is used to suspend the calling thread for at | ||
506 | least the number of microseconds given. This method is used to | ||
507 | implement the [sqlite3_sleep()] and [sqlite3_busy_timeout()] APIs. | ||
508 | In the case of [sqlite3_sleep()] the xSleep method of the default | ||
509 | VFS is always used. If the underlying system does not have a | ||
510 | microsecond resolution sleep capability, then the sleep time should | ||
511 | be rounded up. xSleep returns this rounded-up value. | ||
512 | } | ||
513 | |||
514 | PARAGRAPH { | ||
515 | The xCurrentTime method finds the current time and date and writes | ||
516 | the result as double-precision floating point value into pointer | ||
517 | provided by the second parameter. The time and date is in | ||
518 | coordinated universal time (UTC) and is a fractional julian day number. | ||
519 | } | ||
520 | |||
521 | HEADING 3 {The Open File Object} | ||
522 | |||
523 | PARAGRAPH { | ||
524 | The result of opening a file is an instance of an [sqlite3_file] object. | ||
525 | The [sqlite3_file] object is an abstract base class defined as follows: | ||
526 | } | ||
527 | |||
528 | CODE { | ||
529 | typedef struct sqlite3_file sqlite3_file; | ||
530 | struct sqlite3_file { | ||
531 | const struct sqlite3_io_methods *pMethods; | ||
532 | }; | ||
533 | } | ||
534 | |||
535 | PARAGRAPH { | ||
536 | Each VFS implementation will subclass the [sqlite3_file] by adding | ||
537 | additional fields at the end to hold whatever information the VFS | ||
538 | needs to know about an open file. It does not matter what information | ||
539 | is stored as long as the total size of the structure does not exceed | ||
540 | the szOsFile value recorded in the [sqlite3_vfs] object. | ||
541 | } | ||
542 | |||
543 | PARAGRAPH { | ||
544 | The [sqlite3_io_methods] object is a structure that contains pointers | ||
545 | to methods for reading, writing, and otherwise dealing with files. | ||
546 | This object is defined as follows: | ||
547 | } | ||
548 | |||
549 | CODE { | ||
550 | typedef struct sqlite3_io_methods sqlite3_io_methods; | ||
551 | struct sqlite3_io_methods { | ||
552 | int iVersion; | ||
553 | int (*xClose)(sqlite3_file*); | ||
554 | int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); | ||
555 | int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); | ||
556 | int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); | ||
557 | int (*xSync)(sqlite3_file*, int flags); | ||
558 | int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); | ||
559 | int (*xLock)(sqlite3_file*, int); | ||
560 | int (*xUnlock)(sqlite3_file*, int); | ||
561 | int (*xCheckReservedLock)(sqlite3_file*); | ||
562 | int (*xFileControl)(sqlite3_file*, int op, void *pArg); | ||
563 | int (*xSectorSize)(sqlite3_file*); | ||
564 | int (*xDeviceCharacteristics)(sqlite3_file*); | ||
565 | /* Additional methods may be added in future releases */ | ||
566 | }; | ||
567 | } | ||
568 | |||
569 | PARAGRAPH { | ||
570 | The iVersion field of [sqlite3_io_methods] is provided as insurance | ||
571 | against future enhancements. The iVersion value should always be | ||
572 | 1 for SQLite version 3.5. | ||
573 | } | ||
574 | |||
575 | PARAGRAPH { | ||
576 | The xClose method closes the file. The space for the [sqlite3_file] | ||
577 | structure is deallocated by the caller. But if the [sqlite3_file] | ||
578 | contains pointers to other allocated memory or resources, those | ||
579 | allocations should be released by the xClose method. | ||
580 | } | ||
581 | |||
582 | PARAGRAPH { | ||
583 | The xRead method reads iAmt bytes from the file beginning at a byte | ||
584 | offset to iOfst. The data read is stored in the pointer of the | ||
585 | second parameter. xRead returns the [SQLITE_OK] on success, | ||
586 | [SQLITE_IOERR_SHORT_READ] if it was not able to read the full number | ||
587 | of bytes because it reached end-of-file, or [SQLITE_IOERR_READ] for | ||
588 | any other error. | ||
589 | } | ||
590 | |||
591 | PARAGRAPH { | ||
592 | The xWrite method writes iAmt bytes of data from the second parameter | ||
593 | into the file beginning at an offset of iOfst bytes. If the size of | ||
594 | the file is less than iOfst bytes prior to the write, then xWrite should | ||
595 | ensure that the file is extended with zeros up to iOfst bytes prior | ||
596 | to beginning its write. xWrite continues to extends the file as | ||
597 | necessary so that the size of the file is at least iAmt+iOfst bytes | ||
598 | at the conclusion of the xWrite call. The xWrite method returns | ||
599 | [SQLITE_OK] on success. If the write cannot complete because the | ||
600 | underlying storage medium is full, then [SQLITE_FULL] is returned. | ||
601 | [SQLITE_IOERR_WRITE] should be returned for any other error. | ||
602 | } | ||
603 | |||
604 | PARAGRAPH { | ||
605 | The xTruncate method truncates a file to be nByte bytes in length. | ||
606 | If the file is already nByte bytes or less in length then this | ||
607 | method is a no-op. The xTruncate method returns [SQLITE_OK] on | ||
608 | success and [SQLITE_IOERR_TRUNCATE] if anything goes wrong. | ||
609 | } | ||
610 | |||
611 | PARAGRAPH { | ||
612 | The xSync method is used to force previously written data out of | ||
613 | operating system cache and into non-volatile memory. The second | ||
614 | parameter is usually [SQLITE_SYNC_NORMAL]. If the second parameter | ||
615 | is [SQLITE_SYNC_FULL] then the xSync method should make sure that | ||
616 | data has also been flushed through the disk controllers cache. | ||
617 | The [SQLITE_SYNC_FULL] parameter is the equivalent of the F_FULLSYNC | ||
618 | ioctl() on Mac OS X. The xSync method returns | ||
619 | [SQLITE_OK] on success and [SQLITE_IOERR_FSYNC] if anything goes wrong. | ||
620 | } | ||
621 | |||
622 | PARAGRAPH { | ||
623 | The xFileSize() method determines the current size of the file | ||
624 | in bytes and writes that value into *pSize. It returns [SQLITE_OK] | ||
625 | on success and [SQLITE_IOERR_FSTAT] if something goes wrong. | ||
626 | } | ||
627 | |||
628 | PARAGRAPH { | ||
629 | The xLock and xUnlock methods are used to set and clear file locks. | ||
630 | SQLite supports five levels of file locks, in order: | ||
631 | <ul> | ||
632 | <li> [SQLITE_LOCK_NONE] | ||
633 | <li> [SQLITE_LOCK_SHARED] | ||
634 | <li> [SQLITE_LOCK_RESERVED] | ||
635 | <li> [SQLITE_LOCK_PENDING] | ||
636 | <li> [SQLITE_LOCK_EXCLUSIVE] | ||
637 | </ul> | ||
638 | The underlying implementation can support some subset of these locking | ||
639 | levels as long as it meets the other requirements of this paragraph. | ||
640 | The locking level is specified as the second argument to both xLock | ||
641 | and xUnlock. The xLock method increases the locking level to the | ||
642 | specified locking level or higher. The xUnlock method decreases the | ||
643 | locking level to no lower than the level specified. | ||
644 | [SQLITE_LOCK_NONE] means that the file is unlocked. [SQLITE_LOCK_SHARED] | ||
645 | gives permission to read the file. Multiple database connections can | ||
646 | hold [SQLITE_LOCK_SHARED] at the same time. | ||
647 | [SQLITE_LOCK_RESERVED] is like [SQLITE_LOCK_SHARED] in that its is permission | ||
648 | to read the file. But only a single connection can hold a reserved lock | ||
649 | at any point in time. The [SQLITE_LOCK_PENDING] is also permission to | ||
650 | read the file. Other connections can continue to read the file as well, | ||
651 | but no other connection is allowed to escalate a lock from none to shared. | ||
652 | [SQLITE_LOCK_EXCLUSIVE] is permission to write on the file. Only a single | ||
653 | connection can hold an exclusive lock and no other connection can hold | ||
654 | any lock (other than "none") while one connection is hold an exclusive | ||
655 | lock. The xLock returns [SQLITE_OK] on success, [SQLITE_BUSY] if it | ||
656 | is unable to obtain the lock, or [SQLITE_IOERR_RDLOCK] if something else | ||
657 | goes wrong. The xUnlock method returns [SQLITE_OK] on success and | ||
658 | [SQLITE_IOERR_UNLOCK] for problems. | ||
659 | } | ||
660 | |||
661 | PARAGRAPH { | ||
662 | The xCheckReservedLock method checks to see if another connection or | ||
663 | another process is currently holding a reserved, pending, or exclusive | ||
664 | lock on the file. It returns true or false. | ||
665 | } | ||
666 | |||
667 | PARAGRAPH { | ||
668 | The xFileControl() method is a generic interface that allows custom | ||
669 | VFS implementations to directly control an open file using the | ||
670 | (new and experimental) | ||
671 | [sqlite3_file_control()] interface. The second "op" argument | ||
672 | is an integer opcode. The third | ||
673 | argument is a generic pointer which is intended to be a pointer | ||
674 | to a structure that may contain arguments or space in which to | ||
675 | write return values. Potential uses for xFileControl() might be | ||
676 | functions to enable blocking locks with timeouts, to change the | ||
677 | locking strategy (for example to use dot-file locks), to inquire | ||
678 | about the status of a lock, or to break stale locks. The SQLite | ||
679 | core reserves opcodes less than 100 for its own use. | ||
680 | A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. | ||
681 | Applications that define a custom xFileControl method should use opcodes | ||
682 | greater than 100 to avoid conflicts. | ||
683 | } | ||
684 | |||
685 | PARAGRAPH { | ||
686 | The xSectorSize returns the "sector size" of the underlying | ||
687 | non-volatile media. A "sector" is defined as the smallest unit of | ||
688 | storage that can be written without disturbing adjacent storage. | ||
689 | On a disk drive the "sector size" has until recently been 512 bytes, | ||
690 | though there is a push to increase this value to 4KiB. SQLite needs | ||
691 | to know the sector size so that it can write a full sector at a | ||
692 | time, and thus avoid corrupting adjacent storage space if a power | ||
693 | lose occurs in the middle of a write. | ||
694 | } | ||
695 | |||
696 | PARAGRAPH { | ||
697 | The xDeviceCharacteristics method returns an integer bit vector that | ||
698 | defines any special properties that the underlying storage medium might | ||
699 | have that SQLite can use to increase performance. The allowed return | ||
700 | is the bit-wise OR of the following values: | ||
701 | <ul> | ||
702 | <li> [SQLITE_IOCAP_ATOMIC] | ||
703 | <li> [SQLITE_IOCAP_ATOMIC512] | ||
704 | <li> [SQLITE_IOCAP_ATOMIC1K] | ||
705 | <li> [SQLITE_IOCAP_ATOMIC2K] | ||
706 | <li> [SQLITE_IOCAP_ATOMIC4K] | ||
707 | <li> [SQLITE_IOCAP_ATOMIC8K] | ||
708 | <li> [SQLITE_IOCAP_ATOMIC16K] | ||
709 | <li> [SQLITE_IOCAP_ATOMIC32K] | ||
710 | <li> [SQLITE_IOCAP_ATOMIC64K] | ||
711 | <li> [SQLITE_IOCAP_SAFE_APPEND] | ||
712 | <li> [SQLITE_IOCAP_SEQUENTIAL] | ||
713 | </ul> | ||
714 | The [SQLITE_IOCAP_ATOMIC] bit means that all writes to this device are | ||
715 | atomic in the sense that either the entire write occurs or none of it | ||
716 | occurs. The other | ||
717 | [SQLITE_IOCAP_ATOMIC | SQLITE_IOCAP_ATOMIC<i>nnn</i>] values indicate that | ||
718 | writes of aligned blocks of the indicated size are atomic. | ||
719 | [SQLITE_IOCAP_SAFE_APPEND] means that when extending a file with new | ||
720 | data, the new data is written first and then the file size is updated. | ||
721 | So if a power failure occurs, there is no chance that the file might have | ||
722 | been extended with randomness. The [SQLITE_IOCAP_SEQUENTIAL] bit means | ||
723 | that all writes occur in the order that they are issued and are not | ||
724 | reordered by the underlying file system. | ||
725 | } | ||
726 | |||
727 | HEADING 3 {Checklist For Constructing A New VFS} | ||
728 | |||
729 | PARAGRAPH { | ||
730 | The preceding paragraphs contain a lot of information. | ||
731 | To ease the task of constructing | ||
732 | a new VFS for SQLite we offer the following implementation checklist: | ||
733 | } | ||
734 | |||
735 | PARAGRAPH { | ||
736 | <ol> | ||
737 | <li> Define an appropriate subclass of the [sqlite3_file] object. | ||
738 | <li> Implement the methods required by the [sqlite3_io_methods] object. | ||
739 | <li> Create a static and | ||
740 | constant [sqlite3_io_methods] object containing pointers | ||
741 | to the methods from the previous step. | ||
742 | <li> Implement the xOpen method that opens a file and populates an | ||
743 | [sqlite3_file] object, including setting pMethods to | ||
744 | point to the [sqlite3_io_methods] object from the previous step. | ||
745 | <li> Implement the other methods required by [sqlite3_vfs]. | ||
746 | <li> Define a static (but not constant) [sqlite3_vfs] structure that | ||
747 | contains pointers to the xOpen method and the other methods and | ||
748 | which contains the appropriate values for iVersion, szOsFile, | ||
749 | mxPathname, zName, and pAppData. | ||
750 | <li> Implement a procedure that calls [sqlite3_vfs_register()] and | ||
751 | passes it a pointer to the [sqlite3_vfs] structure from the previous | ||
752 | step. This procedure is probably the only exported symbol in the | ||
753 | source file that implements your VFS. | ||
754 | </ol> | ||
755 | } | ||
756 | |||
757 | PARAGRAPH { | ||
758 | Within your application, call the procedure implemented in the last | ||
759 | step above as part of your initialization process before any | ||
760 | database connections are opened. | ||
761 | } | ||
762 | |||
763 | HEADING 1 {The Memory Allocation Subsystem} | ||
764 | |||
765 | PARAGRAPH { | ||
766 | Beginning with version 3.5, SQLite obtains all of the heap memory it | ||
767 | needs using the routines [sqlite3_malloc()], [sqlite3_free()], and | ||
768 | [sqlite3_realloc()]. These routines have existed in prior versions | ||
769 | of SQLite, but SQLite has previously bypassed these routines and used | ||
770 | its own memory allocator. This all changes in version 3.5.0. | ||
771 | } | ||
772 | |||
773 | PARAGRAPH { | ||
774 | The SQLite source tree actually contains multiple versions of the | ||
775 | memory allocator. The default high-speed version found in the | ||
776 | "mem1.c" source file is used for most builds. But if the SQLITE_MEMDEBUG | ||
777 | flag is enabled, a separate memory allocator the "mem2.c" source file | ||
778 | is used instead. The mem2.c allocator implements lots of hooks to | ||
779 | do error checking and to simulate memory allocation failures for testing | ||
780 | purposes. Both of these allocators use the malloc()/free() implementation | ||
781 | in the standard C library. | ||
782 | } | ||
783 | |||
784 | PARAGRAPH { | ||
785 | Applications are not required to use either of these standard memory | ||
786 | allocators. If SQLite is compiled with SQLITE_OMIT_MEMORY_ALLOCATION | ||
787 | then no implementation for the [sqlite3_malloc()], [sqlite3_realloc()], | ||
788 | and [sqlite3_free()] functions is provided. Instead, the application | ||
789 | that links against SQLite must provide its own implementation of these | ||
790 | functions. The application provided memory allocator is not required | ||
791 | to use the malloc()/free() implementation in the standard C library. | ||
792 | An embedded application might provide an alternative memory allocator | ||
793 | that uses memory for a fixed memory pool set aside for the exclusive | ||
794 | use of SQLite, for example. | ||
795 | } | ||
796 | |||
797 | PARAGRAPH { | ||
798 | Applications that implement their own memory allocator must provide | ||
799 | implementation for the usual three allocation functions | ||
800 | [sqlite3_malloc()], [sqlite3_realloc()], and [sqlite3_free()]. | ||
801 | And they must also implement a fourth function: | ||
802 | } | ||
803 | |||
804 | CODE { | ||
805 | int sqlite3_memory_alarm( | ||
806 | void(*xCallback)(void *pArg, sqlite3_int64 used, int N), | ||
807 | void *pArg, | ||
808 | sqlite3_int64 iThreshold | ||
809 | ); | ||
810 | } | ||
811 | |||
812 | PARAGRAPH { | ||
813 | The [sqlite3_memory_alarm] routine is used to register | ||
814 | a callback on memory allocation events. | ||
815 | This routine registers or clears a callbacks that fires when | ||
816 | the amount of memory allocated exceeds iThreshold. Only | ||
817 | a single callback can be registered at a time. Each call | ||
818 | to [sqlite3_memory_alarm()] overwrites the previous callback. | ||
819 | The callback is disabled by setting xCallback to a NULL | ||
820 | pointer. | ||
821 | } | ||
822 | |||
823 | PARAGRAPH { | ||
824 | The parameters to the callback are the pArg value, the | ||
825 | amount of memory currently in use, and the size of the | ||
826 | allocation that provoked the callback. The callback will | ||
827 | presumably invoke [sqlite3_free()] to free up memory space. | ||
828 | The callback may invoke [sqlite3_malloc()] or [sqlite3_realloc()] | ||
829 | but if it does, no additional callbacks will be invoked by | ||
830 | the recursive calls. | ||
831 | } | ||
832 | |||
833 | PARAGRAPH { | ||
834 | The [sqlite3_soft_heap_limit()] interface works by registering | ||
835 | a memory alarm at the soft heap limit and invoking | ||
836 | [sqlite3_release_memory()] in the alarm callback. Application | ||
837 | programs should not attempt to use the [sqlite3_memory_alarm()] | ||
838 | interface because doing so will interfere with the | ||
839 | [sqlite3_soft_heap_limit()] module. This interface is exposed | ||
840 | only so that applications can provide their own | ||
841 | alternative implementation when the SQLite core is | ||
842 | compiled with SQLITE_OMIT_MEMORY_ALLOCATION. | ||
843 | } | ||
844 | |||
845 | PARAGRAPH { | ||
846 | The built-in memory allocators in SQLite also provide the following | ||
847 | additional interfaces: | ||
848 | } | ||
849 | |||
850 | CODE { | ||
851 | sqlite3_int64 sqlite3_memory_used(void); | ||
852 | sqlite3_int64 sqlite3_memory_highwater(int resetFlag); | ||
853 | } | ||
854 | |||
855 | PARAGRAPH { | ||
856 | These interfaces can be used by an application to monitor how | ||
857 | much memory SQLite is using. The [sqlite3_memory_used()] routine | ||
858 | returns the number of bytes of memory currently in use and the | ||
859 | [sqlite3_memory_highwater()] returns the maximum instantaneous | ||
860 | memory usage. Neither routine includes the overhead associated | ||
861 | with the memory allocator. These routines are provided for use | ||
862 | by the application. SQLite never invokes them itself. So if | ||
863 | the application is providing its own memory allocation subsystem, | ||
864 | it can omit these interfaces if desired. | ||
865 | } | ||
866 | |||
867 | HEADING 1 {The Mutex Subsystem} | ||
868 | |||
869 | PARAGRAPH { | ||
870 | SQLite has always been threadsafe in the sense that it is safe to | ||
871 | use different SQLite database connections in different threads at the | ||
872 | same time. The constraint was that the same database connection | ||
873 | could not be used in two separate threads at once. SQLite version 3.5.0 | ||
874 | relaxes this constraint. | ||
875 | } | ||
876 | |||
877 | PARAGRAPH { | ||
878 | In order to allow multiple threads to use the same database connection | ||
879 | at the same time, SQLite must make extensive use of mutexes. And for | ||
880 | this reason a new mutex subsystem as been added. The mutex subsystem | ||
881 | as the following interface: | ||
882 | } | ||
883 | |||
884 | CODE { | ||
885 | sqlite3_mutex *sqlite3_mutex_alloc(int); | ||
886 | void sqlite3_mutex_free(sqlite3_mutex*); | ||
887 | void sqlite3_mutex_enter(sqlite3_mutex*); | ||
888 | int sqlite3_mutex_try(sqlite3_mutex*); | ||
889 | void sqlite3_mutex_leave(sqlite3_mutex*); | ||
890 | } | ||
891 | |||
892 | PARAGRAPH { | ||
893 | Though these routines exist for the use of the SQLite core, | ||
894 | application code is free to use these routines as well, if desired. | ||
895 | A mutex is an [sqlite3_mutex] object. The [sqlite3_mutex_alloc()] | ||
896 | routine allocates a new mutex object and returns a pointer to it. | ||
897 | The argument to [sqlite3_mutex_alloc()] should be | ||
898 | [SQLITE_MUTEX_FAST] or [SQLITE_MUTEX_RECURSIVE] for non-recursive | ||
899 | and recursive mutexes, respectively. If the underlying system does | ||
900 | not provide non-recursive mutexes, then a recursive mutex can be | ||
901 | substituted in that case. The argument to [sqlite3_mutex_alloc()] | ||
902 | can also be a constant designating one of several static mutexes: | ||
903 | <ul> | ||
904 | <li> [SQLITE_MUTEX_STATIC_MASTER] | ||
905 | <li> [SQLITE_MUTEX_STATIC_MEM] | ||
906 | <li> [SQLITE_MUTEX_STATIC_MEM2] | ||
907 | <li> [SQLITE_MUTEX_STATIC_PRNG] | ||
908 | <li> [SQLITE_MUTEX_STATIC_LRU] | ||
909 | </ul> | ||
910 | These static mutexes are reserved for use internally by SQLite | ||
911 | and should not be used by the application. The static mutexes | ||
912 | are all non-recursive. | ||
913 | } | ||
914 | |||
915 | PARAGRAPH { | ||
916 | The [sqlite3_mutex_free()] routine should be used to deallocate | ||
917 | a non-static mutex. If a static mutex is passed to this routine | ||
918 | then the behavior is undefined. | ||
919 | } | ||
920 | |||
921 | PARAGRAPH { | ||
922 | The [sqlite3_mutex_enter()] attempts to enter the mutex and blocks | ||
923 | if another threads is already there. [sqlite3_mutex_try()] attempts | ||
924 | to enter and returns [SQLITE_OK] on success or [SQLITE_BUSY] if another | ||
925 | thread is already there. [sqlite3_mutex_leave()] exits a mutex. | ||
926 | The mutex is held until the number of exits matches the number of | ||
927 | entrances. If [sqlite3_mutex_leave()] is called on a mutex that | ||
928 | the thread is not currently holding, then the behavior is undefined. | ||
929 | If any routine is called for a deallocated mutex, then the behavior | ||
930 | is undefined. | ||
931 | } | ||
932 | |||
933 | PARAGRAPH { | ||
934 | The SQLite source code provides multiple implementations of these | ||
935 | APIs, suitable for varying environments. If SQLite is compiled with | ||
936 | the SQLITE_THREADSAFE=0 flag then a no-op mutex implementation that | ||
937 | is fast but does no real mutual exclusion is provided. That | ||
938 | implementation is suitable for use in single-threaded applications | ||
939 | or applications that only use SQLite in a single thread. Other | ||
940 | real mutex implementations are provided based on the underlying | ||
941 | operating system. | ||
942 | } | ||
943 | |||
944 | PARAGRAPH { | ||
945 | Embedded applications may wish to provide their own mutex implementation. | ||
946 | If SQLite is compiled with the -DSQLITE_MUTEX_APPDEF=1 compile-time flag | ||
947 | then the SQLite core provides no mutex subsystem and a mutex subsystem | ||
948 | that matches the interface described above must be provided by the | ||
949 | application that links against SQLite. | ||
950 | } | ||
951 | |||
952 | HEADING 1 {Other Interface Changes} | ||
953 | |||
954 | PARAGRAPH { | ||
955 | Version 3.5.0 of SQLite changes the behavior of a few APIs in ways | ||
956 | that are technically incompatible. However, these APIs are seldom | ||
957 | used and even when they are used it is difficult to imagine a | ||
958 | scenario where the change might break something. The changes | ||
959 | actually makes these interface much more useful and powerful. | ||
960 | } | ||
961 | |||
962 | PARAGRAPH { | ||
963 | Prior to version 3.5.0, the [sqlite3_enable_shared_cache()] API | ||
964 | would enable and disable the shared cache feature for all connections | ||
965 | within a single thread - the same thread from which the | ||
966 | sqlite3_enable_shared_cache() routine was called. Database connections | ||
967 | that used the shared cache were restricted to running in the same | ||
968 | thread in which they were opened. Beginning with version 3.5.0, | ||
969 | the sqlite3_enable_shared_cache() applies to all database connections | ||
970 | in all threads within the process. Now database connections running | ||
971 | in separate threads can share a cache. And database connections that | ||
972 | use shared cache can migrate from one thread to another. | ||
973 | } | ||
974 | |||
975 | PARAGRAPH { | ||
976 | Prior to version 3.5.0 the [sqlite3_soft_heap_limit()] set an upper | ||
977 | bound on heap memory usage for all database connections within a | ||
978 | single thread. Each thread could have its own heap limit. Beginning | ||
979 | in version 3.5.0, there is a single heap limit for the entire process. | ||
980 | This seems more restrictive (one limit as opposed to many) but in | ||
981 | practice it is what most users want. | ||
982 | } | ||
983 | |||
984 | PARAGRAPH { | ||
985 | Prior to version 3.5.0 the [sqlite3_release_memory()] function would | ||
986 | try to reclaim memory from all database connections in the same thread | ||
987 | as the sqlite3_release_memory() call. Beginning with version 3.5.0, | ||
988 | the sqlite3_release_memory() function will attempt to reclaim memory | ||
989 | from all database connections in all threads. | ||
990 | } | ||
991 | |||
992 | HEADING 1 {Summary} | ||
993 | |||
994 | PARAGRAPH { | ||
995 | The transition from SQLite version 3.4.2 to 3.5.0 is a major change. | ||
996 | Every source code file in the SQLite core had to be modified, some | ||
997 | extensively. And the change introduced some minor incompatibilities | ||
998 | in the C interface. But we feel that the benefits of the transition | ||
999 | from 3.4.2 to 3.5.0 far outweigh the pain of porting. The new | ||
1000 | VFS layer is now well-defined and stable and should simplify future | ||
1001 | customizations. The VFS layer, and the separable memory allocator | ||
1002 | and mutex subsystems allow a standard SQLite source code amalgamation | ||
1003 | to be used in an embedded project without change, greatly simplifying | ||
1004 | configuration management. And the resulting system is much more | ||
1005 | tolerant of highly threaded designs. | ||
1006 | } | ||