Skip to content
This repository
Browse code

Merge branch 'master' of git://github.com/pkgng/pkgng

  • Loading branch information...
commit 838dd4cac448cdc228f900c14d98b0e143e6a894 2 parents 1cd02f4 + 419e47b
namore authored September 06, 2012

Showing 189 changed files with 27,346 additions and 6,647 deletions. Show diff stats Hide diff stats

  1. 3  AUTHORS
  2. 2  Doxyfile
  3. 104  FAQ.md
  4. 16  README.md
  5. 6  docs/GOALS
  6. 275  external/sqlite/shell.c
  7. 7,176  external/sqlite/sqlite3.c
  8. 90  external/sqlite/sqlite3.h
  9. 915  external/uthash/uthash.h
  10. 14  libpkg/Makefile
  11. 229  libpkg/backup.c
  12. 138  libpkg/dns_utils.c
  13. 502  libpkg/elfhints.c
  14. 84  libpkg/fetch.c
  15. 85  libpkg/packing.c
  16. 538  libpkg/pkg.c
  17. 338  libpkg/pkg.h
  18. 81  libpkg/pkg_add.c
  19. 244  libpkg/pkg_attributes.c
  20. 229  libpkg/pkg_config.c
  21. 207  libpkg/pkg_create.c
  22. 71  libpkg/pkg_delete.c
  23. 405  libpkg/pkg_elf.c
  24. 40  libpkg/pkg_event.c
  25. 117  libpkg/pkg_jobs.c
  26. 612  libpkg/pkg_manifest.c
  27. 259  libpkg/pkg_ports.c
  28. 982  libpkg/pkg_repo.c
  29. 38  libpkg/pkg_version.c
  30. 2,501  libpkg/pkgdb.c
  31. 635  libpkg/plugins.c
  32. 1  libpkg/private/event.h
  33. 50  libpkg/private/ldconfig.h
  34. 208  libpkg/private/pkg.h
  35. 16  libpkg/private/pkgdb.h
  36. 67  libpkg/private/thd_repo.h
  37. 16  libpkg/private/utils.h
  38. 89  libpkg/rcscripts.c
  39. 26  libpkg/rsa.c
  40. 136  libpkg/scripts.c
  41. 111  libpkg/update.c
  42. 58  libpkg/usergroup.c
  43. 139  libpkg/utils.c
  44. 1  pkg-static/Makefile
  45. 19  pkg/Makefile
  46. 13  pkg/add.c
  47. 114  pkg/audit.c
  48. 38  pkg/autoremove.c
  49. 23  pkg/backup.c
  50. 135  pkg/check.c
  51. 284  pkg/clean.c
  52. 210  pkg/create.c
  53. 111  pkg/delete.c
  54. 78  pkg/event.c
  55. 12  pkg/fetch.c
  56. 52  pkg/fix-xrefs
  57. 261  pkg/info.c
  58. 104  pkg/install.c
  59. 130  pkg/main.c
  60. 11  pkg/pkg-add.8
  61. 17  pkg/pkg-audit.8
  62. 3  pkg/pkg-autoremove.8
  63. 17  pkg/pkg-backup.8
  64. 13  pkg/pkg-check.8
  65. 31  pkg/pkg-clean.8
  66. 136  pkg/pkg-create.8
  67. 59  pkg/pkg-delete.8
  68. 8  pkg/pkg-fetch.8
  69. 6  pkg/pkg-info.8
  70. 142  pkg/pkg-install.8
  71. 50  pkg/pkg-query.8
  72. 8  pkg/pkg-register.8
  73. 42  pkg/pkg-repo.8
  74. 22  pkg/pkg-rquery.8
  75. 377  pkg/pkg-search.8
  76. 1  pkg/pkg-set.8
  77. 2  pkg/pkg-shell.8
  78. 6  pkg/pkg-shlib.8
  79. 77  pkg/pkg-stats.8
  80. 25  pkg/pkg-update.8
  81. 8  pkg/pkg-updating.8
  82. 37  pkg/pkg-upgrade.8
  83. 87  pkg/pkg-version.8
  84. 1  pkg/pkg-which.8
  85. 27  pkg/pkg.8
  86. 36  pkg/pkg.conf.5
  87. 36  pkg/pkg.conf.sample
  88. 120  pkg/pkgcli.h
  89. 94  pkg/plugins.c
  90. 4  pkg/progressmeter.c
  91. 882  pkg/query.c
  92. 92  pkg/register.c
  93. 49  pkg/repo.c
  94. 54  pkg/rquery.c
  95. 338  pkg/search.c
  96. 130  pkg/set.c
  97. 4  pkg/shell.c
  98. 4  pkg/shlib.c
  99. 103  pkg/stats.c
  100. 45  pkg/update.c
  101. 22  pkg/updating.c
  102. 70  pkg/upgrade.c
  103. 545  pkg/utils.c
  104. 379  pkg/version.c
  105. 21  pkg/which.c
  106. 18  plugins/pkg-plugin-mystats-command/Makefile
  107. 43  plugins/pkg-plugin-mystats-command/README.md
  108. 127  plugins/pkg-plugin-mystats-command/mystats.c
  109. 6  plugins/pkg-plugin-mystats-command/mystats.conf
  110. 37  plugins/pkg-plugin-mystats-command/mystats.h
  111. 18  plugins/pkg-plugin-stats/Makefile
  112. 43  plugins/pkg-plugin-stats/README.md
  113. 97  plugins/pkg-plugin-stats/stats.c
  114. 6  plugins/pkg-plugin-stats/stats.conf
  115. 37  plugins/pkg-plugin-stats/stats.h
  116. 18  plugins/pkg-plugin-template/Makefile
  117. 40  plugins/pkg-plugin-template/README.md
  118. 161  plugins/pkg-plugin-template/template.c
  119. 26  plugins/pkg-plugin-template/template.conf
  120. 38  plugins/pkg-plugin-template/template.h
  121. 18  plugins/pkg-plugin-zfssnap/Makefile
  122. 45  plugins/pkg-plugin-zfssnap/README.md
  123. 165  plugins/pkg-plugin-zfssnap/zfssnap.c
  124. 23  plugins/pkg-plugin-zfssnap/zfssnap.conf
  125. 37  plugins/pkg-plugin-zfssnap/zfssnap.h
  126. 4  plugins/pkg-plugins-serve/Makefile
  127. 48  plugins/pkg-plugins-serve/README.md
  128. 19  plugins/pkg-plugins-serve/mongoose/LICENSE
  129. 20  plugins/pkg-plugins-serve/mongoose/Makefile
  130. 151  plugins/pkg-plugins-serve/mongoose/Makefile.orig
  131. 29  plugins/pkg-plugins-serve/mongoose/README.md
  132. 52  plugins/pkg-plugins-serve/mongoose/bindings/csharp/example.cs
  133. 134  plugins/pkg-plugins-serve/mongoose/bindings/csharp/mongoose.cs
  134. 63  plugins/pkg-plugins-serve/mongoose/bindings/python/example.py
  135. 160  plugins/pkg-plugins-serve/mongoose/bindings/python/mongoose.py
  136. 8  plugins/pkg-plugins-serve/mongoose/examples/Makefile
  137. 387  plugins/pkg-plugins-serve/mongoose/examples/chat.c
  138. 37  plugins/pkg-plugins-serve/mongoose/examples/hello.c
  139. BIN  plugins/pkg-plugins-serve/mongoose/examples/html/favicon.ico
  140. 73  plugins/pkg-plugins-serve/mongoose/examples/html/index.html
  141. 154  plugins/pkg-plugins-serve/mongoose/examples/html/jquery.js
  142. 43  plugins/pkg-plugins-serve/mongoose/examples/html/login.html
  143. BIN  plugins/pkg-plugins-serve/mongoose/examples/html/logo.png
  144. 99  plugins/pkg-plugins-serve/mongoose/examples/html/main.js
  145. 154  plugins/pkg-plugins-serve/mongoose/examples/html/style.css
  146. 61  plugins/pkg-plugins-serve/mongoose/examples/post.c
  147. 50  plugins/pkg-plugins-serve/mongoose/examples/ssl_cert.pem
  148. 507  plugins/pkg-plugins-serve/mongoose/main.c
  149. 174  plugins/pkg-plugins-serve/mongoose/mongoose.1
  150. 4,474  plugins/pkg-plugins-serve/mongoose/mongoose.c
  151. 301  plugins/pkg-plugins-serve/mongoose/mongoose.h
  152. 1  plugins/pkg-plugins-serve/mongoose/test/.leading.dot.txt
  153. 1  plugins/pkg-plugins-serve/mongoose/test/\/a.txt
  154. 28  plugins/pkg-plugins-serve/mongoose/test/all_build_flags.pl
  155. 5  plugins/pkg-plugins-serve/mongoose/test/bad.cgi
  156. 3  plugins/pkg-plugins-serve/mongoose/test/bad2.cgi
  157. 181  plugins/pkg-plugins-serve/mongoose/test/embed.c
  158. 46  plugins/pkg-plugins-serve/mongoose/test/env.cgi
  159. 69  plugins/pkg-plugins-serve/mongoose/test/exploit.pl
  160. 6  plugins/pkg-plugins-serve/mongoose/test/hello.cgi
  161. 1  plugins/pkg-plugins-serve/mongoose/test/hello.txt
  162. 3  plugins/pkg-plugins-serve/mongoose/test/passfile
  163. 6  plugins/pkg-plugins-serve/mongoose/test/sh.cgi
  164. 5  plugins/pkg-plugins-serve/mongoose/test/ssi1.shtml
  165. 5  plugins/pkg-plugins-serve/mongoose/test/ssi2.shtml
  166. 5  plugins/pkg-plugins-serve/mongoose/test/ssi3.shtml
  167. 5  plugins/pkg-plugins-serve/mongoose/test/ssi4.shtml
  168. 5  plugins/pkg-plugins-serve/mongoose/test/ssi5.shtml
  169. 5  plugins/pkg-plugins-serve/mongoose/test/ssi6.shtml
  170. 6  plugins/pkg-plugins-serve/mongoose/test/ssi7.shtml
  171. 1  plugins/pkg-plugins-serve/mongoose/test/ssi8.shtml
  172. 3  plugins/pkg-plugins-serve/mongoose/test/ssi9.shtml
  173. 533  plugins/pkg-plugins-serve/mongoose/test/test.pl
  174. 12  plugins/pkg-plugins-serve/mongoose/test/timeout.cgi
  175. 206  plugins/pkg-plugins-serve/mongoose/test/unit_test.c
  176. 15  plugins/pkg-plugins-serve/mongoose/win32/dll.def
  177. 1  plugins/pkg-plugins-serve/mongoose/win32/res.rc
  178. 50  plugins/pkg-plugins-serve/mongoose/win32/ssl_cert.pem
  179. BIN  plugins/pkg-plugins-serve/mongoose/win32/systray.ico
  180. 22  plugins/pkg-plugins-serve/plugin/Makefile
  181. 131  plugins/pkg-plugins-serve/plugin/serve.c
  182. 6  plugins/pkg-plugins-serve/plugin/serve.conf
  183. 37  plugins/pkg-plugins-serve/plugin/serve.h
  184. 458  ports/patch-portmaster-pkgng
  185. 42  ports/pkg2ng
  186. 26  scripts/find-missing-man-page-sa.sh
  187. 2  scripts/periodic/410.pkg-audit
  188. 47  scripts/periodic/411.pkg-backup
  189. 131  scripts/pkg_tree.sh
