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 37 20 44 2e 20 52 69 63 68 (c) 2007 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 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76 lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65 ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 tributed in the
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 l be useful,.**
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 but WITHOUT ANY
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20 RPOSE. See the
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50 GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 d have received
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 ation, Inc., 59
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 ton, MA 02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 307, USA..**.**
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 nformation:.**
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 * http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 contains code u
0380: 73 65 64 20 74 6f 20 6d 61 6e 61 67 65 20 74 61 sed to manage ta
0390: 67 73 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 gs.*/.#include "
03a0: 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 config.h".#inclu
03b0: 64 65 20 22 74 61 67 2e 68 22 0a 23 69 6e 63 6c de "tag.h".#incl
03c0: 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 0a ude <assert.h>..
03d0: 2f 2a 0a 2a 2a 20 50 72 6f 70 61 67 61 74 65 20 /*.** Propagate
03e0: 74 68 65 20 74 61 67 20 67 69 76 65 6e 20 62 79 the tag given by
03f0: 20 74 61 67 69 64 20 74 6f 20 74 68 65 20 63 68 tagid to the ch
0400: 69 6c 64 72 65 6e 20 6f 66 20 70 69 64 2e 0a 2a ildren of pid..*
0410: 2a 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e *.** This routin
0420: 65 20 61 73 73 75 6d 65 73 20 74 68 61 74 20 74 e assumes that t
0430: 61 67 69 64 20 69 73 20 61 20 74 61 67 20 74 68 agid is a tag th
0440: 61 74 20 73 68 6f 75 6c 64 20 62 65 0a 2a 2a 20 at should be.**
0450: 70 72 6f 70 61 67 61 74 65 64 20 61 6e 64 20 74 propagated and t
0460: 68 61 74 20 74 68 65 20 74 61 67 20 69 73 20 61 hat the tag is a
0470: 6c 72 65 61 64 79 20 70 72 65 73 65 6e 74 20 69 lready present i
0480: 6e 20 70 69 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 n pid..**.** If
0490: 61 64 64 46 6c 61 67 20 69 73 20 74 72 75 65 20 addFlag is true
04a0: 74 68 65 6e 20 74 68 65 20 74 61 67 20 69 73 20 then the tag is
04b0: 61 64 64 65 64 2e 20 20 49 66 20 66 61 6c 73 65 added. If false
04c0: 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 74 61 , then the.** ta
04d0: 67 20 69 73 20 72 65 6d 6f 76 65 64 2e 0a 2a 2f g is removed..*/
04e0: 0a 76 6f 69 64 20 74 61 67 5f 70 72 6f 70 61 67 .void tag_propag
04f0: 61 74 65 28 0a 20 20 69 6e 74 20 70 69 64 2c 20 ate(. int pid,
0500: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
0510: 72 6f 70 61 67 61 74 65 20 74 68 65 20 74 61 67 ropagate the tag
0520: 20 74 6f 20 63 68 69 6c 64 72 65 6e 20 6f 66 20 to children of
0530: 74 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 20 69 this node */. i
0540: 6e 74 20 74 61 67 69 64 2c 20 20 20 20 20 20 20 nt tagid,
0550: 20 20 20 20 2f 2a 20 54 61 67 20 74 6f 20 70 72 /* Tag to pr
0560: 6f 70 61 67 61 74 65 20 2a 2f 0a 20 20 69 6e 74 opagate */. int
0570: 20 61 64 64 46 6c 61 67 2c 20 20 20 20 20 20 20 addFlag,
0580: 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 61 64 64 /* True to add
0590: 20 74 68 65 20 74 61 67 2e 20 46 61 6c 73 65 20 the tag. False
05a0: 74 6f 20 64 65 6c 65 74 65 20 69 74 2e 20 2a 2f to delete it. */
05b0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
05c0: 56 61 6c 75 65 2c 20 20 2f 2a 20 56 61 6c 75 65 Value, /* Value
05d0: 20 6f 66 20 74 68 65 20 74 61 67 2e 20 20 4d 69 of the tag. Mi
05e0: 67 68 74 20 62 65 20 4e 55 4c 4c 20 2a 2f 0a 20 ght be NULL */.
05f0: 20 64 6f 75 62 6c 65 20 6d 74 69 6d 65 20 20 20 double mtime
0600: 20 20 20 20 20 20 2f 2a 20 54 69 6d 65 73 74 61 /* Timesta
0610: 6d 70 20 6f 6e 20 74 68 65 20 74 61 67 20 2a 2f mp on the tag */
0620: 0a 29 7b 0a 20 20 50 51 75 65 75 65 20 71 75 65 .){. PQueue que
0630: 75 65 3b 0a 20 20 53 74 6d 74 20 73 2c 20 69 6e ue;. Stmt s, in
0640: 73 2c 20 65 76 65 6e 74 75 70 64 61 74 65 3b 0a s, eventupdate;.
0650: 20 20 70 71 75 65 75 65 5f 69 6e 69 74 28 26 71 pqueue_init(&q
0660: 75 65 75 65 29 3b 0a 20 20 70 71 75 65 75 65 5f ueue);. pqueue_
0670: 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20 70 insert(&queue, p
0680: 69 64 2c 20 30 2e 30 29 3b 0a 20 20 64 62 5f 70 id, 0.0);. db_p
0690: 72 65 70 61 72 65 28 26 73 2c 20 0a 20 20 20 20 repare(&s, .
06a0: 20 22 53 45 4c 45 43 54 20 63 69 64 2c 20 70 6c "SELECT cid, pl
06b0: 69 6e 6b 2e 6d 74 69 6d 65 2c 22 0a 20 20 20 20 ink.mtime,".
06c0: 20 22 20 20 20 20 20 20 20 63 6f 61 6c 65 73 63 " coalesc
06d0: 65 28 73 72 63 69 64 3d 30 20 41 4e 44 20 74 61 e(srcid=0 AND ta
06e0: 67 78 72 65 66 2e 6d 74 69 6d 65 3c 3a 6d 74 69 gxref.mtime<:mti
06f0: 6d 65 2c 20 25 64 29 20 41 53 20 64 6f 69 74 22 me, %d) AS doit"
0700: 0a 20 20 20 20 20 22 20 20 46 52 4f 4d 20 70 6c . " FROM pl
0710: 69 6e 6b 20 4c 45 46 54 20 4a 4f 49 4e 20 74 61 ink LEFT JOIN ta
0720: 67 78 72 65 66 20 4f 4e 20 63 69 64 3d 72 69 64 gxref ON cid=rid
0730: 20 41 4e 44 20 74 61 67 69 64 3d 25 64 22 0a 20 AND tagid=%d".
0740: 20 20 20 20 22 20 57 48 45 52 45 20 70 69 64 3d " WHERE pid=
0750: 3a 70 69 64 20 41 4e 44 20 69 73 70 72 69 6d 22 :pid AND isprim"
0760: 2c 0a 20 20 20 20 20 61 64 64 46 6c 61 67 2c 20 ,. addFlag,
0770: 74 61 67 69 64 0a 20 20 29 3b 0a 20 20 64 62 5f tagid. );. db_
0780: 62 69 6e 64 5f 64 6f 75 62 6c 65 28 26 73 2c 20 bind_double(&s,
0790: 22 3a 6d 74 69 6d 65 22 2c 20 6d 74 69 6d 65 29 ":mtime", mtime)
07a0: 3b 0a 20 20 69 66 28 20 61 64 64 46 6c 61 67 20 ;. if( addFlag
07b0: 29 7b 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 ){. db_prepar
07c0: 65 28 26 69 6e 73 2c 0a 20 20 20 20 20 20 20 22 e(&ins,. "
07d0: 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 74 61 67 REPLACE INTO tag
07e0: 78 72 65 66 28 74 61 67 69 64 2c 20 61 64 64 46 xref(tagid, addF
07f0: 6c 61 67 2c 20 73 72 63 69 64 2c 20 76 61 6c 75 lag, srcid, valu
0800: 65 2c 20 6d 74 69 6d 65 2c 20 72 69 64 29 22 0a e, mtime, rid)".
0810: 20 20 20 20 20 20 20 22 56 41 4c 55 45 53 28 25 "VALUES(%
0820: 64 2c 31 2c 30 2c 25 51 2c 3a 6d 74 69 6d 65 2c d,1,0,%Q,:mtime,
0830: 3a 72 69 64 29 22 2c 0a 20 20 20 20 20 20 20 74 :rid)",. t
0840: 61 67 69 64 2c 20 7a 56 61 6c 75 65 0a 20 20 20 agid, zValue.
0850: 20 29 3b 0a 20 20 20 20 64 62 5f 62 69 6e 64 5f );. db_bind_
0860: 64 6f 75 62 6c 65 28 26 69 6e 73 2c 20 22 3a 6d double(&ins, ":m
0870: 74 69 6d 65 22 2c 20 6d 74 69 6d 65 29 3b 0a 20 time", mtime);.
0880: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 56 61 6c }else{. zVal
0890: 75 65 20 3d 20 30 3b 0a 20 20 20 20 64 62 5f 70 ue = 0;. db_p
08a0: 72 65 70 61 72 65 28 26 69 6e 73 2c 0a 20 20 20 repare(&ins,.
08b0: 20 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d "DELETE FROM
08c0: 20 74 61 67 78 72 65 66 20 57 48 45 52 45 20 74 tagxref WHERE t
08d0: 61 67 69 64 3d 25 64 20 41 4e 44 20 72 69 64 3d agid=%d AND rid=
08e0: 3a 72 69 64 22 2c 20 74 61 67 69 64 0a 20 20 20 :rid", tagid.
08f0: 20 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 74 61 );. }. if( ta
0900: 67 69 64 3d 3d 54 41 47 5f 42 52 5f 42 47 43 4f gid==TAG_BR_BGCO
0910: 4c 4f 52 20 29 7b 0a 20 20 20 20 64 62 5f 70 72 LOR ){. db_pr
0920: 65 70 61 72 65 28 26 65 76 65 6e 74 75 70 64 61 epare(&eventupda
0930: 74 65 2c 0a 20 20 20 20 20 20 22 55 50 44 41 54 te,. "UPDAT
0940: 45 20 65 76 65 6e 74 20 53 45 54 20 62 72 62 67 E event SET brbg
0950: 63 6f 6c 6f 72 3d 25 51 20 57 48 45 52 45 20 6f color=%Q WHERE o
0960: 62 6a 69 64 3d 3a 72 69 64 22 2c 20 7a 56 61 6c bjid=:rid", zVal
0970: 75 65 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 ue. );. }.
0980: 77 68 69 6c 65 28 20 28 70 69 64 20 3d 20 70 71 while( (pid = pq
0990: 75 65 75 65 5f 65 78 74 72 61 63 74 28 26 71 75 ueue_extract(&qu
09a0: 65 75 65 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 eue))!=0 ){.
09b0: 64 62 5f 62 69 6e 64 5f 69 6e 74 28 26 73 2c 20 db_bind_int(&s,
09c0: 22 3a 70 69 64 22 2c 20 70 69 64 29 3b 0a 20 20 ":pid", pid);.
09d0: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 while( db_step
09e0: 28 26 73 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 (&s)==SQLITE_ROW
09f0: 20 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 64 6f ){. int do
0a00: 69 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 it = db_column_i
0a10: 6e 74 28 26 73 2c 20 32 29 3b 0a 20 20 20 20 20 nt(&s, 2);.
0a20: 20 69 66 28 20 64 6f 69 74 20 29 7b 0a 20 20 20 if( doit ){.
0a30: 20 20 20 20 20 69 6e 74 20 63 69 64 20 3d 20 64 int cid = d
0a40: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 73 2c b_column_int(&s,
0a50: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 64 6f 75 0);. dou
0a60: 62 6c 65 20 6d 74 69 6d 65 20 3d 20 64 62 5f 63 ble mtime = db_c
0a70: 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65 28 26 73 2c olumn_double(&s,
0a80: 20 31 29 3b 0a 20 20 20 20 20 20 20 20 70 71 75 1);. pqu
0a90: 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75 65 75 eue_insert(&queu
0aa0: 65 2c 20 63 69 64 2c 20 6d 74 69 6d 65 29 3b 0a e, cid, mtime);.
0ab0: 20 20 20 20 20 20 20 20 64 62 5f 62 69 6e 64 5f db_bind_
0ac0: 69 6e 74 28 26 69 6e 73 2c 20 22 3a 72 69 64 22 int(&ins, ":rid"
0ad0: 2c 20 63 69 64 29 3b 0a 20 20 20 20 20 20 20 20 , cid);.
0ae0: 64 62 5f 73 74 65 70 28 26 69 6e 73 29 3b 0a 20 db_step(&ins);.
0af0: 20 20 20 20 20 20 20 64 62 5f 72 65 73 65 74 28 db_reset(
0b00: 26 69 6e 73 29 3b 0a 20 20 20 20 20 20 20 20 69 &ins);. i
0b10: 66 28 20 74 61 67 69 64 3d 3d 54 41 47 5f 42 52 f( tagid==TAG_BR
0b20: 5f 42 47 43 4f 4c 4f 52 20 29 7b 0a 20 20 20 20 _BGCOLOR ){.
0b30: 20 20 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e db_bind_in
0b40: 74 28 26 65 76 65 6e 74 75 70 64 61 74 65 2c 20 t(&eventupdate,
0b50: 22 3a 72 69 64 22 2c 20 63 69 64 29 3b 0a 20 20 ":rid", cid);.
0b60: 20 20 20 20 20 20 20 20 64 62 5f 73 74 65 70 28 db_step(
0b70: 26 65 76 65 6e 74 75 70 64 61 74 65 29 3b 0a 20 &eventupdate);.
0b80: 20 20 20 20 20 20 20 20 20 64 62 5f 72 65 73 65 db_rese
0b90: 74 28 26 65 76 65 6e 74 75 70 64 61 74 65 29 3b t(&eventupdate);
0ba0: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
0bb0: 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 5f }. }. db_
0bc0: 72 65 73 65 74 28 26 73 29 3b 0a 20 20 7d 0a 20 reset(&s);. }.
0bd0: 20 70 71 75 65 75 65 5f 63 6c 65 61 72 28 26 71 pqueue_clear(&q
0be0: 75 65 75 65 29 3b 0a 20 20 64 62 5f 66 69 6e 61 ueue);. db_fina
0bf0: 6c 69 7a 65 28 26 69 6e 73 29 3b 0a 20 20 64 62 lize(&ins);. db
0c00: 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 20 _finalize(&s);.
0c10: 20 69 66 28 20 74 61 67 69 64 3d 3d 54 41 47 5f if( tagid==TAG_
0c20: 42 52 5f 42 47 43 4f 4c 4f 52 20 29 7b 0a 20 20 BR_BGCOLOR ){.
0c30: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 65 db_finalize(&e
0c40: 76 65 6e 74 75 70 64 61 74 65 29 3b 0a 20 20 7d ventupdate);. }
0c50: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 70 61 67 .}../*.** Propag
0c60: 61 74 65 20 61 6c 6c 20 70 72 6f 70 61 67 61 74 ate all propagat
0c70: 61 62 6c 65 20 74 61 67 73 20 69 6e 20 70 69 64 able tags in pid
0c80: 20 74 6f 20 69 74 73 20 63 68 69 6c 64 72 65 6e to its children
0c90: 2e 0a 2a 2f 0a 76 6f 69 64 20 74 61 67 5f 70 72 ..*/.void tag_pr
0ca0: 6f 70 61 67 61 74 65 5f 61 6c 6c 28 69 6e 74 20 opagate_all(int
0cb0: 70 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a pid){. Stmt q;.
0cc0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c db_prepare(&q,
0cd0: 0a 20 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 . "SELECT ta
0ce0: 67 69 64 2c 20 61 64 64 66 6c 61 67 2c 20 6d 74 gid, addflag, mt
0cf0: 69 6d 65 2c 20 76 61 6c 75 65 20 46 52 4f 4d 20 ime, value FROM
0d00: 74 61 67 78 72 65 66 22 0a 20 20 20 20 20 22 20 tagxref". "
0d10: 57 48 45 52 45 20 72 69 64 3d 25 64 22 0a 20 20 WHERE rid=%d".
0d20: 20 20 20 22 20 20 20 41 4e 44 20 28 53 45 4c 45 " AND (SELE
0d30: 43 54 20 74 61 67 6e 61 6d 65 20 46 52 4f 4d 20 CT tagname FROM
0d40: 74 61 67 20 57 48 45 52 45 20 74 61 67 69 64 3d tag WHERE tagid=
0d50: 74 61 67 78 72 65 66 2e 74 61 67 69 64 29 20 4c tagxref.tagid) L
0d60: 49 4b 45 20 27 62 72 25 27 22 2c 0a 20 20 20 20 IKE 'br%'",.
0d70: 20 70 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c pid. );. whil
0d80: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
0d90: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
0da0: 20 20 69 6e 74 20 74 61 67 69 64 20 3d 20 64 62 int tagid = db
0db0: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 _column_int(&q,
0dc0: 30 29 3b 0a 20 20 20 20 69 6e 74 20 61 64 64 66 0);. int addf
0dd0: 6c 61 67 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f lag = db_column_
0de0: 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 int(&q, 1);.
0df0: 64 6f 75 62 6c 65 20 6d 74 69 6d 65 20 3d 20 64 double mtime = d
0e00: 62 5f 63 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65 28 b_column_double(
0e10: 26 71 2c 20 32 29 3b 0a 20 20 20 20 63 6f 6e 73 &q, 2);. cons
0e20: 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 20 3d t char *zValue =
0e30: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
0e40: 26 71 2c 20 33 29 3b 0a 20 20 20 20 74 61 67 5f &q, 3);. tag_
0e50: 70 72 6f 70 61 67 61 74 65 28 70 69 64 2c 20 74 propagate(pid, t
0e60: 61 67 69 64 2c 20 61 64 64 66 6c 61 67 2c 20 7a agid, addflag, z
0e70: 56 61 6c 75 65 2c 20 6d 74 69 6d 65 29 3b 0a 20 Value, mtime);.
0e80: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
0e90: 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 47 (&q);.}../*.** G
0ea0: 65 74 20 61 20 74 61 67 69 64 20 66 6f 72 20 74 et a tagid for t
0eb0: 68 65 20 67 69 76 65 6e 20 54 41 47 2e 20 20 43 he given TAG. C
0ec0: 72 65 61 74 65 20 61 20 6e 65 77 20 74 61 67 20 reate a new tag
0ed0: 69 66 20 6e 65 63 65 73 73 61 72 79 0a 2a 2a 20 if necessary.**
0ee0: 69 66 20 63 72 65 61 74 65 46 6c 61 67 20 69 73 if createFlag is
0ef0: 20 31 2e 0a 2a 2f 0a 69 6e 74 20 74 61 67 5f 66 1..*/.int tag_f
0f00: 69 6e 64 69 64 28 63 6f 6e 73 74 20 63 68 61 72 indid(const char
0f10: 20 2a 7a 54 61 67 2c 20 69 6e 74 20 63 72 65 61 *zTag, int crea
0f20: 74 65 46 6c 61 67 29 7b 0a 20 20 69 6e 74 20 69 teFlag){. int i
0f30: 64 3b 0a 20 20 69 64 20 3d 20 64 62 5f 69 6e 74 d;. id = db_int
0f40: 28 30 2c 20 22 53 45 4c 45 43 54 20 74 61 67 69 (0, "SELECT tagi
0f50: 64 20 46 52 4f 4d 20 74 61 67 20 57 48 45 52 45 d FROM tag WHERE
0f60: 20 74 61 67 6e 61 6d 65 3d 25 51 22 2c 20 7a 54 tagname=%Q", zT
0f70: 61 67 29 3b 0a 20 20 69 66 28 20 69 64 3d 3d 30 ag);. if( id==0
0f80: 20 26 26 20 63 72 65 61 74 65 46 6c 61 67 20 29 && createFlag )
0f90: 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 {. db_multi_e
0fa0: 78 65 63 28 22 49 4e 53 45 52 54 20 49 4e 54 4f xec("INSERT INTO
0fb0: 20 74 61 67 28 74 61 67 6e 61 6d 65 29 20 56 41 tag(tagname) VA
0fc0: 4c 55 45 53 28 25 51 29 22 2c 20 7a 54 61 67 29 LUES(%Q)", zTag)
0fd0: 3b 0a 20 20 20 20 69 64 20 3d 20 64 62 5f 6c 61 ;. id = db_la
0fe0: 73 74 5f 69 6e 73 65 72 74 5f 72 6f 77 69 64 28 st_insert_rowid(
0ff0: 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 );. }. return
1000: 69 64 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 6e 73 id;.}../*.** Ins
1010: 65 72 74 20 61 20 74 61 67 20 69 6e 74 6f 20 74 ert a tag into t
1020: 68 65 20 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a he database..*/.
1030: 76 6f 69 64 20 74 61 67 5f 69 6e 73 65 72 74 28 void tag_insert(
1040: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
1050: 54 61 67 2c 20 20 20 20 20 20 20 20 2f 2a 20 4e Tag, /* N
1060: 61 6d 65 20 6f 66 20 74 68 65 20 74 61 67 20 28 ame of the tag (
1070: 77 2f 6f 20 74 68 65 20 22 2b 22 20 6f 72 20 22 w/o the "+" or "
1080: 2d 22 20 70 72 65 66 69 78 20 2a 2f 0a 20 20 69 -" prefix */. i
1090: 6e 74 20 61 64 64 46 6c 61 67 2c 20 20 20 20 20 nt addFlag,
10a0: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
10b0: 74 6f 20 61 64 64 2e 20 20 46 61 6c 73 65 20 74 to add. False t
10c0: 6f 20 72 65 6d 6f 76 65 20 2a 2f 0a 20 20 63 6f o remove */. co
10d0: 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 nst char *zValue
10e0: 2c 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 , /* Value
10f0: 69 66 20 74 68 65 20 74 61 67 20 69 73 20 72 65 if the tag is re
1100: 61 6c 6c 79 20 61 20 70 72 6f 70 65 72 74 79 20 ally a property
1110: 2a 2f 0a 20 20 69 6e 74 20 73 72 63 49 64 2c 20 */. int srcId,
1120: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1130: 20 41 72 74 69 66 61 63 74 20 74 68 61 74 20 63 Artifact that c
1140: 6f 6e 74 61 69 6e 73 20 74 68 69 73 20 74 61 67 ontains this tag
1150: 20 2a 2f 0a 20 20 64 6f 75 62 6c 65 20 6d 74 69 */. double mti
1160: 6d 65 2c 20 20 20 20 20 20 20 20 20 20 20 20 2f me, /
1170: 2a 20 54 69 6d 65 73 74 61 6d 70 2e 20 20 55 73 * Timestamp. Us
1180: 65 20 64 65 66 61 75 6c 74 20 69 66 20 3c 3d 30 e default if <=0
1190: 2e 30 20 2a 2f 0a 20 20 69 6e 74 20 72 69 64 20 .0 */. int rid
11a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11b0: 20 2f 2a 20 41 72 74 69 66 61 63 74 20 74 6f 20 /* Artifact to
11c0: 77 68 69 63 68 20 74 68 65 20 74 61 67 20 69 73 which the tag is
11d0: 20 74 6f 20 61 74 74 61 63 68 65 64 20 2a 2f 0a to attached */.
11e0: 29 7b 0a 20 20 53 74 6d 74 20 73 3b 0a 20 20 69 ){. Stmt s;. i
11f0: 6e 74 20 74 61 67 69 64 20 3d 20 74 61 67 5f 66 nt tagid = tag_f
1200: 69 6e 64 69 64 28 7a 54 61 67 2c 20 31 29 3b 0a indid(zTag, 1);.
1210: 20 20 69 66 28 20 6d 74 69 6d 65 3c 3d 30 2e 30 if( mtime<=0.0
1220: 20 29 7b 0a 20 20 20 20 6d 74 69 6d 65 20 3d 20 ){. mtime =
1230: 64 62 5f 64 6f 75 62 6c 65 28 30 2e 30 2c 20 22 db_double(0.0, "
1240: 53 45 4c 45 43 54 20 6a 75 6c 69 61 6e 64 61 79 SELECT julianday
1250: 28 27 6e 6f 77 27 29 22 29 3b 0a 20 20 7d 0a 20 ('now')");. }.
1260: 20 64 62 5f 70 72 65 70 61 72 65 28 26 73 2c 20 db_prepare(&s,
1270: 0a 20 20 20 20 22 52 45 50 4c 41 43 45 20 49 4e . "REPLACE IN
1280: 54 4f 20 74 61 67 78 72 65 66 28 74 61 67 69 64 TO tagxref(tagid
1290: 2c 61 64 64 46 6c 61 67 2c 73 72 63 49 64 2c 76 ,addFlag,srcId,v
12a0: 61 6c 75 65 2c 6d 74 69 6d 65 2c 72 69 64 29 22 alue,mtime,rid)"
12b0: 0a 20 20 20 20 22 20 56 41 4c 55 45 53 28 25 64 . " VALUES(%d
12c0: 2c 25 64 2c 25 64 2c 25 51 2c 3a 6d 74 69 6d 65 ,%d,%d,%Q,:mtime
12d0: 2c 25 64 29 22 2c 0a 20 20 20 20 74 61 67 69 64 ,%d)",. tagid
12e0: 2c 20 61 64 64 46 6c 61 67 2c 20 73 72 63 49 64 , addFlag, srcId
12f0: 2c 20 7a 56 61 6c 75 65 2c 20 72 69 64 0a 20 20 , zValue, rid.
1300: 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64 6f 75 );. db_bind_dou
1310: 62 6c 65 28 26 73 2c 20 22 3a 6d 74 69 6d 65 22 ble(&s, ":mtime"
1320: 2c 20 6d 74 69 6d 65 29 3b 0a 20 20 64 62 5f 73 , mtime);. db_s
1330: 74 65 70 28 26 73 29 3b 0a 20 20 64 62 5f 66 69 tep(&s);. db_fi
1340: 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 20 20 69 66 nalize(&s);. if
1350: 28 20 61 64 64 46 6c 61 67 3d 3d 30 20 29 7b 0a ( addFlag==0 ){.
1360: 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 30 3b 0a zValue = 0;.
1370: 20 20 7d 0a 20 20 73 77 69 74 63 68 28 20 74 61 }. switch( ta
1380: 67 69 64 20 29 7b 0a 20 20 20 20 63 61 73 65 20 gid ){. case
1390: 54 41 47 5f 42 47 43 4f 4c 4f 52 3a 20 7b 0a 20 TAG_BGCOLOR: {.
13a0: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 db_multi_ex
13b0: 65 63 28 22 55 50 44 41 54 45 20 65 76 65 6e 74 ec("UPDATE event
13c0: 20 53 45 54 20 62 67 63 6f 6c 6f 72 3d 25 51 20 SET bgcolor=%Q
13d0: 57 48 45 52 45 20 6f 62 6a 69 64 3d 25 64 22 2c WHERE objid=%d",
13e0: 20 7a 56 61 6c 75 65 2c 20 72 69 64 29 3b 0a 20 zValue, rid);.
13f0: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
1400: 7d 0a 20 20 20 20 63 61 73 65 20 54 41 47 5f 42 }. case TAG_B
1410: 52 5f 42 47 43 4f 4c 4f 52 3a 20 7b 0a 20 20 20 R_BGCOLOR: {.
1420: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 db_multi_exec
1430: 28 22 55 50 44 41 54 45 20 65 76 65 6e 74 20 53 ("UPDATE event S
1440: 45 54 20 62 72 62 67 63 6f 6c 6f 72 3d 25 51 20 ET brbgcolor=%Q
1450: 57 48 45 52 45 20 6f 62 6a 69 64 3d 25 64 22 2c WHERE objid=%d",
1460: 20 7a 56 61 6c 75 65 2c 72 69 64 29 3b 0a 20 20 zValue,rid);.
1470: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d break;. }
1480: 0a 20 20 20 20 63 61 73 65 20 54 41 47 5f 43 4f . case TAG_CO
1490: 4d 4d 45 4e 54 3a 20 7b 0a 20 20 20 20 20 20 64 MMENT: {. d
14a0: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 55 50 b_multi_exec("UP
14b0: 44 41 54 45 20 65 76 65 6e 74 20 53 45 54 20 65 DATE event SET e
14c0: 63 6f 6d 6d 65 6e 74 3d 25 51 20 57 48 45 52 45 comment=%Q WHERE
14d0: 20 6f 62 6a 69 64 3d 25 64 22 2c 20 7a 56 61 6c objid=%d", zVal
14e0: 75 65 2c 20 72 69 64 29 3b 0a 20 20 20 20 20 20 ue, rid);.
14f0: 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 break;. }.
1500: 20 63 61 73 65 20 54 41 47 5f 55 53 45 52 3a 20 case TAG_USER:
1510: 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 {. db_multi
1520: 5f 65 78 65 63 28 22 55 50 44 41 54 45 20 65 76 _exec("UPDATE ev
1530: 65 6e 74 20 53 45 54 20 65 75 73 65 72 3d 25 51 ent SET euser=%Q
1540: 20 57 48 45 52 45 20 6f 62 6a 69 64 3d 25 64 22 WHERE objid=%d"
1550: 2c 20 7a 56 61 6c 75 65 2c 20 72 69 64 29 3b 0a , zValue, rid);.
1560: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 break;.
1570: 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 73 74 72 }. }. if( str
1580: 6e 63 6d 70 28 7a 54 61 67 2c 20 22 62 72 22 2c ncmp(zTag, "br",
1590: 20 32 29 3d 3d 30 20 29 7b 0a 20 20 20 20 74 61 2)==0 ){. ta
15a0: 67 5f 70 72 6f 70 61 67 61 74 65 28 72 69 64 2c g_propagate(rid,
15b0: 20 74 61 67 69 64 2c 20 61 64 64 46 6c 61 67 2c tagid, addFlag,
15c0: 20 7a 56 61 6c 75 65 2c 20 6d 74 69 6d 65 29 3b zValue, mtime);
15d0: 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 . }.}.../*.** C
15e0: 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 61 64 64 OMMAND: test-add
15f0: 74 61 67 0a 2a 2a 20 25 66 6f 73 73 69 6c 20 74 tag.** %fossil t
1600: 65 73 74 2d 61 64 64 74 61 67 20 54 41 47 4e 41 est-addtag TAGNA
1610: 4d 45 20 55 55 49 44 20 3f 56 41 4c 55 45 3f 0a ME UUID ?VALUE?.
1620: 2a 2a 0a 2a 2a 20 41 64 64 20 61 20 74 61 67 20 **.** Add a tag
1630: 74 6f 20 74 68 65 20 72 65 62 75 69 6c 64 61 62 to the rebuildab
1640: 6c 65 20 74 61 62 6c 65 73 20 6f 66 20 74 68 65 le tables of the
1650: 20 6c 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f 72 local repositor
1660: 79 2e 0a 2a 2a 20 4e 6f 20 74 61 67 20 61 72 74 y..** No tag art
1670: 69 66 61 63 74 20 69 73 20 63 72 65 61 74 65 64 ifact is created
1680: 20 73 6f 20 74 68 65 20 6e 65 77 20 74 61 67 20 so the new tag
1690: 69 73 20 65 72 61 73 65 64 20 74 68 65 20 6e 65 is erased the ne
16a0: 78 74 0a 2a 2a 20 74 69 6d 65 20 74 68 65 20 72 xt.** time the r
16b0: 65 70 6f 73 69 74 6f 72 79 20 69 73 20 72 65 62 epository is reb
16c0: 75 69 6c 74 2e 20 20 54 68 69 73 20 72 6f 75 74 uilt. This rout
16d0: 69 6e 65 20 69 73 20 66 6f 72 20 74 65 73 74 69 ine is for testi
16e0: 6e 67 0a 2a 2a 20 75 73 65 20 6f 6e 6c 79 2e 0a ng.** use only..
16f0: 2a 2f 0a 76 6f 69 64 20 61 64 64 74 61 67 5f 63 */.void addtag_c
1700: 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 md(void){. cons
1710: 74 20 63 68 61 72 20 2a 7a 54 61 67 3b 0a 20 20 t char *zTag;.
1720: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c const char *zVal
1730: 75 65 3b 0a 20 20 69 6e 74 20 72 69 64 3b 0a 20 ue;. int rid;.
1740: 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 db_must_be_with
1750: 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 69 66 28 in_tree();. if(
1760: 20 67 2e 61 72 67 63 21 3d 34 20 26 26 20 67 2e g.argc!=4 && g.
1770: 61 72 67 63 21 3d 35 20 29 7b 0a 20 20 20 20 75 argc!=5 ){. u
1780: 73 61 67 65 28 22 54 41 47 4e 41 4d 45 20 55 55 sage("TAGNAME UU
1790: 49 44 20 3f 56 41 4c 55 45 3f 22 29 3b 0a 20 20 ID ?VALUE?");.
17a0: 7d 0a 20 20 7a 54 61 67 20 3d 20 67 2e 61 72 67 }. zTag = g.arg
17b0: 76 5b 32 5d 3b 0a 20 20 72 69 64 20 3d 20 6e 61 v[2];. rid = na
17c0: 6d 65 5f 74 6f 5f 72 69 64 28 67 2e 61 72 67 76 me_to_rid(g.argv
17d0: 5b 33 5d 29 3b 0a 20 20 69 66 28 20 72 69 64 3d [3]);. if( rid=
17e0: 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c =0 ){. fossil
17f0: 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 _fatal("no such
1800: 6f 62 6a 65 63 74 3a 20 25 73 22 2c 20 67 2e 61 object: %s", g.a
1810: 72 67 76 5b 33 5d 29 3b 0a 20 20 7d 0a 20 20 7a rgv[3]);. }. z
1820: 56 61 6c 75 65 20 3d 20 67 2e 61 72 67 63 3d 3d Value = g.argc==
1830: 35 20 3f 20 67 2e 61 72 67 76 5b 34 5d 20 3a 20 5 ? g.argv[4] :
1840: 30 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 0;. db_begin_tr
1850: 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 74 ansaction();. t
1860: 61 67 5f 69 6e 73 65 72 74 28 7a 54 61 67 2c 20 ag_insert(zTag,
1870: 31 2c 20 7a 56 61 6c 75 65 2c 20 2d 31 2c 20 30 1, zValue, -1, 0
1880: 2e 30 2c 20 72 69 64 29 3b 0a 20 20 64 62 5f 65 .0, rid);. db_e
1890: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 nd_transaction(0
18a0: 29 3b 20 0a 7d 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d ); .}./*.** COMM
18b0: 41 4e 44 3a 20 74 65 73 74 2d 64 65 6c 74 61 67 AND: test-deltag
18c0: 0a 2a 2a 20 25 66 6f 73 73 69 6c 20 74 65 73 74 .** %fossil test
18d0: 2d 64 65 6c 74 61 67 20 54 41 47 4e 41 4d 45 20 -deltag TAGNAME
18e0: 55 55 49 44 0a 2a 2a 0a 2a 2a 20 43 61 6e 63 65 UUID.**.** Cance
18f0: 6c 20 61 20 74 61 67 20 74 6f 20 74 68 65 20 72 l a tag to the r
1900: 65 62 75 69 6c 64 61 62 6c 65 20 74 61 62 6c 65 ebuildable table
1910: 73 20 6f 66 20 74 68 65 20 6c 6f 63 61 6c 20 72 s of the local r
1920: 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 20 4e 6f epository..** No
1930: 20 74 61 67 20 61 72 74 69 66 61 63 74 20 69 73 tag artifact is
1940: 20 63 72 65 61 74 65 64 20 73 6f 20 74 68 65 20 created so the
1950: 63 61 6e 63 65 6c 6c 61 74 69 6f 6e 20 69 73 20 cancellation is
1960: 75 6e 64 6f 6e 65 20 74 68 65 20 6e 65 78 74 0a undone the next.
1970: 2a 2a 20 74 69 6d 65 20 74 68 65 20 72 65 70 6f ** time the repo
1980: 73 69 74 6f 72 79 20 69 73 20 72 65 62 75 69 6c sitory is rebuil
1990: 74 2e 20 20 54 68 69 73 20 72 6f 75 74 69 6e 65 t. This routine
19a0: 20 69 73 20 66 6f 72 20 74 65 73 74 69 6e 67 0a is for testing.
19b0: 2a 2a 20 75 73 65 20 6f 6e 6c 79 2e 0a 2a 2f 0a ** use only..*/.
19c0: 76 6f 69 64 20 64 65 6c 74 61 67 5f 63 6d 64 28 void deltag_cmd(
19d0: 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 void){. const c
19e0: 68 61 72 20 2a 7a 54 61 67 3b 0a 20 20 69 6e 74 har *zTag;. int
19f0: 20 72 69 64 3b 0a 20 20 64 62 5f 6d 75 73 74 5f rid;. db_must_
1a00: 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 be_within_tree()
1a10: 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d ;. if( g.argc!=
1a20: 34 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 4 ){. usage("
1a30: 54 41 47 4e 41 4d 45 20 55 55 49 44 22 29 3b 0a TAGNAME UUID");.
1a40: 20 20 7d 0a 20 20 7a 54 61 67 20 3d 20 67 2e 61 }. zTag = g.a
1a50: 72 67 76 5b 32 5d 3b 0a 20 20 72 69 64 20 3d 20 rgv[2];. rid =
1a60: 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 67 2e 61 72 name_to_rid(g.ar
1a70: 67 76 5b 33 5d 29 3b 0a 20 20 69 66 28 20 72 69 gv[3]);. if( ri
1a80: 64 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 d==0 ){. foss
1a90: 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 il_fatal("no suc
1aa0: 68 20 6f 62 6a 65 63 74 3a 20 25 73 22 2c 20 67 h object: %s", g
1ab0: 2e 61 72 67 76 5b 33 5d 29 3b 0a 20 20 7d 0a 20 .argv[3]);. }.
1ac0: 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 db_begin_transa
1ad0: 63 74 69 6f 6e 28 29 3b 0a 20 20 74 61 67 5f 69 ction();. tag_i
1ae0: 6e 73 65 72 74 28 7a 54 61 67 2c 20 30 2c 20 30 nsert(zTag, 0, 0
1af0: 2c 20 2d 31 2c 20 30 2e 30 2c 20 72 69 64 29 3b , -1, 0.0, rid);
1b00: 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 . db_end_transa
1b10: 63 74 69 6f 6e 28 30 29 3b 20 0a 7d 0a 0a 2f 2a ction(0); .}../*
1b20: 0a 2a 2a 20 41 64 64 20 61 20 63 6f 6e 74 72 6f .** Add a contro
1b30: 6c 20 72 65 63 6f 72 64 20 74 6f 20 74 68 65 20 l record to the
1b40: 72 65 70 6f 73 69 74 6f 72 79 20 74 68 61 74 20 repository that
1b50: 65 69 74 68 65 72 20 63 72 65 61 74 65 73 0a 2a either creates.*
1b60: 2a 20 6f 72 20 63 61 6e 63 65 6c 73 20 61 20 74 * or cancels a t
1b70: 61 67 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f ag..*/.static vo
1b80: 69 64 20 74 61 67 5f 61 64 64 5f 61 72 74 69 66 id tag_add_artif
1b90: 61 63 74 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 act(. const cha
1ba0: 72 20 2a 7a 54 61 67 6e 61 6d 65 2c 20 20 20 20 r *zTagname,
1bb0: 20 20 20 2f 2a 20 54 68 65 20 74 61 67 20 74 6f /* The tag to
1bc0: 20 61 64 64 20 6f 72 20 63 61 6e 63 65 6c 20 2a add or cancel *
1bd0: 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
1be0: 7a 4f 62 6a 4e 61 6d 65 2c 20 20 20 20 20 20 20 zObjName,
1bf0: 2f 2a 20 4e 61 6d 65 20 6f 66 20 6f 62 6a 65 63 /* Name of objec
1c00: 74 20 61 74 74 61 63 68 65 64 20 74 6f 20 2a 2f t attached to */
1c10: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
1c20: 56 61 6c 75 65 2c 20 20 20 20 20 20 20 20 20 2f Value, /
1c30: 2a 20 56 61 6c 75 65 20 66 6f 72 20 74 68 65 20 * Value for the
1c40: 74 61 67 2e 20 20 4d 69 67 68 74 20 62 65 20 4e tag. Might be N
1c50: 55 4c 4c 20 2a 2f 0a 20 20 69 6e 74 20 61 64 64 ULL */. int add
1c60: 46 6c 61 67 20 20 20 20 20 20 20 20 20 20 20 20 Flag
1c70: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 /* True to
1c80: 61 64 64 2e 20 20 66 61 6c 73 65 20 74 6f 20 63 add. false to c
1c90: 61 6e 63 65 6c 20 2a 2f 0a 29 7b 0a 20 20 69 6e ancel */.){. in
1ca0: 74 20 72 69 64 3b 0a 20 20 69 6e 74 20 6e 72 69 t rid;. int nri
1cb0: 64 3b 0a 20 20 63 68 61 72 20 2a 7a 44 61 74 65 d;. char *zDate
1cc0: 3b 0a 20 20 42 6c 6f 62 20 75 75 69 64 3b 0a 20 ;. Blob uuid;.
1cd0: 20 42 6c 6f 62 20 63 74 72 6c 3b 0a 20 20 42 6c Blob ctrl;. Bl
1ce0: 6f 62 20 63 6b 73 75 6d 3b 0a 0a 20 20 75 73 65 ob cksum;.. use
1cf0: 72 5f 73 65 6c 65 63 74 28 29 3b 0a 20 20 72 69 r_select();. ri
1d00: 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 d = name_to_rid(
1d10: 7a 4f 62 6a 4e 61 6d 65 29 3b 0a 20 20 62 6c 6f zObjName);. blo
1d20: 62 5f 7a 65 72 6f 28 26 75 75 69 64 29 3b 0a 20 b_zero(&uuid);.
1d30: 20 64 62 5f 62 6c 6f 62 28 26 75 75 69 64 2c 20 db_blob(&uuid,
1d40: 22 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f "SELECT uuid FRO
1d50: 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 M blob WHERE rid
1d60: 3d 25 64 22 2c 20 72 69 64 29 3b 0a 20 20 62 6c =%d", rid);. bl
1d70: 6f 62 5f 7a 65 72 6f 28 26 63 74 72 6c 29 3b 0a ob_zero(&ctrl);.
1d80: 20 20 0a 20 20 69 66 28 20 76 61 6c 69 64 61 74 . if( validat
1d90: 65 31 36 28 7a 54 61 67 6e 61 6d 65 2c 20 73 74 e16(zTagname, st
1da0: 72 6c 65 6e 28 7a 54 61 67 6e 61 6d 65 29 29 20 rlen(zTagname))
1db0: 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 ){. fossil_fa
1dc0: 74 61 6c 28 22 69 6e 76 61 6c 69 64 20 74 61 67 tal("invalid tag
1dd0: 20 6e 61 6d 65 20 5c 22 25 73 5c 22 20 2d 20 6d name \"%s\" - m
1de0: 69 67 68 74 20 62 65 20 63 6f 6e 66 75 73 65 64 ight be confused
1df0: 20 77 69 74 68 20 61 20 55 55 49 44 22 2c 0a 20 with a UUID",.
1e00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e10: 7a 54 61 67 6e 61 6d 65 29 3b 0a 20 20 7d 0a 20 zTagname);. }.
1e20: 20 7a 44 61 74 65 20 3d 20 64 62 5f 74 65 78 74 zDate = db_text
1e30: 28 30 2c 20 22 53 45 4c 45 43 54 20 64 61 74 65 (0, "SELECT date
1e40: 74 69 6d 65 28 27 6e 6f 77 27 29 22 29 3b 0a 20 time('now')");.
1e50: 20 7a 44 61 74 65 5b 31 30 5d 20 3d 20 27 54 27 zDate[10] = 'T'
1e60: 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 ;. blob_appendf
1e70: 28 26 63 74 72 6c 2c 20 22 44 20 25 73 5c 6e 22 (&ctrl, "D %s\n"
1e80: 2c 20 7a 44 61 74 65 29 3b 0a 20 20 62 6c 6f 62 , zDate);. blob
1e90: 5f 61 70 70 65 6e 64 66 28 26 63 74 72 6c 2c 20 _appendf(&ctrl,
1ea0: 22 54 20 25 63 25 46 20 25 62 22 2c 20 61 64 64 "T %c%F %b", add
1eb0: 46 6c 61 67 20 3f 20 27 2b 27 20 3a 20 27 2d 27 Flag ? '+' : '-'
1ec0: 2c 20 7a 54 61 67 6e 61 6d 65 2c 20 26 75 75 69 , zTagname, &uui
1ed0: 64 29 3b 0a 20 20 69 66 28 20 61 64 64 46 6c 61 d);. if( addFla
1ee0: 67 20 26 26 20 7a 56 61 6c 75 65 20 26 26 20 7a g && zValue && z
1ef0: 56 61 6c 75 65 5b 30 5d 20 29 7b 0a 20 20 20 20 Value[0] ){.
1f00: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 74 blob_appendf(&ct
1f10: 72 6c 2c 20 22 20 25 46 5c 6e 22 2c 20 7a 56 61 rl, " %F\n", zVa
1f20: 6c 75 65 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 lue);. }else{.
1f30: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
1f40: 26 63 74 72 6c 2c 20 22 5c 6e 22 29 3b 0a 20 20 &ctrl, "\n");.
1f50: 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 }. blob_appendf
1f60: 28 26 63 74 72 6c 2c 20 22 55 20 25 46 5c 6e 22 (&ctrl, "U %F\n"
1f70: 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 6d , g.zLogin);. m
1f80: 64 35 73 75 6d 5f 62 6c 6f 62 28 26 63 74 72 6c d5sum_blob(&ctrl
1f90: 2c 20 26 63 6b 73 75 6d 29 3b 0a 20 20 62 6c 6f , &cksum);. blo
1fa0: 62 5f 61 70 70 65 6e 64 66 28 26 63 74 72 6c 2c b_appendf(&ctrl,
1fb0: 20 22 5a 20 25 62 5c 6e 22 2c 20 26 63 6b 73 75 "Z %b\n", &cksu
1fc0: 6d 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 m);. db_begin_t
1fd0: 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 ransaction();.
1fe0: 6e 72 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 70 nrid = content_p
1ff0: 75 74 28 26 63 74 72 6c 2c 20 30 2c 20 30 29 3b ut(&ctrl, 0, 0);
2000: 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 72 6f 73 . manifest_cros
2010: 73 6c 69 6e 6b 28 6e 72 69 64 2c 20 26 63 74 72 slink(nrid, &ctr
2020: 6c 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 l);. db_end_tra
2030: 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a nsaction(0);.}..
2040: 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 74 /*.** COMMAND: t
2050: 61 67 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f ag.** Usage: %fo
2060: 73 73 69 6c 20 74 61 67 20 53 55 42 43 4f 4d 4d ssil tag SUBCOMM
2070: 41 4e 44 20 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 52 75 AND ....**.** Ru
2080: 6e 20 76 61 72 69 6f 75 73 20 73 75 62 63 6f 6d n various subcom
2090: 6d 61 6e 64 73 20 74 6f 20 63 6f 6e 74 72 6f 6c mands to control
20a0: 20 74 61 67 73 20 61 6e 64 20 70 72 6f 70 65 72 tags and proper
20b0: 74 69 65 73 0a 2a 2a 0a 2a 2a 20 20 20 20 20 25 ties.**.** %
20c0: 66 6f 73 73 69 6c 20 74 61 67 20 61 64 64 20 54 fossil tag add T
20d0: 41 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 41 4c AGNAME UUID ?VAL
20e0: 55 45 3f 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 UE?.**.**
20f0: 20 20 41 64 64 20 61 20 6e 65 77 20 74 61 67 20 Add a new tag
2100: 6f 72 20 70 72 6f 70 65 72 74 79 20 74 6f 20 55 or property to U
2110: 55 49 44 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 25 UID..**.** %
2120: 66 6f 73 73 69 6c 20 74 61 67 20 64 65 6c 65 74 fossil tag delet
2130: 65 20 54 41 47 4e 41 4d 45 20 55 55 49 44 0a 2a e TAGNAME UUID.*
2140: 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 44 65 6c *.** Del
2150: 65 74 65 20 74 68 65 20 74 61 67 20 54 41 47 4e ete the tag TAGN
2160: 41 4d 45 20 66 72 6f 6d 20 55 55 49 44 0a 2a 2a AME from UUID.**
2170: 0a 2a 2a 20 20 20 20 20 25 66 6f 73 73 69 6c 20 .** %fossil
2180: 74 61 67 20 66 69 6e 64 20 54 41 47 4e 41 4d 45 tag find TAGNAME
2190: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 4c .**.** L
21a0: 69 73 74 20 61 6c 6c 20 62 61 73 65 6c 69 6e 65 ist all baseline
21b0: 73 20 74 68 61 74 20 75 73 65 20 54 41 47 4e 41 s that use TAGNA
21c0: 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20 20 25 66 6f ME.**.** %fo
21d0: 73 73 69 6c 20 74 61 67 20 6c 69 73 74 20 3f 55 ssil tag list ?U
21e0: 55 49 44 3f 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 UID?.**.**
21f0: 20 20 20 4c 69 73 74 20 61 6c 6c 20 74 61 67 73 List all tags
2200: 2c 20 6f 72 20 69 66 20 55 55 49 44 20 69 73 20 , or if UUID is
2210: 73 75 70 70 6c 69 65 64 2c 20 6c 69 73 74 0a 2a supplied, list.*
2220: 2a 20 20 20 20 20 20 20 20 20 61 6c 6c 20 74 61 * all ta
2230: 67 73 20 61 6e 64 20 74 68 65 69 72 20 76 61 6c gs and their val
2240: 75 65 73 20 66 6f 72 20 55 55 49 44 2e 0a 2a 2f ues for UUID..*/
2250: 0a 76 6f 69 64 20 74 61 67 5f 63 6d 64 28 76 6f .void tag_cmd(vo
2260: 69 64 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 id){. int n;.
2270: 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e db_find_and_open
2280: 5f 72 65 70 6f 73 69 74 6f 72 79 28 29 3b 0a 20 _repository();.
2290: 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 29 7b if( g.argc<3 ){
22a0: 0a 20 20 20 20 67 6f 74 6f 20 74 61 67 5f 63 6d . goto tag_cm
22b0: 64 5f 75 73 61 67 65 3b 0a 20 20 7d 0a 20 20 6e d_usage;. }. n
22c0: 20 3d 20 73 74 72 6c 65 6e 28 67 2e 61 72 67 76 = strlen(g.argv
22d0: 5b 32 5d 29 3b 0a 20 20 69 66 28 20 6e 3d 3d 30 [2]);. if( n==0
22e0: 20 29 7b 0a 20 20 20 20 67 6f 74 6f 20 74 61 67 ){. goto tag
22f0: 5f 63 6d 64 5f 75 73 61 67 65 3b 0a 20 20 7d 0a _cmd_usage;. }.
2300: 0a 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28 67 . if( strncmp(g
2310: 2e 61 72 67 76 5b 32 5d 2c 22 61 64 64 22 2c 6e .argv[2],"add",n
2320: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 63 68 61 72 )==0 ){. char
2330: 20 2a 7a 56 61 6c 75 65 3b 0a 20 20 20 20 69 66 *zValue;. if
2340: 28 20 67 2e 61 72 67 63 21 3d 35 20 26 26 20 67 ( g.argc!=5 && g
2350: 2e 61 72 67 63 21 3d 36 20 29 7b 0a 20 20 20 20 .argc!=6 ){.
2360: 20 20 75 73 61 67 65 28 22 74 61 67 20 61 64 64 usage("tag add
2370: 20 54 41 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 TAGNAME UUID ?V
2380: 41 4c 55 45 3f 22 29 3b 0a 20 20 20 20 7d 0a 20 ALUE?");. }.
2390: 20 20 20 7a 56 61 6c 75 65 20 3d 20 67 2e 61 72 zValue = g.ar
23a0: 67 63 3d 3d 36 20 3f 20 67 2e 61 72 67 76 5b 35 gc==6 ? g.argv[5
23b0: 5d 20 3a 20 30 3b 0a 20 20 20 20 74 61 67 5f 61 ] : 0;. tag_a
23c0: 64 64 5f 61 72 74 69 66 61 63 74 28 67 2e 61 72 dd_artifact(g.ar
23d0: 67 76 5b 33 5d 2c 20 67 2e 61 72 67 76 5b 34 5d gv[3], g.argv[4]
23e0: 2c 20 7a 56 61 6c 75 65 2c 20 31 29 3b 0a 20 20 , zValue, 1);.
23f0: 7d 65 6c 73 65 0a 0a 20 20 69 66 28 20 73 74 72 }else.. if( str
2400: 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 ncmp(g.argv[2],"
2410: 64 65 6c 65 74 65 22 2c 6e 29 3d 3d 30 20 29 7b delete",n)==0 ){
2420: 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 21 . if( g.argc!
2430: 3d 35 20 29 7b 0a 20 20 20 20 20 20 75 73 61 67 =5 ){. usag
2440: 65 28 22 74 61 67 20 64 65 6c 65 74 65 20 54 41 e("tag delete TA
2450: 47 4e 41 4d 45 20 55 55 49 44 22 29 3b 0a 20 20 GNAME UUID");.
2460: 20 20 7d 0a 20 20 20 20 74 61 67 5f 61 64 64 5f }. tag_add_
2470: 61 72 74 69 66 61 63 74 28 67 2e 61 72 67 76 5b artifact(g.argv[
2480: 33 5d 2c 20 67 2e 61 72 67 76 5b 34 5d 2c 20 30 3], g.argv[4], 0
2490: 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65 0a 0a 20 , 0);. }else..
24a0: 20 69 66 28 20 73 74 72 6e 63 6d 70 28 67 2e 61 if( strncmp(g.a
24b0: 72 67 76 5b 32 5d 2c 22 66 69 6e 64 22 2c 6e 29 rgv[2],"find",n)
24c0: 3d 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 ==0 ){. Stmt
24d0: 71 3b 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 q;. if( g.arg
24e0: 63 21 3d 34 20 29 7b 0a 20 20 20 20 20 20 75 73 c!=4 ){. us
24f0: 61 67 65 28 22 74 61 67 20 66 69 6e 64 20 54 41 age("tag find TA
2500: 47 4e 41 4d 45 22 29 3b 0a 20 20 20 20 7d 0a 20 GNAME");. }.
2510: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 db_prepare(&q
2520: 2c 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 ,. "SELECT
2530: 62 6c 6f 62 2e 75 75 69 64 20 46 52 4f 4d 20 74 blob.uuid FROM t
2540: 61 67 78 72 65 66 2c 20 62 6c 6f 62 22 0a 20 20 agxref, blob".
2550: 20 20 20 20 22 20 57 48 45 52 45 20 74 61 67 69 " WHERE tagi
2560: 64 3d 28 53 45 4c 45 43 54 20 74 61 67 69 64 20 d=(SELECT tagid
2570: 46 52 4f 4d 20 74 61 67 20 57 48 45 52 45 20 74 FROM tag WHERE t
2580: 61 67 6e 61 6d 65 3d 25 51 29 22 0a 20 20 20 20 agname=%Q)".
2590: 20 20 22 20 20 20 41 4e 44 20 62 6c 6f 62 2e 72 " AND blob.r
25a0: 69 64 3d 74 61 67 78 72 65 66 2e 72 69 64 22 2c id=tagxref.rid",
25b0: 20 67 2e 61 72 67 76 5b 33 5d 0a 20 20 20 20 29 g.argv[3]. )
25c0: 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64 62 5f ;. while( db_
25d0: 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 step(&q)==SQLITE
25e0: 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 70 72 _ROW ){. pr
25f0: 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 64 62 5f intf("%s\n", db_
2600: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 column_text(&q,
2610: 30 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 0));. }. d
2620: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
2630: 20 20 7d 65 6c 73 65 0a 0a 20 20 69 66 28 20 73 }else.. if( s
2640: 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d trncmp(g.argv[2]
2650: 2c 22 6c 69 73 74 22 2c 6e 29 3d 3d 30 20 29 7b ,"list",n)==0 ){
2660: 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a 20 20 20 . Stmt q;.
2670: 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 29 if( g.argc==3 )
2680: 7b 0a 20 20 20 20 20 20 64 62 5f 70 72 65 70 61 {. db_prepa
2690: 72 65 28 26 71 2c 20 0a 20 20 20 20 20 20 20 20 re(&q, .
26a0: 22 53 45 4c 45 43 54 20 74 61 67 6e 61 6d 65 22 "SELECT tagname"
26b0: 0a 20 20 20 20 20 20 20 20 22 20 20 46 52 4f 4d . " FROM
26c0: 20 74 61 67 22 0a 20 20 20 20 20 20 20 20 22 20 tag". "
26d0: 57 48 45 52 45 20 45 58 49 53 54 53 28 53 45 4c WHERE EXISTS(SEL
26e0: 45 43 54 20 31 20 46 52 4f 4d 20 74 61 67 78 72 ECT 1 FROM tagxr
26f0: 65 66 22 0a 20 20 20 20 20 20 20 20 22 20 20 20 ef". "
2700: 20 20 20 20 20 20 20 20 20 20 20 20 57 48 45 52 WHER
2710: 45 20 74 61 67 69 64 3d 74 61 67 2e 74 61 67 69 E tagid=tag.tagi
2720: 64 22 0a 20 20 20 20 20 20 20 20 22 20 20 20 20 d". "
2730: 20 20 20 20 20 20 20 20 20 20 20 20 20 41 4e 44 AND
2740: 20 61 64 64 66 6c 61 67 29 22 0a 20 20 20 20 20 addflag)".
2750: 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 74 61 " ORDER BY ta
2760: 67 6e 61 6d 65 22 0a 20 20 20 20 20 20 29 3b 0a gname". );.
2770: 20 20 20 20 20 20 77 68 69 6c 65 28 20 64 62 5f while( db_
2780: 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 step(&q)==SQLITE
2790: 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 20 20 _ROW ){.
27a0: 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 64 printf("%s\n", d
27b0: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 b_column_text(&q
27c0: 2c 20 30 29 29 3b 0a 20 20 20 20 20 20 7d 0a 20 , 0));. }.
27d0: 20 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 db_finalize
27e0: 28 26 71 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 (&q);. }else
27f0: 69 66 28 20 67 2e 61 72 67 63 3d 3d 34 20 29 7b if( g.argc==4 ){
2800: 0a 20 20 20 20 20 20 69 6e 74 20 72 69 64 20 3d . int rid =
2810: 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 67 2e 61 name_to_rid(g.a
2820: 72 67 76 5b 33 5d 29 3b 0a 20 20 20 20 20 20 64 rgv[3]);. d
2830: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20 20 b_prepare(&q,.
2840: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 "SELECT ta
2850: 67 6e 61 6d 65 2c 20 76 61 6c 75 65 22 0a 20 20 gname, value".
2860: 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 74 61 " FROM ta
2870: 67 78 72 65 66 2c 20 74 61 67 22 0a 20 20 20 20 gxref, tag".
2880: 20 20 20 20 22 20 57 48 45 52 45 20 74 61 67 78 " WHERE tagx
2890: 72 65 66 2e 72 69 64 3d 25 64 20 41 4e 44 20 74 ref.rid=%d AND t
28a0: 61 67 78 72 65 66 2e 74 61 67 69 64 3d 74 61 67 agxref.tagid=tag
28b0: 2e 74 61 67 69 64 22 0a 20 20 20 20 20 20 20 20 .tagid".
28c0: 22 20 20 20 41 4e 44 20 61 64 64 66 6c 61 67 22 " AND addflag"
28d0: 0a 20 20 20 20 20 20 20 20 22 20 4f 52 44 45 52 . " ORDER
28e0: 20 42 59 20 74 61 67 6e 61 6d 65 22 2c 0a 20 20 BY tagname",.
28f0: 20 20 20 20 20 20 72 69 64 0a 20 20 20 20 20 20 rid.
2900: 29 3b 0a 20 20 20 20 20 20 77 68 69 6c 65 28 20 );. while(
2910: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c db_step(&q)==SQL
2920: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 ITE_ROW ){.
2930: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a const char *z
2940: 4e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e Name = db_column
2950: 5f 74 65 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 _text(&q, 0);.
2960: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
2970: 20 2a 7a 56 61 6c 75 65 20 3d 20 64 62 5f 63 6f *zValue = db_co
2980: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 31 29 lumn_text(&q, 1)
2990: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 56 ;. if( zV
29a0: 61 6c 75 65 20 29 7b 0a 20 20 20 20 20 20 20 20 alue ){.
29b0: 20 20 70 72 69 6e 74 66 28 22 25 73 3d 25 73 5c printf("%s=%s\
29c0: 6e 22 2c 20 7a 4e 61 6d 65 2c 20 7a 56 61 6c 75 n", zName, zValu
29d0: 65 29 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 e);. }els
29e0: 65 7b 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 e{. pri
29f0: 6e 74 66 28 22 25 73 5c 6e 22 2c 20 7a 4e 61 6d ntf("%s\n", zNam
2a00: 65 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 e);. }.
2a10: 20 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 66 }. db_f
2a20: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 inalize(&q);.
2a30: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 75 73 }else{. us
2a40: 61 67 65 28 22 74 61 67 20 6c 69 73 74 20 3f 55 age("tag list ?U
2a50: 55 49 44 3f 22 29 3b 0a 20 20 20 20 7d 0a 20 20 UID?");. }.
2a60: 7d 65 6c 73 65 0a 20 20 7b 0a 20 20 20 20 67 6f }else. {. go
2a70: 74 6f 20 74 61 67 5f 63 6d 64 5f 75 73 61 67 65 to tag_cmd_usage
2a80: 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 3b 0a ;. }. return;.
2a90: 0a 74 61 67 5f 63 6d 64 5f 75 73 61 67 65 3a 0a .tag_cmd_usage:.
2aa0: 20 20 75 73 61 67 65 28 22 61 64 64 7c 64 65 6c usage("add|del
2ab0: 65 74 65 7c 66 69 6e 64 7c 6c 69 73 74 20 2e 2e ete|find|list ..
2ac0: 2e 22 29 3b 0a 7d 0a .");.}.