0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20 /*.** Copyright
0010: 28 63 29 20 32 30 30 36 20 44 2e 20 52 69 63 68 (c) 2006 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 53 69 6d 70 6c 69 66 69 65 64 20 42 53 44 20 Simplified BSD
00a0: 4c 69 63 65 6e 73 65 20 28 61 6c 73 6f 0a 2a 2a License (also.**
00b0: 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 32 known as the "2
00c0: 2d 43 6c 61 75 73 65 20 4c 69 63 65 6e 73 65 22 -Clause License"
00d0: 20 6f 72 20 22 46 72 65 65 42 53 44 20 4c 69 63 or "FreeBSD Lic
00e0: 65 6e 73 65 22 2e 29 0a 0a 2a 2a 20 54 68 69 73 ense".)..** This
00f0: 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 74 program is dist
0100: 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 68 ributed in the h
0110: 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c 6c ope that it will
0120: 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 62 be useful,.** b
0130: 75 74 20 77 69 74 68 6f 75 74 20 61 6e 79 20 77 ut without any w
0140: 61 72 72 61 6e 74 79 3b 20 77 69 74 68 6f 75 74 arranty; without
0150: 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 65 even the implie
0160: 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a 2a d warranty of.**
0170: 20 6d 65 72 63 68 61 6e 74 61 62 69 6c 69 74 79 merchantability
0180: 20 6f 72 20 66 69 74 6e 65 73 73 20 66 6f 72 20 or fitness for
0190: 61 20 70 61 72 74 69 63 75 6c 61 72 20 70 75 72 a particular pur
01a0: 70 6f 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 75 74 68 pose..**.** Auth
01b0: 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e 66 6f 72 or contact infor
01c0: 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20 64 72 68 mation:.** drh
01d0: 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a 20 20 20 @hwaci.com.**
01e0: 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77 61 63 69 http://www.hwaci
01f0: 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a 2a 2a 2a .com/drh/.**.***
0200: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0210: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a 2a 0a ************.**.
0250: 2a 2a 20 43 6f 64 65 20 66 6f 72 20 69 6e 74 65 ** Code for inte
0260: 72 66 61 63 69 6e 67 20 74 6f 20 74 68 65 20 76 rfacing to the v
0270: 61 72 69 6f 75 73 20 64 61 74 61 62 61 73 65 73 arious databases
0280: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 20 61 72 ..**.** There ar
0290: 65 20 74 68 72 65 65 20 73 65 70 61 72 61 74 65 e three separate
02a0: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 73 20 database files
02b0: 74 68 61 74 20 66 6f 73 73 69 6c 20 69 6e 74 65 that fossil inte
02c0: 72 61 63 74 73 0a 2a 2a 20 77 69 74 68 3a 0a 2a racts.** with:.*
02d0: 2a 0a 2a 2a 20 20 20 20 28 31 29 20 20 54 68 65 *.** (1) The
02e0: 20 22 75 73 65 72 22 20 64 61 74 61 62 61 73 65 "user" database
02f0: 20 69 6e 20 7e 2f 2e 66 6f 73 73 69 6c 0a 2a 2a in ~/.fossil.**
0300: 0a 2a 2a 20 20 20 20 28 32 29 20 20 54 68 65 20 .** (2) The
0310: 22 72 65 70 6f 73 69 74 6f 72 79 22 20 64 61 74 "repository" dat
0320: 61 62 61 73 65 0a 2a 2a 0a 2a 2a 20 20 20 20 28 abase.**.** (
0330: 33 29 20 20 41 20 6c 6f 63 61 6c 20 63 68 65 63 3) A local chec
0340: 6b 6f 75 74 20 64 61 74 61 62 61 73 65 20 6e 61 kout database na
0350: 6d 65 64 20 22 5f 46 4f 53 53 49 4c 5f 22 20 6f med "_FOSSIL_" o
0360: 72 20 22 2e 66 73 6c 63 6b 6f 75 74 22 0a 2a 2a r ".fslckout".**
0370: 20 20 20 20 20 20 20 20 20 61 6e 64 20 6c 6f 63 and loc
0380: 61 74 65 64 20 61 74 20 74 68 65 20 72 6f 6f 74 ated at the root
0390: 20 6f 66 20 74 68 65 20 6c 6f 63 61 6c 20 63 6f of the local co
03a0: 70 79 20 6f 66 20 74 68 65 20 73 6f 75 72 63 65 py of the source
03b0: 20 74 72 65 65 2e 0a 2a 2a 0a 2a 2f 0a 23 69 6e tree..**.*/.#in
03c0: 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 clude "config.h"
03d0: 0a 23 69 66 20 21 20 64 65 66 69 6e 65 64 28 5f .#if ! defined(_
03e0: 57 49 4e 33 32 29 0a 23 20 20 69 6e 63 6c 75 64 WIN32).# includ
03f0: 65 20 3c 70 77 64 2e 68 3e 0a 23 65 6e 64 69 66 e <pwd.h>.#endif
0400: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 71 6c 69 74 .#include <sqlit
0410: 65 33 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c e3.h>.#include <
0420: 73 79 73 2f 74 79 70 65 73 2e 68 3e 0a 23 69 6e sys/types.h>.#in
0430: 63 6c 75 64 65 20 3c 73 79 73 2f 73 74 61 74 2e clude <sys/stat.
0440: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 75 6e 69 h>.#include <uni
0450: 73 74 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 std.h>.#include
0460: 3c 74 69 6d 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 <time.h>.#includ
0470: 65 20 22 64 62 2e 68 22 0a 0a 23 69 66 20 49 4e e "db.h"..#if IN
0480: 54 45 52 46 41 43 45 0a 2f 2a 0a 2a 2a 20 41 6e TERFACE./*.** An
0490: 20 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 single SQL stat
04a0: 65 6d 65 6e 74 20 69 73 20 72 65 70 72 65 73 65 ement is represe
04b0: 6e 74 65 64 20 61 73 20 61 6e 20 69 6e 73 74 61 nted as an insta
04c0: 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
04d0: 77 69 6e 67 0a 2a 2a 20 73 74 72 75 63 74 75 72 wing.** structur
04e0: 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 74 6d e..*/.struct Stm
04f0: 74 20 7b 0a 20 20 42 6c 6f 62 20 73 71 6c 3b 20 t {. Blob sql;
0500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
0510: 20 54 68 65 20 53 51 4c 20 66 6f 72 20 74 68 69 The SQL for thi
0520: 73 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f 0a 20 s statement */.
0530: 20 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a 70 sqlite3_stmt *p
0540: 53 74 6d 74 3b 20 20 20 20 2f 2a 20 54 68 65 20 Stmt; /* The
0550: 72 65 73 75 6c 74 73 20 6f 66 20 73 71 6c 69 74 results of sqlit
0560: 65 33 5f 70 72 65 70 61 72 65 5f 76 32 28 29 20 e3_prepare_v2()
0570: 2a 2f 0a 20 20 53 74 6d 74 20 2a 70 4e 65 78 74 */. Stmt *pNext
0580: 2c 20 2a 70 50 72 65 76 3b 20 20 20 20 2f 2a 20 , *pPrev; /*
0590: 4c 69 73 74 20 6f 66 20 61 6c 6c 20 75 6e 66 69 List of all unfi
05a0: 6e 61 6c 69 7a 65 64 20 73 74 61 74 65 6d 65 6e nalized statemen
05b0: 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 65 ts */. int nSte
05c0: 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 p;
05d0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 71 6c /* Number of sql
05e0: 69 74 65 33 5f 73 74 65 70 28 29 20 63 61 6c 6c ite3_step() call
05f0: 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 43 s */.};../*.** C
0600: 6f 70 79 20 74 68 69 73 20 74 6f 20 69 6e 69 74 opy this to init
0610: 69 61 6c 69 7a 65 20 61 20 53 74 6d 74 20 6f 62 ialize a Stmt ob
0620: 6a 65 63 74 20 74 6f 20 61 20 63 6c 65 61 6e 2f ject to a clean/
0630: 65 6d 70 74 79 20 73 74 61 74 65 2e 20 54 68 69 empty state. Thi
0640: 73 0a 2a 2a 20 69 73 20 75 73 65 66 75 6c 20 74 s.** is useful t
0650: 6f 20 68 65 6c 70 20 61 76 6f 69 64 20 61 73 73 o help avoid ass
0660: 65 72 74 69 6f 6e 73 20 77 68 65 6e 20 70 65 72 ertions when per
0670: 66 6f 72 6d 69 6e 67 20 63 6c 65 61 6e 75 70 20 forming cleanup
0680: 69 6e 20 73 6f 6d 65 0a 2a 2a 20 65 72 72 6f 72 in some.** error
0690: 20 68 61 6e 64 6c 69 6e 67 20 63 61 73 65 73 2e handling cases.
06a0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 65 6d 70 74 .*/.#define empt
06b0: 79 5f 53 74 6d 74 5f 6d 20 7b 42 4c 4f 42 5f 49 y_Stmt_m {BLOB_I
06c0: 4e 49 54 49 41 4c 49 5a 45 52 2c 4e 55 4c 4c 2c NITIALIZER,NULL,
06d0: 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 30 7d 0a NULL, NULL, 0}.
06e0: 23 65 6e 64 69 66 20 2f 2a 20 49 4e 54 45 52 46 #endif /* INTERF
06f0: 41 43 45 20 2a 2f 0a 63 6f 6e 73 74 20 73 74 72 ACE */.const str
0700: 75 63 74 20 53 74 6d 74 20 65 6d 70 74 79 5f 53 uct Stmt empty_S
0710: 74 6d 74 20 3d 20 65 6d 70 74 79 5f 53 74 6d 74 tmt = empty_Stmt
0720: 5f 6d 3b 0a 0a 2f 2a 0a 2a 2a 20 43 61 6c 6c 20 _m;../*.** Call
0730: 74 68 69 73 20 72 6f 75 74 69 6e 65 20 77 68 65 this routine whe
0740: 6e 20 61 20 64 61 74 61 62 61 73 65 20 65 72 72 n a database err
0750: 6f 72 20 6f 63 63 75 72 73 2e 0a 2a 2f 0a 73 74 or occurs..*/.st
0760: 61 74 69 63 20 76 6f 69 64 20 64 62 5f 65 72 72 atic void db_err
0770: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 6f (const char *zFo
0780: 72 6d 61 74 2c 20 2e 2e 2e 29 7b 0a 20 20 76 61 rmat, ...){. va
0790: 5f 6c 69 73 74 20 61 70 3b 0a 20 20 63 68 61 72 _list ap;. char
07a0: 20 2a 7a 3b 0a 20 20 69 6e 74 20 72 63 20 3d 20 *z;. int rc =
07b0: 31 3b 0a 20 20 73 74 61 74 69 63 20 63 6f 6e 73 1;. static cons
07c0: 74 20 63 68 61 72 20 7a 52 65 62 75 69 6c 64 4d t char zRebuildM
07d0: 73 67 5b 5d 20 3d 0a 20 20 20 20 20 20 22 49 66 sg[] =. "If
07e0: 20 79 6f 75 20 68 61 76 65 20 72 65 63 65 6e 74 you have recent
07f0: 6c 79 20 75 70 64 61 74 65 64 20 79 6f 75 72 20 ly updated your
0800: 66 6f 73 73 69 6c 20 65 78 65 63 75 74 61 62 6c fossil executabl
0810: 65 2c 20 79 6f 75 20 6d 69 67 68 74 5c 6e 22 0a e, you might\n".
0820: 20 20 20 20 20 20 22 6e 65 65 64 20 74 6f 20 72 "need to r
0830: 75 6e 20 5c 22 66 6f 73 73 69 6c 20 61 6c 6c 20 un \"fossil all
0840: 72 65 62 75 69 6c 64 5c 22 20 74 6f 20 62 72 69 rebuild\" to bri
0850: 6e 67 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 ng the repositor
0860: 79 5c 6e 22 0a 20 20 20 20 20 20 22 73 63 68 65 y\n". "sche
0870: 6d 61 73 20 75 70 20 74 6f 20 64 61 74 65 2e 5c mas up to date.\
0880: 6e 22 3b 0a 20 20 76 61 5f 73 74 61 72 74 28 61 n";. va_start(a
0890: 70 2c 20 7a 46 6f 72 6d 61 74 29 3b 0a 20 20 7a p, zFormat);. z
08a0: 20 3d 20 76 6d 70 72 69 6e 74 66 28 7a 46 6f 72 = vmprintf(zFor
08b0: 6d 61 74 2c 20 61 70 29 3b 0a 20 20 76 61 5f 65 mat, ap);. va_e
08c0: 6e 64 28 61 70 29 3b 0a 23 69 66 64 65 66 20 46 nd(ap);.#ifdef F
08d0: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f OSSIL_ENABLE_JSO
08e0: 4e 0a 20 20 69 66 28 20 67 2e 6a 73 6f 6e 2e 69 N. if( g.json.i
08f0: 73 4a 73 6f 6e 4d 6f 64 65 20 29 7b 0a 20 20 20 sJsonMode ){.
0900: 20 6a 73 6f 6e 5f 65 72 72 28 20 30 2c 20 7a 2c json_err( 0, z,
0910: 20 31 20 29 3b 0a 20 20 20 20 69 66 28 20 67 2e 1 );. if( g.
0920: 69 73 48 54 54 50 20 29 7b 0a 20 20 20 20 20 20 isHTTP ){.
0930: 72 63 20 3d 20 30 20 2f 2a 20 61 76 6f 69 64 20 rc = 0 /* avoid
0940: 48 54 54 50 20 35 30 30 20 2a 2f 3b 0a 20 20 20 HTTP 500 */;.
0950: 20 7d 0a 20 20 7d 0a 20 20 65 6c 73 65 0a 23 65 }. }. else.#e
0960: 6e 64 69 66 20 2f 2a 20 46 4f 53 53 49 4c 5f 45 ndif /* FOSSIL_E
0970: 4e 41 42 4c 45 5f 4a 53 4f 4e 20 2a 2f 0a 20 20 NABLE_JSON */.
0980: 69 66 28 20 67 2e 78 66 65 72 50 61 6e 69 63 20 if( g.xferPanic
0990: 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 73 65 74 ){. cgi_reset
09a0: 5f 63 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 _content();.
09b0: 40 20 65 72 72 6f 72 20 44 61 74 61 62 61 73 65 @ error Database
09c0: 5c 73 65 72 72 6f 72 3a 5c 73 25 46 28 7a 29 0a \serror:\s%F(z).
09d0: 20 20 20 20 20 20 63 67 69 5f 72 65 70 6c 79 28 cgi_reply(
09e0: 29 3b 0a 20 20 7d 0a 20 20 65 6c 73 65 20 69 66 );. }. else if
09f0: 28 20 67 2e 63 67 69 4f 75 74 70 75 74 20 29 7b ( g.cgiOutput ){
0a00: 0a 20 20 20 20 67 2e 63 67 69 4f 75 74 70 75 74 . g.cgiOutput
0a10: 20 3d 20 30 3b 0a 20 20 20 20 63 67 69 5f 70 72 = 0;. cgi_pr
0a20: 69 6e 74 66 28 22 3c 68 31 3e 44 61 74 61 62 61 intf("<h1>Databa
0a30: 73 65 20 45 72 72 6f 72 3c 2f 68 31 3e 5c 6e 22 se Error</h1>\n"
0a40: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0a50: 22 3c 70 72 65 3e 25 68 3c 2f 70 72 65 3e 5c 6e "<pre>%h</pre>\n
0a60: 3c 70 3e 25 73 3c 2f 70 3e 5c 6e 22 2c 20 7a 2c <p>%s</p>\n", z,
0a70: 20 7a 52 65 62 75 69 6c 64 4d 73 67 29 3b 0a 20 zRebuildMsg);.
0a80: 20 20 20 63 67 69 5f 72 65 70 6c 79 28 29 3b 0a cgi_reply();.
0a90: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 66 70 72 }else{. fpr
0aa0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 intf(stderr, "%s
0ab0: 3a 20 25 73 5c 6e 5c 6e 25 73 22 2c 20 67 2e 61 : %s\n\n%s", g.a
0ac0: 72 67 76 5b 30 5d 2c 20 7a 2c 20 7a 52 65 62 75 rgv[0], z, zRebu
0ad0: 69 6c 64 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 66 ildMsg);. }. f
0ae0: 72 65 65 28 7a 29 3b 0a 20 20 64 62 5f 66 6f 72 ree(z);. db_for
0af0: 63 65 5f 72 6f 6c 6c 62 61 63 6b 28 29 3b 0a 20 ce_rollback();.
0b00: 20 66 6f 73 73 69 6c 5f 65 78 69 74 28 72 63 29 fossil_exit(rc)
0b10: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 73 ;.}../*.** All s
0b20: 74 61 74 69 63 20 76 61 72 69 61 62 6c 65 20 74 tatic variable t
0b30: 68 61 74 20 61 20 75 73 65 64 20 62 79 20 6f 6e hat a used by on
0b40: 6c 79 20 74 68 69 73 20 66 69 6c 65 20 61 72 65 ly this file are
0b50: 20 67 61 74 68 65 72 65 64 20 69 6e 74 6f 0a 2a gathered into.*
0b60: 2a 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * the following
0b70: 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 structure..*/.st
0b80: 61 74 69 63 20 73 74 72 75 63 74 20 44 62 4c 6f atic struct DbLo
0b90: 63 61 6c 44 61 74 61 20 7b 0a 20 20 69 6e 74 20 calData {. int
0ba0: 6e 42 65 67 69 6e 3b 20 20 20 20 20 20 20 20 20 nBegin;
0bb0: 20 20 20 20 20 20 2f 2a 20 4e 65 73 74 69 6e 67 /* Nesting
0bc0: 20 64 65 70 74 68 20 6f 66 20 42 45 47 49 4e 20 depth of BEGIN
0bd0: 2a 2f 0a 20 20 69 6e 74 20 64 6f 52 6f 6c 6c 62 */. int doRollb
0be0: 61 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 2f ack; /
0bf0: 2a 20 54 72 75 65 20 74 6f 20 66 6f 72 63 65 20 * True to force
0c00: 61 20 72 6f 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 a rollback */.
0c10: 69 6e 74 20 6e 43 6f 6d 6d 69 74 48 6f 6f 6b 3b int nCommitHook;
0c20: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
0c30: 62 65 72 20 6f 66 20 63 6f 6d 6d 69 74 20 68 6f ber of commit ho
0c40: 6f 6b 73 20 2a 2f 0a 20 20 53 74 6d 74 20 2a 70 oks */. Stmt *p
0c50: 41 6c 6c 53 74 6d 74 3b 20 20 20 20 20 20 20 20 AllStmt;
0c60: 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 6c /* List of al
0c70: 6c 20 75 6e 66 69 6e 61 6c 69 7a 65 64 20 73 74 l unfinalized st
0c80: 61 74 65 6d 65 6e 74 73 20 2a 2f 0a 20 20 69 6e atements */. in
0c90: 74 20 6e 50 72 65 70 61 72 65 3b 20 20 20 20 20 t nPrepare;
0ca0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
0cb0: 72 20 6f 66 20 63 61 6c 6c 73 20 74 6f 20 73 71 r of calls to sq
0cc0: 6c 69 74 65 33 5f 70 72 65 70 61 72 65 5f 76 32 lite3_prepare_v2
0cd0: 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 44 65 6c () */. int nDel
0ce0: 65 74 65 4f 6e 46 61 69 6c 3b 20 20 20 20 20 20 eteOnFail;
0cf0: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
0d00: 6e 74 72 69 65 73 20 69 6e 20 61 7a 44 65 6c 65 ntries in azDele
0d10: 74 65 4f 6e 46 61 69 6c 5b 5d 20 2a 2f 0a 20 20 teOnFail[] */.
0d20: 73 74 72 75 63 74 20 73 43 6f 6d 6d 69 74 48 6f struct sCommitHo
0d30: 6f 6b 20 7b 0a 20 20 20 20 69 6e 74 20 28 2a 78 ok {. int (*x
0d40: 48 6f 6f 6b 29 28 76 6f 69 64 29 3b 20 20 20 20 Hook)(void);
0d50: 20 20 20 20 20 2f 2a 20 46 75 6e 63 74 69 6f 6e /* Function
0d60: 73 20 74 6f 20 63 61 6c 6c 20 61 74 20 64 62 5f s to call at db_
0d70: 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 end_transaction(
0d80: 29 20 2a 2f 0a 20 20 20 20 69 6e 74 20 73 65 71 ) */. int seq
0d90: 75 65 6e 63 65 3b 20 20 20 20 20 20 20 20 20 20 uence;
0da0: 20 20 20 20 20 2f 2a 20 43 61 6c 6c 20 66 75 6e /* Call fun
0db0: 63 74 69 6f 6e 73 20 69 6e 20 73 65 71 75 65 6e ctions in sequen
0dc0: 63 65 20 6f 72 64 65 72 20 2a 2f 0a 20 20 7d 20 ce order */. }
0dd0: 61 48 6f 6f 6b 5b 35 5d 3b 0a 20 20 63 68 61 72 aHook[5];. char
0de0: 20 2a 61 7a 44 65 6c 65 74 65 4f 6e 46 61 69 6c *azDeleteOnFail
0df0: 5b 33 5d 3b 20 20 2f 2a 20 46 69 6c 65 73 20 74 [3]; /* Files t
0e00: 6f 20 64 65 6c 65 74 65 20 6f 6e 20 61 20 66 61 o delete on a fa
0e10: 69 6c 75 72 65 20 2a 2f 0a 20 20 63 68 61 72 20 ilure */. char
0e20: 2a 61 7a 42 65 66 6f 72 65 43 6f 6d 6d 69 74 5b *azBeforeCommit[
0e30: 35 5d 3b 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 73 5]; /* Commands
0e40: 20 74 6f 20 72 75 6e 20 70 72 69 6f 72 20 74 6f to run prior to
0e50: 20 43 4f 4d 4d 49 54 20 2a 2f 0a 20 20 69 6e 74 COMMIT */. int
0e60: 20 6e 42 65 66 6f 72 65 43 6f 6d 6d 69 74 3b 20 nBeforeCommit;
0e70: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
0e80: 20 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 of entries in a
0e90: 7a 42 65 66 6f 72 65 43 6f 6d 6d 69 74 20 2a 2f zBeforeCommit */
0ea0: 0a 20 20 69 6e 74 20 6e 50 72 69 6f 72 43 68 61 . int nPriorCha
0eb0: 6e 67 65 73 3b 20 20 20 20 20 20 20 20 2f 2a 20 nges; /*
0ec0: 73 71 6c 69 74 65 33 5f 74 6f 74 61 6c 5f 63 68 sqlite3_total_ch
0ed0: 61 6e 67 65 73 28 29 20 61 74 20 74 72 61 6e 73 anges() at trans
0ee0: 61 63 74 69 6f 6e 20 73 74 61 72 74 20 2a 2f 0a action start */.
0ef0: 7d 20 64 62 20 3d 20 7b 30 2c 20 30 2c 20 30 2c } db = {0, 0, 0,
0f00: 20 30 2c 20 30 2c 20 30 2c 20 7d 3b 0a 0a 2f 2a 0, 0, 0, };../*
0f10: 0a 2a 2a 20 41 72 72 61 6e 67 65 20 66 6f 72 20 .** Arrange for
0f20: 74 68 65 20 67 69 76 65 6e 20 66 69 6c 65 20 74 the given file t
0f30: 6f 20 62 65 20 64 65 6c 65 74 65 64 20 6f 6e 20 o be deleted on
0f40: 61 20 66 61 69 6c 75 72 65 2e 0a 2a 2f 0a 76 6f a failure..*/.vo
0f50: 69 64 20 64 62 5f 64 65 6c 65 74 65 5f 6f 6e 5f id db_delete_on_
0f60: 66 61 69 6c 75 72 65 28 63 6f 6e 73 74 20 63 68 failure(const ch
0f70: 61 72 20 2a 7a 46 69 6c 65 6e 61 6d 65 29 7b 0a ar *zFilename){.
0f80: 20 20 61 73 73 65 72 74 28 20 64 62 2e 6e 44 65 assert( db.nDe
0f90: 6c 65 74 65 4f 6e 46 61 69 6c 3c 63 6f 75 6e 74 leteOnFail<count
0fa0: 28 64 62 2e 61 7a 44 65 6c 65 74 65 4f 6e 46 61 (db.azDeleteOnFa
0fb0: 69 6c 29 20 29 3b 0a 20 20 64 62 2e 61 7a 44 65 il) );. db.azDe
0fc0: 6c 65 74 65 4f 6e 46 61 69 6c 5b 64 62 2e 6e 44 leteOnFail[db.nD
0fd0: 65 6c 65 74 65 4f 6e 46 61 69 6c 2b 2b 5d 20 3d eleteOnFail++] =
0fe0: 20 66 6f 73 73 69 6c 5f 73 74 72 64 75 70 28 7a fossil_strdup(z
0ff0: 46 69 6c 65 6e 61 6d 65 29 3b 0a 7d 0a 0a 2f 2a Filename);.}../*
1000: 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e 65 .** This routine
1010: 20 69 73 20 63 61 6c 6c 65 64 20 62 79 20 74 68 is called by th
1020: 65 20 53 51 4c 69 74 65 20 63 6f 6d 6d 69 74 2d e SQLite commit-
1030: 68 6f 6f 6b 20 6d 65 63 68 61 6e 69 73 6d 0a 2a hook mechanism.*
1040: 2a 20 6a 75 73 74 20 70 72 69 6f 72 20 74 6f 20 * just prior to
1050: 65 61 63 68 20 63 6f 6d 6d 69 74 2e 20 20 41 6c each commit. Al
1060: 6c 20 74 68 69 73 20 72 6f 75 74 69 6e 65 20 64 l this routine d
1070: 6f 65 73 20 69 73 20 76 65 72 69 66 79 0a 2a 2a oes is verify.**
1080: 20 74 68 61 74 20 6e 42 65 67 69 6e 20 72 65 61 that nBegin rea
1090: 6c 6c 79 20 69 73 20 7a 65 72 6f 2e 20 20 54 68 lly is zero. Th
10a0: 61 74 20 69 6e 73 75 72 65 73 20 74 68 61 74 20 at insures that
10b0: 74 72 61 6e 73 61 63 74 69 6f 6e 73 0a 2a 2a 20 transactions.**
10c0: 63 61 6e 6e 6f 74 20 63 6f 6d 6d 69 74 20 62 79 cannot commit by
10d0: 20 61 6e 79 20 6d 65 61 6e 73 20 6f 74 68 65 72 any means other
10e0: 20 74 68 61 6e 20 62 79 20 63 61 6c 6c 69 6e 67 than by calling
10f0: 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 db_end_transact
1100: 69 6f 6e 28 29 0a 2a 2a 20 62 65 6c 6f 77 2e 0a ion().** below..
1110: 2a 2a 0a 2a 2a 20 54 68 69 73 20 69 73 20 6a 75 **.** This is ju
1120: 73 74 20 61 20 73 61 66 65 74 79 20 61 6e 64 20 st a safety and
1130: 73 61 6e 69 74 79 20 63 68 65 63 6b 2e 0a 2a 2f sanity check..*/
1140: 0a 73 74 61 74 69 63 20 69 6e 74 20 64 62 5f 76 .static int db_v
1150: 65 72 69 66 79 5f 61 74 5f 63 6f 6d 6d 69 74 28 erify_at_commit(
1160: 76 6f 69 64 20 2a 6e 6f 74 55 73 65 64 29 7b 0a void *notUsed){.
1170: 20 20 69 66 28 20 64 62 2e 6e 42 65 67 69 6e 20 if( db.nBegin
1180: 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 ){. fossil_pa
1190: 6e 69 63 28 22 69 6c 6c 65 67 61 6c 20 63 6f 6d nic("illegal com
11a0: 6d 69 74 20 61 74 74 65 6d 70 74 22 29 3b 0a 20 mit attempt");.
11b0: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 7d return 1;. }
11c0: 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a . return 0;.}..
11d0: 2f 2a 0a 2a 2a 20 42 65 67 69 6e 20 61 6e 64 20 /*.** Begin and
11e0: 65 6e 64 20 61 20 6e 65 73 74 65 64 20 74 72 61 end a nested tra
11f0: 6e 73 61 63 74 69 6f 6e 0a 2a 2f 0a 76 6f 69 64 nsaction.*/.void
1200: 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 db_begin_transa
1210: 63 74 69 6f 6e 28 76 6f 69 64 29 7b 0a 20 20 69 ction(void){. i
1220: 66 28 20 64 62 2e 6e 42 65 67 69 6e 3d 3d 30 20 f( db.nBegin==0
1230: 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f ){. db_multi_
1240: 65 78 65 63 28 22 42 45 47 49 4e 22 29 3b 0a 20 exec("BEGIN");.
1250: 20 20 20 73 71 6c 69 74 65 33 5f 63 6f 6d 6d 69 sqlite3_commi
1260: 74 5f 68 6f 6f 6b 28 67 2e 64 62 2c 20 64 62 5f t_hook(g.db, db_
1270: 76 65 72 69 66 79 5f 61 74 5f 63 6f 6d 6d 69 74 verify_at_commit
1280: 2c 20 30 29 3b 0a 20 20 20 20 64 62 2e 6e 50 72 , 0);. db.nPr
1290: 69 6f 72 43 68 61 6e 67 65 73 20 3d 20 73 71 6c iorChanges = sql
12a0: 69 74 65 33 5f 74 6f 74 61 6c 5f 63 68 61 6e 67 ite3_total_chang
12b0: 65 73 28 67 2e 64 62 29 3b 0a 20 20 7d 0a 20 20 es(g.db);. }.
12c0: 64 62 2e 6e 42 65 67 69 6e 2b 2b 3b 0a 7d 0a 76 db.nBegin++;.}.v
12d0: 6f 69 64 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 oid db_end_trans
12e0: 61 63 74 69 6f 6e 28 69 6e 74 20 72 6f 6c 6c 62 action(int rollb
12f0: 61 63 6b 46 6c 61 67 29 7b 0a 20 20 69 66 28 20 ackFlag){. if(
1300: 67 2e 64 62 3d 3d 30 20 29 20 72 65 74 75 72 6e g.db==0 ) return
1310: 3b 0a 20 20 69 66 28 20 64 62 2e 6e 42 65 67 69 ;. if( db.nBegi
1320: 6e 3c 3d 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 n<=0 ) return;.
1330: 20 69 66 28 20 72 6f 6c 6c 62 61 63 6b 46 6c 61 if( rollbackFla
1340: 67 20 29 20 64 62 2e 64 6f 52 6f 6c 6c 62 61 63 g ) db.doRollbac
1350: 6b 20 3d 20 31 3b 0a 20 20 64 62 2e 6e 42 65 67 k = 1;. db.nBeg
1360: 69 6e 2d 2d 3b 0a 20 20 69 66 28 20 64 62 2e 6e in--;. if( db.n
1370: 42 65 67 69 6e 3d 3d 30 20 29 7b 0a 20 20 20 20 Begin==0 ){.
1380: 69 6e 74 20 69 3b 0a 20 20 20 20 69 66 28 20 64 int i;. if( d
1390: 62 2e 64 6f 52 6f 6c 6c 62 61 63 6b 3d 3d 30 20 b.doRollback==0
13a0: 26 26 20 64 62 2e 6e 50 72 69 6f 72 43 68 61 6e && db.nPriorChan
13b0: 67 65 73 3c 73 71 6c 69 74 65 33 5f 74 6f 74 61 ges<sqlite3_tota
13c0: 6c 5f 63 68 61 6e 67 65 73 28 67 2e 64 62 29 20 l_changes(g.db)
13d0: 29 7b 0a 20 20 20 20 20 20 77 68 69 6c 65 28 20 ){. while(
13e0: 64 62 2e 6e 42 65 66 6f 72 65 43 6f 6d 6d 69 74 db.nBeforeCommit
13f0: 20 29 7b 0a 20 20 20 20 20 20 20 20 64 62 2e 6e ){. db.n
1400: 42 65 66 6f 72 65 43 6f 6d 6d 69 74 2d 2d 3b 0a BeforeCommit--;.
1410: 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f sqlite3_
1420: 65 78 65 63 28 67 2e 64 62 2c 20 64 62 2e 61 7a exec(g.db, db.az
1430: 42 65 66 6f 72 65 43 6f 6d 6d 69 74 5b 64 62 2e BeforeCommit[db.
1440: 6e 42 65 66 6f 72 65 43 6f 6d 6d 69 74 5d 2c 20 nBeforeCommit],
1450: 30 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 0, 0, 0);.
1460: 20 20 73 71 6c 69 74 65 33 5f 66 72 65 65 28 64 sqlite3_free(d
1470: 62 2e 61 7a 42 65 66 6f 72 65 43 6f 6d 6d 69 74 b.azBeforeCommit
1480: 5b 64 62 2e 6e 42 65 66 6f 72 65 43 6f 6d 6d 69 [db.nBeforeCommi
1490: 74 5d 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 t]);. }.
14a0: 20 20 20 6c 65 61 66 5f 64 6f 5f 70 65 6e 64 69 leaf_do_pendi
14b0: 6e 67 5f 63 68 65 63 6b 73 28 29 3b 0a 20 20 20 ng_checks();.
14c0: 20 7d 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 }. for(i=0;
14d0: 64 62 2e 64 6f 52 6f 6c 6c 62 61 63 6b 3d 3d 30 db.doRollback==0
14e0: 20 26 26 20 69 3c 64 62 2e 6e 43 6f 6d 6d 69 74 && i<db.nCommit
14f0: 48 6f 6f 6b 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 Hook; i++){.
1500: 20 20 64 62 2e 64 6f 52 6f 6c 6c 62 61 63 6b 20 db.doRollback
1510: 7c 3d 20 64 62 2e 61 48 6f 6f 6b 5b 69 5d 2e 78 |= db.aHook[i].x
1520: 48 6f 6f 6b 28 29 3b 0a 20 20 20 20 7d 0a 20 20 Hook();. }.
1530: 20 20 77 68 69 6c 65 28 20 64 62 2e 70 41 6c 6c while( db.pAll
1540: 53 74 6d 74 20 29 7b 0a 20 20 20 20 20 20 64 62 Stmt ){. db
1550: 5f 66 69 6e 61 6c 69 7a 65 28 64 62 2e 70 41 6c _finalize(db.pAl
1560: 6c 53 74 6d 74 29 3b 0a 20 20 20 20 7d 0a 20 20 lStmt);. }.
1570: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
1580: 64 62 2e 64 6f 52 6f 6c 6c 62 61 63 6b 20 3f 20 db.doRollback ?
1590: 22 52 4f 4c 4c 42 41 43 4b 22 20 3a 20 22 43 4f "ROLLBACK" : "CO
15a0: 4d 4d 49 54 22 29 3b 0a 20 20 20 20 64 62 2e 64 MMIT");. db.d
15b0: 6f 52 6f 6c 6c 62 61 63 6b 20 3d 20 30 3b 0a 20 oRollback = 0;.
15c0: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 63 }.}../*.** Forc
15d0: 65 20 61 20 72 6f 6c 6c 62 61 63 6b 20 61 6e 64 e a rollback and
15e0: 20 73 68 75 74 64 6f 77 6e 20 74 68 65 20 64 61 shutdown the da
15f0: 74 61 62 61 73 65 0a 2a 2f 0a 76 6f 69 64 20 64 tabase.*/.void d
1600: 62 5f 66 6f 72 63 65 5f 72 6f 6c 6c 62 61 63 6b b_force_rollback
1610: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 3b (void){. int i;
1620: 0a 20 20 73 74 61 74 69 63 20 69 6e 74 20 62 75 . static int bu
1630: 73 79 20 3d 20 30 3b 0a 20 20 73 71 6c 69 74 65 sy = 0;. sqlite
1640: 33 5f 73 74 6d 74 20 2a 70 53 74 6d 74 20 3d 20 3_stmt *pStmt =
1650: 30 3b 0a 20 20 69 66 28 20 62 75 73 79 20 7c 7c 0;. if( busy ||
1660: 20 67 2e 64 62 3d 3d 30 20 29 20 72 65 74 75 72 g.db==0 ) retur
1670: 6e 3b 0a 20 20 62 75 73 79 20 3d 20 31 3b 0a 20 n;. busy = 1;.
1680: 20 75 6e 64 6f 5f 72 6f 6c 6c 62 61 63 6b 28 29 undo_rollback()
1690: 3b 0a 20 20 77 68 69 6c 65 28 20 28 70 53 74 6d ;. while( (pStm
16a0: 74 20 3d 20 73 71 6c 69 74 65 33 5f 6e 65 78 74 t = sqlite3_next
16b0: 5f 73 74 6d 74 28 67 2e 64 62 2c 70 53 74 6d 74 _stmt(g.db,pStmt
16c0: 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 73 71 6c ))!=0 ){. sql
16d0: 69 74 65 33 5f 72 65 73 65 74 28 70 53 74 6d 74 ite3_reset(pStmt
16e0: 29 3b 0a 20 20 7d 0a 20 20 77 68 69 6c 65 28 20 );. }. while(
16f0: 64 62 2e 70 41 6c 6c 53 74 6d 74 20 29 7b 0a 20 db.pAllStmt ){.
1700: 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 64 db_finalize(d
1710: 62 2e 70 41 6c 6c 53 74 6d 74 29 3b 0a 20 20 7d b.pAllStmt);. }
1720: 0a 20 20 69 66 28 20 64 62 2e 6e 42 65 67 69 6e . if( db.nBegin
1730: 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f ){. sqlite3_
1740: 65 78 65 63 28 67 2e 64 62 2c 20 22 52 4f 4c 4c exec(g.db, "ROLL
1750: 42 41 43 4b 22 2c 20 30 2c 20 30 2c 20 30 29 3b BACK", 0, 0, 0);
1760: 0a 20 20 20 20 64 62 2e 6e 42 65 67 69 6e 20 3d . db.nBegin =
1770: 20 30 3b 0a 20 20 7d 0a 20 20 62 75 73 79 20 3d 0;. }. busy =
1780: 20 30 3b 0a 20 20 64 62 5f 63 6c 6f 73 65 28 30 0;. db_close(0
1790: 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c );. for(i=0; i<
17a0: 64 62 2e 6e 44 65 6c 65 74 65 4f 6e 46 61 69 6c db.nDeleteOnFail
17b0: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 66 69 6c 65 ; i++){. file
17c0: 5f 64 65 6c 65 74 65 28 64 62 2e 61 7a 44 65 6c _delete(db.azDel
17d0: 65 74 65 4f 6e 46 61 69 6c 5b 69 5d 29 3b 0a 20 eteOnFail[i]);.
17e0: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 6e 73 74 }.}../*.** Inst
17f0: 61 6c 6c 20 61 20 63 6f 6d 6d 69 74 20 68 6f 6f all a commit hoo
1800: 6b 2e 20 20 48 6f 6f 6b 73 20 61 72 65 20 69 6e k. Hooks are in
1810: 73 74 61 6c 6c 65 64 20 69 6e 20 73 65 71 75 65 stalled in seque
1820: 6e 63 65 20 6f 72 64 65 72 2e 0a 2a 2a 20 49 74 nce order..** It
1830: 20 69 73 20 61 6e 20 65 72 72 6f 72 20 74 6f 20 is an error to
1840: 69 6e 73 74 61 6c 6c 20 74 68 65 20 73 61 6d 65 install the same
1850: 20 63 6f 6d 6d 69 74 20 68 6f 6f 6b 20 6d 6f 72 commit hook mor
1860: 65 20 74 68 61 6e 20 6f 6e 63 65 2e 0a 2a 2a 0a e than once..**.
1870: 2a 2a 20 45 61 63 68 20 63 6f 6d 6d 69 74 20 68 ** Each commit h
1880: 6f 6f 6b 20 69 73 20 63 61 6c 6c 65 64 20 28 69 ook is called (i
1890: 6e 20 6f 72 64 65 72 20 6f 66 20 61 73 63 65 6e n order of ascen
18a0: 64 69 6e 67 20 73 65 71 75 65 6e 63 65 29 20 61 ding sequence) a
18b0: 74 0a 2a 2a 20 65 61 63 68 20 63 6f 6d 6d 69 74 t.** each commit
18c0: 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 49 66 20 operation. If
18d0: 61 6e 79 20 63 6f 6d 6d 69 74 20 68 6f 6f 6b 20 any commit hook
18e0: 72 65 74 75 72 6e 73 20 6e 6f 6e 2d 7a 65 72 6f returns non-zero
18f0: 2c 0a 2a 2a 20 74 68 65 20 73 75 62 73 65 71 75 ,.** the subsequ
1900: 65 6e 63 65 20 63 6f 6d 6d 69 74 20 68 6f 6f 6b ence commit hook
1910: 73 20 61 72 65 20 6f 6d 69 74 74 65 64 20 61 6e s are omitted an
1920: 64 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f d the transactio
1930: 6e 0a 2a 2a 20 72 6f 6c 6c 73 20 62 61 63 6b 20 n.** rolls back
1940: 72 61 74 68 65 72 20 74 68 61 6e 20 63 6f 6d 6d rather than comm
1950: 69 74 2e 20 20 49 74 20 69 73 20 74 68 65 20 72 it. It is the r
1960: 65 73 70 6f 6e 73 69 62 69 6c 69 74 79 20 6f 66 esponsibility of
1970: 20 74 68 65 0a 2a 2a 20 68 6f 6f 6b 73 20 74 68 the.** hooks th
1980: 65 6d 73 65 6c 76 65 73 20 74 6f 20 69 73 73 75 emselves to issu
1990: 65 20 61 6e 79 20 65 72 72 6f 72 20 6d 65 73 73 e any error mess
19a0: 61 67 65 73 2e 0a 2a 2f 0a 76 6f 69 64 20 64 62 ages..*/.void db
19b0: 5f 63 6f 6d 6d 69 74 5f 68 6f 6f 6b 28 69 6e 74 _commit_hook(int
19c0: 20 28 2a 78 29 28 76 6f 69 64 29 2c 20 69 6e 74 (*x)(void), int
19d0: 20 73 65 71 75 65 6e 63 65 29 7b 0a 20 20 69 6e sequence){. in
19e0: 74 20 69 3b 0a 20 20 61 73 73 65 72 74 28 20 64 t i;. assert( d
19f0: 62 2e 6e 43 6f 6d 6d 69 74 48 6f 6f 6b 20 3c 20 b.nCommitHook <
1a00: 63 6f 75 6e 74 28 64 62 2e 61 48 6f 6f 6b 29 20 count(db.aHook)
1a10: 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c );. for(i=0; i<
1a20: 64 62 2e 6e 43 6f 6d 6d 69 74 48 6f 6f 6b 3b 20 db.nCommitHook;
1a30: 69 2b 2b 29 7b 0a 20 20 20 20 61 73 73 65 72 74 i++){. assert
1a40: 28 20 78 21 3d 64 62 2e 61 48 6f 6f 6b 5b 69 5d ( x!=db.aHook[i]
1a50: 2e 78 48 6f 6f 6b 20 29 3b 0a 20 20 20 20 69 66 .xHook );. if
1a60: 28 20 64 62 2e 61 48 6f 6f 6b 5b 69 5d 2e 73 65 ( db.aHook[i].se
1a70: 71 75 65 6e 63 65 3e 73 65 71 75 65 6e 63 65 20 quence>sequence
1a80: 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 73 20 3d ){. int s =
1a90: 20 73 65 71 75 65 6e 63 65 3b 0a 20 20 20 20 20 sequence;.
1aa0: 20 69 6e 74 20 28 2a 78 53 29 28 76 6f 69 64 29 int (*xS)(void)
1ab0: 20 3d 20 78 3b 0a 20 20 20 20 20 20 73 65 71 75 = x;. sequ
1ac0: 65 6e 63 65 20 3d 20 64 62 2e 61 48 6f 6f 6b 5b ence = db.aHook[
1ad0: 69 5d 2e 73 65 71 75 65 6e 63 65 3b 0a 20 20 20 i].sequence;.
1ae0: 20 20 20 78 20 3d 20 64 62 2e 61 48 6f 6f 6b 5b x = db.aHook[
1af0: 69 5d 2e 78 48 6f 6f 6b 3b 0a 20 20 20 20 20 20 i].xHook;.
1b00: 64 62 2e 61 48 6f 6f 6b 5b 69 5d 2e 73 65 71 75 db.aHook[i].sequ
1b10: 65 6e 63 65 20 3d 20 73 3b 0a 20 20 20 20 20 20 ence = s;.
1b20: 64 62 2e 61 48 6f 6f 6b 5b 69 5d 2e 78 48 6f 6f db.aHook[i].xHoo
1b30: 6b 20 3d 20 78 53 3b 0a 20 20 20 20 7d 0a 20 20 k = xS;. }.
1b40: 7d 0a 20 20 64 62 2e 61 48 6f 6f 6b 5b 64 62 2e }. db.aHook[db.
1b50: 6e 43 6f 6d 6d 69 74 48 6f 6f 6b 5d 2e 73 65 71 nCommitHook].seq
1b60: 75 65 6e 63 65 20 3d 20 73 65 71 75 65 6e 63 65 uence = sequence
1b70: 3b 0a 20 20 64 62 2e 61 48 6f 6f 6b 5b 64 62 2e ;. db.aHook[db.
1b80: 6e 43 6f 6d 6d 69 74 48 6f 6f 6b 5d 2e 78 48 6f nCommitHook].xHo
1b90: 6f 6b 20 3d 20 78 3b 0a 20 20 64 62 2e 6e 43 6f ok = x;. db.nCo
1ba0: 6d 6d 69 74 48 6f 6f 6b 2b 2b 3b 0a 7d 0a 0a 2f mmitHook++;.}../
1bb0: 2a 0a 2a 2a 20 50 72 65 70 61 72 65 20 61 20 53 *.** Prepare a S
1bc0: 74 6d 74 2e 20 20 41 73 73 75 6d 65 20 74 68 61 tmt. Assume tha
1bd0: 74 20 74 68 65 20 53 74 6d 74 20 69 73 20 70 72 t the Stmt is pr
1be0: 65 76 69 6f 75 73 6c 79 20 75 6e 69 6e 69 74 69 eviously uniniti
1bf0: 61 6c 69 7a 65 64 2e 0a 2a 2a 20 49 66 20 74 68 alized..** If th
1c00: 65 20 69 6e 70 75 74 20 73 74 72 69 6e 67 20 63 e input string c
1c10: 6f 6e 74 61 69 6e 73 20 6d 75 6c 74 69 70 6c 65 ontains multiple
1c20: 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 2c SQL statements,
1c30: 20 6f 6e 6c 79 20 74 68 65 20 66 69 72 73 74 0a only the first.
1c40: 2a 2a 20 6f 6e 65 20 69 73 20 70 72 6f 63 65 73 ** one is proces
1c50: 73 65 64 2e 20 20 41 6c 6c 20 73 74 61 74 65 6d sed. All statem
1c60: 65 6e 74 73 20 62 65 79 6f 6e 64 20 74 68 65 20 ents beyond the
1c70: 66 69 72 73 74 20 61 72 65 20 73 69 6c 65 6e 74 first are silent
1c80: 6c 79 20 69 67 6e 6f 72 65 64 2e 0a 2a 2f 0a 69 ly ignored..*/.i
1c90: 6e 74 20 64 62 5f 76 70 72 65 70 61 72 65 28 53 nt db_vprepare(S
1ca0: 74 6d 74 20 2a 70 53 74 6d 74 2c 20 69 6e 74 20 tmt *pStmt, int
1cb0: 65 72 72 4f 6b 2c 20 63 6f 6e 73 74 20 63 68 61 errOk, const cha
1cc0: 72 20 2a 7a 46 6f 72 6d 61 74 2c 20 76 61 5f 6c r *zFormat, va_l
1cd0: 69 73 74 20 61 70 29 7b 0a 20 20 69 6e 74 20 72 ist ap){. int r
1ce0: 63 3b 0a 20 20 63 68 61 72 20 2a 7a 53 71 6c 3b c;. char *zSql;
1cf0: 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 70 53 . blob_zero(&pS
1d00: 74 6d 74 2d 3e 73 71 6c 29 3b 0a 20 20 62 6c 6f tmt->sql);. blo
1d10: 62 5f 76 61 70 70 65 6e 64 66 28 26 70 53 74 6d b_vappendf(&pStm
1d20: 74 2d 3e 73 71 6c 2c 20 7a 46 6f 72 6d 61 74 2c t->sql, zFormat,
1d30: 20 61 70 29 3b 0a 20 20 76 61 5f 65 6e 64 28 61 ap);. va_end(a
1d40: 70 29 3b 0a 20 20 7a 53 71 6c 20 3d 20 62 6c 6f p);. zSql = blo
1d50: 62 5f 73 74 72 28 26 70 53 74 6d 74 2d 3e 73 71 b_str(&pStmt->sq
1d60: 6c 29 3b 0a 20 20 64 62 2e 6e 50 72 65 70 61 72 l);. db.nPrepar
1d70: 65 2b 2b 3b 0a 20 20 72 63 20 3d 20 73 71 6c 69 e++;. rc = sqli
1d80: 74 65 33 5f 70 72 65 70 61 72 65 5f 76 32 28 67 te3_prepare_v2(g
1d90: 2e 64 62 2c 20 7a 53 71 6c 2c 20 2d 31 2c 20 26 .db, zSql, -1, &
1da0: 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 30 29 pStmt->pStmt, 0)
1db0: 3b 0a 20 20 69 66 28 20 72 63 21 3d 30 20 26 26 ;. if( rc!=0 &&
1dc0: 20 21 65 72 72 4f 6b 20 29 7b 0a 20 20 20 20 64 !errOk ){. d
1dd0: 62 5f 65 72 72 28 22 25 73 5c 6e 25 73 22 2c 20 b_err("%s\n%s",
1de0: 73 71 6c 69 74 65 33 5f 65 72 72 6d 73 67 28 67 sqlite3_errmsg(g
1df0: 2e 64 62 29 2c 20 7a 53 71 6c 29 3b 0a 20 20 7d .db), zSql);. }
1e00: 0a 20 20 70 53 74 6d 74 2d 3e 70 4e 65 78 74 20 . pStmt->pNext
1e10: 3d 20 70 53 74 6d 74 2d 3e 70 50 72 65 76 20 3d = pStmt->pPrev =
1e20: 20 30 3b 0a 20 20 70 53 74 6d 74 2d 3e 6e 53 74 0;. pStmt->nSt
1e30: 65 70 20 3d 20 30 3b 0a 20 20 72 65 74 75 72 6e ep = 0;. return
1e40: 20 72 63 3b 0a 7d 0a 69 6e 74 20 64 62 5f 70 72 rc;.}.int db_pr
1e50: 65 70 61 72 65 28 53 74 6d 74 20 2a 70 53 74 6d epare(Stmt *pStm
1e60: 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a t, const char *z
1e70: 46 6f 72 6d 61 74 2c 20 2e 2e 2e 29 7b 0a 20 20 Format, ...){.
1e80: 69 6e 74 20 72 63 3b 0a 20 20 76 61 5f 6c 69 73 int rc;. va_lis
1e90: 74 20 61 70 3b 0a 20 20 76 61 5f 73 74 61 72 74 t ap;. va_start
1ea0: 28 61 70 2c 20 7a 46 6f 72 6d 61 74 29 3b 0a 20 (ap, zFormat);.
1eb0: 20 72 63 20 3d 20 64 62 5f 76 70 72 65 70 61 72 rc = db_vprepar
1ec0: 65 28 70 53 74 6d 74 2c 20 30 2c 20 7a 46 6f 72 e(pStmt, 0, zFor
1ed0: 6d 61 74 2c 20 61 70 29 3b 0a 20 20 76 61 5f 65 mat, ap);. va_e
1ee0: 6e 64 28 61 70 29 3b 0a 20 20 72 65 74 75 72 6e nd(ap);. return
1ef0: 20 72 63 3b 0a 7d 0a 69 6e 74 20 64 62 5f 70 72 rc;.}.int db_pr
1f00: 65 70 61 72 65 5f 69 67 6e 6f 72 65 5f 65 72 72 epare_ignore_err
1f10: 6f 72 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c 20 or(Stmt *pStmt,
1f20: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 6f 72 const char *zFor
1f30: 6d 61 74 2c 20 2e 2e 2e 29 7b 0a 20 20 69 6e 74 mat, ...){. int
1f40: 20 72 63 3b 0a 20 20 76 61 5f 6c 69 73 74 20 61 rc;. va_list a
1f50: 70 3b 0a 20 20 76 61 5f 73 74 61 72 74 28 61 70 p;. va_start(ap
1f60: 2c 20 7a 46 6f 72 6d 61 74 29 3b 0a 20 20 72 63 , zFormat);. rc
1f70: 20 3d 20 64 62 5f 76 70 72 65 70 61 72 65 28 70 = db_vprepare(p
1f80: 53 74 6d 74 2c 20 31 2c 20 7a 46 6f 72 6d 61 74 Stmt, 1, zFormat
1f90: 2c 20 61 70 29 3b 0a 20 20 76 61 5f 65 6e 64 28 , ap);. va_end(
1fa0: 61 70 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 ap);. return rc
1fb0: 3b 0a 7d 0a 69 6e 74 20 64 62 5f 73 74 61 74 69 ;.}.int db_stati
1fc0: 63 5f 70 72 65 70 61 72 65 28 53 74 6d 74 20 2a c_prepare(Stmt *
1fd0: 70 53 74 6d 74 2c 20 63 6f 6e 73 74 20 63 68 61 pStmt, const cha
1fe0: 72 20 2a 7a 46 6f 72 6d 61 74 2c 20 2e 2e 2e 29 r *zFormat, ...)
1ff0: 7b 0a 20 20 69 6e 74 20 72 63 20 3d 20 53 51 4c {. int rc = SQL
2000: 49 54 45 5f 4f 4b 3b 0a 20 20 69 66 28 20 62 6c ITE_OK;. if( bl
2010: 6f 62 5f 73 69 7a 65 28 26 70 53 74 6d 74 2d 3e ob_size(&pStmt->
2020: 73 71 6c 29 3d 3d 30 20 29 7b 0a 20 20 20 20 76 sql)==0 ){. v
2030: 61 5f 6c 69 73 74 20 61 70 3b 0a 20 20 20 20 76 a_list ap;. v
2040: 61 5f 73 74 61 72 74 28 61 70 2c 20 7a 46 6f 72 a_start(ap, zFor
2050: 6d 61 74 29 3b 0a 20 20 20 20 72 63 20 3d 20 64 mat);. rc = d
2060: 62 5f 76 70 72 65 70 61 72 65 28 70 53 74 6d 74 b_vprepare(pStmt
2070: 2c 20 30 2c 20 7a 46 6f 72 6d 61 74 2c 20 61 70 , 0, zFormat, ap
2080: 29 3b 0a 20 20 20 20 70 53 74 6d 74 2d 3e 70 4e );. pStmt->pN
2090: 65 78 74 20 3d 20 64 62 2e 70 41 6c 6c 53 74 6d ext = db.pAllStm
20a0: 74 3b 0a 20 20 20 20 70 53 74 6d 74 2d 3e 70 50 t;. pStmt->pP
20b0: 72 65 76 20 3d 20 30 3b 0a 20 20 20 20 69 66 28 rev = 0;. if(
20c0: 20 64 62 2e 70 41 6c 6c 53 74 6d 74 20 29 20 64 db.pAllStmt ) d
20d0: 62 2e 70 41 6c 6c 53 74 6d 74 2d 3e 70 50 72 65 b.pAllStmt->pPre
20e0: 76 20 3d 20 70 53 74 6d 74 3b 0a 20 20 20 20 64 v = pStmt;. d
20f0: 62 2e 70 41 6c 6c 53 74 6d 74 20 3d 20 70 53 74 b.pAllStmt = pSt
2100: 6d 74 3b 0a 20 20 20 20 76 61 5f 65 6e 64 28 61 mt;. va_end(a
2110: 70 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e p);. }. return
2120: 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 rc;.}../*.** Re
2130: 74 75 72 6e 20 74 68 65 20 69 6e 64 65 78 20 6f turn the index o
2140: 66 20 61 20 62 69 6e 64 20 70 61 72 61 6d 65 74 f a bind paramet
2150: 65 72 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 er.*/.static int
2160: 20 70 61 72 61 6d 49 64 78 28 53 74 6d 74 20 2a paramIdx(Stmt *
2170: 70 53 74 6d 74 2c 20 63 6f 6e 73 74 20 63 68 61 pStmt, const cha
2180: 72 20 2a 7a 50 61 72 61 6d 4e 61 6d 65 29 7b 0a r *zParamName){.
2190: 20 20 69 6e 74 20 69 20 3d 20 73 71 6c 69 74 65 int i = sqlite
21a0: 33 5f 62 69 6e 64 5f 70 61 72 61 6d 65 74 65 72 3_bind_parameter
21b0: 5f 69 6e 64 65 78 28 70 53 74 6d 74 2d 3e 70 53 _index(pStmt->pS
21c0: 74 6d 74 2c 20 7a 50 61 72 61 6d 4e 61 6d 65 29 tmt, zParamName)
21d0: 3b 0a 20 20 69 66 28 20 69 3d 3d 30 20 29 7b 0a ;. if( i==0 ){.
21e0: 20 20 20 20 64 62 5f 65 72 72 28 22 6e 6f 20 73 db_err("no s
21f0: 75 63 68 20 62 69 6e 64 20 70 61 72 61 6d 65 74 uch bind paramet
2200: 65 72 3a 20 25 73 5c 6e 53 51 4c 3a 20 25 62 22 er: %s\nSQL: %b"
2210: 2c 20 7a 50 61 72 61 6d 4e 61 6d 65 2c 20 26 70 , zParamName, &p
2220: 53 74 6d 74 2d 3e 73 71 6c 29 3b 0a 20 20 7d 0a Stmt->sql);. }.
2230: 20 20 72 65 74 75 72 6e 20 69 3b 0a 7d 0a 2f 2a return i;.}./*
2240: 0a 2a 2a 20 42 69 6e 64 20 61 6e 20 69 6e 74 65 .** Bind an inte
2250: 67 65 72 2c 20 73 74 72 69 6e 67 2c 20 6f 72 20 ger, string, or
2260: 42 6c 6f 62 20 76 61 6c 75 65 20 74 6f 20 61 20 Blob value to a
2270: 6e 61 6d 65 64 20 70 61 72 61 6d 65 74 65 72 2e named parameter.
2280: 0a 2a 2f 0a 69 6e 74 20 64 62 5f 62 69 6e 64 5f .*/.int db_bind_
2290: 69 6e 74 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c int(Stmt *pStmt,
22a0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 const char *zPa
22b0: 72 61 6d 4e 61 6d 65 2c 20 69 6e 74 20 69 56 61 ramName, int iVa
22c0: 6c 75 65 29 7b 0a 20 20 72 65 74 75 72 6e 20 73 lue){. return s
22d0: 71 6c 69 74 65 33 5f 62 69 6e 64 5f 69 6e 74 28 qlite3_bind_int(
22e0: 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 70 61 pStmt->pStmt, pa
22f0: 72 61 6d 49 64 78 28 70 53 74 6d 74 2c 20 7a 50 ramIdx(pStmt, zP
2300: 61 72 61 6d 4e 61 6d 65 29 2c 20 69 56 61 6c 75 aramName), iValu
2310: 65 29 3b 0a 7d 0a 69 6e 74 20 64 62 5f 62 69 6e e);.}.int db_bin
2320: 64 5f 69 6e 74 36 34 28 53 74 6d 74 20 2a 70 53 d_int64(Stmt *pS
2330: 74 6d 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 tmt, const char
2340: 2a 7a 50 61 72 61 6d 4e 61 6d 65 2c 20 69 36 34 *zParamName, i64
2350: 20 69 56 61 6c 75 65 29 7b 0a 20 20 72 65 74 75 iValue){. retu
2360: 72 6e 20 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f rn sqlite3_bind_
2370: 69 6e 74 36 34 28 70 53 74 6d 74 2d 3e 70 53 74 int64(pStmt->pSt
2380: 6d 74 2c 20 70 61 72 61 6d 49 64 78 28 70 53 74 mt, paramIdx(pSt
2390: 6d 74 2c 20 7a 50 61 72 61 6d 4e 61 6d 65 29 2c mt, zParamName),
23a0: 20 69 56 61 6c 75 65 29 3b 0a 7d 0a 69 6e 74 20 iValue);.}.int
23b0: 64 62 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 28 53 db_bind_double(S
23c0: 74 6d 74 20 2a 70 53 74 6d 74 2c 20 63 6f 6e 73 tmt *pStmt, cons
23d0: 74 20 63 68 61 72 20 2a 7a 50 61 72 61 6d 4e 61 t char *zParamNa
23e0: 6d 65 2c 20 64 6f 75 62 6c 65 20 72 56 61 6c 75 me, double rValu
23f0: 65 29 7b 0a 20 20 72 65 74 75 72 6e 20 73 71 6c e){. return sql
2400: 69 74 65 33 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 ite3_bind_double
2410: 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 70 (pStmt->pStmt, p
2420: 61 72 61 6d 49 64 78 28 70 53 74 6d 74 2c 20 7a aramIdx(pStmt, z
2430: 50 61 72 61 6d 4e 61 6d 65 29 2c 20 72 56 61 6c ParamName), rVal
2440: 75 65 29 3b 0a 7d 0a 69 6e 74 20 64 62 5f 62 69 ue);.}.int db_bi
2450: 6e 64 5f 74 65 78 74 28 53 74 6d 74 20 2a 70 53 nd_text(Stmt *pS
2460: 74 6d 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 tmt, const char
2470: 2a 7a 50 61 72 61 6d 4e 61 6d 65 2c 20 63 6f 6e *zParamName, con
2480: 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 29 st char *zValue)
2490: 7b 0a 20 20 72 65 74 75 72 6e 20 73 71 6c 69 74 {. return sqlit
24a0: 65 33 5f 62 69 6e 64 5f 74 65 78 74 28 70 53 74 e3_bind_text(pSt
24b0: 6d 74 2d 3e 70 53 74 6d 74 2c 20 70 61 72 61 6d mt->pStmt, param
24c0: 49 64 78 28 70 53 74 6d 74 2c 20 7a 50 61 72 61 Idx(pStmt, zPara
24d0: 6d 4e 61 6d 65 29 2c 20 7a 56 61 6c 75 65 2c 0a mName), zValue,.
24e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24f0: 20 20 20 20 20 20 20 20 20 20 20 2d 31 2c 20 53 -1, S
2500: 51 4c 49 54 45 5f 53 54 41 54 49 43 29 3b 0a 7d QLITE_STATIC);.}
2510: 0a 69 6e 74 20 64 62 5f 62 69 6e 64 5f 74 65 78 .int db_bind_tex
2520: 74 31 36 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c t16(Stmt *pStmt,
2530: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 const char *zPa
2540: 72 61 6d 4e 61 6d 65 2c 20 63 6f 6e 73 74 20 63 ramName, const c
2550: 68 61 72 20 2a 7a 56 61 6c 75 65 29 7b 0a 20 20 har *zValue){.
2560: 72 65 74 75 72 6e 20 73 71 6c 69 74 65 33 5f 62 return sqlite3_b
2570: 69 6e 64 5f 74 65 78 74 31 36 28 70 53 74 6d 74 ind_text16(pStmt
2580: 2d 3e 70 53 74 6d 74 2c 20 70 61 72 61 6d 49 64 ->pStmt, paramId
2590: 78 28 70 53 74 6d 74 2c 20 7a 50 61 72 61 6d 4e x(pStmt, zParamN
25a0: 61 6d 65 29 2c 20 7a 56 61 6c 75 65 2c 0a 20 20 ame), zValue,.
25b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25c0: 20 20 20 20 20 20 20 20 20 20 20 2d 31 2c 20 53 -1, S
25d0: 51 4c 49 54 45 5f 53 54 41 54 49 43 29 3b 0a 7d QLITE_STATIC);.}
25e0: 0a 69 6e 74 20 64 62 5f 62 69 6e 64 5f 6e 75 6c .int db_bind_nul
25f0: 6c 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c 20 63 l(Stmt *pStmt, c
2600: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 72 61 onst char *zPara
2610: 6d 4e 61 6d 65 29 7b 0a 20 20 72 65 74 75 72 6e mName){. return
2620: 20 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 6e 75 sqlite3_bind_nu
2630: 6c 6c 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c ll(pStmt->pStmt,
2640: 20 70 61 72 61 6d 49 64 78 28 70 53 74 6d 74 2c paramIdx(pStmt,
2650: 20 7a 50 61 72 61 6d 4e 61 6d 65 29 29 3b 0a 7d zParamName));.}
2660: 0a 69 6e 74 20 64 62 5f 62 69 6e 64 5f 62 6c 6f .int db_bind_blo
2670: 62 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c 20 63 b(Stmt *pStmt, c
2680: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 72 61 onst char *zPara
2690: 6d 4e 61 6d 65 2c 20 42 6c 6f 62 20 2a 70 42 6c mName, Blob *pBl
26a0: 6f 62 29 7b 0a 20 20 72 65 74 75 72 6e 20 73 71 ob){. return sq
26b0: 6c 69 74 65 33 5f 62 69 6e 64 5f 62 6c 6f 62 28 lite3_bind_blob(
26c0: 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 70 61 pStmt->pStmt, pa
26d0: 72 61 6d 49 64 78 28 70 53 74 6d 74 2c 20 7a 50 ramIdx(pStmt, zP
26e0: 61 72 61 6d 4e 61 6d 65 29 2c 0a 20 20 20 20 20 aramName),.
26f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2700: 20 20 20 20 20 62 6c 6f 62 5f 62 75 66 66 65 72 blob_buffer
2710: 28 70 42 6c 6f 62 29 2c 20 62 6c 6f 62 5f 73 69 (pBlob), blob_si
2720: 7a 65 28 70 42 6c 6f 62 29 2c 20 53 51 4c 49 54 ze(pBlob), SQLIT
2730: 45 5f 53 54 41 54 49 43 29 3b 0a 7d 0a 0a 2f 2a E_STATIC);.}../*
2740: 20 62 69 6e 64 5f 73 74 72 28 29 20 74 72 65 61 bind_str() trea
2750: 74 73 20 61 20 42 6c 6f 62 20 6f 62 6a 65 63 74 ts a Blob object
2760: 20 6c 69 6b 65 20 61 20 54 45 58 54 20 73 74 72 like a TEXT str
2770: 69 6e 67 20 61 6e 64 20 62 69 6e 64 73 20 69 74 ing and binds it
2780: 0a 2a 2a 20 74 6f 20 74 68 65 20 53 51 4c 20 76 .** to the SQL v
2790: 61 72 69 61 62 6c 65 2e 20 20 43 6f 6e 74 72 61 ariable. Contra
27a0: 73 74 20 74 68 69 73 20 74 6f 20 62 69 6e 64 5f st this to bind_
27b0: 62 6c 6f 62 28 29 20 77 68 69 63 68 20 74 72 65 blob() which tre
27c0: 61 74 73 0a 2a 2a 20 74 68 65 20 42 6c 6f 62 20 ats.** the Blob
27d0: 6f 62 6a 65 63 74 20 6c 69 6b 65 20 61 6e 20 53 object like an S
27e0: 51 4c 20 42 4c 4f 42 2e 0a 2a 2f 0a 69 6e 74 20 QL BLOB..*/.int
27f0: 64 62 5f 62 69 6e 64 5f 73 74 72 28 53 74 6d 74 db_bind_str(Stmt
2800: 20 2a 70 53 74 6d 74 2c 20 63 6f 6e 73 74 20 63 *pStmt, const c
2810: 68 61 72 20 2a 7a 50 61 72 61 6d 4e 61 6d 65 2c har *zParamName,
2820: 20 42 6c 6f 62 20 2a 70 42 6c 6f 62 29 7b 0a 20 Blob *pBlob){.
2830: 20 72 65 74 75 72 6e 20 73 71 6c 69 74 65 33 5f return sqlite3_
2840: 62 69 6e 64 5f 74 65 78 74 28 70 53 74 6d 74 2d bind_text(pStmt-
2850: 3e 70 53 74 6d 74 2c 20 70 61 72 61 6d 49 64 78 >pStmt, paramIdx
2860: 28 70 53 74 6d 74 2c 20 7a 50 61 72 61 6d 4e 61 (pStmt, zParamNa
2870: 6d 65 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 me),.
2880: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 b
2890: 6c 6f 62 5f 62 75 66 66 65 72 28 70 42 6c 6f 62 lob_buffer(pBlob
28a0: 29 2c 20 62 6c 6f 62 5f 73 69 7a 65 28 70 42 6c ), blob_size(pBl
28b0: 6f 62 29 2c 20 53 51 4c 49 54 45 5f 53 54 41 54 ob), SQLITE_STAT
28c0: 49 43 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 74 IC);.}../*.** St
28d0: 65 70 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 ep the SQL state
28e0: 6d 65 6e 74 2e 20 20 52 65 74 75 72 6e 20 65 69 ment. Return ei
28f0: 74 68 65 72 20 53 51 4c 49 54 45 5f 52 4f 57 20 ther SQLITE_ROW
2900: 6f 72 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 65 or an error code
2910: 0a 2a 2a 20 6f 72 20 53 51 4c 49 54 45 5f 4f 4b .** or SQLITE_OK
2920: 20 69 66 20 74 68 65 20 73 74 61 74 65 6d 65 6e if the statemen
2930: 74 20 66 69 6e 69 73 68 65 73 20 73 75 63 63 65 t finishes succe
2940: 73 73 66 75 6c 6c 79 2e 0a 2a 2f 0a 69 6e 74 20 ssfully..*/.int
2950: 64 62 5f 73 74 65 70 28 53 74 6d 74 20 2a 70 53 db_step(Stmt *pS
2960: 74 6d 74 29 7b 0a 20 20 69 6e 74 20 72 63 3b 0a tmt){. int rc;.
2970: 20 20 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 73 rc = sqlite3_s
2980: 74 65 70 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 tep(pStmt->pStmt
2990: 29 3b 0a 20 20 70 53 74 6d 74 2d 3e 6e 53 74 65 );. pStmt->nSte
29a0: 70 2b 2b 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 p++;. return rc
29b0: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 69 6e 74 ;.}../*.** Print
29c0: 20 77 61 72 6e 69 6e 67 73 20 69 66 20 61 20 71 warnings if a q
29d0: 75 65 72 79 20 69 73 20 69 6e 65 66 66 69 63 69 uery is ineffici
29e0: 65 6e 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 ent..*/.static v
29f0: 6f 69 64 20 64 62 5f 73 74 61 74 73 28 53 74 6d oid db_stats(Stm
2a00: 74 20 2a 70 53 74 6d 74 29 7b 0a 23 69 66 64 65 t *pStmt){.#ifde
2a10: 66 20 46 4f 53 53 49 4c 5f 44 45 42 55 47 0a 20 f FOSSIL_DEBUG.
2a20: 20 69 6e 74 20 63 31 2c 20 63 32 2c 20 63 33 3b int c1, c2, c3;
2a30: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
2a40: 53 71 6c 20 3d 20 73 71 6c 69 74 65 33 5f 73 71 Sql = sqlite3_sq
2a50: 6c 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 29 3b l(pStmt->pStmt);
2a60: 0a 20 20 69 66 28 20 7a 53 71 6c 3d 3d 30 20 29 . if( zSql==0 )
2a70: 20 72 65 74 75 72 6e 3b 0a 20 20 63 31 20 3d 20 return;. c1 =
2a80: 73 71 6c 69 74 65 33 5f 73 74 6d 74 5f 73 74 61 sqlite3_stmt_sta
2a90: 74 75 73 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 tus(pStmt->pStmt
2aa0: 2c 20 53 51 4c 49 54 45 5f 53 54 4d 54 53 54 41 , SQLITE_STMTSTA
2ab0: 54 55 53 5f 46 55 4c 4c 53 43 41 4e 5f 53 54 45 TUS_FULLSCAN_STE
2ac0: 50 2c 20 31 29 3b 0a 20 20 63 32 20 3d 20 73 71 P, 1);. c2 = sq
2ad0: 6c 69 74 65 33 5f 73 74 6d 74 5f 73 74 61 74 75 lite3_stmt_statu
2ae0: 73 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 s(pStmt->pStmt,
2af0: 53 51 4c 49 54 45 5f 53 54 4d 54 53 54 41 54 55 SQLITE_STMTSTATU
2b00: 53 5f 41 55 54 4f 49 4e 44 45 58 2c 20 31 29 3b S_AUTOINDEX, 1);
2b10: 0a 20 20 63 33 20 3d 20 73 71 6c 69 74 65 33 5f . c3 = sqlite3_
2b20: 73 74 6d 74 5f 73 74 61 74 75 73 28 70 53 74 6d stmt_status(pStm
2b30: 74 2d 3e 70 53 74 6d 74 2c 20 53 51 4c 49 54 45 t->pStmt, SQLITE
2b40: 5f 53 54 4d 54 53 54 41 54 55 53 5f 53 4f 52 54 _STMTSTATUS_SORT
2b50: 2c 20 31 29 3b 0a 20 20 69 66 28 20 63 31 3e 70 , 1);. if( c1>p
2b60: 53 74 6d 74 2d 3e 6e 53 74 65 70 2a 34 20 26 26 Stmt->nStep*4 &&
2b70: 20 73 74 72 73 74 72 28 7a 53 71 6c 2c 22 2f 2a strstr(zSql,"/*
2b80: 73 63 61 6e 2a 2f 22 29 3d 3d 30 20 29 7b 0a 20 scan*/")==0 ){.
2b90: 20 20 20 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e fossil_warnin
2ba0: 67 28 22 25 64 20 73 63 61 6e 20 73 74 65 70 73 g("%d scan steps
2bb0: 20 66 6f 72 20 25 64 20 72 6f 77 73 20 69 6e 20 for %d rows in
2bc0: 5b 25 73 5d 22 2c 20 63 31 2c 20 70 53 74 6d 74 [%s]", c1, pStmt
2bd0: 2d 3e 6e 53 74 65 70 2c 20 7a 53 71 6c 29 3b 0a ->nStep, zSql);.
2be0: 20 20 7d 65 6c 73 65 20 69 66 28 20 63 32 20 29 }else if( c2 )
2bf0: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 77 61 72 {. fossil_war
2c00: 6e 69 6e 67 28 22 25 64 20 61 75 74 6f 6d 61 74 ning("%d automat
2c10: 69 63 20 69 6e 64 65 78 20 72 6f 77 73 20 69 6e ic index rows in
2c20: 20 5b 25 73 5d 22 2c 20 63 32 2c 20 7a 53 71 6c [%s]", c2, zSql
2c30: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 63 );. }else if( c
2c40: 33 20 26 26 20 73 74 72 73 74 72 28 7a 53 71 6c 3 && strstr(zSql
2c50: 2c 22 2f 2a 73 6f 72 74 2a 2f 22 29 3d 3d 30 20 ,"/*sort*/")==0
2c60: 26 26 20 73 74 72 73 74 72 28 7a 53 71 6c 2c 22 && strstr(zSql,"
2c70: 2f 2a 73 63 61 6e 2a 2f 22 29 3d 3d 30 20 29 7b /*scan*/")==0 ){
2c80: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 77 61 72 6e . fossil_warn
2c90: 69 6e 67 28 22 73 6f 72 74 20 77 2f 6f 20 69 6e ing("sort w/o in
2ca0: 64 65 78 20 69 6e 20 5b 25 73 5d 22 2c 20 7a 53 dex in [%s]", zS
2cb0: 71 6c 29 3b 0a 20 20 7d 0a 20 20 70 53 74 6d 74 ql);. }. pStmt
2cc0: 2d 3e 6e 53 74 65 70 20 3d 20 30 3b 0a 23 65 6e ->nStep = 0;.#en
2cd0: 64 69 66 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 73 dif.}../*.** Res
2ce0: 65 74 20 6f 72 20 66 69 6e 61 6c 69 7a 65 20 61 et or finalize a
2cf0: 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a 69 statement..*/.i
2d00: 6e 74 20 64 62 5f 72 65 73 65 74 28 53 74 6d 74 nt db_reset(Stmt
2d10: 20 2a 70 53 74 6d 74 29 7b 0a 20 20 69 6e 74 20 *pStmt){. int
2d20: 72 63 3b 0a 20 20 64 62 5f 73 74 61 74 73 28 70 rc;. db_stats(p
2d30: 53 74 6d 74 29 3b 0a 20 20 72 63 20 3d 20 73 71 Stmt);. rc = sq
2d40: 6c 69 74 65 33 5f 72 65 73 65 74 28 70 53 74 6d lite3_reset(pStm
2d50: 74 2d 3e 70 53 74 6d 74 29 3b 0a 20 20 64 62 5f t->pStmt);. db_
2d60: 63 68 65 63 6b 5f 72 65 73 75 6c 74 28 72 63 29 check_result(rc)
2d70: 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d ;. return rc;.}
2d80: 0a 69 6e 74 20 64 62 5f 66 69 6e 61 6c 69 7a 65 .int db_finalize
2d90: 28 53 74 6d 74 20 2a 70 53 74 6d 74 29 7b 0a 20 (Stmt *pStmt){.
2da0: 20 69 6e 74 20 72 63 3b 0a 20 20 64 62 5f 73 74 int rc;. db_st
2db0: 61 74 73 28 70 53 74 6d 74 29 3b 0a 20 20 62 6c ats(pStmt);. bl
2dc0: 6f 62 5f 72 65 73 65 74 28 26 70 53 74 6d 74 2d ob_reset(&pStmt-
2dd0: 3e 73 71 6c 29 3b 0a 20 20 72 63 20 3d 20 73 71 >sql);. rc = sq
2de0: 6c 69 74 65 33 5f 66 69 6e 61 6c 69 7a 65 28 70 lite3_finalize(p
2df0: 53 74 6d 74 2d 3e 70 53 74 6d 74 29 3b 0a 20 20 Stmt->pStmt);.
2e00: 64 62 5f 63 68 65 63 6b 5f 72 65 73 75 6c 74 28 db_check_result(
2e10: 72 63 29 3b 0a 20 20 70 53 74 6d 74 2d 3e 70 53 rc);. pStmt->pS
2e20: 74 6d 74 20 3d 20 30 3b 0a 20 20 69 66 28 20 70 tmt = 0;. if( p
2e30: 53 74 6d 74 2d 3e 70 4e 65 78 74 20 29 7b 0a 20 Stmt->pNext ){.
2e40: 20 20 20 70 53 74 6d 74 2d 3e 70 4e 65 78 74 2d pStmt->pNext-
2e50: 3e 70 50 72 65 76 20 3d 20 70 53 74 6d 74 2d 3e >pPrev = pStmt->
2e60: 70 50 72 65 76 3b 0a 20 20 7d 0a 20 20 69 66 28 pPrev;. }. if(
2e70: 20 70 53 74 6d 74 2d 3e 70 50 72 65 76 20 29 7b pStmt->pPrev ){
2e80: 0a 20 20 20 20 70 53 74 6d 74 2d 3e 70 50 72 65 . pStmt->pPre
2e90: 76 2d 3e 70 4e 65 78 74 20 3d 20 70 53 74 6d 74 v->pNext = pStmt
2ea0: 2d 3e 70 4e 65 78 74 3b 0a 20 20 7d 65 6c 73 65 ->pNext;. }else
2eb0: 20 69 66 28 20 64 62 2e 70 41 6c 6c 53 74 6d 74 if( db.pAllStmt
2ec0: 3d 3d 70 53 74 6d 74 20 29 7b 0a 20 20 20 20 64 ==pStmt ){. d
2ed0: 62 2e 70 41 6c 6c 53 74 6d 74 20 3d 20 70 53 74 b.pAllStmt = pSt
2ee0: 6d 74 2d 3e 70 4e 65 78 74 3b 0a 20 20 7d 0a 20 mt->pNext;. }.
2ef0: 20 70 53 74 6d 74 2d 3e 70 4e 65 78 74 20 3d 20 pStmt->pNext =
2f00: 30 3b 0a 20 20 70 53 74 6d 74 2d 3e 70 50 72 65 0;. pStmt->pPre
2f10: 76 20 3d 20 30 3b 0a 20 20 72 65 74 75 72 6e 20 v = 0;. return
2f20: 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 rc;.}../*.** Ret
2f30: 75 72 6e 20 74 68 65 20 72 6f 77 69 64 20 6f 66 urn the rowid of
2f40: 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 the most recent
2f50: 20 69 6e 73 65 72 74 0a 2a 2f 0a 69 6e 74 20 64 insert.*/.int d
2f60: 62 5f 6c 61 73 74 5f 69 6e 73 65 72 74 5f 72 6f b_last_insert_ro
2f70: 77 69 64 28 76 6f 69 64 29 7b 0a 20 20 69 36 34 wid(void){. i64
2f80: 20 78 20 3d 20 73 71 6c 69 74 65 33 5f 6c 61 73 x = sqlite3_las
2f90: 74 5f 69 6e 73 65 72 74 5f 72 6f 77 69 64 28 67 t_insert_rowid(g
2fa0: 2e 64 62 29 3b 0a 20 20 69 66 28 20 78 3c 30 20 .db);. if( x<0
2fb0: 7c 7c 20 78 3e 28 69 36 34 29 32 31 34 37 34 38 || x>(i64)214748
2fc0: 33 36 34 37 20 29 7b 0a 20 20 20 20 66 6f 73 73 3647 ){. foss
2fd0: 69 6c 5f 66 61 74 61 6c 28 22 72 6f 77 69 64 20 il_fatal("rowid
2fe0: 6f 75 74 20 6f 66 20 72 61 6e 67 65 20 28 30 2e out of range (0.
2ff0: 2e 32 31 34 37 34 38 33 36 34 37 29 22 29 3b 0a .2147483647)");.
3000: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 28 69 6e }. return (in
3010: 74 29 78 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 t)x;.}../*.** Re
3020: 74 75 72 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 turn the number
3030: 6f 66 20 72 6f 77 73 20 74 68 61 74 20 77 65 72 of rows that wer
3040: 65 20 63 68 61 6e 67 65 64 20 62 79 20 74 68 65 e changed by the
3050: 20 6d 6f 73 74 20 72 65 63 65 6e 74 0a 2a 2a 20 most recent.**
3060: 49 4e 53 45 52 54 2c 20 55 50 44 41 54 45 2c 20 INSERT, UPDATE,
3070: 6f 72 20 44 45 4c 45 54 45 2e 20 20 41 75 78 69 or DELETE. Auxi
3080: 6c 69 61 72 79 20 63 68 61 6e 67 65 73 20 63 61 liary changes ca
3090: 75 73 65 64 20 62 79 20 74 72 69 67 67 65 72 73 used by triggers
30a0: 0a 2a 2a 20 6f 72 20 6f 74 68 65 72 20 73 69 64 .** or other sid
30b0: 65 20 65 66 66 65 63 74 73 20 61 72 65 20 6e 6f e effects are no
30c0: 74 20 63 6f 75 6e 74 65 64 2e 0a 2a 2f 0a 69 6e t counted..*/.in
30d0: 74 20 64 62 5f 63 68 61 6e 67 65 73 28 76 6f 69 t db_changes(voi
30e0: 64 29 7b 0a 20 20 72 65 74 75 72 6e 20 73 71 6c d){. return sql
30f0: 69 74 65 33 5f 63 68 61 6e 67 65 73 28 67 2e 64 ite3_changes(g.d
3100: 62 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 45 78 74 b);.}../*.** Ext
3110: 72 61 63 74 20 74 65 78 74 2c 20 69 6e 74 65 67 ract text, integ
3120: 65 72 2c 20 6f 72 20 62 6c 6f 62 20 76 61 6c 75 er, or blob valu
3130: 65 73 20 66 72 6f 6d 20 74 68 65 20 4e 2d 74 68 es from the N-th
3140: 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 68 65 0a 2a column of the.*
3150: 2a 20 63 75 72 72 65 6e 74 20 72 6f 77 2e 0a 2a * current row..*
3160: 2f 0a 69 6e 74 20 64 62 5f 63 6f 6c 75 6d 6e 5f /.int db_column_
3170: 62 79 74 65 73 28 53 74 6d 74 20 2a 70 53 74 6d bytes(Stmt *pStm
3180: 74 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 72 65 74 t, int N){. ret
3190: 75 72 6e 20 73 71 6c 69 74 65 33 5f 63 6f 6c 75 urn sqlite3_colu
31a0: 6d 6e 5f 62 79 74 65 73 28 70 53 74 6d 74 2d 3e mn_bytes(pStmt->
31b0: 70 53 74 6d 74 2c 20 4e 29 3b 0a 7d 0a 69 6e 74 pStmt, N);.}.int
31c0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 53 db_column_int(S
31d0: 74 6d 74 20 2a 70 53 74 6d 74 2c 20 69 6e 74 20 tmt *pStmt, int
31e0: 4e 29 7b 0a 20 20 72 65 74 75 72 6e 20 73 71 6c N){. return sql
31f0: 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 ite3_column_int(
3200: 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 4e 29 pStmt->pStmt, N)
3210: 3b 0a 7d 0a 69 36 34 20 64 62 5f 63 6f 6c 75 6d ;.}.i64 db_colum
3220: 6e 5f 69 6e 74 36 34 28 53 74 6d 74 20 2a 70 53 n_int64(Stmt *pS
3230: 74 6d 74 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 72 tmt, int N){. r
3240: 65 74 75 72 6e 20 73 71 6c 69 74 65 33 5f 63 6f eturn sqlite3_co
3250: 6c 75 6d 6e 5f 69 6e 74 36 34 28 70 53 74 6d 74 lumn_int64(pStmt
3260: 2d 3e 70 53 74 6d 74 2c 20 4e 29 3b 0a 7d 0a 64 ->pStmt, N);.}.d
3270: 6f 75 62 6c 65 20 64 62 5f 63 6f 6c 75 6d 6e 5f ouble db_column_
3280: 64 6f 75 62 6c 65 28 53 74 6d 74 20 2a 70 53 74 double(Stmt *pSt
3290: 6d 74 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 72 65 mt, int N){. re
32a0: 74 75 72 6e 20 73 71 6c 69 74 65 33 5f 63 6f 6c turn sqlite3_col
32b0: 75 6d 6e 5f 64 6f 75 62 6c 65 28 70 53 74 6d 74 umn_double(pStmt
32c0: 2d 3e 70 53 74 6d 74 2c 20 4e 29 3b 0a 7d 0a 63 ->pStmt, N);.}.c
32d0: 6f 6e 73 74 20 63 68 61 72 20 2a 64 62 5f 63 6f onst char *db_co
32e0: 6c 75 6d 6e 5f 74 65 78 74 28 53 74 6d 74 20 2a lumn_text(Stmt *
32f0: 70 53 74 6d 74 2c 20 69 6e 74 20 4e 29 7b 0a 20 pStmt, int N){.
3300: 20 72 65 74 75 72 6e 20 28 63 68 61 72 2a 29 73 return (char*)s
3310: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 74 65 qlite3_column_te
3320: 78 74 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c xt(pStmt->pStmt,
3330: 20 4e 29 3b 0a 7d 0a 63 6f 6e 73 74 20 63 68 61 N);.}.const cha
3340: 72 20 2a 64 62 5f 63 6f 6c 75 6d 6e 5f 72 61 77 r *db_column_raw
3350: 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c 20 69 6e (Stmt *pStmt, in
3360: 74 20 4e 29 7b 0a 20 20 72 65 74 75 72 6e 20 28 t N){. return (
3370: 63 6f 6e 73 74 20 63 68 61 72 2a 29 73 71 6c 69 const char*)sqli
3380: 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 6c 6f 62 28 te3_column_blob(
3390: 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 4e 29 pStmt->pStmt, N)
33a0: 3b 0a 7d 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a ;.}.const char *
33b0: 64 62 5f 63 6f 6c 75 6d 6e 5f 6e 61 6d 65 28 53 db_column_name(S
33c0: 74 6d 74 20 2a 70 53 74 6d 74 2c 20 69 6e 74 20 tmt *pStmt, int
33d0: 4e 29 7b 0a 20 20 72 65 74 75 72 6e 20 28 63 68 N){. return (ch
33e0: 61 72 2a 29 73 71 6c 69 74 65 33 5f 63 6f 6c 75 ar*)sqlite3_colu
33f0: 6d 6e 5f 6e 61 6d 65 28 70 53 74 6d 74 2d 3e 70 mn_name(pStmt->p
3400: 53 74 6d 74 2c 20 4e 29 3b 0a 7d 0a 69 6e 74 20 Stmt, N);.}.int
3410: 64 62 5f 63 6f 6c 75 6d 6e 5f 63 6f 75 6e 74 28 db_column_count(
3420: 53 74 6d 74 20 2a 70 53 74 6d 74 29 7b 0a 20 20 Stmt *pStmt){.
3430: 72 65 74 75 72 6e 20 73 71 6c 69 74 65 33 5f 63 return sqlite3_c
3440: 6f 6c 75 6d 6e 5f 63 6f 75 6e 74 28 70 53 74 6d olumn_count(pStm
3450: 74 2d 3e 70 53 74 6d 74 29 3b 0a 7d 0a 63 68 61 t->pStmt);.}.cha
3460: 72 20 2a 64 62 5f 63 6f 6c 75 6d 6e 5f 6d 61 6c r *db_column_mal
3470: 6c 6f 63 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c loc(Stmt *pStmt,
3480: 20 69 6e 74 20 4e 29 7b 0a 20 20 72 65 74 75 72 int N){. retur
3490: 6e 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 n mprintf("%s",
34a0: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 70 db_column_text(p
34b0: 53 74 6d 74 2c 20 4e 29 29 3b 0a 7d 0a 76 6f 69 Stmt, N));.}.voi
34c0: 64 20 64 62 5f 63 6f 6c 75 6d 6e 5f 62 6c 6f 62 d db_column_blob
34d0: 28 53 74 6d 74 20 2a 70 53 74 6d 74 2c 20 69 6e (Stmt *pStmt, in
34e0: 74 20 4e 2c 20 42 6c 6f 62 20 2a 70 42 6c 6f 62 t N, Blob *pBlob
34f0: 29 7b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 ){. blob_append
3500: 28 70 42 6c 6f 62 2c 20 73 71 6c 69 74 65 33 5f (pBlob, sqlite3_
3510: 63 6f 6c 75 6d 6e 5f 62 6c 6f 62 28 70 53 74 6d column_blob(pStm
3520: 74 2d 3e 70 53 74 6d 74 2c 20 4e 29 2c 0a 20 20 t->pStmt, N),.
3530: 20 20 20 20 20 20 20 20 20 20 20 20 73 71 6c 69 sqli
3540: 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 79 74 65 73 te3_column_bytes
3550: 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 4e (pStmt->pStmt, N
3560: 29 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 6e 69 ));.}../*.** Ini
3570: 74 69 61 6c 69 7a 65 20 61 20 62 6c 6f 62 20 74 tialize a blob t
3580: 6f 20 61 6e 20 65 70 68 65 6d 65 72 61 6c 20 63 o an ephemeral c
3590: 6f 70 79 20 6f 66 20 74 68 65 20 63 6f 6e 74 65 opy of the conte
35a0: 6e 74 20 6f 66 20 61 0a 2a 2a 20 63 6f 6c 75 6d nt of a.** colum
35b0: 6e 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 n in the current
35c0: 20 72 6f 77 2e 20 20 54 68 65 20 64 61 74 61 20 row. The data
35d0: 69 6e 20 74 68 65 20 62 6c 6f 62 20 77 69 6c 6c in the blob will
35e0: 20 62 65 63 6f 6d 65 0a 2a 2a 20 69 6e 76 61 6c become.** inval
35f0: 69 64 20 77 68 65 6e 20 74 68 65 20 73 74 61 74 id when the stat
3600: 65 6d 65 6e 74 20 69 73 20 73 74 65 70 70 65 64 ement is stepped
3610: 20 6f 72 20 72 65 73 65 74 2e 0a 2a 2f 0a 76 6f or reset..*/.vo
3620: 69 64 20 64 62 5f 65 70 68 65 6d 65 72 61 6c 5f id db_ephemeral_
3630: 62 6c 6f 62 28 53 74 6d 74 20 2a 70 53 74 6d 74 blob(Stmt *pStmt
3640: 2c 20 69 6e 74 20 4e 2c 20 42 6c 6f 62 20 2a 70 , int N, Blob *p
3650: 42 6c 6f 62 29 7b 0a 20 20 62 6c 6f 62 5f 69 6e Blob){. blob_in
3660: 69 74 28 70 42 6c 6f 62 2c 20 73 71 6c 69 74 65 it(pBlob, sqlite
3670: 33 5f 63 6f 6c 75 6d 6e 5f 62 6c 6f 62 28 70 53 3_column_blob(pS
3680: 74 6d 74 2d 3e 70 53 74 6d 74 2c 20 4e 29 2c 0a tmt->pStmt, N),.
3690: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 71 sq
36a0: 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 79 74 lite3_column_byt
36b0: 65 73 28 70 53 74 6d 74 2d 3e 70 53 74 6d 74 2c es(pStmt->pStmt,
36c0: 20 4e 29 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 N));.}../*.** C
36d0: 68 65 63 6b 20 61 20 72 65 73 75 6c 74 20 63 6f heck a result co
36e0: 64 65 2e 20 20 49 66 20 69 74 20 69 73 20 6e 6f de. If it is no
36f0: 74 20 53 51 4c 49 54 45 5f 4f 4b 2c 20 70 72 69 t SQLITE_OK, pri
3700: 6e 74 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 nt the.** corres
3710: 70 6f 6e 64 69 6e 67 20 65 72 72 6f 72 20 6d 65 ponding error me
3720: 73 73 61 67 65 20 61 6e 64 20 65 78 69 74 2e 0a ssage and exit..
3730: 2a 2f 0a 76 6f 69 64 20 64 62 5f 63 68 65 63 6b */.void db_check
3740: 5f 72 65 73 75 6c 74 28 69 6e 74 20 72 63 29 7b _result(int rc){
3750: 0a 20 20 69 66 28 20 72 63 21 3d 53 51 4c 49 54 . if( rc!=SQLIT
3760: 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 64 62 5f 65 E_OK ){. db_e
3770: 72 72 28 22 53 51 4c 20 65 72 72 6f 72 3a 20 25 rr("SQL error: %
3780: 73 22 2c 20 73 71 6c 69 74 65 33 5f 65 72 72 6d s", sqlite3_errm
3790: 73 67 28 67 2e 64 62 29 29 3b 0a 20 20 7d 0a 7d sg(g.db));. }.}
37a0: 0a 0a 2f 2a 0a 2a 2a 20 45 78 65 63 75 74 65 20 ../*.** Execute
37b0: 61 20 73 69 6e 67 6c 65 20 70 72 65 70 61 72 65 a single prepare
37c0: 64 20 73 74 61 74 65 6d 65 6e 74 20 75 6e 74 69 d statement unti
37d0: 6c 20 69 74 20 66 69 6e 69 73 68 65 73 2e 0a 2a l it finishes..*
37e0: 2f 0a 69 6e 74 20 64 62 5f 65 78 65 63 28 53 74 /.int db_exec(St
37f0: 6d 74 20 2a 70 53 74 6d 74 29 7b 0a 20 20 69 6e mt *pStmt){. in
3800: 74 20 72 63 3b 0a 20 20 77 68 69 6c 65 28 20 28 t rc;. while( (
3810: 72 63 20 3d 20 64 62 5f 73 74 65 70 28 70 53 74 rc = db_step(pSt
3820: 6d 74 29 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 mt))==SQLITE_ROW
3830: 20 29 7b 7d 0a 20 20 72 63 20 3d 20 64 62 5f 72 ){}. rc = db_r
3840: 65 73 65 74 28 70 53 74 6d 74 29 3b 0a 20 20 64 eset(pStmt);. d
3850: 62 5f 63 68 65 63 6b 5f 72 65 73 75 6c 74 28 72 b_check_result(r
3860: 63 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 3b c);. return rc;
3870: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 45 78 65 63 75 74 .}../*.** Execut
3880: 65 20 6d 75 6c 74 69 70 6c 65 20 53 51 4c 20 73 e multiple SQL s
3890: 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2f 0a 69 6e tatements..*/.in
38a0: 74 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 t db_multi_exec(
38b0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c const char *zSql
38c0: 2c 20 2e 2e 2e 29 7b 0a 20 20 42 6c 6f 62 20 73 , ...){. Blob s
38d0: 71 6c 3b 0a 20 20 69 6e 74 20 72 63 20 3d 20 53 ql;. int rc = S
38e0: 51 4c 49 54 45 5f 4f 4b 3b 0a 20 20 76 61 5f 6c QLITE_OK;. va_l
38f0: 69 73 74 20 61 70 3b 0a 20 20 63 6f 6e 73 74 20 ist ap;. const
3900: 63 68 61 72 20 2a 7a 2c 20 2a 7a 45 6e 64 3b 0a char *z, *zEnd;.
3910: 20 20 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a sqlite3_stmt *
3920: 70 53 74 6d 74 3b 0a 20 20 62 6c 6f 62 5f 69 6e pStmt;. blob_in
3930: 69 74 28 26 73 71 6c 2c 20 30 2c 20 30 29 3b 0a it(&sql, 0, 0);.
3940: 20 20 76 61 5f 73 74 61 72 74 28 61 70 2c 20 7a va_start(ap, z
3950: 53 71 6c 29 3b 0a 20 20 62 6c 6f 62 5f 76 61 70 Sql);. blob_vap
3960: 70 65 6e 64 66 28 26 73 71 6c 2c 20 7a 53 71 6c pendf(&sql, zSql
3970: 2c 20 61 70 29 3b 0a 20 20 76 61 5f 65 6e 64 28 , ap);. va_end(
3980: 61 70 29 3b 0a 20 20 7a 20 3d 20 62 6c 6f 62 5f ap);. z = blob_
3990: 73 74 72 28 26 73 71 6c 29 3b 0a 20 20 77 68 69 str(&sql);. whi
39a0: 6c 65 28 20 72 63 3d 3d 53 51 4c 49 54 45 5f 4f le( rc==SQLITE_O
39b0: 4b 20 26 26 20 7a 5b 30 5d 20 29 7b 0a 20 20 20 K && z[0] ){.
39c0: 20 70 53 74 6d 74 20 3d 20 30 3b 0a 20 20 20 20 pStmt = 0;.
39d0: 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 70 72 65 rc = sqlite3_pre
39e0: 70 61 72 65 5f 76 32 28 67 2e 64 62 2c 20 7a 2c pare_v2(g.db, z,
39f0: 20 2d 31 2c 20 26 70 53 74 6d 74 2c 20 26 7a 45 -1, &pStmt, &zE
3a00: 6e 64 29 3b 0a 20 20 20 20 69 66 28 20 72 63 21 nd);. if( rc!
3a10: 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 20 62 72 65 =SQLITE_OK ) bre
3a20: 61 6b 3b 0a 20 20 20 20 69 66 28 20 70 53 74 6d ak;. if( pStm
3a30: 74 20 29 7b 0a 20 20 20 20 20 20 64 62 2e 6e 50 t ){. db.nP
3a40: 72 65 70 61 72 65 2b 2b 3b 0a 20 20 20 20 20 20 repare++;.
3a50: 77 68 69 6c 65 28 20 73 71 6c 69 74 65 33 5f 73 while( sqlite3_s
3a60: 74 65 70 28 70 53 74 6d 74 29 3d 3d 53 51 4c 49 tep(pStmt)==SQLI
3a70: 54 45 5f 52 4f 57 20 29 7b 7d 0a 20 20 20 20 20 TE_ROW ){}.
3a80: 20 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 66 69 rc = sqlite3_fi
3a90: 6e 61 6c 69 7a 65 28 70 53 74 6d 74 29 3b 0a 20 nalize(pStmt);.
3aa0: 20 20 20 20 20 69 66 28 20 72 63 20 29 20 64 62 if( rc ) db
3ab0: 5f 65 72 72 28 22 25 73 3a 20 7b 25 2e 2a 73 7d _err("%s: {%.*s}
3ac0: 22 2c 20 73 71 6c 69 74 65 33 5f 65 72 72 6d 73 ", sqlite3_errms
3ad0: 67 28 67 2e 64 62 29 2c 20 28 69 6e 74 29 28 7a g(g.db), (int)(z
3ae0: 45 6e 64 2d 7a 29 2c 20 7a 29 3b 0a 20 20 20 20 End-z), z);.
3af0: 7d 0a 20 20 20 20 7a 20 3d 20 7a 45 6e 64 3b 0a }. z = zEnd;.
3b00: 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 }. blob_reset
3b10: 28 26 73 71 6c 29 3b 0a 20 20 72 65 74 75 72 6e (&sql);. return
3b20: 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4f 70 rc;.}../*.** Op
3b30: 74 69 6f 6e 61 6c 6c 79 20 6d 61 6b 65 20 74 68 tionally make th
3b40: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 68 61 6e e following chan
3b50: 67 65 73 20 74 6f 20 74 68 65 20 64 61 74 61 62 ges to the datab
3b60: 61 73 65 20 69 66 20 66 65 61 73 69 62 6c 65 20 ase if feasible
3b70: 61 6e 64 0a 2a 2a 20 63 6f 6e 76 65 6e 69 65 6e and.** convenien
3b80: 74 2e 20 20 44 6f 20 6e 6f 74 20 73 74 61 72 74 t. Do not start
3b90: 20 61 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 66 a transaction f
3ba0: 6f 72 20 74 68 65 73 65 20 63 68 61 6e 67 65 73 or these changes
3bb0: 2c 20 62 75 74 20 6f 6e 6c 79 0a 2a 2a 20 6d 61 , but only.** ma
3bc0: 6b 65 20 74 68 65 73 65 20 63 68 61 6e 67 65 73 ke these changes
3bd0: 20 69 66 20 6f 74 68 65 72 20 63 68 61 6e 67 65 if other change
3be0: 73 20 61 72 65 20 61 6c 73 6f 20 62 65 69 6e 67 s are also being
3bf0: 20 6d 61 64 65 2e 0a 2a 2f 0a 76 6f 69 64 20 64 made..*/.void d
3c00: 62 5f 6f 70 74 69 6f 6e 61 6c 5f 73 71 6c 28 63 b_optional_sql(c
3c10: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 2c 20 onst char *zDb,
3c20: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c const char *zSql
3c30: 2c 20 2e 2e 2e 29 7b 0a 20 20 69 66 28 20 64 62 , ...){. if( db
3c40: 5f 69 73 5f 77 72 69 74 65 61 62 6c 65 28 7a 44 _is_writeable(zD
3c50: 62 29 20 26 26 20 64 62 2e 6e 42 65 66 6f 72 65 b) && db.nBefore
3c60: 43 6f 6d 6d 69 74 20 3c 20 63 6f 75 6e 74 28 64 Commit < count(d
3c70: 62 2e 61 7a 42 65 66 6f 72 65 43 6f 6d 6d 69 74 b.azBeforeCommit
3c80: 29 20 29 7b 0a 20 20 20 20 76 61 5f 6c 69 73 74 ) ){. va_list
3c90: 20 61 70 3b 0a 20 20 20 20 76 61 5f 73 74 61 72 ap;. va_star
3ca0: 74 28 61 70 2c 20 7a 53 71 6c 29 3b 0a 20 20 20 t(ap, zSql);.
3cb0: 20 64 62 2e 61 7a 42 65 66 6f 72 65 43 6f 6d 6d db.azBeforeComm
3cc0: 69 74 5b 64 62 2e 6e 42 65 66 6f 72 65 43 6f 6d it[db.nBeforeCom
3cd0: 6d 69 74 2b 2b 5d 20 3d 20 73 71 6c 69 74 65 33 mit++] = sqlite3
3ce0: 5f 76 6d 70 72 69 6e 74 66 28 7a 53 71 6c 2c 20 _vmprintf(zSql,
3cf0: 61 70 29 3b 0a 20 20 20 20 76 61 5f 65 6e 64 28 ap);. va_end(
3d00: 61 70 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a ap);. }.}../*.*
3d10: 2a 20 45 78 65 63 75 74 65 20 61 20 71 75 65 72 * Execute a quer
3d20: 79 20 61 6e 64 20 72 65 74 75 72 6e 20 61 20 73 y and return a s
3d30: 69 6e 67 6c 65 20 69 6e 74 65 67 65 72 20 76 61 ingle integer va
3d40: 6c 75 65 2e 0a 2a 2f 0a 69 36 34 20 64 62 5f 69 lue..*/.i64 db_i
3d50: 6e 74 36 34 28 69 36 34 20 69 44 66 6c 74 2c 20 nt64(i64 iDflt,
3d60: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c const char *zSql
3d70: 2c 20 2e 2e 2e 29 7b 0a 20 20 76 61 5f 6c 69 73 , ...){. va_lis
3d80: 74 20 61 70 3b 0a 20 20 53 74 6d 74 20 73 3b 0a t ap;. Stmt s;.
3d90: 20 20 69 36 34 20 72 63 3b 0a 20 20 76 61 5f 73 i64 rc;. va_s
3da0: 74 61 72 74 28 61 70 2c 20 7a 53 71 6c 29 3b 0a tart(ap, zSql);.
3db0: 20 20 64 62 5f 76 70 72 65 70 61 72 65 28 26 73 db_vprepare(&s
3dc0: 2c 20 30 2c 20 7a 53 71 6c 2c 20 61 70 29 3b 0a , 0, zSql, ap);.
3dd0: 20 20 76 61 5f 65 6e 64 28 61 70 29 3b 0a 20 20 va_end(ap);.
3de0: 69 66 28 20 64 62 5f 73 74 65 70 28 26 73 29 21 if( db_step(&s)!
3df0: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 =SQLITE_ROW ){.
3e00: 20 20 20 72 63 20 3d 20 69 44 66 6c 74 3b 0a 20 rc = iDflt;.
3e10: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63 20 3d }else{. rc =
3e20: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 36 34 db_column_int64
3e30: 28 26 73 2c 20 30 29 3b 0a 20 20 7d 0a 20 20 64 (&s, 0);. }. d
3e40: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a b_finalize(&s);.
3e50: 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a 69 return rc;.}.i
3e60: 6e 74 20 64 62 5f 69 6e 74 28 69 6e 74 20 69 44 nt db_int(int iD
3e70: 66 6c 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 flt, const char
3e80: 2a 7a 53 71 6c 2c 20 2e 2e 2e 29 7b 0a 20 20 76 *zSql, ...){. v
3e90: 61 5f 6c 69 73 74 20 61 70 3b 0a 20 20 53 74 6d a_list ap;. Stm
3ea0: 74 20 73 3b 0a 20 20 69 6e 74 20 72 63 3b 0a 20 t s;. int rc;.
3eb0: 20 76 61 5f 73 74 61 72 74 28 61 70 2c 20 7a 53 va_start(ap, zS
3ec0: 71 6c 29 3b 0a 20 20 64 62 5f 76 70 72 65 70 61 ql);. db_vprepa
3ed0: 72 65 28 26 73 2c 20 30 2c 20 7a 53 71 6c 2c 20 re(&s, 0, zSql,
3ee0: 61 70 29 3b 0a 20 20 76 61 5f 65 6e 64 28 61 70 ap);. va_end(ap
3ef0: 29 3b 0a 20 20 69 66 28 20 64 62 5f 73 74 65 70 );. if( db_step
3f00: 28 26 73 29 21 3d 53 51 4c 49 54 45 5f 52 4f 57 (&s)!=SQLITE_ROW
3f10: 20 29 7b 0a 20 20 20 20 72 63 20 3d 20 69 44 66 ){. rc = iDf
3f20: 6c 74 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 lt;. }else{.
3f30: 20 72 63 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f rc = db_column_
3f40: 69 6e 74 28 26 73 2c 20 30 29 3b 0a 20 20 7d 0a int(&s, 0);. }.
3f50: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 db_finalize(&s
3f60: 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 3b 0a );. return rc;.
3f70: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 }../*.** Return
3f80: 54 52 55 45 20 69 66 20 74 68 65 20 71 75 65 72 TRUE if the quer
3f90: 79 20 77 6f 75 6c 64 20 72 65 74 75 72 6e 20 31 y would return 1
3fa0: 20 6f 72 20 6d 6f 72 65 20 72 6f 77 73 2e 20 20 or more rows.
3fb0: 52 65 74 75 72 6e 0a 2a 2a 20 46 41 4c 53 45 20 Return.** FALSE
3fc0: 69 66 20 74 68 65 20 71 75 65 72 79 20 72 65 73 if the query res
3fd0: 75 6c 74 20 77 6f 75 6c 64 20 62 65 20 61 6e 20 ult would be an
3fe0: 65 6d 70 74 79 20 73 65 74 2e 0a 2a 2f 0a 69 6e empty set..*/.in
3ff0: 74 20 64 62 5f 65 78 69 73 74 73 28 63 6f 6e 73 t db_exists(cons
4000: 74 20 63 68 61 72 20 2a 7a 53 71 6c 2c 20 2e 2e t char *zSql, ..
4010: 2e 29 7b 0a 20 20 76 61 5f 6c 69 73 74 20 61 70 .){. va_list ap
4020: 3b 0a 20 20 53 74 6d 74 20 73 3b 0a 20 20 69 6e ;. Stmt s;. in
4030: 74 20 72 63 3b 0a 20 20 76 61 5f 73 74 61 72 74 t rc;. va_start
4040: 28 61 70 2c 20 7a 53 71 6c 29 3b 0a 20 20 64 62 (ap, zSql);. db
4050: 5f 76 70 72 65 70 61 72 65 28 26 73 2c 20 30 2c _vprepare(&s, 0,
4060: 20 7a 53 71 6c 2c 20 61 70 29 3b 0a 20 20 76 61 zSql, ap);. va
4070: 5f 65 6e 64 28 61 70 29 3b 0a 20 20 69 66 28 20 _end(ap);. if(
4080: 64 62 5f 73 74 65 70 28 26 73 29 21 3d 53 51 4c db_step(&s)!=SQL
4090: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 72 ITE_ROW ){. r
40a0: 63 20 3d 20 30 3b 0a 20 20 7d 65 6c 73 65 7b 0a c = 0;. }else{.
40b0: 20 20 20 20 72 63 20 3d 20 31 3b 0a 20 20 7d 0a rc = 1;. }.
40c0: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 db_finalize(&s
40d0: 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 63 3b 0a );. return rc;.
40e0: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 45 78 65 63 75 74 }.../*.** Execut
40f0: 65 20 61 20 71 75 65 72 79 20 61 6e 64 20 72 65 e a query and re
4100: 74 75 72 6e 20 61 20 66 6c 6f 61 74 69 6e 67 2d turn a floating-
4110: 70 6f 69 6e 74 20 76 61 6c 75 65 2e 0a 2a 2f 0a point value..*/.
4120: 64 6f 75 62 6c 65 20 64 62 5f 64 6f 75 62 6c 65 double db_double
4130: 28 64 6f 75 62 6c 65 20 72 44 66 6c 74 2c 20 63 (double rDflt, c
4140: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c 2c onst char *zSql,
4150: 20 2e 2e 2e 29 7b 0a 20 20 76 61 5f 6c 69 73 74 ...){. va_list
4160: 20 61 70 3b 0a 20 20 53 74 6d 74 20 73 3b 0a 20 ap;. Stmt s;.
4170: 20 64 6f 75 62 6c 65 20 72 3b 0a 20 20 76 61 5f double r;. va_
4180: 73 74 61 72 74 28 61 70 2c 20 7a 53 71 6c 29 3b start(ap, zSql);
4190: 0a 20 20 64 62 5f 76 70 72 65 70 61 72 65 28 26 . db_vprepare(&
41a0: 73 2c 20 30 2c 20 7a 53 71 6c 2c 20 61 70 29 3b s, 0, zSql, ap);
41b0: 0a 20 20 76 61 5f 65 6e 64 28 61 70 29 3b 0a 20 . va_end(ap);.
41c0: 20 69 66 28 20 64 62 5f 73 74 65 70 28 26 73 29 if( db_step(&s)
41d0: 21 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a !=SQLITE_ROW ){.
41e0: 20 20 20 20 72 20 3d 20 72 44 66 6c 74 3b 0a 20 r = rDflt;.
41f0: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 20 3d 20 }else{. r =
4200: 64 62 5f 63 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65 db_column_double
4210: 28 26 73 2c 20 30 29 3b 0a 20 20 7d 0a 20 20 64 (&s, 0);. }. d
4220: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a b_finalize(&s);.
4230: 20 20 72 65 74 75 72 6e 20 72 3b 0a 7d 0a 0a 2f return r;.}../
4240: 2a 0a 2a 2a 20 45 78 65 63 75 74 65 20 61 20 71 *.** Execute a q
4250: 75 65 72 79 20 61 6e 64 20 61 70 70 65 6e 64 20 uery and append
4260: 74 68 65 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e the first column
4270: 20 6f 66 20 74 68 65 20 66 69 72 73 74 20 72 6f of the first ro
4280: 77 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 73 75 w.** of the resu
4290: 6c 74 20 73 65 74 20 74 6f 20 62 6c 6f 62 20 67 lt set to blob g
42a0: 69 76 65 6e 20 69 6e 20 74 68 65 20 66 69 72 73 iven in the firs
42b0: 74 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f 0a 76 t argument..*/.v
42c0: 6f 69 64 20 64 62 5f 62 6c 6f 62 28 42 6c 6f 62 oid db_blob(Blob
42d0: 20 2a 70 52 65 73 75 6c 74 2c 20 63 6f 6e 73 74 *pResult, const
42e0: 20 63 68 61 72 20 2a 7a 53 71 6c 2c 20 2e 2e 2e char *zSql, ...
42f0: 29 7b 0a 20 20 76 61 5f 6c 69 73 74 20 61 70 3b ){. va_list ap;
4300: 0a 20 20 53 74 6d 74 20 73 3b 0a 20 20 76 61 5f . Stmt s;. va_
4310: 73 74 61 72 74 28 61 70 2c 20 7a 53 71 6c 29 3b start(ap, zSql);
4320: 0a 20 20 64 62 5f 76 70 72 65 70 61 72 65 28 26 . db_vprepare(&
4330: 73 2c 20 30 2c 20 7a 53 71 6c 2c 20 61 70 29 3b s, 0, zSql, ap);
4340: 0a 20 20 76 61 5f 65 6e 64 28 61 70 29 3b 0a 20 . va_end(ap);.
4350: 20 69 66 28 20 64 62 5f 73 74 65 70 28 26 73 29 if( db_step(&s)
4360: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a ==SQLITE_ROW ){.
4370: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 blob_append(
4380: 70 52 65 73 75 6c 74 2c 20 73 71 6c 69 74 65 33 pResult, sqlite3
4390: 5f 63 6f 6c 75 6d 6e 5f 62 6c 6f 62 28 73 2e 70 _column_blob(s.p
43a0: 53 74 6d 74 2c 20 30 29 2c 0a 20 20 20 20 20 20 Stmt, 0),.
43b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
43c0: 20 20 20 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d sqlite3_colum
43d0: 6e 5f 62 79 74 65 73 28 73 2e 70 53 74 6d 74 2c n_bytes(s.pStmt,
43e0: 20 30 29 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 0));. }. db_f
43f0: 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 7d 0a 0a inalize(&s);.}..
4400: 2f 2a 0a 2a 2a 20 45 78 65 63 75 74 65 20 61 20 /*.** Execute a
4410: 71 75 65 72 79 2e 20 20 52 65 74 75 72 6e 20 74 query. Return t
4420: 68 65 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 he first column
4430: 6f 66 20 74 68 65 20 66 69 72 73 74 20 72 6f 77 of the first row
4440: 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 73 75 6c .** of the resul
4450: 74 20 73 65 74 20 61 73 20 61 20 73 74 72 69 6e t set as a strin
4460: 67 2e 20 20 53 70 61 63 65 20 74 6f 20 68 6f 6c g. Space to hol
4470: 64 20 74 68 65 20 73 74 72 69 6e 67 20 69 73 0a d the string is.
4480: 2a 2a 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d ** obtained from
4490: 20 6d 61 6c 6c 6f 63 28 29 2e 20 20 49 66 20 74 malloc(). If t
44a0: 68 65 20 72 65 73 75 6c 74 20 73 65 74 20 69 73 he result set is
44b0: 20 65 6d 70 74 79 2c 20 72 65 74 75 72 6e 0a 2a empty, return.*
44c0: 2a 20 7a 44 65 66 61 75 6c 74 20 69 6e 73 74 65 * zDefault inste
44d0: 61 64 2e 0a 2a 2f 0a 63 68 61 72 20 2a 64 62 5f ad..*/.char *db_
44e0: 74 65 78 74 28 63 68 61 72 20 63 6f 6e 73 74 20 text(char const
44f0: 2a 7a 44 65 66 61 75 6c 74 2c 20 63 6f 6e 73 74 *zDefault, const
4500: 20 63 68 61 72 20 2a 7a 53 71 6c 2c 20 2e 2e 2e char *zSql, ...
4510: 29 7b 0a 20 20 76 61 5f 6c 69 73 74 20 61 70 3b ){. va_list ap;
4520: 0a 20 20 53 74 6d 74 20 73 3b 0a 20 20 63 68 61 . Stmt s;. cha
4530: 72 20 2a 7a 3b 0a 20 20 76 61 5f 73 74 61 72 74 r *z;. va_start
4540: 28 61 70 2c 20 7a 53 71 6c 29 3b 0a 20 20 64 62 (ap, zSql);. db
4550: 5f 76 70 72 65 70 61 72 65 28 26 73 2c 20 30 2c _vprepare(&s, 0,
4560: 20 7a 53 71 6c 2c 20 61 70 29 3b 0a 20 20 76 61 zSql, ap);. va
4570: 5f 65 6e 64 28 61 70 29 3b 0a 20 20 69 66 28 20 _end(ap);. if(
4580: 64 62 5f 73 74 65 70 28 26 73 29 3d 3d 53 51 4c db_step(&s)==SQL
4590: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 7a ITE_ROW ){. z
45a0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c = mprintf("%s",
45b0: 20 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f sqlite3_column_
45c0: 74 65 78 74 28 73 2e 70 53 74 6d 74 2c 20 30 29 text(s.pStmt, 0)
45d0: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 7a );. }else if( z
45e0: 44 65 66 61 75 6c 74 20 29 7b 0a 20 20 20 20 7a Default ){. z
45f0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c = mprintf("%s",
4600: 20 7a 44 65 66 61 75 6c 74 29 3b 0a 20 20 7d 65 zDefault);. }e
4610: 6c 73 65 7b 0a 20 20 20 20 7a 20 3d 20 30 3b 0a lse{. z = 0;.
4620: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a }. db_finaliz
4630: 65 28 26 73 29 3b 0a 20 20 72 65 74 75 72 6e 20 e(&s);. return
4640: 7a 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 6e 69 74 z;.}../*.** Init
4650: 69 61 6c 69 7a 65 20 61 20 6e 65 77 20 64 61 74 ialize a new dat
4660: 61 62 61 73 65 20 66 69 6c 65 20 77 69 74 68 20 abase file with
4670: 74 68 65 20 67 69 76 65 6e 20 73 63 68 65 6d 61 the given schema
4680: 2e 20 20 49 66 20 61 6e 79 74 68 69 6e 67 0a 2a . If anything.*
4690: 2a 20 67 6f 65 73 20 77 72 6f 6e 67 2c 20 63 61 * goes wrong, ca
46a0: 6c 6c 20 64 62 5f 65 72 72 28 29 20 74 6f 20 65 ll db_err() to e
46b0: 78 69 74 2e 0a 2a 2f 0a 76 6f 69 64 20 64 62 5f xit..*/.void db_
46c0: 69 6e 69 74 5f 64 61 74 61 62 61 73 65 28 0a 20 init_database(.
46d0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 const char *zFi
46e0: 6c 65 4e 61 6d 65 2c 20 20 20 2f 2a 20 4e 61 6d leName, /* Nam
46f0: 65 20 6f 66 20 64 61 74 61 62 61 73 65 20 66 69 e of database fi
4700: 6c 65 20 74 6f 20 63 72 65 61 74 65 20 2a 2f 0a le to create */.
4710: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 const char *zS
4720: 63 68 65 6d 61 2c 20 20 20 20 20 2f 2a 20 46 69 chema, /* Fi
4730: 72 73 74 20 70 61 72 74 20 6f 66 20 73 63 68 65 rst part of sche
4740: 6d 61 20 2a 2f 0a 20 20 2e 2e 2e 20 20 20 20 20 ma */. ...
4750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4760: 20 2f 2a 20 41 64 64 69 74 69 6f 6e 61 6c 20 53 /* Additional S
4770: 51 4c 20 74 6f 20 72 75 6e 2e 20 20 54 65 72 6d QL to run. Term
4780: 69 6e 61 74 65 20 77 69 74 68 20 4e 55 4c 4c 2e inate with NULL.
4790: 20 2a 2f 0a 29 7b 0a 20 20 73 71 6c 69 74 65 33 */.){. sqlite3
47a0: 20 2a 64 62 3b 0a 20 20 69 6e 74 20 72 63 3b 0a *db;. int rc;.
47b0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 const char *zS
47c0: 71 6c 3b 0a 20 20 76 61 5f 6c 69 73 74 20 61 70 ql;. va_list ap
47d0: 3b 0a 0a 20 20 64 62 20 3d 20 64 62 5f 6f 70 65 ;.. db = db_ope
47e0: 6e 28 7a 46 69 6c 65 4e 61 6d 65 29 3b 0a 20 20 n(zFileName);.
47f0: 73 71 6c 69 74 65 33 5f 65 78 65 63 28 64 62 2c sqlite3_exec(db,
4800: 20 22 42 45 47 49 4e 20 45 58 43 4c 55 53 49 56 "BEGIN EXCLUSIV
4810: 45 22 2c 20 30 2c 20 30 2c 20 30 29 3b 0a 20 20 E", 0, 0, 0);.
4820: 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 65 78 65 rc = sqlite3_exe
4830: 63 28 64 62 2c 20 7a 53 63 68 65 6d 61 2c 20 30 c(db, zSchema, 0
4840: 2c 20 30 2c 20 30 29 3b 0a 20 20 69 66 28 20 72 , 0, 0);. if( r
4850: 63 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b 0a c!=SQLITE_OK ){.
4860: 20 20 20 20 64 62 5f 65 72 72 28 73 71 6c 69 74 db_err(sqlit
4870: 65 33 5f 65 72 72 6d 73 67 28 64 62 29 29 3b 0a e3_errmsg(db));.
4880: 20 20 7d 0a 20 20 76 61 5f 73 74 61 72 74 28 61 }. va_start(a
4890: 70 2c 20 7a 53 63 68 65 6d 61 29 3b 0a 20 20 77 p, zSchema);. w
48a0: 68 69 6c 65 28 20 28 7a 53 71 6c 20 3d 20 76 61 hile( (zSql = va
48b0: 5f 61 72 67 28 61 70 2c 20 63 6f 6e 73 74 20 63 _arg(ap, const c
48c0: 68 61 72 2a 29 29 21 3d 30 20 29 7b 0a 20 20 20 har*))!=0 ){.
48d0: 20 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 65 78 rc = sqlite3_ex
48e0: 65 63 28 64 62 2c 20 7a 53 71 6c 2c 20 30 2c 20 ec(db, zSql, 0,
48f0: 30 2c 20 30 29 3b 0a 20 20 20 20 69 66 28 20 72 0, 0);. if( r
4900: 63 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b 0a c!=SQLITE_OK ){.
4910: 20 20 20 20 20 20 64 62 5f 65 72 72 28 73 71 6c db_err(sql
4920: 69 74 65 33 5f 65 72 72 6d 73 67 28 64 62 29 29 ite3_errmsg(db))
4930: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 76 61 ;. }. }. va
4940: 5f 65 6e 64 28 61 70 29 3b 0a 20 20 73 71 6c 69 _end(ap);. sqli
4950: 74 65 33 5f 65 78 65 63 28 64 62 2c 20 22 43 4f te3_exec(db, "CO
4960: 4d 4d 49 54 22 2c 20 30 2c 20 30 2c 20 30 29 3b MMIT", 0, 0, 0);
4970: 0a 20 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 . sqlite3_close
4980: 28 64 62 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 46 (db);.}../*.** F
4990: 75 6e 63 74 69 6f 6e 20 74 6f 20 72 65 74 75 72 unction to retur
49a0: 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 n the number of
49b0: 73 65 63 6f 6e 64 73 20 73 69 6e 63 65 20 31 39 seconds since 19
49c0: 37 30 2e 20 20 54 68 69 73 20 69 73 0a 2a 2a 20 70. This is.**
49d0: 74 68 65 20 73 61 6d 65 20 61 73 20 73 74 72 66 the same as strf
49e0: 74 69 6d 65 28 27 25 73 27 2c 27 6e 6f 77 27 29 time('%s','now')
49f0: 20 62 75 74 20 69 73 20 6d 6f 72 65 20 63 6f 6d but is more com
4a00: 70 61 63 74 2e 0a 2a 2f 0a 76 6f 69 64 20 64 62 pact..*/.void db
4a10: 5f 6e 6f 77 5f 66 75 6e 63 74 69 6f 6e 28 0a 20 _now_function(.
4a20: 20 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 sqlite3_context
4a30: 20 2a 63 6f 6e 74 65 78 74 2c 0a 20 20 69 6e 74 *context,. int
4a40: 20 61 72 67 63 2c 0a 20 20 73 71 6c 69 74 65 33 argc,. sqlite3
4a50: 5f 76 61 6c 75 65 20 2a 2a 61 72 67 76 0a 29 7b _value **argv.){
4a60: 0a 20 20 73 71 6c 69 74 65 33 5f 72 65 73 75 6c . sqlite3_resul
4a70: 74 5f 69 6e 74 36 34 28 63 6f 6e 74 65 78 74 2c t_int64(context,
4a80: 20 74 69 6d 65 28 30 29 29 3b 0a 7d 0a 0a 2f 2a time(0));.}../*
4a90: 0a 2a 2a 20 46 75 6e 63 74 69 6f 6e 20 74 6f 20 .** Function to
4aa0: 72 65 74 75 72 6e 20 74 68 65 20 63 68 65 63 6b return the check
4ab0: 2d 69 6e 20 74 69 6d 65 20 66 6f 72 20 61 20 66 -in time for a f
4ac0: 69 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 64 62 5f ile..*/.void db_
4ad0: 63 68 65 63 6b 69 6e 5f 6d 74 69 6d 65 5f 66 75 checkin_mtime_fu
4ae0: 6e 63 74 69 6f 6e 28 0a 20 20 73 71 6c 69 74 65 nction(. sqlite
4af0: 33 5f 63 6f 6e 74 65 78 74 20 2a 63 6f 6e 74 65 3_context *conte
4b00: 78 74 2c 0a 20 20 69 6e 74 20 61 72 67 63 2c 0a xt,. int argc,.
4b10: 20 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 sqlite3_value
4b20: 2a 2a 61 72 67 76 0a 29 7b 0a 20 20 69 36 34 20 **argv.){. i64
4b30: 6d 74 69 6d 65 3b 0a 20 20 69 6e 74 20 72 63 20 mtime;. int rc
4b40: 3d 20 6d 74 69 6d 65 5f 6f 66 5f 6d 61 6e 69 66 = mtime_of_manif
4b50: 65 73 74 5f 66 69 6c 65 28 73 71 6c 69 74 65 33 est_file(sqlite3
4b60: 5f 76 61 6c 75 65 5f 69 6e 74 28 61 72 67 76 5b _value_int(argv[
4b70: 30 5d 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 0]),.
4b80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4b90: 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f 76 sqlite3_v
4ba0: 61 6c 75 65 5f 69 6e 74 28 61 72 67 76 5b 31 5d alue_int(argv[1]
4bb0: 29 2c 20 26 6d 74 69 6d 65 29 3b 0a 20 20 69 66 ), &mtime);. if
4bc0: 28 20 72 63 3d 3d 30 20 29 7b 0a 20 20 20 20 73 ( rc==0 ){. s
4bd0: 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 69 6e qlite3_result_in
4be0: 74 36 34 28 63 6f 6e 74 65 78 74 2c 20 6d 74 69 t64(context, mti
4bf0: 6d 65 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a me);. }.}.../*.
4c00: 2a 2a 20 4f 70 65 6e 20 61 20 64 61 74 61 62 61 ** Open a databa
4c10: 73 65 20 66 69 6c 65 2e 20 20 52 65 74 75 72 6e se file. Return
4c20: 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 a pointer to th
4c30: 65 20 6e 65 77 20 64 61 74 61 62 61 73 65 0a 2a e new database.*
4c40: 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 41 * connection. A
4c50: 6e 20 65 72 72 6f 72 20 72 65 73 75 6c 74 73 20 n error results
4c60: 69 6e 20 70 72 6f 63 65 73 73 20 61 62 6f 72 74 in process abort
4c70: 2e 0a 2a 2f 0a 4c 4f 43 41 4c 20 73 71 6c 69 74 ..*/.LOCAL sqlit
4c80: 65 33 20 2a 64 62 5f 6f 70 65 6e 28 63 6f 6e 73 e3 *db_open(cons
4c90: 74 20 63 68 61 72 20 2a 7a 44 62 4e 61 6d 65 29 t char *zDbName)
4ca0: 7b 0a 20 20 69 6e 74 20 72 63 3b 0a 20 20 73 71 {. int rc;. sq
4cb0: 6c 69 74 65 33 20 2a 64 62 3b 0a 0a 23 69 66 20 lite3 *db;..#if
4cc0: 64 65 66 69 6e 65 64 28 5f 5f 43 59 47 57 49 4e defined(__CYGWIN
4cd0: 5f 5f 29 20 26 26 20 55 53 45 5f 53 59 53 54 45 __) && USE_SYSTE
4ce0: 4d 5f 53 51 4c 49 54 45 2b 30 21 3d 31 0a 20 20 M_SQLITE+0!=1.
4cf0: 7a 44 62 4e 61 6d 65 20 3d 20 66 6f 73 73 69 6c zDbName = fossil
4d00: 5f 75 74 66 38 5f 74 6f 5f 66 69 6c 65 6e 61 6d _utf8_to_filenam
4d10: 65 28 7a 44 62 4e 61 6d 65 29 3b 0a 23 65 6e 64 e(zDbName);.#end
4d20: 69 66 0a 20 20 69 66 28 20 67 2e 66 53 71 6c 54 if. if( g.fSqlT
4d30: 72 61 63 65 20 29 20 66 6f 73 73 69 6c 5f 74 72 race ) fossil_tr
4d40: 61 63 65 28 22 2d 2d 20 73 71 6c 69 74 65 33 5f ace("-- sqlite3_
4d50: 6f 70 65 6e 3a 20 5b 25 73 5d 5c 6e 22 2c 20 7a open: [%s]\n", z
4d60: 44 62 4e 61 6d 65 29 3b 0a 20 20 72 63 20 3d 20 DbName);. rc =
4d70: 73 71 6c 69 74 65 33 5f 6f 70 65 6e 5f 76 32 28 sqlite3_open_v2(
4d80: 0a 20 20 20 20 20 20 20 7a 44 62 4e 61 6d 65 2c . zDbName,
4d90: 20 26 64 62 2c 0a 20 20 20 20 20 20 20 53 51 4c &db,. SQL
4da0: 49 54 45 5f 4f 50 45 4e 5f 52 45 41 44 57 52 49 ITE_OPEN_READWRI
4db0: 54 45 20 7c 20 53 51 4c 49 54 45 5f 4f 50 45 4e TE | SQLITE_OPEN
4dc0: 5f 43 52 45 41 54 45 2c 0a 20 20 20 20 20 20 20 _CREATE,.
4dd0: 67 2e 7a 56 66 73 4e 61 6d 65 0a 20 20 29 3b 0a g.zVfsName. );.
4de0: 20 20 69 66 28 20 72 63 21 3d 53 51 4c 49 54 45 if( rc!=SQLITE
4df0: 5f 4f 4b 20 29 7b 0a 20 20 20 20 64 62 5f 65 72 _OK ){. db_er
4e00: 72 28 22 5b 25 73 5d 3a 20 25 73 22 2c 20 7a 44 r("[%s]: %s", zD
4e10: 62 4e 61 6d 65 2c 20 73 71 6c 69 74 65 33 5f 65 bName, sqlite3_e
4e20: 72 72 6d 73 67 28 64 62 29 29 3b 0a 20 20 7d 0a rrmsg(db));. }.
4e30: 20 20 73 71 6c 69 74 65 33 5f 62 75 73 79 5f 74 sqlite3_busy_t
4e40: 69 6d 65 6f 75 74 28 64 62 2c 20 35 30 30 30 29 imeout(db, 5000)
4e50: 3b 0a 20 20 73 71 6c 69 74 65 33 5f 77 61 6c 5f ;. sqlite3_wal_
4e60: 61 75 74 6f 63 68 65 63 6b 70 6f 69 6e 74 28 64 autocheckpoint(d
4e70: 62 2c 20 31 29 3b 20 20 2f 2a 20 53 65 74 20 74 b, 1); /* Set t
4e80: 6f 20 63 68 65 63 6b 70 6f 69 6e 74 20 66 72 65 o checkpoint fre
4e90: 71 75 65 6e 74 6c 79 20 2a 2f 0a 20 20 73 71 6c quently */. sql
4ea0: 69 74 65 33 5f 63 72 65 61 74 65 5f 66 75 6e 63 ite3_create_func
4eb0: 74 69 6f 6e 28 64 62 2c 20 22 6e 6f 77 22 2c 20 tion(db, "now",
4ec0: 30 2c 20 53 51 4c 49 54 45 5f 41 4e 59 2c 20 30 0, SQLITE_ANY, 0
4ed0: 2c 20 64 62 5f 6e 6f 77 5f 66 75 6e 63 74 69 6f , db_now_functio
4ee0: 6e 2c 20 30 2c 20 30 29 3b 0a 20 20 73 71 6c 69 n, 0, 0);. sqli
4ef0: 74 65 33 5f 63 72 65 61 74 65 5f 66 75 6e 63 74 te3_create_funct
4f00: 69 6f 6e 28 64 62 2c 20 22 63 68 65 63 6b 69 6e ion(db, "checkin
4f10: 5f 6d 74 69 6d 65 22 2c 20 32 2c 20 53 51 4c 49 _mtime", 2, SQLI
4f20: 54 45 5f 41 4e 59 2c 20 30 2c 0a 20 20 20 20 20 TE_ANY, 0,.
4f30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4f40: 20 20 20 20 20 64 62 5f 63 68 65 63 6b 69 6e 5f db_checkin_
4f50: 6d 74 69 6d 65 5f 66 75 6e 63 74 69 6f 6e 2c 20 mtime_function,
4f60: 30 2c 20 30 29 3b 0a 20 20 73 71 6c 69 74 65 33 0, 0);. sqlite3
4f70: 5f 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e _create_function
4f80: 28 64 62 2c 20 22 75 73 65 72 22 2c 20 30 2c 20 (db, "user", 0,
4f90: 53 51 4c 49 54 45 5f 41 4e 59 2c 20 30 2c 20 64 SQLITE_ANY, 0, d
4fa0: 62 5f 73 71 6c 5f 75 73 65 72 2c 20 30 2c 20 30 b_sql_user, 0, 0
4fb0: 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 63 72 65 );. sqlite3_cre
4fc0: 61 74 65 5f 66 75 6e 63 74 69 6f 6e 28 64 62 2c ate_function(db,
4fd0: 20 22 63 67 69 22 2c 20 31 2c 20 53 51 4c 49 54 "cgi", 1, SQLIT
4fe0: 45 5f 41 4e 59 2c 20 30 2c 20 64 62 5f 73 71 6c E_ANY, 0, db_sql
4ff0: 5f 63 67 69 2c 20 30 2c 20 30 29 3b 0a 20 20 73 _cgi, 0, 0);. s
5000: 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f 66 75 qlite3_create_fu
5010: 6e 63 74 69 6f 6e 28 64 62 2c 20 22 63 67 69 22 nction(db, "cgi"
5020: 2c 20 32 2c 20 53 51 4c 49 54 45 5f 41 4e 59 2c , 2, SQLITE_ANY,
5030: 20 30 2c 20 64 62 5f 73 71 6c 5f 63 67 69 2c 20 0, db_sql_cgi,
5040: 30 2c 20 30 29 3b 0a 20 20 73 71 6c 69 74 65 33 0, 0);. sqlite3
5050: 5f 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e _create_function
5060: 28 64 62 2c 20 22 70 72 69 6e 74 22 2c 20 2d 31 (db, "print", -1
5070: 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 2c 20 30 , SQLITE_UTF8, 0
5080: 2c 64 62 5f 73 71 6c 5f 70 72 69 6e 74 2c 30 2c ,db_sql_print,0,
5090: 30 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 63 72 0);. sqlite3_cr
50a0: 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 28 0a 20 eate_function(.
50b0: 20 20 20 64 62 2c 20 22 69 73 5f 73 65 6c 65 63 db, "is_selec
50c0: 74 65 64 22 2c 20 31 2c 20 53 51 4c 49 54 45 5f ted", 1, SQLITE_
50d0: 55 54 46 38 2c 20 30 2c 20 66 69 6c 65 5f 69 73 UTF8, 0, file_is
50e0: 5f 73 65 6c 65 63 74 65 64 2c 30 2c 30 0a 20 20 _selected,0,0.
50f0: 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 63 72 65 );. sqlite3_cre
5100: 61 74 65 5f 66 75 6e 63 74 69 6f 6e 28 0a 20 20 ate_function(.
5110: 20 20 64 62 2c 20 22 69 66 5f 73 65 6c 65 63 74 db, "if_select
5120: 65 64 22 2c 20 33 2c 20 53 51 4c 49 54 45 5f 55 ed", 3, SQLITE_U
5130: 54 46 38 2c 20 30 2c 20 66 69 6c 65 5f 69 73 5f TF8, 0, file_is_
5140: 73 65 6c 65 63 74 65 64 2c 30 2c 30 0a 20 20 29 selected,0,0. )
5150: 3b 0a 20 20 69 66 28 20 67 2e 66 53 71 6c 54 72 ;. if( g.fSqlTr
5160: 61 63 65 20 29 20 73 71 6c 69 74 65 33 5f 74 72 ace ) sqlite3_tr
5170: 61 63 65 28 64 62 2c 20 64 62 5f 73 71 6c 5f 74 ace(db, db_sql_t
5180: 72 61 63 65 2c 20 30 29 3b 0a 20 20 72 65 5f 61 race, 0);. re_a
5190: 64 64 5f 73 71 6c 5f 66 75 6e 63 28 64 62 29 3b dd_sql_func(db);
51a0: 0a 20 20 73 71 6c 69 74 65 33 5f 65 78 65 63 28 . sqlite3_exec(
51b0: 64 62 2c 20 22 50 52 41 47 4d 41 20 66 6f 72 65 db, "PRAGMA fore
51c0: 69 67 6e 5f 6b 65 79 73 3d 4f 46 46 3b 22 2c 20 ign_keys=OFF;",
51d0: 30 2c 20 30 2c 20 30 29 3b 0a 20 20 72 65 74 75 0, 0, 0);. retu
51e0: 72 6e 20 64 62 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a rn db;.}.../*.**
51f0: 20 44 65 74 61 63 68 65 73 20 74 68 65 20 7a 4c Detaches the zL
5200: 61 62 65 6c 20 64 61 74 61 62 61 73 65 2e 0a 2a abel database..*
5210: 2f 0a 76 6f 69 64 20 64 62 5f 64 65 74 61 63 68 /.void db_detach
5220: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4c 61 (const char *zLa
5230: 62 65 6c 29 7b 0a 20 20 64 62 5f 6d 75 6c 74 69 bel){. db_multi
5240: 5f 65 78 65 63 28 22 44 45 54 41 43 48 20 44 41 _exec("DETACH DA
5250: 54 41 42 41 53 45 20 25 73 22 2c 20 7a 4c 61 62 TABASE %s", zLab
5260: 65 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 7a 44 el);.}../*.** zD
5270: 62 4e 61 6d 65 20 69 73 20 74 68 65 20 6e 61 6d bName is the nam
5280: 65 20 6f 66 20 61 20 64 61 74 61 62 61 73 65 20 e of a database
5290: 66 69 6c 65 2e 20 20 41 74 74 61 63 68 20 7a 44 file. Attach zD
52a0: 62 4e 61 6d 65 20 75 73 69 6e 67 0a 2a 2a 20 74 bName using.** t
52b0: 68 65 20 6e 61 6d 65 20 7a 4c 61 62 65 6c 2e 0a he name zLabel..
52c0: 2a 2f 0a 76 6f 69 64 20 64 62 5f 61 74 74 61 63 */.void db_attac
52d0: 68 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 h(const char *zD
52e0: 62 4e 61 6d 65 2c 20 63 6f 6e 73 74 20 63 68 61 bName, const cha
52f0: 72 20 2a 7a 4c 61 62 65 6c 29 7b 0a 20 20 64 62 r *zLabel){. db
5300: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 41 54 54 _multi_exec("ATT
5310: 41 43 48 20 44 41 54 41 42 41 53 45 20 25 51 20 ACH DATABASE %Q
5320: 41 53 20 25 73 22 2c 20 7a 44 62 4e 61 6d 65 2c AS %s", zDbName,
5330: 20 7a 4c 61 62 65 6c 29 3b 0a 7d 0a 0a 2f 2a 0a zLabel);.}../*.
5340: 2a 2a 20 7a 44 62 4e 61 6d 65 20 69 73 20 74 68 ** zDbName is th
5350: 65 20 6e 61 6d 65 20 6f 66 20 61 20 64 61 74 61 e name of a data
5360: 62 61 73 65 20 66 69 6c 65 2e 20 20 49 66 20 6e base file. If n
5370: 6f 20 6f 74 68 65 72 20 64 61 74 61 62 61 73 65 o other database
5380: 0a 2a 2a 20 66 69 6c 65 20 69 73 20 6f 70 65 6e .** file is open
5390: 2c 20 74 68 65 6e 20 6f 70 65 6e 20 74 68 69 73 , then open this
53a0: 20 6f 6e 65 2e 20 20 49 66 20 61 6e 6f 74 68 65 one. If anothe
53b0: 72 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 r database file
53c0: 69 73 0a 2a 2a 20 61 6c 72 65 61 64 79 20 6f 70 is.** already op
53d0: 65 6e 2c 20 74 68 65 6e 20 61 74 74 61 63 68 20 en, then attach
53e0: 7a 44 62 4e 61 6d 65 20 75 73 69 6e 67 20 74 68 zDbName using th
53f0: 65 20 6e 61 6d 65 20 7a 4c 61 62 65 6c 2e 0a 2a e name zLabel..*
5400: 2f 0a 76 6f 69 64 20 64 62 5f 6f 70 65 6e 5f 6f /.void db_open_o
5410: 72 5f 61 74 74 61 63 68 28 0a 20 20 63 6f 6e 73 r_attach(. cons
5420: 74 20 63 68 61 72 20 2a 7a 44 62 4e 61 6d 65 2c t char *zDbName,
5430: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
5440: 4c 61 62 65 6c 2c 0a 20 20 69 6e 74 20 2a 70 57 Label,. int *pW
5450: 61 73 41 74 74 61 63 68 65 64 0a 29 7b 0a 20 20 asAttached.){.
5460: 69 66 28 20 21 67 2e 64 62 20 29 7b 0a 20 20 20 if( !g.db ){.
5470: 20 61 73 73 65 72 74 28 20 67 2e 7a 4d 61 69 6e assert( g.zMain
5480: 44 62 54 79 70 65 3d 3d 30 20 29 3b 0a 20 20 20 DbType==0 );.
5490: 20 67 2e 64 62 20 3d 20 64 62 5f 6f 70 65 6e 28 g.db = db_open(
54a0: 7a 44 62 4e 61 6d 65 29 3b 0a 20 20 20 20 67 2e zDbName);. g.
54b0: 7a 4d 61 69 6e 44 62 54 79 70 65 20 3d 20 7a 4c zMainDbType = zL
54c0: 61 62 65 6c 3b 0a 20 20 20 20 69 66 28 20 70 57 abel;. if( pW
54d0: 61 73 41 74 74 61 63 68 65 64 20 29 20 2a 70 57 asAttached ) *pW
54e0: 61 73 41 74 74 61 63 68 65 64 20 3d 20 30 3b 0a asAttached = 0;.
54f0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 61 73 73 }else{. ass
5500: 65 72 74 28 20 67 2e 7a 4d 61 69 6e 44 62 54 79 ert( g.zMainDbTy
5510: 70 65 21 3d 30 20 29 3b 0a 20 20 20 20 64 62 5f pe!=0 );. db_
5520: 61 74 74 61 63 68 28 7a 44 62 4e 61 6d 65 2c 20 attach(zDbName,
5530: 7a 4c 61 62 65 6c 29 3b 0a 20 20 20 20 69 66 28 zLabel);. if(
5540: 20 70 57 61 73 41 74 74 61 63 68 65 64 20 29 20 pWasAttached )
5550: 2a 70 57 61 73 41 74 74 61 63 68 65 64 20 3d 20 *pWasAttached =
5560: 31 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 1;. }.}../*.**
5570: 4f 70 65 6e 20 74 68 65 20 75 73 65 72 20 64 61 Open the user da
5580: 74 61 62 61 73 65 20 69 6e 20 22 7e 2f 2e 66 6f tabase in "~/.fo
5590: 73 73 69 6c 22 2e 20 20 43 72 65 61 74 65 20 74 ssil". Create t
55a0: 68 65 20 64 61 74 61 62 61 73 65 20 61 6e 65 77 he database anew
55b0: 20 69 66 0a 2a 2a 20 69 74 20 64 6f 65 73 20 6e if.** it does n
55c0: 6f 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 ot already exist
55d0: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 75 ..**.** If the u
55e0: 73 65 41 74 74 61 63 68 20 66 6c 61 67 20 69 73 seAttach flag is
55f0: 20 30 20 28 74 68 65 20 75 73 75 61 6c 20 63 61 0 (the usual ca
5600: 73 65 29 20 74 68 65 6e 20 74 68 65 20 75 73 65 se) then the use
5610: 72 20 64 61 74 61 62 61 73 65 20 69 73 0a 2a 2a r database is.**
5620: 20 6f 70 65 6e 65 64 20 6f 6e 20 61 20 73 65 70 opened on a sep
5630: 61 72 61 74 65 20 64 61 74 61 62 61 73 65 20 63 arate database c
5640: 6f 6e 6e 65 63 74 69 6f 6e 20 67 2e 64 62 43 6f onnection g.dbCo
5650: 6e 66 69 67 2e 20 20 54 68 69 73 20 70 72 65 76 nfig. This prev
5660: 65 6e 74 73 0a 2a 2a 20 74 68 65 20 7e 2f 2e 66 ents.** the ~/.f
5670: 6f 73 73 69 6c 20 64 61 74 61 62 61 73 65 20 66 ossil database f
5680: 72 6f 6d 20 62 65 63 6f 6d 69 6e 67 20 6c 6f 63 rom becoming loc
5690: 6b 65 64 20 6f 6e 20 6c 6f 6e 67 20 63 68 65 63 ked on long chec
56a0: 6b 2d 69 6e 20 6f 72 20 73 79 6e 63 0a 2a 2a 20 k-in or sync.**
56b0: 6f 70 65 72 61 74 69 6f 6e 73 20 77 68 69 63 68 operations which
56c0: 20 68 6f 6c 64 20 61 6e 20 65 78 63 6c 75 73 69 hold an exclusi
56d0: 76 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e 20 ve transaction.
56e0: 20 49 6e 20 61 20 66 65 77 20 63 61 73 65 73 2c In a few cases,
56f0: 20 74 68 6f 75 67 68 2c 0a 2a 2a 20 69 74 20 69 though,.** it i
5700: 73 20 63 6f 6e 76 65 6e 69 65 6e 74 20 66 6f 72 s convenient for
5710: 20 74 68 65 20 7e 2f 2e 66 6f 73 73 69 6c 20 74 the ~/.fossil t
5720: 6f 20 62 65 20 61 74 74 61 63 68 65 64 20 74 6f o be attached to
5730: 20 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 the main databa
5740: 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e se.** connection
5750: 20 73 6f 20 74 68 61 74 20 77 65 20 63 61 6e 20 so that we can
5760: 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 65 join between the
5770: 20 76 61 72 69 6f 75 73 20 64 61 74 61 62 61 73 various databas
5780: 65 73 2e 20 20 49 6e 20 74 68 61 74 0a 2a 2a 20 es. In that.**
5790: 63 61 73 65 2c 20 69 6e 76 6f 6b 65 20 74 68 69 case, invoke thi
57a0: 73 20 72 6f 75 74 69 6e 65 20 77 69 74 68 20 75 s routine with u
57b0: 73 65 41 74 74 61 63 68 20 61 73 20 31 2e 0a 2a seAttach as 1..*
57c0: 2f 0a 76 6f 69 64 20 64 62 5f 6f 70 65 6e 5f 63 /.void db_open_c
57d0: 6f 6e 66 69 67 28 69 6e 74 20 75 73 65 41 74 74 onfig(int useAtt
57e0: 61 63 68 29 7b 0a 20 20 63 68 61 72 20 2a 7a 44 ach){. char *zD
57f0: 62 4e 61 6d 65 3b 0a 20 20 63 68 61 72 20 2a 7a bName;. char *z
5800: 48 6f 6d 65 3b 0a 20 20 69 66 28 20 67 2e 7a 43 Home;. if( g.zC
5810: 6f 6e 66 69 67 44 62 4e 61 6d 65 20 29 20 72 65 onfigDbName ) re
5820: 74 75 72 6e 3b 0a 23 69 66 20 64 65 66 69 6e 65 turn;.#if define
5830: 64 28 5f 57 49 4e 33 32 29 20 7c 7c 20 64 65 66 d(_WIN32) || def
5840: 69 6e 65 64 28 5f 5f 43 59 47 57 49 4e 5f 5f 29 ined(__CYGWIN__)
5850: 0a 20 20 7a 48 6f 6d 65 20 3d 20 66 6f 73 73 69 . zHome = fossi
5860: 6c 5f 67 65 74 65 6e 76 28 22 4c 4f 43 41 4c 41 l_getenv("LOCALA
5870: 50 50 44 41 54 41 22 29 3b 0a 20 20 69 66 28 20 PPDATA");. if(
5880: 7a 48 6f 6d 65 3d 3d 30 20 29 7b 0a 20 20 20 20 zHome==0 ){.
5890: 7a 48 6f 6d 65 20 3d 20 66 6f 73 73 69 6c 5f 67 zHome = fossil_g
58a0: 65 74 65 6e 76 28 22 41 50 50 44 41 54 41 22 29 etenv("APPDATA")
58b0: 3b 0a 20 20 20 20 69 66 28 20 7a 48 6f 6d 65 3d ;. if( zHome=
58c0: 3d 30 20 29 7b 0a 20 20 20 20 20 20 63 68 61 72 =0 ){. char
58d0: 20 2a 7a 44 72 69 76 65 20 3d 20 66 6f 73 73 69 *zDrive = fossi
58e0: 6c 5f 67 65 74 65 6e 76 28 22 48 4f 4d 45 44 52 l_getenv("HOMEDR
58f0: 49 56 45 22 29 3b 0a 20 20 20 20 20 20 7a 48 6f IVE");. zHo
5900: 6d 65 20 3d 20 66 6f 73 73 69 6c 5f 67 65 74 65 me = fossil_gete
5910: 6e 76 28 22 48 4f 4d 45 50 41 54 48 22 29 3b 0a nv("HOMEPATH");.
5920: 20 20 20 20 20 20 69 66 28 20 7a 44 72 69 76 65 if( zDrive
5930: 20 26 26 20 7a 48 6f 6d 65 20 29 20 7a 48 6f 6d && zHome ) zHom
5940: 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 e = mprintf("%s%
5950: 73 22 2c 20 7a 44 72 69 76 65 2c 20 7a 48 6f 6d s", zDrive, zHom
5960: 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 e);. }. }.
5970: 69 66 28 20 7a 48 6f 6d 65 3d 3d 30 20 29 7b 0a if( zHome==0 ){.
5980: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c fossil_fatal
5990: 28 22 63 61 6e 6e 6f 74 20 6c 6f 63 61 74 65 20 ("cannot locate
59a0: 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 2d home directory -
59b0: 20 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ".
59c0: 20 20 20 22 70 6c 65 61 73 65 20 73 65 74 20 74 "please set t
59d0: 68 65 20 4c 4f 43 41 4c 41 50 50 44 41 54 41 20 he LOCALAPPDATA
59e0: 6f 72 20 41 50 50 44 41 54 41 20 6f 72 20 48 4f or APPDATA or HO
59f0: 4d 45 50 41 54 48 20 22 0a 20 20 20 20 20 20 20 MEPATH ".
5a00: 20 20 20 20 20 20 20 20 20 22 65 6e 76 69 72 6f "enviro
5a10: 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 73 22 nment variables"
5a20: 29 3b 0a 20 20 7d 0a 23 65 6c 73 65 0a 20 20 7a );. }.#else. z
5a30: 48 6f 6d 65 20 3d 20 66 6f 73 73 69 6c 5f 67 65 Home = fossil_ge
5a40: 74 65 6e 76 28 22 48 4f 4d 45 22 29 3b 0a 20 20 tenv("HOME");.
5a50: 69 66 28 20 7a 48 6f 6d 65 3d 3d 30 20 29 7b 0a if( zHome==0 ){.
5a60: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c fossil_fatal
5a70: 28 22 63 61 6e 6e 6f 74 20 6c 6f 63 61 74 65 20 ("cannot locate
5a80: 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 2d home directory -
5a90: 20 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ".
5aa0: 20 20 20 20 22 70 6c 65 61 73 65 20 73 65 74 20 "please set
5ab0: 74 68 65 20 48 4f 4d 45 20 65 6e 76 69 72 6f 6e the HOME environ
5ac0: 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 22 29 3b ment variable");
5ad0: 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 69 66 . }.#endif. if
5ae0: 28 20 66 69 6c 65 5f 69 73 64 69 72 28 7a 48 6f ( file_isdir(zHo
5af0: 6d 65 29 21 3d 31 20 29 7b 0a 20 20 20 20 66 6f me)!=1 ){. fo
5b00: 73 73 69 6c 5f 66 61 74 61 6c 28 22 69 6e 76 61 ssil_fatal("inva
5b10: 6c 69 64 20 68 6f 6d 65 20 64 69 72 65 63 74 6f lid home directo
5b20: 72 79 3a 20 25 73 22 2c 20 7a 48 6f 6d 65 29 3b ry: %s", zHome);
5b30: 0a 20 20 7d 0a 23 69 66 20 64 65 66 69 6e 65 64 . }.#if defined
5b40: 28 5f 57 49 4e 33 32 29 20 7c 7c 20 64 65 66 69 (_WIN32) || defi
5b50: 6e 65 64 28 5f 5f 43 59 47 57 49 4e 5f 5f 29 0a ned(__CYGWIN__).
5b60: 20 20 2f 2a 20 2e 20 66 69 6c 65 6e 61 6d 65 73 /* . filenames
5b70: 20 67 69 76 65 20 73 6f 6d 65 20 77 69 6e 64 6f give some windo
5b80: 77 20 73 79 73 74 65 6d 73 20 70 72 6f 62 6c 65 w systems proble
5b90: 6d 73 20 61 6e 64 20 6d 61 6e 79 20 61 70 70 73 ms and many apps
5ba0: 20 70 72 6f 62 6c 65 6d 73 20 2a 2f 0a 20 20 7a problems */. z
5bb0: 44 62 4e 61 6d 65 20 3d 20 6d 70 72 69 6e 74 66 DbName = mprintf
5bc0: 28 22 25 2f 2f 5f 66 6f 73 73 69 6c 22 2c 20 7a ("%//_fossil", z
5bd0: 48 6f 6d 65 29 3b 0a 23 65 6c 73 65 0a 20 20 7a Home);.#else. z
5be0: 44 62 4e 61 6d 65 20 3d 20 6d 70 72 69 6e 74 66 DbName = mprintf
5bf0: 28 22 25 73 2f 2e 66 6f 73 73 69 6c 22 2c 20 7a ("%s/.fossil", z
5c00: 48 6f 6d 65 29 3b 0a 23 65 6e 64 69 66 0a 20 20 Home);.#endif.
5c10: 69 66 28 20 66 69 6c 65 5f 73 69 7a 65 28 7a 44 if( file_size(zD
5c20: 62 4e 61 6d 65 29 3c 31 30 32 34 2a 33 20 29 7b bName)<1024*3 ){
5c30: 0a 20 20 20 20 69 66 28 20 66 69 6c 65 5f 61 63 . if( file_ac
5c40: 63 65 73 73 28 7a 48 6f 6d 65 2c 20 57 5f 4f 4b cess(zHome, W_OK
5c50: 29 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 ) ){. fossi
5c60: 6c 5f 66 61 74 61 6c 28 22 68 6f 6d 65 20 64 69 l_fatal("home di
5c70: 72 65 63 74 6f 72 79 20 25 73 20 6d 75 73 74 20 rectory %s must
5c80: 62 65 20 77 72 69 74 65 61 62 6c 65 22 2c 20 7a be writeable", z
5c90: 48 6f 6d 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 Home);. }.
5ca0: 20 64 62 5f 69 6e 69 74 5f 64 61 74 61 62 61 73 db_init_databas
5cb0: 65 28 7a 44 62 4e 61 6d 65 2c 20 7a 43 6f 6e 66 e(zDbName, zConf
5cc0: 69 67 53 63 68 65 6d 61 2c 20 28 63 68 61 72 2a igSchema, (char*
5cd0: 29 30 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 66 )0);. }. if( f
5ce0: 69 6c 65 5f 61 63 63 65 73 73 28 7a 44 62 4e 61 ile_access(zDbNa
5cf0: 6d 65 2c 20 57 5f 4f 4b 29 20 29 7b 0a 20 20 20 me, W_OK) ){.
5d00: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 fossil_fatal("c
5d10: 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 66 69 6c onfiguration fil
5d20: 65 20 25 73 20 6d 75 73 74 20 62 65 20 77 72 69 e %s must be wri
5d30: 74 65 61 62 6c 65 22 2c 20 7a 44 62 4e 61 6d 65 teable", zDbName
5d40: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 75 73 65 );. }. if( use
5d50: 41 74 74 61 63 68 20 29 7b 0a 20 20 20 20 64 62 Attach ){. db
5d60: 5f 6f 70 65 6e 5f 6f 72 5f 61 74 74 61 63 68 28 _open_or_attach(
5d70: 7a 44 62 4e 61 6d 65 2c 20 22 63 6f 6e 66 69 67 zDbName, "config
5d80: 64 62 22 2c 20 26 67 2e 75 73 65 41 74 74 61 63 db", &g.useAttac
5d90: 68 29 3b 0a 20 20 20 20 67 2e 64 62 43 6f 6e 66 h);. g.dbConf
5da0: 69 67 20 3d 20 30 3b 0a 20 20 20 20 67 2e 7a 43 ig = 0;. g.zC
5db0: 6f 6e 66 69 67 44 62 54 79 70 65 20 3d 20 30 3b onfigDbType = 0;
5dc0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 2e . }else{. g.
5dd0: 75 73 65 41 74 74 61 63 68 20 3d 20 30 3b 0a 20 useAttach = 0;.
5de0: 20 20 20 67 2e 64 62 43 6f 6e 66 69 67 20 3d 20 g.dbConfig =
5df0: 64 62 5f 6f 70 65 6e 28 7a 44 62 4e 61 6d 65 29 db_open(zDbName)
5e00: 3b 0a 20 20 20 20 67 2e 7a 43 6f 6e 66 69 67 44 ;. g.zConfigD
5e10: 62 54 79 70 65 20 3d 20 22 63 6f 6e 66 69 67 64 bType = "configd
5e20: 62 22 3b 0a 20 20 7d 0a 20 20 67 2e 7a 43 6f 6e b";. }. g.zCon
5e30: 66 69 67 44 62 4e 61 6d 65 20 3d 20 7a 44 62 4e figDbName = zDbN
5e40: 61 6d 65 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 52 ame;.}.../*.** R
5e50: 65 74 75 72 6e 73 20 54 52 55 45 20 69 66 20 7a eturns TRUE if z
5e60: 54 61 62 6c 65 20 65 78 69 73 74 73 20 69 6e 20 Table exists in
5e70: 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 the local databa
5e80: 73 65 20 62 75 74 20 6c 61 63 6b 73 20 63 6f 6c se but lacks col
5e90: 75 6d 6e 0a 2a 2a 20 7a 43 6f 6c 75 6d 6e 0a 2a umn.** zColumn.*
5ea0: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 64 62 5f /.static int db_
5eb0: 6c 6f 63 61 6c 5f 74 61 62 6c 65 5f 65 78 69 73 local_table_exis
5ec0: 74 73 5f 62 75 74 5f 6c 61 63 6b 73 5f 63 6f 6c ts_but_lacks_col
5ed0: 75 6d 6e 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 umn(. const cha
5ee0: 72 20 2a 7a 54 61 62 6c 65 2c 0a 20 20 63 6f 6e r *zTable,. con
5ef0: 73 74 20 63 68 61 72 20 2a 7a 43 6f 6c 75 6d 6e st char *zColumn
5f00: 0a 29 7b 0a 20 20 63 68 61 72 20 2a 7a 44 65 66 .){. char *zDef
5f10: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 = db_text(0, "S
5f20: 45 4c 45 43 54 20 73 71 6c 20 46 52 4f 4d 20 25 ELECT sql FROM %
5f30: 73 2e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 22 s.sqlite_master"
5f40: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
5f50: 20 20 20 20 22 20 57 48 45 52 45 20 6e 61 6d 65 " WHERE name
5f60: 3d 3d 27 25 73 27 20 2f 2a 73 63 61 6e 2a 2f 22 =='%s' /*scan*/"
5f70: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
5f80: 20 20 20 20 20 64 62 5f 6e 61 6d 65 28 22 6c 6f db_name("lo
5f90: 63 61 6c 64 62 22 29 2c 20 7a 54 61 62 6c 65 29 caldb"), zTable)
5fa0: 3b 0a 20 20 69 6e 74 20 72 63 20 3d 20 30 3b 0a ;. int rc = 0;.
5fb0: 20 20 69 66 28 20 7a 44 65 66 20 29 7b 0a 20 20 if( zDef ){.
5fc0: 20 20 63 68 61 72 20 2a 7a 50 61 74 74 65 72 6e char *zPattern
5fd0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 2a 20 25 73 = mprintf("* %s
5fe0: 20 2a 22 2c 20 7a 43 6f 6c 75 6d 6e 29 3b 0a 20 *", zColumn);.
5ff0: 20 20 20 72 63 20 3d 20 73 74 72 67 6c 6f 62 28 rc = strglob(
6000: 7a 50 61 74 74 65 72 6e 2c 20 7a 44 65 66 29 3d zPattern, zDef)=
6010: 3d 30 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 =0;. fossil_f
6020: 72 65 65 28 7a 50 61 74 74 65 72 6e 29 3b 0a 20 ree(zPattern);.
6030: 20 20 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 7a fossil_free(z
6040: 44 65 66 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 Def);. }. retu
6050: 72 6e 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 rn rc;.}../*.**
6060: 49 66 20 7a 44 62 4e 61 6d 65 20 69 73 20 61 20 If zDbName is a
6070: 76 61 6c 69 64 20 6c 6f 63 61 6c 20 64 61 74 61 valid local data
6080: 62 61 73 65 20 66 69 6c 65 2c 20 6f 70 65 6e 20 base file, open
6090: 69 74 20 61 6e 64 20 72 65 74 75 72 6e 0a 2a 2a it and return.**
60a0: 20 74 72 75 65 2e 20 20 49 66 20 69 74 20 69 73 true. If it is
60b0: 20 6e 6f 74 20 61 20 76 61 6c 69 64 20 6c 6f 63 not a valid loc
60c0: 61 6c 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 al database file
60d0: 2c 20 72 65 74 75 72 6e 20 30 2e 0a 2a 2f 0a 73 , return 0..*/.s
60e0: 74 61 74 69 63 20 69 6e 74 20 69 73 56 61 6c 69 tatic int isVali
60f0: 64 4c 6f 63 61 6c 44 62 28 63 6f 6e 73 74 20 63 dLocalDb(const c
6100: 68 61 72 20 2a 7a 44 62 4e 61 6d 65 29 7b 0a 20 har *zDbName){.
6110: 20 69 36 34 20 6c 73 69 7a 65 3b 0a 20 20 63 68 i64 lsize;. ch
6120: 61 72 20 2a 7a 56 46 69 6c 65 44 65 66 3b 0a 0a ar *zVFileDef;..
6130: 20 20 69 66 28 20 66 69 6c 65 5f 61 63 63 65 73 if( file_acces
6140: 73 28 7a 44 62 4e 61 6d 65 2c 20 46 5f 4f 4b 29 s(zDbName, F_OK)
6150: 20 29 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 6c ) return 0;. l
6160: 73 69 7a 65 20 3d 20 66 69 6c 65 5f 73 69 7a 65 size = file_size
6170: 28 7a 44 62 4e 61 6d 65 29 3b 0a 20 20 69 66 28 (zDbName);. if(
6180: 20 6c 73 69 7a 65 25 31 30 32 34 21 3d 30 20 7c lsize%1024!=0 |
6190: 7c 20 6c 73 69 7a 65 3c 34 30 39 36 20 29 20 72 | lsize<4096 ) r
61a0: 65 74 75 72 6e 20 30 3b 0a 20 20 64 62 5f 6f 70 eturn 0;. db_op
61b0: 65 6e 5f 6f 72 5f 61 74 74 61 63 68 28 7a 44 62 en_or_attach(zDb
61c0: 4e 61 6d 65 2c 20 22 6c 6f 63 61 6c 64 62 22 2c Name, "localdb",
61d0: 20 30 29 3b 0a 20 20 7a 56 46 69 6c 65 44 65 66 0);. zVFileDef
61e0: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 = db_text(0, "S
61f0: 45 4c 45 43 54 20 73 71 6c 20 46 52 4f 4d 20 25 ELECT sql FROM %
6200: 73 2e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 22 s.sqlite_master"
6210: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
6220: 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45 52 " WHER
6230: 45 20 6e 61 6d 65 3d 3d 27 76 66 69 6c 65 27 22 E name=='vfile'"
6240: 2c 20 64 62 5f 6e 61 6d 65 28 22 6c 6f 63 61 6c , db_name("local
6250: 64 62 22 29 29 3b 0a 20 20 69 66 28 20 7a 56 46 db"));. if( zVF
6260: 69 6c 65 44 65 66 3d 3d 30 20 29 20 72 65 74 75 ileDef==0 ) retu
6270: 72 6e 20 30 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 rn 0;.. /* If t
6280: 68 65 20 22 69 73 65 78 65 22 20 63 6f 6c 75 6d he "isexe" colum
6290: 6e 20 69 73 20 6d 69 73 73 69 6e 67 20 66 72 6f n is missing fro
62a0: 6d 20 74 68 65 20 76 66 69 6c 65 20 74 61 62 6c m the vfile tabl
62b0: 65 2c 20 74 68 65 6e 0a 20 20 2a 2a 20 61 64 64 e, then. ** add
62c0: 20 69 74 20 6e 6f 77 2e 20 20 20 54 68 69 73 20 it now. This
62d0: 63 6f 64 65 20 61 64 64 65 64 20 6f 6e 20 32 30 code added on 20
62e0: 31 30 2d 30 33 2d 30 36 2e 20 20 41 66 74 65 72 10-03-06. After
62f0: 20 61 6c 6c 20 75 73 65 72 73 20 68 61 76 65 0a all users have.
6300: 20 20 2a 2a 20 75 70 67 72 61 64 65 64 2c 20 74 ** upgraded, t
6310: 68 69 73 20 63 6f 64 65 20 63 61 6e 20 62 65 20 his code can be
6320: 73 61 66 65 6c 79 20 64 65 6c 65 74 65 64 2e 0a safely deleted..
6330: 20 20 2a 2f 0a 20 20 69 66 28 20 21 73 74 72 67 */. if( !strg
6340: 6c 6f 62 28 22 2a 20 69 73 65 78 65 20 2a 22 2c lob("* isexe *",
6350: 20 7a 56 46 69 6c 65 44 65 66 29 20 29 7b 0a 20 zVFileDef) ){.
6360: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 db_multi_exec
6370: 28 22 41 4c 54 45 52 20 54 41 42 4c 45 20 76 66 ("ALTER TABLE vf
6380: 69 6c 65 20 41 44 44 20 43 4f 4c 55 4d 4e 20 69 ile ADD COLUMN i
6390: 73 65 78 65 20 42 4f 4f 4c 45 41 4e 20 44 45 46 sexe BOOLEAN DEF
63a0: 41 55 4c 54 20 30 22 29 3b 0a 20 20 7d 0a 0a 20 AULT 0");. }..
63b0: 20 2f 2a 20 49 66 20 22 69 73 6c 69 6e 6b 22 2f /* If "islink"/
63c0: 22 69 73 4c 69 6e 6b 22 20 63 6f 6c 75 6d 6e 73 "isLink" columns
63d0: 20 61 72 65 20 6d 69 73 73 69 6e 67 20 66 72 6f are missing fro
63e0: 6d 20 74 61 62 6c 65 73 2c 20 74 68 65 6e 0a 20 m tables, then.
63f0: 20 2a 2a 20 61 64 64 20 74 68 65 6d 20 6e 6f 77 ** add them now
6400: 2e 20 20 20 54 68 69 73 20 63 6f 64 65 20 61 64 . This code ad
6410: 64 65 64 20 6f 6e 20 32 30 31 31 2d 30 31 2d 31 ded on 2011-01-1
6420: 37 20 61 6e 64 20 32 30 31 31 2d 30 38 2d 32 37 7 and 2011-08-27
6430: 2e 0a 20 20 2a 2a 20 41 66 74 65 72 20 61 6c 6c .. ** After all
6440: 20 75 73 65 72 73 20 68 61 76 65 20 75 70 67 72 users have upgr
6450: 61 64 65 64 2c 20 74 68 69 73 20 63 6f 64 65 20 aded, this code
6460: 63 61 6e 20 62 65 20 73 61 66 65 6c 79 20 64 65 can be safely de
6470: 6c 65 74 65 64 2e 0a 20 20 2a 2f 0a 20 20 69 66 leted.. */. if
6480: 28 20 21 73 74 72 67 6c 6f 62 28 22 2a 20 69 73 ( !strglob("* is
6490: 6c 69 6e 6b 20 2a 22 2c 20 7a 56 46 69 6c 65 44 link *", zVFileD
64a0: 65 66 29 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 ef) ){. db_mu
64b0: 6c 74 69 5f 65 78 65 63 28 22 41 4c 54 45 52 20 lti_exec("ALTER
64c0: 54 41 42 4c 45 20 76 66 69 6c 65 20 41 44 44 20 TABLE vfile ADD
64d0: 43 4f 4c 55 4d 4e 20 69 73 6c 69 6e 6b 20 42 4f COLUMN islink BO
64e0: 4f 4c 45 41 4e 20 44 45 46 41 55 4c 54 20 30 22 OLEAN DEFAULT 0"
64f0: 29 3b 0a 20 20 20 20 69 66 28 20 64 62 5f 6c 6f );. if( db_lo
6500: 63 61 6c 5f 74 61 62 6c 65 5f 65 78 69 73 74 73 cal_table_exists
6510: 5f 62 75 74 5f 6c 61 63 6b 73 5f 63 6f 6c 75 6d _but_lacks_colum
6520: 6e 28 22 73 74 61 73 68 66 69 6c 65 22 2c 20 22 n("stashfile", "
6530: 69 73 4c 69 6e 6b 22 29 20 29 7b 0a 20 20 20 20 isLink") ){.
6540: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
6550: 22 41 4c 54 45 52 20 54 41 42 4c 45 20 73 74 61 "ALTER TABLE sta
6560: 73 68 66 69 6c 65 20 41 44 44 20 43 4f 4c 55 4d shfile ADD COLUM
6570: 4e 20 69 73 4c 69 6e 6b 20 42 4f 4f 4c 20 44 45 N isLink BOOL DE
6580: 46 41 55 4c 54 20 30 22 29 3b 0a 20 20 20 20 7d FAULT 0");. }
6590: 0a 20 20 20 20 69 66 28 20 64 62 5f 6c 6f 63 61 . if( db_loca
65a0: 6c 5f 74 61 62 6c 65 5f 65 78 69 73 74 73 5f 62 l_table_exists_b
65b0: 75 74 5f 6c 61 63 6b 73 5f 63 6f 6c 75 6d 6e 28 ut_lacks_column(
65c0: 22 75 6e 64 6f 22 2c 20 22 69 73 4c 69 6e 6b 22 "undo", "isLink"
65d0: 29 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 ) ){. db_mu
65e0: 6c 74 69 5f 65 78 65 63 28 22 41 4c 54 45 52 20 lti_exec("ALTER
65f0: 54 41 42 4c 45 20 75 6e 64 6f 20 41 44 44 20 43 TABLE undo ADD C
6600: 4f 4c 55 4d 4e 20 69 73 4c 69 6e 6b 20 42 4f 4f OLUMN isLink BOO
6610: 4c 45 41 4e 20 44 45 46 41 55 4c 54 20 30 22 29 LEAN DEFAULT 0")
6620: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 ;. }. if(
6630: 64 62 5f 6c 6f 63 61 6c 5f 74 61 62 6c 65 5f 65 db_local_table_e
6640: 78 69 73 74 73 5f 62 75 74 5f 6c 61 63 6b 73 5f xists_but_lacks_
6650: 63 6f 6c 75 6d 6e 28 22 75 6e 64 6f 5f 76 66 69 column("undo_vfi
6660: 6c 65 22 2c 20 22 69 73 6c 69 6e 6b 22 29 20 29 le", "islink") )
6670: 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 {. db_multi
6680: 5f 65 78 65 63 28 22 41 4c 54 45 52 20 54 41 42 _exec("ALTER TAB
6690: 4c 45 20 75 6e 64 6f 5f 76 66 69 6c 65 20 41 44 LE undo_vfile AD
66a0: 44 20 43 4f 4c 55 4d 4e 20 69 73 6c 69 6e 6b 20 D COLUMN islink
66b0: 42 4f 4f 4c 20 44 45 46 41 55 4c 54 20 30 22 29 BOOL DEFAULT 0")
66c0: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 ;. }. }. re
66d0: 74 75 72 6e 20 31 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a turn 1;.}../*.**
66e0: 20 4c 6f 63 61 74 65 20 74 68 65 20 72 6f 6f 74 Locate the root
66f0: 20 64 69 72 65 63 74 6f 72 79 20 6f 66 20 74 68 directory of th
6700: 65 20 6c 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f e local reposito
6710: 72 79 20 74 72 65 65 2e 20 20 54 68 65 20 72 6f ry tree. The ro
6720: 6f 74 0a 2a 2a 20 64 69 72 65 63 74 6f 72 79 20 ot.** directory
6730: 69 73 20 66 6f 75 6e 64 20 62 79 20 73 65 61 72 is found by sear
6740: 63 68 69 6e 67 20 66 6f 72 20 61 20 66 69 6c 65 ching for a file
6750: 20 6e 61 6d 65 64 20 22 5f 46 4f 53 53 49 4c 5f named "_FOSSIL_
6760: 22 20 6f 72 20 22 2e 66 73 6c 63 6b 6f 75 74 22 " or ".fslckout"
6770: 0a 2a 2a 20 74 68 61 74 20 63 6f 6e 74 61 69 6e .** that contain
6780: 73 20 61 20 76 61 6c 69 64 20 72 65 70 6f 73 69 s a valid reposi
6790: 74 6f 72 79 20 64 61 74 61 62 61 73 65 2e 0a 2a tory database..*
67a0: 2a 0a 2a 2a 20 46 6f 72 20 6c 65 67 61 63 79 2c *.** For legacy,
67b0: 20 61 6c 73 6f 20 6c 6f 6f 6b 20 66 6f 72 20 22 also look for "
67c0: 2e 66 6f 73 22 2e 20 20 54 68 65 20 75 73 65 20 .fos". The use
67d0: 6f 66 20 22 2e 66 6f 73 22 20 69 73 20 64 65 70 of ".fos" is dep
67e0: 72 65 63 61 74 65 64 0a 2a 2a 20 73 69 6e 63 65 recated.** since
67f0: 20 22 66 6f 73 22 20 68 61 73 20 6e 65 67 61 74 "fos" has negat
6800: 69 76 65 20 63 6f 6e 6e 6f 74 61 74 69 6f 6e 73 ive connotations
6810: 20 69 6e 20 48 75 6e 67 61 72 69 61 6e 2c 20 77 in Hungarian, w
6820: 65 20 61 72 65 20 74 6f 6c 64 2e 0a 2a 2a 0a 2a e are told..**.*
6830: 2a 20 49 66 20 6e 6f 20 76 61 6c 69 64 20 5f 46 * If no valid _F
6840: 4f 53 53 49 4c 5f 20 6f 72 20 2e 66 73 6c 63 6b OSSIL_ or .fslck
6850: 6f 75 74 20 66 69 6c 65 20 69 73 20 66 6f 75 6e out file is foun
6860: 64 2c 20 77 65 20 6d 6f 76 65 20 75 70 20 6f 6e d, we move up on
6870: 65 20 6c 65 76 65 6c 20 61 6e 64 0a 2a 2a 20 74 e level and.** t
6880: 72 79 20 61 67 61 69 6e 2e 20 4f 6e 63 65 20 74 ry again. Once t
6890: 68 65 20 66 69 6c 65 20 69 73 20 66 6f 75 6e 64 he file is found
68a0: 2c 20 74 68 65 20 67 2e 7a 4c 6f 63 61 6c 52 6f , the g.zLocalRo
68b0: 6f 74 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 ot variable is s
68c0: 65 74 0a 2a 2a 20 74 6f 20 74 68 65 20 72 6f 6f et.** to the roo
68d0: 74 20 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 t of the reposit
68e0: 6f 72 79 20 74 72 65 65 20 61 6e 64 20 74 68 69 ory tree and thi
68f0: 73 20 72 6f 75 74 69 6e 65 20 72 65 74 75 72 6e s routine return
6900: 73 20 31 2e 20 20 49 66 0a 2a 2a 20 6e 6f 20 64 s 1. If.** no d
6910: 61 74 61 62 61 73 65 20 69 73 20 66 6f 75 6e 64 atabase is found
6920: 2c 20 74 68 65 6e 20 74 68 69 73 20 72 6f 75 74 , then this rout
6930: 69 6e 65 20 72 65 74 75 72 6e 20 30 2e 0a 2a 2a ine return 0..**
6940: 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e 65 .** This routine
6950: 20 61 6c 77 61 79 73 20 6f 70 65 6e 73 20 74 68 always opens th
6960: 65 20 75 73 65 72 20 64 61 74 61 62 61 73 65 20 e user database
6970: 72 65 67 61 72 64 6c 65 73 73 20 6f 66 20 77 68 regardless of wh
6980: 65 74 68 65 72 20 6f 72 0a 2a 2a 20 6e 6f 74 20 ether or.** not
6990: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 64 the repository d
69a0: 61 74 61 62 61 73 65 20 69 73 20 66 6f 75 6e 64 atabase is found
69b0: 2e 20 20 49 66 20 74 68 65 20 5f 46 4f 53 53 49 . If the _FOSSI
69c0: 4c 5f 20 6f 72 20 2e 66 73 6c 63 6b 6f 75 74 20 L_ or .fslckout
69d0: 66 69 6c 65 0a 2a 2a 20 69 73 20 66 6f 75 6e 64 file.** is found
69e0: 2c 20 69 74 20 69 73 20 61 74 74 61 63 68 65 64 , it is attached
69f0: 20 74 6f 20 74 68 65 20 6f 70 65 6e 20 64 61 74 to the open dat
6a00: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
6a10: 20 74 6f 6f 2e 0a 2a 2f 0a 69 6e 74 20 64 62 5f too..*/.int db_
6a20: 6f 70 65 6e 5f 6c 6f 63 61 6c 28 63 6f 6e 73 74 open_local(const
6a30: 20 63 68 61 72 20 2a 7a 44 62 4e 61 6d 65 29 7b char *zDbName){
6a40: 0a 20 20 69 6e 74 20 69 2c 20 6e 3b 0a 20 20 63 . int i, n;. c
6a50: 68 61 72 20 7a 50 77 64 5b 32 30 30 30 5d 3b 0a har zPwd[2000];.
6a60: 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 static const c
6a70: 68 61 72 20 61 44 62 4e 61 6d 65 5b 5d 5b 31 30 har aDbName[][10
6a80: 5d 20 3d 20 7b 20 22 5f 46 4f 53 53 49 4c 5f 22 ] = { "_FOSSIL_"
6a90: 2c 20 22 2e 66 73 6c 63 6b 6f 75 74 22 2c 20 22 , ".fslckout", "
6aa0: 2e 66 6f 73 22 20 7d 3b 0a 0a 20 20 69 66 28 20 .fos" };.. if(
6ab0: 67 2e 6c 6f 63 61 6c 4f 70 65 6e 29 20 72 65 74 g.localOpen) ret
6ac0: 75 72 6e 20 31 3b 0a 20 20 66 69 6c 65 5f 67 65 urn 1;. file_ge
6ad0: 74 63 77 64 28 7a 50 77 64 2c 20 73 69 7a 65 6f tcwd(zPwd, sizeo
6ae0: 66 28 7a 50 77 64 29 2d 32 30 29 3b 0a 20 20 6e f(zPwd)-20);. n
6af0: 20 3d 20 73 74 72 6c 65 6e 28 7a 50 77 64 29 3b = strlen(zPwd);
6b00: 0a 20 20 77 68 69 6c 65 28 20 6e 3e 30 20 29 7b . while( n>0 ){
6b10: 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c . for(i=0; i<
6b20: 63 6f 75 6e 74 28 61 44 62 4e 61 6d 65 29 3b 20 count(aDbName);
6b30: 69 2b 2b 29 7b 0a 20 20 20 20 20 20 73 71 6c 69 i++){. sqli
6b40: 74 65 33 5f 73 6e 70 72 69 6e 74 66 28 73 69 7a te3_snprintf(siz
6b50: 65 6f 66 28 7a 50 77 64 29 2d 6e 2c 20 26 7a 50 eof(zPwd)-n, &zP
6b60: 77 64 5b 6e 5d 2c 20 22 2f 25 73 22 2c 20 61 44 wd[n], "/%s", aD
6b70: 62 4e 61 6d 65 5b 69 5d 29 3b 0a 20 20 20 20 20 bName[i]);.
6b80: 20 69 66 28 20 69 73 56 61 6c 69 64 4c 6f 63 61 if( isValidLoca
6b90: 6c 44 62 28 7a 50 77 64 29 20 29 7b 0a 20 20 20 lDb(zPwd) ){.
6ba0: 20 20 20 20 20 2f 2a 20 46 6f 75 6e 64 20 61 20 /* Found a
6bb0: 76 61 6c 69 64 20 63 68 65 63 6b 6f 75 74 20 64 valid checkout d
6bc0: 61 74 61 62 61 73 65 20 66 69 6c 65 20 2a 2f 0a atabase file */.
6bd0: 20 20 20 20 20 20 20 20 7a 50 77 64 5b 6e 5d 20 zPwd[n]
6be0: 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 77 68 69 = 0;. whi
6bf0: 6c 65 28 20 6e 3e 30 20 26 26 20 7a 50 77 64 5b le( n>0 && zPwd[
6c00: 6e 2d 31 5d 3d 3d 27 2f 27 20 29 7b 0a 20 20 20 n-1]=='/' ){.
6c10: 20 20 20 20 20 20 20 6e 2d 2d 3b 0a 20 20 20 20 n--;.
6c20: 20 20 20 20 20 20 7a 50 77 64 5b 6e 5d 20 3d 20 zPwd[n] =
6c30: 30 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 0;. }.
6c40: 20 20 20 20 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f g.zLocalRoo
6c50: 74 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 2f t = mprintf("%s/
6c60: 22 2c 20 7a 50 77 64 29 3b 0a 20 20 20 20 20 20 ", zPwd);.
6c70: 20 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 3d 20 g.localOpen =
6c80: 31 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 6f 70 1;. db_op
6c90: 65 6e 5f 63 6f 6e 66 69 67 28 30 29 3b 0a 20 20 en_config(0);.
6ca0: 20 20 20 20 20 20 64 62 5f 6f 70 65 6e 5f 72 65 db_open_re
6cb0: 70 6f 73 69 74 6f 72 79 28 7a 44 62 4e 61 6d 65 pository(zDbName
6cc0: 29 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 );. retur
6cd0: 6e 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 n 1;. }.
6ce0: 20 7d 0a 20 20 20 20 6e 2d 2d 3b 0a 20 20 20 20 }. n--;.
6cf0: 77 68 69 6c 65 28 20 6e 3e 31 20 26 26 20 7a 50 while( n>1 && zP
6d00: 77 64 5b 6e 5d 21 3d 27 2f 27 20 29 7b 20 6e 2d wd[n]!='/' ){ n-
6d10: 2d 3b 20 7d 0a 20 20 20 20 77 68 69 6c 65 28 20 -; }. while(
6d20: 6e 3e 31 20 26 26 20 7a 50 77 64 5b 6e 2d 31 5d n>1 && zPwd[n-1]
6d30: 3d 3d 27 2f 27 20 29 7b 20 6e 2d 2d 3b 20 7d 0a =='/' ){ n--; }.
6d40: 20 20 20 20 7a 50 77 64 5b 6e 5d 20 3d 20 30 3b zPwd[n] = 0;
6d50: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 41 20 63 68 65 . }.. /* A che
6d60: 63 6b 6f 75 74 20 64 61 74 61 62 61 73 65 20 66 ckout database f
6d70: 69 6c 65 20 63 6f 75 6c 64 20 6e 6f 74 20 62 65 ile could not be
6d80: 20 66 6f 75 6e 64 20 2a 2f 0a 20 20 72 65 74 75 found */. retu
6d90: 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 47 rn 0;.}../*.** G
6da0: 65 74 20 74 68 65 20 66 75 6c 6c 20 70 61 74 68 et the full path
6db0: 6e 61 6d 65 20 74 6f 20 74 68 65 20 72 65 70 6f name to the repo
6dc0: 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 65 20 sitory database
6dd0: 66 69 6c 65 2e 20 20 54 68 65 0a 2a 2a 20 6c 6f file. The.** lo
6de0: 63 61 6c 20 64 61 74 61 62 61 73 65 20 28 74 68 cal database (th
6df0: 65 20 5f 46 4f 53 53 49 4c 5f 20 6f 72 20 2e 66 e _FOSSIL_ or .f
6e00: 73 6c 63 6b 6f 75 74 20 64 61 74 61 62 61 73 65 slckout database
6e10: 29 20 6d 75 73 74 20 68 61 76 65 20 61 6c 72 65 ) must have alre
6e20: 61 64 79 0a 2a 2a 20 62 65 65 6e 20 6f 70 65 6e ady.** been open
6e30: 65 64 20 62 65 66 6f 72 65 20 74 68 69 73 20 72 ed before this r
6e40: 6f 75 74 69 6e 65 20 69 73 20 63 61 6c 6c 65 64 outine is called
6e50: 2e 0a 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 ..*/.const char
6e60: 2a 64 62 5f 72 65 70 6f 73 69 74 6f 72 79 5f 66 *db_repository_f
6e70: 69 6c 65 6e 61 6d 65 28 76 6f 69 64 29 7b 0a 20 ilename(void){.
6e80: 20 73 74 61 74 69 63 20 63 68 61 72 20 2a 7a 52 static char *zR
6e90: 65 70 6f 20 3d 20 30 3b 0a 20 20 61 73 73 65 72 epo = 0;. asser
6ea0: 74 28 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 t( g.localOpen )
6eb0: 3b 0a 20 20 61 73 73 65 72 74 28 20 67 2e 7a 4c ;. assert( g.zL
6ec0: 6f 63 61 6c 52 6f 6f 74 20 29 3b 0a 20 20 69 66 ocalRoot );. if
6ed0: 28 20 7a 52 65 70 6f 3d 3d 30 20 29 7b 0a 20 20 ( zRepo==0 ){.
6ee0: 20 20 7a 52 65 70 6f 20 3d 20 64 62 5f 6c 67 65 zRepo = db_lge
6ef0: 74 28 22 72 65 70 6f 73 69 74 6f 72 79 22 2c 20 t("repository",
6f00: 30 29 3b 0a 20 20 20 20 69 66 28 20 7a 52 65 70 0);. if( zRep
6f10: 6f 20 26 26 20 21 66 69 6c 65 5f 69 73 5f 61 62 o && !file_is_ab
6f20: 73 6f 6c 75 74 65 5f 70 61 74 68 28 7a 52 65 70 solute_path(zRep
6f30: 6f 29 20 29 7b 0a 20 20 20 20 20 20 7a 52 65 70 o) ){. zRep
6f40: 6f 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 o = mprintf("%s%
6f50: 73 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 s", g.zLocalRoot
6f60: 2c 20 7a 52 65 70 6f 29 3b 0a 20 20 20 20 7d 0a , zRepo);. }.
6f70: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a 52 65 }. return zRe
6f80: 70 6f 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4f 70 65 po;.}../*.** Ope
6f90: 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 n the repository
6fa0: 20 64 61 74 61 62 61 73 65 20 67 69 76 65 6e 20 database given
6fb0: 62 79 20 7a 44 62 4e 61 6d 65 2e 20 20 49 66 20 by zDbName. If
6fc0: 7a 44 62 4e 61 6d 65 3d 3d 4e 55 4c 4c 20 74 68 zDbName==NULL th
6fd0: 65 6e 0a 2a 2a 20 67 65 74 20 74 68 65 20 6e 61 en.** get the na
6fe0: 6d 65 20 66 72 6f 6d 20 74 68 65 20 61 6c 72 65 me from the alre
6ff0: 61 64 79 20 6f 70 65 6e 20 6c 6f 63 61 6c 20 64 ady open local d
7000: 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 76 6f 69 64 atabase..*/.void
7010: 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 db_open_reposit
7020: 6f 72 79 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ory(const char *
7030: 7a 44 62 4e 61 6d 65 29 7b 0a 20 20 69 66 28 20 zDbName){. if(
7040: 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e g.repositoryOpen
7050: 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 66 28 ) return;. if(
7060: 20 7a 44 62 4e 61 6d 65 3d 3d 30 20 29 7b 0a 20 zDbName==0 ){.
7070: 20 20 20 69 66 28 20 67 2e 6c 6f 63 61 6c 4f 70 if( g.localOp
7080: 65 6e 20 29 7b 0a 20 20 20 20 20 20 7a 44 62 4e en ){. zDbN
7090: 61 6d 65 20 3d 20 64 62 5f 72 65 70 6f 73 69 74 ame = db_reposit
70a0: 6f 72 79 5f 66 69 6c 65 6e 61 6d 65 28 29 3b 0a ory_filename();.
70b0: 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 7a 44 }. if( zD
70c0: 62 4e 61 6d 65 3d 3d 30 20 29 7b 0a 20 20 20 20 bName==0 ){.
70d0: 20 20 64 62 5f 65 72 72 28 22 75 6e 61 62 6c 65 db_err("unable
70e0: 20 74 6f 20 66 69 6e 64 20 74 68 65 20 6e 61 6d to find the nam
70f0: 65 20 6f 66 20 61 20 72 65 70 6f 73 69 74 6f 72 e of a repositor
7100: 79 20 64 61 74 61 62 61 73 65 22 29 3b 0a 20 20 y database");.
7110: 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 66 69 }. }. if( fi
7120: 6c 65 5f 61 63 63 65 73 73 28 7a 44 62 4e 61 6d le_access(zDbNam
7130: 65 2c 20 52 5f 4f 4b 29 20 7c 7c 20 66 69 6c 65 e, R_OK) || file
7140: 5f 73 69 7a 65 28 7a 44 62 4e 61 6d 65 29 3c 31 _size(zDbName)<1
7150: 30 32 34 20 29 7b 0a 20 20 20 20 69 66 28 20 66 024 ){. if( f
7160: 69 6c 65 5f 61 63 63 65 73 73 28 7a 44 62 4e 61 ile_access(zDbNa
7170: 6d 65 2c 20 30 29 20 29 7b 0a 23 69 66 64 65 66 me, 0) ){.#ifdef
7180: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a FOSSIL_ENABLE_J
7190: 53 4f 4e 0a 20 20 20 20 20 20 67 2e 6a 73 6f 6e SON. g.json
71a0: 2e 72 65 73 75 6c 74 43 6f 64 65 20 3d 20 46 53 .resultCode = FS
71b0: 4c 5f 4a 53 4f 4e 5f 45 5f 44 42 5f 4e 4f 54 5f L_JSON_E_DB_NOT_
71c0: 46 4f 55 4e 44 3b 0a 23 65 6e 64 69 66 0a 20 20 FOUND;.#endif.
71d0: 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 fossil_panic
71e0: 28 22 72 65 70 6f 73 69 74 6f 72 79 20 64 6f 65 ("repository doe
71f0: 73 20 6e 6f 74 20 65 78 69 73 74 20 6f 72 22 0a s not exist or".
7200: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7210: 20 20 20 22 20 69 73 20 69 6e 20 61 6e 20 75 6e " is in an un
7220: 72 65 61 64 61 62 6c 65 20 64 69 72 65 63 74 6f readable directo
7230: 72 79 3a 20 25 73 22 2c 20 7a 44 62 4e 61 6d 65 ry: %s", zDbName
7240: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 );. }else if(
7250: 20 66 69 6c 65 5f 61 63 63 65 73 73 28 7a 44 62 file_access(zDb
7260: 4e 61 6d 65 2c 20 52 5f 4f 4b 29 20 29 7b 0a 23 Name, R_OK) ){.#
7270: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
7280: 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 20 20 20 67 BLE_JSON. g
7290: 2e 6a 73 6f 6e 2e 72 65 73 75 6c 74 43 6f 64 65 .json.resultCode
72a0: 20 3d 20 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 44 45 = FSL_JSON_E_DE
72b0: 4e 49 45 44 3b 0a 23 65 6e 64 69 66 0a 20 20 20 NIED;.#endif.
72c0: 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 fossil_panic(
72d0: 22 72 65 61 64 20 70 65 72 6d 69 73 73 69 6f 6e "read permission
72e0: 20 64 65 6e 69 65 64 20 66 6f 72 20 72 65 70 6f denied for repo
72f0: 73 69 74 6f 72 79 20 25 73 22 2c 20 7a 44 62 4e sitory %s", zDbN
7300: 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b ame);. }else{
7310: 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 .#ifdef FOSSIL_E
7320: 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 20 20 NABLE_JSON.
7330: 20 67 2e 6a 73 6f 6e 2e 72 65 73 75 6c 74 43 6f g.json.resultCo
7340: 64 65 20 3d 20 46 53 4c 5f 4a 53 4f 4e 5f 45 5f de = FSL_JSON_E_
7350: 44 42 5f 4e 4f 54 5f 56 41 4c 49 44 3b 0a 23 65 DB_NOT_VALID;.#e
7360: 6e 64 69 66 0a 20 20 20 20 20 20 66 6f 73 73 69 ndif. fossi
7370: 6c 5f 70 61 6e 69 63 28 22 6e 6f 74 20 61 20 76 l_panic("not a v
7380: 61 6c 69 64 20 72 65 70 6f 73 69 74 6f 72 79 3a alid repository:
7390: 20 25 73 22 2c 20 7a 44 62 4e 61 6d 65 29 3b 0a %s", zDbName);.
73a0: 20 20 20 20 7d 0a 20 20 7d 0a 23 69 66 20 64 65 }. }.#if de
73b0: 66 69 6e 65 64 28 5f 5f 43 59 47 57 49 4e 5f 5f fined(__CYGWIN__
73c0: 29 0a 20 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 ). g.zRepositor
73d0: 79 4e 61 6d 65 20 3d 20 66 6f 73 73 69 6c 5f 75 yName = fossil_u
73e0: 74 66 38 5f 74 6f 5f 66 69 6c 65 6e 61 6d 65 28 tf8_to_filename(
73f0: 7a 44 62 4e 61 6d 65 29 3b 0a 23 65 6c 73 65 0a zDbName);.#else.
7400: 20 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e g.zRepositoryN
7410: 61 6d 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 ame = mprintf("%
7420: 73 22 2c 20 7a 44 62 4e 61 6d 65 29 3b 0a 23 65 s", zDbName);.#e
7430: 6e 64 69 66 0a 20 20 64 62 5f 6f 70 65 6e 5f 6f ndif. db_open_o
7440: 72 5f 61 74 74 61 63 68 28 67 2e 7a 52 65 70 6f r_attach(g.zRepo
7450: 73 69 74 6f 72 79 4e 61 6d 65 2c 20 22 72 65 70 sitoryName, "rep
7460: 6f 73 69 74 6f 72 79 22 2c 20 30 29 3b 0a 20 20 ository", 0);.
7470: 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e g.repositoryOpen
7480: 20 3d 20 31 3b 0a 20 20 2f 2a 20 43 61 63 68 65 = 1;. /* Cache
7490: 20 22 61 6c 6c 6f 77 2d 73 79 6d 6c 69 6e 6b 73 "allow-symlinks
74a0: 22 20 6f 70 74 69 6f 6e 2c 20 62 65 63 61 75 73 " option, becaus
74b0: 65 20 77 65 27 6c 6c 20 6e 65 65 64 20 69 74 20 e we'll need it
74c0: 6f 6e 20 65 76 65 72 79 20 73 74 61 74 20 63 61 on every stat ca
74d0: 6c 6c 20 2a 2f 0a 20 20 67 2e 61 6c 6c 6f 77 53 ll */. g.allowS
74e0: 79 6d 6c 69 6e 6b 73 20 3d 20 64 62 5f 67 65 74 ymlinks = db_get
74f0: 5f 62 6f 6f 6c 65 61 6e 28 22 61 6c 6c 6f 77 2d _boolean("allow-
7500: 73 79 6d 6c 69 6e 6b 73 22 2c 20 30 29 3b 0a 7d symlinks", 0);.}
7510: 0a 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 73 20 66 6f ../*.** Flags fo
7520: 72 20 74 68 65 20 64 62 5f 66 69 6e 64 5f 61 6e r the db_find_an
7530: 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 d_open_repositor
7540: 79 28 29 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f y() function..*/
7550: 0a 23 69 66 20 49 4e 54 45 52 46 41 43 45 0a 23 .#if INTERFACE.#
7560: 64 65 66 69 6e 65 20 4f 50 45 4e 5f 4f 4b 5f 4e define OPEN_OK_N
7570: 4f 54 5f 46 4f 55 4e 44 20 20 20 20 30 78 30 30 OT_FOUND 0x00
7580: 31 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 1 /* Do not
7590: 20 65 72 72 6f 72 20 6f 75 74 20 69 66 20 6e 6f error out if no
75a0: 74 20 66 6f 75 6e 64 20 2a 2f 0a 23 64 65 66 69 t found */.#defi
75b0: 6e 65 20 4f 50 45 4e 5f 41 4e 59 5f 53 43 48 45 ne OPEN_ANY_SCHE
75c0: 4d 41 20 20 20 20 20 20 30 78 30 30 32 20 20 20 MA 0x002
75d0: 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 72 72 /* Do not err
75e0: 6f 72 20 69 66 20 73 63 68 65 6d 61 20 69 73 20 or if schema is
75f0: 77 72 6f 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 0a wrong */.#endif.
7600: 0a 2f 2a 0a 2a 2a 20 54 72 79 20 74 6f 20 66 69 ./*.** Try to fi
7610: 6e 64 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 nd the repositor
7620: 79 20 61 6e 64 20 6f 70 65 6e 20 69 74 2e 20 20 y and open it.
7630: 55 73 65 20 74 68 65 20 2d 52 20 6f 72 20 2d 2d Use the -R or --
7640: 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 6f 70 repository.** op
7650: 74 69 6f 6e 20 74 6f 20 6c 6f 63 61 74 65 20 74 tion to locate t
7660: 68 65 20 72 65 70 6f 73 69 74 6f 72 79 2e 20 20 he repository.
7670: 49 66 20 6e 6f 20 73 75 63 68 20 6f 70 74 69 6f If no such optio
7680: 6e 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2c 20 n is available,
7690: 74 68 65 6e 0a 2a 2a 20 75 73 65 20 74 68 65 20 then.** use the
76a0: 72 65 70 6f 73 69 74 6f 72 79 20 6f 66 20 74 68 repository of th
76b0: 65 20 6f 70 65 6e 20 63 68 65 63 6b 6f 75 74 20 e open checkout
76c0: 69 66 20 74 68 65 72 65 20 69 73 20 6f 6e 65 2e if there is one.
76d0: 0a 2a 2a 0a 2a 2a 20 45 72 72 6f 72 20 6f 75 74 .**.** Error out
76e0: 20 69 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f if the reposito
76f0: 72 79 20 63 61 6e 6e 6f 74 20 62 65 20 6f 70 65 ry cannot be ope
7700: 6e 65 64 2e 0a 2a 2f 0a 76 6f 69 64 20 64 62 5f ned..*/.void db_
7710: 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 find_and_open_re
7720: 70 6f 73 69 74 6f 72 79 28 69 6e 74 20 62 46 6c pository(int bFl
7730: 61 67 73 2c 20 69 6e 74 20 6e 41 72 67 55 73 65 ags, int nArgUse
7740: 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 d){. const char
7750: 20 2a 7a 52 65 70 20 3d 20 66 69 6e 64 5f 6f 70 *zRep = find_op
7760: 74 69 6f 6e 28 22 72 65 70 6f 73 69 74 6f 72 79 tion("repository
7770: 22 2c 20 22 52 22 2c 20 31 29 3b 0a 20 20 69 66 ", "R", 1);. if
7780: 28 20 7a 52 65 70 3d 3d 30 20 26 26 20 6e 41 72 ( zRep==0 && nAr
7790: 67 55 73 65 64 20 26 26 20 67 2e 61 72 67 63 3d gUsed && g.argc=
77a0: 3d 6e 41 72 67 55 73 65 64 2b 31 20 29 7b 0a 20 =nArgUsed+1 ){.
77b0: 20 20 20 7a 52 65 70 20 3d 20 67 2e 61 72 67 76 zRep = g.argv
77c0: 5b 6e 41 72 67 55 73 65 64 5d 3b 0a 20 20 7d 0a [nArgUsed];. }.
77d0: 20 20 69 66 28 20 7a 52 65 70 3d 3d 30 20 29 7b if( zRep==0 ){
77e0: 0a 20 20 20 20 69 66 28 20 64 62 5f 6f 70 65 6e . if( db_open
77f0: 5f 6c 6f 63 61 6c 28 30 29 3d 3d 30 20 29 7b 0a _local(0)==0 ){.
7800: 20 20 20 20 20 20 67 6f 74 6f 20 72 65 70 5f 6e goto rep_n
7810: 6f 74 5f 66 6f 75 6e 64 3b 0a 20 20 20 20 7d 0a ot_found;. }.
7820: 20 20 20 20 7a 52 65 70 20 3d 20 64 62 5f 72 65 zRep = db_re
7830: 70 6f 73 69 74 6f 72 79 5f 66 69 6c 65 6e 61 6d pository_filenam
7840: 65 28 29 3b 0a 20 20 20 20 69 66 28 20 7a 52 65 e();. if( zRe
7850: 70 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 67 6f p==0 ){. go
7860: 74 6f 20 72 65 70 5f 6e 6f 74 5f 66 6f 75 6e 64 to rep_not_found
7870: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 ;. }. }. db
7880: 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 _open_repository
7890: 28 7a 52 65 70 29 3b 0a 20 20 69 66 28 20 67 2e (zRep);. if( g.
78a0: 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 repositoryOpen )
78b0: 7b 0a 20 20 20 20 69 66 28 20 28 62 46 6c 61 67 {. if( (bFlag
78c0: 73 20 26 20 4f 50 45 4e 5f 41 4e 59 5f 53 43 48 s & OPEN_ANY_SCH
78d0: 45 4d 41 29 3d 3d 30 20 29 20 64 62 5f 76 65 72 EMA)==0 ) db_ver
78e0: 69 66 79 5f 73 63 68 65 6d 61 28 29 3b 0a 20 20 ify_schema();.
78f0: 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 72 65 return;. }.re
7900: 70 5f 6e 6f 74 5f 66 6f 75 6e 64 3a 0a 20 20 69 p_not_found:. i
7910: 66 28 20 28 62 46 6c 61 67 73 20 26 20 4f 50 45 f( (bFlags & OPE
7920: 4e 5f 4f 4b 5f 4e 4f 54 5f 46 4f 55 4e 44 29 3d N_OK_NOT_FOUND)=
7930: 3d 30 20 29 7b 0a 23 69 66 64 65 66 20 46 4f 53 =0 ){.#ifdef FOS
7940: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
7950: 20 20 20 20 67 2e 6a 73 6f 6e 2e 72 65 73 75 6c g.json.resul
7960: 74 43 6f 64 65 20 3d 20 46 53 4c 5f 4a 53 4f 4e tCode = FSL_JSON
7970: 5f 45 5f 44 42 5f 4e 4f 54 5f 46 4f 55 4e 44 3b _E_DB_NOT_FOUND;
7980: 0a 23 65 6e 64 69 66 0a 20 20 20 20 69 66 28 20 .#endif. if(
7990: 6e 41 72 67 55 73 65 64 3d 3d 30 20 29 7b 0a 20 nArgUsed==0 ){.
79a0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 fossil_fata
79b0: 6c 28 22 75 73 65 20 2d 2d 72 65 70 6f 73 69 74 l("use --reposit
79c0: 6f 72 79 20 6f 72 20 2d 52 20 74 6f 20 73 70 65 ory or -R to spe
79d0: 63 69 66 79 20 74 68 65 20 72 65 70 6f 73 69 74 cify the reposit
79e0: 6f 72 79 20 64 61 74 61 62 61 73 65 22 29 3b 0a ory database");.
79f0: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
7a00: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 73 fossil_fatal("s
7a10: 70 65 63 69 66 79 20 74 68 65 20 72 65 70 6f 73 pecify the repos
7a20: 69 74 6f 72 79 20 6e 61 6d 65 20 61 73 20 61 20 itory name as a
7a30: 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 61 72 67 command-line arg
7a40: 75 6d 65 6e 74 22 29 3b 0a 20 20 20 20 7d 0a 20 ument");. }.
7a50: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 }.}../*.** Retu
7a60: 72 6e 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 rn the name of t
7a70: 68 65 20 64 61 74 61 62 61 73 65 20 22 6c 6f 63 he database "loc
7a80: 61 6c 64 62 22 2c 20 22 63 6f 6e 66 69 67 64 62 aldb", "configdb
7a90: 22 2c 20 6f 72 20 22 72 65 70 6f 73 69 74 6f 72 ", or "repositor
7aa0: 79 22 2e 0a 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 y"..*/.const cha
7ab0: 72 20 2a 64 62 5f 6e 61 6d 65 28 63 6f 6e 73 74 r *db_name(const
7ac0: 20 63 68 61 72 20 2a 7a 44 62 29 7b 0a 20 20 61 char *zDb){. a
7ad0: 73 73 65 72 74 28 20 66 6f 73 73 69 6c 5f 73 74 ssert( fossil_st
7ae0: 72 63 6d 70 28 7a 44 62 2c 22 6c 6f 63 61 6c 64 rcmp(zDb,"locald
7af0: 62 22 29 3d 3d 30 0a 20 20 20 20 20 20 20 7c 7c b")==0. ||
7b00: 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a fossil_strcmp(z
7b10: 44 62 2c 22 63 6f 6e 66 69 67 64 62 22 29 3d 3d Db,"configdb")==
7b20: 30 0a 20 20 20 20 20 20 20 7c 7c 20 66 6f 73 73 0. || foss
7b30: 69 6c 5f 73 74 72 63 6d 70 28 7a 44 62 2c 22 72 il_strcmp(zDb,"r
7b40: 65 70 6f 73 69 74 6f 72 79 22 29 3d 3d 30 20 29 epository")==0 )
7b50: 3b 0a 20 20 69 66 28 20 66 6f 73 73 69 6c 5f 73 ;. if( fossil_s
7b60: 74 72 63 6d 70 28 7a 44 62 2c 20 67 2e 7a 4d 61 trcmp(zDb, g.zMa
7b70: 69 6e 44 62 54 79 70 65 29 3d 3d 30 20 29 20 7a inDbType)==0 ) z
7b80: 44 62 20 3d 20 22 6d 61 69 6e 22 3b 0a 20 20 72 Db = "main";. r
7b90: 65 74 75 72 6e 20 7a 44 62 3b 0a 7d 0a 0a 2f 2a eturn zDb;.}../*
7ba0: 0a 2a 2a 20 52 65 74 75 72 6e 20 54 52 55 45 20 .** Return TRUE
7bb0: 69 66 20 74 68 65 20 73 63 68 65 6d 61 20 69 73 if the schema is
7bc0: 20 6f 75 74 2d 6f 66 2d 64 61 74 65 0a 2a 2f 0a out-of-date.*/.
7bd0: 69 6e 74 20 64 62 5f 73 63 68 65 6d 61 5f 69 73 int db_schema_is
7be0: 5f 6f 75 74 6f 66 64 61 74 65 28 76 6f 69 64 29 _outofdate(void)
7bf0: 7b 0a 20 20 72 65 74 75 72 6e 20 64 62 5f 65 78 {. return db_ex
7c00: 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20 46 ists("SELECT 1 F
7c10: 52 4f 4d 20 63 6f 6e 66 69 67 22 0a 20 20 20 20 ROM config".
7c20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
7c30: 20 57 48 45 52 45 20 6e 61 6d 65 3d 27 61 75 78 WHERE name='aux
7c40: 2d 73 63 68 65 6d 61 27 22 0a 20 20 20 20 20 20 -schema'".
7c50: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 20 "
7c60: 20 41 4e 44 20 76 61 6c 75 65 3c 3e 27 25 73 27 AND value<>'%s'
7c70: 22 2c 20 41 55 58 5f 53 43 48 45 4d 41 29 3b 0a ", AUX_SCHEMA);.
7c80: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 }../*.** Return
7c90: 74 72 75 65 20 69 66 20 74 68 65 20 64 61 74 61 true if the data
7ca0: 62 61 73 65 20 69 73 20 77 72 69 74 65 61 62 6c base is writeabl
7cb0: 65 0a 2a 2f 0a 69 6e 74 20 64 62 5f 69 73 5f 77 e.*/.int db_is_w
7cc0: 72 69 74 65 61 62 6c 65 28 63 6f 6e 73 74 20 63 riteable(const c
7cd0: 68 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20 72 har *zName){. r
7ce0: 65 74 75 72 6e 20 67 2e 64 62 21 3d 30 20 26 26 eturn g.db!=0 &&
7cf0: 20 21 73 71 6c 69 74 65 33 5f 64 62 5f 72 65 61 !sqlite3_db_rea
7d00: 64 6f 6e 6c 79 28 67 2e 64 62 2c 20 64 62 5f 6e donly(g.db, db_n
7d10: 61 6d 65 28 7a 4e 61 6d 65 29 29 3b 0a 7d 0a 0a ame(zName));.}..
7d20: 2f 2a 0a 2a 2a 20 56 65 72 69 66 79 20 74 68 61 /*.** Verify tha
7d30: 74 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 t the repository
7d40: 20 73 63 68 65 6d 61 20 69 73 20 63 6f 72 72 65 schema is corre
7d50: 63 74 2e 20 20 49 66 20 69 74 20 69 73 20 6e 6f ct. If it is no
7d60: 74 20 63 6f 72 72 65 63 74 2c 0a 2a 2a 20 69 73 t correct,.** is
7d70: 73 75 65 20 61 20 66 61 74 61 6c 20 65 72 72 6f sue a fatal erro
7d80: 72 20 61 6e 64 20 64 69 65 2e 0a 2a 2f 0a 76 6f r and die..*/.vo
7d90: 69 64 20 64 62 5f 76 65 72 69 66 79 5f 73 63 68 id db_verify_sch
7da0: 65 6d 61 28 76 6f 69 64 29 7b 0a 20 20 69 66 28 ema(void){. if(
7db0: 20 64 62 5f 73 63 68 65 6d 61 5f 69 73 5f 6f 75 db_schema_is_ou
7dc0: 74 6f 66 64 61 74 65 28 29 20 29 7b 0a 23 69 66 tofdate() ){.#if
7dd0: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
7de0: 45 5f 4a 53 4f 4e 0a 20 20 20 20 67 2e 6a 73 6f E_JSON. g.jso
7df0: 6e 2e 72 65 73 75 6c 74 43 6f 64 65 20 3d 20 46 n.resultCode = F
7e00: 53 4c 5f 4a 53 4f 4e 5f 45 5f 44 42 5f 4e 45 45 SL_JSON_E_DB_NEE
7e10: 44 53 5f 52 45 42 55 49 4c 44 3b 0a 23 65 6e 64 DS_REBUILD;.#end
7e20: 69 66 0a 20 20 20 20 66 6f 73 73 69 6c 5f 77 61 if. fossil_wa
7e30: 72 6e 69 6e 67 28 22 69 6e 63 6f 72 72 65 63 74 rning("incorrect
7e40: 20 72 65 70 6f 73 69 74 6f 72 79 20 73 63 68 65 repository sche
7e50: 6d 61 20 76 65 72 73 69 6f 6e 22 29 3b 0a 20 20 ma version");.
7e60: 20 20 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e 67 fossil_warning
7e70: 28 22 79 6f 75 72 20 72 65 70 6f 73 69 74 6f 72 ("your repositor
7e80: 79 20 68 61 73 20 73 63 68 65 6d 61 20 76 65 72 y has schema ver
7e90: 73 69 6f 6e 20 5c 22 25 73 5c 22 20 22 0a 20 20 sion \"%s\" ".
7ea0: 20 20 20 20 20 20 20 20 22 62 75 74 20 74 68 69 "but thi
7eb0: 73 20 62 69 6e 61 72 79 20 65 78 70 65 63 74 73 s binary expects
7ec0: 20 76 65 72 73 69 6f 6e 20 5c 22 25 73 5c 22 22 version \"%s\""
7ed0: 2c 0a 20 20 20 20 20 20 20 20 20 20 64 62 5f 67 ,. db_g
7ee0: 65 74 28 22 61 75 78 2d 73 63 68 65 6d 61 22 2c et("aux-schema",
7ef0: 30 29 2c 20 41 55 58 5f 53 43 48 45 4d 41 29 3b 0), AUX_SCHEMA);
7f00: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 . fossil_fata
7f10: 6c 28 22 72 75 6e 20 5c 22 66 6f 73 73 69 6c 20 l("run \"fossil
7f20: 72 65 62 75 69 6c 64 5c 22 20 74 6f 20 66 69 78 rebuild\" to fix
7f30: 20 74 68 69 73 20 70 72 6f 62 6c 65 6d 22 29 3b this problem");
7f40: 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 . }.}.../*.** C
7f50: 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 6d 6f 76 OMMAND: test-mov
7f60: 65 2d 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 0a e-repository.**.
7f70: 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 ** Usage: %fossi
7f80: 6c 20 74 65 73 74 2d 6d 6f 76 65 2d 72 65 70 6f l test-move-repo
7f90: 73 69 74 6f 72 79 20 50 41 54 48 4e 41 4d 45 0a sitory PATHNAME.
7fa0: 2a 2a 0a 2a 2a 20 43 68 61 6e 67 65 20 74 68 65 **.** Change the
7fb0: 20 6c 6f 63 61 74 69 6f 6e 20 6f 66 20 74 68 65 location of the
7fc0: 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61 74 61 repository data
7fd0: 62 61 73 65 20 6f 6e 20 61 20 6c 6f 63 61 6c 20 base on a local
7fe0: 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2a 20 55 73 check-out..** Us
7ff0: 65 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 20 74 e this command t
8000: 6f 20 61 76 6f 69 64 20 68 61 76 69 6e 67 20 74 o avoid having t
8010: 6f 20 63 6c 6f 73 65 20 61 6e 64 20 72 65 6f 70 o close and reop
8020: 65 6e 20 61 20 63 68 65 63 6b 6f 75 74 0a 2a 2a en a checkout.**
8030: 20 77 68 65 6e 20 72 65 6c 6f 63 61 74 69 6e 67 when relocating
8040: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
8050: 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 76 6f 69 database..*/.voi
8060: 64 20 6d 6f 76 65 5f 72 65 70 6f 5f 63 6d 64 28 d move_repo_cmd(
8070: 76 6f 69 64 29 7b 0a 20 20 42 6c 6f 62 20 72 65 void){. Blob re
8080: 70 6f 3b 0a 20 20 63 68 61 72 20 2a 7a 52 65 70 po;. char *zRep
8090: 6f 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 o;. if( g.argc!
80a0: 3d 33 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28 =3 ){. usage(
80b0: 22 50 41 54 48 4e 41 4d 45 22 29 3b 0a 20 20 7d "PATHNAME");. }
80c0: 0a 20 20 66 69 6c 65 5f 63 61 6e 6f 6e 69 63 61 . file_canonica
80d0: 6c 5f 6e 61 6d 65 28 67 2e 61 72 67 76 5b 32 5d l_name(g.argv[2]
80e0: 2c 20 26 72 65 70 6f 2c 20 30 29 3b 0a 20 20 7a , &repo, 0);. z
80f0: 52 65 70 6f 20 3d 20 62 6c 6f 62 5f 73 74 72 28 Repo = blob_str(
8100: 26 72 65 70 6f 29 3b 0a 20 20 69 66 28 20 66 69 &repo);. if( fi
8110: 6c 65 5f 61 63 63 65 73 73 28 7a 52 65 70 6f 2c le_access(zRepo,
8120: 20 30 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 0) ){. fossi
8130: 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 l_fatal("no such
8140: 20 66 69 6c 65 3a 20 25 73 22 2c 20 7a 52 65 70 file: %s", zRep
8150: 6f 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 64 62 o);. }. if( db
8160: 5f 6f 70 65 6e 5f 6c 6f 63 61 6c 28 7a 52 65 70 _open_local(zRep
8170: 6f 29 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 o)==0 ){. fos
8180: 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 74 20 69 sil_fatal("not i
8190: 6e 20 61 20 6c 6f 63 61 6c 20 63 68 65 63 6b 6f n a local checko
81a0: 75 74 22 29 3b 0a 20 20 20 20 72 65 74 75 72 6e ut");. return
81b0: 3b 0a 20 20 7d 0a 20 20 64 62 5f 6f 70 65 6e 5f ;. }. db_open_
81c0: 6f 72 5f 61 74 74 61 63 68 28 7a 52 65 70 6f 2c or_attach(zRepo,
81d0: 20 22 74 65 73 74 5f 72 65 70 6f 22 2c 20 30 29 "test_repo", 0)
81e0: 3b 0a 20 20 64 62 5f 6c 73 65 74 28 22 72 65 70 ;. db_lset("rep
81f0: 6f 73 69 74 6f 72 79 22 2c 20 62 6c 6f 62 5f 73 ository", blob_s
8200: 74 72 28 26 72 65 70 6f 29 29 3b 0a 20 20 64 62 tr(&repo));. db
8210: 5f 63 6c 6f 73 65 28 31 29 3b 0a 7d 0a 0a 0a 2f _close(1);.}.../
8220: 2a 0a 2a 2a 20 4f 70 65 6e 20 74 68 65 20 6c 6f *.** Open the lo
8230: 63 61 6c 20 64 61 74 61 62 61 73 65 2e 20 20 49 cal database. I
8240: 66 20 75 6e 61 62 6c 65 2c 20 65 78 69 74 20 77 f unable, exit w
8250: 69 74 68 20 61 6e 20 65 72 72 6f 72 2e 0a 2a 2f ith an error..*/
8260: 0a 76 6f 69 64 20 64 62 5f 6d 75 73 74 5f 62 65 .void db_must_be
8270: 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 76 6f 69 _within_tree(voi
8280: 64 29 7b 0a 20 20 69 66 28 20 64 62 5f 6f 70 65 d){. if( db_ope
8290: 6e 5f 6c 6f 63 61 6c 28 30 29 3d 3d 30 20 29 7b n_local(0)==0 ){
82a0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 . fossil_fata
82b0: 6c 28 22 63 75 72 72 65 6e 74 20 64 69 72 65 63 l("current direc
82c0: 74 6f 72 79 20 69 73 20 6e 6f 74 20 77 69 74 68 tory is not with
82d0: 69 6e 20 61 6e 20 6f 70 65 6e 20 63 68 65 63 6b in an open check
82e0: 6f 75 74 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f out");. }. db_
82f0: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 open_repository(
8300: 30 29 3b 0a 20 20 64 62 5f 76 65 72 69 66 79 5f 0);. db_verify_
8310: 73 63 68 65 6d 61 28 29 3b 0a 7d 0a 0a 2f 2a 0a schema();.}../*.
8320: 2a 2a 20 43 6c 6f 73 65 20 74 68 65 20 64 61 74 ** Close the dat
8330: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
8340: 2e 0a 2a 2a 0a 2a 2a 20 43 68 65 63 6b 20 66 6f ..**.** Check fo
8350: 72 20 75 6e 66 69 6e 61 6c 69 7a 65 64 20 73 74 r unfinalized st
8360: 61 74 65 6d 65 6e 74 73 20 61 6e 64 20 72 65 70 atements and rep
8370: 6f 72 74 20 65 72 72 6f 72 73 20 69 66 20 74 68 ort errors if th
8380: 65 20 72 65 70 6f 72 74 45 72 72 6f 72 73 0a 2a e reportErrors.*
8390: 2a 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74 72 * argument is tr
83a0: 75 65 2e 20 20 49 67 6e 6f 72 65 20 75 6e 66 69 ue. Ignore unfi
83b0: 6e 61 6c 69 7a 65 64 20 73 74 61 74 65 6d 65 6e nalized statemen
83c0: 74 73 20 77 68 65 6e 20 66 61 6c 73 65 2e 0a 2a ts when false..*
83d0: 2f 0a 76 6f 69 64 20 64 62 5f 63 6c 6f 73 65 28 /.void db_close(
83e0: 69 6e 74 20 72 65 70 6f 72 74 45 72 72 6f 72 73 int reportErrors
83f0: 29 7b 0a 20 20 73 71 6c 69 74 65 33 5f 73 74 6d ){. sqlite3_stm
8400: 74 20 2a 70 53 74 6d 74 3b 0a 20 20 69 66 28 20 t *pStmt;. if(
8410: 67 2e 64 62 3d 3d 30 20 29 20 72 65 74 75 72 6e g.db==0 ) return
8420: 3b 0a 20 20 69 66 28 20 67 2e 66 53 71 6c 53 74 ;. if( g.fSqlSt
8430: 61 74 73 20 29 7b 0a 20 20 20 20 69 6e 74 20 63 ats ){. int c
8440: 75 72 2c 20 68 69 77 74 72 3b 0a 20 20 20 20 73 ur, hiwtr;. s
8450: 71 6c 69 74 65 33 5f 64 62 5f 73 74 61 74 75 73 qlite3_db_status
8460: 28 67 2e 64 62 2c 20 53 51 4c 49 54 45 5f 44 42 (g.db, SQLITE_DB
8470: 53 54 41 54 55 53 5f 4c 4f 4f 4b 41 53 49 44 45 STATUS_LOOKASIDE
8480: 5f 55 53 45 44 2c 20 26 63 75 72 2c 20 26 68 69 _USED, &cur, &hi
8490: 77 74 72 2c 20 30 29 3b 0a 20 20 20 20 66 70 72 wtr, 0);. fpr
84a0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 2d 2d intf(stderr, "--
84b0: 20 4c 4f 4f 4b 41 53 49 44 45 5f 55 53 45 44 20 LOOKASIDE_USED
84c0: 20 20 20 20 20 20 20 20 25 31 30 64 20 25 31 30 %10d %10
84d0: 64 5c 6e 22 2c 20 63 75 72 2c 20 68 69 77 74 72 d\n", cur, hiwtr
84e0: 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 64 );. sqlite3_d
84f0: 62 5f 73 74 61 74 75 73 28 67 2e 64 62 2c 20 53 b_status(g.db, S
8500: 51 4c 49 54 45 5f 44 42 53 54 41 54 55 53 5f 4c QLITE_DBSTATUS_L
8510: 4f 4f 4b 41 53 49 44 45 5f 48 49 54 2c 20 26 63 OOKASIDE_HIT, &c
8520: 75 72 2c 20 26 68 69 77 74 72 2c 20 30 29 3b 0a ur, &hiwtr, 0);.
8530: 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 fprintf(stde
8540: 72 72 2c 20 22 2d 2d 20 4c 4f 4f 4b 41 53 49 44 rr, "-- LOOKASID
8550: 45 5f 48 49 54 20 20 20 20 20 20 20 20 20 20 20 E_HIT
8560: 20 20 20 20 20 20 20 20 20 20 25 31 30 64 5c 6e %10d\n
8570: 22 2c 20 68 69 77 74 72 29 3b 0a 20 20 20 20 73 ", hiwtr);. s
8580: 71 6c 69 74 65 33 5f 64 62 5f 73 74 61 74 75 73 qlite3_db_status
8590: 28 67 2e 64 62 2c 20 53 51 4c 49 54 45 5f 44 42 (g.db, SQLITE_DB
85a0: 53 54 41 54 55 53 5f 4c 4f 4f 4b 41 53 49 44 45 STATUS_LOOKASIDE
85b0: 5f 4d 49 53 53 5f 53 49 5a 45 2c 20 26 63 75 72 _MISS_SIZE, &cur
85c0: 2c 26 68 69 77 74 72 2c 30 29 3b 0a 20 20 20 20 ,&hiwtr,0);.
85d0: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
85e0: 22 2d 2d 20 4c 4f 4f 4b 41 53 49 44 45 5f 4d 49 "-- LOOKASIDE_MI
85f0: 53 53 5f 53 49 5a 45 20 20 20 20 20 20 20 20 20 SS_SIZE
8600: 20 20 20 20 20 20 25 31 30 64 5c 6e 22 2c 20 68 %10d\n", h
8610: 69 77 74 72 29 3b 0a 20 20 20 20 73 71 6c 69 74 iwtr);. sqlit
8620: 65 33 5f 64 62 5f 73 74 61 74 75 73 28 67 2e 64 e3_db_status(g.d
8630: 62 2c 20 53 51 4c 49 54 45 5f 44 42 53 54 41 54 b, SQLITE_DBSTAT
8640: 55 53 5f 4c 4f 4f 4b 41 53 49 44 45 5f 4d 49 53 US_LOOKASIDE_MIS
8650: 53 5f 46 55 4c 4c 2c 20 26 63 75 72 2c 26 68 69 S_FULL, &cur,&hi
8660: 77 74 72 2c 30 29 3b 0a 20 20 20 20 66 70 72 69 wtr,0);. fpri
8670: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 2d 2d 20 ntf(stderr, "--
8680: 4c 4f 4f 4b 41 53 49 44 45 5f 4d 49 53 53 5f 46 LOOKASIDE_MISS_F
8690: 55 4c 4c 20 20 20 20 20 20 20 20 20 20 20 20 20 ULL
86a0: 20 20 25 31 30 64 5c 6e 22 2c 20 68 69 77 74 72 %10d\n", hiwtr
86b0: 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 64 );. sqlite3_d
86c0: 62 5f 73 74 61 74 75 73 28 67 2e 64 62 2c 20 53 b_status(g.db, S
86d0: 51 4c 49 54 45 5f 44 42 53 54 41 54 55 53 5f 43 QLITE_DBSTATUS_C
86e0: 41 43 48 45 5f 55 53 45 44 2c 20 26 63 75 72 2c ACHE_USED, &cur,
86f0: 20 26 68 69 77 74 72 2c 20 30 29 3b 0a 20 20 20 &hiwtr, 0);.
8700: 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c fprintf(stderr,
8710: 20 22 2d 2d 20 43 41 43 48 45 5f 55 53 45 44 20 "-- CACHE_USED
8720: 20 20 20 20 20 20 20 20 20 20 20 20 25 31 30 64 %10d
8730: 5c 6e 22 2c 20 63 75 72 29 3b 0a 20 20 20 20 73 \n", cur);. s
8740: 71 6c 69 74 65 33 5f 64 62 5f 73 74 61 74 75 73 qlite3_db_status
8750: 28 67 2e 64 62 2c 20 53 51 4c 49 54 45 5f 44 42 (g.db, SQLITE_DB
8760: 53 54 41 54 55 53 5f 53 43 48 45 4d 41 5f 55 53 STATUS_SCHEMA_US
8770: 45 44 2c 20 26 63 75 72 2c 20 26 68 69 77 74 72 ED, &cur, &hiwtr
8780: 2c 20 30 29 3b 0a 20 20 20 20 66 70 72 69 6e 74 , 0);. fprint
8790: 66 28 73 74 64 65 72 72 2c 20 22 2d 2d 20 53 43 f(stderr, "-- SC
87a0: 48 45 4d 41 5f 55 53 45 44 20 20 20 20 20 20 20 HEMA_USED
87b0: 20 20 20 20 20 25 31 30 64 5c 6e 22 2c 20 63 75 %10d\n", cu
87c0: 72 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f r);. sqlite3_
87d0: 64 62 5f 73 74 61 74 75 73 28 67 2e 64 62 2c 20 db_status(g.db,
87e0: 53 51 4c 49 54 45 5f 44 42 53 54 41 54 55 53 5f SQLITE_DBSTATUS_
87f0: 53 54 4d 54 5f 55 53 45 44 2c 20 26 63 75 72 2c STMT_USED, &cur,
8800: 20 26 68 69 77 74 72 2c 20 30 29 3b 0a 20 20 20 &hiwtr, 0);.
8810: 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c fprintf(stderr,
8820: 20 22 2d 2d 20 53 54 4d 54 5f 55 53 45 44 20 20 "-- STMT_USED
8830: 20 20 20 20 20 20 20 20 20 20 20 20 25 31 30 64 %10d
8840: 5c 6e 22 2c 20 63 75 72 29 3b 0a 20 20 20 20 73 \n", cur);. s
8850: 71 6c 69 74 65 33 5f 73 74 61 74 75 73 28 53 51 qlite3_status(SQ
8860: 4c 49 54 45 5f 53 54 41 54 55 53 5f 4d 45 4d 4f LITE_STATUS_MEMO
8870: 52 59 5f 55 53 45 44 2c 20 26 63 75 72 2c 20 26 RY_USED, &cur, &
8880: 68 69 77 74 72 2c 20 30 29 3b 0a 20 20 20 20 66 hiwtr, 0);. f
8890: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
88a0: 2d 2d 20 4d 45 4d 4f 52 59 5f 55 53 45 44 20 20 -- MEMORY_USED
88b0: 20 20 20 20 20 20 20 20 20 20 25 31 30 64 20 25 %10d %
88c0: 31 30 64 5c 6e 22 2c 20 63 75 72 2c 20 68 69 77 10d\n", cur, hiw
88d0: 74 72 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 tr);. sqlite3
88e0: 5f 73 74 61 74 75 73 28 53 51 4c 49 54 45 5f 53 _status(SQLITE_S
88f0: 54 41 54 55 53 5f 4d 41 4c 4c 4f 43 5f 53 49 5a TATUS_MALLOC_SIZ
8900: 45 2c 20 26 63 75 72 2c 20 26 68 69 77 74 72 2c E, &cur, &hiwtr,
8910: 20 30 29 3b 0a 20 20 20 20 66 70 72 69 6e 74 66 0);. fprintf
8920: 28 73 74 64 65 72 72 2c 20 22 2d 2d 20 4d 41 4c (stderr, "-- MAL
8930: 4c 4f 43 5f 53 49 5a 45 20 20 20 20 20 20 20 20 LOC_SIZE
8940: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 25 %
8950: 31 30 64 5c 6e 22 2c 20 68 69 77 74 72 29 3b 0a 10d\n", hiwtr);.
8960: 20 20 20 20 73 71 6c 69 74 65 33 5f 73 74 61 74 sqlite3_stat
8970: 75 73 28 53 51 4c 49 54 45 5f 53 54 41 54 55 53 us(SQLITE_STATUS
8980: 5f 4d 41 4c 4c 4f 43 5f 43 4f 55 4e 54 2c 20 26 _MALLOC_COUNT, &
8990: 63 75 72 2c 20 26 68 69 77 74 72 2c 20 30 29 3b cur, &hiwtr, 0);
89a0: 0a 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 . fprintf(std
89b0: 65 72 72 2c 20 22 2d 2d 20 4d 41 4c 4c 4f 43 5f err, "-- MALLOC_
89c0: 43 4f 55 4e 54 20 20 20 20 20 20 20 20 20 20 20 COUNT
89d0: 25 31 30 64 20 25 31 30 64 5c 6e 22 2c 20 63 75 %10d %10d\n", cu
89e0: 72 2c 20 68 69 77 74 72 29 3b 0a 20 20 20 20 73 r, hiwtr);. s
89f0: 71 6c 69 74 65 33 5f 73 74 61 74 75 73 28 53 51 qlite3_status(SQ
8a00: 4c 49 54 45 5f 53 54 41 54 55 53 5f 50 41 47 45 LITE_STATUS_PAGE
8a10: 43 41 43 48 45 5f 4f 56 45 52 46 4c 4f 57 2c 20 CACHE_OVERFLOW,
8a20: 26 63 75 72 2c 20 26 68 69 77 74 72 2c 20 30 29 &cur, &hiwtr, 0)
8a30: 3b 0a 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 ;. fprintf(st
8a40: 64 65 72 72 2c 20 22 2d 2d 20 50 43 41 43 48 45 derr, "-- PCACHE
8a50: 5f 4f 56 46 4c 4f 57 20 20 20 20 20 20 20 20 20 _OVFLOW
8a60: 20 25 31 30 64 20 25 31 30 64 5c 6e 22 2c 20 63 %10d %10d\n", c
8a70: 75 72 2c 20 68 69 77 74 72 29 3b 0a 20 20 20 20 ur, hiwtr);.
8a80: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
8a90: 22 2d 2d 20 70 72 65 70 61 72 65 64 20 73 74 61 "-- prepared sta
8aa0: 74 65 6d 65 6e 74 73 20 20 20 20 25 31 30 64 5c tements %10d\
8ab0: 6e 22 2c 20 64 62 2e 6e 50 72 65 70 61 72 65 29 n", db.nPrepare)
8ac0: 3b 0a 20 20 7d 0a 20 20 77 68 69 6c 65 28 20 64 ;. }. while( d
8ad0: 62 2e 70 41 6c 6c 53 74 6d 74 20 29 7b 0a 20 20 b.pAllStmt ){.
8ae0: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 64 62 db_finalize(db
8af0: 2e 70 41 6c 6c 53 74 6d 74 29 3b 0a 20 20 7d 0a .pAllStmt);. }.
8b00: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
8b10: 74 69 6f 6e 28 31 29 3b 0a 20 20 70 53 74 6d 74 tion(1);. pStmt
8b20: 20 3d 20 30 3b 0a 20 20 69 66 28 20 72 65 70 6f = 0;. if( repo
8b30: 72 74 45 72 72 6f 72 73 20 29 7b 0a 20 20 20 20 rtErrors ){.
8b40: 77 68 69 6c 65 28 20 28 70 53 74 6d 74 20 3d 20 while( (pStmt =
8b50: 73 71 6c 69 74 65 33 5f 6e 65 78 74 5f 73 74 6d sqlite3_next_stm
8b60: 74 28 67 2e 64 62 2c 20 70 53 74 6d 74 29 29 21 t(g.db, pStmt))!
8b70: 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 =0 ){. foss
8b80: 69 6c 5f 77 61 72 6e 69 6e 67 28 22 75 6e 66 69 il_warning("unfi
8b90: 6e 61 6c 69 7a 65 64 20 53 51 4c 20 73 74 61 74 nalized SQL stat
8ba0: 65 6d 65 6e 74 3a 20 5b 25 73 5d 22 2c 20 73 71 ement: [%s]", sq
8bb0: 6c 69 74 65 33 5f 73 71 6c 28 70 53 74 6d 74 29 lite3_sql(pStmt)
8bc0: 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 67 );. }. }. g
8bd0: 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 .repositoryOpen
8be0: 3d 20 30 3b 0a 20 20 67 2e 6c 6f 63 61 6c 4f 70 = 0;. g.localOp
8bf0: 65 6e 20 3d 20 30 3b 0a 20 20 67 2e 7a 43 6f 6e en = 0;. g.zCon
8c00: 66 69 67 44 62 4e 61 6d 65 20 3d 20 4e 55 4c 4c figDbName = NULL
8c10: 3b 0a 20 20 73 71 6c 69 74 65 33 5f 77 61 6c 5f ;. sqlite3_wal_
8c20: 63 68 65 63 6b 70 6f 69 6e 74 28 67 2e 64 62 2c checkpoint(g.db,
8c30: 20 30 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 63 0);. sqlite3_c
8c40: 6c 6f 73 65 28 67 2e 64 62 29 3b 0a 20 20 67 2e lose(g.db);. g.
8c50: 64 62 20 3d 20 30 3b 0a 20 20 67 2e 7a 4d 61 69 db = 0;. g.zMai
8c60: 6e 44 62 54 79 70 65 20 3d 20 30 3b 0a 20 20 69 nDbType = 0;. i
8c70: 66 28 20 67 2e 64 62 43 6f 6e 66 69 67 20 29 7b f( g.dbConfig ){
8c80: 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 63 6c 6f . sqlite3_clo
8c90: 73 65 28 67 2e 64 62 43 6f 6e 66 69 67 29 3b 0a se(g.dbConfig);.
8ca0: 20 20 20 20 67 2e 64 62 43 6f 6e 66 69 67 20 3d g.dbConfig =
8cb0: 20 30 3b 0a 20 20 20 20 67 2e 7a 43 6f 6e 66 69 0;. g.zConfi
8cc0: 67 44 62 54 79 70 65 20 3d 20 30 3b 0a 20 20 7d gDbType = 0;. }
8cd0: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 72 65 61 74 .}.../*.** Creat
8ce0: 65 20 61 20 6e 65 77 20 65 6d 70 74 79 20 72 65 e a new empty re
8cf0: 70 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 pository databas
8d00: 65 20 77 69 74 68 20 74 68 65 20 67 69 76 65 6e e with the given
8d10: 20 6e 61 6d 65 2e 0a 2a 2a 0a 2a 2a 20 4f 6e 6c name..**.** Onl
8d20: 79 20 74 68 65 20 73 63 68 65 6d 61 20 69 73 20 y the schema is
8d30: 69 6e 69 74 69 61 6c 69 7a 65 64 2e 20 20 54 68 initialized. Th
8d40: 65 20 72 65 71 75 69 72 65 64 20 56 41 52 20 74 e required VAR t
8d50: 61 62 6c 65 73 20 65 6e 74 72 69 65 73 0a 2a 2a ables entries.**
8d60: 20 61 72 65 20 6e 6f 74 20 73 65 74 20 62 79 20 are not set by
8d70: 74 68 69 73 20 72 6f 75 74 69 6e 65 20 61 6e 64 this routine and
8d80: 20 6d 75 73 74 20 62 65 20 73 65 74 20 73 65 70 must be set sep
8d90: 61 72 61 74 65 6c 79 20 69 6e 20 6f 72 64 65 72 arately in order
8da0: 0a 2a 2a 20 74 6f 20 6d 61 6b 65 20 74 68 65 20 .** to make the
8db0: 6e 65 77 20 66 69 6c 65 20 61 20 76 61 6c 69 64 new file a valid
8dc0: 20 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 76 6f database..*/.vo
8dd0: 69 64 20 64 62 5f 63 72 65 61 74 65 5f 72 65 70 id db_create_rep
8de0: 6f 73 69 74 6f 72 79 28 63 6f 6e 73 74 20 63 68 ository(const ch
8df0: 61 72 20 2a 7a 46 69 6c 65 6e 61 6d 65 29 7b 0a ar *zFilename){.
8e00: 20 20 64 62 5f 69 6e 69 74 5f 64 61 74 61 62 61 db_init_databa
8e10: 73 65 28 0a 20 20 20 20 20 7a 46 69 6c 65 6e 61 se(. zFilena
8e20: 6d 65 2c 0a 20 20 20 20 20 7a 52 65 70 6f 73 69 me,. zReposi
8e30: 74 6f 72 79 53 63 68 65 6d 61 31 2c 0a 20 20 20 torySchema1,.
8e40: 20 20 7a 52 65 70 6f 73 69 74 6f 72 79 53 63 68 zRepositorySch
8e50: 65 6d 61 44 65 66 61 75 6c 74 52 65 70 6f 72 74 emaDefaultReport
8e60: 73 2c 0a 20 20 20 20 20 7a 52 65 70 6f 73 69 74 s,. zReposit
8e70: 6f 72 79 53 63 68 65 6d 61 32 2c 0a 20 20 20 20 orySchema2,.
8e80: 20 28 63 68 61 72 2a 29 30 0a 20 20 29 3b 0a 20 (char*)0. );.
8e90: 20 64 62 5f 64 65 6c 65 74 65 5f 6f 6e 5f 66 61 db_delete_on_fa
8ea0: 69 6c 75 72 65 28 7a 46 69 6c 65 6e 61 6d 65 29 ilure(zFilename)
8eb0: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 72 65 61 74 ;.}../*.** Creat
8ec0: 65 20 74 68 65 20 64 65 66 61 75 6c 74 20 75 73 e the default us
8ed0: 65 72 20 61 63 63 6f 75 6e 74 73 20 69 6e 20 74 er accounts in t
8ee0: 68 65 20 55 53 45 52 20 74 61 62 6c 65 2e 0a 2a he USER table..*
8ef0: 2f 0a 76 6f 69 64 20 64 62 5f 63 72 65 61 74 65 /.void db_create
8f00: 5f 64 65 66 61 75 6c 74 5f 75 73 65 72 73 28 69 _default_users(i
8f10: 6e 74 20 73 65 74 75 70 55 73 65 72 4f 6e 6c 79 nt setupUserOnly
8f20: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 , const char *zD
8f30: 65 66 61 75 6c 74 55 73 65 72 29 7b 0a 20 20 63 efaultUser){. c
8f40: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 73 65 72 onst char *zUser
8f50: 20 3d 20 7a 44 65 66 61 75 6c 74 55 73 65 72 3b = zDefaultUser;
8f60: 0a 20 20 69 66 28 20 7a 55 73 65 72 3d 3d 30 20 . if( zUser==0
8f70: 29 7b 0a 20 20 20 20 7a 55 73 65 72 20 3d 20 64 ){. zUser = d
8f80: 62 5f 67 65 74 28 22 64 65 66 61 75 6c 74 2d 75 b_get("default-u
8f90: 73 65 72 22 2c 20 30 29 3b 0a 20 20 7d 0a 20 20 ser", 0);. }.
8fa0: 69 66 28 20 7a 55 73 65 72 3d 3d 30 20 29 7b 0a if( zUser==0 ){.
8fb0: 20 20 20 20 7a 55 73 65 72 20 3d 20 66 6f 73 73 zUser = foss
8fc0: 69 6c 5f 67 65 74 65 6e 76 28 22 46 4f 53 53 49 il_getenv("FOSSI
8fd0: 4c 5f 55 53 45 52 22 29 3b 0a 20 20 7d 0a 20 20 L_USER");. }.
8fe0: 69 66 28 20 7a 55 73 65 72 3d 3d 30 20 29 7b 0a if( zUser==0 ){.
8ff0: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e #if defined(_WIN
9000: 33 32 29 0a 20 20 20 20 7a 55 73 65 72 20 3d 20 32). zUser =
9010: 66 6f 73 73 69 6c 5f 67 65 74 65 6e 76 28 22 55 fossil_getenv("U
9020: 53 45 52 4e 41 4d 45 22 29 3b 0a 23 65 6c 73 65 SERNAME");.#else
9030: 0a 20 20 20 20 7a 55 73 65 72 20 3d 20 66 6f 73 . zUser = fos
9040: 73 69 6c 5f 67 65 74 65 6e 76 28 22 55 53 45 52 sil_getenv("USER
9050: 22 29 3b 0a 20 20 20 20 69 66 28 20 7a 55 73 65 ");. if( zUse
9060: 72 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 7a 55 r==0 ){. zU
9070: 73 65 72 20 3d 20 66 6f 73 73 69 6c 5f 67 65 74 ser = fossil_get
9080: 65 6e 76 28 22 4c 4f 47 4e 41 4d 45 22 29 3b 0a env("LOGNAME");.
9090: 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 7d }.#endif. }
90a0: 0a 20 20 69 66 28 20 7a 55 73 65 72 3d 3d 30 20 . if( zUser==0
90b0: 29 7b 0a 20 20 20 20 7a 55 73 65 72 20 3d 20 22 ){. zUser = "
90c0: 72 6f 6f 74 22 3b 0a 20 20 7d 0a 20 20 64 62 5f root";. }. db_
90d0: 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 multi_exec(.
90e0: 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f "INSERT OR IGNO
90f0: 52 45 20 49 4e 54 4f 20 75 73 65 72 28 6c 6f 67 RE INTO user(log
9100: 69 6e 2c 20 69 6e 66 6f 29 20 56 41 4c 55 45 53 in, info) VALUES
9110: 28 25 51 2c 27 27 29 22 2c 20 7a 55 73 65 72 0a (%Q,'')", zUser.
9120: 20 20 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f );. db_multi_
9130: 65 78 65 63 28 0a 20 20 20 20 20 22 55 50 44 41 exec(. "UPDA
9140: 54 45 20 75 73 65 72 20 53 45 54 20 63 61 70 3d TE user SET cap=
9150: 27 73 27 2c 20 70 77 3d 6c 6f 77 65 72 28 68 65 's', pw=lower(he
9160: 78 28 72 61 6e 64 6f 6d 62 6c 6f 62 28 33 29 29 x(randomblob(3))
9170: 29 22 0a 20 20 20 20 20 22 20 57 48 45 52 45 20 )". " WHERE
9180: 6c 6f 67 69 6e 3d 25 51 22 2c 20 7a 55 73 65 72 login=%Q", zUser
9190: 0a 20 20 29 3b 0a 20 20 69 66 28 20 21 73 65 74 . );. if( !set
91a0: 75 70 55 73 65 72 4f 6e 6c 79 20 29 7b 0a 20 20 upUserOnly ){.
91b0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
91c0: 0a 20 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 . "INSERT
91d0: 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 75 OR IGNORE INTO u
91e0: 73 65 72 28 6c 6f 67 69 6e 2c 70 77 2c 63 61 70 ser(login,pw,cap
91f0: 2c 69 6e 66 6f 29 22 0a 20 20 20 20 20 20 20 22 ,info)". "
9200: 20 20 20 56 41 4c 55 45 53 28 27 61 6e 6f 6e 79 VALUES('anony
9210: 6d 6f 75 73 27 2c 68 65 78 28 72 61 6e 64 6f 6d mous',hex(random
9220: 62 6c 6f 62 28 38 29 29 2c 27 68 6d 6e 63 7a 27 blob(8)),'hmncz'
9230: 2c 27 41 6e 6f 6e 27 29 3b 22 0a 20 20 20 20 20 ,'Anon');".
9240: 20 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e "INSERT OR IGN
9250: 4f 52 45 20 49 4e 54 4f 20 75 73 65 72 28 6c 6f ORE INTO user(lo
9260: 67 69 6e 2c 70 77 2c 63 61 70 2c 69 6e 66 6f 29 gin,pw,cap,info)
9270: 22 0a 20 20 20 20 20 20 20 22 20 20 20 56 41 4c ". " VAL
9280: 55 45 53 28 27 6e 6f 62 6f 64 79 27 2c 27 27 2c UES('nobody','',
9290: 27 67 6a 6f 72 27 2c 27 4e 6f 62 6f 64 79 27 29 'gjor','Nobody')
92a0: 3b 22 0a 20 20 20 20 20 20 20 22 49 4e 53 45 52 ;". "INSER
92b0: 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f T OR IGNORE INTO
92c0: 20 75 73 65 72 28 6c 6f 67 69 6e 2c 70 77 2c 63 user(login,pw,c
92d0: 61 70 2c 69 6e 66 6f 29 22 0a 20 20 20 20 20 20 ap,info)".
92e0: 20 22 20 20 20 56 41 4c 55 45 53 28 27 64 65 76 " VALUES('dev
92f0: 65 6c 6f 70 65 72 27 2c 27 27 2c 27 64 65 69 27 eloper','','dei'
9300: 2c 27 44 65 76 27 29 3b 22 0a 20 20 20 20 20 20 ,'Dev');".
9310: 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f "INSERT OR IGNO
9320: 52 45 20 49 4e 54 4f 20 75 73 65 72 28 6c 6f 67 RE INTO user(log
9330: 69 6e 2c 70 77 2c 63 61 70 2c 69 6e 66 6f 29 22 in,pw,cap,info)"
9340: 0a 20 20 20 20 20 20 20 22 20 20 20 56 41 4c 55 . " VALU
9350: 45 53 28 27 72 65 61 64 65 72 27 2c 27 27 2c 27 ES('reader','','
9360: 6b 70 74 77 27 2c 27 52 65 61 64 65 72 27 29 3b kptw','Reader');
9370: 22 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 7d 0a 0a ". );. }.}..
9380: 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 61 20 70 /*.** Return a p
9390: 6f 69 6e 74 65 72 20 74 6f 20 61 20 73 74 72 69 ointer to a stri
93a0: 6e 67 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 ng that contains
93b0: 20 74 68 65 20 52 48 53 20 6f 66 20 61 6e 20 49 the RHS of an I
93c0: 4e 20 6f 70 65 72 61 74 6f 72 0a 2a 2a 20 74 68 N operator.** th
93d0: 61 74 20 77 69 6c 6c 20 73 65 6c 65 63 74 20 43 at will select C
93e0: 4f 4e 46 49 47 20 74 61 62 6c 65 20 6e 61 6d 65 ONFIG table name
93f0: 73 20 74 68 61 74 20 61 72 65 20 69 6e 20 74 68 s that are in th
9400: 65 20 6c 69 73 74 20 6f 66 20 63 6f 6e 74 72 6f e list of contro
9410: 6c 0a 2a 2a 20 73 65 74 74 69 6e 67 73 2e 0a 2a l.** settings..*
9420: 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 64 62 /.const char *db
9430: 5f 73 65 74 74 69 6e 67 5f 69 6e 6f 70 5f 72 68 _setting_inop_rh
9440: 73 28 29 7b 0a 20 20 42 6c 6f 62 20 78 3b 0a 20 s(){. Blob x;.
9450: 20 69 6e 74 20 69 3b 0a 20 20 63 6f 6e 73 74 20 int i;. const
9460: 63 68 61 72 20 2a 7a 53 65 70 20 3d 20 22 22 3b char *zSep = "";
9470: 0a 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 78 .. blob_zero(&x
9480: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 );. blob_append
9490: 28 26 78 2c 20 22 28 22 2c 20 31 29 3b 0a 20 20 (&x, "(", 1);.
94a0: 66 6f 72 28 69 3d 30 3b 20 63 74 72 6c 53 65 74 for(i=0; ctrlSet
94b0: 74 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 3b 20 69 tings[i].name; i
94c0: 2b 2b 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 ++){. blob_ap
94d0: 70 65 6e 64 66 28 26 78 2c 20 22 25 73 27 25 73 pendf(&x, "%s'%s
94e0: 27 22 2c 20 7a 53 65 70 2c 20 63 74 72 6c 53 65 '", zSep, ctrlSe
94f0: 74 74 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 29 3b ttings[i].name);
9500: 0a 20 20 20 20 7a 53 65 70 20 3d 20 22 2c 22 3b . zSep = ",";
9510: 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65 . }. blob_appe
9520: 6e 64 28 26 78 2c 20 22 29 22 2c 20 31 29 3b 0a nd(&x, ")", 1);.
9530: 20 20 72 65 74 75 72 6e 20 62 6c 6f 62 5f 73 74 return blob_st
9540: 72 28 26 78 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 r(&x);.}../*.**
9550: 46 69 6c 6c 20 61 6e 20 65 6d 70 74 79 20 72 65 Fill an empty re
9560: 70 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 pository databas
9570: 65 20 77 69 74 68 20 74 68 65 20 62 61 73 69 63 e with the basic
9580: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 66 6f 72 information for
9590: 20 61 0a 2a 2a 20 72 65 70 6f 73 69 74 6f 72 79 a.** repository
95a0: 2e 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 . This function
95b0: 69 73 20 73 68 61 72 65 64 20 62 65 74 77 65 65 is shared betwee
95c0: 6e 20 27 63 72 65 61 74 65 5f 72 65 70 6f 73 69 n 'create_reposi
95d0: 74 6f 72 79 5f 63 6d 64 27 0a 2a 2a 20 28 27 6e tory_cmd'.** ('n
95e0: 65 77 27 29 20 61 6e 64 20 27 72 65 63 6f 6e 73 ew') and 'recons
95f0: 74 72 75 63 74 5f 63 6d 64 27 20 28 27 72 65 63 truct_cmd' ('rec
9600: 6f 6e 73 74 72 75 63 74 27 29 2c 20 62 6f 74 68 onstruct'), both
9610: 20 6f 66 20 77 68 69 63 68 20 63 72 65 61 74 65 of which create
9620: 0a 2a 2a 20 6e 65 77 20 72 65 70 6f 73 69 74 6f .** new reposito
9630: 72 69 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 ries..**.** The
9640: 7a 54 65 6d 70 6c 61 74 65 20 70 61 72 61 6d 65 zTemplate parame
9650: 74 65 72 20 64 65 74 65 72 6d 69 6e 65 73 20 69 ter determines i
9660: 66 20 74 68 65 20 73 65 74 74 69 6e 67 73 20 66 f the settings f
9670: 6f 72 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 or the repositor
9680: 79 0a 2a 2a 20 73 68 6f 75 6c 64 20 62 65 20 63 y.** should be c
9690: 6f 70 69 65 64 20 66 72 6f 6d 20 61 6e 6f 74 68 opied from anoth
96a0: 65 72 20 72 65 70 6f 73 69 74 6f 72 79 2e 20 20 er repository.
96b0: 49 66 20 7a 54 65 6d 70 6c 61 74 65 20 69 73 20 If zTemplate is
96c0: 30 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 73 65 0 then the.** se
96d0: 74 74 69 6e 67 73 20 77 69 6c 6c 20 68 61 76 65 ttings will have
96e0: 20 74 68 65 69 72 20 6e 6f 72 6d 61 6c 20 64 65 their normal de
96f0: 66 61 75 6c 74 20 76 61 6c 75 65 73 2e 20 20 49 fault values. I
9700: 66 20 7a 54 65 6d 70 6c 61 74 65 20 69 73 0a 2a f zTemplate is.*
9710: 2a 20 6e 6f 6e 2d 7a 65 72 6f 2c 20 69 74 20 69 * non-zero, it i
9720: 73 20 61 73 73 75 6d 65 64 20 74 68 61 74 20 74 s assumed that t
9730: 68 65 20 63 61 6c 6c 65 72 20 6f 66 20 74 68 69 he caller of thi
9740: 73 20 66 75 6e 63 74 69 6f 6e 20 68 61 73 20 61 s function has a
9750: 6c 72 65 61 64 79 0a 2a 2a 20 61 74 74 61 63 68 lready.** attach
9760: 65 64 20 61 20 64 61 74 61 62 61 73 65 20 75 73 ed a database us
9770: 69 6e 67 20 74 68 65 20 6c 61 62 65 6c 20 22 73 ing the label "s
9780: 65 74 74 69 6e 67 53 72 63 22 2e 20 20 49 66 20 ettingSrc". If
9790: 6e 6f 74 2c 20 74 68 65 20 63 61 6c 6c 20 74 6f not, the call to
97a0: 0a 2a 2a 20 74 68 69 73 20 66 75 6e 63 74 69 6f .** this functio
97b0: 6e 20 77 69 6c 6c 20 66 61 69 6c 2e 0a 2a 2a 0a n will fail..**.
97c0: 2a 2a 20 54 68 65 20 7a 49 6e 69 74 69 61 6c 44 ** The zInitialD
97d0: 61 74 65 20 70 61 72 61 6d 65 74 65 72 20 64 65 ate parameter de
97e0: 74 65 72 6d 69 6e 65 73 20 74 68 65 20 64 61 74 termines the dat
97f0: 65 20 6f 66 20 74 68 65 20 69 6e 69 74 69 61 6c e of the initial
9800: 20 63 68 65 63 6b 2d 69 6e 0a 2a 2a 20 74 68 61 check-in.** tha
9810: 74 20 69 73 20 61 75 74 6f 6d 61 74 69 63 61 6c t is automatical
9820: 6c 79 20 63 72 65 61 74 65 64 2e 20 20 49 66 20 ly created. If
9830: 7a 49 6e 69 74 69 61 6c 44 61 74 65 20 69 73 20 zInitialDate is
9840: 30 20 74 68 65 6e 20 6e 6f 20 69 6e 69 74 69 61 0 then no initia
9850: 6c 0a 2a 2a 20 63 68 65 63 6b 2d 69 6e 20 69 73 l.** check-in is
9860: 20 63 72 65 61 74 65 64 2e 20 54 68 65 20 6d 61 created. The ma
9870: 6b 65 53 65 72 76 65 72 43 6f 64 65 73 20 66 6c keServerCodes fl
9880: 61 67 20 64 65 74 65 72 6d 69 6e 65 73 20 77 68 ag determines wh
9890: 65 74 68 65 72 20 6f 72 0a 2a 2a 20 6e 6f 74 20 ether or.** not
98a0: 73 65 72 76 65 72 20 61 6e 64 20 70 72 6f 6a 65 server and proje
98b0: 63 74 20 63 6f 64 65 73 20 61 72 65 20 69 6e 76 ct codes are inv
98c0: 65 6e 74 65 64 20 66 6f 72 20 74 68 69 73 20 72 ented for this r
98d0: 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2f 0a 76 6f epository..*/.vo
98e0: 69 64 20 64 62 5f 69 6e 69 74 69 61 6c 5f 73 65 id db_initial_se
98f0: 74 75 70 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 tup(. const cha
9900: 72 20 2a 7a 54 65 6d 70 6c 61 74 65 2c 20 20 20 r *zTemplate,
9910: 20 20 20 20 2f 2a 20 52 65 70 6f 73 69 74 6f 72 /* Repositor
9920: 79 20 66 72 6f 6d 20 77 68 69 63 68 20 74 6f 20 y from which to
9930: 63 6f 70 79 20 73 65 74 74 69 6e 67 73 2e 20 2a copy settings. *
9940: 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
9950: 7a 49 6e 69 74 69 61 6c 44 61 74 65 2c 20 20 20 zInitialDate,
9960: 20 2f 2a 20 49 6e 69 74 69 61 6c 20 64 61 74 65 /* Initial date
9970: 20 6f 66 20 72 65 70 6f 73 69 74 6f 72 79 2e 20 of repository.
9980: 28 65 78 3a 20 22 6e 6f 77 22 29 20 2a 2f 0a 20 (ex: "now") */.
9990: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 65 const char *zDe
99a0: 66 61 75 6c 74 55 73 65 72 2c 20 20 20 20 2f 2a faultUser, /*
99b0: 20 44 65 66 61 75 6c 74 20 75 73 65 72 20 66 6f Default user fo
99c0: 72 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 r the repository
99d0: 20 2a 2f 0a 20 20 69 6e 74 20 6d 61 6b 65 53 65 */. int makeSe
99e0: 72 76 65 72 43 6f 64 65 73 20 20 20 20 20 20 20 rverCodes
99f0: 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 6d 61 /* True to ma
9a00: 6b 65 20 6e 65 77 20 73 65 72 76 65 72 20 26 20 ke new server &
9a10: 70 72 6f 6a 65 63 74 20 63 6f 64 65 73 20 2a 2f project codes */
9a20: 0a 29 7b 0a 20 20 63 68 61 72 20 2a 7a 44 61 74 .){. char *zDat
9a30: 65 3b 0a 20 20 42 6c 6f 62 20 68 61 73 68 3b 0a e;. Blob hash;.
9a40: 20 20 42 6c 6f 62 20 6d 61 6e 69 66 65 73 74 3b Blob manifest;
9a50: 0a 0a 20 20 64 62 5f 73 65 74 28 22 63 6f 6e 74 .. db_set("cont
9a60: 65 6e 74 2d 73 63 68 65 6d 61 22 2c 20 43 4f 4e ent-schema", CON
9a70: 54 45 4e 54 5f 53 43 48 45 4d 41 2c 20 30 29 3b TENT_SCHEMA, 0);
9a80: 0a 20 20 64 62 5f 73 65 74 28 22 61 75 78 2d 73 . db_set("aux-s
9a90: 63 68 65 6d 61 22 2c 20 41 55 58 5f 53 43 48 45 chema", AUX_SCHE
9aa0: 4d 41 2c 20 30 29 3b 0a 20 20 64 62 5f 73 65 74 MA, 0);. db_set
9ab0: 28 22 72 65 62 75 69 6c 74 22 2c 20 67 65 74 5f ("rebuilt", get_
9ac0: 76 65 72 73 69 6f 6e 28 29 2c 20 30 29 3b 0a 20 version(), 0);.
9ad0: 20 69 66 28 20 6d 61 6b 65 53 65 72 76 65 72 43 if( makeServerC
9ae0: 6f 64 65 73 20 29 7b 0a 20 20 20 20 64 62 5f 6d odes ){. db_m
9af0: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 ulti_exec(.
9b00: 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 63 6f "INSERT INTO co
9b10: 6e 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 65 2c nfig(name,value,
9b20: 6d 74 69 6d 65 29 22 0a 20 20 20 20 20 20 22 20 mtime)". "
9b30: 56 41 4c 55 45 53 28 27 73 65 72 76 65 72 2d 63 VALUES('server-c
9b40: 6f 64 65 27 2c 20 6c 6f 77 65 72 28 68 65 78 28 ode', lower(hex(
9b50: 72 61 6e 64 6f 6d 62 6c 6f 62 28 32 30 29 29 29 randomblob(20)))
9b60: 2c 6e 6f 77 28 29 29 3b 22 0a 20 20 20 20 20 20 ,now());".
9b70: 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 63 6f 6e "INSERT INTO con
9b80: 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 65 2c 6d fig(name,value,m
9b90: 74 69 6d 65 29 22 0a 20 20 20 20 20 20 22 20 56 time)". " V
9ba0: 41 4c 55 45 53 28 27 70 72 6f 6a 65 63 74 2d 63 ALUES('project-c
9bb0: 6f 64 65 27 2c 20 6c 6f 77 65 72 28 68 65 78 28 ode', lower(hex(
9bc0: 72 61 6e 64 6f 6d 62 6c 6f 62 28 32 30 29 29 29 randomblob(20)))
9bd0: 2c 6e 6f 77 28 29 29 3b 22 0a 20 20 20 20 29 3b ,now());". );
9be0: 0a 20 20 7d 0a 20 20 69 66 28 20 21 64 62 5f 69 . }. if( !db_i
9bf0: 73 5f 67 6c 6f 62 61 6c 28 22 61 75 74 6f 73 79 s_global("autosy
9c00: 6e 63 22 29 20 29 20 64 62 5f 73 65 74 5f 69 6e nc") ) db_set_in
9c10: 74 28 22 61 75 74 6f 73 79 6e 63 22 2c 20 31 2c t("autosync", 1,
9c20: 20 30 29 3b 0a 20 20 69 66 28 20 21 64 62 5f 69 0);. if( !db_i
9c30: 73 5f 67 6c 6f 62 61 6c 28 22 6c 6f 63 61 6c 61 s_global("locala
9c40: 75 74 68 22 29 20 29 20 64 62 5f 73 65 74 5f 69 uth") ) db_set_i
9c50: 6e 74 28 22 6c 6f 63 61 6c 61 75 74 68 22 2c 20 nt("localauth",
9c60: 30 2c 20 30 29 3b 0a 20 20 69 66 28 20 21 64 62 0, 0);. if( !db
9c70: 5f 69 73 5f 67 6c 6f 62 61 6c 28 22 74 69 6d 65 _is_global("time
9c80: 6c 69 6e 65 2d 70 6c 61 69 6e 74 65 78 74 22 29 line-plaintext")
9c90: 20 29 7b 0a 20 20 20 20 64 62 5f 73 65 74 5f 69 ){. db_set_i
9ca0: 6e 74 28 22 74 69 6d 65 6c 69 6e 65 2d 70 6c 61 nt("timeline-pla
9cb0: 69 6e 74 65 78 74 22 2c 20 31 2c 20 30 29 3b 0a intext", 1, 0);.
9cc0: 20 20 7d 0a 20 20 64 62 5f 63 72 65 61 74 65 5f }. db_create_
9cd0: 64 65 66 61 75 6c 74 5f 75 73 65 72 73 28 30 2c default_users(0,
9ce0: 20 7a 44 65 66 61 75 6c 74 55 73 65 72 29 3b 0a zDefaultUser);.
9cf0: 20 20 69 66 28 20 7a 44 65 66 61 75 6c 74 55 73 if( zDefaultUs
9d00: 65 72 20 29 20 67 2e 7a 4c 6f 67 69 6e 20 3d 20 er ) g.zLogin =
9d10: 7a 44 65 66 61 75 6c 74 55 73 65 72 3b 0a 20 20 zDefaultUser;.
9d20: 75 73 65 72 5f 73 65 6c 65 63 74 28 29 3b 0a 0a user_select();..
9d30: 20 20 69 66 28 20 7a 54 65 6d 70 6c 61 74 65 20 if( zTemplate
9d40: 29 7b 0a 20 20 20 20 2f 2a 0a 20 20 20 20 2a 2a ){. /*. **
9d50: 20 43 6f 70 79 20 61 6c 6c 20 73 65 74 74 69 6e Copy all settin
9d60: 67 73 20 66 72 6f 6d 20 74 68 65 20 73 75 70 70 gs from the supp
9d70: 6c 69 65 64 20 74 65 6d 70 6c 61 74 65 20 72 65 lied template re
9d80: 70 6f 73 69 74 6f 72 79 2e 0a 20 20 20 20 2a 2f pository.. */
9d90: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 . db_multi_ex
9da0: 65 63 28 0a 20 20 20 20 20 20 22 49 4e 53 45 52 ec(. "INSER
9db0: 54 20 4f 52 20 52 45 50 4c 41 43 45 20 49 4e 54 T OR REPLACE INT
9dc0: 4f 20 63 6f 6e 66 69 67 22 0a 20 20 20 20 20 20 O config".
9dd0: 22 20 53 45 4c 45 43 54 20 6e 61 6d 65 2c 76 61 " SELECT name,va
9de0: 6c 75 65 2c 6d 74 69 6d 65 20 46 52 4f 4d 20 73 lue,mtime FROM s
9df0: 65 74 74 69 6e 67 53 72 63 2e 63 6f 6e 66 69 67 ettingSrc.config
9e00: 22 0a 20 20 20 20 20 20 22 20 20 57 48 45 52 45 ". " WHERE
9e10: 20 28 6e 61 6d 65 20 49 4e 20 25 73 20 4f 52 20 (name IN %s OR
9e20: 6e 61 6d 65 20 49 4e 20 25 73 29 22 0a 20 20 20 name IN %s)".
9e30: 20 20 20 22 20 20 20 20 41 4e 44 20 6e 61 6d 65 " AND name
9e40: 20 4e 4f 54 20 47 4c 4f 42 20 27 70 72 6f 6a 65 NOT GLOB 'proje
9e50: 63 74 2d 2a 27 22 0a 20 20 20 20 20 20 22 20 20 ct-*'". "
9e60: 20 20 41 4e 44 20 6e 61 6d 65 20 4e 4f 54 20 47 AND name NOT G
9e70: 4c 4f 42 20 27 73 68 6f 72 74 2d 70 72 6f 6a 65 LOB 'short-proje
9e80: 63 74 2d 2a 27 3b 22 2c 0a 20 20 20 20 20 20 63 ct-*';",. c
9e90: 6f 6e 66 69 67 75 72 65 5f 69 6e 6f 70 5f 72 68 onfigure_inop_rh
9ea0: 73 28 43 4f 4e 46 49 47 53 45 54 5f 41 4c 4c 29 s(CONFIGSET_ALL)
9eb0: 2c 0a 20 20 20 20 20 20 64 62 5f 73 65 74 74 69 ,. db_setti
9ec0: 6e 67 5f 69 6e 6f 70 5f 72 68 73 28 29 0a 20 20 ng_inop_rhs().
9ed0: 20 20 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 );. db_mult
9ee0: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 52 i_exec(. "R
9ef0: 45 50 4c 41 43 45 20 49 4e 54 4f 20 72 65 70 6f EPLACE INTO repo
9f00: 72 74 66 6d 74 20 53 45 4c 45 43 54 20 2a 20 46 rtfmt SELECT * F
9f10: 52 4f 4d 20 73 65 74 74 69 6e 67 53 72 63 2e 72 ROM settingSrc.r
9f20: 65 70 6f 72 74 66 6d 74 3b 22 0a 20 20 20 20 29 eportfmt;". )
9f30: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 2a 2a ;.. /*. **
9f40: 20 43 6f 70 79 20 74 68 65 20 75 73 65 72 20 70 Copy the user p
9f50: 65 72 6d 69 73 73 69 6f 6e 73 2c 20 63 6f 6e 74 ermissions, cont
9f60: 61 63 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c act information,
9f70: 20 6c 61 73 74 20 6d 6f 64 69 66 69 65 64 0a 20 last modified.
9f80: 20 20 20 2a 2a 20 74 69 6d 65 2c 20 61 6e 64 20 ** time, and
9f90: 70 68 6f 74 6f 20 66 6f 72 20 61 6c 6c 20 74 68 photo for all th
9fa0: 65 20 22 73 79 73 74 65 6d 22 20 75 73 65 72 73 e "system" users
9fb0: 20 66 72 6f 6d 20 74 68 65 20 73 75 70 70 6c 69 from the suppli
9fc0: 65 64 0a 20 20 20 20 2a 2a 20 74 65 6d 70 6c 61 ed. ** templa
9fd0: 74 65 20 72 65 70 6f 73 69 74 6f 72 79 20 69 6e te repository in
9fe0: 74 6f 20 74 68 65 20 6f 6e 65 20 62 65 69 6e 67 to the one being
9ff0: 20 73 65 74 75 70 2e 20 20 54 68 65 20 6f 74 68 setup. The oth
a000: 65 72 20 63 6f 6c 75 6d 6e 73 0a 20 20 20 20 2a er columns. *
a010: 2a 20 61 72 65 20 6e 6f 74 20 63 6f 70 69 65 64 * are not copied
a020: 20 62 65 63 61 75 73 65 20 74 68 65 79 20 63 6f because they co
a030: 6e 74 61 69 6e 20 73 65 63 75 72 69 74 79 20 69 ntain security i
a040: 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 72 20 6f 74 nformation or ot
a050: 68 65 72 0a 20 20 20 20 2a 2a 20 64 61 74 61 20 her. ** data
a060: 73 70 65 63 69 66 69 63 20 74 6f 20 74 68 65 20 specific to the
a070: 6f 74 68 65 72 20 72 65 70 6f 73 69 74 6f 72 79 other repository
a080: 2e 20 20 54 68 65 20 6c 69 73 74 20 6f 66 20 63 . The list of c
a090: 6f 6c 75 6d 6e 73 20 63 6f 70 69 65 64 0a 20 20 olumns copied.
a0a0: 20 20 2a 2a 20 62 79 20 74 68 69 73 20 53 51 4c ** by this SQL
a0b0: 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 6e statement may n
a0c0: 65 65 64 20 74 6f 20 62 65 20 72 65 76 69 73 65 eed to be revise
a0d0: 64 20 69 6e 20 74 68 65 20 66 75 74 75 72 65 2e d in the future.
a0e0: 0a 20 20 20 20 2a 2f 0a 20 20 20 20 64 62 5f 6d . */. db_m
a0f0: 75 6c 74 69 5f 65 78 65 63 28 22 55 50 44 41 54 ulti_exec("UPDAT
a100: 45 20 75 73 65 72 20 53 45 54 22 0a 20 20 20 20 E user SET".
a110: 20 20 22 20 20 63 61 70 20 3d 20 28 53 45 4c 45 " cap = (SELE
a120: 43 54 20 75 32 2e 63 61 70 20 46 52 4f 4d 20 73 CT u2.cap FROM s
a130: 65 74 74 69 6e 67 53 72 63 2e 75 73 65 72 20 75 ettingSrc.user u
a140: 32 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 20 2". "
a150: 20 20 20 57 48 45 52 45 20 75 32 2e 6c 6f 67 69 WHERE u2.logi
a160: 6e 20 3d 20 75 73 65 72 2e 6c 6f 67 69 6e 29 2c n = user.login),
a170: 22 0a 20 20 20 20 20 20 22 20 20 69 6e 66 6f 20 ". " info
a180: 3d 20 28 53 45 4c 45 43 54 20 75 32 2e 69 6e 66 = (SELECT u2.inf
a190: 6f 20 46 52 4f 4d 20 73 65 74 74 69 6e 67 53 72 o FROM settingSr
a1a0: 63 2e 75 73 65 72 20 75 32 22 0a 20 20 20 20 20 c.user u2".
a1b0: 20 22 20 20 20 20 20 20 20 20 20 20 57 48 45 52 " WHER
a1c0: 45 20 75 32 2e 6c 6f 67 69 6e 20 3d 20 75 73 65 E u2.login = use
a1d0: 72 2e 6c 6f 67 69 6e 29 2c 22 0a 20 20 20 20 20 r.login),".
a1e0: 20 22 20 20 6d 74 69 6d 65 20 3d 20 28 53 45 4c " mtime = (SEL
a1f0: 45 43 54 20 75 32 2e 6d 74 69 6d 65 20 46 52 4f ECT u2.mtime FRO
a200: 4d 20 73 65 74 74 69 6e 67 53 72 63 2e 75 73 65 M settingSrc.use
a210: 72 20 75 32 22 0a 20 20 20 20 20 20 22 20 20 20 r u2". "
a220: 20 20 20 20 20 20 20 20 57 48 45 52 45 20 75 32 WHERE u2
a230: 2e 6c 6f 67 69 6e 20 3d 20 75 73 65 72 2e 6c 6f .login = user.lo
a240: 67 69 6e 29 2c 22 0a 20 20 20 20 20 20 22 20 20 gin),". "
a250: 70 68 6f 74 6f 20 3d 20 28 53 45 4c 45 43 54 20 photo = (SELECT
a260: 75 32 2e 70 68 6f 74 6f 20 46 52 4f 4d 20 73 65 u2.photo FROM se
a270: 74 74 69 6e 67 53 72 63 2e 75 73 65 72 20 75 32 ttingSrc.user u2
a280: 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 20 20 ". "
a290: 20 20 20 20 57 48 45 52 45 20 75 32 2e 6c 6f 67 WHERE u2.log
a2a0: 69 6e 20 3d 20 75 73 65 72 2e 6c 6f 67 69 6e 29 in = user.login)
a2b0: 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 20 ". " WHERE
a2c0: 75 73 65 72 2e 6c 6f 67 69 6e 20 49 4e 20 28 27 user.login IN ('
a2d0: 61 6e 6f 6e 79 6d 6f 75 73 27 2c 27 6e 6f 62 6f anonymous','nobo
a2e0: 64 79 27 2c 27 64 65 76 65 6c 6f 70 65 72 27 2c dy','developer',
a2f0: 27 72 65 61 64 65 72 27 29 3b 22 0a 20 20 20 20 'reader');".
a300: 29 3b 0a 20 20 7d 0a 0a 20 20 69 66 28 20 7a 49 );. }.. if( zI
a310: 6e 69 74 69 61 6c 44 61 74 65 20 29 7b 0a 20 20 nitialDate ){.
a320: 20 20 69 6e 74 20 72 69 64 3b 0a 20 20 20 20 62 int rid;. b
a330: 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66 65 lob_zero(&manife
a340: 73 74 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 st);. blob_ap
a350: 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c pendf(&manifest,
a360: 20 22 43 20 69 6e 69 74 69 61 6c 5c 5c 73 65 6d "C initial\\sem
a370: 70 74 79 5c 5c 73 63 68 65 63 6b 2d 69 6e 5c 6e pty\\scheck-in\n
a380: 22 29 3b 0a 20 20 20 20 7a 44 61 74 65 20 3d 20 ");. zDate =
a390: 64 61 74 65 5f 69 6e 5f 73 74 61 6e 64 61 72 64 date_in_standard
a3a0: 5f 66 6f 72 6d 61 74 28 7a 49 6e 69 74 69 61 6c _format(zInitial
a3b0: 44 61 74 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f Date);. blob_
a3c0: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
a3d0: 74 2c 20 22 44 20 25 73 5c 6e 22 2c 20 7a 44 61 t, "D %s\n", zDa
a3e0: 74 65 29 3b 0a 20 20 20 20 6d 64 35 73 75 6d 5f te);. md5sum_
a3f0: 69 6e 69 74 28 29 3b 0a 20 20 20 20 2f 2a 20 54 init();. /* T
a400: 68 65 20 52 2d 63 61 72 64 20 69 73 20 6e 65 63 he R-card is nec
a410: 65 73 73 61 72 79 20 68 65 72 65 20 62 65 63 61 essary here beca
a420: 75 73 65 20 77 69 74 68 6f 75 74 20 69 74 0a 20 use without it.
a430: 20 20 20 20 2a 20 66 6f 73 73 69 6c 20 76 65 72 * fossil ver
a440: 73 69 6f 6e 73 20 65 61 72 6c 69 65 72 20 74 68 sions earlier th
a450: 61 6e 20 76 65 72 73 69 6f 6e 73 20 31 2e 32 37 an versions 1.27
a460: 20 77 6f 75 6c 64 0a 20 20 20 20 20 2a 20 69 6e would. * in
a470: 74 65 72 70 72 65 74 20 74 68 69 73 20 61 72 74 terpret this art
a480: 69 66 61 63 74 20 61 73 20 61 20 22 63 6f 6e 74 ifact as a "cont
a490: 72 6f 6c 22 2e 20 2a 2f 0a 20 20 20 20 62 6c 6f rol". */. blo
a4a0: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 b_appendf(&manif
a4b0: 65 73 74 2c 20 22 52 20 25 73 5c 6e 22 2c 20 6d est, "R %s\n", m
a4c0: 64 35 73 75 6d 5f 66 69 6e 69 73 68 28 30 29 29 d5sum_finish(0))
a4d0: 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e ;. blob_appen
a4e0: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54 df(&manifest, "T
a4f0: 20 2a 62 72 61 6e 63 68 20 2a 20 74 72 75 6e 6b *branch * trunk
a500: 5c 6e 22 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 \n");. blob_a
a510: 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 ppendf(&manifest
a520: 2c 20 22 54 20 2a 73 79 6d 2d 74 72 75 6e 6b 20 , "T *sym-trunk
a530: 2a 5c 6e 22 29 3b 0a 20 20 20 20 62 6c 6f 62 5f *\n");. blob_
a540: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
a550: 74 2c 20 22 55 20 25 46 5c 6e 22 2c 20 67 2e 7a t, "U %F\n", g.z
a560: 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 6d 64 35 73 Login);. md5s
a570: 75 6d 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 um_blob(&manifes
a580: 74 2c 20 26 68 61 73 68 29 3b 0a 20 20 20 20 62 t, &hash);. b
a590: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e lob_appendf(&man
a5a0: 69 66 65 73 74 2c 20 22 5a 20 25 62 5c 6e 22 2c ifest, "Z %b\n",
a5b0: 20 26 68 61 73 68 29 3b 0a 20 20 20 20 62 6c 6f &hash);. blo
a5c0: 62 5f 72 65 73 65 74 28 26 68 61 73 68 29 3b 0a b_reset(&hash);.
a5d0: 20 20 20 20 72 69 64 20 3d 20 63 6f 6e 74 65 6e rid = conten
a5e0: 74 5f 70 75 74 28 26 6d 61 6e 69 66 65 73 74 29 t_put(&manifest)
a5f0: 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 63 ;. manifest_c
a600: 72 6f 73 73 6c 69 6e 6b 28 72 69 64 2c 20 26 6d rosslink(rid, &m
a610: 61 6e 69 66 65 73 74 2c 20 4d 43 5f 4e 4f 4e 45 anifest, MC_NONE
a620: 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 );. }.}../*.**
a630: 43 4f 4d 4d 41 4e 44 3a 20 6e 65 77 2a 0a 2a 2a COMMAND: new*.**
a640: 20 43 4f 4d 4d 41 4e 44 3a 20 69 6e 69 74 0a 2a COMMAND: init.*
a650: 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 *.** Usage: %fos
a660: 73 69 6c 20 6e 65 77 20 3f 4f 50 54 49 4f 4e 53 sil new ?OPTIONS
a670: 3f 20 46 49 4c 45 4e 41 4d 45 0a 2a 2a 20 20 20 ? FILENAME.**
a680: 20 4f 72 3a 20 25 66 6f 73 73 69 6c 20 69 6e 69 Or: %fossil ini
a690: 74 20 3f 4f 50 54 49 4f 4e 53 3f 20 46 49 4c 45 t ?OPTIONS? FILE
a6a0: 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 43 72 65 61 74 NAME.**.** Creat
a6b0: 65 20 61 20 72 65 70 6f 73 69 74 6f 72 79 20 66 e a repository f
a6c0: 6f 72 20 61 20 6e 65 77 20 70 72 6f 6a 65 63 74 or a new project
a6d0: 20 69 6e 20 74 68 65 20 66 69 6c 65 20 6e 61 6d in the file nam
a6e0: 65 64 20 46 49 4c 45 4e 41 4d 45 2e 0a 2a 2a 20 ed FILENAME..**
a6f0: 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 69 73 20 This command is
a700: 64 69 73 74 69 6e 63 74 20 66 72 6f 6d 20 22 63 distinct from "c
a710: 6c 6f 6e 65 22 2e 20 20 54 68 65 20 22 63 6c 6f lone". The "clo
a720: 6e 65 22 20 63 6f 6d 6d 61 6e 64 20 6d 61 6b 65 ne" command make
a730: 73 0a 2a 2a 20 61 20 63 6f 70 79 20 6f 66 20 61 s.** a copy of a
a740: 6e 20 65 78 69 73 74 69 6e 67 20 70 72 6f 6a 65 n existing proje
a750: 63 74 2e 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e ct. This comman
a760: 64 20 73 74 61 72 74 73 20 61 20 6e 65 77 20 70 d starts a new p
a770: 72 6f 6a 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 42 79 roject..**.** By
a780: 20 64 65 66 61 75 6c 74 2c 20 79 6f 75 72 20 63 default, your c
a790: 75 72 72 65 6e 74 20 6c 6f 67 69 6e 20 6e 61 6d urrent login nam
a7a0: 65 20 69 73 20 75 73 65 64 20 74 6f 20 63 72 65 e is used to cre
a7b0: 61 74 65 20 74 68 65 20 64 65 66 61 75 6c 74 0a ate the default.
a7c0: 2a 2a 20 61 64 6d 69 6e 20 75 73 65 72 2e 20 54 ** admin user. T
a7d0: 68 69 73 20 63 61 6e 20 62 65 20 6f 76 65 72 72 his can be overr
a7e0: 69 64 64 65 6e 20 75 73 69 6e 67 20 74 68 65 20 idden using the
a7f0: 2d 41 7c 2d 2d 61 64 6d 69 6e 2d 75 73 65 72 0a -A|--admin-user.
a800: 2a 2a 20 70 61 72 61 6d 65 74 65 72 2e 0a 2a 2a ** parameter..**
a810: 0a 2a 2a 20 42 79 20 64 65 66 61 75 6c 74 2c 20 .** By default,
a820: 61 6c 6c 20 73 65 74 74 69 6e 67 73 20 77 69 6c all settings wil
a830: 6c 20 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 l be initialized
a840: 20 74 6f 20 74 68 65 69 72 20 64 65 66 61 75 6c to their defaul
a850: 74 20 76 61 6c 75 65 73 2e 0a 2a 2a 20 54 68 69 t values..** Thi
a860: 73 20 63 61 6e 20 62 65 20 6f 76 65 72 72 69 64 s can be overrid
a870: 64 65 6e 20 75 73 69 6e 67 20 74 68 65 20 2d 2d den using the --
a880: 74 65 6d 70 6c 61 74 65 20 70 61 72 61 6d 65 74 template paramet
a890: 65 72 20 74 6f 20 73 70 65 63 69 66 79 20 61 0a er to specify a.
a8a0: 2a 2a 20 72 65 70 6f 73 69 74 6f 72 79 20 66 69 ** repository fi
a8b0: 6c 65 20 66 72 6f 6d 20 77 68 69 63 68 20 74 6f le from which to
a8c0: 20 63 6f 70 79 20 74 68 65 20 69 6e 69 74 69 61 copy the initia
a8d0: 6c 20 73 65 74 74 69 6e 67 73 2e 20 20 57 68 65 l settings. Whe
a8e0: 6e 20 61 20 74 65 6d 70 6c 61 74 65 0a 2a 2a 20 n a template.**
a8f0: 72 65 70 6f 73 69 74 6f 72 79 20 69 73 20 75 73 repository is us
a900: 65 64 2c 20 61 6c 6d 6f 73 74 20 61 6c 6c 20 6f ed, almost all o
a910: 66 20 74 68 65 20 73 65 74 74 69 6e 67 73 20 61 f the settings a
a920: 63 63 65 73 73 69 62 6c 65 20 66 72 6f 6d 20 74 ccessible from t
a930: 68 65 20 73 65 74 75 70 0a 2a 2a 20 70 61 67 65 he setup.** page
a940: 2c 20 65 69 74 68 65 72 20 64 69 72 65 63 74 6c , either directl
a950: 79 20 6f 72 20 69 6e 64 69 72 65 63 74 6c 79 2c y or indirectly,
a960: 20 77 69 6c 6c 20 62 65 20 63 6f 70 69 65 64 2e will be copied.
a970: 20 20 4e 6f 72 6d 61 6c 20 75 73 65 72 73 20 61 Normal users a
a980: 6e 64 0a 2a 2a 20 74 68 65 69 72 20 61 73 73 6f nd.** their asso
a990: 63 69 61 74 65 64 20 70 65 72 6d 69 73 73 69 6f ciated permissio
a9a0: 6e 73 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 63 ns will not be c
a9b0: 6f 70 69 65 64 3b 20 68 6f 77 65 76 65 72 2c 20 opied; however,
a9c0: 74 68 65 20 73 79 73 74 65 6d 0a 2a 2a 20 64 65 the system.** de
a9d0: 66 61 75 6c 74 20 75 73 65 72 73 20 22 61 6e 6f fault users "ano
a9e0: 6e 79 6d 6f 75 73 22 2c 20 22 6e 6f 62 6f 64 79 nymous", "nobody
a9f0: 22 2c 20 22 72 65 61 64 65 72 22 2c 20 22 64 65 ", "reader", "de
aa00: 76 65 6c 6f 70 65 72 22 2c 20 61 6e 64 20 74 68 veloper", and th
aa10: 65 69 72 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65 eir.** associate
aa20: 64 20 70 65 72 6d 69 73 73 69 6f 6e 73 20 77 69 d permissions wi
aa30: 6c 6c 20 62 65 20 63 6f 70 69 65 64 2e 0a 2a 2a ll be copied..**
aa40: 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a 2a 20 .** Options:.**
aa50: 20 20 20 2d 2d 74 65 6d 70 6c 61 74 65 20 20 20 --template
aa60: 20 20 20 46 49 4c 45 20 20 20 20 20 20 63 6f 70 FILE cop
aa70: 79 20 73 65 74 74 69 6e 67 73 20 66 72 6f 6d 20 y settings from
aa80: 72 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65 0a repository file.
aa90: 2a 2a 20 20 20 20 2d 2d 61 64 6d 69 6e 2d 75 73 ** --admin-us
aaa0: 65 72 7c 2d 41 20 55 53 45 52 4e 41 4d 45 20 20 er|-A USERNAME
aab0: 73 65 6c 65 63 74 20 67 69 76 65 6e 20 55 53 45 select given USE
aac0: 52 4e 41 4d 45 20 61 73 20 61 64 6d 69 6e 20 75 RNAME as admin u
aad0: 73 65 72 0a 2a 2a 20 20 20 20 2d 2d 64 61 74 65 ser.** --date
aae0: 2d 6f 76 65 72 72 69 64 65 20 44 41 54 45 54 49 -override DATETI
aaf0: 4d 45 20 20 75 73 65 20 44 41 54 45 54 49 4d 45 ME use DATETIME
ab00: 20 61 73 20 74 69 6d 65 20 6f 66 20 74 68 65 20 as time of the
ab10: 69 6e 69 74 69 61 6c 20 63 68 65 63 6b 69 6e 0a initial checkin.
ab20: 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 **.** See also:
ab30: 63 6c 6f 6e 65 0a 2a 2f 0a 76 6f 69 64 20 63 72 clone.*/.void cr
ab40: 65 61 74 65 5f 72 65 70 6f 73 69 74 6f 72 79 5f eate_repository_
ab50: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 68 61 cmd(void){. cha
ab60: 72 20 2a 7a 50 61 73 73 77 6f 72 64 3b 0a 20 20 r *zPassword;.
ab70: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 65 6d const char *zTem
ab80: 70 6c 61 74 65 3b 20 20 20 20 20 20 2f 2a 20 52 plate; /* R
ab90: 65 70 6f 73 69 74 6f 72 79 20 66 72 6f 6d 20 77 epository from w
aba0: 68 69 63 68 20 74 6f 20 63 6f 70 79 20 73 65 74 hich to copy set
abb0: 74 69 6e 67 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 tings */. const
abc0: 20 63 68 61 72 20 2a 7a 44 61 74 65 3b 20 20 20 char *zDate;
abd0: 20 20 20 20 20 20 20 2f 2a 20 44 61 74 65 20 6f /* Date o
abe0: 66 20 74 68 65 20 69 6e 69 74 69 61 6c 20 63 68 f the initial ch
abf0: 65 63 6b 2d 69 6e 20 2a 2f 0a 20 20 63 6f 6e 73 eck-in */. cons
ac00: 74 20 63 68 61 72 20 2a 7a 44 65 66 61 75 6c 74 t char *zDefault
ac10: 55 73 65 72 3b 20 20 20 2f 2a 20 4f 70 74 69 6f User; /* Optio
ac20: 6e 61 6c 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 nal name of the
ac30: 64 65 66 61 75 6c 74 20 75 73 65 72 20 2a 2f 0a default user */.
ac40: 0a 20 20 7a 54 65 6d 70 6c 61 74 65 20 3d 20 66 . zTemplate = f
ac50: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 74 65 6d 70 ind_option("temp
ac60: 6c 61 74 65 22 2c 30 2c 31 29 3b 0a 20 20 7a 44 late",0,1);. zD
ac70: 61 74 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f ate = find_optio
ac80: 6e 28 22 64 61 74 65 2d 6f 76 65 72 72 69 64 65 n("date-override
ac90: 22 2c 30 2c 31 29 3b 0a 20 20 7a 44 65 66 61 75 ",0,1);. zDefau
aca0: 6c 74 55 73 65 72 20 3d 20 66 69 6e 64 5f 6f 70 ltUser = find_op
acb0: 74 69 6f 6e 28 22 61 64 6d 69 6e 2d 75 73 65 72 tion("admin-user
acc0: 22 2c 22 41 22 2c 31 29 3b 0a 20 20 69 66 28 20 ","A",1);. if(
acd0: 7a 44 61 74 65 3d 3d 30 20 29 20 7a 44 61 74 65 zDate==0 ) zDate
ace0: 20 3d 20 22 6e 6f 77 22 3b 0a 20 20 69 66 28 20 = "now";. if(
acf0: 67 2e 61 72 67 63 21 3d 33 20 29 7b 0a 20 20 20 g.argc!=3 ){.
ad00: 20 75 73 61 67 65 28 22 52 45 50 4f 53 49 54 4f usage("REPOSITO
ad10: 52 59 2d 4e 41 4d 45 22 29 3b 0a 20 20 7d 0a 20 RY-NAME");. }.
ad20: 20 64 62 5f 63 72 65 61 74 65 5f 72 65 70 6f 73 db_create_repos
ad30: 69 74 6f 72 79 28 67 2e 61 72 67 76 5b 32 5d 29 itory(g.argv[2])
ad40: 3b 0a 20 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f ;. db_open_repo
ad50: 73 69 74 6f 72 79 28 67 2e 61 72 67 76 5b 32 5d sitory(g.argv[2]
ad60: 29 3b 0a 20 20 64 62 5f 6f 70 65 6e 5f 63 6f 6e );. db_open_con
ad70: 66 69 67 28 30 29 3b 0a 20 20 69 66 28 20 7a 54 fig(0);. if( zT
ad80: 65 6d 70 6c 61 74 65 20 29 20 64 62 5f 61 74 74 emplate ) db_att
ad90: 61 63 68 28 7a 54 65 6d 70 6c 61 74 65 2c 20 22 ach(zTemplate, "
ada0: 73 65 74 74 69 6e 67 53 72 63 22 29 3b 0a 20 20 settingSrc");.
adb0: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 db_begin_transac
adc0: 74 69 6f 6e 28 29 3b 0a 20 20 64 62 5f 69 6e 69 tion();. db_ini
add0: 74 69 61 6c 5f 73 65 74 75 70 28 7a 54 65 6d 70 tial_setup(zTemp
ade0: 6c 61 74 65 2c 20 7a 44 61 74 65 2c 20 7a 44 65 late, zDate, zDe
adf0: 66 61 75 6c 74 55 73 65 72 2c 20 31 29 3b 0a 20 faultUser, 1);.
ae00: 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 db_end_transact
ae10: 69 6f 6e 28 30 29 3b 0a 20 20 69 66 28 20 7a 54 ion(0);. if( zT
ae20: 65 6d 70 6c 61 74 65 20 29 20 64 62 5f 64 65 74 emplate ) db_det
ae30: 61 63 68 28 22 73 65 74 74 69 6e 67 53 72 63 22 ach("settingSrc"
ae40: 29 3b 0a 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e );. fossil_prin
ae50: 74 28 22 70 72 6f 6a 65 63 74 2d 69 64 3a 20 25 t("project-id: %
ae60: 73 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 70 72 s\n", db_get("pr
ae70: 6f 6a 65 63 74 2d 63 6f 64 65 22 2c 20 30 29 29 oject-code", 0))
ae80: 3b 0a 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 ;. fossil_print
ae90: 28 22 73 65 72 76 65 72 2d 69 64 3a 20 20 25 73 ("server-id: %s
aea0: 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 73 65 72 \n", db_get("ser
aeb0: 76 65 72 2d 63 6f 64 65 22 2c 20 30 29 29 3b 0a ver-code", 0));.
aec0: 20 20 7a 50 61 73 73 77 6f 72 64 20 3d 20 64 62 zPassword = db
aed0: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 _text(0, "SELECT
aee0: 20 70 77 20 46 52 4f 4d 20 75 73 65 72 20 57 48 pw FROM user WH
aef0: 45 52 45 20 6c 6f 67 69 6e 3d 25 51 22 2c 20 67 ERE login=%Q", g
af00: 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 66 6f 73 73 .zLogin);. foss
af10: 69 6c 5f 70 72 69 6e 74 28 22 61 64 6d 69 6e 2d il_print("admin-
af20: 75 73 65 72 3a 20 25 73 20 28 69 6e 69 74 69 61 user: %s (initia
af30: 6c 20 70 61 73 73 77 6f 72 64 20 69 73 20 5c 22 l password is \"
af40: 25 73 5c 22 29 5c 6e 22 2c 0a 20 20 20 20 20 20 %s\")\n",.
af50: 20 20 20 20 20 20 20 20 20 67 2e 7a 4c 6f 67 69 g.zLogi
af60: 6e 2c 20 7a 50 61 73 73 77 6f 72 64 29 3b 0a 7d n, zPassword);.}
af70: 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 20 66 75 6e 63 ../*.** SQL func
af80: 74 69 6f 6e 73 20 66 6f 72 20 64 65 62 75 67 67 tions for debugg
af90: 69 6e 67 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 70 ing..**.** The p
afa0: 72 69 6e 74 28 29 20 66 75 6e 63 74 69 6f 6e 20 rint() function
afb0: 77 72 69 74 65 73 20 69 74 73 20 61 72 67 75 6d writes its argum
afc0: 65 6e 74 73 20 6f 6e 20 73 74 64 6f 75 74 2c 20 ents on stdout,
afd0: 62 75 74 20 6f 6e 6c 79 0a 2a 2a 20 69 66 20 74 but only.** if t
afe0: 68 65 20 2d 73 71 6c 70 72 69 6e 74 20 63 6f 6d he -sqlprint com
aff0: 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e mand-line option
b000: 20 69 73 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a is turned on..*
b010: 2f 0a 4c 4f 43 41 4c 20 76 6f 69 64 20 64 62 5f /.LOCAL void db_
b020: 73 71 6c 5f 70 72 69 6e 74 28 0a 20 20 73 71 6c sql_print(. sql
b030: 69 74 65 33 5f 63 6f 6e 74 65 78 74 20 2a 63 6f ite3_context *co
b040: 6e 74 65 78 74 2c 0a 20 20 69 6e 74 20 61 72 67 ntext,. int arg
b050: 63 2c 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 6c c,. sqlite3_val
b060: 75 65 20 2a 2a 61 72 67 76 0a 29 7b 0a 20 20 69 ue **argv.){. i
b070: 6e 74 20 69 3b 0a 20 20 69 66 28 20 67 2e 66 53 nt i;. if( g.fS
b080: 71 6c 50 72 69 6e 74 20 29 7b 0a 20 20 20 20 66 qlPrint ){. f
b090: 6f 72 28 69 3d 30 3b 20 69 3c 61 72 67 63 3b 20 or(i=0; i<argc;
b0a0: 69 2b 2b 29 7b 0a 20 20 20 20 20 20 63 68 61 72 i++){. char
b0b0: 20 63 20 3d 20 69 3d 3d 61 72 67 63 2d 31 20 3f c = i==argc-1 ?
b0c0: 20 27 5c 6e 27 20 3a 20 27 20 27 3b 0a 20 20 20 '\n' : ' ';.
b0d0: 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 fossil_print(
b0e0: 22 25 73 25 63 22 2c 20 73 71 6c 69 74 65 33 5f "%s%c", sqlite3_
b0f0: 76 61 6c 75 65 5f 74 65 78 74 28 61 72 67 76 5b value_text(argv[
b100: 69 5d 29 2c 20 63 29 3b 0a 20 20 20 20 7d 0a 20 i]), c);. }.
b110: 20 7d 0a 7d 0a 4c 4f 43 41 4c 20 76 6f 69 64 20 }.}.LOCAL void
b120: 64 62 5f 73 71 6c 5f 74 72 61 63 65 28 76 6f 69 db_sql_trace(voi
b130: 64 20 2a 6e 6f 74 55 73 65 64 2c 20 63 6f 6e 73 d *notUsed, cons
b140: 74 20 63 68 61 72 20 2a 7a 53 71 6c 29 7b 0a 20 t char *zSql){.
b150: 20 69 6e 74 20 6e 20 3d 20 73 74 72 6c 65 6e 28 int n = strlen(
b160: 7a 53 71 6c 29 3b 0a 20 20 66 6f 73 73 69 6c 5f zSql);. fossil_
b170: 74 72 61 63 65 28 22 25 73 25 73 5c 6e 22 2c 20 trace("%s%s\n",
b180: 7a 53 71 6c 2c 20 28 6e 3e 30 20 26 26 20 7a 53 zSql, (n>0 && zS
b190: 71 6c 5b 6e 2d 31 5d 3d 3d 27 3b 27 29 20 3f 20 ql[n-1]==';') ?
b1a0: 22 22 20 3a 20 22 3b 22 29 3b 0a 7d 0a 0a 2f 2a "" : ";");.}../*
b1b0: 0a 2a 2a 20 49 6d 70 6c 65 6d 65 6e 74 20 74 68 .** Implement th
b1c0: 65 20 75 73 65 72 28 29 20 53 51 4c 20 66 75 6e e user() SQL fun
b1d0: 63 74 69 6f 6e 2e 20 20 75 73 65 72 28 29 20 74 ction. user() t
b1e0: 61 6b 65 73 20 6e 6f 20 61 72 67 75 6d 65 6e 74 akes no argument
b1f0: 73 20 61 6e 64 0a 2a 2a 20 72 65 74 75 72 6e 73 s and.** returns
b200: 20 74 68 65 20 75 73 65 72 20 49 44 20 6f 66 20 the user ID of
b210: 74 68 65 20 63 75 72 72 65 6e 74 20 75 73 65 72 the current user
b220: 2e 0a 2a 2f 0a 4c 4f 43 41 4c 20 76 6f 69 64 20 ..*/.LOCAL void
b230: 64 62 5f 73 71 6c 5f 75 73 65 72 28 0a 20 20 73 db_sql_user(. s
b240: 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 20 2a qlite3_context *
b250: 63 6f 6e 74 65 78 74 2c 0a 20 20 69 6e 74 20 61 context,. int a
b260: 72 67 63 2c 0a 20 20 73 71 6c 69 74 65 33 5f 76 rgc,. sqlite3_v
b270: 61 6c 75 65 20 2a 2a 61 72 67 76 0a 29 7b 0a 20 alue **argv.){.
b280: 20 69 66 28 20 67 2e 7a 4c 6f 67 69 6e 21 3d 30 if( g.zLogin!=0
b290: 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f ){. sqlite3_
b2a0: 72 65 73 75 6c 74 5f 74 65 78 74 28 63 6f 6e 74 result_text(cont
b2b0: 65 78 74 2c 20 67 2e 7a 4c 6f 67 69 6e 2c 20 2d ext, g.zLogin, -
b2c0: 31 2c 20 53 51 4c 49 54 45 5f 53 54 41 54 49 43 1, SQLITE_STATIC
b2d0: 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 );. }.}../*.**
b2e0: 49 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20 63 67 Implement the cg
b2f0: 69 28 29 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e i() SQL function
b300: 2e 20 20 63 67 69 28 29 20 74 61 6b 65 73 20 61 . cgi() takes a
b310: 6e 20 61 72 67 75 6d 65 6e 74 20 77 68 69 63 68 n argument which
b320: 20 69 73 0a 2a 2a 20 61 20 6e 61 6d 65 20 6f 66 is.** a name of
b330: 20 43 47 49 20 71 75 65 72 79 20 70 61 72 61 6d CGI query param
b340: 65 74 65 72 2e 20 54 68 65 20 76 61 6c 75 65 20 eter. The value
b350: 6f 66 20 74 68 61 74 20 70 61 72 61 6d 65 74 65 of that paramete
b360: 72 20 69 73 20 72 65 74 75 72 6e 65 64 2c 0a 2a r is returned,.*
b370: 2a 20 69 66 20 61 76 61 69 6c 61 62 6c 65 2e 20 * if available.
b380: 4f 70 74 69 6f 6e 61 6c 20 73 65 63 6f 6e 64 20 Optional second
b390: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65 argument will be
b3a0: 20 72 65 74 75 72 6e 65 64 20 69 66 20 74 68 65 returned if the
b3b0: 20 66 69 72 73 74 0a 2a 2a 20 64 6f 65 73 6e 27 first.** doesn'
b3c0: 74 20 65 78 69 73 74 20 61 73 20 61 20 43 47 49 t exist as a CGI
b3d0: 20 70 61 72 61 6d 65 74 65 72 2e 0a 2a 2f 0a 4c parameter..*/.L
b3e0: 4f 43 41 4c 20 76 6f 69 64 20 64 62 5f 73 71 6c OCAL void db_sql
b3f0: 5f 63 67 69 28 73 71 6c 69 74 65 33 5f 63 6f 6e _cgi(sqlite3_con
b400: 74 65 78 74 20 2a 63 6f 6e 74 65 78 74 2c 20 69 text *context, i
b410: 6e 74 20 61 72 67 63 2c 20 73 71 6c 69 74 65 33 nt argc, sqlite3
b420: 5f 76 61 6c 75 65 20 2a 2a 61 72 67 76 29 7b 0a _value **argv){.
b430: 20 20 63 6f 6e 73 74 20 63 68 61 72 2a 20 7a 50 const char* zP
b440: 3b 0a 20 20 69 66 28 20 61 72 67 63 21 3d 31 20 ;. if( argc!=1
b450: 26 26 20 61 72 67 63 21 3d 32 20 29 20 72 65 74 && argc!=2 ) ret
b460: 75 72 6e 3b 0a 20 20 7a 50 20 3d 20 50 28 28 63 urn;. zP = P((c
b470: 6f 6e 73 74 20 63 68 61 72 2a 29 73 71 6c 69 74 onst char*)sqlit
b480: 65 33 5f 76 61 6c 75 65 5f 74 65 78 74 28 61 72 e3_value_text(ar
b490: 67 76 5b 30 5d 29 29 3b 0a 20 20 69 66 28 20 7a gv[0]));. if( z
b4a0: 50 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 P ){. sqlite3
b4b0: 5f 72 65 73 75 6c 74 5f 74 65 78 74 28 63 6f 6e _result_text(con
b4c0: 74 65 78 74 2c 20 7a 50 2c 20 2d 31 2c 20 53 51 text, zP, -1, SQ
b4d0: 4c 49 54 45 5f 53 54 41 54 49 43 29 3b 0a 20 20 LITE_STATIC);.
b4e0: 7d 65 6c 73 65 20 69 66 28 20 61 72 67 63 3d 3d }else if( argc==
b4f0: 32 20 29 7b 0a 20 20 20 20 7a 50 20 3d 20 28 63 2 ){. zP = (c
b500: 6f 6e 73 74 20 63 68 61 72 2a 29 73 71 6c 69 74 onst char*)sqlit
b510: 65 33 5f 76 61 6c 75 65 5f 74 65 78 74 28 61 72 e3_value_text(ar
b520: 67 76 5b 31 5d 29 3b 0a 20 20 20 20 69 66 28 20 gv[1]);. if(
b530: 7a 50 20 29 20 73 71 6c 69 74 65 33 5f 72 65 73 zP ) sqlite3_res
b540: 75 6c 74 5f 74 65 78 74 28 63 6f 6e 74 65 78 74 ult_text(context
b550: 2c 20 7a 50 2c 20 2d 31 2c 20 53 51 4c 49 54 45 , zP, -1, SQLITE
b560: 5f 54 52 41 4e 53 49 45 4e 54 29 3b 0a 20 20 7d _TRANSIENT);. }
b570: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 20 66 75 .}../*.** SQL fu
b580: 6e 63 74 69 6f 6e 3a 0a 2a 2a 0a 2a 2a 20 20 20 nction:.**.**
b590: 20 20 20 20 69 73 5f 73 65 6c 65 63 74 65 64 28 is_selected(
b5a0: 69 64 29 0a 2a 2a 20 20 20 20 20 20 20 69 66 5f id).** if_
b5b0: 73 65 6c 65 63 74 65 64 28 69 64 2c 20 58 2c 20 selected(id, X,
b5c0: 59 29 0a 2a 2a 0a 2a 2a 20 4f 6e 20 74 68 65 20 Y).**.** On the
b5d0: 63 6f 6d 6d 69 74 20 63 6f 6d 6d 61 6e 64 2c 20 commit command,
b5e0: 77 68 65 6e 20 66 69 6c 65 6e 61 6d 65 73 20 61 when filenames a
b5f0: 72 65 20 73 70 65 63 69 66 69 65 64 20 28 69 6e re specified (in
b600: 20 6f 72 64 65 72 20 74 6f 20 64 6f 0a 2a 2a 20 order to do.**
b610: 61 20 70 61 72 74 69 61 6c 20 63 6f 6d 6d 69 74 a partial commit
b620: 29 20 74 68 65 20 76 66 69 6c 65 2e 69 64 20 76 ) the vfile.id v
b630: 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 6e 61 alues for the na
b640: 6d 65 64 20 66 69 6c 65 73 20 61 72 65 20 6c 6f med files are lo
b650: 61 64 65 64 0a 2a 2a 20 69 6e 74 6f 20 74 68 65 aded.** into the
b660: 20 67 2e 61 43 6f 6d 6d 69 74 46 69 6c 65 5b 5d g.aCommitFile[]
b670: 20 61 72 72 61 79 2e 20 20 54 68 69 73 20 66 75 array. This fu
b680: 6e 63 74 69 6f 6e 20 6c 6f 6f 6b 73 20 61 74 20 nction looks at
b690: 74 68 61 74 20 61 72 72 61 79 0a 2a 2a 20 74 6f that array.** to
b6a0: 20 73 65 65 20 69 66 20 61 20 66 69 6c 65 20 69 see if a file i
b6b0: 73 20 6e 61 6d 65 64 20 6f 6e 20 74 68 65 20 63 s named on the c
b6c0: 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2e 0a 2a 2a 0a ommand-line..**.
b6d0: 2a 2a 20 49 6e 20 74 68 65 20 66 69 72 73 74 20 ** In the first
b6e0: 66 6f 72 6d 20 28 31 20 61 72 67 75 6d 65 6e 74 form (1 argument
b6f0: 29 20 72 65 74 75 72 6e 20 54 52 55 45 20 69 66 ) return TRUE if
b700: 20 65 69 74 68 65 72 20 6e 6f 20 66 69 6c 65 73 either no files
b710: 20 61 72 65 0a 2a 2a 20 6e 61 6d 65 64 20 6f 6e are.** named on
b720: 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e the command lin
b730: 65 20 28 67 2e 61 43 6f 6d 6d 69 74 46 69 6c 65 e (g.aCommitFile
b740: 20 69 73 20 4e 55 4c 4c 20 6d 65 61 6e 69 6e 67 is NULL meaning
b750: 20 74 68 61 74 20 61 6c 6c 0a 2a 2a 20 63 68 61 that all.** cha
b760: 6e 67 65 73 20 61 72 65 20 74 6f 20 62 65 20 63 nges are to be c
b770: 6f 6d 6d 69 74 74 65 64 29 20 6f 72 20 69 66 20 ommitted) or if
b780: 69 64 20 69 73 20 66 6f 75 6e 64 20 69 6e 20 67 id is found in g
b790: 2e 61 43 6f 6d 6d 69 74 46 69 6c 65 5b 5d 0a 2a .aCommitFile[].*
b7a0: 2a 20 28 6d 65 61 6e 69 6e 67 20 74 68 61 74 20 * (meaning that
b7b0: 69 64 20 77 61 73 20 6e 61 6d 65 64 20 6f 6e 20 id was named on
b7c0: 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 the command-line
b7d0: 29 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 )..**.** In the
b7e0: 73 65 63 6f 6e 64 20 66 6f 72 6d 20 28 33 20 61 second form (3 a
b7f0: 72 67 75 6d 65 6e 74 73 29 20 72 65 74 75 72 6e rguments) return
b800: 20 61 72 67 75 6d 65 6e 74 20 58 20 69 66 20 74 argument X if t
b810: 72 75 65 20 61 6e 64 20 59 0a 2a 2a 20 69 66 20 rue and Y.** if
b820: 66 61 6c 73 65 2e 20 20 45 78 63 65 70 74 20 69 false. Except i
b830: 66 20 59 20 69 73 20 4e 55 4c 4c 20 74 68 65 6e f Y is NULL then
b840: 20 61 6c 77 61 79 73 20 72 65 74 75 72 6e 20 58 always return X
b850: 2e 0a 2a 2f 0a 4c 4f 43 41 4c 20 76 6f 69 64 20 ..*/.LOCAL void
b860: 66 69 6c 65 5f 69 73 5f 73 65 6c 65 63 74 65 64 file_is_selected
b870: 28 0a 20 20 73 71 6c 69 74 65 33 5f 63 6f 6e 74 (. sqlite3_cont
b880: 65 78 74 20 2a 63 6f 6e 74 65 78 74 2c 0a 20 20 ext *context,.
b890: 69 6e 74 20 61 72 67 63 2c 0a 20 20 73 71 6c 69 int argc,. sqli
b8a0: 74 65 33 5f 76 61 6c 75 65 20 2a 2a 61 72 67 76 te3_value **argv
b8b0: 0a 29 7b 0a 20 20 69 6e 74 20 72 63 20 3d 20 30 .){. int rc = 0
b8c0: 3b 0a 0a 20 20 61 73 73 65 72 74 28 61 72 67 63 ;.. assert(argc
b8d0: 3d 3d 31 20 7c 7c 20 61 72 67 63 3d 3d 33 29 3b ==1 || argc==3);
b8e0: 0a 20 20 69 66 28 20 67 2e 61 43 6f 6d 6d 69 74 . if( g.aCommit
b8f0: 46 69 6c 65 20 29 7b 0a 20 20 20 20 69 6e 74 20 File ){. int
b900: 69 49 64 20 3d 20 73 71 6c 69 74 65 33 5f 76 61 iId = sqlite3_va
b910: 6c 75 65 5f 69 6e 74 28 61 72 67 76 5b 30 5d 29 lue_int(argv[0])
b920: 3b 0a 20 20 20 20 69 6e 74 20 69 69 3b 0a 20 20 ;. int ii;.
b930: 20 20 66 6f 72 28 69 69 3d 30 3b 20 67 2e 61 43 for(ii=0; g.aC
b940: 6f 6d 6d 69 74 46 69 6c 65 5b 69 69 5d 3b 20 69 ommitFile[ii]; i
b950: 69 2b 2b 29 7b 0a 20 20 20 20 20 20 69 66 28 20 i++){. if(
b960: 69 49 64 3d 3d 67 2e 61 43 6f 6d 6d 69 74 46 69 iId==g.aCommitFi
b970: 6c 65 5b 69 69 5d 20 29 7b 0a 20 20 20 20 20 20 le[ii] ){.
b980: 20 20 72 63 20 3d 20 31 3b 0a 20 20 20 20 20 20 rc = 1;.
b990: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d break;. }
b9a0: 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a . }. }else{.
b9b0: 20 20 20 20 72 63 20 3d 20 31 3b 0a 20 20 7d 0a rc = 1;. }.
b9c0: 20 20 69 66 28 20 61 72 67 63 3d 3d 31 20 29 7b if( argc==1 ){
b9d0: 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 72 65 73 . sqlite3_res
b9e0: 75 6c 74 5f 69 6e 74 28 63 6f 6e 74 65 78 74 2c ult_int(context,
b9f0: 20 72 63 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 rc);. }else{.
ba00: 20 20 20 61 73 73 65 72 74 28 20 61 72 67 63 3d assert( argc=
ba10: 3d 33 20 29 3b 0a 20 20 20 20 61 73 73 65 72 74 =3 );. assert
ba20: 28 20 72 63 3d 3d 30 20 7c 7c 20 72 63 3d 3d 31 ( rc==0 || rc==1
ba30: 20 29 3b 0a 20 20 20 20 69 66 28 20 73 71 6c 69 );. if( sqli
ba40: 74 65 33 5f 76 61 6c 75 65 5f 74 79 70 65 28 61 te3_value_type(a
ba50: 72 67 76 5b 32 2d 72 63 5d 29 3d 3d 53 51 4c 49 rgv[2-rc])==SQLI
ba60: 54 45 5f 4e 55 4c 4c 20 29 20 72 63 20 3d 20 31 TE_NULL ) rc = 1
ba70: 2d 72 63 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 -rc;. sqlite3
ba80: 5f 72 65 73 75 6c 74 5f 76 61 6c 75 65 28 63 6f _result_value(co
ba90: 6e 74 65 78 74 2c 20 61 72 67 76 5b 32 2d 72 63 ntext, argv[2-rc
baa0: 5d 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a ]);. }.}../*.**
bab0: 20 43 6f 6e 76 65 72 74 20 74 68 65 20 69 6e 70 Convert the inp
bac0: 75 74 20 73 74 72 69 6e 67 20 69 6e 74 6f 20 61 ut string into a
bad0: 6e 20 53 48 41 31 2e 20 20 4d 61 6b 65 20 61 20 n SHA1. Make a
bae0: 6e 6f 74 61 74 69 6f 6e 20 69 6e 20 74 68 65 0a notation in the.
baf0: 2a 2a 20 43 4f 4e 43 45 41 4c 45 44 20 74 61 62 ** CONCEALED tab
bb00: 6c 65 20 73 6f 20 74 68 61 74 20 74 68 65 20 68 le so that the h
bb10: 61 73 68 20 63 61 6e 20 62 65 20 75 6e 64 6f 20 ash can be undo
bb20: 75 73 69 6e 67 20 74 68 65 20 64 62 5f 72 65 76 using the db_rev
bb30: 65 61 6c 28 29 0a 2a 2a 20 66 75 6e 63 74 69 6f eal().** functio
bb40: 6e 20 61 74 20 73 6f 6d 65 20 6c 61 74 65 72 20 n at some later
bb50: 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 time..**.** The
bb60: 76 61 6c 75 65 20 72 65 74 75 72 6e 65 64 20 69 value returned i
bb70: 73 20 73 74 6f 72 65 64 20 69 6e 20 73 74 61 74 s stored in stat
bb80: 69 63 20 73 70 61 63 65 20 61 6e 64 20 77 69 6c ic space and wil
bb90: 6c 20 62 65 20 6f 76 65 72 77 72 69 74 74 65 6e l be overwritten
bba0: 0a 2a 2a 20 6f 6e 20 73 75 62 73 65 71 75 65 6e .** on subsequen
bbb0: 74 20 63 61 6c 6c 73 2e 0a 2a 2a 0a 2a 2a 20 49 t calls..**.** I
bbc0: 66 20 7a 43 6f 6e 74 65 6e 74 20 69 73 20 61 6c f zContent is al
bbd0: 72 65 61 64 79 20 61 20 77 65 6c 6c 2d 66 6f 72 ready a well-for
bbe0: 6d 65 64 20 53 48 41 31 20 68 61 73 68 2c 20 74 med SHA1 hash, t
bbf0: 68 65 6e 20 72 65 74 75 72 6e 20 61 20 63 6f 70 hen return a cop
bc00: 79 0a 2a 2a 20 6f 66 20 74 68 61 74 20 68 61 73 y.** of that has
bc10: 68 2c 20 6e 6f 74 20 61 20 68 61 73 68 20 6f 66 h, not a hash of
bc20: 20 74 68 65 20 68 61 73 68 2e 0a 2a 2a 0a 2a 2a the hash..**.**
bc30: 20 54 68 65 20 43 4f 4e 43 45 41 4c 45 44 20 74 The CONCEALED t
bc40: 61 62 6c 65 20 69 73 20 6d 65 61 6e 74 20 74 6f able is meant to
bc50: 20 6f 62 73 63 75 72 65 20 65 6d 61 69 6c 20 61 obscure email a
bc60: 64 64 72 65 73 73 65 73 2e 20 20 45 76 65 72 79 ddresses. Every
bc70: 20 76 61 6c 69 64 0a 2a 2a 20 65 6d 61 69 6c 20 valid.** email
bc80: 61 64 64 72 65 73 73 20 77 69 6c 6c 20 63 6f 6e address will con
bc90: 74 61 69 6e 20 61 20 22 40 22 20 63 68 61 72 61 tain a "@" chara
bca0: 63 74 65 72 20 61 6e 64 20 22 40 22 20 69 73 20 cter and "@" is
bcb0: 6e 6f 74 20 76 61 6c 69 64 20 77 69 74 68 69 6e not valid within
bcc0: 0a 2a 2a 20 61 6e 20 53 48 41 31 20 68 61 73 68 .** an SHA1 hash
bcd0: 20 73 6f 20 74 68 65 72 65 20 69 73 20 6e 6f 20 so there is no
bce0: 63 68 61 6e 63 65 20 74 68 61 74 20 61 20 76 61 chance that a va
bcf0: 6c 69 64 20 65 6d 61 69 6c 20 61 64 64 72 65 73 lid email addres
bd00: 73 20 77 69 6c 6c 20 67 6f 0a 2a 2a 20 75 6e 63 s will go.** unc
bd10: 6f 6e 63 65 61 6c 65 64 2e 0a 2a 2f 0a 63 68 61 oncealed..*/.cha
bd20: 72 20 2a 64 62 5f 63 6f 6e 63 65 61 6c 28 63 6f r *db_conceal(co
bd30: 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6e 74 65 nst char *zConte
bd40: 6e 74 2c 20 69 6e 74 20 6e 29 7b 0a 20 20 73 74 nt, int n){. st
bd50: 61 74 69 63 20 63 68 61 72 20 7a 48 61 73 68 5b atic char zHash[
bd60: 34 32 5d 3b 0a 20 20 42 6c 6f 62 20 6f 75 74 3b 42];. Blob out;
bd70: 0a 20 20 69 66 28 20 6e 3d 3d 34 30 20 26 26 20 . if( n==40 &&
bd80: 76 61 6c 69 64 61 74 65 31 36 28 7a 43 6f 6e 74 validate16(zCont
bd90: 65 6e 74 2c 20 6e 29 20 29 7b 0a 20 20 20 20 6d ent, n) ){. m
bda0: 65 6d 63 70 79 28 7a 48 61 73 68 2c 20 7a 43 6f emcpy(zHash, zCo
bdb0: 6e 74 65 6e 74 2c 20 6e 29 3b 0a 20 20 20 20 7a ntent, n);. z
bdc0: 48 61 73 68 5b 6e 5d 20 3d 20 30 3b 0a 20 20 7d Hash[n] = 0;. }
bdd0: 65 6c 73 65 7b 0a 20 20 20 20 73 68 61 31 73 75 else{. sha1su
bde0: 6d 5f 73 74 65 70 5f 74 65 78 74 28 7a 43 6f 6e m_step_text(zCon
bdf0: 74 65 6e 74 2c 20 6e 29 3b 0a 20 20 20 20 73 68 tent, n);. sh
be00: 61 31 73 75 6d 5f 66 69 6e 69 73 68 28 26 6f 75 a1sum_finish(&ou
be10: 74 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f t);. sqlite3_
be20: 73 6e 70 72 69 6e 74 66 28 73 69 7a 65 6f 66 28 snprintf(sizeof(
be30: 7a 48 61 73 68 29 2c 20 7a 48 61 73 68 2c 20 22 zHash), zHash, "
be40: 25 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6f %s", blob_str(&o
be50: 75 74 29 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 ut));. blob_r
be60: 65 73 65 74 28 26 6f 75 74 29 3b 0a 20 20 20 20 eset(&out);.
be70: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 db_multi_exec(.
be80: 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52 "INSERT OR
be90: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 63 6f 6e IGNORE INTO con
bea0: 63 65 61 6c 65 64 28 68 61 73 68 2c 63 6f 6e 74 cealed(hash,cont
beb0: 65 6e 74 2c 6d 74 69 6d 65 29 22 0a 20 20 20 20 ent,mtime)".
bec0: 20 20 20 22 20 56 41 4c 55 45 53 28 25 51 2c 25 " VALUES(%Q,%
bed0: 23 51 2c 6e 6f 77 28 29 29 22 2c 0a 20 20 20 20 #Q,now())",.
bee0: 20 20 20 7a 48 61 73 68 2c 20 6e 2c 20 7a 43 6f zHash, n, zCo
bef0: 6e 74 65 6e 74 0a 20 20 20 20 29 3b 0a 20 20 7d ntent. );. }
bf00: 0a 20 20 72 65 74 75 72 6e 20 7a 48 61 73 68 3b . return zHash;
bf10: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 74 74 65 6d 70 .}../*.** Attemp
bf20: 74 20 74 6f 20 6c 6f 6f 6b 20 75 70 20 74 68 65 t to look up the
bf30: 20 69 6e 70 75 74 20 69 6e 20 74 68 65 20 43 4f input in the CO
bf40: 4e 43 45 41 4c 45 44 20 74 61 62 6c 65 2e 20 20 NCEALED table.
bf50: 49 66 20 66 6f 75 6e 64 2c 0a 2a 2a 20 61 6e 64 If found,.** and
bf60: 20 69 66 20 74 68 65 20 6f 6b 52 64 41 64 64 72 if the okRdAddr
bf70: 20 70 65 72 6d 69 73 73 69 6f 6e 20 69 73 20 65 permission is e
bf80: 6e 61 62 6c 65 64 20 74 68 65 6e 20 72 65 74 75 nabled then retu
bf90: 72 6e 20 74 68 65 0a 2a 2a 20 6f 72 69 67 69 6e rn the.** origin
bfa0: 61 6c 20 76 61 6c 75 65 20 66 6f 72 20 77 68 69 al value for whi
bfb0: 63 68 20 74 68 65 20 69 6e 70 75 74 20 69 73 20 ch the input is
bfc0: 61 20 68 61 73 68 2e 20 20 49 66 20 6f 6b 52 64 a hash. If okRd
bfd0: 41 64 64 72 20 69 73 0a 2a 2a 20 66 61 6c 73 65 Addr is.** false
bfe0: 20 6f 72 20 69 66 20 74 68 65 20 6c 6f 6f 6b 75 or if the looku
bff0: 70 20 66 61 69 6c 73 2c 20 72 65 74 75 72 6e 20 p fails, return
c000: 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 73 74 72 the original str
c010: 69 6e 67 20 63 6f 6e 74 65 6e 74 2e 0a 2a 2a 0a ing content..**.
c020: 2a 2a 20 49 6e 20 65 69 74 68 65 72 20 63 61 73 ** In either cas
c030: 65 2c 20 74 68 65 20 73 74 72 69 6e 67 20 72 65 e, the string re
c040: 74 75 72 6e 65 64 20 69 73 20 73 74 6f 72 65 64 turned is stored
c050: 20 69 6e 20 73 70 61 63 65 20 6f 62 74 61 69 6e in space obtain
c060: 65 64 0a 2a 2a 20 66 72 6f 6d 20 6d 61 6c 6c 6f ed.** from mallo
c070: 63 20 61 6e 64 20 73 68 6f 75 6c 64 20 62 65 20 c and should be
c080: 66 72 65 65 64 20 62 79 20 74 68 65 20 63 61 6c freed by the cal
c090: 6c 69 6e 67 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a ling function..*
c0a0: 2f 0a 63 68 61 72 20 2a 64 62 5f 72 65 76 65 61 /.char *db_revea
c0b0: 6c 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4b l(const char *zK
c0c0: 65 79 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4f 75 ey){. char *zOu
c0d0: 74 3b 0a 20 20 69 66 28 20 67 2e 70 65 72 6d 2e t;. if( g.perm.
c0e0: 52 64 41 64 64 72 20 29 7b 0a 20 20 20 20 7a 4f RdAddr ){. zO
c0f0: 75 74 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 ut = db_text(0,
c100: 22 53 45 4c 45 43 54 20 63 6f 6e 74 65 6e 74 20 "SELECT content
c110: 46 52 4f 4d 20 63 6f 6e 63 65 61 6c 65 64 20 57 FROM concealed W
c120: 48 45 52 45 20 68 61 73 68 3d 25 51 22 2c 20 7a HERE hash=%Q", z
c130: 4b 65 79 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 Key);. }else{.
c140: 20 20 20 7a 4f 75 74 20 3d 20 30 3b 0a 20 20 7d zOut = 0;. }
c150: 0a 20 20 69 66 28 20 7a 4f 75 74 3d 3d 30 20 29 . if( zOut==0 )
c160: 7b 0a 20 20 20 20 7a 4f 75 74 20 3d 20 6d 70 72 {. zOut = mpr
c170: 69 6e 74 66 28 22 25 73 22 2c 20 7a 4b 65 79 29 intf("%s", zKey)
c180: 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a ;. }. return z
c190: 4f 75 74 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 Out;.}../*.** Re
c1a0: 74 75 72 6e 20 74 72 75 65 20 69 66 20 74 68 65 turn true if the
c1b0: 20 73 74 72 69 6e 67 20 7a 56 61 6c 20 72 65 70 string zVal rep
c1c0: 72 65 73 65 6e 74 73 20 22 74 72 75 65 22 20 28 resents "true" (
c1d0: 6f 72 20 22 66 61 6c 73 65 22 29 2e 0a 2a 2f 0a or "false")..*/.
c1e0: 69 6e 74 20 69 73 5f 74 72 75 74 68 28 63 6f 6e int is_truth(con
c1f0: 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 29 7b 0a st char *zVal){.
c200: 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 static const c
c210: 68 61 72 20 2a 63 6f 6e 73 74 20 61 7a 4f 6e 5b har *const azOn[
c220: 5d 20 3d 20 7b 20 22 6f 6e 22 2c 20 22 79 65 73 ] = { "on", "yes
c230: 22 2c 20 22 74 72 75 65 22 2c 20 22 31 22 20 7d ", "true", "1" }
c240: 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 66 6f 72 ;. int i;. for
c250: 28 69 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 61 7a (i=0; i<count(az
c260: 4f 6e 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 69 On); i++){. i
c270: 66 28 20 66 6f 73 73 69 6c 5f 73 74 72 69 63 6d f( fossil_stricm
c280: 70 28 7a 56 61 6c 2c 61 7a 4f 6e 5b 69 5d 29 3d p(zVal,azOn[i])=
c290: 3d 30 20 29 20 72 65 74 75 72 6e 20 31 3b 0a 20 =0 ) return 1;.
c2a0: 20 7d 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d }. return 0;.}
c2b0: 0a 69 6e 74 20 69 73 5f 66 61 6c 73 65 28 63 6f .int is_false(co
c2c0: 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 29 7b nst char *zVal){
c2d0: 0a 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 . static const
c2e0: 63 68 61 72 20 2a 63 6f 6e 73 74 20 61 7a 4f 66 char *const azOf
c2f0: 66 5b 5d 20 3d 20 7b 20 22 6f 66 66 22 2c 20 22 f[] = { "off", "
c300: 6e 6f 22 2c 20 22 66 61 6c 73 65 22 2c 20 22 30 no", "false", "0
c310: 22 20 7d 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 " };. int i;.
c320: 66 6f 72 28 69 3d 30 3b 20 69 3c 63 6f 75 6e 74 for(i=0; i<count
c330: 28 61 7a 4f 66 66 29 3b 20 69 2b 2b 29 7b 0a 20 (azOff); i++){.
c340: 20 20 20 69 66 28 20 66 6f 73 73 69 6c 5f 73 74 if( fossil_st
c350: 72 69 63 6d 70 28 7a 56 61 6c 2c 61 7a 4f 66 66 ricmp(zVal,azOff
c360: 5b 69 5d 29 3d 3d 30 20 29 20 72 65 74 75 72 6e [i])==0 ) return
c370: 20 31 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 1;. }. return
c380: 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 77 61 0;.}../*.** Swa
c390: 70 20 74 68 65 20 67 2e 64 62 20 61 6e 64 20 67 p the g.db and g
c3a0: 2e 64 62 43 6f 6e 66 69 67 20 63 6f 6e 6e 65 63 .dbConfig connec
c3b0: 74 69 6f 6e 73 20 73 6f 20 74 68 61 74 20 74 68 tions so that th
c3c0: 65 20 76 61 72 69 6f 75 73 20 64 62 5f 2a 20 72 e various db_* r
c3d0: 6f 75 74 69 6e 65 73 0a 2a 2a 20 77 6f 72 6b 20 outines.** work
c3e0: 6f 6e 20 74 68 65 20 7e 2f 2e 66 6f 73 73 69 6c on the ~/.fossil
c3f0: 20 64 61 74 61 62 61 73 65 20 69 6e 73 74 65 61 database instea
c400: 64 20 6f 66 20 6f 6e 20 74 68 65 20 72 65 70 6f d of on the repo
c410: 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 65 2e sitory database.
c420: 0a 2a 2a 20 42 65 20 73 75 72 65 20 74 6f 20 73 .** Be sure to s
c430: 77 61 70 20 74 68 65 6d 20 62 61 63 6b 20 61 66 wap them back af
c440: 74 65 72 20 64 6f 69 6e 67 20 74 68 65 20 6f 70 ter doing the op
c450: 65 72 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 49 eration..**.** I
c460: 66 20 74 68 65 20 7e 2f 2e 66 6f 73 73 69 6c 20 f the ~/.fossil
c470: 64 61 74 61 62 61 73 65 20 68 61 73 20 61 6c 72 database has alr
c480: 65 61 64 79 20 62 65 65 6e 20 6f 70 65 6e 65 64 eady been opened
c490: 20 61 73 20 74 68 65 20 6d 61 69 6e 20 64 61 74 as the main dat
c4a0: 61 62 61 73 65 20 6f 72 0a 2a 2a 20 69 73 20 61 abase or.** is a
c4b0: 74 74 61 63 68 65 64 20 74 6f 20 74 68 65 20 6d ttached to the m
c4c0: 61 69 6e 20 64 61 74 61 62 61 73 65 2c 20 6e 6f ain database, no
c4d0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 77 61 70 connection swap
c4e0: 73 20 61 72 65 20 72 65 71 75 69 72 65 64 20 73 s are required s
c4f0: 6f 20 74 68 69 73 0a 2a 2a 20 72 6f 75 74 69 6e o this.** routin
c500: 65 20 69 73 20 61 20 6e 6f 2d 6f 70 2e 0a 2a 2f e is a no-op..*/
c510: 0a 76 6f 69 64 20 64 62 5f 73 77 61 70 5f 63 6f .void db_swap_co
c520: 6e 6e 65 63 74 69 6f 6e 73 28 76 6f 69 64 29 7b nnections(void){
c530: 0a 20 20 2f 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 . /*. ** When
c540: 73 77 61 70 70 69 6e 67 20 74 68 65 20 6d 61 69 swapping the mai
c550: 6e 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 n database conne
c560: 63 74 69 6f 6e 20 77 69 74 68 20 74 68 65 20 63 ction with the c
c570: 6f 6e 66 69 67 20 64 61 74 61 62 61 73 65 0a 20 onfig database.
c580: 20 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 2c 20 ** connection,
c590: 74 68 65 20 63 6f 6e 66 69 67 20 64 61 74 61 62 the config datab
c5a0: 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 6d ase connection m
c5b0: 75 73 74 20 62 65 20 6f 70 65 6e 20 28 6e 6f 74 ust be open (not
c5c0: 20 73 69 6d 70 6c 79 0a 20 20 2a 2a 20 61 74 74 simply. ** att
c5d0: 61 63 68 65 64 29 3b 20 6f 74 68 65 72 77 69 73 ached); otherwis
c5e0: 65 2c 20 74 68 65 20 73 77 61 70 20 77 6f 75 6c e, the swap woul
c5f0: 64 20 65 6e 64 20 75 70 20 6c 65 61 76 69 6e 67 d end up leaving
c600: 20 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 the main databa
c610: 73 65 0a 20 20 2a 2a 20 63 6f 6e 6e 65 63 74 69 se. ** connecti
c620: 6f 6e 20 69 6e 76 61 6c 69 64 2c 20 64 65 66 65 on invalid, defe
c630: 61 74 69 6e 67 20 74 68 65 20 76 65 72 79 20 70 ating the very p
c640: 75 72 70 6f 73 65 20 6f 66 20 74 68 69 73 20 72 urpose of this r
c650: 6f 75 74 69 6e 65 2e 20 20 54 68 69 73 0a 20 20 outine. This.
c660: 2a 2a 20 73 61 6d 65 20 63 6f 6e 73 74 72 61 69 ** same constrai
c670: 6e 74 20 61 6c 73 6f 20 68 6f 6c 64 73 20 74 72 nt also holds tr
c680: 75 65 20 77 68 65 6e 20 72 65 73 74 6f 72 69 6e ue when restorin
c690: 67 20 74 68 65 20 70 72 65 76 69 6f 75 73 6c 79 g the previously
c6a0: 20 73 77 61 70 70 65 64 0a 20 20 2a 2a 20 64 61 swapped. ** da
c6b0: 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
c6c0: 6e 3b 20 6f 74 68 65 72 77 69 73 65 2c 20 69 74 n; otherwise, it
c6d0: 20 6d 65 61 6e 73 20 74 68 61 74 20 6e 6f 20 73 means that no s
c6e0: 77 61 70 20 77 61 73 20 70 65 72 66 6f 72 6d 65 wap was performe
c6f0: 64 0a 20 20 2a 2a 20 62 65 63 61 75 73 65 20 74 d. ** because t
c700: 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 he main database
c710: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 77 61 73 20 connection was
c720: 61 6c 72 65 61 64 79 20 70 6f 69 6e 74 69 6e 67 already pointing
c730: 20 74 6f 20 74 68 65 20 63 6f 6e 66 69 67 0a 20 to the config.
c740: 20 2a 2a 20 64 61 74 61 62 61 73 65 2e 0a 20 20 ** database..
c750: 2a 2f 0a 20 20 69 66 28 20 67 2e 64 62 43 6f 6e */. if( g.dbCon
c760: 66 69 67 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 fig ){. sqlit
c770: 65 33 20 2a 64 62 54 65 6d 70 20 3d 20 67 2e 64 e3 *dbTemp = g.d
c780: 62 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 b;. const cha
c790: 72 20 2a 7a 54 65 6d 70 44 62 54 79 70 65 20 3d r *zTempDbType =
c7a0: 20 67 2e 7a 4d 61 69 6e 44 62 54 79 70 65 3b 0a g.zMainDbType;.
c7b0: 20 20 20 20 67 2e 64 62 20 3d 20 67 2e 64 62 43 g.db = g.dbC
c7c0: 6f 6e 66 69 67 3b 0a 20 20 20 20 67 2e 7a 4d 61 onfig;. g.zMa
c7d0: 69 6e 44 62 54 79 70 65 20 3d 20 67 2e 7a 43 6f inDbType = g.zCo
c7e0: 6e 66 69 67 44 62 54 79 70 65 3b 0a 20 20 20 20 nfigDbType;.
c7f0: 67 2e 64 62 43 6f 6e 66 69 67 20 3d 20 64 62 54 g.dbConfig = dbT
c800: 65 6d 70 3b 0a 20 20 20 20 67 2e 7a 43 6f 6e 66 emp;. g.zConf
c810: 69 67 44 62 54 79 70 65 20 3d 20 7a 54 65 6d 70 igDbType = zTemp
c820: 44 62 54 79 70 65 3b 0a 20 20 7d 0a 7d 0a 0a 2f DbType;. }.}../
c830: 2a 0a 2a 2a 20 4c 6f 67 69 63 20 66 6f 72 20 72 *.** Logic for r
c840: 65 61 64 69 6e 67 20 70 6f 74 65 6e 74 69 61 6c eading potential
c850: 6c 79 20 76 65 72 73 69 6f 6e 65 64 20 73 65 74 ly versioned set
c860: 74 69 6e 67 73 20 66 72 6f 6d 0a 2a 2a 20 2e 66 tings from.** .f
c870: 6f 73 73 69 6c 2d 73 65 74 74 69 6e 67 73 2f 3c ossil-settings/<
c880: 6e 61 6d 65 3e 20 2c 20 61 6e 64 20 65 6d 69 74 name> , and emit
c890: 73 20 77 61 72 6e 69 6e 67 73 20 69 66 20 6e 65 s warnings if ne
c8a0: 63 65 73 73 61 72 79 2e 0a 2a 2a 20 52 65 74 75 cessary..** Retu
c8b0: 72 6e 73 20 74 68 65 20 6e 6f 6e 2d 76 65 72 73 rns the non-vers
c8c0: 69 6f 6e 65 64 20 76 61 6c 75 65 20 77 69 74 68 ioned value with
c8d0: 6f 75 74 20 6d 6f 64 69 66 69 63 61 74 69 6f 6e out modification
c8e0: 20 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 0a if there is no.
c8f0: 2a 2a 20 76 65 72 73 69 6f 6e 65 64 20 76 61 6c ** versioned val
c900: 75 65 2e 0a 2a 2f 0a 63 68 61 72 20 2a 64 62 5f ue..*/.char *db_
c910: 67 65 74 5f 64 6f 5f 76 65 72 73 69 6f 6e 61 62 get_do_versionab
c920: 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a le(const char *z
c930: 4e 61 6d 65 2c 20 63 68 61 72 20 2a 7a 4e 6f 6e Name, char *zNon
c940: 56 65 72 73 69 6f 6e 65 64 53 65 74 74 69 6e 67 VersionedSetting
c950: 29 7b 0a 20 20 63 68 61 72 20 2a 7a 56 65 72 73 ){. char *zVers
c960: 69 6f 6e 65 64 53 65 74 74 69 6e 67 20 3d 20 30 ionedSetting = 0
c970: 3b 0a 20 20 69 6e 74 20 6e 6f 57 61 72 6e 20 3d ;. int noWarn =
c980: 20 30 3b 0a 20 20 73 74 72 75 63 74 20 5f 63 61 0;. struct _ca
c990: 63 68 65 45 6e 74 72 79 20 7b 0a 20 20 20 20 73 cheEntry {. s
c9a0: 74 72 75 63 74 20 5f 63 61 63 68 65 45 6e 74 72 truct _cacheEntr
c9b0: 79 20 2a 6e 65 78 74 3b 0a 20 20 20 20 63 6f 6e y *next;. con
c9c0: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 st char *zName,
c9d0: 2a 7a 56 61 6c 75 65 3b 0a 20 20 7d 20 2a 63 61 *zValue;. } *ca
c9e0: 63 68 65 45 6e 74 72 79 20 3d 20 30 3b 0a 20 20 cheEntry = 0;.
c9f0: 73 74 61 74 69 63 20 73 74 72 75 63 74 20 5f 63 static struct _c
ca00: 61 63 68 65 45 6e 74 72 79 20 2a 63 61 63 68 65 acheEntry *cache
ca10: 20 3d 20 30 3b 0a 0a 20 20 69 66 28 20 21 67 2e = 0;.. if( !g.
ca20: 6c 6f 63 61 6c 4f 70 65 6e 29 20 72 65 74 75 72 localOpen) retur
ca30: 6e 20 7a 4e 6f 6e 56 65 72 73 69 6f 6e 65 64 53 n zNonVersionedS
ca40: 65 74 74 69 6e 67 3b 0a 20 20 2f 2a 20 4c 6f 6f etting;. /* Loo
ca50: 6b 20 75 70 20 6e 61 6d 65 20 69 6e 20 63 61 63 k up name in cac
ca60: 68 65 20 2a 2f 0a 20 20 63 61 63 68 65 45 6e 74 he */. cacheEnt
ca70: 72 79 20 3d 20 63 61 63 68 65 3b 0a 20 20 77 68 ry = cache;. wh
ca80: 69 6c 65 28 20 63 61 63 68 65 45 6e 74 72 79 21 ile( cacheEntry!
ca90: 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 66 6f =0 ){. if( fo
caa0: 73 73 69 6c 5f 73 74 72 63 6d 70 28 63 61 63 68 ssil_strcmp(cach
cab0: 65 45 6e 74 72 79 2d 3e 7a 4e 61 6d 65 2c 20 7a eEntry->zName, z
cac0: 4e 61 6d 65 29 3d 3d 30 20 29 7b 0a 20 20 20 20 Name)==0 ){.
cad0: 20 20 7a 56 65 72 73 69 6f 6e 65 64 53 65 74 74 zVersionedSett
cae0: 69 6e 67 20 3d 20 66 6f 73 73 69 6c 5f 73 74 72 ing = fossil_str
caf0: 64 75 70 28 63 61 63 68 65 45 6e 74 72 79 2d 3e dup(cacheEntry->
cb00: 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 62 zValue);. b
cb10: 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 reak;. }.
cb20: 63 61 63 68 65 45 6e 74 72 79 20 3d 20 63 61 63 cacheEntry = cac
cb30: 68 65 45 6e 74 72 79 2d 3e 6e 65 78 74 3b 0a 20 heEntry->next;.
cb40: 20 7d 0a 20 20 2f 2a 20 41 74 74 65 6d 70 74 20 }. /* Attempt
cb50: 74 6f 20 72 65 61 64 20 76 61 6c 75 65 20 66 72 to read value fr
cb60: 6f 6d 20 66 69 6c 65 20 69 6e 20 63 68 65 63 6b om file in check
cb70: 6f 75 74 20 69 66 20 74 68 65 72 65 20 77 61 73 out if there was
cb80: 6e 27 74 20 61 20 63 61 63 68 65 20 68 69 74 0a n't a cache hit.
cb90: 20 20 2a 2a 20 61 6e 64 20 61 20 63 68 65 63 6b ** and a check
cba0: 6f 75 74 20 69 73 20 6f 70 65 6e 2e 20 2a 2f 0a out is open. */.
cbb0: 20 20 69 66 28 20 63 61 63 68 65 45 6e 74 72 79 if( cacheEntry
cbc0: 3d 3d 30 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 ==0 ){. Blob
cbd0: 76 65 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d versionedPathnam
cbe0: 65 3b 0a 20 20 20 20 63 68 61 72 20 2a 7a 56 65 e;. char *zVe
cbf0: 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 3b rsionedPathname;
cc00: 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 . blob_zero(&
cc10: 76 65 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d versionedPathnam
cc20: 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 e);. blob_app
cc30: 65 6e 64 66 28 26 76 65 72 73 69 6f 6e 65 64 50 endf(&versionedP
cc40: 61 74 68 6e 61 6d 65 2c 20 22 25 73 2e 66 6f 73 athname, "%s.fos
cc50: 73 69 6c 2d 73 65 74 74 69 6e 67 73 2f 25 73 22 sil-settings/%s"
cc60: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
cc70: 20 20 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c g.zLocalRoot,
cc80: 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 7a 56 65 zName);. zVe
cc90: 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 20 rsionedPathname
cca0: 3d 20 62 6c 6f 62 5f 73 74 72 28 26 76 65 72 73 = blob_str(&vers
ccb0: 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 29 3b 0a ionedPathname);.
ccc0: 20 20 20 20 69 66 28 20 66 69 6c 65 5f 73 69 7a if( file_siz
ccd0: 65 28 7a 56 65 72 73 69 6f 6e 65 64 50 61 74 68 e(zVersionedPath
cce0: 6e 61 6d 65 29 3e 3d 30 20 29 7b 0a 20 20 20 20 name)>=0 ){.
ccf0: 20 20 2f 2a 20 46 69 6c 65 20 65 78 69 73 74 73 /* File exists
cd00: 2c 20 61 6e 64 20 63 6f 6e 74 61 69 6e 73 20 74 , and contains t
cd10: 68 65 20 76 61 6c 75 65 20 66 6f 72 20 74 68 69 he value for thi
cd20: 73 20 73 65 74 74 69 6e 67 2e 20 4c 6f 61 64 20 s setting. Load
cd30: 66 72 6f 6d 0a 20 20 20 20 20 20 2a 2a 20 74 68 from. ** th
cd40: 65 20 66 69 6c 65 2e 20 2a 2f 0a 20 20 20 20 20 e file. */.
cd50: 20 42 6c 6f 62 20 73 65 74 74 69 6e 67 3b 0a 20 Blob setting;.
cd60: 20 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 blob_zero(&
cd70: 73 65 74 74 69 6e 67 29 3b 0a 20 20 20 20 20 20 setting);.
cd80: 69 66 28 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 if( blob_read_fr
cd90: 6f 6d 5f 66 69 6c 65 28 26 73 65 74 74 69 6e 67 om_file(&setting
cda0: 2c 20 7a 56 65 72 73 69 6f 6e 65 64 50 61 74 68 , zVersionedPath
cdb0: 6e 61 6d 65 29 20 3e 3d 20 30 20 29 7b 0a 20 20 name) >= 0 ){.
cdc0: 20 20 20 20 20 20 62 6c 6f 62 5f 74 72 69 6d 28 blob_trim(
cdd0: 26 73 65 74 74 69 6e 67 29 3b 20 2f 2a 20 41 76 &setting); /* Av
cde0: 6f 69 64 20 6e 6f 6e 2d 6f 62 76 69 6f 75 73 20 oid non-obvious
cdf0: 70 72 6f 62 6c 65 6d 73 20 77 69 74 68 20 6c 69 problems with li
ce00: 6e 65 20 65 6e 64 69 6e 67 73 0a 20 20 20 20 20 ne endings.
ce10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ce20: 20 20 20 20 20 20 20 20 2a 2a 20 6f 6e 20 62 6f ** on bo
ce30: 6f 6c 65 61 6e 20 70 72 6f 70 65 72 74 69 65 73 olean properties
ce40: 20 2a 2f 0a 20 20 20 20 20 20 20 20 7a 56 65 72 */. zVer
ce50: 73 69 6f 6e 65 64 53 65 74 74 69 6e 67 20 3d 20 sionedSetting =
ce60: 73 74 72 64 75 70 28 62 6c 6f 62 5f 73 74 72 28 strdup(blob_str(
ce70: 26 73 65 74 74 69 6e 67 29 29 3b 0a 20 20 20 20 &setting));.
ce80: 20 20 7d 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 }. blob_r
ce90: 65 73 65 74 28 26 73 65 74 74 69 6e 67 29 3b 0a eset(&setting);.
cea0: 20 20 20 20 20 20 2f 2a 20 53 65 65 20 69 66 20 /* See if
ceb0: 74 68 65 72 65 27 73 20 61 20 6e 6f 2d 77 61 72 there's a no-war
cec0: 6e 20 66 6c 61 67 20 2a 2f 0a 20 20 20 20 20 20 n flag */.
ced0: 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 76 65 72 blob_append(&ver
cee0: 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 2c 20 sionedPathname,
cef0: 22 2e 6e 6f 2d 77 61 72 6e 22 2c 20 2d 31 29 3b ".no-warn", -1);
cf00: 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c 65 5f . if( file_
cf10: 73 69 7a 65 28 62 6c 6f 62 5f 73 74 72 28 26 76 size(blob_str(&v
cf20: 65 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 ersionedPathname
cf30: 29 29 3e 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 ))>=0 ){.
cf40: 20 6e 6f 57 61 72 6e 20 3d 20 31 3b 0a 20 20 20 noWarn = 1;.
cf50: 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 62 }. }. b
cf60: 6c 6f 62 5f 72 65 73 65 74 28 26 76 65 72 73 69 lob_reset(&versi
cf70: 6f 6e 65 64 50 61 74 68 6e 61 6d 65 29 3b 0a 20 onedPathname);.
cf80: 20 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 /* Store resu
cf90: 6c 74 20 69 6e 20 63 61 63 68 65 2c 20 77 68 69 lt in cache, whi
cfa0: 63 68 20 63 61 6e 20 62 65 20 74 68 65 20 76 61 ch can be the va
cfb0: 6c 75 65 20 6f 72 20 30 20 69 66 20 6e 6f 74 20 lue or 0 if not
cfc0: 66 6f 75 6e 64 20 2a 2f 0a 20 20 20 20 63 61 63 found */. cac
cfd0: 68 65 45 6e 74 72 79 20 3d 20 28 73 74 72 75 63 heEntry = (struc
cfe0: 74 20 5f 63 61 63 68 65 45 6e 74 72 79 2a 29 66 t _cacheEntry*)f
cff0: 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 28 73 69 7a ossil_malloc(siz
d000: 65 6f 66 28 73 74 72 75 63 74 20 5f 63 61 63 68 eof(struct _cach
d010: 65 45 6e 74 72 79 29 29 3b 0a 20 20 20 20 63 61 eEntry));. ca
d020: 63 68 65 45 6e 74 72 79 2d 3e 6e 65 78 74 20 3d cheEntry->next =
d030: 20 63 61 63 68 65 3b 0a 20 20 20 20 63 61 63 68 cache;. cach
d040: 65 45 6e 74 72 79 2d 3e 7a 4e 61 6d 65 20 3d 20 eEntry->zName =
d050: 7a 4e 61 6d 65 3b 0a 20 20 20 20 63 61 63 68 65 zName;. cache
d060: 45 6e 74 72 79 2d 3e 7a 56 61 6c 75 65 20 3d 20 Entry->zValue =
d070: 66 6f 73 73 69 6c 5f 73 74 72 64 75 70 28 7a 56 fossil_strdup(zV
d080: 65 72 73 69 6f 6e 65 64 53 65 74 74 69 6e 67 29 ersionedSetting)
d090: 3b 0a 20 20 20 20 63 61 63 68 65 20 3d 20 63 61 ;. cache = ca
d0a0: 63 68 65 45 6e 74 72 79 3b 0a 20 20 7d 0a 20 20 cheEntry;. }.
d0b0: 2f 2a 20 44 69 73 70 6c 61 79 20 61 20 77 61 72 /* Display a war
d0c0: 6e 69 6e 67 3f 20 2a 2f 0a 20 20 69 66 28 20 7a ning? */. if( z
d0d0: 56 65 72 73 69 6f 6e 65 64 53 65 74 74 69 6e 67 VersionedSetting
d0e0: 21 3d 30 20 26 26 20 7a 4e 6f 6e 56 65 72 73 69 !=0 && zNonVersi
d0f0: 6f 6e 65 64 53 65 74 74 69 6e 67 21 3d 30 0a 20 onedSetting!=0.
d100: 20 20 26 26 20 7a 4e 6f 6e 56 65 72 73 69 6f 6e && zNonVersion
d110: 65 64 53 65 74 74 69 6e 67 5b 30 5d 21 3d 27 5c edSetting[0]!='\
d120: 30 27 20 26 26 20 21 6e 6f 57 61 72 6e 0a 20 20 0' && !noWarn.
d130: 29 7b 0a 20 20 20 20 2f 2a 20 54 68 65 72 65 27 ){. /* There'
d140: 73 20 61 20 76 65 72 73 69 6f 6e 65 64 20 73 65 s a versioned se
d150: 74 74 69 6e 67 2c 20 61 6e 64 20 61 20 6e 6f 6e tting, and a non
d160: 2d 76 65 72 73 69 6f 6e 65 64 20 73 65 74 74 69 -versioned setti
d170: 6e 67 2e 20 54 65 6c 6c 0a 20 20 20 20 2a 2a 20 ng. Tell. **
d180: 74 68 65 20 75 73 65 72 20 61 62 6f 75 74 20 74 the user about t
d190: 68 65 20 63 6f 6e 66 6c 69 63 74 20 2a 2f 0a 20 he conflict */.
d1a0: 20 20 20 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e fossil_warnin
d1b0: 67 28 0a 20 20 20 20 20 20 20 20 22 73 65 74 74 g(. "sett
d1c0: 69 6e 67 20 25 73 20 68 61 73 20 62 6f 74 68 20 ing %s has both
d1d0: 76 65 72 73 69 6f 6e 65 64 20 61 6e 64 20 6e 6f versioned and no
d1e0: 6e 2d 76 65 72 73 69 6f 6e 65 64 20 76 61 6c 75 n-versioned valu
d1f0: 65 73 3a 20 75 73 69 6e 67 20 22 0a 20 20 20 20 es: using ".
d200: 20 20 20 20 22 76 65 72 73 69 6f 6e 65 64 20 76 "versioned v
d210: 61 6c 75 65 20 66 72 6f 6d 20 66 69 6c 65 20 2e alue from file .
d220: 66 6f 73 73 69 6c 2d 73 65 74 74 69 6e 67 73 2f fossil-settings/
d230: 25 73 20 28 74 6f 20 73 69 6c 65 6e 63 65 20 74 %s (to silence t
d240: 68 69 73 20 22 0a 20 20 20 20 20 20 20 20 22 77 his ". "w
d250: 61 72 6e 69 6e 67 2c 20 65 69 74 68 65 72 20 63 arning, either c
d260: 72 65 61 74 65 20 61 6e 20 65 6d 70 74 79 20 66 reate an empty f
d270: 69 6c 65 20 6e 61 6d 65 64 20 22 0a 20 20 20 20 ile named ".
d280: 20 20 20 20 22 2e 66 6f 73 73 69 6c 2d 73 65 74 ".fossil-set
d290: 74 69 6e 67 73 2f 25 73 2e 6e 6f 2d 77 61 72 6e tings/%s.no-warn
d2a0: 20 6f 72 20 64 65 6c 65 74 65 20 74 68 65 20 6e or delete the n
d2b0: 6f 6e 2d 76 65 72 73 69 6f 6e 65 64 20 73 65 74 on-versioned set
d2c0: 74 69 6e 67 20 22 0a 20 20 20 20 20 20 20 20 22 ting ". "
d2d0: 20 77 69 74 68 20 5c 22 66 6f 73 73 69 6c 20 75 with \"fossil u
d2e0: 6e 73 65 74 20 25 73 5c 22 29 22 2c 20 7a 4e 61 nset %s\")", zNa
d2f0: 6d 65 2c 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d 65 me, zName, zName
d300: 2c 20 7a 4e 61 6d 65 0a 20 20 20 20 29 3b 0a 20 , zName. );.
d310: 20 7d 0a 20 20 2f 2a 20 50 72 65 66 65 72 20 74 }. /* Prefer t
d320: 68 65 20 76 65 72 73 69 6f 6e 65 64 20 73 65 74 he versioned set
d330: 74 69 6e 67 20 2a 2f 0a 20 20 72 65 74 75 72 6e ting */. return
d340: 20 28 20 7a 56 65 72 73 69 6f 6e 65 64 53 65 74 ( zVersionedSet
d350: 74 69 6e 67 21 3d 30 20 29 20 3f 20 7a 56 65 72 ting!=0 ) ? zVer
d360: 73 69 6f 6e 65 64 53 65 74 74 69 6e 67 20 3a 20 sionedSetting :
d370: 7a 4e 6f 6e 56 65 72 73 69 6f 6e 65 64 53 65 74 zNonVersionedSet
d380: 74 69 6e 67 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 ting;.}.../*.**
d390: 47 65 74 20 61 6e 64 20 73 65 74 20 76 61 6c 75 Get and set valu
d3a0: 65 73 20 66 72 6f 6d 20 74 68 65 20 43 4f 4e 46 es from the CONF
d3b0: 49 47 2c 20 47 4c 4f 42 41 4c 5f 43 4f 4e 46 49 IG, GLOBAL_CONFI
d3c0: 47 20 61 6e 64 20 56 56 41 52 20 74 61 62 6c 65 G and VVAR table
d3d0: 20 69 6e 20 74 68 65 0a 2a 2a 20 72 65 70 6f 73 in the.** repos
d3e0: 69 74 6f 72 79 20 61 6e 64 20 6c 6f 63 61 6c 20 itory and local
d3f0: 64 61 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 63 68 databases..*/.ch
d400: 61 72 20 2a 64 62 5f 67 65 74 28 63 6f 6e 73 74 ar *db_get(const
d410: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 63 68 char *zName, ch
d420: 61 72 20 2a 7a 44 65 66 61 75 6c 74 29 7b 0a 20 ar *zDefault){.
d430: 20 63 68 61 72 20 2a 7a 20 3d 20 30 3b 0a 20 20 char *z = 0;.
d440: 69 6e 74 20 69 3b 0a 20 20 63 6f 6e 73 74 20 73 int i;. const s
d450: 74 72 75 63 74 20 73 74 43 6f 6e 74 72 6f 6c 53 truct stControlS
d460: 65 74 74 69 6e 67 73 20 2a 63 74 72 6c 53 65 74 ettings *ctrlSet
d470: 74 69 6e 67 20 3d 20 30 3b 0a 20 20 2f 2a 20 49 ting = 0;. /* I
d480: 73 20 74 68 69 73 20 61 20 73 65 74 74 69 6e 67 s this a setting
d490: 3f 20 2a 2f 0a 20 20 66 6f 72 28 69 3d 30 3b 20 ? */. for(i=0;
d4a0: 63 74 72 6c 53 65 74 74 69 6e 67 73 5b 69 5d 2e ctrlSettings[i].
d4b0: 6e 61 6d 65 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 name; i++){.
d4c0: 69 66 28 20 73 74 72 63 6d 70 28 63 74 72 6c 53 if( strcmp(ctrlS
d4d0: 65 74 74 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 2c ettings[i].name,
d4e0: 20 7a 4e 61 6d 65 29 3d 3d 30 20 29 7b 0a 20 20 zName)==0 ){.
d4f0: 20 20 20 20 63 74 72 6c 53 65 74 74 69 6e 67 20 ctrlSetting
d500: 3d 20 26 28 63 74 72 6c 53 65 74 74 69 6e 67 73 = &(ctrlSettings
d510: 5b 69 5d 29 3b 0a 20 20 20 20 20 20 62 72 65 61 [i]);. brea
d520: 6b 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 k;. }. }. i
d530: 66 28 20 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f f( g.repositoryO
d540: 70 65 6e 20 29 7b 0a 20 20 20 20 7a 20 3d 20 64 pen ){. z = d
d550: 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 b_text(0, "SELEC
d560: 54 20 76 61 6c 75 65 20 46 52 4f 4d 20 63 6f 6e T value FROM con
d570: 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 fig WHERE name=%
d580: 51 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a Q", zName);. }.
d590: 20 20 69 66 28 20 7a 3d 3d 30 20 26 26 20 67 2e if( z==0 && g.
d5a0: 7a 43 6f 6e 66 69 67 44 62 4e 61 6d 65 20 29 7b zConfigDbName ){
d5b0: 0a 20 20 20 20 64 62 5f 73 77 61 70 5f 63 6f 6e . db_swap_con
d5c0: 6e 65 63 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20 nections();.
d5d0: 7a 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 z = db_text(0, "
d5e0: 53 45 4c 45 43 54 20 76 61 6c 75 65 20 46 52 4f SELECT value FRO
d5f0: 4d 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 20 M global_config
d600: 57 48 45 52 45 20 6e 61 6d 65 3d 25 51 22 2c 20 WHERE name=%Q",
d610: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 64 62 5f 73 zName);. db_s
d620: 77 61 70 5f 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 wap_connections(
d630: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 63 74 72 );. }. if( ctr
d640: 6c 53 65 74 74 69 6e 67 21 3d 30 20 26 26 20 63 lSetting!=0 && c
d650: 74 72 6c 53 65 74 74 69 6e 67 2d 3e 76 65 72 73 trlSetting->vers
d660: 69 6f 6e 61 62 6c 65 20 29 7b 0a 20 20 20 20 2f ionable ){. /
d670: 2a 20 54 68 69 73 20 69 73 20 61 20 76 65 72 73 * This is a vers
d680: 69 6f 6e 61 62 6c 65 20 73 65 74 74 69 6e 67 2c ionable setting,
d690: 20 74 72 79 20 61 6e 64 20 67 65 74 20 74 68 65 try and get the
d6a0: 20 69 6e 66 6f 20 66 72 6f 6d 20 61 0a 20 20 20 info from a.
d6b0: 20 2a 2a 20 63 68 65 63 6b 65 64 20 6f 75 74 20 ** checked out
d6c0: 66 69 6c 65 20 2a 2f 0a 20 20 20 20 7a 20 3d 20 file */. z =
d6d0: 64 62 5f 67 65 74 5f 64 6f 5f 76 65 72 73 69 6f db_get_do_versio
d6e0: 6e 61 62 6c 65 28 7a 4e 61 6d 65 2c 20 7a 29 3b nable(zName, z);
d6f0: 0a 20 20 7d 0a 20 20 69 66 28 20 7a 3d 3d 30 20 . }. if( z==0
d700: 29 7b 0a 20 20 20 20 7a 20 3d 20 7a 44 65 66 61 ){. z = zDefa
d710: 75 6c 74 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 ult;. }. retur
d720: 6e 20 7a 3b 0a 7d 0a 63 68 61 72 20 2a 64 62 5f n z;.}.char *db_
d730: 67 65 74 5f 6d 74 69 6d 65 28 63 6f 6e 73 74 20 get_mtime(const
d740: 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 63 68 61 char *zName, cha
d750: 72 20 2a 7a 46 6f 72 6d 61 74 2c 20 63 68 61 72 r *zFormat, char
d760: 20 2a 7a 44 65 66 61 75 6c 74 29 7b 0a 20 20 63 *zDefault){. c
d770: 68 61 72 20 2a 7a 20 3d 20 30 3b 0a 20 20 69 66 har *z = 0;. if
d780: 28 20 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 ( g.repositoryOp
d790: 65 6e 20 29 7b 0a 20 20 20 20 7a 20 3d 20 64 62 en ){. z = db
d7a0: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 _text(0, "SELECT
d7b0: 20 6d 74 69 6d 65 20 46 52 4f 4d 20 63 6f 6e 66 mtime FROM conf
d7c0: 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 51 ig WHERE name=%Q
d7d0: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20 ", zName);. }.
d7e0: 20 69 66 28 20 7a 3d 3d 30 20 29 7b 0a 20 20 20 if( z==0 ){.
d7f0: 20 7a 20 3d 20 7a 44 65 66 61 75 6c 74 3b 0a 20 z = zDefault;.
d800: 20 7d 65 6c 73 65 20 69 66 28 20 7a 46 6f 72 6d }else if( zForm
d810: 61 74 21 3d 30 20 29 7b 0a 20 20 20 20 7a 20 3d at!=0 ){. z =
d820: 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c db_text(0, "SEL
d830: 45 43 54 20 73 74 72 66 74 69 6d 65 28 25 51 2c ECT strftime(%Q,
d840: 25 51 2c 27 75 6e 69 78 65 70 6f 63 68 27 29 3b %Q,'unixepoch');
d850: 22 2c 20 7a 46 6f 72 6d 61 74 2c 20 7a 29 3b 0a ", zFormat, z);.
d860: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a 3b 0a }. return z;.
d870: 7d 0a 76 6f 69 64 20 64 62 5f 73 65 74 28 63 6f }.void db_set(co
d880: 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c nst char *zName,
d890: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 const char *zVa
d8a0: 6c 75 65 2c 20 69 6e 74 20 67 6c 6f 62 61 6c 46 lue, int globalF
d8b0: 6c 61 67 29 7b 0a 20 20 64 62 5f 62 65 67 69 6e lag){. db_begin
d8c0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a _transaction();.
d8d0: 20 20 69 66 28 20 67 6c 6f 62 61 6c 46 6c 61 67 if( globalFlag
d8e0: 20 29 7b 0a 20 20 20 20 64 62 5f 73 77 61 70 5f ){. db_swap_
d8f0: 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 29 3b 0a 20 connections();.
d900: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 db_multi_exec
d910: 28 22 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 67 ("REPLACE INTO g
d920: 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 28 6e 61 6d lobal_config(nam
d930: 65 2c 76 61 6c 75 65 29 20 56 41 4c 55 45 53 28 e,value) VALUES(
d940: 25 51 2c 25 51 29 22 2c 0a 20 20 20 20 20 20 20 %Q,%Q)",.
d950: 20 20 20 20 20 20 20 20 20 20 20 20 7a 4e 61 6d zNam
d960: 65 2c 20 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 e, zValue);.
d970: 64 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 63 74 69 db_swap_connecti
d980: 6f 6e 73 28 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a ons();. }else{.
d990: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 db_multi_exe
d9a0: 63 28 22 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 c("REPLACE INTO
d9b0: 63 6f 6e 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 config(name,valu
d9c0: 65 2c 6d 74 69 6d 65 29 20 56 41 4c 55 45 53 28 e,mtime) VALUES(
d9d0: 25 51 2c 25 51 2c 6e 6f 77 28 29 29 22 2c 0a 20 %Q,%Q,now())",.
d9e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d9f0: 20 20 7a 4e 61 6d 65 2c 20 7a 56 61 6c 75 65 29 zName, zValue)
da00: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67 6c 6f 62 ;. }. if( glob
da10: 61 6c 46 6c 61 67 20 26 26 20 67 2e 72 65 70 6f alFlag && g.repo
da20: 73 69 74 6f 72 79 4f 70 65 6e 20 29 7b 0a 20 20 sitoryOpen ){.
da30: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
da40: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 63 6f 6e "DELETE FROM con
da50: 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 fig WHERE name=%
da60: 51 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a Q", zName);. }.
da70: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
da80: 74 69 6f 6e 28 30 29 3b 0a 7d 0a 76 6f 69 64 20 tion(0);.}.void
da90: 64 62 5f 75 6e 73 65 74 28 63 6f 6e 73 74 20 63 db_unset(const c
daa0: 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 69 6e 74 20 har *zName, int
dab0: 67 6c 6f 62 61 6c 46 6c 61 67 29 7b 0a 20 20 64 globalFlag){. d
dac0: 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 b_begin_transact
dad0: 69 6f 6e 28 29 3b 0a 20 20 69 66 28 20 67 6c 6f ion();. if( glo
dae0: 62 61 6c 46 6c 61 67 20 29 7b 0a 20 20 20 20 64 balFlag ){. d
daf0: 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 63 74 69 6f b_swap_connectio
db00: 6e 73 28 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c ns();. db_mul
db10: 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 ti_exec("DELETE
db20: 46 52 4f 4d 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 FROM global_conf
db30: 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 51 ig WHERE name=%Q
db40: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 64 ", zName);. d
db50: 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 63 74 69 6f b_swap_connectio
db60: 6e 73 28 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 ns();. }else{.
db70: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 db_multi_exec
db80: 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 63 6f ("DELETE FROM co
db90: 6e 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d nfig WHERE name=
dba0: 25 51 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d %Q", zName);. }
dbb0: 0a 20 20 69 66 28 20 67 6c 6f 62 61 6c 46 6c 61 . if( globalFla
dbc0: 67 20 26 26 20 67 2e 72 65 70 6f 73 69 74 6f 72 g && g.repositor
dbd0: 79 4f 70 65 6e 20 29 7b 0a 20 20 20 20 64 62 5f yOpen ){. db_
dbe0: 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 multi_exec("DELE
dbf0: 54 45 20 46 52 4f 4d 20 63 6f 6e 66 69 67 20 57 TE FROM config W
dc00: 48 45 52 45 20 6e 61 6d 65 3d 25 51 22 2c 20 7a HERE name=%Q", z
dc10: 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64 62 5f Name);. }. db_
dc20: 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 end_transaction(
dc30: 30 29 3b 0a 7d 0a 69 6e 74 20 64 62 5f 69 73 5f 0);.}.int db_is_
dc40: 67 6c 6f 62 61 6c 28 63 6f 6e 73 74 20 63 68 61 global(const cha
dc50: 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20 69 6e 74 r *zName){. int
dc60: 20 72 63 20 3d 20 30 3b 0a 20 20 69 66 28 20 67 rc = 0;. if( g
dc70: 2e 7a 43 6f 6e 66 69 67 44 62 4e 61 6d 65 20 29 .zConfigDbName )
dc80: 7b 0a 20 20 20 20 64 62 5f 73 77 61 70 5f 63 6f {. db_swap_co
dc90: 6e 6e 65 63 74 69 6f 6e 73 28 29 3b 0a 20 20 20 nnections();.
dca0: 20 72 63 20 3d 20 64 62 5f 65 78 69 73 74 73 28 rc = db_exists(
dcb0: 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 67 "SELECT 1 FROM g
dcc0: 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 20 57 48 45 lobal_config WHE
dcd0: 52 45 20 6e 61 6d 65 3d 25 51 22 2c 20 7a 4e 61 RE name=%Q", zNa
dce0: 6d 65 29 3b 0a 20 20 20 20 64 62 5f 73 77 61 70 me);. db_swap
dcf0: 5f 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 29 3b 0a _connections();.
dd00: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 72 63 3b }. return rc;
dd10: 0a 7d 0a 69 6e 74 20 64 62 5f 67 65 74 5f 69 6e .}.int db_get_in
dd20: 74 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e t(const char *zN
dd30: 61 6d 65 2c 20 69 6e 74 20 64 66 6c 74 29 7b 0a ame, int dflt){.
dd40: 20 20 69 6e 74 20 76 20 3d 20 64 66 6c 74 3b 0a int v = dflt;.
dd50: 20 20 69 6e 74 20 72 63 3b 0a 20 20 69 66 28 20 int rc;. if(
dd60: 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e g.repositoryOpen
dd70: 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a ){. Stmt q;.
dd80: 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 db_prepare(&
dd90: 71 2c 20 22 53 45 4c 45 43 54 20 76 61 6c 75 65 q, "SELECT value
dda0: 20 46 52 4f 4d 20 63 6f 6e 66 69 67 20 57 48 45 FROM config WHE
ddb0: 52 45 20 6e 61 6d 65 3d 25 51 22 2c 20 7a 4e 61 RE name=%Q", zNa
ddc0: 6d 65 29 3b 0a 20 20 20 20 72 63 20 3d 20 64 62 me);. rc = db
ddd0: 5f 73 74 65 70 28 26 71 29 3b 0a 20 20 20 20 69 _step(&q);. i
dde0: 66 28 20 72 63 3d 3d 53 51 4c 49 54 45 5f 52 4f f( rc==SQLITE_RO
ddf0: 57 20 29 7b 0a 20 20 20 20 20 20 76 20 3d 20 64 W ){. v = d
de00: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c b_column_int(&q,
de10: 20 30 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 0);. }. d
de20: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
de30: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63 20 }else{. rc
de40: 3d 20 53 51 4c 49 54 45 5f 44 4f 4e 45 3b 0a 20 = SQLITE_DONE;.
de50: 20 7d 0a 20 20 69 66 28 20 72 63 3d 3d 53 51 4c }. if( rc==SQL
de60: 49 54 45 5f 44 4f 4e 45 20 26 26 20 67 2e 7a 43 ITE_DONE && g.zC
de70: 6f 6e 66 69 67 44 62 4e 61 6d 65 20 29 7b 0a 20 onfigDbName ){.
de80: 20 20 20 64 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 db_swap_conne
de90: 63 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20 76 20 ctions();. v
dea0: 3d 20 64 62 5f 69 6e 74 28 64 66 6c 74 2c 20 22 = db_int(dflt, "
deb0: 53 45 4c 45 43 54 20 76 61 6c 75 65 20 46 52 4f SELECT value FRO
dec0: 4d 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 20 M global_config
ded0: 57 48 45 52 45 20 6e 61 6d 65 3d 25 51 22 2c 20 WHERE name=%Q",
dee0: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 64 62 5f 73 zName);. db_s
def0: 77 61 70 5f 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 wap_connections(
df00: 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 );. }. return
df10: 76 3b 0a 7d 0a 76 6f 69 64 20 64 62 5f 73 65 74 v;.}.void db_set
df20: 5f 69 6e 74 28 63 6f 6e 73 74 20 63 68 61 72 20 _int(const char
df30: 2a 7a 4e 61 6d 65 2c 20 69 6e 74 20 76 61 6c 75 *zName, int valu
df40: 65 2c 20 69 6e 74 20 67 6c 6f 62 61 6c 46 6c 61 e, int globalFla
df50: 67 29 7b 0a 20 20 69 66 28 20 67 6c 6f 62 61 6c g){. if( global
df60: 46 6c 61 67 20 29 7b 0a 20 20 20 20 64 62 5f 73 Flag ){. db_s
df70: 77 61 70 5f 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 wap_connections(
df80: 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f );. db_multi_
df90: 65 78 65 63 28 22 52 45 50 4c 41 43 45 20 49 4e exec("REPLACE IN
dfa0: 54 4f 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 TO global_config
dfb0: 28 6e 61 6d 65 2c 76 61 6c 75 65 29 20 56 41 4c (name,value) VAL
dfc0: 55 45 53 28 25 51 2c 25 64 29 22 2c 0a 20 20 20 UES(%Q,%d)",.
dfd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7a z
dfe0: 4e 61 6d 65 2c 20 76 61 6c 75 65 29 3b 0a 20 20 Name, value);.
dff0: 20 20 64 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 63 db_swap_connec
e000: 74 69 6f 6e 73 28 29 3b 0a 20 20 7d 65 6c 73 65 tions();. }else
e010: 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 {. db_multi_e
e020: 78 65 63 28 22 52 45 50 4c 41 43 45 20 49 4e 54 xec("REPLACE INT
e030: 4f 20 63 6f 6e 66 69 67 28 6e 61 6d 65 2c 76 61 O config(name,va
e040: 6c 75 65 2c 6d 74 69 6d 65 29 20 56 41 4c 55 45 lue,mtime) VALUE
e050: 53 28 25 51 2c 25 64 2c 6e 6f 77 28 29 29 22 2c S(%Q,%d,now())",
e060: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
e070: 20 20 20 7a 4e 61 6d 65 2c 20 76 61 6c 75 65 29 zName, value)
e080: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67 6c 6f 62 ;. }. if( glob
e090: 61 6c 46 6c 61 67 20 26 26 20 67 2e 72 65 70 6f alFlag && g.repo
e0a0: 73 69 74 6f 72 79 4f 70 65 6e 20 29 7b 0a 20 20 sitoryOpen ){.
e0b0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
e0c0: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 63 6f 6e "DELETE FROM con
e0d0: 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 fig WHERE name=%
e0e0: 51 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a Q", zName);. }.
e0f0: 7d 0a 69 6e 74 20 64 62 5f 67 65 74 5f 62 6f 6f }.int db_get_boo
e100: 6c 65 61 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 lean(const char
e110: 2a 7a 4e 61 6d 65 2c 20 69 6e 74 20 64 66 6c 74 *zName, int dflt
e120: 29 7b 0a 20 20 63 68 61 72 20 2a 7a 56 61 6c 20 ){. char *zVal
e130: 3d 20 64 62 5f 67 65 74 28 7a 4e 61 6d 65 2c 20 = db_get(zName,
e140: 64 66 6c 74 20 3f 20 22 6f 6e 22 20 3a 20 22 6f dflt ? "on" : "o
e150: 66 66 22 29 3b 0a 20 20 69 66 28 20 69 73 5f 74 ff");. if( is_t
e160: 72 75 74 68 28 7a 56 61 6c 29 20 29 20 72 65 74 ruth(zVal) ) ret
e170: 75 72 6e 20 31 3b 0a 20 20 69 66 28 20 69 73 5f urn 1;. if( is_
e180: 66 61 6c 73 65 28 7a 56 61 6c 29 20 29 20 72 65 false(zVal) ) re
e190: 74 75 72 6e 20 30 3b 0a 20 20 72 65 74 75 72 6e turn 0;. return
e1a0: 20 64 66 6c 74 3b 0a 7d 0a 63 68 61 72 20 2a 64 dflt;.}.char *d
e1b0: 62 5f 6c 67 65 74 28 63 6f 6e 73 74 20 63 68 61 b_lget(const cha
e1c0: 72 20 2a 7a 4e 61 6d 65 2c 20 63 68 61 72 20 2a r *zName, char *
e1d0: 7a 44 65 66 61 75 6c 74 29 7b 0a 20 20 72 65 74 zDefault){. ret
e1e0: 75 72 6e 20 64 62 5f 74 65 78 74 28 28 63 68 61 urn db_text((cha
e1f0: 72 2a 29 7a 44 65 66 61 75 6c 74 2c 0a 20 20 20 r*)zDefault,.
e200: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 53 "S
e210: 45 4c 45 43 54 20 76 61 6c 75 65 20 46 52 4f 4d ELECT value FROM
e220: 20 76 76 61 72 20 57 48 45 52 45 20 6e 61 6d 65 vvar WHERE name
e230: 3d 25 51 22 2c 20 7a 4e 61 6d 65 29 3b 0a 7d 0a =%Q", zName);.}.
e240: 76 6f 69 64 20 64 62 5f 6c 73 65 74 28 63 6f 6e void db_lset(con
e250: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 st char *zName,
e260: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c const char *zVal
e270: 75 65 29 7b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f ue){. db_multi_
e280: 65 78 65 63 28 22 52 45 50 4c 41 43 45 20 49 4e exec("REPLACE IN
e290: 54 4f 20 76 76 61 72 28 6e 61 6d 65 2c 76 61 6c TO vvar(name,val
e2a0: 75 65 29 20 56 41 4c 55 45 53 28 25 51 2c 25 51 ue) VALUES(%Q,%Q
e2b0: 29 22 2c 20 7a 4e 61 6d 65 2c 20 7a 56 61 6c 75 )", zName, zValu
e2c0: 65 29 3b 0a 7d 0a 69 6e 74 20 64 62 5f 6c 67 65 e);.}.int db_lge
e2d0: 74 5f 69 6e 74 28 63 6f 6e 73 74 20 63 68 61 72 t_int(const char
e2e0: 20 2a 7a 4e 61 6d 65 2c 20 69 6e 74 20 64 66 6c *zName, int dfl
e2f0: 74 29 7b 0a 20 20 72 65 74 75 72 6e 20 64 62 5f t){. return db_
e300: 69 6e 74 28 64 66 6c 74 2c 20 22 53 45 4c 45 43 int(dflt, "SELEC
e310: 54 20 76 61 6c 75 65 20 46 52 4f 4d 20 76 76 61 T value FROM vva
e320: 72 20 57 48 45 52 45 20 6e 61 6d 65 3d 25 51 22 r WHERE name=%Q"
e330: 2c 20 7a 4e 61 6d 65 29 3b 0a 7d 0a 76 6f 69 64 , zName);.}.void
e340: 20 64 62 5f 6c 73 65 74 5f 69 6e 74 28 63 6f 6e db_lset_int(con
e350: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 st char *zName,
e360: 69 6e 74 20 76 61 6c 75 65 29 7b 0a 20 20 64 62 int value){. db
e370: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 52 45 50 _multi_exec("REP
e380: 4c 41 43 45 20 49 4e 54 4f 20 76 76 61 72 28 6e LACE INTO vvar(n
e390: 61 6d 65 2c 76 61 6c 75 65 29 20 56 41 4c 55 45 ame,value) VALUE
e3a0: 53 28 25 51 2c 25 64 29 22 2c 20 7a 4e 61 6d 65 S(%Q,%d)", zName
e3b0: 2c 20 76 61 6c 75 65 29 3b 0a 7d 0a 0a 2f 2a 0a , value);.}../*.
e3c0: 2a 2a 20 52 65 74 75 72 6e 73 20 6e 6f 6e 2d 30 ** Returns non-0
e3d0: 20 69 66 20 74 68 65 20 64 61 74 61 62 61 73 65 if the database
e3e0: 20 28 77 68 69 63 68 20 6d 75 73 74 20 62 65 20 (which must be
e3f0: 6f 70 65 6e 29 20 74 61 62 6c 65 20 69 64 65 6e open) table iden
e400: 74 69 66 69 65 64 0a 2a 2a 20 62 79 20 7a 54 61 tified.** by zTa
e410: 62 6c 65 4e 61 6d 65 20 68 61 73 20 61 20 63 6f bleName has a co
e420: 6c 75 6d 6e 20 6e 61 6d 65 64 20 7a 43 6f 6c 4e lumn named zColN
e430: 61 6d 65 20 28 63 61 73 65 2d 73 65 6e 73 69 74 ame (case-sensit
e440: 69 76 65 29 2c 20 65 6c 73 65 0a 2a 2a 20 72 65 ive), else.** re
e450: 74 75 72 6e 73 20 30 2e 0a 2a 2f 0a 69 6e 74 20 turns 0..*/.int
e460: 64 62 5f 74 61 62 6c 65 5f 68 61 73 5f 63 6f 6c db_table_has_col
e470: 75 6d 6e 28 20 63 68 61 72 20 63 6f 6e 73 74 20 umn( char const
e480: 2a 7a 54 61 62 6c 65 4e 61 6d 65 2c 20 63 68 61 *zTableName, cha
e490: 72 20 63 6f 6e 73 74 20 2a 7a 43 6f 6c 4e 61 6d r const *zColNam
e4a0: 65 20 29 7b 0a 20 20 53 74 6d 74 20 71 20 3d 20 e ){. Stmt q =
e4b0: 65 6d 70 74 79 5f 53 74 6d 74 3b 0a 20 20 69 6e empty_Stmt;. in
e4c0: 74 20 72 63 20 3d 20 30 3b 0a 20 20 64 62 5f 70 t rc = 0;. db_p
e4d0: 72 65 70 61 72 65 28 20 26 71 2c 20 22 50 52 41 repare( &q, "PRA
e4e0: 47 4d 41 20 74 61 62 6c 65 5f 69 6e 66 6f 28 25 GMA table_info(%
e4f0: 51 29 22 2c 20 7a 54 61 62 6c 65 4e 61 6d 65 20 Q)", zTableName
e500: 29 3b 0a 20 20 77 68 69 6c 65 28 53 51 4c 49 54 );. while(SQLIT
e510: 45 5f 52 4f 57 20 3d 3d 20 64 62 5f 73 74 65 70 E_ROW == db_step
e520: 28 26 71 29 29 7b 0a 20 20 20 20 2f 2a 20 43 6f (&q)){. /* Co
e530: 6c 75 6d 6e 73 3a 20 28 63 69 64 2c 20 6e 61 6d lumns: (cid, nam
e540: 65 2c 20 74 79 70 65 2c 20 6e 6f 74 6e 75 6c 6c e, type, notnull
e550: 2c 20 64 66 6c 74 5f 76 61 6c 75 65 2c 20 70 6b , dflt_value, pk
e560: 29 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 63 6f ) */. char co
e570: 6e 73 74 20 2a 20 7a 43 6f 6c 20 3d 20 64 62 5f nst * zCol = db_
e580: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 column_text(&q,
e590: 31 29 3b 0a 20 20 20 20 69 66 28 30 3d 3d 66 6f 1);. if(0==fo
e5a0: 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a 43 6f 6c ssil_strcmp(zCol
e5b0: 4e 61 6d 65 2c 20 7a 43 6f 6c 29 29 7b 0a 20 20 Name, zCol)){.
e5c0: 20 20 20 20 72 63 20 3d 20 31 3b 0a 20 20 20 20 rc = 1;.
e5d0: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 break;. }.
e5e0: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
e5f0: 28 26 71 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 (&q);. return r
e600: 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 63 6f c;.}../*.** Reco
e610: 72 64 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 rd the name of a
e620: 20 6c 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f 72 local repositor
e630: 79 20 69 6e 20 74 68 65 20 67 6c 6f 62 61 6c 5f y in the global_
e640: 63 6f 6e 66 69 67 28 29 20 64 61 74 61 62 61 73 config() databas
e650: 65 2e 0a 2a 2a 20 54 68 65 20 72 65 70 6f 73 69 e..** The reposi
e660: 74 6f 72 79 20 66 69 6c 65 6e 61 6d 65 20 25 73 tory filename %s
e670: 20 69 73 20 72 65 63 6f 72 64 65 64 20 61 73 20 is recorded as
e680: 61 6e 20 65 6e 74 72 79 20 77 69 74 68 20 61 20 an entry with a
e690: 22 6e 61 6d 65 22 20 66 69 65 6c 64 0a 2a 2a 20 "name" field.**
e6a0: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
e6b0: 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 form:.**.**
e6c0: 20 20 20 72 65 70 6f 3a 25 73 0a 2a 2a 0a 2a 2a repo:%s.**.**
e6d0: 20 54 68 65 20 76 61 6c 75 65 20 66 69 65 6c 64 The value field
e6e0: 20 69 73 20 73 65 74 20 74 6f 20 31 2e 0a 2a 2a is set to 1..**
e6f0: 0a 2a 2a 20 49 66 20 72 75 6e 6e 69 6e 67 20 66 .** If running f
e700: 72 6f 6d 20 61 20 6c 6f 63 61 6c 20 63 68 65 63 rom a local chec
e710: 6b 6f 75 74 2c 20 61 6c 73 6f 20 72 65 63 6f 72 kout, also recor
e720: 64 20 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 d the root of th
e730: 65 20 63 68 65 63 6b 6f 75 74 0a 2a 2a 20 61 73 e checkout.** as
e740: 20 66 6f 6c 6c 6f 77 73 3a 0a 2a 2a 0a 2a 2a 20 follows:.**.**
e750: 20 20 20 20 20 20 63 6b 6f 75 74 3a 25 73 0a 2a ckout:%s.*
e760: 2a 0a 2a 2a 20 57 68 65 72 65 20 25 73 20 69 73 *.** Where %s is
e770: 20 74 68 65 20 63 68 65 63 6b 6f 75 74 20 72 6f the checkout ro
e780: 6f 74 2e 20 20 54 68 65 20 76 61 6c 75 65 20 69 ot. The value i
e790: 73 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 s the repository
e7a0: 20 66 69 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 64 file..*/.void d
e7b0: 62 5f 72 65 63 6f 72 64 5f 72 65 70 6f 73 69 74 b_record_reposit
e7c0: 6f 72 79 5f 66 69 6c 65 6e 61 6d 65 28 63 6f 6e ory_filename(con
e7d0: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 29 7b st char *zName){
e7e0: 0a 20 20 42 6c 6f 62 20 66 75 6c 6c 3b 0a 20 20 . Blob full;.
e7f0: 69 66 28 20 7a 4e 61 6d 65 3d 3d 30 20 29 7b 0a if( zName==0 ){.
e800: 20 20 20 20 69 66 28 20 21 67 2e 6c 6f 63 61 6c if( !g.local
e810: 4f 70 65 6e 20 29 20 72 65 74 75 72 6e 3b 0a 20 Open ) return;.
e820: 20 20 20 7a 4e 61 6d 65 20 3d 20 64 62 5f 72 65 zName = db_re
e830: 70 6f 73 69 74 6f 72 79 5f 66 69 6c 65 6e 61 6d pository_filenam
e840: 65 28 29 3b 0a 20 20 7d 0a 20 20 66 69 6c 65 5f e();. }. file_
e850: 63 61 6e 6f 6e 69 63 61 6c 5f 6e 61 6d 65 28 7a canonical_name(z
e860: 4e 61 6d 65 2c 20 26 66 75 6c 6c 2c 20 30 29 3b Name, &full, 0);
e870: 0a 20 20 64 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 . db_swap_conne
e880: 63 74 69 6f 6e 73 28 29 3b 0a 20 20 64 62 5f 6d ctions();. db_m
e890: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 ulti_exec(.
e8a0: 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 "INSERT OR IGNOR
e8b0: 45 20 49 4e 54 4f 20 67 6c 6f 62 61 6c 5f 63 6f E INTO global_co
e8c0: 6e 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 65 29 nfig(name,value)
e8d0: 22 0a 20 20 20 20 20 22 56 41 4c 55 45 53 28 27 ". "VALUES('
e8e0: 72 65 70 6f 3a 25 71 27 2c 31 29 22 2c 0a 20 20 repo:%q',1)",.
e8f0: 20 20 20 62 6c 6f 62 5f 73 74 72 28 26 66 75 6c blob_str(&ful
e900: 6c 29 0a 20 20 29 3b 0a 20 20 69 66 28 20 67 2e l). );. if( g.
e910: 6c 6f 63 61 6c 4f 70 65 6e 20 26 26 20 67 2e 7a localOpen && g.z
e920: 4c 6f 63 61 6c 52 6f 6f 74 20 26 26 20 67 2e 7a LocalRoot && g.z
e930: 4c 6f 63 61 6c 52 6f 6f 74 5b 30 5d 20 29 7b 0a LocalRoot[0] ){.
e940: 20 20 20 20 42 6c 6f 62 20 6c 6f 63 61 6c 52 6f Blob localRo
e950: 6f 74 3b 0a 20 20 20 20 66 69 6c 65 5f 63 61 6e ot;. file_can
e960: 6f 6e 69 63 61 6c 5f 6e 61 6d 65 28 67 2e 7a 4c onical_name(g.zL
e970: 6f 63 61 6c 52 6f 6f 74 2c 20 26 6c 6f 63 61 6c ocalRoot, &local
e980: 52 6f 6f 74 2c 20 31 29 3b 0a 20 20 20 20 64 62 Root, 1);. db
e990: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 _multi_exec(.
e9a0: 20 20 20 22 52 45 50 4c 41 43 45 20 49 4e 54 4f "REPLACE INTO
e9b0: 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 28 6e global_config(n
e9c0: 61 6d 65 2c 20 76 61 6c 75 65 29 22 0a 20 20 20 ame, value)".
e9d0: 20 20 20 22 56 41 4c 55 45 53 28 27 63 6b 6f 75 "VALUES('ckou
e9e0: 74 3a 25 71 27 2c 27 25 71 27 29 3b 22 2c 0a 20 t:%q','%q');",.
e9f0: 20 20 20 20 20 62 6c 6f 62 5f 73 74 72 28 26 6c blob_str(&l
ea00: 6f 63 61 6c 52 6f 6f 74 29 2c 20 62 6c 6f 62 5f ocalRoot), blob_
ea10: 73 74 72 28 26 66 75 6c 6c 29 0a 20 20 20 20 29 str(&full). )
ea20: 3b 0a 20 20 20 20 64 62 5f 73 77 61 70 5f 63 6f ;. db_swap_co
ea30: 6e 6e 65 63 74 69 6f 6e 73 28 29 3b 0a 20 20 20 nnections();.
ea40: 20 64 62 5f 6f 70 74 69 6f 6e 61 6c 5f 73 71 6c db_optional_sql
ea50: 28 22 72 65 70 6f 73 69 74 6f 72 79 22 2c 0a 20 ("repository",.
ea60: 20 20 20 20 20 20 20 22 52 45 50 4c 41 43 45 20 "REPLACE
ea70: 49 4e 54 4f 20 63 6f 6e 66 69 67 28 6e 61 6d 65 INTO config(name
ea80: 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 29 22 0a 20 ,value,mtime)".
ea90: 20 20 20 20 20 20 20 22 56 41 4c 55 45 53 28 27 "VALUES('
eaa0: 63 6b 6f 75 74 3a 25 71 27 2c 31 2c 6e 6f 77 28 ckout:%q',1,now(
eab0: 29 29 22 2c 0a 20 20 20 20 20 20 20 20 62 6c 6f ))",. blo
eac0: 62 5f 73 74 72 28 26 6c 6f 63 61 6c 52 6f 6f 74 b_str(&localRoot
ead0: 29 0a 20 20 20 20 29 3b 0a 20 20 20 20 62 6c 6f ). );. blo
eae0: 62 5f 72 65 73 65 74 28 26 6c 6f 63 61 6c 52 6f b_reset(&localRo
eaf0: 6f 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 ot);. }else{.
eb00: 20 20 64 62 5f 73 77 61 70 5f 63 6f 6e 6e 65 63 db_swap_connec
eb10: 74 69 6f 6e 73 28 29 3b 0a 20 20 7d 0a 20 20 62 tions();. }. b
eb20: 6c 6f 62 5f 72 65 73 65 74 28 26 66 75 6c 6c 29 lob_reset(&full)
eb30: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 ;.}../*.** COMMA
eb40: 4e 44 3a 20 6f 70 65 6e 0a 2a 2a 0a 2a 2a 20 55 ND: open.**.** U
eb50: 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 6f 70 sage: %fossil op
eb60: 65 6e 20 46 49 4c 45 4e 41 4d 45 20 3f 56 45 52 en FILENAME ?VER
eb70: 53 49 4f 4e 3f 20 3f 4f 50 54 49 4f 4e 53 3f 0a SION? ?OPTIONS?.
eb80: 2a 2a 0a 2a 2a 20 4f 70 65 6e 20 61 20 63 6f 6e **.** Open a con
eb90: 6e 65 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 6c nection to the l
eba0: 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f 72 79 20 ocal repository
ebb0: 69 6e 20 46 49 4c 45 4e 41 4d 45 2e 20 20 41 20 in FILENAME. A
ebc0: 63 68 65 63 6b 6f 75 74 0a 2a 2a 20 66 6f 72 20 checkout.** for
ebd0: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 69 the repository i
ebe0: 73 20 63 72 65 61 74 65 64 20 77 69 74 68 20 69 s created with i
ebf0: 74 73 20 72 6f 6f 74 20 61 74 20 74 68 65 20 77 ts root at the w
ec00: 6f 72 6b 69 6e 67 20 64 69 72 65 63 74 6f 72 79 orking directory
ec10: 2e 0a 2a 2a 20 49 66 20 56 45 52 53 49 4f 4e 20 ..** If VERSION
ec20: 69 73 20 73 70 65 63 69 66 69 65 64 20 74 68 65 is specified the
ec30: 6e 20 74 68 61 74 20 76 65 72 73 69 6f 6e 20 69 n that version i
ec40: 73 20 63 68 65 63 6b 65 64 20 6f 75 74 2e 20 20 s checked out.
ec50: 4f 74 68 65 72 77 69 73 65 0a 2a 2a 20 74 68 65 Otherwise.** the
ec60: 20 6c 61 74 65 73 74 20 76 65 72 73 69 6f 6e 20 latest version
ec70: 69 73 20 63 68 65 63 6b 65 64 20 6f 75 74 2e 20 is checked out.
ec80: 20 4e 6f 20 66 69 6c 65 73 20 6f 74 68 65 72 20 No files other
ec90: 74 68 61 6e 20 22 6d 61 6e 69 66 65 73 74 22 0a than "manifest".
eca0: 2a 2a 20 61 6e 64 20 22 6d 61 6e 69 66 65 73 74 ** and "manifest
ecb0: 2e 75 75 69 64 22 20 61 72 65 20 6d 6f 64 69 66 .uuid" are modif
ecc0: 69 65 64 20 69 66 20 74 68 65 20 2d 2d 6b 65 65 ied if the --kee
ecd0: 70 20 6f 70 74 69 6f 6e 20 69 73 20 70 72 65 73 p option is pres
ece0: 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74 69 6f ent..**.** Optio
ecf0: 6e 73 3a 0a 2a 2a 20 20 20 2d 2d 65 6d 70 74 79 ns:.** --empty
ed00: 20 20 20 20 49 6e 69 74 69 61 6c 69 7a 65 20 63 Initialize c
ed10: 68 65 63 6b 6f 75 74 20 61 73 20 62 65 69 6e 67 heckout as being
ed20: 20 65 6d 70 74 79 2c 20 62 75 74 20 73 74 69 6c empty, but stil
ed30: 6c 20 63 6f 6e 6e 65 63 74 65 64 0a 2a 2a 20 20 l connected.**
ed40: 20 20 20 20 20 20 20 20 20 20 20 20 77 69 74 68 with
ed50: 20 74 68 65 20 6c 6f 63 61 6c 20 72 65 70 6f 73 the local repos
ed60: 69 74 6f 72 79 2e 20 49 66 20 79 6f 75 20 63 6f itory. If you co
ed70: 6d 6d 69 74 20 74 68 69 73 20 63 68 65 63 6b 6f mmit this checko
ed80: 75 74 2c 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ut,.**
ed90: 20 20 20 20 69 74 20 77 69 6c 6c 20 62 65 63 6f it will beco
eda0: 6d 65 20 61 20 6e 65 77 20 22 69 6e 69 74 69 61 me a new "initia
edb0: 6c 22 20 63 6f 6d 6d 69 74 20 69 6e 20 74 68 65 l" commit in the
edc0: 20 72 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 20 repository..**
edd0: 20 20 2d 2d 6b 65 65 70 20 20 20 20 20 4f 6e 6c --keep Onl
ede0: 79 20 6d 6f 64 69 66 79 20 74 68 65 20 6d 61 6e y modify the man
edf0: 69 66 65 73 74 20 61 6e 64 20 6d 61 6e 69 66 65 ifest and manife
ee00: 73 74 2e 75 75 69 64 20 66 69 6c 65 73 0a 2a 2a st.uuid files.**
ee10: 20 20 20 2d 2d 6e 65 73 74 65 64 20 20 20 41 6c --nested Al
ee20: 6c 6f 77 20 6f 70 65 6e 69 6e 67 20 61 20 72 65 low opening a re
ee30: 70 6f 73 69 74 6f 72 79 20 69 6e 73 69 64 65 20 pository inside
ee40: 61 6e 20 6f 70 65 6e 65 64 20 63 68 65 63 6b 6f an opened checko
ee50: 75 74 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 ut.**.** See als
ee60: 6f 3a 20 63 6c 6f 73 65 0a 2a 2f 0a 76 6f 69 64 o: close.*/.void
ee70: 20 63 6d 64 5f 6f 70 65 6e 28 76 6f 69 64 29 7b cmd_open(void){
ee80: 0a 20 20 69 6e 74 20 65 6d 70 74 79 46 6c 61 67 . int emptyFlag
ee90: 3b 0a 20 20 69 6e 74 20 6b 65 65 70 46 6c 61 67 ;. int keepFlag
eea0: 3b 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 4e 65 73 ;. int allowNes
eeb0: 74 65 64 3b 0a 20 20 63 68 61 72 20 2a 2a 6f 6c ted;. char **ol
eec0: 64 41 72 67 76 3b 0a 20 20 69 6e 74 20 6f 6c 64 dArgv;. int old
eed0: 41 72 67 63 3b 0a 20 20 73 74 61 74 69 63 20 63 Argc;. static c
eee0: 68 61 72 20 2a 61 7a 4e 65 77 41 72 67 76 5b 5d har *azNewArgv[]
eef0: 20 3d 20 7b 20 30 2c 20 22 63 68 65 63 6b 6f 75 = { 0, "checkou
ef00: 74 22 2c 20 22 2d 2d 70 72 6f 6d 70 74 22 2c 20 t", "--prompt",
ef10: 30 2c 20 30 2c 20 30 20 7d 3b 0a 0a 20 20 75 72 0, 0, 0 };.. ur
ef20: 6c 5f 70 72 6f 78 79 5f 6f 70 74 69 6f 6e 73 28 l_proxy_options(
ef30: 29 3b 0a 20 20 65 6d 70 74 79 46 6c 61 67 20 3d );. emptyFlag =
ef40: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 65 6d find_option("em
ef50: 70 74 79 22 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 pty",0,0)!=0;.
ef60: 6b 65 65 70 46 6c 61 67 20 3d 20 66 69 6e 64 5f keepFlag = find_
ef70: 6f 70 74 69 6f 6e 28 22 6b 65 65 70 22 2c 30 2c option("keep",0,
ef80: 30 29 21 3d 30 3b 0a 20 20 61 6c 6c 6f 77 4e 65 0)!=0;. allowNe
ef90: 73 74 65 64 20 3d 20 66 69 6e 64 5f 6f 70 74 69 sted = find_opti
efa0: 6f 6e 28 22 6e 65 73 74 65 64 22 2c 30 2c 30 29 on("nested",0,0)
efb0: 21 3d 30 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 !=0;. if( g.arg
efc0: 63 21 3d 33 20 26 26 20 67 2e 61 72 67 63 21 3d c!=3 && g.argc!=
efd0: 34 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 4 ){. usage("
efe0: 52 45 50 4f 53 49 54 4f 52 59 2d 46 49 4c 45 4e REPOSITORY-FILEN
eff0: 41 4d 45 20 3f 56 45 52 53 49 4f 4e 3f 22 29 3b AME ?VERSION?");
f000: 0a 20 20 7d 0a 20 20 69 66 28 20 21 61 6c 6c 6f . }. if( !allo
f010: 77 4e 65 73 74 65 64 20 26 26 20 64 62 5f 6f 70 wNested && db_op
f020: 65 6e 5f 6c 6f 63 61 6c 28 30 29 20 29 7b 0a 20 en_local(0) ){.
f030: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 fossil_fatal(
f040: 22 61 6c 72 65 61 64 79 20 77 69 74 68 69 6e 20 "already within
f050: 61 6e 20 6f 70 65 6e 20 74 72 65 65 20 72 6f 6f an open tree roo
f060: 74 65 64 20 61 74 20 25 73 22 2c 20 67 2e 7a 4c ted at %s", g.zL
f070: 6f 63 61 6c 52 6f 6f 74 29 3b 0a 20 20 7d 0a 20 ocalRoot);. }.
f080: 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 db_open_reposit
f090: 6f 72 79 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a ory(g.argv[2]);.
f0a0: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e #if defined(_WIN
f0b0: 33 32 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 32) || defined(_
f0c0: 5f 43 59 47 57 49 4e 5f 5f 29 0a 23 20 64 65 66 _CYGWIN__).# def
f0d0: 69 6e 65 20 4c 4f 43 41 4c 44 42 5f 4e 41 4d 45 ine LOCALDB_NAME
f0e0: 20 22 2e 2f 5f 46 4f 53 53 49 4c 5f 22 0a 23 65 "./_FOSSIL_".#e
f0f0: 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 4c 4f 43 lse.# define LOC
f100: 41 4c 44 42 5f 4e 41 4d 45 20 22 2e 2f 2e 66 73 ALDB_NAME "./.fs
f110: 6c 63 6b 6f 75 74 22 0a 23 65 6e 64 69 66 0a 20 lckout".#endif.
f120: 20 64 62 5f 69 6e 69 74 5f 64 61 74 61 62 61 73 db_init_databas
f130: 65 28 4c 4f 43 41 4c 44 42 5f 4e 41 4d 45 2c 20 e(LOCALDB_NAME,
f140: 7a 4c 6f 63 61 6c 53 63 68 65 6d 61 2c 0a 23 69 zLocalSchema,.#i
f150: 66 64 65 66 20 46 4f 53 53 49 4c 5f 4c 4f 43 41 fdef FOSSIL_LOCA
f160: 4c 5f 57 41 4c 0a 20 20 20 20 20 20 20 20 20 20 L_WAL.
f170: 20 20 20 20 20 20 20 20 20 22 43 4f 4d 4d 49 54 "COMMIT
f180: 3b 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e 61 6c ; PRAGMA journal
f190: 5f 6d 6f 64 65 3d 57 41 4c 3b 20 42 45 47 49 4e _mode=WAL; BEGIN
f1a0: 3b 22 2c 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 ;",.#endif.
f1b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 63 (c
f1c0: 68 61 72 2a 29 30 29 3b 0a 20 20 64 62 5f 64 65 har*)0);. db_de
f1d0: 6c 65 74 65 5f 6f 6e 5f 66 61 69 6c 75 72 65 28 lete_on_failure(
f1e0: 4c 4f 43 41 4c 44 42 5f 4e 41 4d 45 29 3b 0a 20 LOCALDB_NAME);.
f1f0: 20 64 62 5f 6f 70 65 6e 5f 6c 6f 63 61 6c 28 30 db_open_local(0
f200: 29 3b 0a 20 20 64 62 5f 6c 73 65 74 28 22 72 65 );. db_lset("re
f210: 70 6f 73 69 74 6f 72 79 22 2c 20 67 2e 61 72 67 pository", g.arg
f220: 76 5b 32 5d 29 3b 0a 20 20 64 62 5f 72 65 63 6f v[2]);. db_reco
f230: 72 64 5f 72 65 70 6f 73 69 74 6f 72 79 5f 66 69 rd_repository_fi
f240: 6c 65 6e 61 6d 65 28 67 2e 61 72 67 76 5b 32 5d lename(g.argv[2]
f250: 29 3b 0a 20 20 64 62 5f 6c 73 65 74 5f 69 6e 74 );. db_lset_int
f260: 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b ("checkout", 0);
f270: 0a 20 20 6f 6c 64 41 72 67 76 20 3d 20 67 2e 61 . oldArgv = g.a
f280: 72 67 76 3b 0a 20 20 6f 6c 64 41 72 67 63 20 3d rgv;. oldArgc =
f290: 20 67 2e 61 72 67 63 3b 0a 20 20 61 7a 4e 65 77 g.argc;. azNew
f2a0: 41 72 67 76 5b 30 5d 20 3d 20 67 2e 61 72 67 76 Argv[0] = g.argv
f2b0: 5b 30 5d 3b 0a 20 20 67 2e 61 72 67 76 20 3d 20 [0];. g.argv =
f2c0: 61 7a 4e 65 77 41 72 67 76 3b 0a 20 20 69 66 28 azNewArgv;. if(
f2d0: 20 21 65 6d 70 74 79 46 6c 61 67 29 7b 0a 20 20 !emptyFlag){.
f2e0: 20 20 67 2e 61 72 67 63 20 3d 20 33 3b 0a 20 20 g.argc = 3;.
f2f0: 20 20 69 66 28 20 6f 6c 64 41 72 67 63 3d 3d 34 if( oldArgc==4
f300: 20 29 7b 0a 20 20 20 20 20 20 61 7a 4e 65 77 41 ){. azNewA
f310: 72 67 76 5b 67 2e 61 72 67 63 2d 31 5d 20 3d 20 rgv[g.argc-1] =
f320: 6f 6c 64 41 72 67 76 5b 33 5d 3b 0a 20 20 20 20 oldArgv[3];.
f330: 7d 65 6c 73 65 20 69 66 28 20 21 64 62 5f 65 78 }else if( !db_ex
f340: 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20 46 ists("SELECT 1 F
f350: 52 4f 4d 20 65 76 65 6e 74 20 57 48 45 52 45 20 ROM event WHERE
f360: 74 79 70 65 3d 27 63 69 27 22 29 20 29 7b 0a 20 type='ci'") ){.
f370: 20 20 20 20 20 61 7a 4e 65 77 41 72 67 76 5b 67 azNewArgv[g
f380: 2e 61 72 67 63 2d 31 5d 20 3d 20 22 2d 2d 6c 61 .argc-1] = "--la
f390: 74 65 73 74 22 3b 0a 20 20 20 20 7d 65 6c 73 65 test";. }else
f3a0: 7b 0a 20 20 20 20 20 20 61 7a 4e 65 77 41 72 67 {. azNewArg
f3b0: 76 5b 67 2e 61 72 67 63 2d 31 5d 20 3d 20 64 62 v[g.argc-1] = db
f3c0: 5f 67 65 74 28 22 6d 61 69 6e 2d 62 72 61 6e 63 _get("main-branc
f3d0: 68 22 2c 20 22 74 72 75 6e 6b 22 29 3b 0a 20 20 h", "trunk");.
f3e0: 20 20 7d 0a 20 20 20 20 69 66 28 20 6b 65 65 70 }. if( keep
f3f0: 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 61 7a Flag ){. az
f400: 4e 65 77 41 72 67 76 5b 67 2e 61 72 67 63 2b 2b NewArgv[g.argc++
f410: 5d 20 3d 20 22 2d 2d 6b 65 65 70 22 3b 0a 20 20 ] = "--keep";.
f420: 20 20 7d 0a 20 20 20 20 63 68 65 63 6b 6f 75 74 }. checkout
f430: 5f 63 6d 64 28 29 3b 0a 20 20 7d 0a 20 20 67 2e _cmd();. }. g.
f440: 61 72 67 63 20 3d 20 32 3b 0a 20 20 69 6e 66 6f argc = 2;. info
f450: 5f 63 6d 64 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a _cmd();.}../*.**
f460: 20 50 72 69 6e 74 20 74 68 65 20 76 61 6c 75 65 Print the value
f470: 20 6f 66 20 61 20 73 65 74 74 69 6e 67 20 6e 61 of a setting na
f480: 6d 65 64 20 7a 4e 61 6d 65 0a 2a 2f 0a 73 74 61 med zName.*/.sta
f490: 74 69 63 20 76 6f 69 64 20 70 72 69 6e 74 5f 73 tic void print_s
f4a0: 65 74 74 69 6e 67 28 0a 20 20 63 6f 6e 73 74 20 etting(. const
f4b0: 73 74 72 75 63 74 20 73 74 43 6f 6e 74 72 6f 6c struct stControl
f4c0: 53 65 74 74 69 6e 67 73 20 2a 63 74 72 6c 53 65 Settings *ctrlSe
f4d0: 74 74 69 6e 67 2c 0a 20 20 69 6e 74 20 6c 6f 63 tting,. int loc
f4e0: 61 6c 4f 70 65 6e 0a 29 7b 0a 20 20 53 74 6d 74 alOpen.){. Stmt
f4f0: 20 71 3b 0a 20 20 69 66 28 20 67 2e 72 65 70 6f q;. if( g.repo
f500: 73 69 74 6f 72 79 4f 70 65 6e 20 29 7b 0a 20 20 sitoryOpen ){.
f510: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c db_prepare(&q,
f520: 0a 20 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 . "SELECT
f530: 27 28 6c 6f 63 61 6c 29 27 2c 20 76 61 6c 75 65 '(local)', value
f540: 20 46 52 4f 4d 20 63 6f 6e 66 69 67 20 57 48 45 FROM config WHE
f550: 52 45 20 6e 61 6d 65 3d 25 51 22 0a 20 20 20 20 RE name=%Q".
f560: 20 20 20 22 20 55 4e 49 4f 4e 20 41 4c 4c 20 22 " UNION ALL "
f570: 0a 20 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 . "SELECT
f580: 27 28 67 6c 6f 62 61 6c 29 27 2c 20 76 61 6c 75 '(global)', valu
f590: 65 20 46 52 4f 4d 20 67 6c 6f 62 61 6c 5f 63 6f e FROM global_co
f5a0: 6e 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d nfig WHERE name=
f5b0: 25 51 22 2c 0a 20 20 20 20 20 20 20 63 74 72 6c %Q",. ctrl
f5c0: 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 2c 20 63 Setting->name, c
f5d0: 74 72 6c 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 trlSetting->name
f5e0: 0a 20 20 20 20 29 3b 0a 20 20 7d 65 6c 73 65 7b . );. }else{
f5f0: 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 . db_prepare(
f600: 26 71 2c 0a 20 20 20 20 20 20 22 53 45 4c 45 43 &q,. "SELEC
f610: 54 20 27 28 67 6c 6f 62 61 6c 29 27 2c 20 76 61 T '(global)', va
f620: 6c 75 65 20 46 52 4f 4d 20 67 6c 6f 62 61 6c 5f lue FROM global_
f630: 63 6f 6e 66 69 67 20 57 48 45 52 45 20 6e 61 6d config WHERE nam
f640: 65 3d 25 51 22 2c 0a 20 20 20 20 20 20 63 74 72 e=%Q",. ctr
f650: 6c 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 0a 20 lSetting->name.
f660: 20 20 20 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 );. }. if(
f670: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c db_step(&q)==SQL
f680: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 66 ITE_ROW ){. f
f690: 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 25 2d 32 ossil_print("%-2
f6a0: 30 73 20 25 2d 38 73 20 25 73 5c 6e 22 2c 20 63 0s %-8s %s\n", c
f6b0: 74 72 6c 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 trlSetting->name
f6c0: 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 , db_column_text
f6d0: 28 26 71 2c 20 30 29 2c 0a 20 20 20 20 20 20 20 (&q, 0),.
f6e0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
f6f0: 26 71 2c 20 31 29 29 3b 0a 20 20 7d 65 6c 73 65 &q, 1));. }else
f700: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 {. fossil_pri
f710: 6e 74 28 22 25 2d 32 30 73 5c 6e 22 2c 20 63 74 nt("%-20s\n", ct
f720: 72 6c 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 29 rlSetting->name)
f730: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 63 74 72 6c ;. }. if( ctrl
f740: 53 65 74 74 69 6e 67 2d 3e 76 65 72 73 69 6f 6e Setting->version
f750: 61 62 6c 65 20 26 26 20 6c 6f 63 61 6c 4f 70 65 able && localOpe
f760: 6e 20 29 7b 0a 20 20 20 20 2f 2a 20 43 68 65 63 n ){. /* Chec
f770: 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68 69 73 k to see if this
f780: 20 69 73 20 6f 76 65 72 72 69 64 64 65 6e 20 62 is overridden b
f790: 79 20 61 20 76 65 72 73 69 6f 6e 61 62 6c 65 20 y a versionable
f7a0: 73 65 74 74 69 6e 67 73 20 66 69 6c 65 20 2a 2f settings file */
f7b0: 0a 20 20 20 20 42 6c 6f 62 20 76 65 72 73 69 6f . Blob versio
f7c0: 6e 65 64 50 61 74 68 6e 61 6d 65 3b 0a 20 20 20 nedPathname;.
f7d0: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 76 65 72 73 blob_zero(&vers
f7e0: 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 29 3b 0a ionedPathname);.
f7f0: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
f800: 28 26 76 65 72 73 69 6f 6e 65 64 50 61 74 68 6e (&versionedPathn
f810: 61 6d 65 2c 20 22 25 73 2f 2e 66 6f 73 73 69 6c ame, "%s/.fossil
f820: 2d 73 65 74 74 69 6e 67 73 2f 25 73 22 2c 0a 20 -settings/%s",.
f830: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f840: 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20 63 74 g.zLocalRoot, ct
f850: 72 6c 53 65 74 74 69 6e 67 2d 3e 6e 61 6d 65 29 rlSetting->name)
f860: 3b 0a 20 20 20 20 69 66 28 20 66 69 6c 65 5f 73 ;. if( file_s
f870: 69 7a 65 28 62 6c 6f 62 5f 73 74 72 28 26 76 65 ize(blob_str(&ve
f880: 72 73 69 6f 6e 65 64 50 61 74 68 6e 61 6d 65 29 rsionedPathname)
f890: 29 3e 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f )>=0 ){. fo
f8a0: 73 73 69 6c 5f 70 72 69 6e 74 28 22 20 20 28 6f ssil_print(" (o
f8b0: 76 65 72 72 69 64 64 65 6e 20 62 79 20 63 6f 6e verridden by con
f8c0: 74 65 6e 74 73 20 6f 66 20 66 69 6c 65 20 2e 66 tents of file .f
f8d0: 6f 73 73 69 6c 2d 73 65 74 74 69 6e 67 73 2f 25 ossil-settings/%
f8e0: 73 29 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 s)\n",.
f8f0: 20 20 20 20 20 20 20 20 20 20 63 74 72 6c 53 65 ctrlSe
f900: 74 74 69 6e 67 2d 3e 6e 61 6d 65 29 3b 0a 20 20 tting->name);.
f910: 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e }. }. db_fin
f920: 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 0a 2f alize(&q);.}.../
f930: 2a 0a 2a 2a 20 64 65 66 69 6e 65 20 61 6c 6c 20 *.** define all
f940: 73 65 74 74 69 6e 67 73 2c 20 77 68 69 63 68 20 settings, which
f950: 63 61 6e 20 62 65 20 63 6f 6e 74 72 6f 6c 6c 65 can be controlle
f960: 64 20 76 69 61 20 74 68 65 20 73 65 74 2f 75 6e d via the set/un
f970: 73 65 74 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 2e 20 set.** command.
f980: 76 61 72 20 69 73 20 74 68 65 20 6e 61 6d 65 20 var is the name
f990: 6f 66 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 of the internal
f9a0: 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 6e 61 configuration na
f9b0: 6d 65 20 66 6f 72 20 64 62 5f 28 75 6e 29 73 65 me for db_(un)se
f9c0: 74 2e 0a 2a 2a 20 49 66 20 76 61 72 20 69 73 20 t..** If var is
f9d0: 30 2c 20 74 68 65 20 73 65 74 74 69 6e 67 73 20 0, the settings
f9e0: 6e 61 6d 65 20 69 73 20 75 73 65 64 2e 0a 2a 2a name is used..**
f9f0: 20 77 69 64 74 68 20 69 73 20 74 68 65 20 6c 65 width is the le
fa00: 6e 67 74 68 20 66 6f 72 20 74 68 65 20 65 64 69 ngth for the edi
fa10: 74 20 66 69 65 6c 64 20 6f 6e 20 74 68 65 20 62 t field on the b
fa20: 65 68 61 76 69 6f 72 20 70 61 67 65 2c 20 30 0a ehavior page, 0.
fa30: 2a 2a 20 69 73 20 75 73 65 64 20 66 6f 72 20 6f ** is used for o
fa40: 6e 2f 6f 66 66 20 63 68 65 63 6b 62 6f 78 65 73 n/off checkboxes
fa50: 2e 0a 2a 2a 20 54 68 65 20 62 65 68 61 76 69 6f ..** The behavio
fa60: 75 72 20 70 61 67 65 20 64 6f 65 73 6e 27 74 20 ur page doesn't
fa70: 75 73 65 20 61 20 73 70 65 63 69 61 6c 20 6c 61 use a special la
fa80: 79 6f 75 74 2e 20 49 74 20 6c 69 73 74 73 20 61 yout. It lists a
fa90: 6c 6c 0a 2a 2a 20 73 65 74 2d 63 6f 6d 6d 61 6e ll.** set-comman
faa0: 64 73 20 61 6e 64 20 64 69 73 70 6c 61 79 73 20 ds and displays
fab0: 74 68 65 20 27 73 65 74 27 2d 68 65 6c 70 20 61 the 'set'-help a
fac0: 73 20 69 6e 66 6f 2e 0a 2a 2f 0a 23 69 66 20 49 s info..*/.#if I
fad0: 4e 54 45 52 46 41 43 45 0a 73 74 72 75 63 74 20 NTERFACE.struct
fae0: 73 74 43 6f 6e 74 72 6f 6c 53 65 74 74 69 6e 67 stControlSetting
faf0: 73 20 7b 0a 20 20 63 68 61 72 20 63 6f 6e 73 74 s {. char const
fb00: 20 2a 6e 61 6d 65 3b 20 20 20 20 20 2f 2a 20 4e *name; /* N
fb10: 61 6d 65 20 6f 66 20 74 68 65 20 73 65 74 74 69 ame of the setti
fb20: 6e 67 20 2a 2f 0a 20 20 63 68 61 72 20 63 6f 6e ng */. char con
fb30: 73 74 20 2a 76 61 72 3b 20 20 20 20 20 20 2f 2a st *var; /*
fb40: 20 49 6e 74 65 72 6e 61 6c 20 76 61 72 69 61 62 Internal variab
fb50: 6c 65 20 6e 61 6d 65 20 75 73 65 64 20 62 79 20 le name used by
fb60: 64 62 5f 73 65 74 28 29 20 2a 2f 0a 20 20 69 6e db_set() */. in
fb70: 74 20 77 69 64 74 68 3b 20 20 20 20 20 20 20 20 t width;
fb80: 20 20 20 20 2f 2a 20 57 69 64 74 68 20 6f 66 20 /* Width of
fb90: 64 69 73 70 6c 61 79 2e 20 20 30 20 66 6f 72 20 display. 0 for
fba0: 62 6f 6f 6c 65 61 6e 20 76 61 6c 75 65 73 2e 20 boolean values.
fbb0: 2a 2f 0a 20 20 69 6e 74 20 76 65 72 73 69 6f 6e */. int version
fbc0: 61 62 6c 65 3b 20 20 20 20 20 20 2f 2a 20 49 73 able; /* Is
fbd0: 20 74 68 69 73 20 73 65 74 74 69 6e 67 20 76 65 this setting ve
fbe0: 72 73 69 6f 6e 61 62 6c 65 3f 20 2a 2f 0a 20 20 rsionable? */.
fbf0: 69 6e 74 20 66 6f 72 63 65 54 65 78 74 41 72 65 int forceTextAre
fc00: 61 3b 20 20 20 20 2f 2a 20 46 6f 72 63 65 20 75 a; /* Force u
fc10: 73 69 6e 67 20 61 20 74 65 78 74 20 61 72 65 61 sing a text area
fc20: 20 66 6f 72 20 64 69 73 70 6c 61 79 3f 20 2a 2f for display? */
fc30: 0a 20 20 63 68 61 72 20 63 6f 6e 73 74 20 2a 64 . char const *d
fc40: 65 66 3b 20 20 20 20 20 20 2f 2a 20 44 65 66 61 ef; /* Defa
fc50: 75 6c 74 20 76 61 6c 75 65 20 2a 2f 0a 7d 3b 0a ult value */.};.
fc60: 23 65 6e 64 69 66 20 2f 2a 20 49 4e 54 45 52 46 #endif /* INTERF
fc70: 41 43 45 20 2a 2f 0a 73 74 72 75 63 74 20 73 74 ACE */.struct st
fc80: 43 6f 6e 74 72 6f 6c 53 65 74 74 69 6e 67 73 20 ControlSettings
fc90: 63 6f 6e 73 74 20 63 74 72 6c 53 65 74 74 69 6e const ctrlSettin
fca0: 67 73 5b 5d 20 3d 20 7b 0a 20 20 7b 20 22 61 63 gs[] = {. { "ac
fcb0: 63 65 73 73 2d 6c 6f 67 22 2c 20 20 20 20 20 20 cess-log",
fcc0: 20 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 0,
fcd0: 20 30 2c 20 30 2c 20 30 2c 20 22 6f 66 66 22 20 0, 0, 0, "off"
fce0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fcf0: 7d 2c 0a 20 20 7b 20 22 61 6c 6c 6f 77 2d 73 79 },. { "allow-sy
fd00: 6d 6c 69 6e 6b 73 22 2c 20 20 20 30 2c 20 20 20 mlinks", 0,
fd10: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 31 2c 0, 1,
fd20: 20 30 2c 20 22 6f 66 66 22 20 20 20 20 20 20 20 0, "off"
fd30: 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b },. {
fd40: 20 22 61 75 74 6f 2d 63 61 70 74 63 68 61 22 2c "auto-captcha",
fd50: 20 20 20 20 20 22 61 75 74 6f 63 61 70 74 63 68 "autocaptch
fd60: 61 22 2c 20 20 30 2c 20 30 2c 20 30 2c 20 22 6f a", 0, 0, 0, "o
fd70: 6e 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n"
fd80: 20 20 20 20 7d 2c 0a 20 20 7b 20 22 61 75 74 6f },. { "auto
fd90: 2d 68 79 70 65 72 6c 69 6e 6b 22 2c 20 20 20 30 -hyperlink", 0
fda0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
fdb0: 2c 20 30 2c 20 30 2c 20 22 6f 6e 22 2c 20 20 20 , 0, 0, "on",
fdc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c },
fdd0: 0a 20 20 7b 20 22 61 75 74 6f 2d 73 68 75 6e 22 . { "auto-shun"
fde0: 2c 20 20 20 20 20 20 20 20 30 2c 20 20 20 20 20 , 0,
fdf0: 20 20 20 20 20 20 20 20 20 30 2c 20 30 2c 20 30 0, 0, 0
fe00: 2c 20 22 6f 6e 22 20 20 20 20 20 20 20 20 20 20 , "on"
fe10: 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 },. { "
fe20: 61 75 74 6f 73 79 6e 63 22 2c 20 20 20 20 20 20 autosync",
fe30: 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 20 0,
fe40: 20 20 20 30 2c 20 30 2c 20 30 2c 20 22 6f 6e 22 0, 0, 0, "on"
fe50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fe60: 20 20 7d 2c 0a 20 20 7b 20 22 62 69 6e 61 72 79 },. { "binary
fe70: 2d 67 6c 6f 62 22 2c 20 20 20 20 20 20 30 2c 20 -glob", 0,
fe80: 20 20 20 20 20 20 20 20 20 20 20 20 34 30 2c 20 40,
fe90: 31 2c 20 30 2c 20 22 22 20 20 20 20 20 20 20 20 1, 0, ""
fea0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 },.
feb0: 20 7b 20 22 63 6c 65 61 72 73 69 67 6e 22 2c 20 { "clearsign",
fec0: 20 20 20 20 20 20 20 30 2c 20 20 20 20 20 20 20 0,
fed0: 20 20 20 20 20 20 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0,
fee0: 22 6f 66 66 22 20 20 20 20 20 20 20 20 20 20 20 "off"
fef0: 20 20 20 20 20 20 7d 2c 0a 23 69 66 20 64 65 66 },.#if def
ff00: 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 7c 7c 20 ined(_WIN32) ||
ff10: 64 65 66 69 6e 65 64 28 5f 5f 43 59 47 57 49 4e defined(__CYGWIN
ff20: 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f __) || defined(_
ff30: 5f 44 41 52 57 49 4e 5f 5f 29 20 7c 7c 20 5c 0a _DARWIN__) || \.
ff40: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 41 50 defined(__AP
ff50: 50 4c 45 5f 5f 29 0a 20 20 7b 20 22 63 61 73 65 PLE__). { "case
ff60: 2d 73 65 6e 73 69 74 69 76 65 22 2c 20 20 20 30 -sensitive", 0
ff70: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
ff80: 2c 20 30 2c 20 30 2c 20 22 6f 66 66 22 20 20 20 , 0, 0, "off"
ff90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c },
ffa0: 0a 23 65 6c 73 65 0a 20 20 7b 20 22 63 61 73 65 .#else. { "case
ffb0: 2d 73 65 6e 73 69 74 69 76 65 22 2c 20 20 20 30 -sensitive", 0
ffc0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
ffd0: 2c 20 30 2c 20 30 2c 20 22 6f 6e 22 20 20 20 20 , 0, 0, "on"
ffe0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c },
fff0: 0a 23 65 6e 64 69 66 0a 20 20 7b 20 22 63 6c 65 .#endif. { "cle
10000 61 6e 2d 67 6c 6f 62 22 2c 20 20 20 20 20 20 20 an-glob",
10010 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 34 0, 4
10020 30 2c 20 31 2c 20 30 2c 20 22 22 20 20 20 20 20 0, 1, 0, ""
10030 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
10040 2c 0a 20 20 7b 20 22 63 72 6e 6c 2d 67 6c 6f 62 ,. { "crnl-glob
10050 22 2c 20 20 20 20 20 20 20 20 30 2c 20 20 20 20 ", 0,
10060 20 20 20 20 20 20 20 20 20 34 30 2c 20 31 2c 20 40, 1,
10070 30 2c 20 22 22 20 20 20 20 20 20 20 20 20 20 20 0, ""
10080 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 },. {
10090 22 64 65 66 61 75 6c 74 2d 70 65 72 6d 73 22 2c "default-perms",
100a0 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 0,
100b0 20 20 20 31 36 2c 20 30 2c 20 30 2c 20 22 75 22 16, 0, 0, "u"
100c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
100d0 20 20 20 7d 2c 0a 20 20 7b 20 22 64 69 66 66 2d },. { "diff-
100e0 62 69 6e 61 72 79 22 2c 20 20 20 20 20 20 30 2c binary", 0,
100f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 0,
10100 20 30 2c 20 30 2c 20 22 6f 6e 22 20 20 20 20 20 0, 0, "on"
10110 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a },.
10120 20 20 7b 20 22 64 69 66 66 2d 63 6f 6d 6d 61 6e { "diff-comman
10130 64 22 2c 20 20 20 20 20 30 2c 20 20 20 20 20 20 d", 0,
10140 20 20 20 20 20 20 20 34 30 2c 20 30 2c 20 30 2c 40, 0, 0,
10150 20 22 22 20 20 20 20 20 20 20 20 20 20 20 20 20 ""
10160 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 64 },. { "d
10170 6f 6e 74 2d 70 75 73 68 22 2c 20 20 20 20 20 20 ont-push",
10180 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 0,
10190 20 20 30 2c 20 30 2c 20 30 2c 20 22 6f 66 66 22 0, 0, 0, "off"
101a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
101b0 20 7d 2c 0a 20 20 7b 20 22 65 64 69 74 6f 72 22 },. { "editor"
101c0 2c 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 20 , 0,
101d0 20 20 20 20 20 20 20 20 20 20 20 33 32 2c 20 30 32, 0
101e0 2c 20 30 2c 20 22 22 20 20 20 20 20 20 20 20 20 , 0, ""
101f0 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 },.
10200 7b 20 22 65 6d 70 74 79 2d 64 69 72 73 22 2c 20 { "empty-dirs",
10210 20 20 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 0,
10220 20 20 20 20 20 34 30 2c 20 31 2c 20 30 2c 20 22 40, 1, 0, "
10230 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
10240 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 65 6e 63 },. { "enc
10250 6f 64 69 6e 67 2d 67 6c 6f 62 22 2c 20 20 20 20 oding-glob",
10260 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 34 0, 4
10270 30 2c 20 31 2c 20 30 2c 20 22 22 20 20 20 20 20 0, 1, 0, ""
10280 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
10290 2c 0a 20 20 7b 20 22 67 64 69 66 66 2d 63 6f 6d ,. { "gdiff-com
102a0 6d 61 6e 64 22 2c 20 20 20 20 30 2c 20 20 20 20 mand", 0,
102b0 20 20 20 20 20 20 20 20 20 34 30 2c 20 30 2c 20 40, 0,
102c0 30 2c 20 22 67 64 69 66 66 22 20 20 20 20 20 20 0, "gdiff"
102d0 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 },. {
102e0 22 67 6d 65 72 67 65 2d 63 6f 6d 6d 61 6e 64 22 "gmerge-command"
102f0 2c 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 , 0,
10300 20 20 20 34 30 2c 20 30 2c 20 30 2c 20 22 22 20 40, 0, 0, ""
10310 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10320 20 20 20 7d 2c 0a 20 20 7b 20 22 68 74 74 70 2d },. { "http-
10330 70 6f 72 74 22 2c 20 20 20 20 20 20 20 20 30 2c port", 0,
10340 20 20 20 20 20 20 20 20 20 20 20 20 20 31 36 2c 16,
10350 20 30 2c 20 30 2c 20 22 38 30 38 30 22 20 20 20 0, 0, "8080"
10360 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a },.
10370 20 20 7b 20 22 68 74 74 70 73 2d 6c 6f 67 69 6e { "https-login
10380 22 2c 20 20 20 20 20 20 30 2c 20 20 20 20 20 20 ", 0,
10390 20 20 20 20 20 20 20 20 30 2c 20 30 2c 20 30 2c 0, 0, 0,
103a0 20 22 6f 66 66 22 20 20 20 20 20 20 20 20 20 20 "off"
103b0 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 69 },. { "i
103c0 67 6e 6f 72 65 2d 67 6c 6f 62 22 2c 20 20 20 20 gnore-glob",
103d0 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 0,
103e0 20 34 30 2c 20 31 2c 20 30 2c 20 22 22 20 20 20 40, 1, 0, ""
103f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10400 20 7d 2c 0a 20 20 7b 20 22 6b 65 65 70 2d 67 6c },. { "keep-gl
10410 6f 62 22 2c 20 20 20 20 20 20 20 20 30 2c 20 20 ob", 0,
10420 20 20 20 20 20 20 20 20 20 20 20 34 30 2c 20 31 40, 1
10430 2c 20 30 2c 20 22 22 20 20 20 20 20 20 20 20 20 , 0, ""
10440 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 },.
10450 7b 20 22 6c 6f 63 61 6c 61 75 74 68 22 2c 20 20 { "localauth",
10460 20 20 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 0,
10470 20 20 20 20 20 20 30 2c 20 30 2c 20 30 2c 20 22 0, 0, 0, "
10480 6f 66 66 22 20 20 20 20 20 20 20 20 20 20 20 20 off"
10490 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 6d 61 69 },. { "mai
104a0 6e 2d 62 72 61 6e 63 68 22 2c 20 20 20 20 20 20 n-branch",
104b0 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 34 0, 4
104c0 30 2c 20 30 2c 20 30 2c 20 22 74 72 75 6e 6b 22 0, 0, 0, "trunk"
104d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
104e0 2c 0a 20 20 7b 20 22 6d 61 6e 69 66 65 73 74 22 ,. { "manifest"
104f0 2c 20 20 20 20 20 20 20 20 20 30 2c 20 20 20 20 , 0,
10500 20 20 20 20 20 20 20 20 20 20 30 2c 20 31 2c 20 0, 1,
10510 30 2c 20 22 6f 66 66 22 20 20 20 20 20 20 20 20 0, "off"
10520 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 },. {
10530 22 6d 61 78 2d 6c 6f 61 64 61 76 67 22 2c 20 20 "max-loadavg",
10540 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 0,
10550 20 20 20 32 35 2c 20 30 2c 20 30 2c 20 22 30 2e 25, 0, 0, "0.
10560 30 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0"
10570 20 20 20 7d 2c 0a 20 20 7b 20 22 6d 61 78 2d 75 },. { "max-u
10580 70 6c 6f 61 64 22 2c 20 20 20 20 20 20 20 30 2c pload", 0,
10590 20 20 20 20 20 20 20 20 20 20 20 20 20 32 35 2c 25,
105a0 20 30 2c 20 30 2c 20 22 32 35 30 30 30 30 22 20 0, 0, "250000"
105b0 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a },.
105c0 20 20 7b 20 22 6d 74 69 6d 65 2d 63 68 61 6e 67 { "mtime-chang
105d0 65 73 22 2c 20 20 20 20 30 2c 20 20 20 20 20 20 es", 0,
105e0 20 20 20 20 20 20 20 20 30 2c 20 30 2c 20 30 2c 0, 0, 0,
105f0 20 22 6f 6e 22 20 20 20 20 20 20 20 20 20 20 20 "on"
10600 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 70 },. { "p
10610 67 70 2d 63 6f 6d 6d 61 6e 64 22 2c 20 20 20 20 gp-command",
10620 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 0,
10630 20 34 30 2c 20 30 2c 20 30 2c 20 22 67 70 67 20 40, 0, 0, "gpg
10640 2d 2d 63 6c 65 61 72 73 69 67 6e 20 2d 6f 20 22 --clearsign -o "
10650 20 7d 2c 0a 20 20 7b 20 22 70 72 6f 78 79 22 2c },. { "proxy",
10660 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 20 0,
10670 20 20 20 20 20 20 20 20 20 20 20 33 32 2c 20 30 32, 0
10680 2c 20 30 2c 20 22 6f 66 66 22 20 20 20 20 20 20 , 0, "off"
10690 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 },.
106a0 7b 20 22 72 65 6c 61 74 69 76 65 2d 70 61 74 68 { "relative-path
106b0 73 22 2c 20 20 20 30 2c 20 20 20 20 20 20 20 20 s", 0,
106c0 20 20 20 20 20 20 30 2c 20 30 2c 20 30 2c 20 22 0, 0, 0, "
106d0 6f 6e 22 20 20 20 20 20 20 20 20 20 20 20 20 20 on"
106e0 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 72 65 70 },. { "rep
106f0 6f 2d 63 6b 73 75 6d 22 2c 20 20 20 20 20 20 20 o-cksum",
10700 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0,
10710 30 2c 20 30 2c 20 30 2c 20 22 6f 6e 22 20 20 20 0, 0, 0, "on"
10720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
10730 2c 0a 20 20 7b 20 22 73 65 6c 66 2d 72 65 67 69 ,. { "self-regi
10740 73 74 65 72 22 2c 20 20 20 20 30 2c 20 20 20 20 ster", 0,
10750 20 20 20 20 20 20 20 20 20 20 30 2c 20 30 2c 20 0, 0,
10760 30 2c 20 22 6f 66 66 22 20 20 20 20 20 20 20 20 0, "off"
10770 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 },. {
10780 22 73 73 68 2d 63 6f 6d 6d 61 6e 64 22 2c 20 20 "ssh-command",
10790 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 20 0,
107a0 20 20 20 34 30 2c 20 30 2c 20 30 2c 20 22 22 20 40, 0, 0, ""
107b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
107c0 20 20 20 7d 2c 0a 20 20 7b 20 22 73 73 6c 2d 63 },. { "ssl-c
107d0 61 2d 6c 6f 63 61 74 69 6f 6e 22 2c 20 20 30 2c a-location", 0,
107e0 20 20 20 20 20 20 20 20 20 20 20 20 20 34 30 2c 40,
107f0 20 30 2c 20 30 2c 20 22 22 20 20 20 20 20 20 20 0, 0, ""
10800 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 2c 0a },.
10810 20 20 7b 20 22 73 73 6c 2d 69 64 65 6e 74 69 74 { "ssl-identit
10820 79 22 2c 20 20 20 20 20 30 2c 20 20 20 20 20 20 y", 0,
10830 20 20 20 20 20 20 20 34 30 2c 20 30 2c 20 30 2c 40, 0, 0,
10840 20 22 22 20 20 20 20 20 20 20 20 20 20 20 20 20 ""
10850 20 20 20 20 20 20 20 7d 2c 0a 23 69 66 64 65 66 },.#ifdef
10860 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 FOSSIL_ENABLE_T
10870 43 4c 0a 20 20 7b 20 22 74 63 6c 22 2c 20 20 20 CL. { "tcl",
10880 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 20 20 0,
10890 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 30 2c 0, 0,
108a0 20 30 2c 20 22 6f 66 66 22 20 20 20 20 20 20 20 0, "off"
108b0 20 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b },. {
108c0 20 22 74 63 6c 2d 73 65 74 75 70 22 2c 20 20 20 "tcl-setup",
108d0 20 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 20 0,
108e0 20 20 20 20 34 30 2c 20 30 2c 20 31 2c 20 22 22 40, 0, 1, ""
108f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10900 20 20 20 20 7d 2c 0a 23 65 6e 64 69 66 0a 20 20 },.#endif.
10910 7b 20 22 74 68 31 2d 73 65 74 75 70 22 2c 20 20 { "th1-setup",
10920 20 20 20 20 20 20 30 2c 20 20 20 20 20 20 20 20 0,
10930 20 20 20 20 20 34 30 2c 20 30 2c 20 31 2c 20 22 40, 0, 1, "
10940 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
10950 20 20 20 20 20 7d 2c 0a 20 20 7b 20 22 74 68 31 },. { "th1
10960 2d 75 72 69 2d 72 65 67 65 78 70 22 2c 20 20 20 -uri-regexp",
10970 30 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 34 0, 4
10980 30 2c 20 30 2c 20 30 2c 20 22 22 20 20 20 20 20 0, 0, 0, ""
10990 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
109a0 2c 0a 20 20 7b 20 22 77 65 62 2d 62 72 6f 77 73 ,. { "web-brows
109b0 65 72 22 2c 20 20 20 20 20 20 30 2c 20 20 20 20 er", 0,
109c0 20 20 20 20 20 20 20 20 20 33 32 2c 20 30 2c 20 32, 0,
109d0 30 2c 20 22 22 20 20 20 20 20 20 20 20 20 20 20 0, ""
109e0 20 20 20 20 20 20 20 20 20 7d 2c 0a 20 20 7b 20 },. {
109f0 22 77 68 69 74 65 2d 66 6f 72 65 67 72 6f 75 6e "white-foregroun
10a00 64 22 2c 20 30 2c 20 20 20 20 20 20 20 20 20 20 d", 0,
10a10 20 20 20 20 30 2c 20 30 2c 20 30 2c 20 22 6f 66 0, 0, 0, "of
10a20 66 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 f"
10a30 20 20 20 7d 2c 0a 20 20 7b 20 30 2c 30 2c 30 2c },. { 0,0,0,
10a40 30 2c 30 2c 30 20 7d 0a 7d 3b 0a 0a 2f 2a 0a 2a 0,0,0 }.};../*.*
10a50 2a 20 43 4f 4d 4d 41 4e 44 3a 20 73 65 74 74 69 * COMMAND: setti
10a60 6e 67 73 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 ngs.** COMMAND:
10a70 75 6e 73 65 74 2a 0a 2a 2a 0a 2a 2a 20 25 66 6f unset*.**.** %fo
10a80 73 73 69 6c 20 73 65 74 74 69 6e 67 73 20 3f 50 ssil settings ?P
10a90 52 4f 50 45 52 54 59 3f 20 3f 56 41 4c 55 45 3f ROPERTY? ?VALUE?
10aa0 20 3f 4f 50 54 49 4f 4e 53 3f 0a 2a 2a 20 25 66 ?OPTIONS?.** %f
10ab0 6f 73 73 69 6c 20 75 6e 73 65 74 20 50 52 4f 50 ossil unset PROP
10ac0 45 52 54 59 20 3f 4f 50 54 49 4f 4e 53 3f 0a 2a ERTY ?OPTIONS?.*
10ad0 2a 0a 2a 2a 20 54 68 65 20 22 73 65 74 74 69 6e *.** The "settin
10ae0 67 73 22 20 63 6f 6d 6d 61 6e 64 20 77 69 74 68 gs" command with
10af0 20 6e 6f 20 61 72 67 75 6d 65 6e 74 73 20 6c 69 no arguments li
10b00 73 74 73 20 61 6c 6c 20 70 72 6f 70 65 72 74 69 sts all properti
10b10 65 73 20 61 6e 64 20 74 68 65 69 72 0a 2a 2a 20 es and their.**
10b20 76 61 6c 75 65 73 2e 20 20 57 69 74 68 20 6a 75 values. With ju
10b30 73 74 20 61 20 70 72 6f 70 65 72 74 79 20 6e 61 st a property na
10b40 6d 65 20 69 74 20 73 68 6f 77 73 20 74 68 65 20 me it shows the
10b50 76 61 6c 75 65 20 6f 66 20 74 68 61 74 20 70 72 value of that pr
10b60 6f 70 65 72 74 79 2e 0a 2a 2a 20 57 69 74 68 20 operty..** With
10b70 61 20 76 61 6c 75 65 20 61 72 67 75 6d 65 6e 74 a value argument
10b80 20 69 74 20 63 68 61 6e 67 65 73 20 74 68 65 20 it changes the
10b90 70 72 6f 70 65 72 74 79 20 66 6f 72 20 74 68 65 property for the
10ba0 20 63 75 72 72 65 6e 74 20 72 65 70 6f 73 69 74 current reposit
10bb0 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 53 65 74 74 69 ory..**.** Setti
10bc0 6e 67 73 20 6d 61 72 6b 65 64 20 61 73 20 76 65 ngs marked as ve
10bd0 72 73 69 6f 6e 61 62 6c 65 20 61 72 65 20 6f 76 rsionable are ov
10be0 65 72 72 69 64 64 65 6e 20 62 79 20 74 68 65 20 erridden by the
10bf0 63 6f 6e 74 65 6e 74 73 20 6f 66 20 74 68 65 0a contents of the.
10c00 2a 2a 20 66 69 6c 65 20 6e 61 6d 65 64 20 2e 66 ** file named .f
10c10 6f 73 73 69 6c 2d 73 65 74 74 69 6e 67 73 2f 50 ossil-settings/P
10c20 52 4f 50 45 52 54 59 20 69 6e 20 74 68 65 20 63 ROPERTY in the c
10c30 68 65 63 6b 65 64 20 6f 75 74 20 66 69 6c 65 73 hecked out files
10c40 2c 20 69 66 20 74 68 61 74 0a 2a 2a 20 66 69 6c , if that.** fil
10c50 65 20 65 78 69 73 74 73 2e 0a 2a 2a 0a 2a 2a 20 e exists..**.**
10c60 54 68 65 20 22 75 6e 73 65 74 22 20 63 6f 6d 6d The "unset" comm
10c70 61 6e 64 20 63 6c 65 61 72 73 20 61 20 70 72 6f and clears a pro
10c80 70 65 72 74 79 20 73 65 74 74 69 6e 67 2e 0a 2a perty setting..*
10c90 2a 0a 2a 2a 0a 2a 2a 20 20 20 20 61 63 63 65 73 *.**.** acces
10ca0 73 2d 6c 6f 67 20 20 20 20 20 20 20 49 66 20 65 s-log If e
10cb0 6e 61 62 6c 65 64 2c 20 72 65 63 6f 72 64 20 73 nabled, record s
10cc0 75 63 63 65 73 73 66 75 6c 20 61 6e 64 20 66 61 uccessful and fa
10cd0 69 6c 65 64 20 6c 6f 67 69 6e 20 61 74 74 65 6d iled login attem
10ce0 70 74 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 pts.**
10cf0 20 20 20 20 20 20 20 20 20 20 20 69 6e 20 74 68 in th
10d00 65 20 22 61 63 63 65 73 73 6c 6f 67 22 20 74 61 e "accesslog" ta
10d10 62 6c 65 2e 20 20 44 65 66 61 75 6c 74 3a 20 6f ble. Default: o
10d20 66 66 0a 2a 2a 0a 2a 2a 20 20 20 20 61 6c 6c 6f ff.**.** allo
10d30 77 2d 73 79 6d 6c 69 6e 6b 73 20 20 20 49 66 20 w-symlinks If
10d40 65 6e 61 62 6c 65 64 2c 20 64 6f 6e 27 74 20 66 enabled, don't f
10d50 6f 6c 6c 6f 77 20 73 79 6d 6c 69 6e 6b 73 2c 20 ollow symlinks,
10d60 61 6e 64 20 69 6e 73 74 65 61 64 20 74 72 65 61 and instead trea
10d70 74 0a 2a 2a 20 20 20 20 20 28 76 65 72 73 69 6f t.** (versio
10d80 6e 61 62 6c 65 29 20 20 20 74 68 65 6d 20 61 73 nable) them as
10d90 20 73 79 6d 6c 69 6e 6b 73 20 6f 6e 20 55 6e 69 symlinks on Uni
10da0 78 2e 20 48 61 73 20 6e 6f 20 65 66 66 65 63 74 x. Has no effect
10db0 20 6f 6e 20 57 69 6e 64 6f 77 73 0a 2a 2a 20 20 on Windows.**
10dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10dd0 20 20 20 28 65 78 69 73 74 69 6e 67 20 6c 69 6e (existing lin
10de0 6b 73 20 69 6e 20 72 65 70 6f 73 69 74 6f 72 79 ks in repository
10df0 20 63 72 65 61 74 65 64 20 6f 6e 20 55 6e 69 78 created on Unix
10e00 20 62 65 63 6f 6d 65 0a 2a 2a 20 20 20 20 20 20 become.**
10e10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 70 p
10e20 6c 61 69 6e 2d 74 65 78 74 20 66 69 6c 65 73 20 lain-text files
10e30 77 69 74 68 20 6c 69 6e 6b 20 64 65 73 74 69 6e with link destin
10e40 61 74 69 6f 6e 20 70 61 74 68 20 69 6e 73 69 64 ation path insid
10e50 65 29 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 e)..**
10e60 20 20 20 20 20 20 20 20 20 20 20 44 65 66 61 75 Defau
10e70 6c 74 3a 20 6f 66 66 0a 2a 2a 0a 2a 2a 20 20 20 lt: off.**.**
10e80 20 61 75 74 6f 2d 63 61 70 74 63 68 61 20 20 20 auto-captcha
10e90 20 20 49 66 20 65 6e 61 62 6c 65 64 2c 20 74 68 If enabled, th
10ea0 65 20 4c 6f 67 69 6e 20 70 61 67 65 20 70 72 6f e Login page pro
10eb0 76 69 64 65 73 20 61 20 62 75 74 74 6f 6e 20 74 vides a button t
10ec0 6f 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 o.**
10ed0 20 20 20 20 20 20 20 20 20 66 69 6c 6c 20 69 6e fill in
10ee0 20 74 68 65 20 63 61 70 74 63 68 61 20 70 61 73 the captcha pas
10ef0 73 77 6f 72 64 2e 20 20 44 65 66 61 75 6c 74 3a sword. Default:
10f00 20 6f 6e 0a 2a 2a 0a 2a 2a 20 20 20 20 61 75 74 on.**.** aut
10f10 6f 2d 68 79 70 65 72 6c 69 6e 6b 20 20 20 55 73 o-hyperlink Us
10f20 65 20 6a 61 76 61 73 63 72 69 70 74 20 74 6f 20 e javascript to
10f30 65 6e 61 62 6c 65 20 68 79 70 65 72 6c 69 6e 6b enable hyperlink
10f40 73 20 6f 6e 20 77 65 62 20 70 61 67 65 73 0a 2a s on web pages.*
10f50 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
10f60 20 20 20 20 20 20 66 6f 72 20 61 6c 6c 20 75 73 for all us
10f70 65 72 73 20 28 72 65 67 61 72 64 6c 65 73 73 20 ers (regardless
10f80 6f 66 20 74 68 65 20 22 68 22 20 70 72 69 76 69 of the "h" privi
10f90 6c 65 67 65 29 20 69 66 20 74 68 65 0a 2a 2a 20 lege) if the.**
10fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10fb0 20 20 20 20 55 73 65 72 2d 41 67 65 6e 74 20 73 User-Agent s
10fc0 74 72 69 6e 67 20 69 6e 20 74 68 65 20 48 54 54 tring in the HTT
10fd0 50 20 68 65 61 64 65 72 20 6c 6f 6f 6b 20 6c 69 P header look li
10fe0 6b 65 20 69 74 20 63 61 6d 65 0a 2a 2a 20 20 20 ke it came.**
10ff0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11000 20 20 66 72 6f 6d 20 72 65 61 6c 20 70 65 72 73 from real pers
11010 6f 6e 2c 20 6e 6f 74 20 61 20 73 70 69 64 65 72 on, not a spider
11020 20 6f 72 20 62 6f 74 2e 20 20 44 65 66 61 75 6c or bot. Defaul
11030 74 3a 20 6f 6e 0a 2a 2a 0a 2a 2a 20 20 20 20 61 t: on.**.** a
11040 75 74 6f 2d 73 68 75 6e 20 20 20 20 20 20 20 20 uto-shun
11050 49 66 20 65 6e 61 62 6c 65 64 2c 20 61 75 74 6f If enabled, auto
11060 6d 61 74 69 63 61 6c 6c 79 20 70 75 6c 6c 20 74 matically pull t
11070 68 65 20 73 68 75 6e 6e 69 6e 67 20 6c 69 73 74 he shunning list
11080 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11090 20 20 20 20 20 20 20 20 66 72 6f 6d 20 61 20 73 from a s
110a0 65 72 76 65 72 20 74 6f 20 77 68 69 63 68 20 74 erver to which t
110b0 68 65 20 63 6c 69 65 6e 74 20 61 75 74 6f 73 79 he client autosy
110c0 6e 63 73 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 ncs..**
110d0 20 20 20 20 20 20 20 20 20 20 20 20 44 65 66 61 Defa
110e0 75 6c 74 3a 20 6f 6e 0a 2a 2a 0a 2a 2a 20 20 20 ult: on.**.**
110f0 20 61 75 74 6f 73 79 6e 63 20 20 20 20 20 20 20 autosync
11100 20 20 49 66 20 65 6e 61 62 6c 65 64 2c 20 61 75 If enabled, au
11110 74 6f 6d 61 74 69 63 61 6c 6c 79 20 70 75 6c 6c tomatically pull
11120 20 70 72 69 6f 72 20 74 6f 20 63 6f 6d 6d 69 74 prior to commit
11130 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11140 20 20 20 20 20 20 20 20 6f 72 20 75 70 64 61 74 or updat
11150 65 20 61 6e 64 20 61 75 74 6f 6d 61 74 69 63 61 e and automatica
11160 6c 6c 79 20 70 75 73 68 20 61 66 74 65 72 20 63 lly push after c
11170 6f 6d 6d 69 74 20 6f 72 0a 2a 2a 20 20 20 20 20 ommit or.**
11180 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11190 74 61 67 20 6f 72 20 62 72 61 6e 63 68 20 63 72 tag or branch cr
111a0 65 61 74 69 6f 6e 2e 20 20 49 66 20 74 68 65 20 eation. If the
111b0 76 61 6c 75 65 20 69 73 20 22 70 75 6c 6c 6f 6e value is "pullon
111c0 6c 79 22 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ly".**
111d0 20 20 20 20 20 20 20 20 20 20 20 74 68 65 6e 20 then
111e0 6f 6e 6c 79 20 70 75 6c 6c 20 6f 70 65 72 61 74 only pull operat
111f0 69 6f 6e 73 20 6f 63 63 75 72 20 61 75 74 6f 6d ions occur autom
11200 61 74 69 63 61 6c 6c 79 2e 0a 2a 2a 20 20 20 20 atically..**
11210 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11220 20 44 65 66 61 75 6c 74 3a 20 6f 6e 0a 2a 2a 0a Default: on.**.
11230 2a 2a 20 20 20 20 62 69 6e 61 72 79 2d 67 6c 6f ** binary-glo
11240 62 20 20 20 20 20 20 54 68 65 20 56 41 4c 55 45 b The VALUE
11250 20 69 73 20 61 20 63 6f 6d 6d 61 20 6f 72 20 6e is a comma or n
11260 65 77 6c 69 6e 65 2d 73 65 70 61 72 61 74 65 64 ewline-separated
11270 20 6c 69 73 74 20 6f 66 0a 2a 2a 20 20 20 20 20 list of.**
11280 28 76 65 72 73 69 6f 6e 61 62 6c 65 29 20 20 20 (versionable)
11290 47 4c 4f 42 20 70 61 74 74 65 72 6e 73 20 74 68 GLOB patterns th
112a0 61 74 20 73 68 6f 75 6c 64 20 62 65 20 74 72 65 at should be tre
112b0 61 74 65 64 20 61 73 20 62 69 6e 61 72 79 20 66 ated as binary f
112c0 69 6c 65 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 iles.**
112d0 20 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 20 for
112e0 63 6f 6d 6d 69 74 74 69 6e 67 20 61 6e 64 20 6d committing and m
112f0 65 72 67 69 6e 67 20 70 75 72 70 6f 73 65 73 2e erging purposes.
11300 20 20 45 78 61 6d 70 6c 65 3a 20 2a 2e 6a 70 67 Example: *.jpg
11310 0a 2a 2a 0a 2a 2a 20 20 20 20 63 61 73 65 2d 73 .**.** case-s
11320 65 6e 73 69 74 69 76 65 20 20 20 49 66 20 54 52 ensitive If TR
11330 55 45 2c 20 74 68 65 20 66 69 6c 65 73 20 77 68 UE, the files wh
11340 6f 73 65 20 6e 61 6d 65 73 20 64 69 66 66 65 72 ose names differ
11350 20 6f 6e 6c 79 20 69 6e 20 63 61 73 65 0a 2a 2a only in case.**
11360 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11370 20 20 20 20 20 61 72 65 20 63 6f 6e 73 69 64 65 are conside
11380 72 65 64 20 64 69 73 74 69 6e 63 74 2e 20 20 49 red distinct. I
11390 66 20 46 41 4c 53 45 20 66 69 6c 65 73 20 77 68 f FALSE files wh
113a0 6f 73 65 20 6e 61 6d 65 73 0a 2a 2a 20 20 20 20 ose names.**
113b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
113c0 20 64 69 66 66 65 72 20 6f 6e 6c 79 20 69 6e 20 differ only in
113d0 63 61 73 65 20 61 72 65 20 74 68 65 20 73 61 6d case are the sam
113e0 65 20 66 69 6c 65 2e 20 20 44 65 66 61 75 6c 74 e file. Default
113f0 73 20 74 6f 0a 2a 2a 20 20 20 20 20 20 20 20 20 s to.**
11400 20 20 20 20 20 20 20 20 20 20 20 20 54 52 55 45 TRUE
11410 20 66 6f 72 20 75 6e 69 78 20 61 6e 64 20 46 41 for unix and FA
11420 4c 53 45 20 66 6f 72 20 43 79 67 77 69 6e 2c 20 LSE for Cygwin,
11430 4d 61 63 20 61 6e 64 20 57 69 6e 64 6f 77 73 2e Mac and Windows.
11440 0a 2a 2a 0a 2a 2a 20 20 20 20 63 6c 65 61 6e 2d .**.** clean-
11450 67 6c 6f 62 20 20 20 20 20 20 20 54 68 65 20 56 glob The V
11460 41 4c 55 45 20 69 73 20 61 20 63 6f 6d 6d 61 20 ALUE is a comma
11470 6f 72 20 6e 65 77 6c 69 6e 65 2d 73 65 70 61 72 or newline-separ
11480 61 74 65 64 20 6c 69 73 74 20 6f 66 20 47 4c 4f ated list of GLO
11490 42 0a 2a 2a 20 20 20 20 20 28 76 65 72 73 69 6f B.** (versio
114a0 6e 61 62 6c 65 29 20 20 20 70 61 74 74 65 72 6e nable) pattern
114b0 73 20 73 70 65 63 69 66 79 69 6e 67 20 66 69 6c s specifying fil
114c0 65 73 20 74 68 61 74 20 74 68 65 20 22 63 6c 65 es that the "cle
114d0 61 6e 22 20 63 6f 6d 6d 61 6e 64 20 77 69 6c 6c an" command will
114e0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
114f0 20 20 20 20 20 20 20 20 64 65 6c 65 74 65 20 77 delete w
11500 69 74 68 6f 75 74 20 70 72 6f 6d 70 74 69 6e 67 ithout prompting
11510 20 65 76 65 6e 20 77 68 65 6e 20 74 68 65 20 2d even when the -
11520 66 6f 72 63 65 20 66 6c 61 67 20 68 61 73 0a 2a force flag has.*
11530 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
11540 20 20 20 20 20 20 6e 6f 74 20 62 65 65 6e 20 75 not been u
11550 73 65 64 2e 20 20 45 78 61 6d 70 6c 65 3a 20 20 sed. Example:
11560 2a 2e 61 20 2a 2e 6c 69 62 20 2a 2e 6f 0a 2a 2a *.a *.lib *.o.**
11570 0a 2a 2a 20 20 20 20 63 6c 65 61 72 73 69 67 6e .** clearsign
11580 20 20 20 20 20 20 20 20 57 68 65 6e 20 65 6e 61 When ena
11590 62 6c 65 64 2c 20 66 6f 73 73 69 6c 20 77 69 6c bled, fossil wil
115a0 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 73 69 67 l attempt to sig
115b0 6e 20 61 6c 6c 20 63 6f 6d 6d 69 74 73 0a 2a 2a n all commits.**
115c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
115d0 20 20 20 20 20 77 69 74 68 20 67 70 67 2e 20 20 with gpg.
115e0 57 68 65 6e 20 64 69 73 61 62 6c 65 64 20 28 74 When disabled (t
115f0 68 65 20 64 65 66 61 75 6c 74 29 2c 20 63 6f 6d he default), com
11600 6d 69 74 73 20 77 69 6c 6c 0a 2a 2a 20 20 20 20 mits will.**
11610 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11620 20 62 65 20 75 6e 73 69 67 6e 65 64 2e 20 20 44 be unsigned. D
11630 65 66 61 75 6c 74 3a 20 6f 66 66 0a 2a 2a 0a 2a efault: off.**.*
11640 2a 20 20 20 20 63 72 6e 6c 2d 67 6c 6f 62 20 20 * crnl-glob
11650 20 20 20 20 20 20 41 20 63 6f 6d 6d 61 20 6f 72 A comma or
11660 20 6e 65 77 6c 69 6e 65 2d 73 65 70 61 72 61 74 newline-separat
11670 65 64 20 6c 69 73 74 20 6f 66 20 47 4c 4f 42 20 ed list of GLOB
11680 70 61 74 74 65 72 6e 73 20 66 6f 72 0a 2a 2a 20 patterns for.**
11690 20 20 20 20 28 76 65 72 73 69 6f 6e 61 62 6c 65 (versionable
116a0 29 20 20 20 74 65 78 74 20 66 69 6c 65 73 20 69 ) text files i
116b0 6e 20 77 68 69 63 68 20 69 74 20 69 73 20 6f 6b n which it is ok
116c0 20 74 6f 20 68 61 76 65 20 43 52 2c 20 43 52 2b to have CR, CR+
116d0 4e 4c 20 6f 72 20 6d 69 78 65 64 0a 2a 2a 20 20 NL or mixed.**
116e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
116f0 20 20 20 6c 69 6e 65 20 65 6e 64 69 6e 67 73 2e line endings.
11700 20 53 65 74 20 74 6f 20 22 2a 22 20 74 6f 20 64 Set to "*" to d
11710 69 73 61 62 6c 65 20 43 52 2b 4e 4c 20 63 68 65 isable CR+NL che
11720 63 6b 69 6e 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 cking..**.**
11730 64 65 66 61 75 6c 74 2d 70 65 72 6d 73 20 20 20 default-perms
11740 20 50 65 72 6d 69 73 73 69 6f 6e 73 20 67 69 76 Permissions giv
11750 65 6e 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 en automatically
11760 20 74 6f 20 6e 65 77 20 75 73 65 72 73 2e 20 20 to new users.
11770 46 6f 72 20 6d 6f 72 65 0a 2a 2a 20 20 20 20 20 For more.**
11780 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11790 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 70 information on p
117a0 65 72 6d 69 73 73 69 6f 6e 73 20 73 65 65 20 55 ermissions see U
117b0 73 65 72 73 20 70 61 67 65 20 69 6e 20 53 65 72 sers page in Ser
117c0 76 65 72 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ver.**
117d0 20 20 20 20 20 20 20 20 20 20 20 41 64 6d 69 6e Admin
117e0 69 73 74 72 61 74 69 6f 6e 20 6f 66 20 74 68 65 istration of the
117f0 20 48 54 54 50 20 55 49 2e 20 44 65 66 61 75 6c HTTP UI. Defaul
11800 74 3a 20 75 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 64 t: u..**.** d
11810 69 66 66 2d 62 69 6e 61 72 79 20 20 20 20 20 20 iff-binary
11820 49 66 20 54 52 55 45 20 28 74 68 65 20 64 65 66 If TRUE (the def
11830 61 75 6c 74 29 2c 20 70 65 72 6d 69 74 20 66 69 ault), permit fi
11840 6c 65 73 20 74 68 61 74 20 6d 61 79 20 62 65 20 les that may be
11850 62 69 6e 61 72 79 0a 2a 2a 20 20 20 20 20 20 20 binary.**
11860 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 72 or
11870 20 74 68 61 74 20 6d 61 74 63 68 20 74 68 65 20 that match the
11880 22 62 69 6e 61 72 79 2d 67 6c 6f 62 22 20 73 65 "binary-glob" se
11890 74 74 69 6e 67 20 74 6f 20 62 65 20 75 73 65 64 tting to be used
118a0 20 77 69 74 68 0a 2a 2a 20 20 20 20 20 20 20 20 with.**
118b0 20 20 20 20 20 20 20 20 20 20 20 20 20 65 78 74 ext
118c0 65 72 6e 61 6c 20 64 69 66 66 20 70 72 6f 67 72 ernal diff progr
118d0 61 6d 73 2e 20 20 49 66 20 46 41 4c 53 45 2c 20 ams. If FALSE,
118e0 73 6b 69 70 20 74 68 65 73 65 20 66 69 6c 65 73 skip these files
118f0 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 64 69 66 66 2d ..**.** diff-
11900 63 6f 6d 6d 61 6e 64 20 20 20 20 20 45 78 74 65 command Exte
11910 72 6e 61 6c 20 63 6f 6d 6d 61 6e 64 20 74 6f 20 rnal command to
11920 72 75 6e 20 77 68 65 6e 20 70 65 72 66 6f 72 6d run when perform
11930 69 6e 67 20 61 20 64 69 66 66 2e 0a 2a 2a 20 20 ing a diff..**
11940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11950 20 20 20 49 66 20 75 6e 64 65 66 69 6e 65 64 2c If undefined,
11960 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 74 65 the internal te
11970 78 74 20 64 69 66 66 20 77 69 6c 6c 20 62 65 20 xt diff will be
11980 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 64 used..**.** d
11990 6f 6e 74 2d 70 75 73 68 20 20 20 20 20 20 20 20 ont-push
119a0 50 72 65 76 65 6e 74 20 74 68 69 73 20 72 65 70 Prevent this rep
119b0 6f 73 69 74 6f 72 79 20 66 72 6f 6d 20 70 75 73 ository from pus
119c0 68 69 6e 67 20 66 72 6f 6d 20 63 6c 69 65 6e 74 hing from client
119d0 20 74 6f 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 to.**
119e0 20 20 20 20 20 20 20 20 20 20 20 73 65 72 76 65 serve
119f0 72 2e 20 20 55 73 65 66 75 6c 20 77 68 65 6e 20 r. Useful when
11a00 73 65 74 74 69 6e 67 20 75 70 20 61 20 70 72 69 setting up a pri
11a10 76 61 74 65 20 62 72 61 6e 63 68 2e 0a 2a 2a 0a vate branch..**.
11a20 2a 2a 20 20 20 20 65 64 69 74 6f 72 20 20 20 20 ** editor
11a30 20 20 20 20 20 20 20 54 65 78 74 20 65 64 69 74 Text edit
11a40 6f 72 20 63 6f 6d 6d 61 6e 64 20 75 73 65 64 20 or command used
11a50 66 6f 72 20 63 68 65 63 6b 2d 69 6e 20 63 6f 6d for check-in com
11a60 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 ments..**.**
11a70 65 6d 70 74 79 2d 64 69 72 73 20 20 20 20 20 20 empty-dirs
11a80 20 41 20 63 6f 6d 6d 61 20 6f 72 20 6e 65 77 6c A comma or newl
11a90 69 6e 65 2d 73 65 70 61 72 61 74 65 64 20 6c 69 ine-separated li
11aa0 73 74 20 6f 66 20 70 61 74 68 6e 61 6d 65 73 2e st of pathnames.
11ab0 20 4f 6e 0a 2a 2a 20 20 20 20 20 28 76 65 72 73 On.** (vers
11ac0 69 6f 6e 61 62 6c 65 29 20 20 20 75 70 64 61 74 ionable) updat
11ad0 65 20 61 6e 64 20 63 68 65 63 6b 6f 75 74 20 63 e and checkout c
11ae0 6f 6d 6d 61 6e 64 73 2c 20 69 66 20 6e 6f 20 66 ommands, if no f
11af0 69 6c 65 20 6f 72 20 64 69 72 65 63 74 6f 72 79 ile or directory
11b00 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11b10 20 20 20 20 20 20 20 20 65 78 69 73 74 73 20 77 exists w
11b20 69 74 68 20 74 68 61 74 20 6e 61 6d 65 2c 20 61 ith that name, a
11b30 6e 20 65 6d 70 74 79 20 64 69 72 65 63 74 6f 72 n empty director
11b40 79 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 20 20 20 y will be.**
11b50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11b60 20 63 72 65 61 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 created..**.**
11b70 20 20 20 65 6e 63 6f 64 69 6e 67 2d 67 6c 6f 62 encoding-glob
11b80 20 20 20 20 54 68 65 20 56 41 4c 55 45 20 69 73 The VALUE is
11b90 20 61 20 63 6f 6d 6d 61 20 6f 72 20 6e 65 77 6c a comma or newl
11ba0 69 6e 65 2d 73 65 70 61 72 61 74 65 64 20 6c 69 ine-separated li
11bb0 73 74 20 6f 66 20 47 4c 4f 42 0a 2a 2a 20 20 20 st of GLOB.**
11bc0 20 20 28 76 65 72 73 69 6f 6e 61 62 6c 65 29 20 (versionable)
11bd0 20 20 70 61 74 74 65 72 6e 73 20 73 70 65 63 69 patterns speci
11be0 66 79 69 6e 67 20 66 69 6c 65 73 20 74 68 61 74 fying files that
11bf0 20 74 68 65 20 22 63 6f 6d 6d 69 74 22 20 63 6f the "commit" co
11c00 6d 6d 61 6e 64 20 77 69 6c 6c 0a 2a 2a 20 20 20 mmand will.**
11c10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11c20 20 20 69 67 6e 6f 72 65 20 77 68 65 6e 20 69 73 ignore when is
11c30 73 75 69 6e 67 20 77 61 72 6e 69 6e 67 73 20 61 suing warnings a
11c40 62 6f 75 74 20 74 65 78 74 20 66 69 6c 65 73 20 bout text files
11c50 74 68 61 74 20 6d 61 79 0a 2a 2a 20 20 20 20 20 that may.**
11c60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11c70 75 73 65 20 61 6e 6f 74 68 65 72 20 65 6e 63 6f use another enco
11c80 64 69 6e 67 20 74 68 61 6e 20 41 53 43 49 49 20 ding than ASCII
11c90 6f 72 20 55 54 46 2d 38 2e 20 53 65 74 20 74 6f or UTF-8. Set to
11ca0 20 22 2a 22 0a 2a 2a 20 20 20 20 20 20 20 20 20 "*".**
11cb0 20 20 20 20 20 20 20 20 20 20 20 20 74 6f 20 64 to d
11cc0 69 73 61 62 6c 65 20 65 6e 63 6f 64 69 6e 67 20 isable encoding
11cd0 63 68 65 63 6b 69 6e 67 2e 0a 2a 2a 0a 2a 2a 20 checking..**.**
11ce0 20 20 20 67 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 gdiff-command
11cf0 20 20 20 20 45 78 74 65 72 6e 61 6c 20 63 6f 6d External com
11d00 6d 61 6e 64 20 74 6f 20 72 75 6e 20 77 68 65 6e mand to run when
11d10 20 70 65 72 66 6f 72 6d 69 6e 67 20 61 20 67 72 performing a gr
11d20 61 70 68 69 63 61 6c 0a 2a 2a 20 20 20 20 20 20 aphical.**
11d30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 64 d
11d40 69 66 66 2e 20 49 66 20 75 6e 64 65 66 69 6e 65 iff. If undefine
11d50 64 2c 20 74 65 78 74 20 64 69 66 66 20 77 69 6c d, text diff wil
11d60 6c 20 62 65 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a l be used..**.**
11d70 20 20 20 20 67 6d 65 72 67 65 2d 63 6f 6d 6d 61 gmerge-comma
11d80 6e 64 20 20 20 41 20 67 72 61 70 68 69 63 61 6c nd A graphical
11d90 20 6d 65 72 67 65 20 63 6f 6e 66 6c 69 63 74 20 merge conflict
11da0 72 65 73 6f 6c 76 65 72 20 63 6f 6d 6d 61 6e 64 resolver command
11db0 20 6f 70 65 72 61 74 69 6e 67 0a 2a 2a 20 20 20 operating.**
11dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11dd0 20 20 6f 6e 20 66 6f 75 72 20 66 69 6c 65 73 2e on four files.
11de0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11df0 20 20 20 20 20 20 20 20 45 78 3a 20 6b 64 69 66 Ex: kdif
11e00 66 33 20 22 25 62 61 73 65 6c 69 6e 65 22 20 22 f3 "%baseline" "
11e10 25 6f 72 69 67 69 6e 61 6c 22 20 22 25 6d 65 72 %original" "%mer
11e20 67 65 22 20 2d 6f 20 22 25 6f 75 74 70 75 74 22 ge" -o "%output"
11e30 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11e40 20 20 20 20 20 20 20 20 45 78 3a 20 78 78 64 69 Ex: xxdi
11e50 66 66 20 22 25 6f 72 69 67 69 6e 61 6c 22 20 22 ff "%original" "
11e60 25 62 61 73 65 6c 69 6e 65 22 20 22 25 6d 65 72 %baseline" "%mer
11e70 67 65 22 20 2d 4d 20 22 25 6f 75 74 70 75 74 22 ge" -M "%output"
11e80 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
11e90 20 20 20 20 20 20 20 20 45 78 3a 20 6d 65 6c 64 Ex: meld
11ea0 20 22 25 62 61 73 65 6c 69 6e 65 22 20 22 25 6f "%baseline" "%o
11eb0 72 69 67 69 6e 61 6c 22 20 22 25 6d 65 72 67 65 riginal" "%merge
11ec0 22 20 22 25 6f 75 74 70 75 74 22 0a 2a 2a 0a 2a " "%output".**.*
11ed0 2a 20 20 20 20 68 74 74 70 2d 70 6f 72 74 20 20 * http-port
11ee0 20 20 20 20 20 20 54 68 65 20 54 43 50 2f 49 50 The TCP/IP
11ef0 20 70 6f 72 74 20 6e 75 6d 62 65 72 20 74 6f 20 port number to
11f00 75 73 65 20 62 79 20 74 68 65 20 22 73 65 72 76 use by the "serv
11f10 65 72 22 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 er".**
11f20 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 20 22 and "
11f30 75 69 22 20 63 6f 6d 6d 61 6e 64 73 2e 20 20 44 ui" commands. D
11f40 65 66 61 75 6c 74 3a 20 38 30 38 30 0a 2a 2a 0a efault: 8080.**.
11f50 2a 2a 20 20 20 20 68 74 74 70 73 2d 6c 6f 67 69 ** https-logi
11f60 6e 20 20 20 20 20 20 53 65 6e 64 20 6c 6f 67 69 n Send logi
11f70 6e 20 63 72 65 64 65 6e 74 69 61 6c 73 20 75 73 n credentials us
11f80 69 6e 67 20 48 54 54 50 53 20 69 6e 73 74 65 61 ing HTTPS instea
11f90 64 20 6f 66 20 48 54 54 50 0a 2a 2a 20 20 20 20 d of HTTP.**
11fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11fb0 20 65 76 65 6e 20 69 66 20 74 68 65 20 6c 6f 67 even if the log
11fc0 69 6e 20 70 61 67 65 20 72 65 71 75 65 73 74 20 in page request
11fd0 63 61 6d 65 20 76 69 61 20 48 54 54 50 2e 0a 2a came via HTTP..*
11fe0 2a 0a 2a 2a 20 20 20 20 69 67 6e 6f 72 65 2d 67 *.** ignore-g
11ff0 6c 6f 62 20 20 20 20 20 20 54 68 65 20 56 41 4c lob The VAL
12000 55 45 20 69 73 20 61 20 63 6f 6d 6d 61 20 6f 72 UE is a comma or
12010 20 6e 65 77 6c 69 6e 65 2d 73 65 70 61 72 61 74 newline-separat
12020 65 64 20 6c 69 73 74 20 6f 66 20 47 4c 4f 42 0a ed list of GLOB.
12030 2a 2a 20 20 20 20 20 28 76 65 72 73 69 6f 6e 61 ** (versiona
12040 62 6c 65 29 20 20 20 70 61 74 74 65 72 6e 73 20 ble) patterns
12050 73 70 65 63 69 66 79 69 6e 67 20 66 69 6c 65 73 specifying files
12060 20 74 68 61 74 20 74 68 65 20 22 61 64 64 22 2c that the "add",
12070 20 22 61 64 64 72 65 6d 6f 76 65 22 2c 0a 2a 2a "addremove",.**
12080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12090 20 20 20 20 20 22 63 6c 65 61 6e 22 2c 20 61 6e "clean", an
120a0 64 20 22 65 78 74 72 61 22 20 63 6f 6d 6d 61 6e d "extra" comman
120b0 64 73 20 77 69 6c 6c 20 69 67 6e 6f 72 65 2e 0a ds will ignore..
120c0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
120d0 20 20 20 20 20 20 20 45 78 61 6d 70 6c 65 3a 20 Example:
120e0 20 2a 2e 6c 6f 67 20 63 75 73 74 6f 6d 43 6f 64 *.log customCod
120f0 65 2e 63 20 6e 6f 74 65 73 2e 74 78 74 0a 2a 2a e.c notes.txt.**
12100 0a 2a 2a 20 20 20 20 6b 65 65 70 2d 67 6c 6f 62 .** keep-glob
12110 20 20 20 20 20 20 20 20 54 68 65 20 56 41 4c 55 The VALU
12120 45 20 69 73 20 61 20 63 6f 6d 6d 61 20 6f 72 20 E is a comma or
12130 6e 65 77 6c 69 6e 65 2d 73 65 70 61 72 61 74 65 newline-separate
12140 64 20 6c 69 73 74 20 6f 66 20 47 4c 4f 42 0a 2a d list of GLOB.*
12150 2a 20 20 20 20 20 28 76 65 72 73 69 6f 6e 61 62 * (versionab
12160 6c 65 29 20 20 20 70 61 74 74 65 72 6e 73 20 73 le) patterns s
12170 70 65 63 69 66 79 69 6e 67 20 66 69 6c 65 73 20 pecifying files
12180 74 68 61 74 20 74 68 65 20 22 63 6c 65 61 6e 22 that the "clean"
12190 20 63 6f 6d 6d 61 6e 64 20 77 69 6c 6c 0a 2a 2a command will.**
121a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
121b0 20 20 20 20 20 6b 65 65 70 2e 0a 2a 2a 0a 2a 2a keep..**.**
121c0 20 20 20 20 6c 6f 63 61 6c 61 75 74 68 20 20 20 localauth
121d0 20 20 20 20 20 49 66 20 65 6e 61 62 6c 65 64 2c If enabled,
121e0 20 72 65 71 75 69 72 65 20 74 68 61 74 20 48 54 require that HT
121f0 54 50 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 20 66 TP connections f
12200 72 6f 6d 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 rom.**
12210 20 20 20 20 20 20 20 20 20 20 20 31 32 37 2e 30 127.0
12220 2e 30 2e 31 20 62 65 20 61 75 74 68 65 6e 74 69 .0.1 be authenti
12230 63 61 74 65 64 20 62 79 20 70 61 73 73 77 6f 72 cated by passwor
12240 64 2e 20 20 49 66 0a 2a 2a 20 20 20 20 20 20 20 d. If.**
12250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 61 fa
12260 6c 73 65 2c 20 61 6c 6c 20 48 54 54 50 20 72 65 lse, all HTTP re
12270 71 75 65 73 74 73 20 66 72 6f 6d 20 6c 6f 63 61 quests from loca
12280 6c 68 6f 73 74 20 68 61 76 65 0a 2a 2a 20 20 20 lhost have.**
12290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
122a0 20 20 75 6e 72 65 73 74 72 69 63 74 65 64 20 61 unrestricted a
122b0 63 63 65 73 73 20 74 6f 20 74 68 65 20 72 65 70 ccess to the rep
122c0 6f 73 69 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 20 ository..**.**
122d0 20 20 6d 61 69 6e 2d 62 72 61 6e 63 68 20 20 20 main-branch
122e0 20 20 20 54 68 65 20 70 72 69 6d 61 72 79 20 62 The primary b
122f0 72 61 6e 63 68 20 66 6f 72 20 74 68 65 20 70 72 ranch for the pr
12300 6f 6a 65 63 74 2e 20 20 44 65 66 61 75 6c 74 3a oject. Default:
12310 20 74 72 75 6e 6b 0a 2a 2a 0a 2a 2a 20 20 20 20 trunk.**.**
12320 6d 61 6e 69 66 65 73 74 20 20 20 20 20 20 20 20 manifest
12330 20 49 66 20 65 6e 61 62 6c 65 64 2c 20 61 75 74 If enabled, aut
12340 6f 6d 61 74 69 63 61 6c 6c 79 20 63 72 65 61 74 omatically creat
12350 65 20 66 69 6c 65 73 20 22 6d 61 6e 69 66 65 73 e files "manifes
12360 74 22 20 61 6e 64 0a 2a 2a 20 20 20 20 20 28 76 t" and.** (v
12370 65 72 73 69 6f 6e 61 62 6c 65 29 20 20 20 22 6d ersionable) "m
12380 61 6e 69 66 65 73 74 2e 75 75 69 64 22 20 69 6e anifest.uuid" in
12390 20 65 76 65 72 79 20 63 68 65 63 6b 6f 75 74 2e every checkout.
123a0 20 20 54 68 65 20 53 51 4c 69 74 65 20 61 6e 64 The SQLite and
123b0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
123c0 20 20 20 20 20 20 20 20 46 6f 73 73 69 6c 20 72 Fossil r
123d0 65 70 6f 73 69 74 6f 72 69 65 73 20 62 6f 74 68 epositories both
123e0 20 72 65 71 75 69 72 65 20 74 68 69 73 2e 20 20 require this.
123f0 44 65 66 61 75 6c 74 3a 20 6f 66 66 2e 0a 2a 2a Default: off..**
12400 0a 2a 2a 20 20 20 20 6d 61 78 2d 6c 6f 61 64 61 .** max-loada
12410 76 67 20 20 20 20 20 20 53 6f 6d 65 20 43 50 55 vg Some CPU
12420 2d 69 6e 74 65 6e 73 69 76 65 20 77 65 62 20 70 -intensive web p
12430 61 67 65 73 20 28 65 78 3a 20 2f 7a 69 70 2c 20 ages (ex: /zip,
12440 2f 74 61 72 62 61 6c 6c 2c 20 2f 62 6c 61 6d 65 /tarball, /blame
12450 29 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ).**
12460 20 20 20 20 20 20 20 20 20 61 72 65 20 64 69 73 are dis
12470 61 6c 6c 6f 77 65 64 20 69 66 20 74 68 65 20 73 allowed if the s
12480 79 73 74 65 6d 20 6c 6f 61 64 20 61 76 65 72 61 ystem load avera
12490 67 65 20 67 6f 65 73 20 61 62 6f 76 65 20 74 68 ge goes above th
124a0 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 is.**
124b0 20 20 20 20 20 20 20 20 20 20 76 61 6c 75 65 2e value.
124c0 20 20 22 30 2e 30 22 20 6d 65 61 6e 73 20 6e 6f "0.0" means no
124d0 20 6c 69 6d 69 74 2e 20 20 54 68 69 73 20 6f 6e limit. This on
124e0 6c 79 20 77 6f 72 6b 73 20 6f 6e 20 75 6e 69 78 ly works on unix
124f0 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ..**
12500 20 20 20 20 20 20 20 20 20 4f 6e 6c 79 20 6c 6f Only lo
12510 63 61 6c 20 73 65 74 74 69 6e 67 73 20 6f 66 20 cal settings of
12520 74 68 69 73 20 76 61 6c 75 65 20 6d 61 6b 65 20 this value make
12530 61 20 64 69 66 66 65 72 65 6e 63 65 20 73 69 6e a difference sin
12540 63 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 ce.**
12550 20 20 20 20 20 20 20 20 20 20 77 68 65 6e 20 72 when r
12560 75 6e 6e 69 6e 67 20 61 73 20 61 20 77 65 62 2d unning as a web-
12570 73 65 72 76 65 72 2c 20 46 6f 73 73 69 6c 20 64 server, Fossil d
12580 6f 65 73 20 6e 6f 74 20 6f 70 65 6e 20 74 68 65 oes not open the
12590 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
125a0 20 20 20 20 20 20 20 20 67 6c 6f 62 61 6c 20 63 global c
125b0 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 64 61 74 onfiguration dat
125c0 61 62 61 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 abase..**.**
125d0 6d 61 78 2d 75 70 6c 6f 61 64 20 20 20 20 20 20 max-upload
125e0 20 41 20 6c 69 6d 69 74 20 6f 6e 20 74 68 65 20 A limit on the
125f0 73 69 7a 65 20 6f 66 20 75 70 6c 69 6e 6b 20 48 size of uplink H
12600 54 54 50 20 72 65 71 75 65 73 74 73 2e 20 20 54 TTP requests. T
12610 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 he.**
12620 20 20 20 20 20 20 20 20 20 20 64 65 66 61 75 6c defaul
12630 74 20 69 73 20 32 35 30 30 30 30 20 62 79 74 65 t is 250000 byte
12640 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 6d 74 69 6d s..**.** mtim
12650 65 2d 63 68 61 6e 67 65 73 20 20 20 20 55 73 65 e-changes Use
12660 20 66 69 6c 65 20 6d 6f 64 69 66 69 63 61 74 69 file modificati
12670 6f 6e 20 74 69 6d 65 73 20 28 6d 74 69 6d 65 73 on times (mtimes
12680 29 20 74 6f 20 64 65 74 65 63 74 20 77 68 65 6e ) to detect when
12690 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
126a0 20 20 20 20 20 20 20 20 66 69 6c 65 73 20 68 61 files ha
126b0 76 65 20 62 65 65 6e 20 6d 6f 64 69 66 69 65 64 ve been modified
126c0 2e 20 20 28 44 65 66 61 75 6c 74 20 22 6f 6e 22 . (Default "on"
126d0 2e 29 0a 2a 2a 0a 2a 2a 20 20 20 20 70 67 70 2d .).**.** pgp-
126e0 63 6f 6d 6d 61 6e 64 20 20 20 20 20 20 43 6f 6d command Com
126f0 6d 61 6e 64 20 75 73 65 64 20 74 6f 20 63 6c 65 mand used to cle
12700 61 72 2d 73 69 67 6e 20 6d 61 6e 69 66 65 73 74 ar-sign manifest
12710 73 20 61 74 20 63 68 65 63 6b 2d 69 6e 2e 0a 2a s at check-in..*
12720 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
12730 20 20 20 20 20 20 54 68 65 20 64 65 66 61 75 6c The defaul
12740 74 20 69 73 20 22 67 70 67 20 2d 2d 63 6c 65 61 t is "gpg --clea
12750 72 73 69 67 6e 20 2d 6f 20 22 2e 0a 2a 2a 0a 2a rsign -o "..**.*
12760 2a 20 20 20 20 70 72 6f 78 79 20 20 20 20 20 20 * proxy
12770 20 20 20 20 20 20 55 52 4c 20 6f 66 20 74 68 65 URL of the
12780 20 48 54 54 50 20 70 72 6f 78 79 2e 20 20 49 66 HTTP proxy. If
12790 20 75 6e 64 65 66 69 6e 65 64 20 6f 72 20 22 6f undefined or "o
127a0 66 66 22 20 74 68 65 6e 0a 2a 2a 20 20 20 20 20 ff" then.**
127b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
127c0 74 68 65 20 22 68 74 74 70 5f 70 72 6f 78 79 22 the "http_proxy"
127d0 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 72 environment var
127e0 69 61 62 6c 65 20 69 73 20 63 6f 6e 73 75 6c 74 iable is consult
127f0 65 64 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ed..**
12800 20 20 20 20 20 20 20 20 20 20 20 49 66 20 74 68 If th
12810 65 20 68 74 74 70 5f 70 72 6f 78 79 20 65 6e 76 e http_proxy env
12820 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c ironment variabl
12830 65 20 69 73 20 75 6e 64 65 66 69 6e 65 64 0a 2a e is undefined.*
12840 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
12850 20 20 20 20 20 20 74 68 65 6e 20 61 20 64 69 72 then a dir
12860 65 63 74 20 48 54 54 50 20 63 6f 6e 6e 65 63 74 ect HTTP connect
12870 69 6f 6e 20 69 73 20 75 73 65 64 2e 0a 2a 2a 0a ion is used..**.
12880 2a 2a 20 20 20 20 72 65 6c 61 74 69 76 65 2d 70 ** relative-p
12890 61 74 68 73 20 20 20 57 68 65 6e 20 73 68 6f 77 aths When show
128a0 69 6e 67 20 63 68 61 6e 67 65 73 20 61 6e 64 20 ing changes and
128b0 65 78 74 72 61 73 2c 20 72 65 70 6f 72 74 20 70 extras, report p
128c0 61 74 68 73 20 72 65 6c 61 74 69 76 65 0a 2a 2a aths relative.**
128d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
128e0 20 20 20 20 20 74 6f 20 74 68 65 20 63 75 72 72 to the curr
128f0 65 6e 74 20 77 6f 72 6b 69 6e 67 20 64 69 72 65 ent working dire
12900 63 74 6f 72 79 2e 20 20 44 65 66 61 75 6c 74 3a ctory. Default:
12910 20 22 6f 6e 22 0a 2a 2a 0a 2a 2a 20 20 20 20 72 "on".**.** r
12920 65 70 6f 2d 63 6b 73 75 6d 20 20 20 20 20 20 20 epo-cksum
12930 43 6f 6d 70 75 74 65 20 63 68 65 63 6b 73 75 6d Compute checksum
12940 73 20 6f 76 65 72 20 61 6c 6c 20 66 69 6c 65 73 s over all files
12950 20 69 6e 20 65 61 63 68 20 63 68 65 63 6b 6f 75 in each checkou
12960 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 t.**
12970 20 20 20 20 20 20 20 20 20 61 73 20 61 20 64 6f as a do
12980 75 62 6c 65 2d 63 68 65 63 6b 20 6f 66 20 63 6f uble-check of co
12990 72 72 65 63 74 6e 65 73 73 2e 20 20 44 65 66 61 rrectness. Defa
129a0 75 6c 74 73 20 74 6f 20 22 6f 6e 22 2e 0a 2a 2a ults to "on"..**
129b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
129c0 20 20 20 20 20 44 69 73 61 62 6c 65 20 6f 6e 20 Disable on
129d0 6c 61 72 67 65 20 72 65 70 6f 73 69 74 6f 72 69 large repositori
129e0 65 73 20 66 6f 72 20 61 20 70 65 72 66 6f 72 6d es for a perform
129f0 61 6e 63 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 ance.**
12a00 20 20 20 20 20 20 20 20 20 20 20 20 69 6d 70 72 impr
12a10 6f 76 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 20 ovement..**.**
12a20 20 20 73 65 6c 66 2d 72 65 67 69 73 74 65 72 20 self-register
12a30 20 20 20 41 6c 6c 6f 77 20 75 73 65 72 73 20 74 Allow users t
12a40 6f 20 72 65 67 69 73 74 65 72 20 74 68 65 6d 73 o register thems
12a50 65 6c 76 65 73 20 74 68 72 6f 75 67 68 20 74 68 elves through th
12a60 65 20 48 54 54 50 20 55 49 2e 0a 2a 2a 20 20 20 e HTTP UI..**
12a70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12a80 20 20 54 68 69 73 20 69 73 20 75 73 65 66 75 6c This is useful
12a90 20 69 66 20 79 6f 75 20 77 61 6e 74 20 74 6f 20 if you want to
12aa0 73 65 65 20 6f 74 68 65 72 20 6e 61 6d 65 73 20 see other names
12ab0 74 68 61 6e 0a 2a 2a 20 20 20 20 20 20 20 20 20 than.**
12ac0 20 20 20 20 20 20 20 20 20 20 20 20 22 41 6e 6f "Ano
12ad0 6e 79 6d 6f 75 73 22 20 69 6e 20 65 2e 67 2e 20 nymous" in e.g.
12ae0 74 69 63 6b 65 74 69 6e 67 20 73 79 73 74 65 6d ticketing system
12af0 2e 20 4f 6e 20 74 68 65 20 6f 74 68 65 72 20 68 . On the other h
12b00 61 6e 64 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 and.**
12b10 20 20 20 20 20 20 20 20 20 20 20 75 73 65 72 73 users
12b20 20 63 61 6e 20 6e 6f 74 20 62 65 20 64 65 6c 65 can not be dele
12b30 74 65 64 2e 20 44 65 66 61 75 6c 74 3a 20 6f 66 ted. Default: of
12b40 66 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 73 73 68 2d f..**.** ssh-
12b50 63 6f 6d 6d 61 6e 64 20 20 20 20 20 20 43 6f 6d command Com
12b60 6d 61 6e 64 20 75 73 65 64 20 74 6f 20 74 61 6c mand used to tal
12b70 6b 20 74 6f 20 61 20 72 65 6d 6f 74 65 20 6d 61 k to a remote ma
12b80 63 68 69 6e 65 20 77 69 74 68 0a 2a 2a 20 20 20 chine with.**
12b90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12ba0 20 20 74 68 65 20 22 73 73 68 3a 2f 2f 22 20 70 the "ssh://" p
12bb0 72 6f 74 6f 63 6f 6c 2e 0a 2a 2a 0a 2a 2a 20 20 rotocol..**.**
12bc0 20 20 73 73 6c 2d 63 61 2d 6c 6f 63 61 74 69 6f ssl-ca-locatio
12bd0 6e 20 20 54 68 65 20 66 75 6c 6c 20 70 61 74 68 n The full path
12be0 6e 61 6d 65 20 74 6f 20 61 20 66 69 6c 65 20 63 name to a file c
12bf0 6f 6e 74 61 69 6e 69 6e 67 20 50 45 4d 20 65 6e ontaining PEM en
12c00 63 6f 64 65 64 0a 2a 2a 20 20 20 20 20 20 20 20 coded.**
12c10 20 20 20 20 20 20 20 20 20 20 20 20 20 43 41 20 CA
12c20 72 6f 6f 74 20 63 65 72 74 69 66 69 63 61 74 65 root certificate
12c30 73 2c 20 6f 72 20 61 20 64 69 72 65 63 74 6f 72 s, or a director
12c40 79 20 6f 66 20 63 65 72 74 69 66 69 63 61 74 65 y of certificate
12c50 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 s.**
12c60 20 20 20 20 20 20 20 20 20 77 69 74 68 20 66 69 with fi
12c70 6c 65 6e 61 6d 65 73 20 66 6f 72 6d 65 64 20 66 lenames formed f
12c80 72 6f 6d 20 74 68 65 20 63 65 72 74 69 66 69 63 rom the certific
12c90 61 74 65 20 68 61 73 68 65 73 20 61 73 0a 2a 2a ate hashes as.**
12ca0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12cb0 20 20 20 20 20 72 65 71 75 69 72 65 64 20 62 79 required by
12cc0 20 4f 70 65 6e 53 53 4c 2e 0a 2a 2a 20 20 20 20 OpenSSL..**
12cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12ce0 20 49 66 20 73 65 74 2c 20 74 68 69 73 20 77 69 If set, this wi
12cf0 6c 6c 20 6f 76 65 72 72 69 64 65 20 74 68 65 20 ll override the
12d00 4f 53 20 64 65 66 61 75 6c 74 20 6c 69 73 74 20 OS default list
12d10 6f 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 of.**
12d20 20 20 20 20 20 20 20 20 20 20 4f 70 65 6e 53 53 OpenSS
12d30 4c 20 43 41 73 2e 20 49 66 20 75 6e 73 65 74 2c L CAs. If unset,
12d40 20 74 68 65 20 64 65 66 61 75 6c 74 20 6c 69 73 the default lis
12d50 74 20 77 69 6c 6c 20 62 65 20 75 73 65 64 2e 0a t will be used..
12d60 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
12d70 20 20 20 20 20 20 20 53 6f 6d 65 20 70 6c 61 74 Some plat
12d80 66 6f 72 6d 73 20 6d 61 79 20 61 64 64 20 61 64 forms may add ad
12d90 64 69 74 69 6f 6e 61 6c 20 63 65 72 74 69 66 69 ditional certifi
12da0 63 61 74 65 73 2e 0a 2a 2a 20 20 20 20 20 20 20 cates..**
12db0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 68 Ch
12dc0 65 63 6b 20 79 6f 75 72 20 70 6c 61 74 66 6f 72 eck your platfor
12dd0 6d 20 62 65 68 61 76 69 6f 75 72 20 69 73 20 61 m behaviour is a
12de0 73 20 72 65 71 75 69 72 65 64 20 69 66 20 74 68 s required if th
12df0 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 e.**
12e00 20 20 20 20 20 20 20 20 20 65 78 61 63 74 20 63 exact c
12e10 6f 6e 74 65 6e 74 73 20 6f 66 20 74 68 65 20 43 ontents of the C
12e20 41 20 72 6f 6f 74 20 69 73 20 63 72 69 74 69 63 A root is critic
12e30 61 6c 20 66 6f 72 20 79 6f 75 72 0a 2a 2a 20 20 al for your.**
12e40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12e50 20 20 20 61 70 70 6c 69 63 61 74 69 6f 6e 2e 0a application..
12e60 2a 2a 0a 2a 2a 20 20 20 20 73 73 6c 2d 69 64 65 **.** ssl-ide
12e70 6e 74 69 74 79 20 20 20 20 20 54 68 65 20 66 75 ntity The fu
12e80 6c 6c 20 70 61 74 68 6e 61 6d 65 20 74 6f 20 61 ll pathname to a
12e90 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67 file containing
12ea0 20 61 20 63 65 72 74 69 66 69 63 61 74 65 0a 2a a certificate.*
12eb0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
12ec0 20 20 20 20 20 20 61 6e 64 20 70 72 69 76 61 74 and privat
12ed0 65 20 6b 65 79 20 69 6e 20 50 45 4d 20 66 6f 72 e key in PEM for
12ee0 6d 61 74 2e 20 43 72 65 61 74 65 20 62 79 20 63 mat. Create by c
12ef0 6f 6e 63 61 74 65 6e 61 74 69 6e 67 0a 2a 2a 20 oncatenating.**
12f00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12f10 20 20 20 20 74 68 65 20 63 65 72 74 69 66 69 63 the certific
12f20 61 74 65 20 61 6e 64 20 70 72 69 76 61 74 65 20 ate and private
12f30 6b 65 79 20 66 69 6c 65 73 2e 0a 2a 2a 20 20 20 key files..**
12f40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12f50 20 20 54 68 69 73 20 69 64 65 6e 74 69 74 79 20 This identity
12f60 77 69 6c 6c 20 62 65 20 70 72 65 73 65 6e 74 65 will be presente
12f70 64 20 74 6f 20 53 53 4c 20 73 65 72 76 65 72 73 d to SSL servers
12f80 20 74 6f 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 to.**
12f90 20 20 20 20 20 20 20 20 20 20 20 61 75 74 68 65 authe
12fa0 6e 74 69 63 61 74 65 20 74 68 69 73 20 63 6c 69 nticate this cli
12fb0 65 6e 74 2c 20 69 6e 20 61 64 64 69 74 69 6f 6e ent, in addition
12fc0 20 74 6f 20 74 68 65 20 6e 6f 72 6d 61 6c 0a 2a to the normal.*
12fd0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
12fe0 20 20 20 20 20 20 70 61 73 73 77 6f 72 64 20 61 password a
12ff0 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 2e 0a 2a uthentication..*
13000 2a 0a 2a 2a 20 20 20 20 74 63 6c 20 20 20 20 20 *.** tcl
13010 20 20 20 20 20 20 20 20 20 49 66 20 65 6e 61 62 If enab
13020 6c 65 64 20 28 61 6e 64 20 46 6f 73 73 69 6c 20 led (and Fossil
13030 77 61 73 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 was compiled wit
13040 68 20 54 63 6c 20 73 75 70 70 6f 72 74 29 2c 0a h Tcl support),.
13050 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
13060 20 20 20 20 20 20 20 54 63 6c 20 69 6e 74 65 67 Tcl integ
13070 72 61 74 69 6f 6e 20 63 6f 6d 6d 61 6e 64 73 20 ration commands
13080 77 69 6c 6c 20 62 65 20 61 64 64 65 64 20 74 6f will be added to
13090 20 74 68 65 20 54 48 31 0a 2a 2a 20 20 20 20 20 the TH1.**
130a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
130b0 69 6e 74 65 72 70 72 65 74 65 72 2c 20 61 6c 6c interpreter, all
130c0 6f 77 69 6e 67 20 61 72 62 69 74 72 61 72 79 20 owing arbitrary
130d0 54 63 6c 20 65 78 70 72 65 73 73 69 6f 6e 73 20 Tcl expressions
130e0 61 6e 64 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 and.**
130f0 20 20 20 20 20 20 20 20 20 20 20 73 63 72 69 70 scrip
13100 74 73 20 74 6f 20 62 65 20 65 76 61 6c 75 61 74 ts to be evaluat
13110 65 64 20 66 72 6f 6d 20 54 48 31 2e 20 20 41 64 ed from TH1. Ad
13120 64 69 74 69 6f 6e 61 6c 6c 79 2c 20 74 68 65 20 ditionally, the
13130 54 63 6c 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 Tcl.**
13140 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 65 72 inter
13150 70 72 65 74 65 72 20 77 69 6c 6c 20 62 65 20 61 preter will be a
13160 62 6c 65 20 74 6f 20 65 76 61 6c 75 61 74 65 20 ble to evaluate
13170 61 72 62 69 74 72 61 72 79 20 54 48 31 0a 2a 2a arbitrary TH1.**
13180 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13190 20 20 20 20 20 65 78 70 72 65 73 73 69 6f 6e 73 expressions
131a0 20 61 6e 64 20 73 63 72 69 70 74 73 2e 20 44 65 and scripts. De
131b0 66 61 75 6c 74 3a 20 6f 66 66 2e 0a 2a 2a 0a 2a fault: off..**.*
131c0 2a 20 20 20 20 74 63 6c 2d 73 65 74 75 70 20 20 * tcl-setup
131d0 20 20 20 20 20 20 54 68 69 73 20 69 73 20 74 68 This is th
131e0 65 20 73 65 74 75 70 20 73 63 72 69 70 74 20 74 e setup script t
131f0 6f 20 62 65 20 65 76 61 6c 75 61 74 65 64 20 61 o be evaluated a
13200 66 74 65 72 20 63 72 65 61 74 69 6e 67 0a 2a 2a fter creating.**
13210 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13220 20 20 20 20 20 61 6e 64 20 69 6e 69 74 69 61 6c and initial
13230 69 7a 69 6e 67 20 74 68 65 20 54 63 6c 20 69 6e izing the Tcl in
13240 74 65 72 70 72 65 74 65 72 2e 20 20 42 79 20 64 terpreter. By d
13250 65 66 61 75 6c 74 2c 20 74 68 69 73 0a 2a 2a 20 efault, this.**
13260 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13270 20 20 20 20 69 73 20 65 6d 70 74 79 20 61 6e 64 is empty and
13280 20 6e 6f 20 65 78 74 72 61 20 73 65 74 75 70 20 no extra setup
13290 69 73 20 70 65 72 66 6f 72 6d 65 64 2e 0a 2a 2a is performed..**
132a0 0a 2a 2a 20 20 20 20 74 68 31 2d 73 65 74 75 70 .** th1-setup
132b0 20 20 20 20 20 20 20 20 54 68 69 73 20 69 73 20 This is
132c0 74 68 65 20 73 65 74 75 70 20 73 63 72 69 70 74 the setup script
132d0 20 74 6f 20 62 65 20 65 76 61 6c 75 61 74 65 64 to be evaluated
132e0 20 61 66 74 65 72 20 63 72 65 61 74 69 6e 67 0a after creating.
132f0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
13300 20 20 20 20 20 20 20 61 6e 64 20 69 6e 69 74 69 and initi
13310 61 6c 69 7a 69 6e 67 20 74 68 65 20 54 48 31 20 alizing the TH1
13320 69 6e 74 65 72 70 72 65 74 65 72 2e 20 20 42 79 interpreter. By
13330 20 64 65 66 61 75 6c 74 2c 20 74 68 69 73 0a 2a default, this.*
13340 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
13350 20 20 20 20 20 20 69 73 20 65 6d 70 74 79 20 61 is empty a
13360 6e 64 20 6e 6f 20 65 78 74 72 61 20 73 65 74 75 nd no extra setu
13370 70 20 69 73 20 70 65 72 66 6f 72 6d 65 64 2e 0a p is performed..
13380 2a 2a 0a 2a 2a 20 20 20 20 74 68 31 2d 75 72 69 **.** th1-uri
13390 2d 72 65 67 65 78 70 20 20 20 53 70 65 63 69 66 -regexp Specif
133a0 79 20 77 68 69 63 68 20 55 52 49 27 73 20 61 72 y which URI's ar
133b0 65 20 61 6c 6c 6f 77 65 64 20 69 6e 20 48 54 54 e allowed in HTT
133c0 50 20 72 65 71 75 65 73 74 73 20 66 72 6f 6d 0a P requests from.
133d0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
133e0 20 20 20 20 20 20 20 54 48 31 20 73 63 72 69 70 TH1 scrip
133f0 74 73 2e 20 20 49 66 20 65 6d 70 74 79 2c 20 6e ts. If empty, n
13400 6f 20 48 54 54 50 20 72 65 71 75 65 73 74 73 20 o HTTP requests
13410 61 72 65 20 61 6c 6c 6f 77 65 64 0a 2a 2a 20 20 are allowed.**
13420 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13430 20 20 20 77 68 61 74 73 6f 65 76 65 72 2e 20 20 whatsoever.
13440 54 68 65 20 64 65 66 61 75 6c 74 20 69 73 20 61 The default is a
13450 6e 20 65 6d 70 74 79 20 73 74 72 69 6e 67 2e 0a n empty string..
13460 2a 2a 0a 2a 2a 20 20 20 20 77 65 62 2d 62 72 6f **.** web-bro
13470 77 73 65 72 20 20 20 20 20 20 41 20 73 68 65 6c wser A shel
13480 6c 20 63 6f 6d 6d 61 6e 64 20 75 73 65 64 20 74 l command used t
13490 6f 20 6c 61 75 6e 63 68 20 79 6f 75 72 20 70 72 o launch your pr
134a0 65 66 65 72 72 65 64 0a 2a 2a 20 20 20 20 20 20 eferred.**
134b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 77 w
134c0 65 62 20 62 72 6f 77 73 65 72 20 77 68 65 6e 20 eb browser when
134d0 67 69 76 65 6e 20 61 20 55 52 4c 20 61 73 20 61 given a URL as a
134e0 6e 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2a 20 20 n argument..**
134f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13500 20 20 20 44 65 66 61 75 6c 74 73 20 74 6f 20 22 Defaults to "
13510 73 74 61 72 74 22 20 6f 6e 20 77 69 6e 64 6f 77 start" on window
13520 73 2c 20 22 6f 70 65 6e 22 20 6f 6e 20 4d 61 63 s, "open" on Mac
13530 2c 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ,.**
13540 20 20 20 20 20 20 20 20 20 61 6e 64 20 22 66 69 and "fi
13550 72 65 66 6f 78 22 20 6f 6e 20 55 6e 69 78 2e 0a refox" on Unix..
13560 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a **.** Options:.*
13570 2a 20 20 20 2d 2d 67 6c 6f 62 61 6c 20 20 20 73 * --global s
13580 65 74 20 6f 72 20 75 6e 73 65 74 20 74 68 65 20 et or unset the
13590 67 69 76 65 6e 20 70 72 6f 70 65 72 74 79 20 67 given property g
135a0 6c 6f 62 61 6c 6c 79 20 69 6e 73 74 65 61 64 20 lobally instead
135b0 6f 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 of.**
135c0 20 20 20 73 65 74 74 69 6e 67 20 6f 72 20 75 6e setting or un
135d0 73 65 74 74 69 6e 67 20 69 74 20 66 6f 72 20 74 setting it for t
135e0 68 65 20 6f 70 65 6e 20 72 65 70 6f 73 69 74 6f he open reposito
135f0 72 79 20 6f 6e 6c 79 2e 0a 2a 2a 0a 2a 2a 20 53 ry only..**.** S
13600 65 65 20 61 6c 73 6f 3a 20 63 6f 6e 66 69 67 75 ee also: configu
13610 72 61 74 69 6f 6e 0a 2a 2f 0a 76 6f 69 64 20 73 ration.*/.void s
13620 65 74 74 69 6e 67 5f 63 6d 64 28 76 6f 69 64 29 etting_cmd(void)
13630 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74 {. int i;. int
13640 20 67 6c 6f 62 61 6c 46 6c 61 67 20 3d 20 66 69 globalFlag = fi
13650 6e 64 5f 6f 70 74 69 6f 6e 28 22 67 6c 6f 62 61 nd_option("globa
13660 6c 22 2c 22 67 22 2c 30 29 21 3d 30 3b 0a 20 20 l","g",0)!=0;.
13670 69 6e 74 20 75 6e 73 65 74 46 6c 61 67 20 3d 20 int unsetFlag =
13680 67 2e 61 72 67 76 5b 31 5d 5b 30 5d 3d 3d 27 75 g.argv[1][0]=='u
13690 27 3b 0a 20 20 64 62 5f 6f 70 65 6e 5f 63 6f 6e ';. db_open_con
136a0 66 69 67 28 31 29 3b 0a 20 20 69 66 28 20 21 67 fig(1);. if( !g
136b0 6c 6f 62 61 6c 46 6c 61 67 20 29 7b 0a 20 20 20 lobalFlag ){.
136c0 20 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 db_find_and_ope
136d0 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 4f 50 45 n_repository(OPE
136e0 4e 5f 41 4e 59 5f 53 43 48 45 4d 41 20 7c 20 4f N_ANY_SCHEMA | O
136f0 50 45 4e 5f 4f 4b 5f 4e 4f 54 5f 46 4f 55 4e 44 PEN_OK_NOT_FOUND
13700 2c 20 30 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 , 0);. }. if(
13710 21 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 !g.repositoryOpe
13720 6e 20 29 7b 0a 20 20 20 20 67 6c 6f 62 61 6c 46 n ){. globalF
13730 6c 61 67 20 3d 20 31 3b 0a 20 20 7d 0a 20 20 69 lag = 1;. }. i
13740 66 28 20 75 6e 73 65 74 46 6c 61 67 20 26 26 20 f( unsetFlag &&
13750 67 2e 61 72 67 63 21 3d 33 20 29 7b 0a 20 20 20 g.argc!=3 ){.
13760 20 75 73 61 67 65 28 22 50 52 4f 50 45 52 54 59 usage("PROPERTY
13770 20 3f 2d 67 6c 6f 62 61 6c 3f 22 29 3b 0a 20 20 ?-global?");.
13780 7d 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d }. if( g.argc==
13790 32 20 29 7b 0a 20 20 20 20 69 6e 74 20 6f 70 65 2 ){. int ope
137a0 6e 4c 6f 63 61 6c 20 3d 20 64 62 5f 6f 70 65 6e nLocal = db_open
137b0 5f 6c 6f 63 61 6c 28 30 29 3b 0a 20 20 20 20 66 _local(0);. f
137c0 6f 72 28 69 3d 30 3b 20 63 74 72 6c 53 65 74 74 or(i=0; ctrlSett
137d0 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 3b 20 69 2b ings[i].name; i+
137e0 2b 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 5f +){. print_
137f0 73 65 74 74 69 6e 67 28 26 63 74 72 6c 53 65 74 setting(&ctrlSet
13800 74 69 6e 67 73 5b 69 5d 2c 20 6f 70 65 6e 4c 6f tings[i], openLo
13810 63 61 6c 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 cal);. }. }e
13820 6c 73 65 20 69 66 28 20 67 2e 61 72 67 63 3d 3d lse if( g.argc==
13830 33 20 7c 7c 20 67 2e 61 72 67 63 3d 3d 34 20 29 3 || g.argc==4 )
13840 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
13850 20 2a 7a 4e 61 6d 65 20 3d 20 67 2e 61 72 67 76 *zName = g.argv
13860 5b 32 5d 3b 0a 20 20 20 20 69 6e 74 20 69 73 4d [2];. int isM
13870 61 6e 69 66 65 73 74 3b 0a 20 20 20 20 69 6e 74 anifest;. int
13880 20 6e 20 3d 20 73 74 72 6c 65 6e 28 7a 4e 61 6d n = strlen(zNam
13890 65 29 3b 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b e);. for(i=0;
138a0 20 63 74 72 6c 53 65 74 74 69 6e 67 73 5b 69 5d ctrlSettings[i]
138b0 2e 6e 61 6d 65 3b 20 69 2b 2b 29 7b 0a 20 20 20 .name; i++){.
138c0 20 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28 63 if( strncmp(c
138d0 74 72 6c 53 65 74 74 69 6e 67 73 5b 69 5d 2e 6e trlSettings[i].n
138e0 61 6d 65 2c 20 7a 4e 61 6d 65 2c 20 6e 29 3d 3d ame, zName, n)==
138f0 30 20 29 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0 ) break;. }
13900 0a 20 20 20 20 69 66 28 20 21 63 74 72 6c 53 65 . if( !ctrlSe
13910 74 74 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 20 29 ttings[i].name )
13920 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 {. fossil_f
13930 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 73 65 atal("no such se
13940 74 74 69 6e 67 3a 20 25 73 22 2c 20 7a 4e 61 6d tting: %s", zNam
13950 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 73 e);. }. is
13960 4d 61 6e 69 66 65 73 74 20 3d 20 66 6f 73 73 69 Manifest = fossi
13970 6c 5f 73 74 72 63 6d 70 28 63 74 72 6c 53 65 74 l_strcmp(ctrlSet
13980 74 69 6e 67 73 5b 69 5d 2e 6e 61 6d 65 2c 20 22 tings[i].name, "
13990 6d 61 6e 69 66 65 73 74 22 29 3d 3d 30 3b 0a 20 manifest")==0;.
139a0 20 20 20 69 66 28 20 69 73 4d 61 6e 69 66 65 73 if( isManifes
139b0 74 20 26 26 20 67 6c 6f 62 61 6c 46 6c 61 67 20 t && globalFlag
139c0 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f ){. fossil_
139d0 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 73 65 fatal("cannot se
139e0 74 20 27 6d 61 6e 69 66 65 73 74 27 20 67 6c 6f t 'manifest' glo
139f0 62 61 6c 6c 79 22 29 3b 0a 20 20 20 20 7d 0a 20 bally");. }.
13a00 20 20 20 69 66 28 20 75 6e 73 65 74 46 6c 61 67 if( unsetFlag
13a10 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 75 6e 73 ){. db_uns
13a20 65 74 28 63 74 72 6c 53 65 74 74 69 6e 67 73 5b et(ctrlSettings[
13a30 69 5d 2e 6e 61 6d 65 2c 20 67 6c 6f 62 61 6c 46 i].name, globalF
13a40 6c 61 67 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 lag);. }else
13a50 69 66 28 20 67 2e 61 72 67 63 3d 3d 34 20 29 7b if( g.argc==4 ){
13a60 0a 20 20 20 20 20 20 64 62 5f 73 65 74 28 63 74 . db_set(ct
13a70 72 6c 53 65 74 74 69 6e 67 73 5b 69 5d 2e 6e 61 rlSettings[i].na
13a80 6d 65 2c 20 67 2e 61 72 67 76 5b 33 5d 2c 20 67 me, g.argv[3], g
13a90 6c 6f 62 61 6c 46 6c 61 67 29 3b 0a 20 20 20 20 lobalFlag);.
13aa0 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 69 73 4d }else{. isM
13ab0 61 6e 69 66 65 73 74 20 3d 20 30 3b 0a 20 20 20 anifest = 0;.
13ac0 20 20 20 70 72 69 6e 74 5f 73 65 74 74 69 6e 67 print_setting
13ad0 28 26 63 74 72 6c 53 65 74 74 69 6e 67 73 5b 69 (&ctrlSettings[i
13ae0 5d 2c 20 64 62 5f 6f 70 65 6e 5f 6c 6f 63 61 6c ], db_open_local
13af0 28 30 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 (0));. }.
13b00 69 66 28 20 69 73 4d 61 6e 69 66 65 73 74 20 26 if( isManifest &
13b10 26 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 7b & g.localOpen ){
13b20 0a 20 20 20 20 20 20 6d 61 6e 69 66 65 73 74 5f . manifest_
13b30 74 6f 5f 64 69 73 6b 28 64 62 5f 6c 67 65 74 5f to_disk(db_lget_
13b40 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 int("checkout",
13b50 30 29 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 0));. }. }el
13b60 73 65 7b 0a 20 20 20 20 75 73 61 67 65 28 22 3f se{. usage("?
13b70 50 52 4f 50 45 52 54 59 3f 20 3f 56 41 4c 55 45 PROPERTY? ?VALUE
13b80 3f 20 3f 2d 67 6c 6f 62 61 6c 3f 22 29 3b 0a 20 ? ?-global?");.
13b90 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 }.}../*.** The
13ba0 69 6e 70 75 74 20 69 6e 20 61 20 74 69 6d 65 73 input in a times
13bb0 70 61 6e 20 6d 65 61 73 75 72 65 64 20 69 6e 20 pan measured in
13bc0 64 61 79 73 2e 20 20 52 65 74 75 72 6e 20 61 20 days. Return a
13bd0 73 74 72 69 6e 67 20 77 68 69 63 68 0a 2a 2a 20 string which.**
13be0 64 65 73 63 72 69 62 65 73 20 74 68 61 74 20 74 describes that t
13bf0 69 6d 65 73 70 61 6e 20 69 6e 20 75 6e 69 74 73 imespan in units
13c00 20 6f 66 20 73 65 63 6f 6e 64 73 2c 20 6d 69 6e of seconds, min
13c10 75 74 65 73 2c 20 68 6f 75 72 73 2c 20 64 61 79 utes, hours, day
13c20 73 2c 0a 2a 2a 20 6f 72 20 79 65 61 72 73 2c 20 s,.** or years,
13c30 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 69 74 73 depending on its
13c40 20 64 75 72 61 74 69 6f 6e 2e 0a 2a 2f 0a 63 68 duration..*/.ch
13c50 61 72 20 2a 64 62 5f 74 69 6d 65 73 70 61 6e 5f ar *db_timespan_
13c60 6e 61 6d 65 28 64 6f 75 62 6c 65 20 72 53 70 61 name(double rSpa
13c70 6e 29 7b 0a 20 20 69 66 28 20 72 53 70 61 6e 3c n){. if( rSpan<
13c80 30 20 29 20 72 53 70 61 6e 20 3d 20 2d 72 53 70 0 ) rSpan = -rSp
13c90 61 6e 3b 0a 20 20 72 53 70 61 6e 20 2a 3d 20 32 an;. rSpan *= 2
13ca0 34 2e 30 2a 33 36 30 30 2e 30 3b 20 20 2f 2a 20 4.0*3600.0; /*
13cb0 43 6f 6e 76 65 72 74 20 75 6e 69 74 73 20 74 6f Convert units to
13cc0 20 73 65 63 6f 6e 64 73 20 2a 2f 0a 20 20 69 66 seconds */. if
13cd0 28 20 72 53 70 61 6e 3c 31 32 30 2e 30 20 29 7b ( rSpan<120.0 ){
13ce0 0a 20 20 20 20 72 65 74 75 72 6e 20 73 71 6c 69 . return sqli
13cf0 74 65 33 5f 6d 70 72 69 6e 74 66 28 22 25 2e 31 te3_mprintf("%.1
13d00 66 20 73 65 63 6f 6e 64 73 22 2c 20 72 53 70 61 f seconds", rSpa
13d10 6e 29 3b 0a 20 20 7d 0a 20 20 72 53 70 61 6e 20 n);. }. rSpan
13d20 2f 3d 20 36 30 2e 30 3b 20 20 20 20 20 20 20 20 /= 60.0;
13d30 20 2f 2a 20 43 6f 6e 76 65 72 74 20 75 6e 69 74 /* Convert unit
13d40 73 20 74 6f 20 6d 69 6e 75 74 65 73 20 2a 2f 0a s to minutes */.
13d50 20 20 69 66 28 20 72 53 70 61 6e 3c 39 30 2e 30 if( rSpan<90.0
13d60 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 73 ){. return s
13d70 71 6c 69 74 65 33 5f 6d 70 72 69 6e 74 66 28 22 qlite3_mprintf("
13d80 25 2e 31 66 20 6d 69 6e 75 74 65 73 22 2c 20 72 %.1f minutes", r
13d90 53 70 61 6e 29 3b 0a 20 20 7d 0a 20 20 72 53 70 Span);. }. rSp
13da0 61 6e 20 2f 3d 20 36 30 2e 30 3b 20 20 20 20 20 an /= 60.0;
13db0 20 20 20 20 2f 2a 20 43 6f 6e 76 65 72 74 20 75 /* Convert u
13dc0 6e 69 74 73 20 74 6f 20 68 6f 75 72 73 20 2a 2f nits to hours */
13dd0 0a 20 20 69 66 28 20 72 53 70 61 6e 3c 3d 34 38 . if( rSpan<=48
13de0 2e 30 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e .0 ){. return
13df0 20 73 71 6c 69 74 65 33 5f 6d 70 72 69 6e 74 66 sqlite3_mprintf
13e00 28 22 25 2e 31 66 20 68 6f 75 72 73 22 2c 20 72 ("%.1f hours", r
13e10 53 70 61 6e 29 3b 0a 20 20 7d 0a 20 20 72 53 70 Span);. }. rSp
13e20 61 6e 20 2f 3d 20 32 34 2e 30 3b 20 20 20 20 20 an /= 24.0;
13e30 20 20 20 20 2f 2a 20 43 6f 6e 76 65 72 74 20 75 /* Convert u
13e40 6e 69 74 73 20 74 6f 20 64 61 79 73 20 2a 2f 0a nits to days */.
13e50 20 20 69 66 28 20 72 53 70 61 6e 3c 3d 33 36 35 if( rSpan<=365
13e60 2e 30 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e .0 ){. return
13e70 20 73 71 6c 69 74 65 33 5f 6d 70 72 69 6e 74 66 sqlite3_mprintf
13e80 28 22 25 2e 31 66 20 64 61 79 73 22 2c 20 72 53 ("%.1f days", rS
13e90 70 61 6e 29 3b 0a 20 20 7d 0a 20 20 72 53 70 61 pan);. }. rSpa
13ea0 6e 20 2f 3d 20 33 35 36 2e 32 34 3b 20 20 20 20 n /= 356.24;
13eb0 20 20 20 20 20 2f 2a 20 43 6f 6e 76 65 72 74 20 /* Convert
13ec0 75 6e 69 74 73 20 74 6f 20 79 65 61 72 73 20 2a units to years *
13ed0 2f 0a 20 20 72 65 74 75 72 6e 20 73 71 6c 69 74 /. return sqlit
13ee0 65 33 5f 6d 70 72 69 6e 74 66 28 22 25 2e 31 66 e3_mprintf("%.1f
13ef0 20 79 65 61 72 73 22 2c 20 72 53 70 61 6e 29 3b years", rSpan);
13f00 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e .}../*.** COMMAN
13f10 44 3a 20 74 65 73 74 2d 74 69 6d 65 73 70 61 6e D: test-timespan
13f20 0a 2a 2a 20 25 66 6f 73 73 69 6c 20 74 65 73 74 .** %fossil test
13f30 2d 74 69 6d 65 73 70 61 6e 20 54 49 4d 45 53 54 -timespan TIMEST
13f40 41 4d 50 0a 2a 2a 0a 2a 2a 20 50 72 69 6e 74 20 AMP.**.** Print
13f50 74 68 65 20 61 70 70 72 6f 78 69 6d 61 74 65 20 the approximate
13f60 73 70 61 6e 20 6f 66 20 74 69 6d 65 20 66 72 6f span of time fro
13f70 6d 20 6e 6f 77 20 74 6f 20 54 49 4d 45 53 54 41 m now to TIMESTA
13f80 4d 50 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 73 74 MP..*/.void test
13f90 5f 74 69 6d 65 73 70 61 6e 5f 63 6d 64 28 76 6f _timespan_cmd(vo
13fa0 69 64 29 7b 0a 20 20 64 6f 75 62 6c 65 20 72 44 id){. double rD
13fb0 69 66 66 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 iff;. if( g.arg
13fc0 63 21 3d 33 20 29 20 75 73 61 67 65 28 22 54 49 c!=3 ) usage("TI
13fd0 4d 45 53 54 41 4d 50 22 29 3b 0a 20 20 73 71 6c MESTAMP");. sql
13fe0 69 74 65 33 5f 6f 70 65 6e 28 22 3a 6d 65 6d 6f ite3_open(":memo
13ff0 72 79 3a 22 2c 20 26 67 2e 64 62 29 3b 0a 20 20 ry:", &g.db);.
14000 72 44 69 66 66 20 3d 20 64 62 5f 64 6f 75 62 6c rDiff = db_doubl
14010 65 28 30 2e 30 2c 20 22 53 45 4c 45 43 54 20 6a e(0.0, "SELECT j
14020 75 6c 69 61 6e 64 61 79 28 27 6e 6f 77 27 29 20 ulianday('now')
14030 2d 20 6a 75 6c 69 61 6e 64 61 79 28 25 51 29 22 - julianday(%Q)"
14040 2c 20 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 , g.argv[2]);.
14050 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 54 69 fossil_print("Ti
14060 6d 65 20 64 69 66 66 65 72 65 6e 63 65 73 3a 20 me differences:
14070 25 73 5c 6e 22 2c 20 64 62 5f 74 69 6d 65 73 70 %s\n", db_timesp
14080 61 6e 5f 6e 61 6d 65 28 72 44 69 66 66 29 29 3b an_name(rDiff));
14090 0a 20 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 . sqlite3_close
140a0 28 67 2e 64 62 29 3b 0a 20 20 67 2e 64 62 20 3d (g.db);. g.db =
140b0 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 0;.}../*.** COM
140c0 4d 41 4e 44 3a 20 74 65 73 74 2d 77 69 74 68 6f MAND: test-witho
140d0 75 74 2d 72 6f 77 69 64 0a 2a 2a 20 25 66 6f 73 ut-rowid.** %fos
140e0 73 69 6c 20 74 65 73 74 2d 77 69 74 68 6f 75 74 sil test-without
140f0 2d 72 6f 77 69 64 20 46 49 4c 45 4e 41 4d 45 2e -rowid FILENAME.
14100 2e 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e 67 65 20 ...**.** Change
14110 74 68 65 20 46 6f 73 73 69 6c 20 72 65 70 6f 73 the Fossil repos
14120 69 74 6f 72 79 20 46 49 4c 45 4e 41 4d 45 20 74 itory FILENAME t
14130 6f 20 6d 61 6b 65 20 75 73 65 20 6f 66 20 74 68 o make use of th
14140 65 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 0a e WITHOUT ROWID.
14150 2a 2a 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 2e ** optimization.
14160 20 20 46 49 4c 45 4e 41 4d 45 20 63 61 6e 20 61 FILENAME can a
14170 6c 73 6f 20 62 65 20 74 68 65 20 7e 2f 2e 66 6f lso be the ~/.fo
14180 73 73 69 6c 20 66 69 6c 65 20 6f 72 20 61 20 6c ssil file or a l
14190 6f 63 61 6c 0a 2a 2a 20 2e 66 73 6c 63 6b 6f 75 ocal.** .fslckou
141a0 74 20 6f 72 20 5f 46 4f 53 53 49 4c 5f 20 66 69 t or _FOSSIL_ fi
141b0 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 70 75 le..**.** The pu
141c0 72 70 6f 73 65 20 6f 66 20 74 68 69 73 20 63 6f rpose of this co
141d0 6d 6d 61 6e 64 20 69 73 20 66 6f 72 20 74 65 73 mmand is for tes
141e0 74 69 6e 67 20 74 68 65 20 57 49 54 48 4f 55 54 ting the WITHOUT
141f0 20 52 4f 57 49 44 20 63 61 70 61 62 69 6c 69 74 ROWID capabilit
14200 69 65 73 0a 2a 2a 20 6f 66 20 53 51 4c 69 74 65 ies.** of SQLite
14210 2e 20 20 54 68 65 72 65 20 69 73 20 6e 6f 20 62 . There is no b
14220 69 67 20 61 64 76 61 6e 74 61 67 65 20 74 6f 20 ig advantage to
14230 75 73 69 6e 67 20 57 49 54 48 4f 55 54 20 52 4f using WITHOUT RO
14240 57 49 44 20 69 6e 20 46 6f 73 73 69 6c 2e 0a 2a WID in Fossil..*
14250 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a 2a *.** Options:.**
14260 20 20 20 20 2d 2d 64 72 79 72 75 6e 20 7c 20 2d --dryrun | -
14270 6e 20 20 20 20 20 20 20 20 20 4e 6f 20 63 68 61 n No cha
14280 6e 67 65 73 2e 20 20 4a 75 73 74 20 70 72 69 6e nges. Just prin
14290 74 20 77 68 61 74 20 77 6f 75 6c 64 20 68 61 70 t what would hap
142a0 70 65 6e 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 73 pen..*/.void tes
142b0 74 5f 77 69 74 68 6f 75 74 5f 72 6f 77 69 64 28 t_without_rowid(
142c0 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 2c 20 void){. int i,
142d0 6a 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 42 j;. Stmt q;. B
142e0 6c 6f 62 20 61 6c 6c 53 71 6c 3b 0a 20 20 69 6e lob allSql;. in
142f0 74 20 64 72 79 52 75 6e 20 3d 20 66 69 6e 64 5f t dryRun = find_
14300 6f 70 74 69 6f 6e 28 22 64 72 79 2d 72 75 6e 22 option("dry-run"
14310 2c 20 22 6e 22 2c 20 30 29 21 3d 30 3b 0a 20 20 , "n", 0)!=0;.
14320 66 6f 72 28 69 3d 32 3b 20 69 3c 67 2e 61 72 67 for(i=2; i<g.arg
14330 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 64 62 5f c; i++){. db_
14340 6f 70 65 6e 5f 6f 72 5f 61 74 74 61 63 68 28 67 open_or_attach(g
14350 2e 61 72 67 76 5b 69 5d 2c 20 22 6d 61 69 6e 22 .argv[i], "main"
14360 2c 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 69 , 0);. blob_i
14370 6e 69 74 28 26 61 6c 6c 53 71 6c 2c 20 22 42 45 nit(&allSql, "BE
14380 47 49 4e 3b 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 GIN;\n", -1);.
14390 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c db_prepare(&q,
143a0 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 6e . "SELECT n
143b0 61 6d 65 2c 20 73 71 6c 20 46 52 4f 4d 20 6d 61 ame, sql FROM ma
143c0 69 6e 2e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 in.sqlite_master
143d0 20 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 ". " WHERE
143e0 20 74 79 70 65 3d 27 74 61 62 6c 65 27 20 41 4e type='table' AN
143f0 44 20 73 71 6c 20 4e 4f 54 20 4c 49 4b 45 20 27 D sql NOT LIKE '
14400 25 25 57 49 54 48 4f 55 54 20 52 4f 57 49 44 25 %%WITHOUT ROWID%
14410 25 27 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e %'". " AN
14420 44 20 6e 61 6d 65 20 49 4e 20 28 27 67 6c 6f 62 D name IN ('glob
14430 61 6c 5f 63 6f 6e 66 69 67 27 2c 27 73 68 75 6e al_config','shun
14440 27 2c 27 63 6f 6e 63 65 61 6c 65 64 27 2c 27 63 ','concealed','c
14450 6f 6e 66 69 67 27 2c 22 0a 20 20 20 20 20 20 20 onfig',".
14460 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 20 "
14470 27 70 6c 69 6e 6b 27 2c 27 74 61 67 78 72 65 66 'plink','tagxref
14480 27 2c 27 62 61 63 6b 6c 69 6e 6b 27 2c 27 76 63 ','backlink','vc
14490 61 63 68 65 27 29 3b 22 0a 20 20 20 20 29 3b 0a ache');". );.
144a0 20 20 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 while( db_st
144b0 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 ep(&q)==SQLITE_R
144c0 4f 57 20 29 7b 0a 20 20 20 20 20 20 63 6f 6e 73 OW ){. cons
144d0 74 20 63 68 61 72 20 2a 7a 54 4e 61 6d 65 20 3d t char *zTName =
144e0 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
144f0 26 71 2c 20 30 29 3b 0a 20 20 20 20 20 20 63 6f &q, 0);. co
14500 6e 73 74 20 63 68 61 72 20 2a 7a 4f 72 69 67 53 nst char *zOrigS
14510 71 6c 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 ql = db_column_t
14520 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 ext(&q, 1);.
14530 20 20 42 6c 6f 62 20 6e 65 77 53 71 6c 3b 0a 20 Blob newSql;.
14540 20 20 20 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 blob_init(&
14550 6e 65 77 53 71 6c 2c 20 30 2c 20 30 29 3b 0a 20 newSql, 0, 0);.
14560 20 20 20 20 20 66 6f 72 28 6a 3d 30 3b 20 7a 4f for(j=0; zO
14570 72 69 67 53 71 6c 5b 6a 5d 3b 20 6a 2b 2b 29 7b rigSql[j]; j++){
14580 0a 20 20 20 20 20 20 20 20 69 66 28 20 66 6f 73 . if( fos
14590 73 69 6c 5f 73 74 72 6e 69 63 6d 70 28 7a 4f 72 sil_strnicmp(zOr
145a0 69 67 53 71 6c 2b 6a 2c 22 75 6e 69 71 75 65 22 igSql+j,"unique"
145b0 2c 36 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 ,6)==0 ){.
145c0 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 blob_append(
145d0 26 6e 65 77 53 71 6c 2c 20 7a 4f 72 69 67 53 71 &newSql, zOrigSq
145e0 6c 2c 20 6a 29 3b 0a 20 20 20 20 20 20 20 20 20 l, j);.
145f0 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 6e 65 blob_append(&ne
14600 77 53 71 6c 2c 20 22 50 52 49 4d 41 52 59 20 4b wSql, "PRIMARY K
14610 45 59 22 2c 20 2d 31 29 3b 0a 20 20 20 20 20 20 EY", -1);.
14620 20 20 20 20 7a 4f 72 69 67 53 71 6c 20 2b 3d 20 zOrigSql +=
14630 6a 2b 36 3b 0a 20 20 20 20 20 20 20 20 20 20 6a j+6;. j
14640 20 3d 20 2d 31 3b 0a 20 20 20 20 20 20 20 20 7d = -1;. }
14650 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 . }. b
14660 6c 6f 62 5f 61 70 70 65 6e 64 28 26 6e 65 77 53 lob_append(&newS
14670 71 6c 2c 20 7a 4f 72 69 67 53 71 6c 2c 20 2d 31 ql, zOrigSql, -1
14680 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 );. blob_ap
14690 70 65 6e 64 66 28 26 61 6c 6c 53 71 6c 2c 20 0a pendf(&allSql, .
146a0 20 20 20 20 20 20 20 20 20 22 41 4c 54 45 52 20 "ALTER
146b0 54 41 42 4c 45 20 25 73 20 52 45 4e 41 4d 45 20 TABLE %s RENAME
146c0 54 4f 20 78 5f 25 73 3b 5c 6e 22 0a 20 20 20 20 TO x_%s;\n".
146d0 20 20 20 20 20 22 25 73 20 57 49 54 48 4f 55 54 "%s WITHOUT
146e0 20 52 4f 57 49 44 3b 5c 6e 22 0a 20 20 20 20 20 ROWID;\n".
146f0 20 20 20 20 22 49 4e 53 45 52 54 20 49 4e 54 4f "INSERT INTO
14700 20 25 73 20 53 45 4c 45 43 54 20 2a 20 46 52 4f %s SELECT * FRO
14710 4d 20 78 5f 25 73 3b 5c 6e 22 0a 20 20 20 20 20 M x_%s;\n".
14720 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45 20 "DROP TABLE
14730 78 5f 25 73 3b 5c 6e 22 2c 0a 20 20 20 20 20 20 x_%s;\n",.
14740 20 20 20 7a 54 4e 61 6d 65 2c 20 7a 54 4e 61 6d zTName, zTNam
14750 65 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6e 65 77 e, blob_str(&new
14760 53 71 6c 29 2c 20 7a 54 4e 61 6d 65 2c 20 7a 54 Sql), zTName, zT
14770 4e 61 6d 65 2c 20 7a 54 4e 61 6d 65 0a 20 20 20 Name, zTName.
14780 20 20 20 29 3b 0a 20 20 20 20 20 20 66 6f 73 73 );. foss
14790 69 6c 5f 70 72 69 6e 74 28 22 43 6f 6e 76 65 72 il_print("Conver
147a0 74 69 6e 67 20 74 61 62 6c 65 20 25 73 20 6f 66 ting table %s of
147b0 20 25 73 20 74 6f 20 57 49 54 48 4f 55 54 20 52 %s to WITHOUT R
147c0 4f 57 49 44 2e 5c 6e 22 2c 20 7a 54 4e 61 6d 65 OWID.\n", zTName
147d0 2c 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 20 20 , g.argv[i]);.
147e0 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 blob_reset(&
147f0 6e 65 77 53 71 6c 29 3b 0a 20 20 20 20 7d 0a 20 newSql);. }.
14800 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
14810 26 61 6c 6c 53 71 6c 2c 20 22 43 4f 4d 4d 49 54 &allSql, "COMMIT
14820 3b 5c 6e 22 29 3b 0a 20 20 20 20 64 62 5f 66 69 ;\n");. db_fi
14830 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 20 nalize(&q);.
14840 69 66 28 20 64 72 79 52 75 6e 20 29 7b 0a 20 20 if( dryRun ){.
14850 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 fossil_print
14860 28 22 53 51 4c 20 74 68 61 74 20 77 6f 75 6c 64 ("SQL that would
14870 20 68 61 76 65 20 62 65 65 6e 20 65 76 61 6c 75 have been evalu
14880 61 74 65 64 3a 5c 6e 22 29 3b 0a 20 20 20 20 20 ated:\n");.
14890 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 2d fossil_print("-
148a0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
148b0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
148c0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
148d0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 5c 6e 22 29 ------------\n")
148e0 3b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 ;. fossil_p
148f0 72 69 6e 74 28 22 25 73 22 2c 20 62 6c 6f 62 5f rint("%s", blob_
14900 73 74 72 28 26 61 6c 6c 53 71 6c 29 29 3b 0a 20 str(&allSql));.
14910 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
14920 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 25 db_multi_exec("%
14930 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 61 6c s", blob_str(&al
14940 6c 53 71 6c 29 29 3b 0a 20 20 20 20 7d 0a 20 20 lSql));. }.
14950 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 61 6c blob_reset(&al
14960 6c 53 71 6c 29 3b 0a 20 20 20 20 64 62 5f 63 6c lSql);. db_cl
14970 6f 73 65 28 31 29 3b 0a 20 20 7d 0a 7d 0a ose(1);. }.}.