3  AUTHORS
@@ -5,6 +5,9 @@ Julien Laffaye <jlaffaye@FreeBSD.org>
5 5
 
6 6
 Contributors:
7 7
 
  8
+All contributors can be seen on github:
  9
+https://github.com/pkgng/pkgng/graphs/contributors
  10
+
8 11
 Philippe Pepiot <phil@philpep.org>
9 12
 Will Andrews <will@FreeBSD.org>
10 13
 Marin Atanasov Nikolov <dnaeon@gmail.com>
2  Doxyfile
@@ -31,7 +31,7 @@ PROJECT_NAME           = libpkg
31 31
 # This could be handy for archiving the generated documentation or
32 32
 # if some version control system is used.
33 33
 
34  
-PROJECT_NUMBER         = 1.0-beta15
  34
+PROJECT_NUMBER         = 1.0.90
35 35
 
36 36
 # Using the PROJECT_BRIEF tag one can provide an optional one line description for a project that appears at the top of each page and should give viewer a quick idea about the purpose of the project. Keep the description short.
37 37
 
104  FAQ.md
Source Rendered
@@ -22,6 +22,16 @@ Table of Contents
22 22
 * [How can I use pkgng with portmaster?](#15)
23 23
 * [How can I use pkgng with portupgrade?](#16)
24 24
 * [pkgng does not work it says: /usr/local/sbin/pkg: Undefined symbol "pkg_event_register"](#17)
  25
+* [Can pkgng cope with parallel installs?  What happpens if I simultaneously (attempt to) install conflicting packages?](#18)
  26
+* [If I use "pkg delete -f", what happens to packages that depended on the forcibly-deleted package?](#19)
  27
+* [What happens if I delete a package where I've modified one of the files managed by the package?](#20)
  28
+* [What facilities does it have for auditing and repairing the package database? (ie checking for inconsistencies between installed files and the content of the package database)?](#21)
  29
+* [Will it detect that a package install would overwrite an existing?](#22)
  30
+* [If so, what happens to the file metadata (particularly uid, gid and mtime)?](#23)
  31
+* [Can it track user-edited configuration files that are associated with packages?](#24)
  32
+* [Can it do 2- or 3-way merges of package configuration files?](#25)
  33
+* [The README states "Directory leftovers are automatically removed if they are not in the MTREE."  How does this work for directories that are shared between multiple packages?  Does this mean that if I add a file to a directory that was created by a package, that file will be deleted automatically if I delete the package?](#26)
  34
+* [How to create a new plugin for pkgng?](#27)
25 35
 
26 36
 <a name="0"></a>
27 37
 ### Q: How can I start using pkgng?
@@ -30,7 +40,7 @@ In order to start using pkgng, please follow the steps below.
30 40
 
31 41
 Install ports-mgmt/pkg:
32 42
 
33  
-        # make -C /usr/ports/ports-mgmt/pkg
  43
+        # make -C /usr/ports/ports-mgmt/pkg install clean
34 44
         # echo "WITH_PKGNG=yes" >> /etc/make.conf
35 45
 
36 46
 Now register all packages you have in the pkgng database:
@@ -94,7 +104,11 @@ The default hierarchy has lots of symlinks which should just be ignored and thus
94 104
 
95 105
 Here is how to do that:
96 106
 
97  
-    sh -c 'find . -name "*.txz" -exec pkg query -f {} %o \;' | sort | uniq -d
  107
+    sh -c 'find . -type f -name "*-*.txz" -exec pkg query -F {} %o \;' | sort | uniq -d
  108
+
  109
+As of beta17, `pkg repo` will emit a warning message and ignore any
  110
+older versions if it finds multiple packages from the same origin
  111
+when building a repo.
98 112
 
99 113
 <a name="11"></a>
100 114
 ### Q: How to start working with multi-repos in pkgng?
@@ -149,8 +163,86 @@ More information can be found in the portupgrade [NEWS](https://github.com/pkgto
149 163
 <a name="17"></a>
150 164
 ### Q: pkgng does not work it says: /usr/local/sbin/pkg: Undefined symbol "pkg_event_register"
151 165
 
152  
-You should have forgotten make delete-old-libs when you upgraded your system.
  166
+You forgot to run `make delete-old-libs` when you upgraded your system.
  167
+
  168
+During 9-CURRENT life the pkg_install tools have been split to provide a
  169
+shared library: libpkg.so.0. This has been reverted, this error message means
  170
+that this library is still on your system. Check for and delete /usr/lib/libpkg.so.0.
  171
+
  172
+<a name="18"></a>
  173
+### Q: Can pkgng cope with parallel installs?  What happpens if I simultaneously (attempt to) install conflicting packages?
  174
+
  175
+No.  Parallel installs will not work -- the first to start will lock the DB, and
  176
+the second won't be able to proceed.
  177
+
  178
+<a name="19"></a>
  179
+### Q: If I use "pkg delete -f", what happens to packages that depended on the forcibly-deleted package?
  180
+
  181
+Nothing.  If you forcibly delete a package it's assumed you understand that you know you're doing something that can break your system.
  182
+pkg check will detect missing dependency packages and reinstall as required.
  183
+
  184
+<a name="20"></a>
  185
+### Q: What happens if I delete a package where I've modified one of the files managed by the package?
  186
+
  187
+The package is removed, but modified file is not:
  188
+
  189
+	# pkg check -s pciids
  190
+	pciids-20120625: checksum mismatch for /usr/local/share/pciids/pci.ids
  191
+	# pkg delete pciids
  192
+	The following packages will be deinstalled:
  193
+	
  194
+		pciids-20120625
  195
+	
  196
+	The deinstallation will free 788 kB
  197
+	Deinstalling pciids-20120625...pkg: /usr/local/share/pciids/pci.ids
  198
+	fails original SHA256 checksum, not removing
  199
+	pkg: rmdir(/usr/local/share/pciids/): Directory not empty
  200
+	done
  201
+	# pkg info pciids
  202
+	pkg: No package(s) matching pciids
  203
+	# ls -l /usr/local/share/pciids/pci.ids
  204
+	-rw-r--r--  1 root  wheel  752925 Jul 16 07:05
  205
+	/usr/local/share/pciids/pci.ids
  206
+
  207
+<a name="21"></a>
  208
+### Q: What facilities does it have for auditing and repairing the package database? (ie checking for inconsistencies between installed files and the content of the package database)
  209
+
  210
+See pkg-check(8)
  211
+
  212
+<a name="22"></a>
  213
+### Q: Will it detect that a package install would overwrite an existing
  214
+
  215
+Yes exactly that.  Files in the older package that are identical in the
  216
+newer one are left untouched.  Otherwise, files from the older package
  217
+are removed, and files from the newer package are installed.
  218
+
  219
+<a name="23"></a>
  220
+### Q: If so, what happens to the file metadata (particularly uid, gid and mtime)?
  221
+
  222
+Nothing.
  223
+
  224
+<a name="24"></a>
  225
+### Q: Can it track user-edited configuration files that are associated with packages?
  226
+
  227
+This works in exactly the same way as it does currently in the ports. Except if the package provide the configuration with a .pkgconf extension
  228
+In that if there is no user config the default configuration is created otherwise, the user edited version is kept
  229
+
  230
+<a name="25"></a>
  231
+### Q: Can it do 2- or 3-way merges of package configuration files?
  232
+
  233
+No.  In general the package will install sample configuration files,
  234
+and will only touch the live config files if either the live configs
  235
+don't exist, or the live configs are identical to the sample configs.
  236
+This is the standard way things work in the ports at the moment.
  237
+
  238
+<a name="26"></a>
  239
+### Q: The README states "Directory leftovers are automatically removed if they are not in the MTREE."  How does this work for directories that are shared between multiple packages?  Does this mean that if I add a file to a directory that was created by a package, that file will be deleted automatically if I delete the package?
  240
+
  241
+No.  Directories have to be empty before they will be removed.
  242
+
  243
+<a name="27"></a>
  244
+### Q: How to create a new plugin for pkgng?
  245
+
  246
+If you are interested in creating a new plugin for pkgng you might want to check the following handbook which is an introduction to plugins writing for pkgng.
153 247
 
154  
-during 9-CURRENT life the pkg_install tools has been splitted to provide a
155  
-shared library: libpkg.so.0 and this has been reverted, this error message means
156  
-that this library is still on your system, please check /usr/lib/libpkg.so.0
  248
+* [Introduction to writing plugins for pkgng in FreeBSD](http://unix-heaven.org/writing-plugins-for-pkgng)
16  README.md
Source Rendered
@@ -152,12 +152,12 @@ show pkg-message, ...
152 152
 `pkg add` can install a package archive from the local disk, or from a
153 153
 remote FTP/HTTP server.
154 154
 
155  
-If only a package name is given, it will search the remote repository
  155
+If only a package name is given, it will search the repository catalogue
156 156
 and download and install the package if it exists. The dependencies will be
157 157
 downloaded and installed first.
158 158
 
159 159
 This is possible because we have the dependency information in the
160  
-remote repository database.
  160
+catalogue of the remote repository.
161 161
 
162 162
 `pkg add` will check if the user attempts to install a package built for another
163 163
 arch or release.
@@ -180,7 +180,7 @@ Directory leftovers are automatically removed if they are not in the MTREE.
180 180
 
181 181
 pkgng beta1 is now in the ports tree. To get it:
182 182
 
183  
-	$ make -C /usr/ports/ports-mgmt/pkg
  183
+	$ make -C /usr/ports/ports-mgmt/pkg install clean
184 184
 	$ echo "WITH_PKGNG=yes" >> /etc/make.conf
185 185
 
186 186
 <a name="usageintro"></a>
@@ -282,7 +282,7 @@ so that it points to a remote location, which contains packages that can be inst
282 282
 or set _PACKAGESITE_ in the *pkg.conf(5)* configuration file.
283 283
 
284 284
 In order to work with a single remote package repository, you would define _PACKAGESITE_ to
285  
-your remote server with packages, like for example (or use */etc/pkg.conf* to set it there):
  285
+your remote server with packages, like for example (or use ${LOCALBASE}/etc/pkg.conf* to set it there):
286 286
 
287 287
 	TCSH users:
288 288
 
@@ -292,7 +292,7 @@ your remote server with packages, like for example (or use */etc/pkg.conf* to se
292 292
 
293 293
 	# export PACKAGESITE=http://example.org/pkgng-repo/
294 294
 
295  
-Then fetch the remote repository using the below command:
  295
+Then fetch the repository catalogue using the command:
296 296
 
297 297
 	# pkg update
298 298
 
@@ -308,11 +308,11 @@ pkgng is also able to work with multiple remote repositories. In the previous se
308 308
 we are using only a single remote repository, which is defined by the _PACKAGESITE_ option.
309 309
 
310 310
 In order to be able to work with multiple remote repositories and instead of changing
311  
-each time _PACKAGESITE_, you can tell *pkg(1)* to work in multi-repos mode as well.
  311
+_PACKAGESITE_ each time, you can tell *pkg(1)* to work in multi-repos mode as well.
312 312
 
313 313
 To do this, simply enable multi-repos in *pkg.conf(5)* like this:
314 314
 
315  
-	# echo "PKG_MULTIREPOS : YES" >> /etc/pkg.conf
  315
+	# echo "PKG_MULTIREPOS : YES" >> /usr/local/etc/pkg.conf
316 316
 
317 317
 The next thing is to define your remote repositories in the *pkg.conf(5)* file.
318 318
 
@@ -327,7 +327,7 @@ the *default* repository.
327 327
 It is important that you always define a *default* repository - this is the repository that is being
328 328
 used when no remote repositories are specified via the `-r <repo>` flag.
329 329
 
330  
-Next, fetch the remote repositories:
  330
+Next, fetch all the repository catalogues:
331 331
 
332 332
 	# pkg update
333 333
 
6  docs/GOALS
@@ -62,7 +62,7 @@ Table of Contents:
62 62
 
63 63
 - search:
64 64
 
65  
-	- Will search the remote repository to provide information
  65
+	- Will search the repository catalogue to provide information
66 66
 	  to the users.
67 67
 
68 68
 - info: 
@@ -87,8 +87,8 @@ Table of Contents:
87 87
 
88 88
 - upgrade:
89 89
 
90  
-	- Will compute the remote repository to check if there are new upgrades
91  
-	  available and apply them.
  90
+	- Will examine the repository catalogue to check if there are
  91
+	  any upgrades available and apply them.
92 92
 
93 93
 - update:
94 94
 
275  external/sqlite/shell.c
@@ -68,6 +68,8 @@
68 68
 # include <io.h>
69 69
 #define isatty(h) _isatty(h)
70 70
 #define access(f,m) _access((f),(m))
  71
+#define popen(a,b) _popen((a),(b))
  72
+#define pclose(x) _pclose(x)
71 73
 #else
72 74
 /* Make sure isatty() has a prototype.
73 75
 */
@@ -419,6 +421,7 @@ struct callback_data {
419 421
   int statsOn;           /* True to display memory stats before each finalize */
420 422
   int cnt;               /* Number of records displayed so far */
421 423
   FILE *out;             /* Write results here */
  424
+  FILE *traceOut;        /* Output for sqlite3_trace() */
422 425
   int nErr;              /* Number of errors seen */
423 426
   int mode;              /* An output mode setting */
424 427
   int writableSchema;    /* True if PRAGMA writable_schema=ON */
@@ -496,7 +499,7 @@ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
496 499
   int i;
497 500
   char *zBlob = (char *)pBlob;
498 501
   fprintf(out,"X'");
499  
-  for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]); }
  502
+  for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]&0xff); }
500 503
   fprintf(out,"'");
501 504
 }
502 505
 
@@ -1077,6 +1080,9 @@ static int display_stats(
1077 1080
     sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1078 1081
     fprintf(pArg->out, "Page cache misses:                   %d\n", iCur); 
1079 1082
     iHiwtr = iCur = -1;
  1083
+    sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
  1084
+    fprintf(pArg->out, "Page cache writes:                   %d\n", iCur); 
  1085
+    iHiwtr = iCur = -1;
1080 1086
     sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1081 1087
     fprintf(pArg->out, "Schema Heap Usage:                   %d bytes\n", iCur); 
1082 1088
     iHiwtr = iCur = -1;
@@ -1287,7 +1293,6 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
1287 1293
     char *zTableInfo = 0;
1288 1294
     char *zTmp = 0;
1289 1295
     int nRow = 0;
1290  
-    int kk;
1291 1296
    
1292 1297
     zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
1293 1298
     zTableInfo = appendText(zTableInfo, zTable, '"');
@@ -1300,14 +1305,12 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
1300 1305
     }
1301 1306
 
1302 1307
     zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
1303  
-    if( !isalpha(zTable[0]) ){
1304  
-      kk = 0;
1305  
-    }else{
1306  
-      for(kk=1; isalnum(zTable[kk]); kk++){}
1307  
-    }
1308  
-    zTmp = appendText(zTmp, zTable, zTable[kk] ? '"' : 0);
  1308
+    /* Always quote the table name, even if it appears to be pure ascii,
  1309
+    ** in case it is a keyword. Ex:  INSERT INTO "table" ... */
  1310
+    zTmp = appendText(zTmp, zTable, '"');
1309 1311
     if( zTmp ){
1310 1312
       zSelect = appendText(zSelect, zTmp, '\'');
  1313
+      free(zTmp);
1311 1314
     }
1312 1315
     zSelect = appendText(zSelect, " || ' VALUES(' || ", 0);
1313 1316
     rc = sqlite3_step(pTableInfo);
@@ -1336,7 +1339,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
1336 1339
       zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
1337 1340
       run_table_dump_query(p, zSelect, 0);
1338 1341
     }
1339  
-    if( zSelect ) free(zSelect);
  1342
+    free(zSelect);
1340 1343
   }
1341 1344
   return 0;
1342 1345
 }
@@ -1366,7 +1369,7 @@ static int run_schema_dump_query(
1366 1369
     }
1367 1370
     zQ2 = malloc( len+100 );
1368 1371
     if( zQ2==0 ) return rc;
1369  
-    sqlite3_snprintf(sizeof(zQ2), zQ2, "%s ORDER BY rowid DESC", zQuery);
  1372
+    sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
1370 1373
     rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
1371 1374
     if( rc ){
1372 1375
       fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
@@ -1432,6 +1435,7 @@ static char zHelp[] =
1432 1435
   "                         If TABLE specified, only list tables matching\n"
1433 1436
   "                         LIKE pattern TABLE.\n"
1434 1437
   ".timeout MS            Try opening locked tables for MS milliseconds\n"
  1438
+  ".trace FILE|off        Output each SQL statement as it is run\n"
1435 1439
   ".vfsname ?AUX?         Print the name of the VFS stack\n"
1436 1440
   ".width NUM1 NUM2 ...   Set column widths for \"column\" mode\n"
1437 1441
 ;
@@ -1522,6 +1526,52 @@ static int booleanValue(char *zArg){
1522 1526
 }
1523 1527
 
1524 1528
 /*
  1529
+** Close an output file, assuming it is not stderr or stdout
  1530
+*/
  1531
+static void output_file_close(FILE *f){
  1532
+  if( f && f!=stdout && f!=stderr ) fclose(f);
  1533
+}
  1534
+
  1535
+/*
  1536
+** Try to open an output file.   The names "stdout" and "stderr" are
  1537
+** recognized and do the right thing.  NULL is returned if the output 
  1538
+** filename is "off".
  1539
+*/
  1540
+static FILE *output_file_open(const char *zFile){
  1541
+  FILE *f;
  1542
+  if( strcmp(zFile,"stdout")==0 ){
  1543
+    f = stdout;
  1544
+  }else if( strcmp(zFile, "stderr")==0 ){
  1545
+    f = stderr;
  1546
+  }else if( strcmp(zFile, "off")==0 ){
  1547
+    f = 0;
  1548
+  }else{
  1549
+    f = fopen(zFile, "wb");
  1550
+    if( f==0 ){
  1551
+      fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
  1552
+    }
  1553
+  }
  1554
+  return f;
  1555
+}
  1556
+
  1557
+/*
  1558
+** A routine for handling output from sqlite3_trace().
  1559
+*/
  1560
+static void sql_trace_callback(void *pArg, const char *z){
  1561
+  FILE *f = (FILE*)pArg;
  1562
+  if( f ) fprintf(f, "%s\n", z);
  1563
+}
  1564
+
  1565
+/*
  1566
+** A no-op routine that runs with the ".breakpoint" doc-command.  This is
  1567
+** a useful spot to set a debugger breakpoint.
  1568
+*/
  1569
+static void test_breakpoint(void){
  1570
+  static int nCall = 0;
  1571
+  nCall++;
  1572
+}
  1573
+
  1574
+/*
1525 1575
 ** If an input line begins with "." then invoke this routine to
1526 1576
 ** process that line.
1527 1577
 **
@@ -1600,6 +1650,13 @@ static int do_meta_command(char *zLine, struct callback_data *p){
1600 1650
     bail_on_error = booleanValue(azArg[1]);
1601 1651
   }else
1602 1652
 
  1653
+  /* The undocumented ".breakpoint" command causes a call to the no-op
  1654
+  ** routine named test_breakpoint().
  1655
+  */
  1656
+  if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
  1657
+    test_breakpoint();
  1658
+  }else
  1659
+
1603 1660
   if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
1604 1661
     struct callback_data data;
1605 1662
     char *zErrMsg = 0;
@@ -1931,22 +1988,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
1931 1988
 
1932 1989
   if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
1933 1990
     const char *zFile = azArg[1];
1934  
-    if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
1935  
-      fclose(p->pLog);
1936  
-      p->pLog = 0;
1937  
-    }
1938  
-    if( strcmp(zFile,"stdout")==0 ){
1939  
-      p->pLog = stdout;
1940  
-    }else if( strcmp(zFile, "stderr")==0 ){
1941  
-      p->pLog = stderr;
1942  
-    }else if( strcmp(zFile, "off")==0 ){
1943  
-      p->pLog = 0;
1944  
-    }else{
1945  
-      p->pLog = fopen(zFile, "w");
1946  
-      if( p->pLog==0 ){
1947  
-        fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
1948  
-      }
1949  
-    }
  1991
+    output_file_close(p->pLog);
  1992
+    p->pLog = output_file_open(zFile);
1950 1993
   }else
1951 1994
 
1952 1995
   if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){
@@ -1999,20 +2042,31 @@ static int do_meta_command(char *zLine, struct callback_data *p){
1999 2042
   }else
2000 2043
 
2001 2044
   if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
2002  
-    if( p->out!=stdout ){
2003  
-      fclose(p->out);
  2045
+    if( p->outfile[0]=='|' ){
  2046
+      pclose(p->out);
  2047
+    }else{
  2048
+      output_file_close(p->out);
2004 2049
     }
2005  
-    if( strcmp(azArg[1],"stdout")==0 ){
2006  
-      p->out = stdout;
2007  
-      sqlite3_snprintf(sizeof(p->outfile), p->outfile, "stdout");
  2050
+    p->outfile[0] = 0;
  2051
+    if( azArg[1][0]=='|' ){
  2052
+      p->out = popen(&azArg[1][1], "w");
  2053
+      if( p->out==0 ){
  2054
+        fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
  2055
+        p->out = stdout;
  2056
+        rc = 1;
  2057
+      }else{
  2058
+        sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
  2059
+      }
2008 2060
     }else{
2009  
-      p->out = fopen(azArg[1], "wb");
  2061
+      p->out = output_file_open(azArg[1]);
2010 2062
       if( p->out==0 ){
2011  
-        fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
  2063
+        if( strcmp(azArg[1],"off")!=0 ){
  2064
+          fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
  2065
+        }
2012 2066
         p->out = stdout;
2013 2067
         rc = 1;
2014 2068
       } else {
2015  
-         sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
  2069
+        sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
2016 2070
       }
2017 2071
     }
2018 2072
   }else
@@ -2130,23 +2184,25 @@ static int do_meta_command(char *zLine, struct callback_data *p){
2130 2184
         zShellStatic = azArg[1];
2131 2185
         rc = sqlite3_exec(p->db,
2132 2186
           "SELECT sql FROM "
2133  
-          "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
  2187
+          "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2134 2188
           "     FROM sqlite_master UNION ALL"
2135  
-          "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
  2189
+          "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2136 2190
           "WHERE lower(tbl_name) LIKE shellstatic()"
2137 2191
           "  AND type!='meta' AND sql NOTNULL "
2138  
-          "ORDER BY substr(type,2,1), name",
  2192
+          "ORDER BY substr(type,2,1), "
  2193
+                  " CASE type WHEN 'view' THEN rowid ELSE name END",
2139 2194
           callback, &data, &zErrMsg);
2140 2195
         zShellStatic = 0;
2141 2196
       }
2142 2197
     }else{
2143 2198
       rc = sqlite3_exec(p->db,
2144 2199
          "SELECT sql FROM "
2145  
-         "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
  2200
+         "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
2146 2201
          "     FROM sqlite_master UNION ALL"
2147  
-         "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
  2202
+         "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
2148 2203
          "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
2149  
-         "ORDER BY substr(type,2,1), name",
  2204
+         "ORDER BY substr(type,2,1),"
  2205
+                  " CASE type WHEN 'view' THEN rowid ELSE name END",
2150 2206
          callback, &data, &zErrMsg
2151 2207
       );
2152 2208
     }
@@ -2194,46 +2250,71 @@ static int do_meta_command(char *zLine, struct callback_data *p){
2194 2250
   }else
2195 2251
 
2196 2252
   if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){
  2253
+    sqlite3_stmt *pStmt;
2197 2254
     char **azResult;
2198  
-    int nRow;
2199  
-    char *zErrMsg;
  2255
+    int nRow, nAlloc;
  2256
+    char *zSql = 0;
  2257
+    int ii;
2200 2258
     open_db(p);
2201  
-    if( nArg==1 ){
2202  
-      rc = sqlite3_get_table(p->db,
2203  
-        "SELECT name FROM sqlite_master "
2204  
-        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
2205  
-        "UNION ALL "
2206  
-        "SELECT name FROM sqlite_temp_master "
2207  
-        "WHERE type IN ('table','view') "
2208  
-        "ORDER BY 1",
2209  
-        &azResult, &nRow, 0, &zErrMsg
2210  
-      );
2211  
-    }else{
2212  
-      zShellStatic = azArg[1];
2213  
-      rc = sqlite3_get_table(p->db,
2214  
-        "SELECT name FROM sqlite_master "
2215  
-        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
2216  
-        "UNION ALL "
2217  
-        "SELECT name FROM sqlite_temp_master "
2218  
-        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
2219  
-        "ORDER BY 1",
2220  
-        &azResult, &nRow, 0, &zErrMsg
2221  
-      );
2222  
-      zShellStatic = 0;
  2259
+    rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
  2260
+    if( rc ) return rc;
  2261
+    zSql = sqlite3_mprintf(
  2262
+        "SELECT name FROM sqlite_master"
  2263
+        " WHERE type IN ('table','view')"
  2264
+        "   AND name NOT LIKE 'sqlite_%%'"
  2265
+        "   AND name LIKE ?1");
  2266
+    while( sqlite3_step(pStmt)==SQLITE_ROW ){
  2267
+      const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
  2268
+      if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue;
  2269
+      if( strcmp(zDbName,"temp")==0 ){
  2270
+        zSql = sqlite3_mprintf(
  2271
+                 "%z UNION ALL "
  2272
+                 "SELECT 'temp.' || name FROM sqlite_temp_master"
  2273
+                 " WHERE type IN ('table','view')"
  2274
+                 "   AND name NOT LIKE 'sqlite_%%'"
  2275
+                 "   AND name LIKE ?1", zSql);
  2276
+      }else{
  2277
+        zSql = sqlite3_mprintf(
  2278
+                 "%z UNION ALL "
  2279
+                 "SELECT '%q.' || name FROM \"%w\".sqlite_master"
  2280
+                 " WHERE type IN ('table','view')"
  2281
+                 "   AND name NOT LIKE 'sqlite_%%'"
  2282
+                 "   AND name LIKE ?1", zSql, zDbName, zDbName);
  2283
+      }
2223 2284
     }
2224  
-    if( zErrMsg ){
2225  
-      fprintf(stderr,"Error: %s\n", zErrMsg);
2226  
-      sqlite3_free(zErrMsg);
2227  
-      rc = 1;
2228  
-    }else if( rc != SQLITE_OK ){
2229  
-      fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
2230  
-      rc = 1;
  2285
+    sqlite3_finalize(pStmt);
  2286
+    zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
  2287
+    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  2288
+    sqlite3_free(zSql);
  2289
+    if( rc ) return rc;
  2290
+    nRow = nAlloc = 0;
  2291
+    azResult = 0;
  2292
+    if( nArg>1 ){
  2293
+      sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT);
2231 2294
     }else{
  2295
+      sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
  2296
+    }
  2297
+    while( sqlite3_step(pStmt)==SQLITE_ROW ){
  2298
+      if( nRow>=nAlloc ){
  2299
+        char **azNew;
  2300
+        int n = nAlloc*2 + 10;
  2301
+        azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n);
  2302
+        if( azNew==0 ){
  2303
+          fprintf(stderr, "Error: out of memory\n");
  2304
+          break;
  2305
+        }
  2306
+        nAlloc = n;
  2307
+        azResult = azNew;
  2308
+      }
  2309
+      azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
  2310
+      if( azResult[nRow] ) nRow++;
  2311
+    }
  2312
+    sqlite3_finalize(pStmt);        
  2313
+    if( nRow>0 ){
2232 2314
       int len, maxlen = 0;
2233 2315
       int i, j;
2234 2316
       int nPrintCol, nPrintRow;
2235  
-      for(i=1; i<=nRow; i++){
2236  
-        if( azResult[i]==0 ) continue;
  2317
+      for(i=0; i<nRow; i++){
2237 2318
         len = strlen30(azResult[i]);
2238 2319
         if( len>maxlen ) maxlen = len;
2239 2320
       }
@@ -2241,14 +2322,15 @@ static int do_meta_command(char *zLine, struct callback_data *p){
2241 2322
       if( nPrintCol<1 ) nPrintCol = 1;
2242 2323
       nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
2243 2324
       for(i=0; i<nPrintRow; i++){
2244  
-        for(j=i+1; j<=nRow; j+=nPrintRow){
2245  
-          char *zSp = j<=nPrintRow ? "" : "  ";
  2325
+        for(j=i; j<nRow; j+=nPrintRow){
  2326
+          char *zSp = j<nPrintRow ? "" : "  ";
2246 2327
           printf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
2247 2328
         }
2248 2329
         printf("\n");
2249 2330
       }
2250 2331
     }
2251  
-    sqlite3_free_table(azResult);
  2332
+    for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
  2333
+    sqlite3_free(azResult);
2252 2334
   }else
2253 2335
 
2254 2336
   if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
@@ -2382,6 +2464,19 @@ static int do_meta_command(char *zLine, struct callback_data *p){
2382 2464
     enableTimer = booleanValue(azArg[1]);
2383 2465
   }else
2384 2466
   
  2467
+  if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
  2468
+    open_db(p);
  2469
+    output_file_close(p->traceOut);
  2470
+    p->traceOut = output_file_open(azArg[1]);
  2471
+#ifndef SQLITE_OMIT_TRACE
  2472
+    if( p->traceOut==0 ){
  2473
+      sqlite3_trace(p->db, 0, 0);
  2474
+    }else{
  2475
+      sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
  2476
+    }
  2477
+#endif
  2478
+  }else
  2479
+
2385 2480
   if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
2386 2481
     printf("SQLite %s %s\n" /*extra-version-info*/,
2387 2482
         sqlite3_libversion(), sqlite3_sourceid());
@@ -2506,7 +2601,9 @@ static int process_input(struct callback_data *p, FILE *in){
2506 2601
     free(zLine);
2507 2602
     zLine = one_input_line(zSql, in);
2508 2603
     if( zLine==0 ){
2509  
-      break;  /* We have reached EOF */
  2604
+      /* End of input */
  2605
+      if( stdin_is_interactive ) printf("\n");
  2606
+      break;
2510 2607
     }
2511 2608
     if( seenInterrupt ){
2512 2609
       if( in!=0 ) break;
@@ -2593,12 +2690,11 @@ static int process_input(struct callback_data *p, FILE *in){
2593 2690
 
2594 2691
 /*
2595 2692
 ** Return a pathname which is the user's home directory.  A
2596  
-** 0 return indicates an error of some kind.  Space to hold the
2597  
-** resulting string is obtained from malloc().  The calling
2598  
-** function should free the result.
  2693
+** 0 return indicates an error of some kind.
2599 2694
 */
2600 2695
 static char *find_home_dir(void){
2601  
-  char *home_dir = NULL;
  2696
+  static char *home_dir = NULL;
  2697
+  if( home_dir ) return home_dir;
2602 2698
 
2603 2699
 #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
2604 2700
   struct passwd *pwent;
@@ -2611,7 +2707,7 @@ static char *find_home_dir(void){
2611 2707
 #if defined(_WIN32_WCE)
2612 2708
   /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv()
2613 2709
    */
2614  
-  home_dir = strdup("/");
  2710
+  home_dir = "/";
2615 2711
 #else
2616 2712
 
2617 2713
 #if defined(_WIN32) || defined(WIN32) || defined(__OS2__)
@@ -2667,7 +2763,6 @@ static int process_sqliterc(
2667 2763
   const char *sqliterc = sqliterc_override;
2668 2764
   char *zBuf = 0;
2669 2765
   FILE *in = NULL;
2670  
-  int nBuf;
2671 2766
   int rc = 0;
2672 2767
 
2673 2768
   if (sqliterc == NULL) {
@@ -2678,15 +2773,8 @@ static int process_sqliterc(
2678 2773
 #endif
2679 2774
       return 1;
2680 2775
     }
2681  
-    nBuf = strlen30(home_dir) + 16;
2682  
-    zBuf = malloc( nBuf );
2683  
-    if( zBuf==0 ){
2684  
-      fprintf(stderr,"%s: Error: out of memory\n",Argv0);
2685  
-      return 1;
2686  
-    }
2687  
-    sqlite3_snprintf(nBuf, zBuf,"%s/.sqliterc",home_dir);
2688  
-    free(home_dir);
2689  
-    sqliterc = (const char*)zBuf;
  2776
+    zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
  2777
+    sqliterc = zBuf;
2690 2778
   }
2691 2779
   in = fopen(sqliterc,"rb");
2692 2780
   if( in ){
@@ -2696,7 +2784,7 @@ static int process_sqliterc(
2696 2784
     rc = process_input(p,in);
2697 2785
     fclose(in);
2698 2786
   }
2699  
-  free(zBuf);
  2787
+  sqlite3_free(zBuf);
2700 2788
   return rc;
2701 2789
 }
2702 2790
 
@@ -3043,7 +3131,6 @@ int main(int argc, char **argv){
3043 3131
         write_history(zHistory);
3044 3132
         free(zHistory);
3045 3133
       }
3046  
-      free(zHome);
3047 3134
     }else{
3048 3135
       rc = process_input(&data, stdin);
3049 3136
     }
7,176  external/sqlite/sqlite3.c 100644 → 100755
5629 additions, 1547 deletions not shown
90  external/sqlite/sqlite3.h
@@ -107,9 +107,9 @@ extern "C" {
107 107
 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 108
 ** [sqlite_version()] and [sqlite_source_id()].
109 109
 */
110  
-#define SQLITE_VERSION        "3.7.11"
111  
-#define SQLITE_VERSION_NUMBER 3007011
112  
-#define SQLITE_SOURCE_ID      "2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669"
  110
+#define SQLITE_VERSION        "3.7.13"
  111
+#define SQLITE_VERSION_NUMBER 3007013
  112
+#define SQLITE_SOURCE_ID      "2012-06-11 02:05:22 f5b5a13f7394dc143aa136f1d4faba6839eaa6dc"
113 113
 
114 114
 /*
115 115
 ** CAPI3REF: Run-Time Library Version Numbers
@@ -458,6 +458,7 @@ SQLITE_API int sqlite3_exec(
458 458
 #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
459 459
 #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
460 460
 #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
  461
+#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
461 462
 #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
462 463
 #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
463 464
 #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
@@ -477,6 +478,7 @@ SQLITE_API int sqlite3_exec(
477 478
 #define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
478 479
 #define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
479 480
 #define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
  481
+#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
480 482
 #define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
481 483
 #define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
482 484
 #define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
@@ -771,7 +773,7 @@ struct sqlite3_io_methods {
771 773
 **
772 774
 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
773 775
 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
774  
-** persistent [WAL | Write AHead Log] setting.  By default, the auxiliary
  776
+** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
775 777
 ** write ahead log and shared memory files used for transaction control
776 778
 ** are automatically deleted when the latest connection to the database
777 779
 ** closes.  Setting persistent WAL mode causes those files to persist after
@@ -1547,7 +1549,7 @@ struct sqlite3_mem_methods {
1547 1549
 ** [SQLITE_USE_URI] symbol defined.
1548 1550
 **
1549 1551
 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
1550  
-** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE
  1552
+** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
1551 1553
 ** <dd> These options are obsolete and should not be used by new code.
1552 1554
 ** They are retained for backwards compatibility but are now no-ops.
1553 1555
 ** </dl>
@@ -2168,12 +2170,12 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
2168 2170
 ** implementation of these routines to be omitted.  That capability
2169 2171
 ** is no longer provided.  Only built-in memory allocators can be used.
2170 2172
 **
2171  
-** The Windows OS interface layer calls
  2173
+** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2172 2174
 ** the system malloc() and free() directly when converting
2173 2175
 ** filenames between the UTF-8 encoding used by SQLite
2174 2176
 ** and whatever filename encoding is used by the particular Windows
2175  
-** installation.  Memory allocation errors are detected, but
2176  
-** they are reported back as [SQLITE_CANTOPEN] or
  2177
+** installation.  Memory allocation errors were detected, but
  2178
+** they were reported back as [SQLITE_CANTOPEN] or
2177 2179
 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2178 2180
 **
2179 2181
 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
@@ -2574,18 +2576,20 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2574 2576
 **     present, then the VFS specified by the option takes precedence over
2575 2577
 **     the value passed as the fourth parameter to sqlite3_open_v2().
2576 2578
 **
2577  
-**   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
2578  
-**     "rwc". Attempting to set it to any other value is an error)^. 
  2579
+**   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
  2580
+**     "rwc", or "memory". Attempting to set it to any other value is
  2581
+**     an error)^. 
2579 2582
 **     ^If "ro" is specified, then the database is opened for read-only 
2580 2583
 **     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 
2581 2584
 **     third argument to sqlite3_prepare_v2(). ^If the mode option is set to 
2582 2585
 **     "rw", then the database is opened for read-write (but not create) 
2583 2586
 **     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 
2584 2587
 **     been set. ^Value "rwc" is equivalent to setting both 
2585  
-**     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is 
2586  
-**     used, it is an error to specify a value for the mode parameter that is 
2587  
-**     less restrictive than that specified by the flags passed as the third 
2588  
-**     parameter.
  2588
+**     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
  2589
+**     set to "memory" then a pure [in-memory database] that never reads
  2590
+**     or writes from disk is used. ^It is an error to specify a value for
  2591
+**     the mode parameter that is less restrictive than that specified by
  2592
+**     the flags passed in the third parameter to sqlite3_open_v2().
2589 2593
 **
2590 2594
 **   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
2591 2595
 **     "private". ^Setting it to "shared" is equivalent to setting the
@@ -4449,6 +4453,43 @@ SQLITE_API int sqlite3_sleep(int);
4449 4453
 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
4450 4454
 
4451 4455
 /*
  4456
+** CAPI3REF: Name Of The Folder Holding Database Files
  4457
+**
  4458
+** ^(If this global variable is made to point to a string which is
  4459
+** the name of a folder (a.k.a. directory), then all database files
  4460
+** specified with a relative pathname and created or accessed by
  4461
+** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
  4462
+** to be relative to that directory.)^ ^If this variable is a NULL
  4463
+** pointer, then SQLite assumes that all database files specified
  4464
+** with a relative pathname are relative to the current directory
  4465
+** for the process.  Only the windows VFS makes use of this global
  4466
+** variable; it is ignored by the unix VFS.
  4467
+**
  4468
+** Changing the value of this variable while a database connection is
  4469
+** open can result in a corrupt database.
  4470
+**
  4471
+** It is not safe to read or modify this variable in more than one
  4472
+** thread at a time.  It is not safe to read or modify this variable
  4473
+** if a [database connection] is being used at the same time in a separate
  4474
+** thread.
  4475
+** It is intended that this variable be set once
  4476
+** as part of process initialization and before any SQLite interface
  4477
+** routines have been called and that this variable remain unchanged
  4478
+** thereafter.
  4479
+**
  4480
+** ^The [data_store_directory pragma] may modify this variable and cause
  4481
+** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
  4482
+** the [data_store_directory pragma] always assumes that any string
  4483
+** that this variable points to is held in memory obtained from 
  4484
+** [sqlite3_malloc] and the pragma may attempt to free that memory
  4485
+** using [sqlite3_free].
  4486
+** Hence, if this variable is modified directly, either it should be
  4487
+** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4488
+** or else the use of the [data_store_directory pragma] should be avoided.
  4489
+*/
  4490
+SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
  4491
+
  4492
+/*
4452 4493
 ** CAPI3REF: Test For Auto-Commit Mode
4453 4494
 ** KEYWORDS: {autocommit mode}
4454 4495
 **
@@ -4626,7 +4667,6 @@ SQLITE_API void *sqlite3_update_hook(
4626 4667
 
4627 4668
 /*
4628 4669
 ** CAPI3REF: Enable Or Disable Shared Pager Cache
4629  
-** KEYWORDS: {shared cache}
4630 4670
 **
4631 4671
 ** ^(This routine enables or disables the sharing of the database cache
4632 4672
 ** and schema data structures between [database connection | connections]
@@ -6006,6 +6046,17 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
6006 6046
 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 
6007 6047
 ** is always 0.
6008 6048
 ** </dd>
  6049
+**
  6050
+** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
  6051
+** <dd>This parameter returns the number of dirty cache entries that have
  6052
+** been written to disk. Specifically, the number of pages written to the
  6053
+** wal file in wal mode databases, or the number of pages written to the
  6054
+** database file in rollback mode databases. Any pages written as part of
  6055
+** transaction rollback or database recovery operations are not included.
  6056
+** If an IO or other error occurs while writing a page to disk, the effect
  6057
+** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
  6058
+** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  6059
+** </dd>
6009 6060
 ** </dl>
6010 6061
 */
6011 6062
 #define SQLITE_DBSTATUS_LOOKASIDE_USED       0
@@ -6017,7 +6068,8 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
6017 6068
 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
6018 6069
 #define SQLITE_DBSTATUS_CACHE_HIT            7
6019 6070
 #define SQLITE_DBSTATUS_CACHE_MISS           8
6020  
-#define SQLITE_DBSTATUS_MAX                  8   /* Largest defined DBSTATUS */
  6071
+#define SQLITE_DBSTATUS_CACHE_WRITE          9
  6072
+#define SQLITE_DBSTATUS_MAX                  9   /* Largest defined DBSTATUS */
6021 6073
 
6022 6074
 
6023 6075
 /*
@@ -6973,7 +7025,11 @@ typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6973 7025
 SQLITE_API int sqlite3_rtree_geometry_callback(
6974 7026
   sqlite3 *db,
6975 7027
   const char *zGeom,
6976  
-  int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
  7028
+#ifdef SQLITE_RTREE_INT_ONLY
  7029
+  int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes),
  7030
+#else
  7031
+  int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes),
  7032
+#endif
6977 7033
   void *pContext
6978 7034
 );
6979 7035
 
915  external/uthash/uthash.h
... ...
@@ -0,0 +1,915 @@
  1
+/*
  2
+Copyright (c) 2003-2012, Troy D. Hanson     http://uthash.sourceforge.net
  3
+All rights reserved.
  4
+
  5
+Redistribution and use in source and binary forms, with or without
  6
+modification, are permitted provided that the following conditions are met:
  7
+
  8
+    * Redistributions of source code must retain the above copyright
  9
+      notice, this list of conditions and the following disclaimer.
  10
+
  11
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  12
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  13
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  14
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  15
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22
+*/
  23
+
  24
+#ifndef UTHASH_H
  25
+#define UTHASH_H 
  26
+
  27
+#include <string.h>   /* memcmp,strlen */
  28
+#include <stddef.h>   /* ptrdiff_t */
  29
+#include <stdlib.h>   /* exit() */
  30
+
  31
+/* These macros use decltype or the earlier __typeof GNU extension.
  32
+   As decltype is only available in newer compilers (VS2010 or gcc 4.3+
  33
+   when compiling c++ source) this code uses whatever method is needed
  34
+   or, for VS2008 where neither is available, uses casting workarounds. */
  35
+#ifdef _MSC_VER         /* MS compiler */
  36
+#if _MSC_VER >= 1600 && defined(__cplusplus)  /* VS2010 or newer in C++ mode */
  37
+#define DECLTYPE(x) (decltype(x))
  38
+#else                   /* VS2008 or older (or VS2010 in C mode) */
  39
+#define NO_DECLTYPE
  40
+#define DECLTYPE(x)
  41
+#endif
  42
+#else                   /* GNU, Sun and other compilers */
  43
+#define DECLTYPE(x) (__typeof(x))
  44
+#endif
  45
+
  46
+#ifdef NO_DECLTYPE
  47
+#define DECLTYPE_ASSIGN(dst,src)                                                 \
  48
+do {                                                                             \
  49
+  char **_da_dst = (char**)(&(dst));                                             \
  50
+  *_da_dst = (char*)(src);                                                       \
  51
+} while(0)
  52
+#else 
  53
+#define DECLTYPE_ASSIGN(dst,src)                                                 \
  54
+do {                                                                             \
  55
+  (dst) = DECLTYPE(dst)(src);                                                    \
  56
+} while(0)
  57
+#endif
  58
+
  59
+/* a number of the hash function use uint32_t which isn't defined on win32 */
  60
+#ifdef _MSC_VER
  61
+typedef unsigned int uint32_t;
  62
+typedef unsigned char uint8_t;
  63
+#else
  64
+#include <inttypes.h>   /* uint32_t */
  65
+#endif
  66
+
  67
+#define UTHASH_VERSION 1.9.6
  68
+
  69
+#ifndef uthash_fatal
  70
+#define uthash_fatal(msg) exit(-1)        /* fatal error (out of memory,etc) */
  71
+#endif
  72
+#ifndef uthash_malloc
  73
+#define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
  74
+#endif
  75
+#ifndef uthash_free
  76
+#define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */
  77
+#endif
  78
+
  79
+#ifndef uthash_noexpand_fyi
  80
+#define uthash_noexpand_fyi(tbl)          /* can be defined to log noexpand  */
  81
+#endif
  82
+#ifndef uthash_expand_fyi
  83
+#define uthash_expand_fyi(tbl)            /* can be defined to log expands   */
  84
+#endif
  85
+
  86
+/* initial number of buckets */
  87
+#define HASH_INITIAL_NUM_BUCKETS 32      /* initial number of buckets        */
  88
+#define HASH_INITIAL_NUM_BUCKETS_LOG2 5  /* lg2 of initial number of buckets */
  89
+#define HASH_BKT_CAPACITY_THRESH 10      /* expand when bucket count reaches */
  90
+
  91
+/* calculate the element whose hash handle address is hhe */
  92
+#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))
  93
+
  94
+#define HASH_FIND(hh,head,keyptr,keylen,out)                                     \
  95
+do {                                                                             \
  96
+  unsigned _hf_bkt,_hf_hashv;                                                    \
  97
+  out=NULL;                                                                      \
  98
+  if (head) {                                                                    \
  99
+     HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt);   \
  100
+     if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) {                           \
  101
+       HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ],  \
  102
+                        keyptr,keylen,out);                                      \
  103
+     }                                                                           \
  104
+  }                                                                              \
  105
+} while (0)
  106
+
  107
+#ifdef HASH_BLOOM
  108
+#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM)
  109
+#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0)
  110
+#define HASH_BLOOM_MAKE(tbl)                                                     \
  111
+do {                                                                             \
  112
+  (tbl)->bloom_nbits = HASH_BLOOM;                                               \
  113
+  (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN);                 \
  114
+  if (!((tbl)->bloom_bv))  { uthash_fatal( "out of memory"); }                   \
  115
+  memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN);                                \
  116
+  (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE;                                       \
  117
+} while (0) 
  118
+
  119
+#define HASH_BLOOM_FREE(tbl)                                                     \
  120
+do {                                                                             \
  121
+  uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                              \
  122
+} while (0) 
  123
+
  124
+#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
  125
+#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
  126
+
  127
+#define HASH_BLOOM_ADD(tbl,hashv)                                                \
  128
+  HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
  129
+
  130
+#define HASH_BLOOM_TEST(tbl,hashv)                                               \
  131
+  HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
  132
+
  133
+#else
  134
+#define HASH_BLOOM_MAKE(tbl) 
  135
+#define HASH_BLOOM_FREE(tbl) 
  136
+#define HASH_BLOOM_ADD(tbl,hashv) 
  137
+#define HASH_BLOOM_TEST(tbl,hashv) (1)
  138
+#endif
  139
+
  140
+#define HASH_MAKE_TABLE(hh,head)                                                 \
  141
+do {                                                                             \
  142
+  (head)->hh.tbl = (UT_hash_table*)uthash_malloc(                                \
  143
+                  sizeof(UT_hash_table));                                        \
  144
+  if (!((head)->hh.tbl))  { uthash_fatal( "out of memory"); }                    \
  145
+  memset((head)->hh.tbl, 0, sizeof(UT_hash_table));                              \
  146
+  (head)->hh.tbl->tail = &((head)->hh);                                          \
  147
+  (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS;                        \
  148
+  (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2;              \
  149
+  (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head);                    \
  150
+  (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc(                      \
  151
+          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
  152
+  if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); }             \
  153
+  memset((head)->hh.tbl->buckets, 0,                                             \
  154
+          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
  155
+  HASH_BLOOM_MAKE((head)->hh.tbl);                                               \
  156
+  (head)->hh.tbl->signature = HASH_SIGNATURE;                                    \
  157
+} while(0)
  158
+
  159
+#define HASH_ADD(hh,head,fieldname,keylen_in,add)                                \
  160
+        HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add)
  161
+ 
  162
+#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add)                            \
  163
+do {                                                                             \
  164
+ unsigned _ha_bkt;                                                               \
  165
+ (add)->hh.next = NULL;                                                          \
  166
+ (add)->hh.key = (char*)keyptr;                                                  \