109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
db_finalize(&q);
rc = 0;
}else{
rc = 0;
}
return rc;
}
/*
** Convert a symbolic tag name into the UUID of a check-in that contains
** that tag. If the tag appears on multiple check-ins, return the UUID
** of the most recent check-in with the tag.
**
** Memory to hold the returned string comes from malloc() and needs to
** be freed by the caller.
*/
char *tag_to_uuid(const char *zTag){
char *zUuid =
db_text(0,
"SELECT blob.uuid"
" FROM tag, tagxref, event, blob"
" WHERE tag.tagname='sym-'||%Q "
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
" AND event.objid=tagxref.rid "
" AND blob.rid=event.objid "
" ORDER BY event.mtime DESC ",
zTag
);
return zUuid;
}
/*
** Convert a date/time string into a UUID.
**
** Input forms accepted:
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
db_finalize(&q);
rc = 0;
}else{
rc = 0;
}
return rc;
}
/*
** Return TRUE if the string begins with an ISO8601 date: YYYY-MM-DD.
*/
static int is_date(const char *z){
if( !isdigit(z[0]) ) return 0;
if( !isdigit(z[1]) ) return 0;
if( !isdigit(z[2]) ) return 0;
if( !isdigit(z[3]) ) return 0;
if( z[4]!='-') return 0;
if( !isdigit(z[5]) ) return 0;
if( !isdigit(z[6]) ) return 0;
if( z[7]!='-') return 0;
if( !isdigit(z[8]) ) return 0;
if( !isdigit(z[9]) ) return 0;
return 1;
}
/*
** Convert a symbolic tag name into the UUID of a check-in that contains
** that tag. If the tag appears on multiple check-ins, return the UUID
** of the most recent check-in with the tag.
**
** If the input string is of the form:
**
** tag:date
**
** Then return the UUID of the oldest check-in with that tag that is
** not older than 'date'.
**
** Memory to hold the returned string comes from malloc() and needs to
** be freed by the caller.
*/
char *tag_to_uuid(const char *zTag){
char *zUuid =
db_text(0,
"SELECT blob.uuid"
" FROM tag, tagxref, event, blob"
" WHERE tag.tagname='sym-'||%Q "
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
" AND event.objid=tagxref.rid "
" AND blob.rid=event.objid "
" ORDER BY event.mtime DESC ",
zTag
);
if( zUuid==0 ){
int nTag = strlen(zTag);
int i;
for(i=0; i<nTag-10; i++){
if( zTag[i]==':' && is_date(&zTag[i+1]) ){
char *zDate = mprintf("%s", &zTag[i+1]);
char *zTagBase = mprintf("%.*s", i, zTag);
int nDate = strlen(zDate);
int useUtc = 0;
if( sqlite3_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
nDate -= 3;
zDate[nDate] = 0;
useUtc = 1;
}
zUuid = db_text(0,
"SELECT blob.uuid"
" FROM tag, tagxref, event, blob"
" WHERE tag.tagname='sym-'||%Q "
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
" AND event.objid=tagxref.rid "
" AND blob.rid=event.objid "
" AND event.mtime<=julianday(%Q %s)"
" ORDER BY event.mtime DESC ",
zTagBase, zDate, (useUtc ? "" : ",'utc'")
);
break;
}
}
}
return zUuid;
}
/*
** Convert a date/time string into a UUID.
**
** Input forms accepted:
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
}else if( memcmp(zDate, "local:", 6)==0 ){
zDate += 6;
}else if( memcmp(zDate, "utc:", 4)==0 ){
zDate += 4;
useUtc = 1;
}
n = strlen(zDate);
if( n<10 || zDate[4]!='-' || zDate[7]!='-' ) return 0;
if( n>4 && sqlite3_strnicmp(&zDate[n-3], "utc", 3)==0 ){
zCopy = mprintf("%s", zDate);
zCopy[n-3] = 0;
zDate = zCopy;
n -= 3;
useUtc = 1;
}
|
|
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
}else if( memcmp(zDate, "local:", 6)==0 ){
zDate += 6;
}else if( memcmp(zDate, "utc:", 4)==0 ){
zDate += 4;
useUtc = 1;
}
n = strlen(zDate);
if( n<10 || !is_date(zDate) ) return 0;
if( n>4 && sqlite3_strnicmp(&zDate[n-3], "utc", 3)==0 ){
zCopy = mprintf("%s", zDate);
zCopy[n-3] = 0;
zDate = zCopy;
n -= 3;
useUtc = 1;
}
|