Fossil SCM

Merge trunk.

achavasse 2018-01-11 23:03 skin-ardoise merge
Commit 9cd063dc388af63098c888945dba7bcc85b2d530deff29242cbe52fe0d8bfd42
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
1919
# define JSON_PARSER_DLL_API __declspec(dllexport)
2020
# else
2121
# define JSON_PARSER_DLL_API __declspec(dllimport)
2222
# endif
2323
# else
24
-# define JSON_PARSER_DLL_API
24
+# define JSON_PARSER_DLL_API
2525
# endif
2626
#else
27
-# define JSON_PARSER_DLL_API
27
+# define JSON_PARSER_DLL_API
2828
#endif
2929
3030
/* Determine the integer type use to parse non-floating point numbers */
3131
#ifdef _WIN32
3232
typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
3434
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
3535
#elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
3636
typedef long long JSON_int_t;
3737
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
3838
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39
-#else
39
+#else
4040
typedef long JSON_int_t;
4141
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
4242
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
4343
#endif
4444
4545
4646
#ifdef __cplusplus
4747
extern "C" {
48
-#endif
48
+#endif
4949
50
-typedef enum
50
+typedef enum
5151
{
5252
JSON_E_NONE = 0,
5353
JSON_E_INVALID_CHAR,
5454
JSON_E_INVALID_KEYWORD,
5555
JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
6060
JSON_E_EXPECTED_KEY,
6161
JSON_E_EXPECTED_COLON,
6262
JSON_E_OUT_OF_MEMORY
6363
} JSON_error;
6464
65
-typedef enum
65
+typedef enum
6666
{
6767
JSON_T_NONE = 0,
6868
JSON_T_ARRAY_BEGIN,
6969
JSON_T_ARRAY_END,
7070
JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
8080
} JSON_type;
8181
8282
typedef struct JSON_value_struct {
8383
union {
8484
JSON_int_t integer_value;
85
-
85
+
8686
double float_value;
87
-
87
+
8888
struct {
8989
const char* value;
9090
size_t length;
9191
} str;
9292
} vu;
9393
} JSON_value;
9494
9595
typedef struct JSON_parser_struct* JSON_parser;
9696
97
-/*! \brief JSON parser callback
97
+/*! \brief JSON parser callback
9898
9999
\param ctx The pointer passed to new_JSON_parser.
100
- \param type An element of JSON_type but not JSON_T_NONE.
100
+ \param type An element of JSON_type but not JSON_T_NONE.
101101
\param value A representation of the parsed value. This parameter is NULL for
102102
JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103103
JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104104
as zero-terminated C strings.
105105
106106
\return Non-zero if parsing should continue, else zero.
107
-*/
107
+*/
108108
typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109109
110110
111111
/**
112112
A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115115
/**
116116
A typedef for deallocator functions semantically compatible with free().
117117
*/
118118
typedef void (*JSON_free_t)(void* mem);
119119
120
-/*! \brief The structure used to configure a JSON parser object
120
+/*! \brief The structure used to configure a JSON parser object
121121
*/
122122
typedef struct {
123123
/** Pointer to a callback, called when the parser has something to tell
124124
the user. This parameter may be NULL. In this case the input is
125125
merely checked for validity.
@@ -176,17 +176,17 @@
176176
177177
\param config. Used to configure the parser.
178178
*/
179179
JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180180
181
-/*! \brief Create a JSON parser object
181
+/*! \brief Create a JSON parser object
182182
183183
\param config. Used to configure the parser. Set to NULL to use
184184
the default configuration. See init_JSON_config. Its contents are
185185
copied by this function, so it need not outlive the returned
186186
object.
187
-
187
+
188188
\return The parser object, which is owned by the caller and must eventually
189189
be freed by calling delete_JSON_parser().
190190
*/
191191
JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192192
@@ -200,16 +200,16 @@
200200
JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201201
202202
/*! \brief Finalize parsing.
203203
204204
Call this method once after all input characters have been consumed.
205
-
205
+
206206
\return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207207
*/
208208
JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209209
210
-/*! \brief Determine if a given string is valid JSON white space
210
+/*! \brief Determine if a given string is valid JSON white space
211211
212212
\return Non-zero if the string is valid, zero otherwise.
213213
*/
214214
JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215215
@@ -226,12 +226,12 @@
226226
JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227227
228228
229229
#ifdef __cplusplus
230230
}
231
-#endif
232
-
231
+#endif
232
+
233233
234234
#endif /* JSON_PARSER_H */
235235
/* end file parser/JSON_parser.h */
236236
/* begin file parser/JSON_parser.c */
237237
/*
@@ -1431,11 +1431,11 @@
14311431
#if defined(__cplusplus)
14321432
extern "C" {
14331433
#endif
14341434
14351435
1436
-
1436
+
14371437
/**
14381438
This type holds the "vtbl" for type-specific operations when
14391439
working with cson_value objects.
14401440
14411441
All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
15831583
*/
15841584
#define CSON_CAST(T,V) ((T*)((V)->value))
15851585
/**
15861586
Assumes V is a pointer to memory which is allocated as part of a
15871587
cson_value instance (the bytes immediately after that part).
1588
- Returns a pointer a cson_value by subtracting sizeof(cson_value)
1588
+ Returns a pointer a a cson_value by subtracting sizeof(cson_value)
15891589
from that address and casting it to a (cson_value*)
15901590
*/
15911591
#define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
15921592
15931593
/**
@@ -1607,11 +1607,11 @@
16071607
#define CSON_OBJ(V) CSON_CAST(cson_object,(V))
16081608
#define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
16091609
16101610
/**
16111611
Holds special shared "constant" (though they are non-const)
1612
- values.
1612
+ values.
16131613
*/
16141614
static struct CSON_EMPTY_HOLDER_
16151615
{
16161616
char trueValue;
16171617
cson_string stringValue;
@@ -1620,17 +1620,17 @@
16201620
cson_string_empty_m
16211621
};
16221622
16231623
/**
16241624
Indexes into the CSON_SPECIAL_VALUES array.
1625
-
1625
+
16261626
If this enum changes in any way,
16271627
makes damned sure that CSON_SPECIAL_VALUES is updated
16281628
to match!!!
16291629
*/
16301630
enum CSON_INTERNAL_VALUES {
1631
-
1631
+
16321632
CSON_VAL_UNDEF = 0,
16331633
CSON_VAL_NULL = 1,
16341634
CSON_VAL_TRUE = 2,
16351635
CSON_VAL_FALSE = 3,
16361636
CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
16421642
/**
16431643
Some "special" shared cson_value instances.
16441644
16451645
These values MUST be initialized in the order specified
16461646
by the CSON_INTERNAL_VALUES enum.
1647
-
1647
+
16481648
Note that they are not const because they are used as
16491649
shared-allocation objects in non-const contexts. However, the
16501650
public API provides no way to modifying them, and clients who
16511651
modify values directly are subject to The Wrath of Undefined
16521652
Behaviour.
@@ -1665,11 +1665,11 @@
16651665
16661666
/**
16671667
Returns non-0 (true) if m is one of our special
16681668
"built-in" values, e.g. from CSON_SPECIAL_VALUES and some
16691669
"empty" values.
1670
-
1670
+
16711671
If this returns true, m MUST NOT be free()d!
16721672
*/
16731673
static char cson_value_is_builtin( void const * m )
16741674
{
16751675
if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
21832183
static int cson_value_list_visit( cson_value_list * self,
21842184
int (*visitor)(cson_value * obj, void * visitorState ),
21852185
void * visitorState );
21862186
#endif
21872187
#endif
2188
-
2188
+
21892189
#if 0
21902190
# define LIST_T cson_value_list
21912191
# define VALUE_T cson_value *
21922192
# define VALUE_T_IS_PTR 1
21932193
# define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
23622362
return cson_value_object_alloc();
23632363
}
23642364
23652365
cson_object * cson_new_object()
23662366
{
2367
-
2367
+
23682368
return cson_value_get_object( cson_value_new_object() );
23692369
}
23702370
23712371
cson_value * cson_value_new_array()
23722372
{
@@ -2608,11 +2608,11 @@
26082608
{
26092609
cson_int_t i = 0;
26102610
int rc = 0;
26112611
switch(val->api->typeID)
26122612
{
2613
- case CSON_TYPE_UNDEF:
2613
+ case CSON_TYPE_UNDEF:
26142614
case CSON_TYPE_NULL:
26152615
i = 0;
26162616
break;
26172617
case CSON_TYPE_BOOL: {
26182618
char b = 0;
@@ -2661,11 +2661,11 @@
26612661
{
26622662
cson_double_t d = 0.0;
26632663
int rc = 0;
26642664
switch(val->api->typeID)
26652665
{
2666
- case CSON_TYPE_UNDEF:
2666
+ case CSON_TYPE_UNDEF:
26672667
case CSON_TYPE_NULL:
26682668
d = 0;
26692669
break;
26702670
case CSON_TYPE_BOOL: {
26712671
char b = 0;
@@ -2791,11 +2791,11 @@
27912791
#if 0
27922792
/**
27932793
Removes and returns the last value from the given array,
27942794
shrinking its size by 1. Returns NULL if ar is NULL,
27952795
ar->list.count is 0, or the element at that index is NULL.
2796
-
2796
+
27972797
27982798
If removeRef is true then cson_value_free() is called to remove
27992799
ar's reference count for the value. In that case NULL is returned,
28002800
even if the object still has live references. If removeRef is false
28012801
then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
28582858
#if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
28592859
assert( sizeof(cson_int_t) <= sizeof(void *) );
28602860
#endif
28612861
if( c )
28622862
{
2863
- memcpy(CSON_INT(c), &v, sizeof(v));
2863
+ memcpy( CSON_INT(c), &v, sizeof(v) );
28642864
}
28652865
return c;
28662866
}
28672867
}
28682868
@@ -2877,11 +2877,11 @@
28772877
else
28782878
{
28792879
cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
28802880
if( c )
28812881
{
2882
- memcpy(CSON_DBL(c), &v, sizeof(v));
2882
+ memcpy( CSON_DBL(c), &v, sizeof(v) );
28832883
}
28842884
return c;
28852885
}
28862886
}
28872887
@@ -3068,11 +3068,11 @@
30683068
qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
30693069
cson_kvp_cmp );
30703070
}
30713071
30723072
}
3073
-#endif
3073
+#endif
30743074
30753075
int cson_object_unset( cson_object * obj, char const * key )
30763076
{
30773077
if( ! obj || !key || !*key ) return cson_rc.ArgError;
30783078
else
@@ -3238,11 +3238,11 @@
32383238
using p->key. In any other case cson_rc.InternalError is returned.
32393239
32403240
Returns cson_rc.AllocError if an allocation fails.
32413241
32423242
Returns 0 on success. On error, parsing must be ceased immediately.
3243
-
3243
+
32443244
Ownership of val is ALWAYS TRANSFERED to this function. If this
32453245
function fails, val will be cleaned up and destroyed. (This
32463246
simplifies error handling in the core parser.)
32473247
*/
32483248
static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
34853485
++p->totalKeyCount;
34863486
break;
34873487
}
34883488
case JSON_T_STRING: {
34893489
cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490
- rc = ( NULL == v )
3490
+ rc = ( NULL == v )
34913491
? cson_rc.AllocError
34923492
: cson_parser_push_value( p, v );
34933493
break;
34943494
}
34953495
default:
@@ -3532,11 +3532,11 @@
35323532
To properly take over ownership of the parser's root node on a
35333533
successful parse:
35343534
35353535
- Copy p->root's pointer and set p->root to NULL.
35363536
- Eventually free up p->root with cson_value_free().
3537
-
3537
+
35383538
If you do not set p->root to NULL, p->root will be freed along with
35393539
any other items inserted into it (or under it) during the parsing
35403540
process.
35413541
*/
35423542
static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
35713571
int rc = 0;
35723572
unsigned int len = 1;
35733573
cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
35743574
cson_parser p = cson_parser_empty;
35753575
if( ! tgt || ! src ) return cson_rc.ArgError;
3576
-
3576
+
35773577
{
35783578
JSON_config jopt = {0};
35793579
init_JSON_config( &jopt );
35803580
jopt.allow_comments = opt.allowComments;
35813581
jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
37803780
unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
37813781
unsigned char const * next = NULL;
37823782
int ch;
37833783
unsigned char clen = 0;
37843784
char escChar[3] = {'\\',0,0};
3785
- enum { UBLen = 13 };
3785
+ enum { UBLen = 20 };
37863786
char ubuf[UBLen];
37873787
int rc = 0;
37883788
rc = f(state, "\"", 1 );
37893789
for( ; (pos < end) && (0 == rc); pos += clen )
37903790
{
@@ -4640,11 +4640,11 @@
46404640
#endif
46414641
#undef TRY_SHARING
46424642
cson_value_add_reference(rc);
46434643
return rc;
46444644
}
4645
-
4645
+
46464646
static cson_value * cson_value_clone_array( cson_value const * orig )
46474647
{
46484648
unsigned int i = 0;
46494649
cson_array const * asrc = cson_value_get_array( orig );
46504650
unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
46804680
cson_value_free(cl)/*remove our artificial reference */;
46814681
}
46824682
}
46834683
return destV;
46844684
}
4685
-
4685
+
46864686
static cson_value * cson_value_clone_object( cson_value const * orig )
46874687
{
46884688
cson_object const * src = cson_value_get_object( orig );
46894689
cson_value * destV = NULL;
46904690
cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
48344834
}
48354835
case CSON_TYPE_STRING: {
48364836
cson_string const * jstr = cson_value_get_string(orig);
48374837
unsigned const int slen = cson_string_length_bytes( jstr );
48384838
assert( NULL != jstr );
4839
- v = cson_strdup( cson_string_cstr( jstr ), slen );
4839
+ v = cson_strdup( cson_string_cstr( jstr ), slen );
48404840
break;
48414841
}
48424842
case CSON_TYPE_INTEGER: {
48434843
char buf[BufSize] = {0};
48444844
if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
48874887
}
48884888
case CSON_TYPE_STRING: {
48894889
cson_string const * jstr = cson_value_get_string(orig);
48904890
unsigned const int slen = cson_string_length_bytes( jstr );
48914891
assert( NULL != jstr );
4892
- v = cson_strdup( cson_string_cstr( jstr ), slen );
4892
+ v = cson_strdup( cson_string_cstr( jstr ), slen );
48934893
break;
48944894
}
48954895
case CSON_TYPE_INTEGER: {
48964896
char buf[BufSize] = {0};
48974897
if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
53515351
int rc = 0;
53525352
int colCount = 0;
53535353
assert(st);
53545354
colCount = sqlite3_column_count(st);
53555355
if( colCount <= 0 ) return NULL;
5356
-
5356
+
53575357
aryV = cson_value_new_array();
53585358
if( ! aryV ) return NULL;
53595359
ary = cson_value_get_array(aryV);
53605360
assert(ary);
53615361
for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
54915491
aryV = NULL;
54925492
end:
54935493
return aryV;
54945494
}
54955495
5496
-
5496
+
54975497
/**
54985498
Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
54995499
parameter is non-0.
55005500
*/
55015501
static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
56365636
int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
56375637
if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
56385638
rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
56395639
sqlite3_finalize( st );
56405640
return rc;
5641
- }
5641
+ }
56425642
}
56435643
56445644
int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
56455645
{
56465646
int rc = 0;
56475647
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
19 # define JSON_PARSER_DLL_API __declspec(dllexport)
20 # else
21 # define JSON_PARSER_DLL_API __declspec(dllimport)
22 # endif
23 # else
24 # define JSON_PARSER_DLL_API
25 # endif
26 #else
27 # define JSON_PARSER_DLL_API
28 #endif
29
30 /* Determine the integer type use to parse non-floating point numbers */
31 #ifdef _WIN32
32 typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
34 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
35 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
36 typedef long long JSON_int_t;
37 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
38 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39 #else
40 typedef long JSON_int_t;
41 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
42 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
43 #endif
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 typedef enum
51 {
52 JSON_E_NONE = 0,
53 JSON_E_INVALID_CHAR,
54 JSON_E_INVALID_KEYWORD,
55 JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
60 JSON_E_EXPECTED_KEY,
61 JSON_E_EXPECTED_COLON,
62 JSON_E_OUT_OF_MEMORY
63 } JSON_error;
64
65 typedef enum
66 {
67 JSON_T_NONE = 0,
68 JSON_T_ARRAY_BEGIN,
69 JSON_T_ARRAY_END,
70 JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
80 } JSON_type;
81
82 typedef struct JSON_value_struct {
83 union {
84 JSON_int_t integer_value;
85
86 double float_value;
87
88 struct {
89 const char* value;
90 size_t length;
91 } str;
92 } vu;
93 } JSON_value;
94
95 typedef struct JSON_parser_struct* JSON_parser;
96
97 /*! \brief JSON parser callback
98
99 \param ctx The pointer passed to new_JSON_parser.
100 \param type An element of JSON_type but not JSON_T_NONE.
101 \param value A representation of the parsed value. This parameter is NULL for
102 JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103 JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104 as zero-terminated C strings.
105
106 \return Non-zero if parsing should continue, else zero.
107 */
108 typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109
110
111 /**
112 A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115 /**
116 A typedef for deallocator functions semantically compatible with free().
117 */
118 typedef void (*JSON_free_t)(void* mem);
119
120 /*! \brief The structure used to configure a JSON parser object
121 */
122 typedef struct {
123 /** Pointer to a callback, called when the parser has something to tell
124 the user. This parameter may be NULL. In this case the input is
125 merely checked for validity.
@@ -176,17 +176,17 @@
176
177 \param config. Used to configure the parser.
178 */
179 JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180
181 /*! \brief Create a JSON parser object
182
183 \param config. Used to configure the parser. Set to NULL to use
184 the default configuration. See init_JSON_config. Its contents are
185 copied by this function, so it need not outlive the returned
186 object.
187
188 \return The parser object, which is owned by the caller and must eventually
189 be freed by calling delete_JSON_parser().
190 */
191 JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192
@@ -200,16 +200,16 @@
200 JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201
202 /*! \brief Finalize parsing.
203
204 Call this method once after all input characters have been consumed.
205
206 \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207 */
208 JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209
210 /*! \brief Determine if a given string is valid JSON white space
211
212 \return Non-zero if the string is valid, zero otherwise.
213 */
214 JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215
@@ -226,12 +226,12 @@
226 JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233
234 #endif /* JSON_PARSER_H */
235 /* end file parser/JSON_parser.h */
236 /* begin file parser/JSON_parser.c */
237 /*
@@ -1431,11 +1431,11 @@
1431 #if defined(__cplusplus)
1432 extern "C" {
1433 #endif
1434
1435
1436
1437 /**
1438 This type holds the "vtbl" for type-specific operations when
1439 working with cson_value objects.
1440
1441 All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
1583 */
1584 #define CSON_CAST(T,V) ((T*)((V)->value))
1585 /**
1586 Assumes V is a pointer to memory which is allocated as part of a
1587 cson_value instance (the bytes immediately after that part).
1588 Returns a pointer a cson_value by subtracting sizeof(cson_value)
1589 from that address and casting it to a (cson_value*)
1590 */
1591 #define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
1592
1593 /**
@@ -1607,11 +1607,11 @@
1607 #define CSON_OBJ(V) CSON_CAST(cson_object,(V))
1608 #define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
1609
1610 /**
1611 Holds special shared "constant" (though they are non-const)
1612 values.
1613 */
1614 static struct CSON_EMPTY_HOLDER_
1615 {
1616 char trueValue;
1617 cson_string stringValue;
@@ -1620,17 +1620,17 @@
1620 cson_string_empty_m
1621 };
1622
1623 /**
1624 Indexes into the CSON_SPECIAL_VALUES array.
1625
1626 If this enum changes in any way,
1627 makes damned sure that CSON_SPECIAL_VALUES is updated
1628 to match!!!
1629 */
1630 enum CSON_INTERNAL_VALUES {
1631
1632 CSON_VAL_UNDEF = 0,
1633 CSON_VAL_NULL = 1,
1634 CSON_VAL_TRUE = 2,
1635 CSON_VAL_FALSE = 3,
1636 CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
1642 /**
1643 Some "special" shared cson_value instances.
1644
1645 These values MUST be initialized in the order specified
1646 by the CSON_INTERNAL_VALUES enum.
1647
1648 Note that they are not const because they are used as
1649 shared-allocation objects in non-const contexts. However, the
1650 public API provides no way to modifying them, and clients who
1651 modify values directly are subject to The Wrath of Undefined
1652 Behaviour.
@@ -1665,11 +1665,11 @@
1665
1666 /**
1667 Returns non-0 (true) if m is one of our special
1668 "built-in" values, e.g. from CSON_SPECIAL_VALUES and some
1669 "empty" values.
1670
1671 If this returns true, m MUST NOT be free()d!
1672 */
1673 static char cson_value_is_builtin( void const * m )
1674 {
1675 if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
2183 static int cson_value_list_visit( cson_value_list * self,
2184 int (*visitor)(cson_value * obj, void * visitorState ),
2185 void * visitorState );
2186 #endif
2187 #endif
2188
2189 #if 0
2190 # define LIST_T cson_value_list
2191 # define VALUE_T cson_value *
2192 # define VALUE_T_IS_PTR 1
2193 # define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
2362 return cson_value_object_alloc();
2363 }
2364
2365 cson_object * cson_new_object()
2366 {
2367
2368 return cson_value_get_object( cson_value_new_object() );
2369 }
2370
2371 cson_value * cson_value_new_array()
2372 {
@@ -2608,11 +2608,11 @@
2608 {
2609 cson_int_t i = 0;
2610 int rc = 0;
2611 switch(val->api->typeID)
2612 {
2613 case CSON_TYPE_UNDEF:
2614 case CSON_TYPE_NULL:
2615 i = 0;
2616 break;
2617 case CSON_TYPE_BOOL: {
2618 char b = 0;
@@ -2661,11 +2661,11 @@
2661 {
2662 cson_double_t d = 0.0;
2663 int rc = 0;
2664 switch(val->api->typeID)
2665 {
2666 case CSON_TYPE_UNDEF:
2667 case CSON_TYPE_NULL:
2668 d = 0;
2669 break;
2670 case CSON_TYPE_BOOL: {
2671 char b = 0;
@@ -2791,11 +2791,11 @@
2791 #if 0
2792 /**
2793 Removes and returns the last value from the given array,
2794 shrinking its size by 1. Returns NULL if ar is NULL,
2795 ar->list.count is 0, or the element at that index is NULL.
2796
2797
2798 If removeRef is true then cson_value_free() is called to remove
2799 ar's reference count for the value. In that case NULL is returned,
2800 even if the object still has live references. If removeRef is false
2801 then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
2858 #if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
2859 assert( sizeof(cson_int_t) <= sizeof(void *) );
2860 #endif
2861 if( c )
2862 {
2863 memcpy(CSON_INT(c), &v, sizeof(v));
2864 }
2865 return c;
2866 }
2867 }
2868
@@ -2877,11 +2877,11 @@
2877 else
2878 {
2879 cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
2880 if( c )
2881 {
2882 memcpy(CSON_DBL(c), &v, sizeof(v));
2883 }
2884 return c;
2885 }
2886 }
2887
@@ -3068,11 +3068,11 @@
3068 qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
3069 cson_kvp_cmp );
3070 }
3071
3072 }
3073 #endif
3074
3075 int cson_object_unset( cson_object * obj, char const * key )
3076 {
3077 if( ! obj || !key || !*key ) return cson_rc.ArgError;
3078 else
@@ -3238,11 +3238,11 @@
3238 using p->key. In any other case cson_rc.InternalError is returned.
3239
3240 Returns cson_rc.AllocError if an allocation fails.
3241
3242 Returns 0 on success. On error, parsing must be ceased immediately.
3243
3244 Ownership of val is ALWAYS TRANSFERED to this function. If this
3245 function fails, val will be cleaned up and destroyed. (This
3246 simplifies error handling in the core parser.)
3247 */
3248 static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
3485 ++p->totalKeyCount;
3486 break;
3487 }
3488 case JSON_T_STRING: {
3489 cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490 rc = ( NULL == v )
3491 ? cson_rc.AllocError
3492 : cson_parser_push_value( p, v );
3493 break;
3494 }
3495 default:
@@ -3532,11 +3532,11 @@
3532 To properly take over ownership of the parser's root node on a
3533 successful parse:
3534
3535 - Copy p->root's pointer and set p->root to NULL.
3536 - Eventually free up p->root with cson_value_free().
3537
3538 If you do not set p->root to NULL, p->root will be freed along with
3539 any other items inserted into it (or under it) during the parsing
3540 process.
3541 */
3542 static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
3571 int rc = 0;
3572 unsigned int len = 1;
3573 cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
3574 cson_parser p = cson_parser_empty;
3575 if( ! tgt || ! src ) return cson_rc.ArgError;
3576
3577 {
3578 JSON_config jopt = {0};
3579 init_JSON_config( &jopt );
3580 jopt.allow_comments = opt.allowComments;
3581 jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
3780 unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
3781 unsigned char const * next = NULL;
3782 int ch;
3783 unsigned char clen = 0;
3784 char escChar[3] = {'\\',0,0};
3785 enum { UBLen = 13 };
3786 char ubuf[UBLen];
3787 int rc = 0;
3788 rc = f(state, "\"", 1 );
3789 for( ; (pos < end) && (0 == rc); pos += clen )
3790 {
@@ -4640,11 +4640,11 @@
4640 #endif
4641 #undef TRY_SHARING
4642 cson_value_add_reference(rc);
4643 return rc;
4644 }
4645
4646 static cson_value * cson_value_clone_array( cson_value const * orig )
4647 {
4648 unsigned int i = 0;
4649 cson_array const * asrc = cson_value_get_array( orig );
4650 unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
4680 cson_value_free(cl)/*remove our artificial reference */;
4681 }
4682 }
4683 return destV;
4684 }
4685
4686 static cson_value * cson_value_clone_object( cson_value const * orig )
4687 {
4688 cson_object const * src = cson_value_get_object( orig );
4689 cson_value * destV = NULL;
4690 cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
4834 }
4835 case CSON_TYPE_STRING: {
4836 cson_string const * jstr = cson_value_get_string(orig);
4837 unsigned const int slen = cson_string_length_bytes( jstr );
4838 assert( NULL != jstr );
4839 v = cson_strdup( cson_string_cstr( jstr ), slen );
4840 break;
4841 }
4842 case CSON_TYPE_INTEGER: {
4843 char buf[BufSize] = {0};
4844 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
4887 }
4888 case CSON_TYPE_STRING: {
4889 cson_string const * jstr = cson_value_get_string(orig);
4890 unsigned const int slen = cson_string_length_bytes( jstr );
4891 assert( NULL != jstr );
4892 v = cson_strdup( cson_string_cstr( jstr ), slen );
4893 break;
4894 }
4895 case CSON_TYPE_INTEGER: {
4896 char buf[BufSize] = {0};
4897 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
5351 int rc = 0;
5352 int colCount = 0;
5353 assert(st);
5354 colCount = sqlite3_column_count(st);
5355 if( colCount <= 0 ) return NULL;
5356
5357 aryV = cson_value_new_array();
5358 if( ! aryV ) return NULL;
5359 ary = cson_value_get_array(aryV);
5360 assert(ary);
5361 for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
5491 aryV = NULL;
5492 end:
5493 return aryV;
5494 }
5495
5496
5497 /**
5498 Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
5499 parameter is non-0.
5500 */
5501 static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
5636 int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
5637 if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
5638 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5639 sqlite3_finalize( st );
5640 return rc;
5641 }
5642 }
5643
5644 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5645 {
5646 int rc = 0;
5647
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
19 # define JSON_PARSER_DLL_API __declspec(dllexport)
20 # else
21 # define JSON_PARSER_DLL_API __declspec(dllimport)
22 # endif
23 # else
24 # define JSON_PARSER_DLL_API
25 # endif
26 #else
27 # define JSON_PARSER_DLL_API
28 #endif
29
30 /* Determine the integer type use to parse non-floating point numbers */
31 #ifdef _WIN32
32 typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
34 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
35 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
36 typedef long long JSON_int_t;
37 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
38 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39 #else
40 typedef long JSON_int_t;
41 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
42 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
43 #endif
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 typedef enum
51 {
52 JSON_E_NONE = 0,
53 JSON_E_INVALID_CHAR,
54 JSON_E_INVALID_KEYWORD,
55 JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
60 JSON_E_EXPECTED_KEY,
61 JSON_E_EXPECTED_COLON,
62 JSON_E_OUT_OF_MEMORY
63 } JSON_error;
64
65 typedef enum
66 {
67 JSON_T_NONE = 0,
68 JSON_T_ARRAY_BEGIN,
69 JSON_T_ARRAY_END,
70 JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
80 } JSON_type;
81
82 typedef struct JSON_value_struct {
83 union {
84 JSON_int_t integer_value;
85
86 double float_value;
87
88 struct {
89 const char* value;
90 size_t length;
91 } str;
92 } vu;
93 } JSON_value;
94
95 typedef struct JSON_parser_struct* JSON_parser;
96
97 /*! \brief JSON parser callback
98
99 \param ctx The pointer passed to new_JSON_parser.
100 \param type An element of JSON_type but not JSON_T_NONE.
101 \param value A representation of the parsed value. This parameter is NULL for
102 JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103 JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104 as zero-terminated C strings.
105
106 \return Non-zero if parsing should continue, else zero.
107 */
108 typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109
110
111 /**
112 A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115 /**
116 A typedef for deallocator functions semantically compatible with free().
117 */
118 typedef void (*JSON_free_t)(void* mem);
119
120 /*! \brief The structure used to configure a JSON parser object
121 */
122 typedef struct {
123 /** Pointer to a callback, called when the parser has something to tell
124 the user. This parameter may be NULL. In this case the input is
125 merely checked for validity.
@@ -176,17 +176,17 @@
176
177 \param config. Used to configure the parser.
178 */
179 JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180
181 /*! \brief Create a JSON parser object
182
183 \param config. Used to configure the parser. Set to NULL to use
184 the default configuration. See init_JSON_config. Its contents are
185 copied by this function, so it need not outlive the returned
186 object.
187
188 \return The parser object, which is owned by the caller and must eventually
189 be freed by calling delete_JSON_parser().
190 */
191 JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192
@@ -200,16 +200,16 @@
200 JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201
202 /*! \brief Finalize parsing.
203
204 Call this method once after all input characters have been consumed.
205
206 \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207 */
208 JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209
210 /*! \brief Determine if a given string is valid JSON white space
211
212 \return Non-zero if the string is valid, zero otherwise.
213 */
214 JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215
@@ -226,12 +226,12 @@
226 JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233
234 #endif /* JSON_PARSER_H */
235 /* end file parser/JSON_parser.h */
236 /* begin file parser/JSON_parser.c */
237 /*
@@ -1431,11 +1431,11 @@
1431 #if defined(__cplusplus)
1432 extern "C" {
1433 #endif
1434
1435
1436
1437 /**
1438 This type holds the "vtbl" for type-specific operations when
1439 working with cson_value objects.
1440
1441 All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
1583 */
1584 #define CSON_CAST(T,V) ((T*)((V)->value))
1585 /**
1586 Assumes V is a pointer to memory which is allocated as part of a
1587 cson_value instance (the bytes immediately after that part).
1588 Returns a pointer a a cson_value by subtracting sizeof(cson_value)
1589 from that address and casting it to a (cson_value*)
1590 */
1591 #define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
1592
1593 /**
@@ -1607,11 +1607,11 @@
1607 #define CSON_OBJ(V) CSON_CAST(cson_object,(V))
1608 #define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
1609
1610 /**
1611 Holds special shared "constant" (though they are non-const)
1612 values.
1613 */
1614 static struct CSON_EMPTY_HOLDER_
1615 {
1616 char trueValue;
1617 cson_string stringValue;
@@ -1620,17 +1620,17 @@
1620 cson_string_empty_m
1621 };
1622
1623 /**
1624 Indexes into the CSON_SPECIAL_VALUES array.
1625
1626 If this enum changes in any way,
1627 makes damned sure that CSON_SPECIAL_VALUES is updated
1628 to match!!!
1629 */
1630 enum CSON_INTERNAL_VALUES {
1631
1632 CSON_VAL_UNDEF = 0,
1633 CSON_VAL_NULL = 1,
1634 CSON_VAL_TRUE = 2,
1635 CSON_VAL_FALSE = 3,
1636 CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
1642 /**
1643 Some "special" shared cson_value instances.
1644
1645 These values MUST be initialized in the order specified
1646 by the CSON_INTERNAL_VALUES enum.
1647
1648 Note that they are not const because they are used as
1649 shared-allocation objects in non-const contexts. However, the
1650 public API provides no way to modifying them, and clients who
1651 modify values directly are subject to The Wrath of Undefined
1652 Behaviour.
@@ -1665,11 +1665,11 @@
1665
1666 /**
1667 Returns non-0 (true) if m is one of our special
1668 "built-in" values, e.g. from CSON_SPECIAL_VALUES and some
1669 "empty" values.
1670
1671 If this returns true, m MUST NOT be free()d!
1672 */
1673 static char cson_value_is_builtin( void const * m )
1674 {
1675 if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
2183 static int cson_value_list_visit( cson_value_list * self,
2184 int (*visitor)(cson_value * obj, void * visitorState ),
2185 void * visitorState );
2186 #endif
2187 #endif
2188
2189 #if 0
2190 # define LIST_T cson_value_list
2191 # define VALUE_T cson_value *
2192 # define VALUE_T_IS_PTR 1
2193 # define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
2362 return cson_value_object_alloc();
2363 }
2364
2365 cson_object * cson_new_object()
2366 {
2367
2368 return cson_value_get_object( cson_value_new_object() );
2369 }
2370
2371 cson_value * cson_value_new_array()
2372 {
@@ -2608,11 +2608,11 @@
2608 {
2609 cson_int_t i = 0;
2610 int rc = 0;
2611 switch(val->api->typeID)
2612 {
2613 case CSON_TYPE_UNDEF:
2614 case CSON_TYPE_NULL:
2615 i = 0;
2616 break;
2617 case CSON_TYPE_BOOL: {
2618 char b = 0;
@@ -2661,11 +2661,11 @@
2661 {
2662 cson_double_t d = 0.0;
2663 int rc = 0;
2664 switch(val->api->typeID)
2665 {
2666 case CSON_TYPE_UNDEF:
2667 case CSON_TYPE_NULL:
2668 d = 0;
2669 break;
2670 case CSON_TYPE_BOOL: {
2671 char b = 0;
@@ -2791,11 +2791,11 @@
2791 #if 0
2792 /**
2793 Removes and returns the last value from the given array,
2794 shrinking its size by 1. Returns NULL if ar is NULL,
2795 ar->list.count is 0, or the element at that index is NULL.
2796
2797
2798 If removeRef is true then cson_value_free() is called to remove
2799 ar's reference count for the value. In that case NULL is returned,
2800 even if the object still has live references. If removeRef is false
2801 then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
2858 #if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
2859 assert( sizeof(cson_int_t) <= sizeof(void *) );
2860 #endif
2861 if( c )
2862 {
2863 memcpy( CSON_INT(c), &v, sizeof(v) );
2864 }
2865 return c;
2866 }
2867 }
2868
@@ -2877,11 +2877,11 @@
2877 else
2878 {
2879 cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
2880 if( c )
2881 {
2882 memcpy( CSON_DBL(c), &v, sizeof(v) );
2883 }
2884 return c;
2885 }
2886 }
2887
@@ -3068,11 +3068,11 @@
3068 qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
3069 cson_kvp_cmp );
3070 }
3071
3072 }
3073 #endif
3074
3075 int cson_object_unset( cson_object * obj, char const * key )
3076 {
3077 if( ! obj || !key || !*key ) return cson_rc.ArgError;
3078 else
@@ -3238,11 +3238,11 @@
3238 using p->key. In any other case cson_rc.InternalError is returned.
3239
3240 Returns cson_rc.AllocError if an allocation fails.
3241
3242 Returns 0 on success. On error, parsing must be ceased immediately.
3243
3244 Ownership of val is ALWAYS TRANSFERED to this function. If this
3245 function fails, val will be cleaned up and destroyed. (This
3246 simplifies error handling in the core parser.)
3247 */
3248 static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
3485 ++p->totalKeyCount;
3486 break;
3487 }
3488 case JSON_T_STRING: {
3489 cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490 rc = ( NULL == v )
3491 ? cson_rc.AllocError
3492 : cson_parser_push_value( p, v );
3493 break;
3494 }
3495 default:
@@ -3532,11 +3532,11 @@
3532 To properly take over ownership of the parser's root node on a
3533 successful parse:
3534
3535 - Copy p->root's pointer and set p->root to NULL.
3536 - Eventually free up p->root with cson_value_free().
3537
3538 If you do not set p->root to NULL, p->root will be freed along with
3539 any other items inserted into it (or under it) during the parsing
3540 process.
3541 */
3542 static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
3571 int rc = 0;
3572 unsigned int len = 1;
3573 cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
3574 cson_parser p = cson_parser_empty;
3575 if( ! tgt || ! src ) return cson_rc.ArgError;
3576
3577 {
3578 JSON_config jopt = {0};
3579 init_JSON_config( &jopt );
3580 jopt.allow_comments = opt.allowComments;
3581 jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
3780 unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
3781 unsigned char const * next = NULL;
3782 int ch;
3783 unsigned char clen = 0;
3784 char escChar[3] = {'\\',0,0};
3785 enum { UBLen = 20 };
3786 char ubuf[UBLen];
3787 int rc = 0;
3788 rc = f(state, "\"", 1 );
3789 for( ; (pos < end) && (0 == rc); pos += clen )
3790 {
@@ -4640,11 +4640,11 @@
4640 #endif
4641 #undef TRY_SHARING
4642 cson_value_add_reference(rc);
4643 return rc;
4644 }
4645
4646 static cson_value * cson_value_clone_array( cson_value const * orig )
4647 {
4648 unsigned int i = 0;
4649 cson_array const * asrc = cson_value_get_array( orig );
4650 unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
4680 cson_value_free(cl)/*remove our artificial reference */;
4681 }
4682 }
4683 return destV;
4684 }
4685
4686 static cson_value * cson_value_clone_object( cson_value const * orig )
4687 {
4688 cson_object const * src = cson_value_get_object( orig );
4689 cson_value * destV = NULL;
4690 cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
4834 }
4835 case CSON_TYPE_STRING: {
4836 cson_string const * jstr = cson_value_get_string(orig);
4837 unsigned const int slen = cson_string_length_bytes( jstr );
4838 assert( NULL != jstr );
4839 v = cson_strdup( cson_string_cstr( jstr ), slen );
4840 break;
4841 }
4842 case CSON_TYPE_INTEGER: {
4843 char buf[BufSize] = {0};
4844 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
4887 }
4888 case CSON_TYPE_STRING: {
4889 cson_string const * jstr = cson_value_get_string(orig);
4890 unsigned const int slen = cson_string_length_bytes( jstr );
4891 assert( NULL != jstr );
4892 v = cson_strdup( cson_string_cstr( jstr ), slen );
4893 break;
4894 }
4895 case CSON_TYPE_INTEGER: {
4896 char buf[BufSize] = {0};
4897 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
5351 int rc = 0;
5352 int colCount = 0;
5353 assert(st);
5354 colCount = sqlite3_column_count(st);
5355 if( colCount <= 0 ) return NULL;
5356
5357 aryV = cson_value_new_array();
5358 if( ! aryV ) return NULL;
5359 ary = cson_value_get_array(aryV);
5360 assert(ary);
5361 for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
5491 aryV = NULL;
5492 end:
5493 return aryV;
5494 }
5495
5496
5497 /**
5498 Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
5499 parameter is non-0.
5500 */
5501 static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
5636 int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
5637 if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
5638 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5639 sqlite3_finalize( st );
5640 return rc;
5641 }
5642 }
5643
5644 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5645 {
5646 int rc = 0;
5647
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
5959
#define CSON_INT_T_PFMT "I64d"
6060
#elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
6161
typedef long long cson_int_t;
6262
#define CSON_INT_T_SFMT "lld"
6363
#define CSON_INT_T_PFMT "lld"
64
-#else
64
+#else
6565
typedef long cson_int_t;
6666
#define CSON_INT_T_SFMT "ld"
6767
#define CSON_INT_T_PFMT "ld"
6868
#endif
6969
@@ -215,11 +215,11 @@
215215
Convenience typedef.
216216
*/
217217
typedef struct cson_value cson_value;
218218
219219
/** @struct cson_value
220
-
220
+
221221
The core value type of this API. It is opaque to clients, and
222222
only the cson public API should be used for setting or
223223
inspecting their values.
224224
225225
This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231231
counting) as long as those insertions do not cause cycles. However,
232232
be very aware that such value re-use uses a reference to the
233233
original copy, meaning that if its value is changed once, it is
234234
changed everywhere. Also beware that multi-threaded write
235235
operations on such references leads to undefined behaviour.
236
-
236
+
237237
PLEASE read the ACHTUNGEN below...
238238
239239
ACHTUNG #1:
240240
241241
cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244244
Not abiding th Holy Law Of No Cycles will lead to double-frees and
245245
the like (i.e. undefined behaviour, likely crashes due to infinite
246246
recursion or stepping on invalid (freed) pointers).
247247
248248
ACHTUNG #2:
249
-
249
+
250250
ALL cson_values returned as non-const cson_value pointers from any
251251
public functions in the cson API are to be treated as if they are
252252
heap-allocated, and MUST be freed by client by doing ONE of:
253
-
253
+
254254
- Passing it to cson_value_free().
255
-
255
+
256256
- Adding it to an Object or Array, in which case the object/array
257257
takes over ownership. As of 20110323, a value may be inserted into
258258
a single container multiple times, or into multiple containers,
259259
in which case they all share ownership (via reference counting)
260260
of the original value (meaning any changes to it are visible in
261261
all references to it).
262
-
262
+
263263
Each call to cson_value_new_xxx() MUST eventually be followed up
264264
by one of those options.
265
-
265
+
266266
Some cson_value_new_XXX() implementations do not actually allocate
267267
memory, but this is an internal implementation detail. Client code
268268
MUST NOT rely on this behaviour and MUST treat each object
269269
returned by such a function as if it was a freshly-allocated copy
270270
(even if their pointer addresses are the same).
271
-
271
+
272272
ACHTUNG #3:
273273
274274
Note that ACHTUNG #2 tells us that we must always free (or transfer
275275
ownership of) all pointers returned bycson_value_new_xxx(), but
276276
that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315315
if( 0 == rc ) {...success...}
316316
else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317317
else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318318
...
319319
@endcode
320
-
320
+
321321
The entries named Parse_XXX are generally only returned by
322322
cson_parse() and friends.
323323
*/
324324
325325
/** @struct cson_rc_
@@ -472,11 +472,11 @@
472472
473473
/**
474474
Length, in bytes.
475475
*/
476476
unsigned int length;
477
-
477
+
478478
/**
479479
Error code of the parse run (0 for no error).
480480
*/
481481
int errorCode;
482482
@@ -523,11 +523,11 @@
523523
/**
524524
Specifies how to indent (or not) output. The values
525525
are:
526526
527527
(0) == no extra indentation.
528
-
528
+
529529
(1) == 1 TAB character for each level.
530530
531531
(>1) == that number of SPACES for each level.
532532
*/
533533
unsigned char indentation;
@@ -536,11 +536,11 @@
536536
Maximum object/array depth to traverse. Traversing deeply can
537537
be indicative of cycles in the object/array tree, and this
538538
value is used to figure out when to abort the traversal.
539539
*/
540540
unsigned short maxDepth;
541
-
541
+
542542
/**
543543
If true, a newline will be added to generated output,
544544
else not.
545545
*/
546546
char addNewline;
@@ -636,11 +636,11 @@
636636
637637
Must return 0 on success, non-0 on error (preferably a value from
638638
cson_rc).
639639
640640
These functions are called relatively often during the JSON-output
641
- process, and should try to be fast.
641
+ process, and should try to be fast.
642642
*/
643643
typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644644
645645
/**
646646
Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664664
used.
665665
666666
The info argument may be NULL. If it is not NULL then the parser
667667
populates it with information which is useful in error
668668
reporting. Namely, it contains the line/column of parse errors.
669
-
669
+
670670
The srcState argument is ignored by this function but is passed on to src,
671671
so any output-destination-specific state can be stored there and accessed
672672
via the src callback.
673
-
673
+
674674
Non-parse error conditions include:
675675
676676
- (!tgt) or !src: cson_rc.ArgError
677677
- cson_rc.AllocError can happen at any time during the input phase
678678
@@ -725,11 +725,11 @@
725725
TODOs:
726726
727727
- Buffer the input in larger chunks. We currently read
728728
byte-by-byte, but i'm too tired to write/test the looping code for
729729
the buffering.
730
-
730
+
731731
@see cson_parse_FILE()
732732
@see cson_parse_string()
733733
*/
734734
int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735735
cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786786
The destState parameter is ignored by this function and is passed
787787
on to the dest function.
788788
789789
Returns 0 on success. On error, any amount of output might have been
790790
generated before the error was triggered.
791
-
791
+
792792
Example:
793793
794794
@code
795795
int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796796
// basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925925
/**
926926
Converts the given value to a boolean, using JavaScript semantics depending
927927
on the concrete type of val:
928928
929929
undef or null: false
930
-
930
+
931931
boolean: same
932
-
932
+
933933
integer, double: 0 or 0.0 == false, else true
934
-
934
+
935935
object, array: true
936936
937937
string: length-0 string is false, else true.
938938
939939
Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945945
Similar to cson_value_fetch_bool(), but fetches an integer value.
946946
947947
The conversion, if any, depends on the concrete type of val:
948948
949949
NULL, null, undefined: *v is set to 0 and 0 is returned.
950
-
950
+
951951
string, object, array: *v is set to 0 and
952952
cson_rc.TypeError is returned. The error may normally be safely
953953
ignored, but it is provided for those wanted to know whether a direct
954954
conversion was possible.
955955
956956
integer: *v is set to the int value and 0 is returned.
957
-
957
+
958958
double: *v is set to the value truncated to int and 0 is returned.
959959
*/
960960
int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961961
962962
/**
@@ -1084,11 +1084,11 @@
10841084
10851085
- The maximum number of bytes compared is the lesser of rhsLen and
10861086
the length of lhs. If the strings do not match, but compare equal
10871087
up to the just-described comparison length, the shorter string is
10881088
considered to be less-than the longer one.
1089
-
1089
+
10901090
- If lhs and rhs are both NULL, or both have a length of 0 then they will
10911091
compare equal.
10921092
10931093
- If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
10941094
rhs.
@@ -1110,11 +1110,11 @@
11101110
Returns the length, in bytes, of str, or 0 if str is NULL. This is
11111111
an O(1) operation.
11121112
11131113
TODO: add cson_string_length_chars() (is O(N) unless we add another
11141114
member to store the char length).
1115
-
1115
+
11161116
@see cson_string_cstr()
11171117
*/
11181118
unsigned int cson_string_length_bytes( cson_string const * str );
11191119
11201120
/**
@@ -1207,11 +1207,11 @@
12071207
ar is expanded, if needed, to be able to hold at least (ndx+1)
12081208
items, and any new entries created by that expansion are empty
12091209
(NULL values).
12101210
12111211
On success, 0 is returned and ownership of v is transfered to ar.
1212
-
1212
+
12131213
On error ownership of v is NOT modified, and the caller may still
12141214
need to clean it up. For example, the following code will introduce
12151215
a leak if this function fails:
12161216
12171217
@code
@@ -1240,11 +1240,11 @@
12401240
12411241
This is functionally equivalent to
12421242
cson_array_set(ar,cson_array_length_get(ar),v), but this
12431243
implementation has slightly different array-preallocation policy
12441244
(it grows more eagerly).
1245
-
1245
+
12461246
Returns 0 on success, non-zero on error. Error cases include:
12471247
12481248
- ar or v are NULL: cson_rc.ArgError
12491249
12501250
- Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
12831283
cson_value * cson_new_bool(char v);
12841284
12851285
/**
12861286
Returns the special JSON "null" value. When outputing JSON,
12871287
its string representation is "null" (without the quotes).
1288
-
1288
+
12891289
See cson_value_new_bool() for notes regarding the returned
12901290
value's memory.
12911291
*/
12921292
cson_value * cson_value_null();
12931293
@@ -1323,16 +1323,16 @@
13231323
13241324
/**
13251325
Semantically the same as cson_value_new_bool(), but for strings.
13261326
This creates a JSON value which copies the first n bytes of str.
13271327
The string will automatically be NUL-terminated.
1328
-
1328
+
13291329
Note that if str is NULL or n is 0, this function still
13301330
returns non-NULL value representing that empty string.
1331
-
1331
+
13321332
Returns NULL on allocation error.
1333
-
1333
+
13341334
See cson_value_new_bool() for important information about the
13351335
returned memory.
13361336
*/
13371337
cson_value * cson_value_new_string( char const * str, unsigned int n );
13381338
@@ -1354,11 +1354,11 @@
13541354
This works like cson_value_new_object() but returns an Object
13551355
handle directly.
13561356
13571357
The value handle for the returned object can be fetched with
13581358
cson_object_value(theObject).
1359
-
1359
+
13601360
Ownership is transfered to the caller, who must eventually free it
13611361
by passing the Value handle (NOT the Object handle) to
13621362
cson_value_free() or passing ownership to a parent container.
13631363
13641364
Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
14191419
cson_value_add_reference(). Even if this function does not
14201420
immediately destroy the value, the value must be considered, from
14211421
the perspective of that client code, to have been
14221422
destroyed/invalidated by this call.
14231423
1424
-
1424
+
14251425
@see cson_value_new_object()
14261426
@see cson_value_new_array()
14271427
@see cson_value_add_reference()
14281428
*/
14291429
void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
14451445
case, the key is set to the special null value.
14461446
14471447
The key may be encoded as ASCII or UTF8. Results are undefined
14481448
with other encodings, and the errors won't show up here, but may
14491449
show up later, e.g. during output.
1450
-
1450
+
14511451
Returns 0 on success, non-0 on error. It has the following error
14521452
cases:
14531453
14541454
- cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
14551455
@@ -1498,11 +1498,11 @@
14981498
*/
14991499
int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
15001500
15011501
/**
15021502
Removes a property from an object.
1503
-
1503
+
15041504
If obj contains the given key, it is removed and 0 is returned. If
15051505
it is not found, cson_rc.NotFoundError is returned (which can
15061506
normally be ignored by client code).
15071507
15081508
cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
15691569
15701570
If it finds the given path, it returns the value by assiging *tgt
15711571
to it. If tgt is NULL then this function has no side-effects but
15721572
will return 0 if the given path is found within the object, so it can be used
15731573
to test for existence without fetching it.
1574
-
1574
+
15751575
Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
15761576
no item, and any other non-zero error code on a "real" error. Errors include:
15771577
15781578
- obj or path are NULL: cson_rc.ArgError
1579
-
1579
+
15801580
- separator is 0, or path is an empty string or contains only
15811581
separator characters: cson_rc.RangeError
15821582
15831583
- There is an upper limit on how long a single path component may
15841584
be (some "reasonable" internal size), and cson_rc.RangeError is
15851585
returned if that length is violated.
15861586
1587
-
1587
+
15881588
Limitations:
15891589
15901590
- It has no way to fetch data from arrays this way. i could
15911591
imagine, e.g., a path of "subobj.subArray.0" for
15921592
subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
15931593
lazy/tired to add this.
15941594
15951595
Example usage:
1596
-
1596
+
15971597
15981598
Assume we have a JSON structure which abstractly looks like:
15991599
16001600
@code
16011601
{"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
16131613
"subobj/subsubobj/myValue" with separator='/' is equivalent the
16141614
path "subobj.subsubobj.myValue" with separator='.'. The value of 0
16151615
is not legal as a separator character because we cannot
16161616
distinguish that use from the real end-of-string without requiring
16171617
the caller to also pass in the length of the string.
1618
-
1618
+
16191619
Multiple successive separators in the list are collapsed into a
16201620
single separator for parsing purposes. e.g. the path "a...b...c"
16211621
(separator='.') is equivalent to "a.b.c".
16221622
16231623
@see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
17001700
@see cson_object_iter_init()
17011701
@see cson_object_iter_next()
17021702
*/
17031703
struct cson_object_iterator
17041704
{
1705
-
1705
+
17061706
/** @internal
17071707
The underlying object.
17081708
*/
17091709
cson_object const * obj;
17101710
/** @internal
@@ -1771,11 +1771,11 @@
17711771
...
17721772
}
17731773
@endcode
17741774
17751775
There is no need to clean up an iterator, as it holds no dynamic resources.
1776
-
1776
+
17771777
@see cson_kvp_key()
17781778
@see cson_kvp_value()
17791779
*/
17801780
cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
17811781
@@ -1863,11 +1863,11 @@
18631863
buf = cson_buffer_empty;
18641864
@endcode
18651865
18661866
(You might also need to store buf.used and buf.capacity,
18671867
depending on what you want to do with the memory.)
1868
-
1868
+
18691869
When doing so, the memory must eventually be passed to free()
18701870
to deallocate it.
18711871
*/
18721872
unsigned char * mem;
18731873
};
@@ -1894,11 +1894,11 @@
18941894
On error non-zero is returned. Errors include:
18951895
18961896
- Invalid arguments: cson_rc.ArgError
18971897
18981898
- Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
-
1899
+
19001900
Example usage:
19011901
19021902
@code
19031903
cson_buffer buf = cson_buffer_empty;
19041904
// optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
19181918
buf = cson_buffer_empty;
19191919
...
19201920
free(mem);
19211921
}
19221922
@endcode
1923
-
1923
+
19241924
@see cson_output()
1925
-
1925
+
19261926
*/
19271927
int cson_output_buffer( cson_value const * v, cson_buffer * buf,
19281928
cson_output_opt const * opt );
19291929
19301930
/**
@@ -1993,11 +1993,11 @@
19931993
calling cson_buffer_reserve(dest,0).
19941994
19951995
dest->mem might (and possibly will) be (re)allocated by this
19961996
function, so any pointers to it held from before this call might be
19971997
invalidated by this call.
1998
-
1998
+
19991999
On error non-0 is returned and dest has almost certainly been
20002000
modified but its state must be considered incomplete.
20012001
20022002
Errors include:
20032003
@@ -2042,11 +2042,11 @@
20422042
void * mem = buf.mem;
20432043
buf = cson_buffer_empty;
20442044
@endcode
20452045
20462046
In which case the memory must eventually be passed to free() to
2047
- free it.
2047
+ free it.
20482048
*/
20492049
int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
20502050
20512051
20522052
/**
@@ -2072,11 +2072,11 @@
20722072
for other sharing points which added a reference.
20732073
20742074
Normally any such value handles would be invalidated when the
20752075
parent container(s) is/are cleaned up, but this function can be
20762076
used to effectively delay the cleanup.
2077
-
2077
+
20782078
This function, at its lowest level, increments the value's
20792079
reference count by 1.
20802080
20812081
To decrement the reference count, pass the value to
20822082
cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
20912091
errors long before the reference count could overflow (assuming
20922092
those reference counts come from container insertions, as opposed
20932093
to via this function).
20942094
20952095
Insider notes which clients really need to know:
2096
-
2096
+
20972097
For shared/constant value instances, such as those returned by
20982098
cson_value_true() and cson_value_null(), this function has no side
20992099
effects - it does not actually modify the reference count because
21002100
(A) those instances are shared across all client code and (B) those
21012101
objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
21732173
returned object will be of the same logical type as orig.
21742174
21752175
ACHTUNG: if orig contains any cyclic references at any depth level
21762176
this function will endlessly recurse. (Having _any_ cyclic
21772177
references violates this library's requirements.)
2178
-
2178
+
21792179
Returns NULL if orig is NULL or if cloning fails. Assuming that
21802180
orig is in a valid state, the only "likely" error case is that an
21812181
allocation fails while constructing the clone. In other words, if
21822182
cloning fails due to something other than an allocation error then
21832183
either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
22782278
--key=VAL : Treats VAL as either a double, integer, or string.
22792279
22802280
--key= : Treats key as a JSON null (not literal NULL) value.
22812281
22822282
Arguments not starting with a dash are skipped.
2283
-
2283
+
22842284
Each key/value pair is inserted into an object. If a given key
22852285
appears more than once then only the final entry is actually
22862286
stored.
22872287
22882288
argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
24342434
Integer, double, null, or string (TEXT and BLOB data, though not
24352435
all blob data is legal for a JSON string).
24362436
24372437
st must be a sqlite3_step()'d row and col must be a 0-based column
24382438
index within that result row.
2439
- */
2439
+ */
24402440
cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
24412441
24422442
/**
24432443
Creates a JSON Array object containing the names of all columns
2444
- of the given prepared statement handle.
2445
-
2444
+ of the given prepared statement handle.
2445
+
24462446
Returns a new array value on success, which the caller owns. Its elements
24472447
are in the same order as in the underlying query.
24482448
24492449
On error NULL is returned.
2450
-
2450
+
24512451
st is not traversed or freed by this function - only the column
24522452
count and names are read.
24532453
*/
24542454
cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
24552455
@@ -2494,22 +2494,22 @@
24942494
*/
24952495
cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
24962496
/**
24972497
Converts the results of an sqlite3 SELECT statement to JSON,
24982498
in the form of a cson_value object tree.
2499
-
2499
+
25002500
st must be a prepared, but not yet traversed, SELECT query.
25012501
tgt must be a pointer to NULL (see the example below). If
25022502
either of those arguments are NULL, cson_rc.ArgError is returned.
2503
-
2503
+
25042504
This walks the query results and returns a JSON object which
25052505
has a different structure depending on the value of the 'fat'
25062506
argument.
2507
-
2508
-
2507
+
2508
+
25092509
If 'fat' is 0 then the structure is:
2510
-
2510
+
25112511
@code
25122512
{
25132513
"columns":["colName1",..."colNameN"],
25142514
"rows":[
25152515
[colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
25162516
[colVal0, ... colValN],
25172517
...
25182518
]
25192519
}
25202520
@endcode
2521
-
2521
+
25222522
In the "non-fat" format the order of the columns and row values is
25232523
guaranteed to be the same as that of the underlying query.
2524
-
2524
+
25252525
If 'fat' is not 0 then the structure is:
2526
-
2526
+
25272527
@code
25282528
{
25292529
"columns":["colName1",..."colNameN"],
25302530
"rows":[
25312531
{"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
25432543
25442544
On success it returns 0 and assigns *tgt to a newly-allocated
25452545
JSON object tree (using the above structure), which the caller owns.
25462546
If the query returns no rows, the "rows" value will be an empty
25472547
array, as opposed to null.
2548
-
2548
+
25492549
On error non-0 is returned and *tgt is not modified.
2550
-
2550
+
25512551
The error code cson_rc.IOError is used to indicate a db-level
25522552
error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
25532553
returns 0 or less (indicating an invalid or non-SELECT statement).
2554
-
2554
+
25552555
The JSON data types are determined by the column type as reported
25562556
by sqlite3_column_type():
2557
-
2557
+
25582558
SQLITE_INTEGER: integer
2559
-
2559
+
25602560
SQLITE_FLOAT: double
2561
-
2561
+
25622562
SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
25632563
the data is UTF8 compatible.
2564
-
2564
+
25652565
If the db returns a literal or SQL NULL for a value it is converted
25662566
to a JSON null. If it somehow finds a column type it cannot handle,
25672567
the value is also converted to a NULL in the output.
25682568
25692569
Example
2570
-
2570
+
25712571
@code
25722572
cson_value * json = NULL;
25732573
int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
25742574
if( 0 != rc ) { ... error ... }
25752575
else {
@@ -2603,14 +2603,14 @@
26032603
TODO: add Object support for named parameters.
26042604
26052605
Returns 0 on success, non-0 on error.
26062606
*/
26072607
int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
-
2608
+
26092609
#if defined(__cplusplus)
26102610
} /*extern "C"*/
26112611
#endif
2612
-
2612
+
26132613
#endif /* CSON_ENABLE_SQLITE3 */
26142614
#endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
26152615
/* end file include/wh/cson/cson_sqlite3.h */
26162616
#endif /* FOSSIL_ENABLE_JSON */
26172617
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
59 #define CSON_INT_T_PFMT "I64d"
60 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
61 typedef long long cson_int_t;
62 #define CSON_INT_T_SFMT "lld"
63 #define CSON_INT_T_PFMT "lld"
64 #else
65 typedef long cson_int_t;
66 #define CSON_INT_T_SFMT "ld"
67 #define CSON_INT_T_PFMT "ld"
68 #endif
69
@@ -215,11 +215,11 @@
215 Convenience typedef.
216 */
217 typedef struct cson_value cson_value;
218
219 /** @struct cson_value
220
221 The core value type of this API. It is opaque to clients, and
222 only the cson public API should be used for setting or
223 inspecting their values.
224
225 This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231 counting) as long as those insertions do not cause cycles. However,
232 be very aware that such value re-use uses a reference to the
233 original copy, meaning that if its value is changed once, it is
234 changed everywhere. Also beware that multi-threaded write
235 operations on such references leads to undefined behaviour.
236
237 PLEASE read the ACHTUNGEN below...
238
239 ACHTUNG #1:
240
241 cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244 Not abiding th Holy Law Of No Cycles will lead to double-frees and
245 the like (i.e. undefined behaviour, likely crashes due to infinite
246 recursion or stepping on invalid (freed) pointers).
247
248 ACHTUNG #2:
249
250 ALL cson_values returned as non-const cson_value pointers from any
251 public functions in the cson API are to be treated as if they are
252 heap-allocated, and MUST be freed by client by doing ONE of:
253
254 - Passing it to cson_value_free().
255
256 - Adding it to an Object or Array, in which case the object/array
257 takes over ownership. As of 20110323, a value may be inserted into
258 a single container multiple times, or into multiple containers,
259 in which case they all share ownership (via reference counting)
260 of the original value (meaning any changes to it are visible in
261 all references to it).
262
263 Each call to cson_value_new_xxx() MUST eventually be followed up
264 by one of those options.
265
266 Some cson_value_new_XXX() implementations do not actually allocate
267 memory, but this is an internal implementation detail. Client code
268 MUST NOT rely on this behaviour and MUST treat each object
269 returned by such a function as if it was a freshly-allocated copy
270 (even if their pointer addresses are the same).
271
272 ACHTUNG #3:
273
274 Note that ACHTUNG #2 tells us that we must always free (or transfer
275 ownership of) all pointers returned bycson_value_new_xxx(), but
276 that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315 if( 0 == rc ) {...success...}
316 else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317 else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318 ...
319 @endcode
320
321 The entries named Parse_XXX are generally only returned by
322 cson_parse() and friends.
323 */
324
325 /** @struct cson_rc_
@@ -472,11 +472,11 @@
472
473 /**
474 Length, in bytes.
475 */
476 unsigned int length;
477
478 /**
479 Error code of the parse run (0 for no error).
480 */
481 int errorCode;
482
@@ -523,11 +523,11 @@
523 /**
524 Specifies how to indent (or not) output. The values
525 are:
526
527 (0) == no extra indentation.
528
529 (1) == 1 TAB character for each level.
530
531 (>1) == that number of SPACES for each level.
532 */
533 unsigned char indentation;
@@ -536,11 +536,11 @@
536 Maximum object/array depth to traverse. Traversing deeply can
537 be indicative of cycles in the object/array tree, and this
538 value is used to figure out when to abort the traversal.
539 */
540 unsigned short maxDepth;
541
542 /**
543 If true, a newline will be added to generated output,
544 else not.
545 */
546 char addNewline;
@@ -636,11 +636,11 @@
636
637 Must return 0 on success, non-0 on error (preferably a value from
638 cson_rc).
639
640 These functions are called relatively often during the JSON-output
641 process, and should try to be fast.
642 */
643 typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644
645 /**
646 Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664 used.
665
666 The info argument may be NULL. If it is not NULL then the parser
667 populates it with information which is useful in error
668 reporting. Namely, it contains the line/column of parse errors.
669
670 The srcState argument is ignored by this function but is passed on to src,
671 so any output-destination-specific state can be stored there and accessed
672 via the src callback.
673
674 Non-parse error conditions include:
675
676 - (!tgt) or !src: cson_rc.ArgError
677 - cson_rc.AllocError can happen at any time during the input phase
678
@@ -725,11 +725,11 @@
725 TODOs:
726
727 - Buffer the input in larger chunks. We currently read
728 byte-by-byte, but i'm too tired to write/test the looping code for
729 the buffering.
730
731 @see cson_parse_FILE()
732 @see cson_parse_string()
733 */
734 int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735 cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786 The destState parameter is ignored by this function and is passed
787 on to the dest function.
788
789 Returns 0 on success. On error, any amount of output might have been
790 generated before the error was triggered.
791
792 Example:
793
794 @code
795 int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796 // basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925 /**
926 Converts the given value to a boolean, using JavaScript semantics depending
927 on the concrete type of val:
928
929 undef or null: false
930
931 boolean: same
932
933 integer, double: 0 or 0.0 == false, else true
934
935 object, array: true
936
937 string: length-0 string is false, else true.
938
939 Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945 Similar to cson_value_fetch_bool(), but fetches an integer value.
946
947 The conversion, if any, depends on the concrete type of val:
948
949 NULL, null, undefined: *v is set to 0 and 0 is returned.
950
951 string, object, array: *v is set to 0 and
952 cson_rc.TypeError is returned. The error may normally be safely
953 ignored, but it is provided for those wanted to know whether a direct
954 conversion was possible.
955
956 integer: *v is set to the int value and 0 is returned.
957
958 double: *v is set to the value truncated to int and 0 is returned.
959 */
960 int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961
962 /**
@@ -1084,11 +1084,11 @@
1084
1085 - The maximum number of bytes compared is the lesser of rhsLen and
1086 the length of lhs. If the strings do not match, but compare equal
1087 up to the just-described comparison length, the shorter string is
1088 considered to be less-than the longer one.
1089
1090 - If lhs and rhs are both NULL, or both have a length of 0 then they will
1091 compare equal.
1092
1093 - If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
1094 rhs.
@@ -1110,11 +1110,11 @@
1110 Returns the length, in bytes, of str, or 0 if str is NULL. This is
1111 an O(1) operation.
1112
1113 TODO: add cson_string_length_chars() (is O(N) unless we add another
1114 member to store the char length).
1115
1116 @see cson_string_cstr()
1117 */
1118 unsigned int cson_string_length_bytes( cson_string const * str );
1119
1120 /**
@@ -1207,11 +1207,11 @@
1207 ar is expanded, if needed, to be able to hold at least (ndx+1)
1208 items, and any new entries created by that expansion are empty
1209 (NULL values).
1210
1211 On success, 0 is returned and ownership of v is transfered to ar.
1212
1213 On error ownership of v is NOT modified, and the caller may still
1214 need to clean it up. For example, the following code will introduce
1215 a leak if this function fails:
1216
1217 @code
@@ -1240,11 +1240,11 @@
1240
1241 This is functionally equivalent to
1242 cson_array_set(ar,cson_array_length_get(ar),v), but this
1243 implementation has slightly different array-preallocation policy
1244 (it grows more eagerly).
1245
1246 Returns 0 on success, non-zero on error. Error cases include:
1247
1248 - ar or v are NULL: cson_rc.ArgError
1249
1250 - Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
1283 cson_value * cson_new_bool(char v);
1284
1285 /**
1286 Returns the special JSON "null" value. When outputing JSON,
1287 its string representation is "null" (without the quotes).
1288
1289 See cson_value_new_bool() for notes regarding the returned
1290 value's memory.
1291 */
1292 cson_value * cson_value_null();
1293
@@ -1323,16 +1323,16 @@
1323
1324 /**
1325 Semantically the same as cson_value_new_bool(), but for strings.
1326 This creates a JSON value which copies the first n bytes of str.
1327 The string will automatically be NUL-terminated.
1328
1329 Note that if str is NULL or n is 0, this function still
1330 returns non-NULL value representing that empty string.
1331
1332 Returns NULL on allocation error.
1333
1334 See cson_value_new_bool() for important information about the
1335 returned memory.
1336 */
1337 cson_value * cson_value_new_string( char const * str, unsigned int n );
1338
@@ -1354,11 +1354,11 @@
1354 This works like cson_value_new_object() but returns an Object
1355 handle directly.
1356
1357 The value handle for the returned object can be fetched with
1358 cson_object_value(theObject).
1359
1360 Ownership is transfered to the caller, who must eventually free it
1361 by passing the Value handle (NOT the Object handle) to
1362 cson_value_free() or passing ownership to a parent container.
1363
1364 Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
1419 cson_value_add_reference(). Even if this function does not
1420 immediately destroy the value, the value must be considered, from
1421 the perspective of that client code, to have been
1422 destroyed/invalidated by this call.
1423
1424
1425 @see cson_value_new_object()
1426 @see cson_value_new_array()
1427 @see cson_value_add_reference()
1428 */
1429 void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
1445 case, the key is set to the special null value.
1446
1447 The key may be encoded as ASCII or UTF8. Results are undefined
1448 with other encodings, and the errors won't show up here, but may
1449 show up later, e.g. during output.
1450
1451 Returns 0 on success, non-0 on error. It has the following error
1452 cases:
1453
1454 - cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
1455
@@ -1498,11 +1498,11 @@
1498 */
1499 int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
1500
1501 /**
1502 Removes a property from an object.
1503
1504 If obj contains the given key, it is removed and 0 is returned. If
1505 it is not found, cson_rc.NotFoundError is returned (which can
1506 normally be ignored by client code).
1507
1508 cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
1569
1570 If it finds the given path, it returns the value by assiging *tgt
1571 to it. If tgt is NULL then this function has no side-effects but
1572 will return 0 if the given path is found within the object, so it can be used
1573 to test for existence without fetching it.
1574
1575 Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
1576 no item, and any other non-zero error code on a "real" error. Errors include:
1577
1578 - obj or path are NULL: cson_rc.ArgError
1579
1580 - separator is 0, or path is an empty string or contains only
1581 separator characters: cson_rc.RangeError
1582
1583 - There is an upper limit on how long a single path component may
1584 be (some "reasonable" internal size), and cson_rc.RangeError is
1585 returned if that length is violated.
1586
1587
1588 Limitations:
1589
1590 - It has no way to fetch data from arrays this way. i could
1591 imagine, e.g., a path of "subobj.subArray.0" for
1592 subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
1593 lazy/tired to add this.
1594
1595 Example usage:
1596
1597
1598 Assume we have a JSON structure which abstractly looks like:
1599
1600 @code
1601 {"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
1613 "subobj/subsubobj/myValue" with separator='/' is equivalent the
1614 path "subobj.subsubobj.myValue" with separator='.'. The value of 0
1615 is not legal as a separator character because we cannot
1616 distinguish that use from the real end-of-string without requiring
1617 the caller to also pass in the length of the string.
1618
1619 Multiple successive separators in the list are collapsed into a
1620 single separator for parsing purposes. e.g. the path "a...b...c"
1621 (separator='.') is equivalent to "a.b.c".
1622
1623 @see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
1700 @see cson_object_iter_init()
1701 @see cson_object_iter_next()
1702 */
1703 struct cson_object_iterator
1704 {
1705
1706 /** @internal
1707 The underlying object.
1708 */
1709 cson_object const * obj;
1710 /** @internal
@@ -1771,11 +1771,11 @@
1771 ...
1772 }
1773 @endcode
1774
1775 There is no need to clean up an iterator, as it holds no dynamic resources.
1776
1777 @see cson_kvp_key()
1778 @see cson_kvp_value()
1779 */
1780 cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
1781
@@ -1863,11 +1863,11 @@
1863 buf = cson_buffer_empty;
1864 @endcode
1865
1866 (You might also need to store buf.used and buf.capacity,
1867 depending on what you want to do with the memory.)
1868
1869 When doing so, the memory must eventually be passed to free()
1870 to deallocate it.
1871 */
1872 unsigned char * mem;
1873 };
@@ -1894,11 +1894,11 @@
1894 On error non-zero is returned. Errors include:
1895
1896 - Invalid arguments: cson_rc.ArgError
1897
1898 - Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
1900 Example usage:
1901
1902 @code
1903 cson_buffer buf = cson_buffer_empty;
1904 // optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
1918 buf = cson_buffer_empty;
1919 ...
1920 free(mem);
1921 }
1922 @endcode
1923
1924 @see cson_output()
1925
1926 */
1927 int cson_output_buffer( cson_value const * v, cson_buffer * buf,
1928 cson_output_opt const * opt );
1929
1930 /**
@@ -1993,11 +1993,11 @@
1993 calling cson_buffer_reserve(dest,0).
1994
1995 dest->mem might (and possibly will) be (re)allocated by this
1996 function, so any pointers to it held from before this call might be
1997 invalidated by this call.
1998
1999 On error non-0 is returned and dest has almost certainly been
2000 modified but its state must be considered incomplete.
2001
2002 Errors include:
2003
@@ -2042,11 +2042,11 @@
2042 void * mem = buf.mem;
2043 buf = cson_buffer_empty;
2044 @endcode
2045
2046 In which case the memory must eventually be passed to free() to
2047 free it.
2048 */
2049 int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
2050
2051
2052 /**
@@ -2072,11 +2072,11 @@
2072 for other sharing points which added a reference.
2073
2074 Normally any such value handles would be invalidated when the
2075 parent container(s) is/are cleaned up, but this function can be
2076 used to effectively delay the cleanup.
2077
2078 This function, at its lowest level, increments the value's
2079 reference count by 1.
2080
2081 To decrement the reference count, pass the value to
2082 cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
2091 errors long before the reference count could overflow (assuming
2092 those reference counts come from container insertions, as opposed
2093 to via this function).
2094
2095 Insider notes which clients really need to know:
2096
2097 For shared/constant value instances, such as those returned by
2098 cson_value_true() and cson_value_null(), this function has no side
2099 effects - it does not actually modify the reference count because
2100 (A) those instances are shared across all client code and (B) those
2101 objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
2173 returned object will be of the same logical type as orig.
2174
2175 ACHTUNG: if orig contains any cyclic references at any depth level
2176 this function will endlessly recurse. (Having _any_ cyclic
2177 references violates this library's requirements.)
2178
2179 Returns NULL if orig is NULL or if cloning fails. Assuming that
2180 orig is in a valid state, the only "likely" error case is that an
2181 allocation fails while constructing the clone. In other words, if
2182 cloning fails due to something other than an allocation error then
2183 either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
2278 --key=VAL : Treats VAL as either a double, integer, or string.
2279
2280 --key= : Treats key as a JSON null (not literal NULL) value.
2281
2282 Arguments not starting with a dash are skipped.
2283
2284 Each key/value pair is inserted into an object. If a given key
2285 appears more than once then only the final entry is actually
2286 stored.
2287
2288 argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
2434 Integer, double, null, or string (TEXT and BLOB data, though not
2435 all blob data is legal for a JSON string).
2436
2437 st must be a sqlite3_step()'d row and col must be a 0-based column
2438 index within that result row.
2439 */
2440 cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
2441
2442 /**
2443 Creates a JSON Array object containing the names of all columns
2444 of the given prepared statement handle.
2445
2446 Returns a new array value on success, which the caller owns. Its elements
2447 are in the same order as in the underlying query.
2448
2449 On error NULL is returned.
2450
2451 st is not traversed or freed by this function - only the column
2452 count and names are read.
2453 */
2454 cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
2455
@@ -2494,22 +2494,22 @@
2494 */
2495 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
2496 /**
2497 Converts the results of an sqlite3 SELECT statement to JSON,
2498 in the form of a cson_value object tree.
2499
2500 st must be a prepared, but not yet traversed, SELECT query.
2501 tgt must be a pointer to NULL (see the example below). If
2502 either of those arguments are NULL, cson_rc.ArgError is returned.
2503
2504 This walks the query results and returns a JSON object which
2505 has a different structure depending on the value of the 'fat'
2506 argument.
2507
2508
2509 If 'fat' is 0 then the structure is:
2510
2511 @code
2512 {
2513 "columns":["colName1",..."colNameN"],
2514 "rows":[
2515 [colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
2516 [colVal0, ... colValN],
2517 ...
2518 ]
2519 }
2520 @endcode
2521
2522 In the "non-fat" format the order of the columns and row values is
2523 guaranteed to be the same as that of the underlying query.
2524
2525 If 'fat' is not 0 then the structure is:
2526
2527 @code
2528 {
2529 "columns":["colName1",..."colNameN"],
2530 "rows":[
2531 {"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
2543
2544 On success it returns 0 and assigns *tgt to a newly-allocated
2545 JSON object tree (using the above structure), which the caller owns.
2546 If the query returns no rows, the "rows" value will be an empty
2547 array, as opposed to null.
2548
2549 On error non-0 is returned and *tgt is not modified.
2550
2551 The error code cson_rc.IOError is used to indicate a db-level
2552 error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
2553 returns 0 or less (indicating an invalid or non-SELECT statement).
2554
2555 The JSON data types are determined by the column type as reported
2556 by sqlite3_column_type():
2557
2558 SQLITE_INTEGER: integer
2559
2560 SQLITE_FLOAT: double
2561
2562 SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
2563 the data is UTF8 compatible.
2564
2565 If the db returns a literal or SQL NULL for a value it is converted
2566 to a JSON null. If it somehow finds a column type it cannot handle,
2567 the value is also converted to a NULL in the output.
2568
2569 Example
2570
2571 @code
2572 cson_value * json = NULL;
2573 int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
2574 if( 0 != rc ) { ... error ... }
2575 else {
@@ -2603,14 +2603,14 @@
2603 TODO: add Object support for named parameters.
2604
2605 Returns 0 on success, non-0 on error.
2606 */
2607 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
2609 #if defined(__cplusplus)
2610 } /*extern "C"*/
2611 #endif
2612
2613 #endif /* CSON_ENABLE_SQLITE3 */
2614 #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
2615 /* end file include/wh/cson/cson_sqlite3.h */
2616 #endif /* FOSSIL_ENABLE_JSON */
2617
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
59 #define CSON_INT_T_PFMT "I64d"
60 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
61 typedef long long cson_int_t;
62 #define CSON_INT_T_SFMT "lld"
63 #define CSON_INT_T_PFMT "lld"
64 #else
65 typedef long cson_int_t;
66 #define CSON_INT_T_SFMT "ld"
67 #define CSON_INT_T_PFMT "ld"
68 #endif
69
@@ -215,11 +215,11 @@
215 Convenience typedef.
216 */
217 typedef struct cson_value cson_value;
218
219 /** @struct cson_value
220
221 The core value type of this API. It is opaque to clients, and
222 only the cson public API should be used for setting or
223 inspecting their values.
224
225 This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231 counting) as long as those insertions do not cause cycles. However,
232 be very aware that such value re-use uses a reference to the
233 original copy, meaning that if its value is changed once, it is
234 changed everywhere. Also beware that multi-threaded write
235 operations on such references leads to undefined behaviour.
236
237 PLEASE read the ACHTUNGEN below...
238
239 ACHTUNG #1:
240
241 cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244 Not abiding th Holy Law Of No Cycles will lead to double-frees and
245 the like (i.e. undefined behaviour, likely crashes due to infinite
246 recursion or stepping on invalid (freed) pointers).
247
248 ACHTUNG #2:
249
250 ALL cson_values returned as non-const cson_value pointers from any
251 public functions in the cson API are to be treated as if they are
252 heap-allocated, and MUST be freed by client by doing ONE of:
253
254 - Passing it to cson_value_free().
255
256 - Adding it to an Object or Array, in which case the object/array
257 takes over ownership. As of 20110323, a value may be inserted into
258 a single container multiple times, or into multiple containers,
259 in which case they all share ownership (via reference counting)
260 of the original value (meaning any changes to it are visible in
261 all references to it).
262
263 Each call to cson_value_new_xxx() MUST eventually be followed up
264 by one of those options.
265
266 Some cson_value_new_XXX() implementations do not actually allocate
267 memory, but this is an internal implementation detail. Client code
268 MUST NOT rely on this behaviour and MUST treat each object
269 returned by such a function as if it was a freshly-allocated copy
270 (even if their pointer addresses are the same).
271
272 ACHTUNG #3:
273
274 Note that ACHTUNG #2 tells us that we must always free (or transfer
275 ownership of) all pointers returned bycson_value_new_xxx(), but
276 that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315 if( 0 == rc ) {...success...}
316 else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317 else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318 ...
319 @endcode
320
321 The entries named Parse_XXX are generally only returned by
322 cson_parse() and friends.
323 */
324
325 /** @struct cson_rc_
@@ -472,11 +472,11 @@
472
473 /**
474 Length, in bytes.
475 */
476 unsigned int length;
477
478 /**
479 Error code of the parse run (0 for no error).
480 */
481 int errorCode;
482
@@ -523,11 +523,11 @@
523 /**
524 Specifies how to indent (or not) output. The values
525 are:
526
527 (0) == no extra indentation.
528
529 (1) == 1 TAB character for each level.
530
531 (>1) == that number of SPACES for each level.
532 */
533 unsigned char indentation;
@@ -536,11 +536,11 @@
536 Maximum object/array depth to traverse. Traversing deeply can
537 be indicative of cycles in the object/array tree, and this
538 value is used to figure out when to abort the traversal.
539 */
540 unsigned short maxDepth;
541
542 /**
543 If true, a newline will be added to generated output,
544 else not.
545 */
546 char addNewline;
@@ -636,11 +636,11 @@
636
637 Must return 0 on success, non-0 on error (preferably a value from
638 cson_rc).
639
640 These functions are called relatively often during the JSON-output
641 process, and should try to be fast.
642 */
643 typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644
645 /**
646 Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664 used.
665
666 The info argument may be NULL. If it is not NULL then the parser
667 populates it with information which is useful in error
668 reporting. Namely, it contains the line/column of parse errors.
669
670 The srcState argument is ignored by this function but is passed on to src,
671 so any output-destination-specific state can be stored there and accessed
672 via the src callback.
673
674 Non-parse error conditions include:
675
676 - (!tgt) or !src: cson_rc.ArgError
677 - cson_rc.AllocError can happen at any time during the input phase
678
@@ -725,11 +725,11 @@
725 TODOs:
726
727 - Buffer the input in larger chunks. We currently read
728 byte-by-byte, but i'm too tired to write/test the looping code for
729 the buffering.
730
731 @see cson_parse_FILE()
732 @see cson_parse_string()
733 */
734 int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735 cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786 The destState parameter is ignored by this function and is passed
787 on to the dest function.
788
789 Returns 0 on success. On error, any amount of output might have been
790 generated before the error was triggered.
791
792 Example:
793
794 @code
795 int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796 // basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925 /**
926 Converts the given value to a boolean, using JavaScript semantics depending
927 on the concrete type of val:
928
929 undef or null: false
930
931 boolean: same
932
933 integer, double: 0 or 0.0 == false, else true
934
935 object, array: true
936
937 string: length-0 string is false, else true.
938
939 Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945 Similar to cson_value_fetch_bool(), but fetches an integer value.
946
947 The conversion, if any, depends on the concrete type of val:
948
949 NULL, null, undefined: *v is set to 0 and 0 is returned.
950
951 string, object, array: *v is set to 0 and
952 cson_rc.TypeError is returned. The error may normally be safely
953 ignored, but it is provided for those wanted to know whether a direct
954 conversion was possible.
955
956 integer: *v is set to the int value and 0 is returned.
957
958 double: *v is set to the value truncated to int and 0 is returned.
959 */
960 int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961
962 /**
@@ -1084,11 +1084,11 @@
1084
1085 - The maximum number of bytes compared is the lesser of rhsLen and
1086 the length of lhs. If the strings do not match, but compare equal
1087 up to the just-described comparison length, the shorter string is
1088 considered to be less-than the longer one.
1089
1090 - If lhs and rhs are both NULL, or both have a length of 0 then they will
1091 compare equal.
1092
1093 - If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
1094 rhs.
@@ -1110,11 +1110,11 @@
1110 Returns the length, in bytes, of str, or 0 if str is NULL. This is
1111 an O(1) operation.
1112
1113 TODO: add cson_string_length_chars() (is O(N) unless we add another
1114 member to store the char length).
1115
1116 @see cson_string_cstr()
1117 */
1118 unsigned int cson_string_length_bytes( cson_string const * str );
1119
1120 /**
@@ -1207,11 +1207,11 @@
1207 ar is expanded, if needed, to be able to hold at least (ndx+1)
1208 items, and any new entries created by that expansion are empty
1209 (NULL values).
1210
1211 On success, 0 is returned and ownership of v is transfered to ar.
1212
1213 On error ownership of v is NOT modified, and the caller may still
1214 need to clean it up. For example, the following code will introduce
1215 a leak if this function fails:
1216
1217 @code
@@ -1240,11 +1240,11 @@
1240
1241 This is functionally equivalent to
1242 cson_array_set(ar,cson_array_length_get(ar),v), but this
1243 implementation has slightly different array-preallocation policy
1244 (it grows more eagerly).
1245
1246 Returns 0 on success, non-zero on error. Error cases include:
1247
1248 - ar or v are NULL: cson_rc.ArgError
1249
1250 - Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
1283 cson_value * cson_new_bool(char v);
1284
1285 /**
1286 Returns the special JSON "null" value. When outputing JSON,
1287 its string representation is "null" (without the quotes).
1288
1289 See cson_value_new_bool() for notes regarding the returned
1290 value's memory.
1291 */
1292 cson_value * cson_value_null();
1293
@@ -1323,16 +1323,16 @@
1323
1324 /**
1325 Semantically the same as cson_value_new_bool(), but for strings.
1326 This creates a JSON value which copies the first n bytes of str.
1327 The string will automatically be NUL-terminated.
1328
1329 Note that if str is NULL or n is 0, this function still
1330 returns non-NULL value representing that empty string.
1331
1332 Returns NULL on allocation error.
1333
1334 See cson_value_new_bool() for important information about the
1335 returned memory.
1336 */
1337 cson_value * cson_value_new_string( char const * str, unsigned int n );
1338
@@ -1354,11 +1354,11 @@
1354 This works like cson_value_new_object() but returns an Object
1355 handle directly.
1356
1357 The value handle for the returned object can be fetched with
1358 cson_object_value(theObject).
1359
1360 Ownership is transfered to the caller, who must eventually free it
1361 by passing the Value handle (NOT the Object handle) to
1362 cson_value_free() or passing ownership to a parent container.
1363
1364 Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
1419 cson_value_add_reference(). Even if this function does not
1420 immediately destroy the value, the value must be considered, from
1421 the perspective of that client code, to have been
1422 destroyed/invalidated by this call.
1423
1424
1425 @see cson_value_new_object()
1426 @see cson_value_new_array()
1427 @see cson_value_add_reference()
1428 */
1429 void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
1445 case, the key is set to the special null value.
1446
1447 The key may be encoded as ASCII or UTF8. Results are undefined
1448 with other encodings, and the errors won't show up here, but may
1449 show up later, e.g. during output.
1450
1451 Returns 0 on success, non-0 on error. It has the following error
1452 cases:
1453
1454 - cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
1455
@@ -1498,11 +1498,11 @@
1498 */
1499 int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
1500
1501 /**
1502 Removes a property from an object.
1503
1504 If obj contains the given key, it is removed and 0 is returned. If
1505 it is not found, cson_rc.NotFoundError is returned (which can
1506 normally be ignored by client code).
1507
1508 cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
1569
1570 If it finds the given path, it returns the value by assiging *tgt
1571 to it. If tgt is NULL then this function has no side-effects but
1572 will return 0 if the given path is found within the object, so it can be used
1573 to test for existence without fetching it.
1574
1575 Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
1576 no item, and any other non-zero error code on a "real" error. Errors include:
1577
1578 - obj or path are NULL: cson_rc.ArgError
1579
1580 - separator is 0, or path is an empty string or contains only
1581 separator characters: cson_rc.RangeError
1582
1583 - There is an upper limit on how long a single path component may
1584 be (some "reasonable" internal size), and cson_rc.RangeError is
1585 returned if that length is violated.
1586
1587
1588 Limitations:
1589
1590 - It has no way to fetch data from arrays this way. i could
1591 imagine, e.g., a path of "subobj.subArray.0" for
1592 subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
1593 lazy/tired to add this.
1594
1595 Example usage:
1596
1597
1598 Assume we have a JSON structure which abstractly looks like:
1599
1600 @code
1601 {"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
1613 "subobj/subsubobj/myValue" with separator='/' is equivalent the
1614 path "subobj.subsubobj.myValue" with separator='.'. The value of 0
1615 is not legal as a separator character because we cannot
1616 distinguish that use from the real end-of-string without requiring
1617 the caller to also pass in the length of the string.
1618
1619 Multiple successive separators in the list are collapsed into a
1620 single separator for parsing purposes. e.g. the path "a...b...c"
1621 (separator='.') is equivalent to "a.b.c".
1622
1623 @see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
1700 @see cson_object_iter_init()
1701 @see cson_object_iter_next()
1702 */
1703 struct cson_object_iterator
1704 {
1705
1706 /** @internal
1707 The underlying object.
1708 */
1709 cson_object const * obj;
1710 /** @internal
@@ -1771,11 +1771,11 @@
1771 ...
1772 }
1773 @endcode
1774
1775 There is no need to clean up an iterator, as it holds no dynamic resources.
1776
1777 @see cson_kvp_key()
1778 @see cson_kvp_value()
1779 */
1780 cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
1781
@@ -1863,11 +1863,11 @@
1863 buf = cson_buffer_empty;
1864 @endcode
1865
1866 (You might also need to store buf.used and buf.capacity,
1867 depending on what you want to do with the memory.)
1868
1869 When doing so, the memory must eventually be passed to free()
1870 to deallocate it.
1871 */
1872 unsigned char * mem;
1873 };
@@ -1894,11 +1894,11 @@
1894 On error non-zero is returned. Errors include:
1895
1896 - Invalid arguments: cson_rc.ArgError
1897
1898 - Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
1900 Example usage:
1901
1902 @code
1903 cson_buffer buf = cson_buffer_empty;
1904 // optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
1918 buf = cson_buffer_empty;
1919 ...
1920 free(mem);
1921 }
1922 @endcode
1923
1924 @see cson_output()
1925
1926 */
1927 int cson_output_buffer( cson_value const * v, cson_buffer * buf,
1928 cson_output_opt const * opt );
1929
1930 /**
@@ -1993,11 +1993,11 @@
1993 calling cson_buffer_reserve(dest,0).
1994
1995 dest->mem might (and possibly will) be (re)allocated by this
1996 function, so any pointers to it held from before this call might be
1997 invalidated by this call.
1998
1999 On error non-0 is returned and dest has almost certainly been
2000 modified but its state must be considered incomplete.
2001
2002 Errors include:
2003
@@ -2042,11 +2042,11 @@
2042 void * mem = buf.mem;
2043 buf = cson_buffer_empty;
2044 @endcode
2045
2046 In which case the memory must eventually be passed to free() to
2047 free it.
2048 */
2049 int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
2050
2051
2052 /**
@@ -2072,11 +2072,11 @@
2072 for other sharing points which added a reference.
2073
2074 Normally any such value handles would be invalidated when the
2075 parent container(s) is/are cleaned up, but this function can be
2076 used to effectively delay the cleanup.
2077
2078 This function, at its lowest level, increments the value's
2079 reference count by 1.
2080
2081 To decrement the reference count, pass the value to
2082 cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
2091 errors long before the reference count could overflow (assuming
2092 those reference counts come from container insertions, as opposed
2093 to via this function).
2094
2095 Insider notes which clients really need to know:
2096
2097 For shared/constant value instances, such as those returned by
2098 cson_value_true() and cson_value_null(), this function has no side
2099 effects - it does not actually modify the reference count because
2100 (A) those instances are shared across all client code and (B) those
2101 objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
2173 returned object will be of the same logical type as orig.
2174
2175 ACHTUNG: if orig contains any cyclic references at any depth level
2176 this function will endlessly recurse. (Having _any_ cyclic
2177 references violates this library's requirements.)
2178
2179 Returns NULL if orig is NULL or if cloning fails. Assuming that
2180 orig is in a valid state, the only "likely" error case is that an
2181 allocation fails while constructing the clone. In other words, if
2182 cloning fails due to something other than an allocation error then
2183 either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
2278 --key=VAL : Treats VAL as either a double, integer, or string.
2279
2280 --key= : Treats key as a JSON null (not literal NULL) value.
2281
2282 Arguments not starting with a dash are skipped.
2283
2284 Each key/value pair is inserted into an object. If a given key
2285 appears more than once then only the final entry is actually
2286 stored.
2287
2288 argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
2434 Integer, double, null, or string (TEXT and BLOB data, though not
2435 all blob data is legal for a JSON string).
2436
2437 st must be a sqlite3_step()'d row and col must be a 0-based column
2438 index within that result row.
2439 */
2440 cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
2441
2442 /**
2443 Creates a JSON Array object containing the names of all columns
2444 of the given prepared statement handle.
2445
2446 Returns a new array value on success, which the caller owns. Its elements
2447 are in the same order as in the underlying query.
2448
2449 On error NULL is returned.
2450
2451 st is not traversed or freed by this function - only the column
2452 count and names are read.
2453 */
2454 cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
2455
@@ -2494,22 +2494,22 @@
2494 */
2495 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
2496 /**
2497 Converts the results of an sqlite3 SELECT statement to JSON,
2498 in the form of a cson_value object tree.
2499
2500 st must be a prepared, but not yet traversed, SELECT query.
2501 tgt must be a pointer to NULL (see the example below). If
2502 either of those arguments are NULL, cson_rc.ArgError is returned.
2503
2504 This walks the query results and returns a JSON object which
2505 has a different structure depending on the value of the 'fat'
2506 argument.
2507
2508
2509 If 'fat' is 0 then the structure is:
2510
2511 @code
2512 {
2513 "columns":["colName1",..."colNameN"],
2514 "rows":[
2515 [colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
2516 [colVal0, ... colValN],
2517 ...
2518 ]
2519 }
2520 @endcode
2521
2522 In the "non-fat" format the order of the columns and row values is
2523 guaranteed to be the same as that of the underlying query.
2524
2525 If 'fat' is not 0 then the structure is:
2526
2527 @code
2528 {
2529 "columns":["colName1",..."colNameN"],
2530 "rows":[
2531 {"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
2543
2544 On success it returns 0 and assigns *tgt to a newly-allocated
2545 JSON object tree (using the above structure), which the caller owns.
2546 If the query returns no rows, the "rows" value will be an empty
2547 array, as opposed to null.
2548
2549 On error non-0 is returned and *tgt is not modified.
2550
2551 The error code cson_rc.IOError is used to indicate a db-level
2552 error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
2553 returns 0 or less (indicating an invalid or non-SELECT statement).
2554
2555 The JSON data types are determined by the column type as reported
2556 by sqlite3_column_type():
2557
2558 SQLITE_INTEGER: integer
2559
2560 SQLITE_FLOAT: double
2561
2562 SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
2563 the data is UTF8 compatible.
2564
2565 If the db returns a literal or SQL NULL for a value it is converted
2566 to a JSON null. If it somehow finds a column type it cannot handle,
2567 the value is also converted to a NULL in the output.
2568
2569 Example
2570
2571 @code
2572 cson_value * json = NULL;
2573 int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
2574 if( 0 != rc ) { ... error ... }
2575 else {
@@ -2603,14 +2603,14 @@
2603 TODO: add Object support for named parameters.
2604
2605 Returns 0 on success, non-0 on error.
2606 */
2607 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
2609 #if defined(__cplusplus)
2610 } /*extern "C"*/
2611 #endif
2612
2613 #endif /* CSON_ENABLE_SQLITE3 */
2614 #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
2615 /* end file include/wh/cson/cson_sqlite3.h */
2616 #endif /* FOSSIL_ENABLE_JSON */
2617
+4 -1
--- src/main.mk
+++ src/main.mk
@@ -551,11 +551,14 @@
551551
-DSQLITE_ENABLE_FTS4 \
552552
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
553553
-DSQLITE_ENABLE_DBSTAT_VTAB \
554554
-DSQLITE_ENABLE_JSON1 \
555555
-DSQLITE_ENABLE_FTS5 \
556
- -DSQLITE_ENABLE_STMTVTAB
556
+ -DSQLITE_ENABLE_STMTVTAB \
557
+ -DSQLITE_USE_ZLIB \
558
+ -DSQLITE_INTROSPECTION_PRAGMAS \
559
+ -DSQLITE_ENABLE_DBPAGE_VTAB
557560
558561
# Setup the options used to compile the included SQLite shell.
559562
SHELL_OPTIONS = -Dmain=sqlite3_shell \
560563
-DSQLITE_SHELL_IS_UTF8=1 \
561564
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
562565
--- src/main.mk
+++ src/main.mk
@@ -551,11 +551,14 @@
551 -DSQLITE_ENABLE_FTS4 \
552 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
553 -DSQLITE_ENABLE_DBSTAT_VTAB \
554 -DSQLITE_ENABLE_JSON1 \
555 -DSQLITE_ENABLE_FTS5 \
556 -DSQLITE_ENABLE_STMTVTAB
 
 
 
557
558 # Setup the options used to compile the included SQLite shell.
559 SHELL_OPTIONS = -Dmain=sqlite3_shell \
560 -DSQLITE_SHELL_IS_UTF8=1 \
561 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
562
--- src/main.mk
+++ src/main.mk
@@ -551,11 +551,14 @@
551 -DSQLITE_ENABLE_FTS4 \
552 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
553 -DSQLITE_ENABLE_DBSTAT_VTAB \
554 -DSQLITE_ENABLE_JSON1 \
555 -DSQLITE_ENABLE_FTS5 \
556 -DSQLITE_ENABLE_STMTVTAB \
557 -DSQLITE_USE_ZLIB \
558 -DSQLITE_INTROSPECTION_PRAGMAS \
559 -DSQLITE_ENABLE_DBPAGE_VTAB
560
561 # Setup the options used to compile the included SQLite shell.
562 SHELL_OPTIONS = -Dmain=sqlite3_shell \
563 -DSQLITE_SHELL_IS_UTF8=1 \
564 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
565
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -189,10 +189,13 @@
189189
-DSQLITE_ENABLE_FTS3_PARENTHESIS
190190
-DSQLITE_ENABLE_DBSTAT_VTAB
191191
-DSQLITE_ENABLE_JSON1
192192
-DSQLITE_ENABLE_FTS5
193193
-DSQLITE_ENABLE_STMTVTAB
194
+ -DSQLITE_USE_ZLIB
195
+ -DSQLITE_INTROSPECTION_PRAGMAS
196
+ -DSQLITE_ENABLE_DBPAGE_VTAB
194197
}
195198
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
196199
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
197200
#lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
198201
#lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
199202
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -189,10 +189,13 @@
189 -DSQLITE_ENABLE_FTS3_PARENTHESIS
190 -DSQLITE_ENABLE_DBSTAT_VTAB
191 -DSQLITE_ENABLE_JSON1
192 -DSQLITE_ENABLE_FTS5
193 -DSQLITE_ENABLE_STMTVTAB
 
 
 
194 }
195 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
196 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
197 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
198 #lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
199
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -189,10 +189,13 @@
189 -DSQLITE_ENABLE_FTS3_PARENTHESIS
190 -DSQLITE_ENABLE_DBSTAT_VTAB
191 -DSQLITE_ENABLE_JSON1
192 -DSQLITE_ENABLE_FTS5
193 -DSQLITE_ENABLE_STMTVTAB
194 -DSQLITE_USE_ZLIB
195 -DSQLITE_INTROSPECTION_PRAGMAS
196 -DSQLITE_ENABLE_DBPAGE_VTAB
197 }
198 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
199 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
200 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
201 #lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
202
+896 -507
--- src/shell.c
+++ src/shell.c
@@ -92,14 +92,14 @@
9292
# include <signal.h>
9393
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
9494
# include <pwd.h>
9595
# endif
9696
#endif
97
-#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H)
97
+#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__)
9898
# include <unistd.h>
9999
# include <dirent.h>
100
-# if defined(__MINGW_H)
100
+# if defined(__MINGW32__)
101101
# define DIRENT dirent
102102
# ifndef S_ISLNK
103103
# define S_ISLNK(mode) (0)
104104
# endif
105105
# endif
@@ -368,10 +368,15 @@
368368
/*
369369
** Used to prevent warnings about unused parameters
370370
*/
371371
#define UNUSED_PARAMETER(x) (void)(x)
372372
373
+/*
374
+** Number of elements in an array
375
+*/
376
+#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
377
+
373378
/*
374379
** If the following flag is set, then command execution stops
375380
** at an error if we are not interactive.
376381
*/
377382
static int bail_on_error = 0;
@@ -640,10 +645,69 @@
640645
if( zResult && *zResult ) shell_add_history(zResult);
641646
#endif
642647
}
643648
return zResult;
644649
}
650
+
651
+
652
+/*
653
+** Return the value of a hexadecimal digit. Return -1 if the input
654
+** is not a hex digit.
655
+*/
656
+static int hexDigitValue(char c){
657
+ if( c>='0' && c<='9' ) return c - '0';
658
+ if( c>='a' && c<='f' ) return c - 'a' + 10;
659
+ if( c>='A' && c<='F' ) return c - 'A' + 10;
660
+ return -1;
661
+}
662
+
663
+/*
664
+** Interpret zArg as an integer value, possibly with suffixes.
665
+*/
666
+static sqlite3_int64 integerValue(const char *zArg){
667
+ sqlite3_int64 v = 0;
668
+ static const struct { char *zSuffix; int iMult; } aMult[] = {
669
+ { "KiB", 1024 },
670
+ { "MiB", 1024*1024 },
671
+ { "GiB", 1024*1024*1024 },
672
+ { "KB", 1000 },
673
+ { "MB", 1000000 },
674
+ { "GB", 1000000000 },
675
+ { "K", 1000 },
676
+ { "M", 1000000 },
677
+ { "G", 1000000000 },
678
+ };
679
+ int i;
680
+ int isNeg = 0;
681
+ if( zArg[0]=='-' ){
682
+ isNeg = 1;
683
+ zArg++;
684
+ }else if( zArg[0]=='+' ){
685
+ zArg++;
686
+ }
687
+ if( zArg[0]=='0' && zArg[1]=='x' ){
688
+ int x;
689
+ zArg += 2;
690
+ while( (x = hexDigitValue(zArg[0]))>=0 ){
691
+ v = (v<<4) + x;
692
+ zArg++;
693
+ }
694
+ }else{
695
+ while( IsDigit(zArg[0]) ){
696
+ v = v*10 + zArg[0] - '0';
697
+ zArg++;
698
+ }
699
+ }
700
+ for(i=0; i<ArraySize(aMult); i++){
701
+ if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
702
+ v *= aMult[i].iMult;
703
+ break;
704
+ }
705
+ }
706
+ return isNeg? -v : v;
707
+}
708
+
645709
/*
646710
** A variable length string to which one can append text.
647711
*/
648712
typedef struct ShellText ShellText;
649713
struct ShellText {
@@ -818,12 +882,13 @@
818882
sqlite3_value **apVal
819883
){
820884
const char *zName = (const char*)sqlite3_value_text(apVal[0]);
821885
char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
822886
if( zFake ){
823
- sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake),
887
+ sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
824888
-1, sqlite3_free);
889
+ free(zFake);
825890
}
826891
}
827892
828893
/*
829894
** SQL function: shell_add_schema(S,X)
@@ -879,14 +944,15 @@
879944
if( zName
880945
&& aPrefix[i][0]=='V'
881946
&& (zFake = shellFakeSchema(db, zSchema, zName))!=0
882947
){
883948
if( z==0 ){
884
- z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake);
949
+ z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
885950
}else{
886
- z = sqlite3_mprintf("%z\n/* %z */", z, zFake);
951
+ z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
887952
}
953
+ free(zFake);
888954
}
889955
if( z ){
890956
sqlite3_result_text(pCtx, z, -1, sqlite3_free);
891957
return;
892958
}
@@ -2068,14 +2134,15 @@
20682134
# include "windows.h"
20692135
# include <io.h>
20702136
# include <direct.h>
20712137
/* # include "test_windirent.h" */
20722138
# define dirent DIRENT
2073
-# define timespec TIMESPEC
2074
-# define stat _stat
2139
+# ifndef stat
2140
+# define stat _stat
2141
+# endif
20752142
# define mkdir(path,mode) _mkdir(path)
2076
-# define lstat(path,buf) _stat(path,buf)
2143
+# define lstat(path,buf) stat(path,buf)
20772144
#endif
20782145
#include <time.h>
20792146
#include <errno.h>
20802147
20812148
@@ -2331,10 +2398,44 @@
23312398
}else{
23322399
ctxErrorMsg(context, "failed to write file: %s", zFile);
23332400
}
23342401
}
23352402
}
2403
+
2404
+/*
2405
+** SQL function: lsmode(MODE)
2406
+**
2407
+** Given a numberic st_mode from stat(), convert it into a human-readable
2408
+** text string in the style of "ls -l".
2409
+*/
2410
+static void lsModeFunc(
2411
+ sqlite3_context *context,
2412
+ int argc,
2413
+ sqlite3_value **argv
2414
+){
2415
+ int i;
2416
+ int iMode = sqlite3_value_int(argv[0]);
2417
+ char z[16];
2418
+ if( S_ISLNK(iMode) ){
2419
+ z[0] = 'l';
2420
+ }else if( S_ISREG(iMode) ){
2421
+ z[0] = '-';
2422
+ }else if( S_ISDIR(iMode) ){
2423
+ z[0] = 'd';
2424
+ }else{
2425
+ z[0] = '?';
2426
+ }
2427
+ for(i=0; i<3; i++){
2428
+ int m = (iMode >> ((2-i)*3));
2429
+ char *a = &z[1 + i*3];
2430
+ a[0] = (m & 0x4) ? 'r' : '-';
2431
+ a[1] = (m & 0x2) ? 'w' : '-';
2432
+ a[2] = (m & 0x1) ? 'x' : '-';
2433
+ }
2434
+ z[10] = '\0';
2435
+ sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
2436
+}
23362437
23372438
#ifndef SQLITE_OMIT_VIRTUALTABLE
23382439
23392440
/*
23402441
** Cursor type for recursively iterating through a directory structure.
@@ -2743,10 +2844,14 @@
27432844
readfileFunc, 0, 0);
27442845
if( rc==SQLITE_OK ){
27452846
rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
27462847
writefileFunc, 0, 0);
27472848
}
2849
+ if( rc==SQLITE_OK ){
2850
+ rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
2851
+ lsModeFunc, 0, 0);
2852
+ }
27482853
if( rc==SQLITE_OK ){
27492854
rc = fsdirRegister(db);
27502855
}
27512856
return rc;
27522857
}
@@ -3885,21 +3990,22 @@
38853990
typedef unsigned short u16;
38863991
typedef unsigned long u32;
38873992
#define MIN(a,b) ((a)<(b) ? (a) : (b))
38883993
#endif
38893994
3890
-#define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3891
- "name, /* Name of file in zip archive */" \
3892
- "mode, /* POSIX mode for file */" \
3893
- "mtime, /* Last modification time in seconds since epoch */" \
3894
- "sz, /* Size of object */" \
3895
- "data, /* Data stored in zip file (possibly compressed) */" \
3896
- "method, /* Compression method (integer) */" \
3897
- "f HIDDEN /* Name of zip file */" \
3995
+#define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3996
+ "name, /* 0: Name of file in zip archive */" \
3997
+ "mode, /* 1: POSIX mode for file */" \
3998
+ "mtime, /* 2: Last modification time in seconds since epoch */" \
3999
+ "sz, /* 3: Size of object */" \
4000
+ "rawdata, /* 4: Raw data */" \
4001
+ "data, /* 5: Uncompressed data */" \
4002
+ "method, /* 6: Compression method (integer) */" \
4003
+ "file HIDDEN /* Name of zip file */" \
38984004
");"
38994005
3900
-#define ZIPFILE_F_COLUMN_IDX 6 /* Index of column "f" in the above */
4006
+#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "f" in the above */
39014007
#define ZIPFILE_BUFFER_SIZE (64*1024)
39024008
39034009
39044010
/*
39054011
** Magic numbers used to read and write zip files.
@@ -4513,10 +4619,84 @@
45134619
pCds->mDate = (u16)(
45144620
(res.tm_mday-1) +
45154621
((res.tm_mon+1) << 5) +
45164622
((res.tm_year-80) << 9));
45174623
}
4624
+
4625
+static void zipfileInflate(
4626
+ sqlite3_context *pCtx, /* Store error here, if any */
4627
+ const u8 *aIn, /* Compressed data */
4628
+ int nIn, /* Size of buffer aIn[] in bytes */
4629
+ int nOut /* Expected output size */
4630
+){
4631
+ u8 *aRes = sqlite3_malloc(nOut);
4632
+ if( aRes==0 ){
4633
+ sqlite3_result_error_nomem(pCtx);
4634
+ }else{
4635
+ int err;
4636
+ z_stream str;
4637
+ memset(&str, 0, sizeof(str));
4638
+
4639
+ str.next_in = (Byte*)aIn;
4640
+ str.avail_in = nIn;
4641
+ str.next_out = (Byte*)aRes;
4642
+ str.avail_out = nOut;
4643
+
4644
+ err = inflateInit2(&str, -15);
4645
+ if( err!=Z_OK ){
4646
+ zipfileCtxErrorMsg(pCtx, "inflateInit2() failed (%d)", err);
4647
+ }else{
4648
+ err = inflate(&str, Z_NO_FLUSH);
4649
+ if( err!=Z_STREAM_END ){
4650
+ zipfileCtxErrorMsg(pCtx, "inflate() failed (%d)", err);
4651
+ }else{
4652
+ sqlite3_result_blob(pCtx, aRes, nOut, SQLITE_TRANSIENT);
4653
+ }
4654
+ }
4655
+ sqlite3_free(aRes);
4656
+ inflateEnd(&str);
4657
+ }
4658
+}
4659
+
4660
+static int zipfileDeflate(
4661
+ ZipfileTab *pTab, /* Set error message here */
4662
+ const u8 *aIn, int nIn, /* Input */
4663
+ u8 **ppOut, int *pnOut /* Output */
4664
+){
4665
+ int nAlloc = (int)compressBound(nIn);
4666
+ u8 *aOut;
4667
+ int rc = SQLITE_OK;
4668
+
4669
+ aOut = (u8*)sqlite3_malloc(nAlloc);
4670
+ if( aOut==0 ){
4671
+ rc = SQLITE_NOMEM;
4672
+ }else{
4673
+ int res;
4674
+ z_stream str;
4675
+ memset(&str, 0, sizeof(str));
4676
+ str.next_in = (z_const Bytef*)aIn;
4677
+ str.avail_in = nIn;
4678
+ str.next_out = aOut;
4679
+ str.avail_out = nAlloc;
4680
+
4681
+ deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
4682
+ res = deflate(&str, Z_FINISH);
4683
+
4684
+ if( res==Z_STREAM_END ){
4685
+ *ppOut = aOut;
4686
+ *pnOut = (int)str.total_out;
4687
+ }else{
4688
+ sqlite3_free(aOut);
4689
+ pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
4690
+ rc = SQLITE_ERROR;
4691
+ }
4692
+ deflateEnd(&str);
4693
+ }
4694
+
4695
+ return rc;
4696
+}
4697
+
45184698
45194699
/*
45204700
** Return values of columns for the row at which the series_cursor
45214701
** is currently pointing.
45224702
*/
@@ -4546,30 +4726,37 @@
45464726
}
45474727
case 3: { /* sz */
45484728
sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
45494729
break;
45504730
}
4551
- case 4: { /* data */
4552
- int sz = pCsr->cds.szCompressed;
4553
- if( sz>0 ){
4554
- u8 *aBuf = sqlite3_malloc(sz);
4555
- if( aBuf==0 ){
4556
- rc = SQLITE_NOMEM;
4557
- }else{
4558
- FILE *pFile = zipfileGetFd(pCsr);
4559
- rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4560
- &pCsr->base.pVtab->zErrMsg
4561
- );
4562
- }
4563
- if( rc==SQLITE_OK ){
4564
- sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4565
- sqlite3_free(aBuf);
4731
+ case 4: /* rawdata */
4732
+ case 5: { /* data */
4733
+ if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
4734
+ int sz = pCsr->cds.szCompressed;
4735
+ if( sz>0 ){
4736
+ u8 *aBuf = sqlite3_malloc(sz);
4737
+ if( aBuf==0 ){
4738
+ rc = SQLITE_NOMEM;
4739
+ }else{
4740
+ FILE *pFile = zipfileGetFd(pCsr);
4741
+ rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4742
+ &pCsr->base.pVtab->zErrMsg
4743
+ );
4744
+ }
4745
+ if( rc==SQLITE_OK ){
4746
+ if( i==5 && pCsr->cds.iCompression ){
4747
+ zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed);
4748
+ }else{
4749
+ sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4750
+ }
4751
+ sqlite3_free(aBuf);
4752
+ }
45664753
}
45674754
}
45684755
break;
45694756
}
4570
- case 5: /* method */
4757
+ case 6: /* method */
45714758
sqlite3_result_int(ctx, pCsr->cds.iCompression);
45724759
break;
45734760
}
45744761
45754762
return SQLITE_OK;
@@ -4794,11 +4981,11 @@
47944981
if( pNew==0 ){
47954982
rc = SQLITE_NOMEM;
47964983
}else{
47974984
memset(pNew, 0, sizeof(ZipfileEntry));
47984985
pNew->zPath = (char*)&pNew[1];
4799
- memcpy(pNew->zPath, &aBuf[ZIPFILE_CDS_FIXED_SZ], nFile);
4986
+ memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
48004987
pNew->zPath[nFile] = '\0';
48014988
pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
48024989
pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
48034990
memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
48044991
zipfileAddEntry(pTab, pNew);
@@ -4913,15 +5100,22 @@
49135100
}
49145101
49155102
return rc;
49165103
}
49175104
4918
-static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
5105
+static int zipfileGetMode(
5106
+ ZipfileTab *pTab,
5107
+ sqlite3_value *pVal,
5108
+ u32 defaultMode, /* Value to use if pVal IS NULL */
5109
+ u32 *pMode
5110
+){
49195111
const char *z = (const char*)sqlite3_value_text(pVal);
4920
- int mode = 0;
4921
- if( z==0 || (z[0]>=0 && z[0]<=9) ){
4922
- mode = sqlite3_value_int(pVal);
5112
+ u32 mode = 0;
5113
+ if( z==0 ){
5114
+ mode = defaultMode;
5115
+ }else if( z[0]>=0 && z[0]<=9 ){
5116
+ mode = (unsigned int)sqlite3_value_int(pVal);
49235117
}else{
49245118
const char zTemplate[11] = "-rwxrwxrwx";
49255119
int i;
49265120
if( strlen(z)!=10 ) goto parse_error;
49275121
switch( z[0] ){
@@ -4942,10 +5136,22 @@
49425136
49435137
parse_error:
49445138
pTab->base.zErrMsg = sqlite3_mprintf("zipfile: parse error in mode: %s", z);
49455139
return SQLITE_ERROR;
49465140
}
5141
+
5142
+/*
5143
+** Both (const char*) arguments point to nul-terminated strings. Argument
5144
+** nB is the value of strlen(zB). This function returns 0 if the strings are
5145
+** identical, ignoring any trailing '/' character in either path. */
5146
+static int zipfileComparePath(const char *zA, const char *zB, int nB){
5147
+ int nA = (int)strlen(zA);
5148
+ if( zA[nA-1]=='/' ) nA--;
5149
+ if( zB[nB-1]=='/' ) nB--;
5150
+ if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5151
+ return 1;
5152
+}
49475153
49485154
/*
49495155
** xUpdate method.
49505156
*/
49515157
static int zipfileUpdate(
@@ -4956,79 +5162,138 @@
49565162
){
49575163
ZipfileTab *pTab = (ZipfileTab*)pVtab;
49585164
int rc = SQLITE_OK; /* Return Code */
49595165
ZipfileEntry *pNew = 0; /* New in-memory CDS entry */
49605166
4961
- int mode; /* Mode for new entry */
4962
- i64 mTime; /* Modification time for new entry */
4963
- i64 sz; /* Uncompressed size */
4964
- const char *zPath; /* Path for new entry */
4965
- int nPath; /* strlen(zPath) */
4966
- const u8 *pData; /* Pointer to buffer containing content */
4967
- int nData; /* Size of pData buffer in bytes */
5167
+ u32 mode = 0; /* Mode for new entry */
5168
+ i64 mTime = 0; /* Modification time for new entry */
5169
+ i64 sz = 0; /* Uncompressed size */
5170
+ const char *zPath = 0; /* Path for new entry */
5171
+ int nPath = 0; /* strlen(zPath) */
5172
+ const u8 *pData = 0; /* Pointer to buffer containing content */
5173
+ int nData = 0; /* Size of pData buffer in bytes */
49685174
int iMethod = 0; /* Compression method for new entry */
49695175
u8 *pFree = 0; /* Free this */
5176
+ char *zFree = 0; /* Also free this */
49705177
ZipfileCDS cds; /* New Central Directory Structure entry */
5178
+
5179
+ int bIsDir = 0;
5180
+
5181
+ int mNull;
49715182
49725183
assert( pTab->zFile );
49735184
assert( pTab->pWriteFd );
49745185
49755186
if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
4976
- i64 iDelete = sqlite3_value_int64(apVal[0]);
4977
- ZipfileEntry *p;
4978
- for(p=pTab->pFirstEntry; p; p=p->pNext){
4979
- if( p->iRowid==iDelete ){
4980
- p->bDeleted = 1;
4981
- break;
4982
- }
4983
- }
4984
- if( nVal==1 ) return SQLITE_OK;
4985
- }
4986
-
4987
- zPath = (const char*)sqlite3_value_text(apVal[2]);
4988
- nPath = (int)strlen(zPath);
4989
- rc = zipfileGetMode(pTab, apVal[3], &mode);
4990
- if( rc!=SQLITE_OK ) return rc;
4991
- mTime = sqlite3_value_int64(apVal[4]);
4992
- sz = sqlite3_value_int(apVal[5]);
4993
- pData = sqlite3_value_blob(apVal[6]);
4994
- nData = sqlite3_value_bytes(apVal[6]);
4995
-
4996
- /* If a NULL value is inserted into the 'method' column, do automatic
4997
- ** compression. */
4998
- if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){
4999
- pFree = (u8*)sqlite3_malloc(nData);
5000
- if( pFree==0 ){
5001
- rc = SQLITE_NOMEM;
5002
- }else{
5003
- int res;
5004
- z_stream str;
5005
- memset(&str, 0, sizeof(str));
5006
- str.next_in = (z_const Bytef*)pData;
5007
- str.avail_in = nData;
5008
- str.next_out = pFree;
5009
- str.avail_out = nData;
5010
- deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5011
- res = deflate(&str, Z_FINISH);
5012
- if( res==Z_STREAM_END ){
5013
- pData = pFree;
5014
- nData = str.total_out;
5015
- iMethod = 8;
5016
- }else if( res!=Z_OK ){
5017
- pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
5018
- rc = SQLITE_ERROR;
5019
- }
5020
- deflateEnd(&str);
5021
- }
5022
- }else{
5023
- iMethod = sqlite3_value_int(apVal[7]);
5187
+ if( nVal>1 ){
5188
+ return SQLITE_CONSTRAINT;
5189
+ }else{
5190
+ i64 iDelete = sqlite3_value_int64(apVal[0]);
5191
+ ZipfileEntry *p;
5192
+ for(p=pTab->pFirstEntry; p; p=p->pNext){
5193
+ if( p->iRowid==iDelete ){
5194
+ p->bDeleted = 1;
5195
+ break;
5196
+ }
5197
+ }
5198
+ return SQLITE_OK;
5199
+ }
5200
+ }
5201
+
5202
+ mNull = (sqlite3_value_type(apVal[5])==SQLITE_NULL ? 0x0 : 0x8) /* sz */
5203
+ + (sqlite3_value_type(apVal[6])==SQLITE_NULL ? 0x0 : 0x4) /* rawdata */
5204
+ + (sqlite3_value_type(apVal[7])==SQLITE_NULL ? 0x0 : 0x2) /* data */
5205
+ + (sqlite3_value_type(apVal[8])==SQLITE_NULL ? 0x0 : 0x1); /* method */
5206
+ if( mNull==0x00 ){
5207
+ /* All four are NULL - this must be a directory */
5208
+ bIsDir = 1;
5209
+ }
5210
+ else if( mNull==0x2 || mNull==0x3 ){
5211
+ /* Value specified for "data", and possibly "method". This must be
5212
+ ** a regular file or a symlink. */
5213
+ const u8 *aIn = sqlite3_value_blob(apVal[7]);
5214
+ int nIn = sqlite3_value_bytes(apVal[7]);
5215
+ int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5216
+
5217
+ iMethod = sqlite3_value_int(apVal[8]);
5218
+ sz = nIn;
5219
+ if( iMethod!=0 && iMethod!=8 ){
5220
+ rc = SQLITE_CONSTRAINT;
5221
+ }else if( bAuto || iMethod ){
5222
+ rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData);
5223
+ if( rc==SQLITE_OK ){
5224
+ if( iMethod || nData<nIn ){
5225
+ iMethod = 8;
5226
+ pData = pFree;
5227
+ }else{
5228
+ pData = aIn;
5229
+ nData = nIn;
5230
+ }
5231
+ }
5232
+ }
5233
+ }
5234
+ else if( mNull==0x0D ){
5235
+ /* Values specified for "sz", "rawdata" and "method". In other words,
5236
+ ** pre-compressed data is being inserted. */
5237
+ pData = sqlite3_value_blob(apVal[6]);
5238
+ nData = sqlite3_value_bytes(apVal[6]);
5239
+ sz = sqlite3_value_int(apVal[5]);
5240
+ iMethod = sqlite3_value_int(apVal[8]);
50245241
if( iMethod<0 || iMethod>65535 ){
50255242
pTab->base.zErrMsg = sqlite3_mprintf(
50265243
"zipfile: invalid compression method: %d", iMethod
50275244
);
50285245
rc = SQLITE_ERROR;
50295246
}
5247
+ }
5248
+ else{
5249
+ rc = SQLITE_CONSTRAINT;
5250
+ }
5251
+
5252
+ if( rc==SQLITE_OK ){
5253
+ rc = zipfileGetMode(pTab, apVal[3],
5254
+ (bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
5255
+ );
5256
+ if( rc==SQLITE_OK && (bIsDir == ((mode & S_IFDIR)==0)) ){
5257
+ /* The "mode" attribute is a directory, but data has been specified.
5258
+ ** Or vice-versa - no data but "mode" is a file or symlink. */
5259
+ rc = SQLITE_CONSTRAINT;
5260
+ }
5261
+ }
5262
+
5263
+ if( rc==SQLITE_OK ){
5264
+ zPath = (const char*)sqlite3_value_text(apVal[2]);
5265
+ nPath = (int)strlen(zPath);
5266
+ if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){
5267
+ mTime = (sqlite3_int64)time(0);
5268
+ }else{
5269
+ mTime = sqlite3_value_int64(apVal[4]);
5270
+ }
5271
+ }
5272
+
5273
+ if( rc==SQLITE_OK && bIsDir ){
5274
+ /* For a directory, check that the last character in the path is a
5275
+ ** '/'. This appears to be required for compatibility with info-zip
5276
+ ** (the unzip command on unix). It does not create directories
5277
+ ** otherwise. */
5278
+ if( zPath[nPath-1]!='/' ){
5279
+ zFree = sqlite3_mprintf("%s/", zPath);
5280
+ if( zFree==0 ){ rc = SQLITE_NOMEM; }
5281
+ zPath = (const char*)zFree;
5282
+ nPath++;
5283
+ }
5284
+ }
5285
+
5286
+ /* Check that we're not inserting a duplicate entry */
5287
+ if( rc==SQLITE_OK ){
5288
+ ZipfileEntry *p;
5289
+ for(p=pTab->pFirstEntry; p; p=p->pNext){
5290
+ if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
5291
+ rc = SQLITE_CONSTRAINT;
5292
+ break;
5293
+ }
5294
+ }
50305295
}
50315296
50325297
if( rc==SQLITE_OK ){
50335298
/* Create the new CDS record. */
50345299
memset(&cds, 0, sizeof(cds));
@@ -5054,10 +5319,11 @@
50545319
if( rc==SQLITE_OK ){
50555320
rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
50565321
}
50575322
50585323
sqlite3_free(pFree);
5324
+ sqlite3_free(zFree);
50595325
return rc;
50605326
}
50615327
50625328
static int zipfileAppendEOCD(ZipfileTab *pTab, ZipfileEOCD *p){
50635329
u8 *aBuf = pTab->aBuffer;
@@ -5195,74 +5461,22 @@
51955461
}
51965462
#else /* SQLITE_OMIT_VIRTUALTABLE */
51975463
# define zipfileRegister(x) SQLITE_OK
51985464
#endif
51995465
5200
-/*
5201
-** zipfile_uncompress(DATA, SZ, METHOD)
5202
-*/
5203
-static void zipfileUncompressFunc(
5204
- sqlite3_context *context,
5205
- int argc,
5206
- sqlite3_value **argv
5207
-){
5208
- int iMethod;
5209
-
5210
- iMethod = sqlite3_value_int(argv[2]);
5211
- if( iMethod==0 ){
5212
- sqlite3_result_value(context, argv[0]);
5213
- }else if( iMethod==8 ){
5214
- Byte *res;
5215
- int sz = sqlite3_value_int(argv[1]);
5216
- z_stream str;
5217
- memset(&str, 0, sizeof(str));
5218
- str.next_in = (Byte*)sqlite3_value_blob(argv[0]);
5219
- str.avail_in = sqlite3_value_bytes(argv[0]);
5220
- res = str.next_out = (Byte*)sqlite3_malloc(sz);
5221
- if( res==0 ){
5222
- sqlite3_result_error_nomem(context);
5223
- }else{
5224
- int err;
5225
- str.avail_out = sz;
5226
-
5227
- err = inflateInit2(&str, -15);
5228
- if( err!=Z_OK ){
5229
- zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err);
5230
- }else{
5231
- err = inflate(&str, Z_NO_FLUSH);
5232
- if( err!=Z_STREAM_END ){
5233
- zipfileCtxErrorMsg(context, "inflate() failed (%d)", err);
5234
- }else{
5235
- sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT);
5236
- }
5237
- }
5238
- sqlite3_free(res);
5239
- inflateEnd(&str);
5240
- }
5241
- }else{
5242
- zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod);
5243
- }
5244
-}
5245
-
52465466
#ifdef _WIN32
52475467
52485468
#endif
52495469
int sqlite3_zipfile_init(
52505470
sqlite3 *db,
52515471
char **pzErrMsg,
52525472
const sqlite3_api_routines *pApi
52535473
){
5254
- int rc = SQLITE_OK;
52555474
SQLITE_EXTENSION_INIT2(pApi);
52565475
(void)pzErrMsg; /* Unused parameter */
5257
- rc = sqlite3_create_function(db, "zipfile_uncompress", 3,
5258
- SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0
5259
- );
5260
- if( rc!=SQLITE_OK ) return rc;
52615476
return zipfileRegister(db);
52625477
}
5263
-
52645478
52655479
/************************* End ../ext/misc/zipfile.c ********************/
52665480
/************************* Begin ../ext/misc/sqlar.c ******************/
52675481
/*
52685482
** 2017-12-17
@@ -5571,10 +5785,12 @@
55715785
*************************************************************************
55725786
*/
55735787
#include <assert.h>
55745788
#include <string.h>
55755789
#include <stdio.h>
5790
+
5791
+#ifndef SQLITE_OMIT_VIRTUALTABLE
55765792
55775793
/* typedef sqlite3_int64 i64; */
55785794
/* typedef sqlite3_uint64 u64; */
55795795
55805796
typedef struct IdxColumn IdxColumn;
@@ -6052,11 +6268,11 @@
60526268
}
60536269
}
60546270
}
60556271
}
60566272
6057
- pIdxInfo->estimatedCost = 1000000.0 / n;
6273
+ pIdxInfo->estimatedCost = 1000000.0 / (n+1);
60586274
return rc;
60596275
}
60606276
60616277
static int expertUpdate(
60626278
sqlite3_vtab *pVtab,
@@ -6311,11 +6527,11 @@
63116527
if( zAppend ){
63126528
nAppend = STRLEN(zAppend);
63136529
zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
63146530
}
63156531
if( zAppend && zRet ){
6316
- memcpy(zRet, zIn, nIn);
6532
+ if( nIn ) memcpy(zRet, zIn, nIn);
63176533
memcpy(&zRet[nIn], zAppend, nAppend+1);
63186534
}else{
63196535
sqlite3_free(zRet);
63206536
zRet = 0;
63216537
*pRc = SQLITE_NOMEM;
@@ -6465,11 +6681,11 @@
64656681
if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
64666682
IdxTable *pTab = pScan->pTab;
64676683
char *zCols = 0;
64686684
char *zIdx = 0;
64696685
IdxConstraint *pCons;
6470
- int h = 0;
6686
+ unsigned int h = 0;
64716687
const char *zFmt;
64726688
64736689
for(pCons=pEq; pCons; pCons=pCons->pLink){
64746690
zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
64756691
}
@@ -7080,10 +7296,11 @@
70807296
zCols = idxAppendText(&rc, zCols,
70817297
"%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
70827298
);
70837299
zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
70847300
}
7301
+ sqlite3_reset(pIndexXInfo);
70857302
if( rc==SQLITE_OK ){
70867303
if( p->iSample==100 ){
70877304
zQuery = sqlite3_mprintf(
70887305
"SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
70897306
);
@@ -7489,10 +7706,12 @@
74897706
idxHashClear(&p->hIdx);
74907707
sqlite3_free(p->zCandidates);
74917708
sqlite3_free(p);
74927709
}
74937710
}
7711
+
7712
+#endif /* ifndef SQLITE_OMIT_VIRTUAL_TABLE */
74947713
74957714
/************************* End ../ext/expert/sqlite3expert.c ********************/
74967715
74977716
#if defined(SQLITE_ENABLE_SESSION)
74987717
/*
@@ -7535,26 +7754,31 @@
75357754
u8 autoExplain; /* Automatically turn on .explain mode */
75367755
u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
75377756
u8 statsOn; /* True to display memory stats before each finalize */
75387757
u8 scanstatsOn; /* True to display scan stats before each finalize */
75397758
u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
7759
+ u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
75407760
int outCount; /* Revert to stdout when reaching zero */
75417761
int cnt; /* Number of records displayed so far */
75427762
FILE *out; /* Write results here */
75437763
FILE *traceOut; /* Output for sqlite3_trace() */
75447764
int nErr; /* Number of errors seen */
75457765
int mode; /* An output mode setting */
7766
+ int modePrior; /* Saved mode */
75467767
int cMode; /* temporary output mode for the current query */
75477768
int normalMode; /* Output mode before ".explain on" */
75487769
int writableSchema; /* True if PRAGMA writable_schema=ON */
75497770
int showHeader; /* True to show column names in List or Column mode */
75507771
int nCheck; /* Number of ".check" commands run */
75517772
unsigned shellFlgs; /* Various flags */
75527773
char *zDestTable; /* Name of destination table when MODE_Insert */
7774
+ char *zTempFile; /* Temporary file that might need deleting */
75537775
char zTestcase[30]; /* Name of current test case */
75547776
char colSeparator[20]; /* Column separator character for several modes */
75557777
char rowSeparator[20]; /* Row separator character for MODE_Ascii */
7778
+ char colSepPrior[20]; /* Saved column separator */
7779
+ char rowSepPrior[20]; /* Saved row separator */
75567780
int colWidth[100]; /* Requested width of each column when in column mode*/
75577781
int actualWidth[100]; /* Actual width of each column */
75587782
char nullValue[20]; /* The text to print when a NULL comes back from
75597783
** the database */
75607784
char outfile[FILENAME_MAX]; /* Filename for *out */
@@ -7648,24 +7872,175 @@
76487872
#define SEP_Comma ","
76497873
#define SEP_CrLf "\r\n"
76507874
#define SEP_Unit "\x1F"
76517875
#define SEP_Record "\x1E"
76527876
7653
-/*
7654
-** Number of elements in an array
7655
-*/
7656
-#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
7657
-
76587877
/*
76597878
** A callback for the sqlite3_log() interface.
76607879
*/
76617880
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
76627881
ShellState *p = (ShellState*)pArg;
76637882
if( p->pLog==0 ) return;
76647883
utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
76657884
fflush(p->pLog);
76667885
}
7886
+
7887
+/*
7888
+** SQL function: shell_putsnl(X)
7889
+**
7890
+** Write the text X to the screen (or whatever output is being directed)
7891
+** adding a newline at the end, and then return X.
7892
+*/
7893
+static void shellPutsFunc(
7894
+ sqlite3_context *pCtx,
7895
+ int nVal,
7896
+ sqlite3_value **apVal
7897
+){
7898
+ ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
7899
+ utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0]));
7900
+ sqlite3_result_value(pCtx, apVal[0]);
7901
+}
7902
+
7903
+/*
7904
+** SQL function: edit(VALUE)
7905
+** edit(VALUE,EDITOR)
7906
+**
7907
+** These steps:
7908
+**
7909
+** (1) Write VALUE into a temporary file.
7910
+** (2) Run program EDITOR on that temporary file.
7911
+** (3) Read the temporary file back and return its content as the result.
7912
+** (4) Delete the temporary file
7913
+**
7914
+** If the EDITOR argument is omitted, use the value in the VISUAL
7915
+** environment variable. If still there is no EDITOR, through an error.
7916
+**
7917
+** Also throw an error if the EDITOR program returns a non-zero exit code.
7918
+*/
7919
+static void editFunc(
7920
+ sqlite3_context *context,
7921
+ int argc,
7922
+ sqlite3_value **argv
7923
+){
7924
+ const char *zEditor;
7925
+ char *zTempFile = 0;
7926
+ sqlite3 *db;
7927
+ char *zCmd = 0;
7928
+ int bBin;
7929
+ int rc;
7930
+ FILE *f = 0;
7931
+ sqlite3_int64 sz;
7932
+ sqlite3_int64 x;
7933
+ unsigned char *p = 0;
7934
+
7935
+ if( argc==2 ){
7936
+ zEditor = (const char*)sqlite3_value_text(argv[1]);
7937
+ }else{
7938
+ zEditor = getenv("VISUAL");
7939
+ }
7940
+ if( zEditor==0 ){
7941
+ sqlite3_result_error(context, "no editor for edit()", -1);
7942
+ return;
7943
+ }
7944
+ if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
7945
+ sqlite3_result_error(context, "NULL input to edit()", -1);
7946
+ return;
7947
+ }
7948
+ db = sqlite3_context_db_handle(context);
7949
+ zTempFile = 0;
7950
+ sqlite3_file_control(db, 0, SQLITE_FCNTL_TEMPFILENAME, &zTempFile);
7951
+ if( zTempFile==0 ){
7952
+ sqlite3_uint64 r = 0;
7953
+ sqlite3_randomness(sizeof(r), &r);
7954
+ zTempFile = sqlite3_mprintf("temp%llx", r);
7955
+ if( zTempFile==0 ){
7956
+ sqlite3_result_error_nomem(context);
7957
+ return;
7958
+ }
7959
+ }
7960
+ bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB;
7961
+ f = fopen(zTempFile, bBin ? "wb" : "w");
7962
+ if( f==0 ){
7963
+ sqlite3_result_error(context, "edit() cannot open temp file", -1);
7964
+ goto edit_func_end;
7965
+ }
7966
+ sz = sqlite3_value_bytes(argv[0]);
7967
+ if( bBin ){
7968
+ x = fwrite(sqlite3_value_blob(argv[0]), 1, sz, f);
7969
+ }else{
7970
+ x = fwrite(sqlite3_value_text(argv[0]), 1, sz, f);
7971
+ }
7972
+ fclose(f);
7973
+ f = 0;
7974
+ if( x!=sz ){
7975
+ sqlite3_result_error(context, "edit() could not write the whole file", -1);
7976
+ goto edit_func_end;
7977
+ }
7978
+ zCmd = sqlite3_mprintf("%s \"%s\"", zEditor, zTempFile);
7979
+ if( zCmd==0 ){
7980
+ sqlite3_result_error_nomem(context);
7981
+ goto edit_func_end;
7982
+ }
7983
+ rc = system(zCmd);
7984
+ sqlite3_free(zCmd);
7985
+ if( rc ){
7986
+ sqlite3_result_error(context, "EDITOR returned non-zero", -1);
7987
+ goto edit_func_end;
7988
+ }
7989
+ f = fopen(zTempFile, bBin ? "rb" : "r");
7990
+ if( f==0 ){
7991
+ sqlite3_result_error(context,
7992
+ "edit() cannot reopen temp file after edit", -1);
7993
+ goto edit_func_end;
7994
+ }
7995
+ fseek(f, 0, SEEK_END);
7996
+ sz = ftell(f);
7997
+ rewind(f);
7998
+ p = sqlite3_malloc64( sz+(bBin==0) );
7999
+ if( p==0 ){
8000
+ sqlite3_result_error_nomem(context);
8001
+ goto edit_func_end;
8002
+ }
8003
+ if( bBin ){
8004
+ x = fread(p, 1, sz, f);
8005
+ }else{
8006
+ x = fread(p, 1, sz, f);
8007
+ p[sz] = 0;
8008
+ }
8009
+ fclose(f);
8010
+ f = 0;
8011
+ if( x!=sz ){
8012
+ sqlite3_result_error(context, "could not read back the whole file", -1);
8013
+ goto edit_func_end;
8014
+ }
8015
+ if( bBin ){
8016
+ sqlite3_result_blob(context, p, sz, sqlite3_free);
8017
+ }else{
8018
+ sqlite3_result_text(context, (const char*)p, sz, sqlite3_free);
8019
+ }
8020
+ p = 0;
8021
+
8022
+edit_func_end:
8023
+ if( f ) fclose(f);
8024
+ unlink(zTempFile);
8025
+ sqlite3_free(zTempFile);
8026
+ sqlite3_free(p);
8027
+}
8028
+
8029
+/*
8030
+** Save or restore the current output mode
8031
+*/
8032
+static void outputModePush(ShellState *p){
8033
+ p->modePrior = p->mode;
8034
+ memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
8035
+ memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
8036
+}
8037
+static void outputModePop(ShellState *p){
8038
+ p->mode = p->modePrior;
8039
+ memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
8040
+ memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
8041
+}
76678042
76688043
/*
76698044
** Output the given string as a hex-encoded blob (eg. X'1234' )
76708045
*/
76718046
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -8987,10 +9362,11 @@
89879362
} while( rc == SQLITE_ROW );
89889363
}
89899364
}
89909365
}
89919366
9367
+#ifndef SQLITE_OMIT_VIRTUALTABLE
89929368
/*
89939369
** This function is called to process SQL if the previous shell command
89949370
** was ".expert". It passes the SQL in the second argument directly to
89959371
** the sqlite3expert object.
89969372
**
@@ -9059,10 +9435,67 @@
90599435
sqlite3_expert_destroy(p);
90609436
pState->expert.pExpert = 0;
90619437
return rc;
90629438
}
90639439
9440
+/*
9441
+** Implementation of ".expert" dot command.
9442
+*/
9443
+static int expertDotCommand(
9444
+ ShellState *pState, /* Current shell tool state */
9445
+ char **azArg, /* Array of arguments passed to dot command */
9446
+ int nArg /* Number of entries in azArg[] */
9447
+){
9448
+ int rc = SQLITE_OK;
9449
+ char *zErr = 0;
9450
+ int i;
9451
+ int iSample = 0;
9452
+
9453
+ assert( pState->expert.pExpert==0 );
9454
+ memset(&pState->expert, 0, sizeof(ExpertInfo));
9455
+
9456
+ for(i=1; rc==SQLITE_OK && i<nArg; i++){
9457
+ char *z = azArg[i];
9458
+ int n;
9459
+ if( z[0]=='-' && z[1]=='-' ) z++;
9460
+ n = strlen30(z);
9461
+ if( n>=2 && 0==strncmp(z, "-verbose", n) ){
9462
+ pState->expert.bVerbose = 1;
9463
+ }
9464
+ else if( n>=2 && 0==strncmp(z, "-sample", n) ){
9465
+ if( i==(nArg-1) ){
9466
+ raw_printf(stderr, "option requires an argument: %s\n", z);
9467
+ rc = SQLITE_ERROR;
9468
+ }else{
9469
+ iSample = (int)integerValue(azArg[++i]);
9470
+ if( iSample<0 || iSample>100 ){
9471
+ raw_printf(stderr, "value out of range: %s\n", azArg[i]);
9472
+ rc = SQLITE_ERROR;
9473
+ }
9474
+ }
9475
+ }
9476
+ else{
9477
+ raw_printf(stderr, "unknown option: %s\n", z);
9478
+ rc = SQLITE_ERROR;
9479
+ }
9480
+ }
9481
+
9482
+ if( rc==SQLITE_OK ){
9483
+ pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
9484
+ if( pState->expert.pExpert==0 ){
9485
+ raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
9486
+ rc = SQLITE_ERROR;
9487
+ }else{
9488
+ sqlite3_expert_config(
9489
+ pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
9490
+ );
9491
+ }
9492
+ }
9493
+
9494
+ return rc;
9495
+}
9496
+#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
90649497
90659498
/*
90669499
** Execute a statement or set of statements. Print
90679500
** any result rows/columns depending on the current mode
90689501
** set via the supplied callback.
@@ -9086,14 +9519,16 @@
90869519
90879520
if( pzErrMsg ){
90889521
*pzErrMsg = NULL;
90899522
}
90909523
9524
+#ifndef SQLITE_OMIT_VIRTUALTABLE
90919525
if( pArg->expert.pExpert ){
90929526
rc = expertHandleSQL(pArg, zSql, pzErrMsg);
90939527
return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
90949528
}
9529
+#endif
90959530
90969531
while( zSql[0] && (SQLITE_OK == rc) ){
90979532
static const char *zStmtSql;
90989533
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
90999534
if( SQLITE_OK != rc ){
@@ -9516,10 +9951,11 @@
95169951
".dump ?TABLE? ... Dump the database in an SQL text format\n"
95179952
" If TABLE specified, only dump tables matching\n"
95189953
" LIKE pattern TABLE.\n"
95199954
".echo on|off Turn command echo on or off\n"
95209955
".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
9956
+ ".excel Display the output of next command in a spreadsheet\n"
95219957
".exit Exit this program\n"
95229958
".expert EXPERIMENTAL. Suggest indexes for specified queries\n"
95239959
/* Because explain mode comes on automatically now, the ".explain" mode
95249960
** is removed from the help screen. It is still supported for legacy, however */
95259961
/*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
@@ -9553,14 +9989,16 @@
95539989
" list Values delimited by \"|\"\n"
95549990
" quote Escape answers as for SQL\n"
95559991
" tabs Tab-separated values\n"
95569992
" tcl TCL list elements\n"
95579993
".nullvalue STRING Use STRING in place of NULL values\n"
9558
- ".once FILENAME Output for the next SQL command only to FILENAME\n"
9994
+ ".once (-e|-x|FILE) Output for the next SQL command only to FILE\n"
9995
+ " or invoke system text editor (-e) or spreadsheet (-x)\n"
9996
+ " on the output.\n"
95599997
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE\n"
95609998
" The --new option starts with an empty file\n"
9561
- ".output ?FILENAME? Send output to FILENAME or stdout\n"
9999
+ ".output ?FILE? Send output to FILE or stdout\n"
956210000
".print STRING... Print literal STRING\n"
956310001
".prompt MAIN CONTINUE Replace the standard prompts\n"
956410002
".quit Exit this program\n"
956510003
".read FILENAME Execute SQL in FILENAME\n"
956610004
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -9775,10 +10213,16 @@
977510213
#endif
977610214
sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
977710215
shellAddSchemaName, 0, 0);
977810216
sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
977910217
shellModuleSchema, 0, 0);
10218
+ sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
10219
+ shellPutsFunc, 0, 0);
10220
+ sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
10221
+ editFunc, 0, 0);
10222
+ sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
10223
+ editFunc, 0, 0);
978010224
if( p->openMode==SHELL_OPEN_ZIPFILE ){
978110225
char *zSql = sqlite3_mprintf(
978210226
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
978310227
sqlite3_exec(p->db, zSql, 0, 0, 0);
978410228
sqlite3_free(zSql);
@@ -9908,67 +10352,10 @@
990810352
z[j] = c;
990910353
}
991010354
if( j<i ) z[j] = 0;
991110355
}
991210356
9913
-/*
9914
-** Return the value of a hexadecimal digit. Return -1 if the input
9915
-** is not a hex digit.
9916
-*/
9917
-static int hexDigitValue(char c){
9918
- if( c>='0' && c<='9' ) return c - '0';
9919
- if( c>='a' && c<='f' ) return c - 'a' + 10;
9920
- if( c>='A' && c<='F' ) return c - 'A' + 10;
9921
- return -1;
9922
-}
9923
-
9924
-/*
9925
-** Interpret zArg as an integer value, possibly with suffixes.
9926
-*/
9927
-static sqlite3_int64 integerValue(const char *zArg){
9928
- sqlite3_int64 v = 0;
9929
- static const struct { char *zSuffix; int iMult; } aMult[] = {
9930
- { "KiB", 1024 },
9931
- { "MiB", 1024*1024 },
9932
- { "GiB", 1024*1024*1024 },
9933
- { "KB", 1000 },
9934
- { "MB", 1000000 },
9935
- { "GB", 1000000000 },
9936
- { "K", 1000 },
9937
- { "M", 1000000 },
9938
- { "G", 1000000000 },
9939
- };
9940
- int i;
9941
- int isNeg = 0;
9942
- if( zArg[0]=='-' ){
9943
- isNeg = 1;
9944
- zArg++;
9945
- }else if( zArg[0]=='+' ){
9946
- zArg++;
9947
- }
9948
- if( zArg[0]=='0' && zArg[1]=='x' ){
9949
- int x;
9950
- zArg += 2;
9951
- while( (x = hexDigitValue(zArg[0]))>=0 ){
9952
- v = (v<<4) + x;
9953
- zArg++;
9954
- }
9955
- }else{
9956
- while( IsDigit(zArg[0]) ){
9957
- v = v*10 + zArg[0] - '0';
9958
- zArg++;
9959
- }
9960
- }
9961
- for(i=0; i<ArraySize(aMult); i++){
9962
- if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
9963
- v *= aMult[i].iMult;
9964
- break;
9965
- }
9966
- }
9967
- return isNeg? -v : v;
9968
-}
9969
-
997010357
/*
997110358
** Interpret zArg as either an integer or a boolean value. Return 1 or 0
997210359
** for TRUE and FALSE. Return the integer value if appropriate.
997310360
*/
997410361
static int booleanValue(const char *zArg){
@@ -10011,20 +10398,20 @@
1001110398
/*
1001210399
** Try to open an output file. The names "stdout" and "stderr" are
1001310400
** recognized and do the right thing. NULL is returned if the output
1001410401
** filename is "off".
1001510402
*/
10016
-static FILE *output_file_open(const char *zFile){
10403
+static FILE *output_file_open(const char *zFile, int bTextMode){
1001710404
FILE *f;
1001810405
if( strcmp(zFile,"stdout")==0 ){
1001910406
f = stdout;
1002010407
}else if( strcmp(zFile, "stderr")==0 ){
1002110408
f = stderr;
1002210409
}else if( strcmp(zFile, "off")==0 ){
1002310410
f = 0;
1002410411
}else{
10025
- f = fopen(zFile, "wb");
10412
+ f = fopen(zFile, bTextMode ? "w" : "wb");
1002610413
if( f==0 ){
1002710414
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
1002810415
}
1002910416
}
1003010417
return f;
@@ -10433,19 +10820,41 @@
1043310820
}
1043410821
sqlite3_close(newDb);
1043510822
}
1043610823
1043710824
/*
10438
-** Change the output file back to stdout
10825
+** Change the output file back to stdout.
10826
+**
10827
+** If the p->doXdgOpen flag is set, that means the output was being
10828
+** redirected to a temporary file named by p->zTempFile. In that case,
10829
+** launch start/open/xdg-open on that temporary file.
1043910830
*/
1044010831
static void output_reset(ShellState *p){
1044110832
if( p->outfile[0]=='|' ){
1044210833
#ifndef SQLITE_OMIT_POPEN
1044310834
pclose(p->out);
1044410835
#endif
1044510836
}else{
1044610837
output_file_close(p->out);
10838
+ if( p->doXdgOpen ){
10839
+ const char *zXdgOpenCmd =
10840
+#if defined(_WIN32)
10841
+ "start";
10842
+#elif defined(__APPLE__)
10843
+ "open";
10844
+#else
10845
+ "xdg-open";
10846
+#endif
10847
+ char *zCmd;
10848
+ zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
10849
+ if( system(zCmd) ){
10850
+ utf8_printf(stderr, "Failed: [%s]\n", zCmd);
10851
+ }
10852
+ sqlite3_free(zCmd);
10853
+ outputModePop(p);
10854
+ p->doXdgOpen = 0;
10855
+ }
1044710856
}
1044810857
p->outfile[0] = 0;
1044910858
p->out = stdout;
1045010859
}
1045110860
@@ -10699,10 +11108,45 @@
1069911108
#else
1070011109
rc = unlink(zFilename);
1070111110
#endif
1070211111
return rc;
1070311112
}
11113
+
11114
+/*
11115
+** Try to delete the temporary file (if there is one) and free the
11116
+** memory used to hold the name of the temp file.
11117
+*/
11118
+static void clearTempFile(ShellState *p){
11119
+ if( p->zTempFile==0 ) return;
11120
+ if( p->doXdgOpen ) return;
11121
+ if( shellDeleteFile(p->zTempFile) ) return;
11122
+ sqlite3_free(p->zTempFile);
11123
+ p->zTempFile = 0;
11124
+}
11125
+
11126
+/*
11127
+** Create a new temp file name with the given suffix.
11128
+*/
11129
+static void newTempFile(ShellState *p, const char *zSuffix){
11130
+ clearTempFile(p);
11131
+ sqlite3_free(p->zTempFile);
11132
+ p->zTempFile = 0;
11133
+ if( p->db ){
11134
+ sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
11135
+ }
11136
+ if( p->zTempFile==0 ){
11137
+ sqlite3_uint64 r;
11138
+ sqlite3_randomness(sizeof(r), &r);
11139
+ p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
11140
+ }else{
11141
+ p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
11142
+ }
11143
+ if( p->zTempFile==0 ){
11144
+ raw_printf(stderr, "out of memory\n");
11145
+ exit(1);
11146
+ }
11147
+}
1070411148
1070511149
1070611150
/*
1070711151
** The implementation of SQL scalar function fkey_collate_clause(), used
1070811152
** by the ".lint fkey-indexes" command. This scalar function is always
@@ -11028,17 +11472,22 @@
1102811472
/*
1102911473
** Structure representing a single ".ar" command.
1103011474
*/
1103111475
typedef struct ArCommand ArCommand;
1103211476
struct ArCommand {
11033
- int eCmd; /* An AR_CMD_* value */
11477
+ u8 eCmd; /* An AR_CMD_* value */
11478
+ u8 bVerbose; /* True if --verbose */
11479
+ u8 bZip; /* True if the archive is a ZIP */
11480
+ u8 bDryRun; /* True if --dry-run */
11481
+ u8 bAppend; /* True if --append */
11482
+ int nArg; /* Number of command arguments */
11483
+ char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
1103411484
const char *zFile; /* --file argument, or NULL */
1103511485
const char *zDir; /* --directory argument, or NULL */
11036
- int bVerbose; /* True if --verbose */
11037
- int bZip; /* True if --zip */
11038
- int nArg; /* Number of command arguments */
1103911486
char **azArg; /* Array of command arguments */
11487
+ ShellState *p; /* Shell state */
11488
+ sqlite3 *db; /* Database containing the archive */
1104011489
};
1104111490
1104211491
/*
1104311492
** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
1104411493
*/
@@ -11060,11 +11509,13 @@
1106011509
" -x, --extract Extract files from archive\n"
1106111510
"\n"
1106211511
"And zero or more optional options:\n"
1106311512
" -v, --verbose Print each filename as it is processed\n"
1106411513
" -f FILE, --file FILE Operate on archive FILE (default is current db)\n"
11514
+" -a FILE, --append FILE Operate on FILE opened using the apndvfs VFS\n"
1106511515
" -C DIR, --directory DIR Change to directory DIR to read/extract files\n"
11516
+" -n, --dryrun Show the SQL that would have occurred\n"
1106611517
"\n"
1106711518
"See also: http://sqlite.org/cli.html#sqlar_archive_support\n"
1106811519
"\n"
1106911520
);
1107011521
return SQLITE_ERROR;
@@ -11095,14 +11546,15 @@
1109511546
#define AR_CMD_HELP 5
1109611547
1109711548
/*
1109811549
** Other (non-command) switches.
1109911550
*/
11100
-#define AR_SWITCH_VERBOSE 6
11101
-#define AR_SWITCH_FILE 7
11102
-#define AR_SWITCH_DIRECTORY 8
11103
-#define AR_SWITCH_ZIP 9
11551
+#define AR_SWITCH_VERBOSE 6
11552
+#define AR_SWITCH_FILE 7
11553
+#define AR_SWITCH_DIRECTORY 8
11554
+#define AR_SWITCH_APPEND 9
11555
+#define AR_SWITCH_DRYRUN 10
1110411556
1110511557
static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
1110611558
switch( eSwitch ){
1110711559
case AR_CMD_CREATE:
1110811560
case AR_CMD_EXTRACT:
@@ -11113,17 +11565,19 @@
1111311565
return arErrorMsg("multiple command options");
1111411566
}
1111511567
pAr->eCmd = eSwitch;
1111611568
break;
1111711569
11570
+ case AR_SWITCH_DRYRUN:
11571
+ pAr->bDryRun = 1;
11572
+ break;
1111811573
case AR_SWITCH_VERBOSE:
1111911574
pAr->bVerbose = 1;
1112011575
break;
11121
- case AR_SWITCH_ZIP:
11122
- pAr->bZip = 1;
11123
- break;
11124
-
11576
+ case AR_SWITCH_APPEND:
11577
+ pAr->bAppend = 1;
11578
+ /* Fall thru into --file */
1112511579
case AR_SWITCH_FILE:
1112611580
pAr->zFile = zArg;
1112711581
break;
1112811582
case AR_SWITCH_DIRECTORY:
1112911583
pAr->zDir = zArg;
@@ -11143,24 +11597,25 @@
1114311597
char **azArg, /* Array of arguments passed to dot command */
1114411598
int nArg, /* Number of entries in azArg[] */
1114511599
ArCommand *pAr /* Populate this object */
1114611600
){
1114711601
struct ArSwitch {
11148
- char cShort;
1114911602
const char *zLong;
11150
- int eSwitch;
11151
- int bArg;
11603
+ char cShort;
11604
+ u8 eSwitch;
11605
+ u8 bArg;
1115211606
} aSwitch[] = {
11153
- { 'c', "create", AR_CMD_CREATE, 0 },
11154
- { 'x', "extract", AR_CMD_EXTRACT, 0 },
11155
- { 't', "list", AR_CMD_LIST, 0 },
11156
- { 'u', "update", AR_CMD_UPDATE, 0 },
11157
- { 'h', "help", AR_CMD_HELP, 0 },
11158
- { 'v', "verbose", AR_SWITCH_VERBOSE, 0 },
11159
- { 'f', "file", AR_SWITCH_FILE, 1 },
11160
- { 'C', "directory", AR_SWITCH_DIRECTORY, 1 },
11161
- { 'z', "zip", AR_SWITCH_ZIP, 0 }
11607
+ { "create", 'c', AR_CMD_CREATE, 0 },
11608
+ { "extract", 'x', AR_CMD_EXTRACT, 0 },
11609
+ { "list", 't', AR_CMD_LIST, 0 },
11610
+ { "update", 'u', AR_CMD_UPDATE, 0 },
11611
+ { "help", 'h', AR_CMD_HELP, 0 },
11612
+ { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
11613
+ { "file", 'f', AR_SWITCH_FILE, 1 },
11614
+ { "append", 'a', AR_SWITCH_APPEND, 1 },
11615
+ { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
11616
+ { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
1116211617
};
1116311618
int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
1116411619
struct ArSwitch *pEnd = &aSwitch[nSwitch];
1116511620
1116611621
if( nArg<=1 ){
@@ -11283,41 +11738,39 @@
1128311738
**
1128411739
** This function strips any trailing '/' characters from each argument.
1128511740
** This is consistent with the way the [tar] command seems to work on
1128611741
** Linux.
1128711742
*/
11288
-static int arCheckEntries(sqlite3 *db, ArCommand *pAr){
11743
+static int arCheckEntries(ArCommand *pAr){
1128911744
int rc = SQLITE_OK;
1129011745
if( pAr->nArg ){
11291
- int i;
11746
+ int i, j;
1129211747
sqlite3_stmt *pTest = 0;
1129311748
11294
- shellPreparePrintf(db, &rc, &pTest, "SELECT name FROM %s WHERE name=?1",
11295
- pAr->bZip ? "zipfile(?2)" : "sqlar"
11749
+ shellPreparePrintf(pAr->db, &rc, &pTest,
11750
+ "SELECT name FROM %s WHERE name=$name",
11751
+ pAr->zSrcTable
1129611752
);
11297
- if( rc==SQLITE_OK && pAr->bZip ){
11298
- sqlite3_bind_text(pTest, 2, pAr->zFile, -1, SQLITE_TRANSIENT);
11299
- }
11753
+ j = sqlite3_bind_parameter_index(pTest, "$name");
1130011754
for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
1130111755
char *z = pAr->azArg[i];
1130211756
int n = strlen30(z);
1130311757
int bOk = 0;
1130411758
while( n>0 && z[n-1]=='/' ) n--;
1130511759
z[n] = '\0';
11306
- sqlite3_bind_text(pTest, 1, z, -1, SQLITE_STATIC);
11760
+ sqlite3_bind_text(pTest, j, z, -1, SQLITE_STATIC);
1130711761
if( SQLITE_ROW==sqlite3_step(pTest) ){
1130811762
bOk = 1;
1130911763
}
1131011764
shellReset(&rc, pTest);
1131111765
if( rc==SQLITE_OK && bOk==0 ){
11312
- raw_printf(stderr, "not found in archive: %s\n", z);
11766
+ utf8_printf(stderr, "not found in archive: %s\n", z);
1131311767
rc = SQLITE_ERROR;
1131411768
}
1131511769
}
1131611770
shellFinalize(&rc, pTest);
1131711771
}
11318
-
1131911772
return rc;
1132011773
}
1132111774
1132211775
/*
1132311776
** Format a WHERE clause that can be used against the "sqlar" table to
@@ -11339,13 +11792,13 @@
1133911792
int i;
1134011793
const char *zSep = "";
1134111794
for(i=0; i<pAr->nArg; i++){
1134211795
const char *z = pAr->azArg[i];
1134311796
zWhere = sqlite3_mprintf(
11344
- "%z%s name = '%q' OR name BETWEEN '%q/' AND '%q0'",
11345
- zWhere, zSep, z, z, z
11346
- );
11797
+ "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
11798
+ zWhere, zSep, z, strlen30(z)+1, z
11799
+ );
1134711800
if( zWhere==0 ){
1134811801
*pRc = SQLITE_NOMEM;
1134911802
break;
1135011803
}
1135111804
zSep = " OR ";
@@ -11353,109 +11806,75 @@
1135311806
}
1135411807
}
1135511808
*pzWhere = zWhere;
1135611809
}
1135711810
11358
-/*
11359
-** Argument zMode must point to a buffer at least 11 bytes in size. This
11360
-** function populates this buffer with the string interpretation of
11361
-** the unix file mode passed as the second argument (e.g. "drwxr-xr-x").
11362
-*/
11363
-static void shellModeToString(char *zMode, int mode){
11364
- int i;
11365
-
11366
- /* Magic numbers copied from [man 2 stat] */
11367
- if( mode & 0040000 ){
11368
- zMode[0] = 'd';
11369
- }else if( (mode & 0120000)==0120000 ){
11370
- zMode[0] = 'l';
11371
- }else{
11372
- zMode[0] = '-';
11373
- }
11374
-
11375
- for(i=0; i<3; i++){
11376
- int m = (mode >> ((2-i)*3));
11377
- char *a = &zMode[1 + i*3];
11378
- a[0] = (m & 0x4) ? 'r' : '-';
11379
- a[1] = (m & 0x2) ? 'w' : '-';
11380
- a[2] = (m & 0x1) ? 'x' : '-';
11381
- }
11382
- zMode[10] = '\0';
11383
-}
11384
-
1138511811
/*
1138611812
** Implementation of .ar "lisT" command.
1138711813
*/
11388
-static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11814
+static int arListCommand(ArCommand *pAr){
1138911815
const char *zSql = "SELECT %s FROM %s WHERE %s";
11390
- const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar");
1139111816
const char *azCols[] = {
1139211817
"name",
11393
- "mode, sz, datetime(mtime, 'unixepoch'), name"
11818
+ "lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
1139411819
};
1139511820
1139611821
char *zWhere = 0;
1139711822
sqlite3_stmt *pSql = 0;
1139811823
int rc;
1139911824
11400
- rc = arCheckEntries(db, pAr);
11825
+ rc = arCheckEntries(pAr);
1140111826
arWhereClause(&rc, pAr, &zWhere);
1140211827
11403
- shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere);
11404
- if( rc==SQLITE_OK && pAr->bZip ){
11405
- sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT);
11406
- }
11407
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11408
- if( pAr->bVerbose ){
11409
- char zMode[11];
11410
- shellModeToString(zMode, sqlite3_column_int(pSql, 0));
11411
-
11412
- raw_printf(p->out, "%s % 10d %s %s\n", zMode,
11413
- sqlite3_column_int(pSql, 1),
11414
- sqlite3_column_text(pSql, 2),
11415
- sqlite3_column_text(pSql, 3)
11416
- );
11417
- }else{
11418
- raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11419
- }
11420
- }
11421
-
11828
+ shellPreparePrintf(pAr->db, &rc, &pSql, zSql, azCols[pAr->bVerbose],
11829
+ pAr->zSrcTable, zWhere);
11830
+ if( pAr->bDryRun ){
11831
+ utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql));
11832
+ }else{
11833
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11834
+ if( pAr->bVerbose ){
11835
+ utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
11836
+ sqlite3_column_text(pSql, 0),
11837
+ sqlite3_column_int(pSql, 1),
11838
+ sqlite3_column_text(pSql, 2),
11839
+ sqlite3_column_text(pSql, 3)
11840
+ );
11841
+ }else{
11842
+ utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
11843
+ }
11844
+ }
11845
+ }
1142211846
shellFinalize(&rc, pSql);
1142311847
return rc;
1142411848
}
1142511849
1142611850
1142711851
/*
1142811852
** Implementation of .ar "eXtract" command.
1142911853
*/
11430
-static int arExtractCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11854
+static int arExtractCommand(ArCommand *pAr){
1143111855
const char *zSql1 =
1143211856
"SELECT "
11433
- " :1 || name, "
11434
- " writefile(?1 || name, %s, mode, mtime) "
11435
- "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";
11857
+ " ($dir || name),"
11858
+ " writefile(($dir || name), %s, mode, mtime) "
11859
+ "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)";
1143611860
1143711861
const char *azExtraArg[] = {
1143811862
"sqlar_uncompress(data, sz)",
11439
- "zipfile_uncompress(data, sz, method)"
11863
+ "data"
1144011864
};
11441
- const char *azSource[] = {
11442
- "sqlar", "zipfile(?3)"
11443
- };
11444
-
11445
-
1144611865
1144711866
sqlite3_stmt *pSql = 0;
1144811867
int rc = SQLITE_OK;
1144911868
char *zDir = 0;
1145011869
char *zWhere = 0;
11451
- int i;
11870
+ int i, j;
1145211871
1145311872
/* If arguments are specified, check that they actually exist within
1145411873
** the archive before proceeding. And formulate a WHERE clause to
1145511874
** match them. */
11456
- rc = arCheckEntries(db, pAr);
11875
+ rc = arCheckEntries(pAr);
1145711876
arWhereClause(&rc, pAr, &zWhere);
1145811877
1145911878
if( rc==SQLITE_OK ){
1146011879
if( pAr->zDir ){
1146111880
zDir = sqlite3_mprintf("%s/", pAr->zDir);
@@ -11463,30 +11882,33 @@
1146311882
zDir = sqlite3_mprintf("");
1146411883
}
1146511884
if( zDir==0 ) rc = SQLITE_NOMEM;
1146611885
}
1146711886
11468
- shellPreparePrintf(db, &rc, &pSql, zSql1,
11469
- azExtraArg[pAr->bZip], azSource[pAr->bZip], zWhere
11887
+ shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
11888
+ azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
1147011889
);
1147111890
1147211891
if( rc==SQLITE_OK ){
11473
- sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC);
11474
- if( pAr->bZip ){
11475
- sqlite3_bind_text(pSql, 3, pAr->zFile, -1, SQLITE_STATIC);
11476
- }
11892
+ j = sqlite3_bind_parameter_index(pSql, "$dir");
11893
+ sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
1147711894
1147811895
/* Run the SELECT statement twice. The first time, writefile() is called
1147911896
** for all archive members that should be extracted. The second time,
1148011897
** only for the directories. This is because the timestamps for
1148111898
** extracted directories must be reset after they are populated (as
1148211899
** populating them changes the timestamp). */
1148311900
for(i=0; i<2; i++){
11484
- sqlite3_bind_int(pSql, 2, i);
11485
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11486
- if( i==0 && pAr->bVerbose ){
11487
- raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11901
+ j = sqlite3_bind_parameter_index(pSql, "$dirOnly");
11902
+ sqlite3_bind_int(pSql, j, i);
11903
+ if( pAr->bDryRun ){
11904
+ utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql));
11905
+ }else{
11906
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11907
+ if( i==0 && pAr->bVerbose ){
11908
+ utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
11909
+ }
1148811910
}
1148911911
}
1149011912
shellReset(&rc, pSql);
1149111913
}
1149211914
shellFinalize(&rc, pSql);
@@ -11494,10 +11916,29 @@
1149411916
1149511917
sqlite3_free(zDir);
1149611918
sqlite3_free(zWhere);
1149711919
return rc;
1149811920
}
11921
+
11922
+/*
11923
+** Run the SQL statement in zSql. Or if doing a --dryrun, merely print it out.
11924
+*/
11925
+static int arExecSql(ArCommand *pAr, const char *zSql){
11926
+ int rc;
11927
+ if( pAr->bDryRun ){
11928
+ utf8_printf(pAr->p->out, "%s\n", zSql);
11929
+ rc = SQLITE_OK;
11930
+ }else{
11931
+ char *zErr = 0;
11932
+ rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr);
11933
+ if( zErr ){
11934
+ utf8_printf(stdout, "ERROR: %s\n", zErr);
11935
+ sqlite3_free(zErr);
11936
+ }
11937
+ }
11938
+ return rc;
11939
+}
1149911940
1150011941
1150111942
/*
1150211943
** Implementation of .ar "create" and "update" commands.
1150311944
**
@@ -11507,116 +11948,60 @@
1150711948
** printed on stdout for each file archived.
1150811949
**
1150911950
** The create command is the same as update, except that it drops
1151011951
** any existing "sqlar" table before beginning.
1151111952
*/
11512
-static int arCreateUpdate(
11513
- ShellState *p, /* Shell state pointer */
11514
- sqlite3 *db,
11953
+static int arCreateOrUpdateCommand(
1151511954
ArCommand *pAr, /* Command arguments and options */
11516
- int bUpdate
11955
+ int bUpdate /* true for a --create. false for --update */
1151711956
){
11518
- const char *zSql = "SELECT name, mode, mtime, data FROM fsdir(?, ?)";
1151911957
const char *zCreate =
1152011958
"CREATE TABLE IF NOT EXISTS sqlar(\n"
1152111959
" name TEXT PRIMARY KEY, -- name of the file\n"
1152211960
" mode INT, -- access permissions\n"
1152311961
" mtime INT, -- last modification time\n"
1152411962
" sz INT, -- original file size\n"
1152511963
" data BLOB -- compressed content\n"
1152611964
")";
1152711965
const char *zDrop = "DROP TABLE IF EXISTS sqlar";
11528
- const char *zInsert = "REPLACE INTO sqlar VALUES(?,?,?,?,sqlar_compress(?))";
11529
-
11530
- sqlite3_stmt *pStmt = 0; /* Directory traverser */
11531
- sqlite3_stmt *pInsert = 0; /* Compilation of zInsert */
11966
+ const char *zInsertFmt =
11967
+ "REPLACE INTO sqlar(name,mode,mtime,sz,data)\n"
11968
+ " SELECT\n"
11969
+ " %s,\n"
11970
+ " mode,\n"
11971
+ " mtime,\n"
11972
+ " CASE substr(lsmode(mode),1,1)\n"
11973
+ " WHEN '-' THEN length(data)\n"
11974
+ " WHEN 'd' THEN 0\n"
11975
+ " ELSE -1 END,\n"
11976
+ " CASE WHEN lsmode(mode) LIKE 'd%%' THEN NULL else data END\n"
11977
+ " FROM fsdir(%Q,%Q)\n"
11978
+ " WHERE lsmode(mode) NOT LIKE '?%%';";
1153211979
int i; /* For iterating through azFile[] */
1153311980
int rc; /* Return code */
1153411981
11535
- assert( pAr->bZip==0 );
11536
-
11537
- rc = sqlite3_exec(db, "SAVEPOINT ar;", 0, 0, 0);
11538
- if( rc!=SQLITE_OK ) return rc;
11539
-
11540
- if( bUpdate==0 ){
11541
- rc = sqlite3_exec(db, zDrop, 0, 0, 0);
11542
- if( rc!=SQLITE_OK ) return rc;
11543
- }
11544
-
11545
- rc = sqlite3_exec(db, zCreate, 0, 0, 0);
11546
- shellPrepare(db, &rc, zInsert, &pInsert);
11547
- shellPrepare(db, &rc, zSql, &pStmt);
11548
- sqlite3_bind_text(pStmt, 2, pAr->zDir, -1, SQLITE_STATIC);
11549
-
11550
- for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11551
- sqlite3_bind_text(pStmt, 1, pAr->azArg[i], -1, SQLITE_STATIC);
11552
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
11553
- int sz;
11554
- const char *zName = (const char*)sqlite3_column_text(pStmt, 0);
11555
- int mode = sqlite3_column_int(pStmt, 1);
11556
- unsigned int mtime = sqlite3_column_int(pStmt, 2);
11557
-
11558
- if( pAr->bVerbose ){
11559
- raw_printf(p->out, "%s\n", zName);
11560
- }
11561
-
11562
- sqlite3_bind_text(pInsert, 1, zName, -1, SQLITE_STATIC);
11563
- sqlite3_bind_int(pInsert, 2, mode);
11564
- sqlite3_bind_int64(pInsert, 3, (sqlite3_int64)mtime);
11565
-
11566
- if( S_ISDIR(mode) ){
11567
- sz = 0;
11568
- sqlite3_bind_null(pInsert, 5);
11569
- }else{
11570
- sqlite3_bind_value(pInsert, 5, sqlite3_column_value(pStmt, 3));
11571
- if( S_ISLNK(mode) ){
11572
- sz = -1;
11573
- }else{
11574
- sz = sqlite3_column_bytes(pStmt, 3);
11575
- }
11576
- }
11577
-
11578
- sqlite3_bind_int(pInsert, 4, sz);
11579
- sqlite3_step(pInsert);
11580
- rc = sqlite3_reset(pInsert);
11581
- }
11582
- shellReset(&rc, pStmt);
11583
- }
11584
-
11585
- if( rc!=SQLITE_OK ){
11586
- sqlite3_exec(db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
11587
- }else{
11588
- rc = sqlite3_exec(db, "RELEASE ar;", 0, 0, 0);
11589
- }
11590
- shellFinalize(&rc, pStmt);
11591
- shellFinalize(&rc, pInsert);
11592
- return rc;
11593
-}
11594
-
11595
-/*
11596
-** Implementation of .ar "Create" command.
11597
-**
11598
-** Create the "sqlar" table in the database if it does not already exist.
11599
-** Then add each file in the azFile[] array to the archive. Directories
11600
-** are added recursively. If argument bVerbose is non-zero, a message is
11601
-** printed on stdout for each file archived.
11602
-*/
11603
-static int arCreateCommand(
11604
- ShellState *p, /* Shell state pointer */
11605
- sqlite3 *db,
11606
- ArCommand *pAr /* Command arguments and options */
11607
-){
11608
- return arCreateUpdate(p, db, pAr, 0);
11609
-}
11610
-
11611
-/*
11612
-** Implementation of .ar "Update" command.
11613
-*/
11614
-static int arUpdateCmd(ShellState *p, sqlite3 *db, ArCommand *pAr){
11615
- return arCreateUpdate(p, db, pAr, 1);
11616
-}
11617
-
11982
+ rc = arExecSql(pAr, "SAVEPOINT ar;");
11983
+ if( rc!=SQLITE_OK ) return rc;
11984
+ if( bUpdate==0 ){
11985
+ rc = arExecSql(pAr, zDrop);
11986
+ if( rc!=SQLITE_OK ) return rc;
11987
+ }
11988
+ rc = arExecSql(pAr, zCreate);
11989
+ for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11990
+ char *zSql = sqlite3_mprintf(zInsertFmt,
11991
+ pAr->bVerbose ? "shell_putsnl(name)" : "name",
11992
+ pAr->azArg[i], pAr->zDir);
11993
+ rc = arExecSql(pAr, zSql);
11994
+ sqlite3_free(zSql);
11995
+ }
11996
+ if( rc!=SQLITE_OK ){
11997
+ arExecSql(pAr, "ROLLBACK TO ar; RELEASE ar;");
11998
+ }else{
11999
+ rc = arExecSql(pAr, "RELEASE ar;");
12000
+ }
12001
+ return rc;
12002
+}
1161812003
1161912004
/*
1162012005
** Implementation of ".ar" dot command.
1162112006
*/
1162212007
static int arDotCommand(
@@ -11624,138 +12009,108 @@
1162412009
char **azArg, /* Array of arguments passed to dot command */
1162512010
int nArg /* Number of entries in azArg[] */
1162612011
){
1162712012
ArCommand cmd;
1162812013
int rc;
12014
+ memset(&cmd, 0, sizeof(cmd));
1162912015
rc = arParseCommand(azArg, nArg, &cmd);
1163012016
if( rc==SQLITE_OK ){
11631
- sqlite3 *db = 0; /* Database handle to use as archive */
11632
-
11633
- if( cmd.bZip ){
12017
+ int eDbType = SHELL_OPEN_UNSPEC;
12018
+ cmd.p = pState;
12019
+ cmd.db = pState->db;
12020
+ if( cmd.zFile ){
12021
+ eDbType = deduceDatabaseType(cmd.zFile);
12022
+ }else{
12023
+ eDbType = pState->openMode;
12024
+ }
12025
+ if( eDbType==SHELL_OPEN_ZIPFILE ){
1163412026
if( cmd.zFile==0 ){
11635
- raw_printf(stderr, "zip format requires a --file switch\n");
11636
- return SQLITE_ERROR;
11637
- }else
12027
+ cmd.zSrcTable = sqlite3_mprintf("zip");
12028
+ }else{
12029
+ cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile);
12030
+ }
1163812031
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11639
- raw_printf(stderr, "zip archives are read-only\n");
11640
- return SQLITE_ERROR;
12032
+ utf8_printf(stderr, "zip archives are read-only\n");
12033
+ rc = SQLITE_ERROR;
12034
+ goto end_ar_command;
1164112035
}
11642
- db = pState->db;
12036
+ cmd.bZip = 1;
1164312037
}else if( cmd.zFile ){
1164412038
int flags;
12039
+ if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
1164512040
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
1164612041
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
1164712042
}else{
1164812043
flags = SQLITE_OPEN_READONLY;
1164912044
}
11650
- rc = sqlite3_open_v2(cmd.zFile, &db, flags, 0);
12045
+ cmd.db = 0;
12046
+ if( cmd.bDryRun ){
12047
+ utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
12048
+ eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
12049
+ }
12050
+ rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
12051
+ eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
1165112052
if( rc!=SQLITE_OK ){
11652
- raw_printf(stderr, "cannot open file: %s (%s)\n",
11653
- cmd.zFile, sqlite3_errmsg(db)
12053
+ utf8_printf(stderr, "cannot open file: %s (%s)\n",
12054
+ cmd.zFile, sqlite3_errmsg(cmd.db)
1165412055
);
11655
- sqlite3_close(db);
11656
- return rc;
12056
+ goto end_ar_command;
1165712057
}
11658
- sqlite3_fileio_init(db, 0, 0);
12058
+ sqlite3_fileio_init(cmd.db, 0, 0);
1165912059
#ifdef SQLITE_HAVE_ZLIB
11660
- sqlite3_sqlar_init(db, 0, 0);
12060
+ sqlite3_sqlar_init(cmd.db, 0, 0);
1166112061
#endif
11662
- }else{
11663
- db = pState->db;
12062
+ sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p,
12063
+ shellPutsFunc, 0, 0);
12064
+
12065
+ }
12066
+ if( cmd.zSrcTable==0 ){
12067
+ if( cmd.eCmd!=AR_CMD_CREATE
12068
+ && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0)
12069
+ ){
12070
+ utf8_printf(stderr, "database does not contain an 'sqlar' table\n");
12071
+ rc = SQLITE_ERROR;
12072
+ goto end_ar_command;
12073
+ }
12074
+ cmd.zSrcTable = sqlite3_mprintf("sqlar");
1166412075
}
1166512076
1166612077
switch( cmd.eCmd ){
1166712078
case AR_CMD_CREATE:
11668
- rc = arCreateCommand(pState, db, &cmd);
12079
+ rc = arCreateOrUpdateCommand(&cmd, 0);
1166912080
break;
1167012081
1167112082
case AR_CMD_EXTRACT:
11672
- rc = arExtractCommand(pState, db, &cmd);
12083
+ rc = arExtractCommand(&cmd);
1167312084
break;
1167412085
1167512086
case AR_CMD_LIST:
11676
- rc = arListCommand(pState, db, &cmd);
12087
+ rc = arListCommand(&cmd);
1167712088
break;
1167812089
1167912090
case AR_CMD_HELP:
1168012091
arUsage(pState->out);
1168112092
break;
1168212093
1168312094
default:
1168412095
assert( cmd.eCmd==AR_CMD_UPDATE );
11685
- rc = arUpdateCmd(pState, db, &cmd);
12096
+ rc = arCreateOrUpdateCommand(&cmd, 1);
1168612097
break;
1168712098
}
11688
-
11689
- if( cmd.zFile ){
11690
- sqlite3_close(db);
11691
- }
12099
+ }
12100
+end_ar_command:
12101
+ if( cmd.db!=pState->db ){
12102
+ sqlite3_close(cmd.db);
1169212103
}
12104
+ sqlite3_free(cmd.zSrcTable);
1169312105
1169412106
return rc;
1169512107
}
1169612108
/* End of the ".archive" or ".ar" command logic
1169712109
**********************************************************************************/
1169812110
#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
1169912111
11700
-/*
11701
-** Implementation of ".expert" dot command.
11702
-*/
11703
-static int expertDotCommand(
11704
- ShellState *pState, /* Current shell tool state */
11705
- char **azArg, /* Array of arguments passed to dot command */
11706
- int nArg /* Number of entries in azArg[] */
11707
-){
11708
- int rc = SQLITE_OK;
11709
- char *zErr = 0;
11710
- int i;
11711
- int iSample = 0;
11712
-
11713
- assert( pState->expert.pExpert==0 );
11714
- memset(&pState->expert, 0, sizeof(ExpertInfo));
11715
-
11716
- for(i=1; rc==SQLITE_OK && i<nArg; i++){
11717
- char *z = azArg[i];
11718
- int n;
11719
- if( z[0]=='-' && z[1]=='-' ) z++;
11720
- n = strlen30(z);
11721
- if( n>=2 && 0==strncmp(z, "-verbose", n) ){
11722
- pState->expert.bVerbose = 1;
11723
- }
11724
- else if( n>=2 && 0==strncmp(z, "-sample", n) ){
11725
- if( i==(nArg-1) ){
11726
- raw_printf(stderr, "option requires an argument: %s\n", z);
11727
- rc = SQLITE_ERROR;
11728
- }else{
11729
- iSample = (int)integerValue(azArg[++i]);
11730
- if( iSample<0 || iSample>100 ){
11731
- raw_printf(stderr, "value out of range: %s\n", azArg[i]);
11732
- rc = SQLITE_ERROR;
11733
- }
11734
- }
11735
- }
11736
- else{
11737
- raw_printf(stderr, "unknown option: %s\n", z);
11738
- rc = SQLITE_ERROR;
11739
- }
11740
- }
11741
-
11742
- if( rc==SQLITE_OK ){
11743
- pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
11744
- if( pState->expert.pExpert==0 ){
11745
- raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
11746
- rc = SQLITE_ERROR;
11747
- }else{
11748
- sqlite3_expert_config(
11749
- pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
11750
- );
11751
- }
11752
- }
11753
-
11754
- return rc;
11755
-}
11756
-
1175712112
1175812113
/*
1175912114
** If an input line begins with "." then invoke this routine to
1176012115
** process that line.
1176112116
**
@@ -11766,13 +12121,15 @@
1176612121
int nArg = 0;
1176712122
int n, c;
1176812123
int rc = 0;
1176912124
char *azArg[50];
1177012125
12126
+#ifndef SQLITE_OMIT_VIRTUALTABLE
1177112127
if( p->expert.pExpert ){
1177212128
expertFinish(p, 1, 0);
1177312129
}
12130
+#endif
1177412131
1177512132
/* Parse the input line into tokens.
1177612133
*/
1177712134
while( zLine[h] && nArg<ArraySize(azArg) ){
1177812135
while( IsSpace(zLine[h]) ){ h++; }
@@ -11799,10 +12156,11 @@
1179912156
/* Process the input line.
1180012157
*/
1180112158
if( nArg==0 ) return 0; /* no tokens, no error */
1180212159
n = strlen30(azArg[0]);
1180312160
c = azArg[0][0];
12161
+ clearTempFile(p);
1180412162
1180512163
#ifndef SQLITE_OMIT_AUTHORIZATION
1180612164
if( c=='a' && strncmp(azArg[0], "auth", n)==0 ){
1180712165
if( nArg!=2 ){
1180812166
raw_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -12133,14 +12491,16 @@
1213312491
if( p->mode==MODE_Explain ) p->mode = p->normalMode;
1213412492
p->autoExplain = 1;
1213512493
}
1213612494
}else
1213712495
12496
+#ifndef SQLITE_OMIT_VIRTUALTABLE
1213812497
if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
1213912498
open_db(p, 0);
1214012499
expertDotCommand(p, azArg, nArg);
1214112500
}else
12501
+#endif
1214212502
1214312503
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
1214412504
ShellState data;
1214512505
char *zErrMsg = 0;
1214612506
int doStats = 0;
@@ -12592,11 +12952,11 @@
1259212952
raw_printf(stderr, "Usage: .log FILENAME\n");
1259312953
rc = 1;
1259412954
}else{
1259512955
const char *zFile = azArg[1];
1259612956
output_file_close(p->pLog);
12597
- p->pLog = output_file_open(zFile);
12957
+ p->pLog = output_file_open(zFile, 0);
1259812958
}
1259912959
}else
1260012960
1260112961
if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
1260212962
const char *zMode = nArg>=2 ? azArg[1] : "";
@@ -12701,30 +13061,54 @@
1270113061
p->zDbFilename = 0;
1270213062
open_db(p, 0);
1270313063
}
1270413064
}else
1270513065
12706
- if( c=='o'
12707
- && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
13066
+ if( (c=='o'
13067
+ && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
13068
+ || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
1270813069
){
1270913070
const char *zFile = nArg>=2 ? azArg[1] : "stdout";
13071
+ int bTxtMode = 0;
13072
+ if( azArg[0][0]=='e' ){
13073
+ /* Transform the ".excel" command into ".once -x" */
13074
+ nArg = 2;
13075
+ azArg[0] = "once";
13076
+ zFile = azArg[1] = "-x";
13077
+ n = 4;
13078
+ }
1271013079
if( nArg>2 ){
12711
- utf8_printf(stderr, "Usage: .%s FILE\n", azArg[0]);
13080
+ utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
1271213081
rc = 1;
1271313082
goto meta_command_exit;
1271413083
}
1271513084
if( n>1 && strncmp(azArg[0], "once", n)==0 ){
1271613085
if( nArg<2 ){
12717
- raw_printf(stderr, "Usage: .once FILE\n");
13086
+ raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
1271813087
rc = 1;
1271913088
goto meta_command_exit;
1272013089
}
1272113090
p->outCount = 2;
1272213091
}else{
1272313092
p->outCount = 0;
1272413093
}
1272513094
output_reset(p);
13095
+ if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
13096
+ if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
13097
+ p->doXdgOpen = 1;
13098
+ outputModePush(p);
13099
+ if( zFile[1]=='x' ){
13100
+ newTempFile(p, "csv");
13101
+ p->mode = MODE_Csv;
13102
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
13103
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
13104
+ }else{
13105
+ newTempFile(p, "txt");
13106
+ bTxtMode = 1;
13107
+ }
13108
+ zFile = p->zTempFile;
13109
+ }
1272613110
if( zFile[0]=='|' ){
1272713111
#ifdef SQLITE_OMIT_POPEN
1272813112
raw_printf(stderr, "Error: pipes are not supported in this OS\n");
1272913113
rc = 1;
1273013114
p->out = stdout;
@@ -12737,11 +13121,11 @@
1273713121
}else{
1273813122
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
1273913123
}
1274013124
#endif
1274113125
}else{
12742
- p->out = output_file_open(zFile);
13126
+ p->out = output_file_open(zFile, bTxtMode);
1274313127
if( p->out==0 ){
1274413128
if( strcmp(zFile,"off")!=0 ){
1274513129
utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
1274613130
}
1274713131
p->out = stdout;
@@ -13614,11 +13998,11 @@
1361413998
}else
1361513999
1361614000
/* Begin redirecting output to the file "testcase-out.txt" */
1361714001
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
1361814002
output_reset(p);
13619
- p->out = output_file_open("testcase-out.txt");
14003
+ p->out = output_file_open("testcase-out.txt", 0);
1362014004
if( p->out==0 ){
1362114005
raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
1362214006
}
1362314007
if( nArg>=2 ){
1362414008
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -13820,11 +14204,11 @@
1382014204
raw_printf(stderr, "Usage: .trace FILE|off\n");
1382114205
rc = 1;
1382214206
goto meta_command_exit;
1382314207
}
1382414208
output_file_close(p->traceOut);
13825
- p->traceOut = output_file_open(azArg[1]);
14209
+ p->traceOut = output_file_open(azArg[1], 0);
1382614210
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
1382714211
if( p->traceOut==0 ){
1382814212
sqlite3_trace_v2(p->db, 0, 0, 0);
1382914213
}else{
1383014214
sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
@@ -14150,10 +14534,12 @@
1415014534
errCnt += runOneSqlLine(p, zSql, in, startline);
1415114535
nSql = 0;
1415214536
if( p->outCount ){
1415314537
output_reset(p);
1415414538
p->outCount = 0;
14539
+ }else{
14540
+ clearTempFile(p);
1415514541
}
1415614542
}else if( nSql && _all_whitespace(zSql) ){
1415714543
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
1415814544
nSql = 0;
1415914545
}
@@ -14772,11 +15158,14 @@
1477215158
session_close_all(&data);
1477315159
sqlite3_close(data.db);
1477415160
}
1477515161
sqlite3_free(data.zFreeOnClose);
1477615162
find_home_dir(1);
15163
+ output_reset(&data);
15164
+ data.doXdgOpen = 0;
15165
+ clearTempFile(&data);
1477715166
#if !SQLITE_SHELL_IS_UTF8
1477815167
for(i=0; i<argc; i++) sqlite3_free(argv[i]);
1477915168
sqlite3_free(argv);
1478015169
#endif
1478115170
return rc;
1478215171
}
1478315172
--- src/shell.c
+++ src/shell.c
@@ -92,14 +92,14 @@
92 # include <signal.h>
93 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
94 # include <pwd.h>
95 # endif
96 #endif
97 #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H)
98 # include <unistd.h>
99 # include <dirent.h>
100 # if defined(__MINGW_H)
101 # define DIRENT dirent
102 # ifndef S_ISLNK
103 # define S_ISLNK(mode) (0)
104 # endif
105 # endif
@@ -368,10 +368,15 @@
368 /*
369 ** Used to prevent warnings about unused parameters
370 */
371 #define UNUSED_PARAMETER(x) (void)(x)
372
 
 
 
 
 
373 /*
374 ** If the following flag is set, then command execution stops
375 ** at an error if we are not interactive.
376 */
377 static int bail_on_error = 0;
@@ -640,10 +645,69 @@
640 if( zResult && *zResult ) shell_add_history(zResult);
641 #endif
642 }
643 return zResult;
644 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645 /*
646 ** A variable length string to which one can append text.
647 */
648 typedef struct ShellText ShellText;
649 struct ShellText {
@@ -818,12 +882,13 @@
818 sqlite3_value **apVal
819 ){
820 const char *zName = (const char*)sqlite3_value_text(apVal[0]);
821 char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
822 if( zFake ){
823 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake),
824 -1, sqlite3_free);
 
825 }
826 }
827
828 /*
829 ** SQL function: shell_add_schema(S,X)
@@ -879,14 +944,15 @@
879 if( zName
880 && aPrefix[i][0]=='V'
881 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
882 ){
883 if( z==0 ){
884 z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake);
885 }else{
886 z = sqlite3_mprintf("%z\n/* %z */", z, zFake);
887 }
 
888 }
889 if( z ){
890 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
891 return;
892 }
@@ -2068,14 +2134,15 @@
2068 # include "windows.h"
2069 # include <io.h>
2070 # include <direct.h>
2071 /* # include "test_windirent.h" */
2072 # define dirent DIRENT
2073 # define timespec TIMESPEC
2074 # define stat _stat
 
2075 # define mkdir(path,mode) _mkdir(path)
2076 # define lstat(path,buf) _stat(path,buf)
2077 #endif
2078 #include <time.h>
2079 #include <errno.h>
2080
2081
@@ -2331,10 +2398,44 @@
2331 }else{
2332 ctxErrorMsg(context, "failed to write file: %s", zFile);
2333 }
2334 }
2335 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2336
2337 #ifndef SQLITE_OMIT_VIRTUALTABLE
2338
2339 /*
2340 ** Cursor type for recursively iterating through a directory structure.
@@ -2743,10 +2844,14 @@
2743 readfileFunc, 0, 0);
2744 if( rc==SQLITE_OK ){
2745 rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
2746 writefileFunc, 0, 0);
2747 }
 
 
 
 
2748 if( rc==SQLITE_OK ){
2749 rc = fsdirRegister(db);
2750 }
2751 return rc;
2752 }
@@ -3885,21 +3990,22 @@
3885 typedef unsigned short u16;
3886 typedef unsigned long u32;
3887 #define MIN(a,b) ((a)<(b) ? (a) : (b))
3888 #endif
3889
3890 #define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3891 "name, /* Name of file in zip archive */" \
3892 "mode, /* POSIX mode for file */" \
3893 "mtime, /* Last modification time in seconds since epoch */" \
3894 "sz, /* Size of object */" \
3895 "data, /* Data stored in zip file (possibly compressed) */" \
3896 "method, /* Compression method (integer) */" \
3897 "f HIDDEN /* Name of zip file */" \
 
3898 ");"
3899
3900 #define ZIPFILE_F_COLUMN_IDX 6 /* Index of column "f" in the above */
3901 #define ZIPFILE_BUFFER_SIZE (64*1024)
3902
3903
3904 /*
3905 ** Magic numbers used to read and write zip files.
@@ -4513,10 +4619,84 @@
4513 pCds->mDate = (u16)(
4514 (res.tm_mday-1) +
4515 ((res.tm_mon+1) << 5) +
4516 ((res.tm_year-80) << 9));
4517 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4518
4519 /*
4520 ** Return values of columns for the row at which the series_cursor
4521 ** is currently pointing.
4522 */
@@ -4546,30 +4726,37 @@
4546 }
4547 case 3: { /* sz */
4548 sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4549 break;
4550 }
4551 case 4: { /* data */
4552 int sz = pCsr->cds.szCompressed;
4553 if( sz>0 ){
4554 u8 *aBuf = sqlite3_malloc(sz);
4555 if( aBuf==0 ){
4556 rc = SQLITE_NOMEM;
4557 }else{
4558 FILE *pFile = zipfileGetFd(pCsr);
4559 rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4560 &pCsr->base.pVtab->zErrMsg
4561 );
4562 }
4563 if( rc==SQLITE_OK ){
4564 sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4565 sqlite3_free(aBuf);
 
 
 
 
 
 
 
4566 }
4567 }
4568 break;
4569 }
4570 case 5: /* method */
4571 sqlite3_result_int(ctx, pCsr->cds.iCompression);
4572 break;
4573 }
4574
4575 return SQLITE_OK;
@@ -4794,11 +4981,11 @@
4794 if( pNew==0 ){
4795 rc = SQLITE_NOMEM;
4796 }else{
4797 memset(pNew, 0, sizeof(ZipfileEntry));
4798 pNew->zPath = (char*)&pNew[1];
4799 memcpy(pNew->zPath, &aBuf[ZIPFILE_CDS_FIXED_SZ], nFile);
4800 pNew->zPath[nFile] = '\0';
4801 pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
4802 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4803 memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4804 zipfileAddEntry(pTab, pNew);
@@ -4913,15 +5100,22 @@
4913 }
4914
4915 return rc;
4916 }
4917
4918 static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
 
 
 
 
 
4919 const char *z = (const char*)sqlite3_value_text(pVal);
4920 int mode = 0;
4921 if( z==0 || (z[0]>=0 && z[0]<=9) ){
4922 mode = sqlite3_value_int(pVal);
 
 
4923 }else{
4924 const char zTemplate[11] = "-rwxrwxrwx";
4925 int i;
4926 if( strlen(z)!=10 ) goto parse_error;
4927 switch( z[0] ){
@@ -4942,10 +5136,22 @@
4942
4943 parse_error:
4944 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: parse error in mode: %s", z);
4945 return SQLITE_ERROR;
4946 }
 
 
 
 
 
 
 
 
 
 
 
 
4947
4948 /*
4949 ** xUpdate method.
4950 */
4951 static int zipfileUpdate(
@@ -4956,79 +5162,138 @@
4956 ){
4957 ZipfileTab *pTab = (ZipfileTab*)pVtab;
4958 int rc = SQLITE_OK; /* Return Code */
4959 ZipfileEntry *pNew = 0; /* New in-memory CDS entry */
4960
4961 int mode; /* Mode for new entry */
4962 i64 mTime; /* Modification time for new entry */
4963 i64 sz; /* Uncompressed size */
4964 const char *zPath; /* Path for new entry */
4965 int nPath; /* strlen(zPath) */
4966 const u8 *pData; /* Pointer to buffer containing content */
4967 int nData; /* Size of pData buffer in bytes */
4968 int iMethod = 0; /* Compression method for new entry */
4969 u8 *pFree = 0; /* Free this */
 
4970 ZipfileCDS cds; /* New Central Directory Structure entry */
 
 
 
 
4971
4972 assert( pTab->zFile );
4973 assert( pTab->pWriteFd );
4974
4975 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
4976 i64 iDelete = sqlite3_value_int64(apVal[0]);
4977 ZipfileEntry *p;
4978 for(p=pTab->pFirstEntry; p; p=p->pNext){
4979 if( p->iRowid==iDelete ){
4980 p->bDeleted = 1;
4981 break;
4982 }
4983 }
4984 if( nVal==1 ) return SQLITE_OK;
4985 }
4986
4987 zPath = (const char*)sqlite3_value_text(apVal[2]);
4988 nPath = (int)strlen(zPath);
4989 rc = zipfileGetMode(pTab, apVal[3], &mode);
4990 if( rc!=SQLITE_OK ) return rc;
4991 mTime = sqlite3_value_int64(apVal[4]);
4992 sz = sqlite3_value_int(apVal[5]);
4993 pData = sqlite3_value_blob(apVal[6]);
4994 nData = sqlite3_value_bytes(apVal[6]);
4995
4996 /* If a NULL value is inserted into the 'method' column, do automatic
4997 ** compression. */
4998 if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){
4999 pFree = (u8*)sqlite3_malloc(nData);
5000 if( pFree==0 ){
5001 rc = SQLITE_NOMEM;
5002 }else{
5003 int res;
5004 z_stream str;
5005 memset(&str, 0, sizeof(str));
5006 str.next_in = (z_const Bytef*)pData;
5007 str.avail_in = nData;
5008 str.next_out = pFree;
5009 str.avail_out = nData;
5010 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5011 res = deflate(&str, Z_FINISH);
5012 if( res==Z_STREAM_END ){
5013 pData = pFree;
5014 nData = str.total_out;
5015 iMethod = 8;
5016 }else if( res!=Z_OK ){
5017 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
5018 rc = SQLITE_ERROR;
5019 }
5020 deflateEnd(&str);
5021 }
5022 }else{
5023 iMethod = sqlite3_value_int(apVal[7]);
 
 
 
 
 
 
5024 if( iMethod<0 || iMethod>65535 ){
5025 pTab->base.zErrMsg = sqlite3_mprintf(
5026 "zipfile: invalid compression method: %d", iMethod
5027 );
5028 rc = SQLITE_ERROR;
5029 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5030 }
5031
5032 if( rc==SQLITE_OK ){
5033 /* Create the new CDS record. */
5034 memset(&cds, 0, sizeof(cds));
@@ -5054,10 +5319,11 @@
5054 if( rc==SQLITE_OK ){
5055 rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
5056 }
5057
5058 sqlite3_free(pFree);
 
5059 return rc;
5060 }
5061
5062 static int zipfileAppendEOCD(ZipfileTab *pTab, ZipfileEOCD *p){
5063 u8 *aBuf = pTab->aBuffer;
@@ -5195,74 +5461,22 @@
5195 }
5196 #else /* SQLITE_OMIT_VIRTUALTABLE */
5197 # define zipfileRegister(x) SQLITE_OK
5198 #endif
5199
5200 /*
5201 ** zipfile_uncompress(DATA, SZ, METHOD)
5202 */
5203 static void zipfileUncompressFunc(
5204 sqlite3_context *context,
5205 int argc,
5206 sqlite3_value **argv
5207 ){
5208 int iMethod;
5209
5210 iMethod = sqlite3_value_int(argv[2]);
5211 if( iMethod==0 ){
5212 sqlite3_result_value(context, argv[0]);
5213 }else if( iMethod==8 ){
5214 Byte *res;
5215 int sz = sqlite3_value_int(argv[1]);
5216 z_stream str;
5217 memset(&str, 0, sizeof(str));
5218 str.next_in = (Byte*)sqlite3_value_blob(argv[0]);
5219 str.avail_in = sqlite3_value_bytes(argv[0]);
5220 res = str.next_out = (Byte*)sqlite3_malloc(sz);
5221 if( res==0 ){
5222 sqlite3_result_error_nomem(context);
5223 }else{
5224 int err;
5225 str.avail_out = sz;
5226
5227 err = inflateInit2(&str, -15);
5228 if( err!=Z_OK ){
5229 zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err);
5230 }else{
5231 err = inflate(&str, Z_NO_FLUSH);
5232 if( err!=Z_STREAM_END ){
5233 zipfileCtxErrorMsg(context, "inflate() failed (%d)", err);
5234 }else{
5235 sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT);
5236 }
5237 }
5238 sqlite3_free(res);
5239 inflateEnd(&str);
5240 }
5241 }else{
5242 zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod);
5243 }
5244 }
5245
5246 #ifdef _WIN32
5247
5248 #endif
5249 int sqlite3_zipfile_init(
5250 sqlite3 *db,
5251 char **pzErrMsg,
5252 const sqlite3_api_routines *pApi
5253 ){
5254 int rc = SQLITE_OK;
5255 SQLITE_EXTENSION_INIT2(pApi);
5256 (void)pzErrMsg; /* Unused parameter */
5257 rc = sqlite3_create_function(db, "zipfile_uncompress", 3,
5258 SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0
5259 );
5260 if( rc!=SQLITE_OK ) return rc;
5261 return zipfileRegister(db);
5262 }
5263
5264
5265 /************************* End ../ext/misc/zipfile.c ********************/
5266 /************************* Begin ../ext/misc/sqlar.c ******************/
5267 /*
5268 ** 2017-12-17
@@ -5571,10 +5785,12 @@
5571 *************************************************************************
5572 */
5573 #include <assert.h>
5574 #include <string.h>
5575 #include <stdio.h>
 
 
5576
5577 /* typedef sqlite3_int64 i64; */
5578 /* typedef sqlite3_uint64 u64; */
5579
5580 typedef struct IdxColumn IdxColumn;
@@ -6052,11 +6268,11 @@
6052 }
6053 }
6054 }
6055 }
6056
6057 pIdxInfo->estimatedCost = 1000000.0 / n;
6058 return rc;
6059 }
6060
6061 static int expertUpdate(
6062 sqlite3_vtab *pVtab,
@@ -6311,11 +6527,11 @@
6311 if( zAppend ){
6312 nAppend = STRLEN(zAppend);
6313 zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
6314 }
6315 if( zAppend && zRet ){
6316 memcpy(zRet, zIn, nIn);
6317 memcpy(&zRet[nIn], zAppend, nAppend+1);
6318 }else{
6319 sqlite3_free(zRet);
6320 zRet = 0;
6321 *pRc = SQLITE_NOMEM;
@@ -6465,11 +6681,11 @@
6465 if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
6466 IdxTable *pTab = pScan->pTab;
6467 char *zCols = 0;
6468 char *zIdx = 0;
6469 IdxConstraint *pCons;
6470 int h = 0;
6471 const char *zFmt;
6472
6473 for(pCons=pEq; pCons; pCons=pCons->pLink){
6474 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6475 }
@@ -7080,10 +7296,11 @@
7080 zCols = idxAppendText(&rc, zCols,
7081 "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
7082 );
7083 zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
7084 }
 
7085 if( rc==SQLITE_OK ){
7086 if( p->iSample==100 ){
7087 zQuery = sqlite3_mprintf(
7088 "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
7089 );
@@ -7489,10 +7706,12 @@
7489 idxHashClear(&p->hIdx);
7490 sqlite3_free(p->zCandidates);
7491 sqlite3_free(p);
7492 }
7493 }
 
 
7494
7495 /************************* End ../ext/expert/sqlite3expert.c ********************/
7496
7497 #if defined(SQLITE_ENABLE_SESSION)
7498 /*
@@ -7535,26 +7754,31 @@
7535 u8 autoExplain; /* Automatically turn on .explain mode */
7536 u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
7537 u8 statsOn; /* True to display memory stats before each finalize */
7538 u8 scanstatsOn; /* True to display scan stats before each finalize */
7539 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
 
7540 int outCount; /* Revert to stdout when reaching zero */
7541 int cnt; /* Number of records displayed so far */
7542 FILE *out; /* Write results here */
7543 FILE *traceOut; /* Output for sqlite3_trace() */
7544 int nErr; /* Number of errors seen */
7545 int mode; /* An output mode setting */
 
7546 int cMode; /* temporary output mode for the current query */
7547 int normalMode; /* Output mode before ".explain on" */
7548 int writableSchema; /* True if PRAGMA writable_schema=ON */
7549 int showHeader; /* True to show column names in List or Column mode */
7550 int nCheck; /* Number of ".check" commands run */
7551 unsigned shellFlgs; /* Various flags */
7552 char *zDestTable; /* Name of destination table when MODE_Insert */
 
7553 char zTestcase[30]; /* Name of current test case */
7554 char colSeparator[20]; /* Column separator character for several modes */
7555 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
 
 
7556 int colWidth[100]; /* Requested width of each column when in column mode*/
7557 int actualWidth[100]; /* Actual width of each column */
7558 char nullValue[20]; /* The text to print when a NULL comes back from
7559 ** the database */
7560 char outfile[FILENAME_MAX]; /* Filename for *out */
@@ -7648,24 +7872,175 @@
7648 #define SEP_Comma ","
7649 #define SEP_CrLf "\r\n"
7650 #define SEP_Unit "\x1F"
7651 #define SEP_Record "\x1E"
7652
7653 /*
7654 ** Number of elements in an array
7655 */
7656 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
7657
7658 /*
7659 ** A callback for the sqlite3_log() interface.
7660 */
7661 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
7662 ShellState *p = (ShellState*)pArg;
7663 if( p->pLog==0 ) return;
7664 utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
7665 fflush(p->pLog);
7666 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7667
7668 /*
7669 ** Output the given string as a hex-encoded blob (eg. X'1234' )
7670 */
7671 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -8987,10 +9362,11 @@
8987 } while( rc == SQLITE_ROW );
8988 }
8989 }
8990 }
8991
 
8992 /*
8993 ** This function is called to process SQL if the previous shell command
8994 ** was ".expert". It passes the SQL in the second argument directly to
8995 ** the sqlite3expert object.
8996 **
@@ -9059,10 +9435,67 @@
9059 sqlite3_expert_destroy(p);
9060 pState->expert.pExpert = 0;
9061 return rc;
9062 }
9063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9064
9065 /*
9066 ** Execute a statement or set of statements. Print
9067 ** any result rows/columns depending on the current mode
9068 ** set via the supplied callback.
@@ -9086,14 +9519,16 @@
9086
9087 if( pzErrMsg ){
9088 *pzErrMsg = NULL;
9089 }
9090
 
9091 if( pArg->expert.pExpert ){
9092 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
9093 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
9094 }
 
9095
9096 while( zSql[0] && (SQLITE_OK == rc) ){
9097 static const char *zStmtSql;
9098 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
9099 if( SQLITE_OK != rc ){
@@ -9516,10 +9951,11 @@
9516 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
9517 " If TABLE specified, only dump tables matching\n"
9518 " LIKE pattern TABLE.\n"
9519 ".echo on|off Turn command echo on or off\n"
9520 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
 
9521 ".exit Exit this program\n"
9522 ".expert EXPERIMENTAL. Suggest indexes for specified queries\n"
9523 /* Because explain mode comes on automatically now, the ".explain" mode
9524 ** is removed from the help screen. It is still supported for legacy, however */
9525 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
@@ -9553,14 +9989,16 @@
9553 " list Values delimited by \"|\"\n"
9554 " quote Escape answers as for SQL\n"
9555 " tabs Tab-separated values\n"
9556 " tcl TCL list elements\n"
9557 ".nullvalue STRING Use STRING in place of NULL values\n"
9558 ".once FILENAME Output for the next SQL command only to FILENAME\n"
 
 
9559 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE\n"
9560 " The --new option starts with an empty file\n"
9561 ".output ?FILENAME? Send output to FILENAME or stdout\n"
9562 ".print STRING... Print literal STRING\n"
9563 ".prompt MAIN CONTINUE Replace the standard prompts\n"
9564 ".quit Exit this program\n"
9565 ".read FILENAME Execute SQL in FILENAME\n"
9566 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -9775,10 +10213,16 @@
9775 #endif
9776 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
9777 shellAddSchemaName, 0, 0);
9778 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
9779 shellModuleSchema, 0, 0);
 
 
 
 
 
 
9780 if( p->openMode==SHELL_OPEN_ZIPFILE ){
9781 char *zSql = sqlite3_mprintf(
9782 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
9783 sqlite3_exec(p->db, zSql, 0, 0, 0);
9784 sqlite3_free(zSql);
@@ -9908,67 +10352,10 @@
9908 z[j] = c;
9909 }
9910 if( j<i ) z[j] = 0;
9911 }
9912
9913 /*
9914 ** Return the value of a hexadecimal digit. Return -1 if the input
9915 ** is not a hex digit.
9916 */
9917 static int hexDigitValue(char c){
9918 if( c>='0' && c<='9' ) return c - '0';
9919 if( c>='a' && c<='f' ) return c - 'a' + 10;
9920 if( c>='A' && c<='F' ) return c - 'A' + 10;
9921 return -1;
9922 }
9923
9924 /*
9925 ** Interpret zArg as an integer value, possibly with suffixes.
9926 */
9927 static sqlite3_int64 integerValue(const char *zArg){
9928 sqlite3_int64 v = 0;
9929 static const struct { char *zSuffix; int iMult; } aMult[] = {
9930 { "KiB", 1024 },
9931 { "MiB", 1024*1024 },
9932 { "GiB", 1024*1024*1024 },
9933 { "KB", 1000 },
9934 { "MB", 1000000 },
9935 { "GB", 1000000000 },
9936 { "K", 1000 },
9937 { "M", 1000000 },
9938 { "G", 1000000000 },
9939 };
9940 int i;
9941 int isNeg = 0;
9942 if( zArg[0]=='-' ){
9943 isNeg = 1;
9944 zArg++;
9945 }else if( zArg[0]=='+' ){
9946 zArg++;
9947 }
9948 if( zArg[0]=='0' && zArg[1]=='x' ){
9949 int x;
9950 zArg += 2;
9951 while( (x = hexDigitValue(zArg[0]))>=0 ){
9952 v = (v<<4) + x;
9953 zArg++;
9954 }
9955 }else{
9956 while( IsDigit(zArg[0]) ){
9957 v = v*10 + zArg[0] - '0';
9958 zArg++;
9959 }
9960 }
9961 for(i=0; i<ArraySize(aMult); i++){
9962 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
9963 v *= aMult[i].iMult;
9964 break;
9965 }
9966 }
9967 return isNeg? -v : v;
9968 }
9969
9970 /*
9971 ** Interpret zArg as either an integer or a boolean value. Return 1 or 0
9972 ** for TRUE and FALSE. Return the integer value if appropriate.
9973 */
9974 static int booleanValue(const char *zArg){
@@ -10011,20 +10398,20 @@
10011 /*
10012 ** Try to open an output file. The names "stdout" and "stderr" are
10013 ** recognized and do the right thing. NULL is returned if the output
10014 ** filename is "off".
10015 */
10016 static FILE *output_file_open(const char *zFile){
10017 FILE *f;
10018 if( strcmp(zFile,"stdout")==0 ){
10019 f = stdout;
10020 }else if( strcmp(zFile, "stderr")==0 ){
10021 f = stderr;
10022 }else if( strcmp(zFile, "off")==0 ){
10023 f = 0;
10024 }else{
10025 f = fopen(zFile, "wb");
10026 if( f==0 ){
10027 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
10028 }
10029 }
10030 return f;
@@ -10433,19 +10820,41 @@
10433 }
10434 sqlite3_close(newDb);
10435 }
10436
10437 /*
10438 ** Change the output file back to stdout
 
 
 
 
10439 */
10440 static void output_reset(ShellState *p){
10441 if( p->outfile[0]=='|' ){
10442 #ifndef SQLITE_OMIT_POPEN
10443 pclose(p->out);
10444 #endif
10445 }else{
10446 output_file_close(p->out);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10447 }
10448 p->outfile[0] = 0;
10449 p->out = stdout;
10450 }
10451
@@ -10699,10 +11108,45 @@
10699 #else
10700 rc = unlink(zFilename);
10701 #endif
10702 return rc;
10703 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10704
10705
10706 /*
10707 ** The implementation of SQL scalar function fkey_collate_clause(), used
10708 ** by the ".lint fkey-indexes" command. This scalar function is always
@@ -11028,17 +11472,22 @@
11028 /*
11029 ** Structure representing a single ".ar" command.
11030 */
11031 typedef struct ArCommand ArCommand;
11032 struct ArCommand {
11033 int eCmd; /* An AR_CMD_* value */
 
 
 
 
 
 
11034 const char *zFile; /* --file argument, or NULL */
11035 const char *zDir; /* --directory argument, or NULL */
11036 int bVerbose; /* True if --verbose */
11037 int bZip; /* True if --zip */
11038 int nArg; /* Number of command arguments */
11039 char **azArg; /* Array of command arguments */
 
 
11040 };
11041
11042 /*
11043 ** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
11044 */
@@ -11060,11 +11509,13 @@
11060 " -x, --extract Extract files from archive\n"
11061 "\n"
11062 "And zero or more optional options:\n"
11063 " -v, --verbose Print each filename as it is processed\n"
11064 " -f FILE, --file FILE Operate on archive FILE (default is current db)\n"
 
11065 " -C DIR, --directory DIR Change to directory DIR to read/extract files\n"
 
11066 "\n"
11067 "See also: http://sqlite.org/cli.html#sqlar_archive_support\n"
11068 "\n"
11069 );
11070 return SQLITE_ERROR;
@@ -11095,14 +11546,15 @@
11095 #define AR_CMD_HELP 5
11096
11097 /*
11098 ** Other (non-command) switches.
11099 */
11100 #define AR_SWITCH_VERBOSE 6
11101 #define AR_SWITCH_FILE 7
11102 #define AR_SWITCH_DIRECTORY 8
11103 #define AR_SWITCH_ZIP 9
 
11104
11105 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
11106 switch( eSwitch ){
11107 case AR_CMD_CREATE:
11108 case AR_CMD_EXTRACT:
@@ -11113,17 +11565,19 @@
11113 return arErrorMsg("multiple command options");
11114 }
11115 pAr->eCmd = eSwitch;
11116 break;
11117
 
 
 
11118 case AR_SWITCH_VERBOSE:
11119 pAr->bVerbose = 1;
11120 break;
11121 case AR_SWITCH_ZIP:
11122 pAr->bZip = 1;
11123 break;
11124
11125 case AR_SWITCH_FILE:
11126 pAr->zFile = zArg;
11127 break;
11128 case AR_SWITCH_DIRECTORY:
11129 pAr->zDir = zArg;
@@ -11143,24 +11597,25 @@
11143 char **azArg, /* Array of arguments passed to dot command */
11144 int nArg, /* Number of entries in azArg[] */
11145 ArCommand *pAr /* Populate this object */
11146 ){
11147 struct ArSwitch {
11148 char cShort;
11149 const char *zLong;
11150 int eSwitch;
11151 int bArg;
 
11152 } aSwitch[] = {
11153 { 'c', "create", AR_CMD_CREATE, 0 },
11154 { 'x', "extract", AR_CMD_EXTRACT, 0 },
11155 { 't', "list", AR_CMD_LIST, 0 },
11156 { 'u', "update", AR_CMD_UPDATE, 0 },
11157 { 'h', "help", AR_CMD_HELP, 0 },
11158 { 'v', "verbose", AR_SWITCH_VERBOSE, 0 },
11159 { 'f', "file", AR_SWITCH_FILE, 1 },
11160 { 'C', "directory", AR_SWITCH_DIRECTORY, 1 },
11161 { 'z', "zip", AR_SWITCH_ZIP, 0 }
 
11162 };
11163 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
11164 struct ArSwitch *pEnd = &aSwitch[nSwitch];
11165
11166 if( nArg<=1 ){
@@ -11283,41 +11738,39 @@
11283 **
11284 ** This function strips any trailing '/' characters from each argument.
11285 ** This is consistent with the way the [tar] command seems to work on
11286 ** Linux.
11287 */
11288 static int arCheckEntries(sqlite3 *db, ArCommand *pAr){
11289 int rc = SQLITE_OK;
11290 if( pAr->nArg ){
11291 int i;
11292 sqlite3_stmt *pTest = 0;
11293
11294 shellPreparePrintf(db, &rc, &pTest, "SELECT name FROM %s WHERE name=?1",
11295 pAr->bZip ? "zipfile(?2)" : "sqlar"
 
11296 );
11297 if( rc==SQLITE_OK && pAr->bZip ){
11298 sqlite3_bind_text(pTest, 2, pAr->zFile, -1, SQLITE_TRANSIENT);
11299 }
11300 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11301 char *z = pAr->azArg[i];
11302 int n = strlen30(z);
11303 int bOk = 0;
11304 while( n>0 && z[n-1]=='/' ) n--;
11305 z[n] = '\0';
11306 sqlite3_bind_text(pTest, 1, z, -1, SQLITE_STATIC);
11307 if( SQLITE_ROW==sqlite3_step(pTest) ){
11308 bOk = 1;
11309 }
11310 shellReset(&rc, pTest);
11311 if( rc==SQLITE_OK && bOk==0 ){
11312 raw_printf(stderr, "not found in archive: %s\n", z);
11313 rc = SQLITE_ERROR;
11314 }
11315 }
11316 shellFinalize(&rc, pTest);
11317 }
11318
11319 return rc;
11320 }
11321
11322 /*
11323 ** Format a WHERE clause that can be used against the "sqlar" table to
@@ -11339,13 +11792,13 @@
11339 int i;
11340 const char *zSep = "";
11341 for(i=0; i<pAr->nArg; i++){
11342 const char *z = pAr->azArg[i];
11343 zWhere = sqlite3_mprintf(
11344 "%z%s name = '%q' OR name BETWEEN '%q/' AND '%q0'",
11345 zWhere, zSep, z, z, z
11346 );
11347 if( zWhere==0 ){
11348 *pRc = SQLITE_NOMEM;
11349 break;
11350 }
11351 zSep = " OR ";
@@ -11353,109 +11806,75 @@
11353 }
11354 }
11355 *pzWhere = zWhere;
11356 }
11357
11358 /*
11359 ** Argument zMode must point to a buffer at least 11 bytes in size. This
11360 ** function populates this buffer with the string interpretation of
11361 ** the unix file mode passed as the second argument (e.g. "drwxr-xr-x").
11362 */
11363 static void shellModeToString(char *zMode, int mode){
11364 int i;
11365
11366 /* Magic numbers copied from [man 2 stat] */
11367 if( mode & 0040000 ){
11368 zMode[0] = 'd';
11369 }else if( (mode & 0120000)==0120000 ){
11370 zMode[0] = 'l';
11371 }else{
11372 zMode[0] = '-';
11373 }
11374
11375 for(i=0; i<3; i++){
11376 int m = (mode >> ((2-i)*3));
11377 char *a = &zMode[1 + i*3];
11378 a[0] = (m & 0x4) ? 'r' : '-';
11379 a[1] = (m & 0x2) ? 'w' : '-';
11380 a[2] = (m & 0x1) ? 'x' : '-';
11381 }
11382 zMode[10] = '\0';
11383 }
11384
11385 /*
11386 ** Implementation of .ar "lisT" command.
11387 */
11388 static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11389 const char *zSql = "SELECT %s FROM %s WHERE %s";
11390 const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar");
11391 const char *azCols[] = {
11392 "name",
11393 "mode, sz, datetime(mtime, 'unixepoch'), name"
11394 };
11395
11396 char *zWhere = 0;
11397 sqlite3_stmt *pSql = 0;
11398 int rc;
11399
11400 rc = arCheckEntries(db, pAr);
11401 arWhereClause(&rc, pAr, &zWhere);
11402
11403 shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere);
11404 if( rc==SQLITE_OK && pAr->bZip ){
11405 sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT);
11406 }
11407 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11408 if( pAr->bVerbose ){
11409 char zMode[11];
11410 shellModeToString(zMode, sqlite3_column_int(pSql, 0));
11411
11412 raw_printf(p->out, "%s % 10d %s %s\n", zMode,
11413 sqlite3_column_int(pSql, 1),
11414 sqlite3_column_text(pSql, 2),
11415 sqlite3_column_text(pSql, 3)
11416 );
11417 }else{
11418 raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11419 }
11420 }
11421
11422 shellFinalize(&rc, pSql);
11423 return rc;
11424 }
11425
11426
11427 /*
11428 ** Implementation of .ar "eXtract" command.
11429 */
11430 static int arExtractCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11431 const char *zSql1 =
11432 "SELECT "
11433 " :1 || name, "
11434 " writefile(?1 || name, %s, mode, mtime) "
11435 "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";
11436
11437 const char *azExtraArg[] = {
11438 "sqlar_uncompress(data, sz)",
11439 "zipfile_uncompress(data, sz, method)"
11440 };
11441 const char *azSource[] = {
11442 "sqlar", "zipfile(?3)"
11443 };
11444
11445
11446
11447 sqlite3_stmt *pSql = 0;
11448 int rc = SQLITE_OK;
11449 char *zDir = 0;
11450 char *zWhere = 0;
11451 int i;
11452
11453 /* If arguments are specified, check that they actually exist within
11454 ** the archive before proceeding. And formulate a WHERE clause to
11455 ** match them. */
11456 rc = arCheckEntries(db, pAr);
11457 arWhereClause(&rc, pAr, &zWhere);
11458
11459 if( rc==SQLITE_OK ){
11460 if( pAr->zDir ){
11461 zDir = sqlite3_mprintf("%s/", pAr->zDir);
@@ -11463,30 +11882,33 @@
11463 zDir = sqlite3_mprintf("");
11464 }
11465 if( zDir==0 ) rc = SQLITE_NOMEM;
11466 }
11467
11468 shellPreparePrintf(db, &rc, &pSql, zSql1,
11469 azExtraArg[pAr->bZip], azSource[pAr->bZip], zWhere
11470 );
11471
11472 if( rc==SQLITE_OK ){
11473 sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC);
11474 if( pAr->bZip ){
11475 sqlite3_bind_text(pSql, 3, pAr->zFile, -1, SQLITE_STATIC);
11476 }
11477
11478 /* Run the SELECT statement twice. The first time, writefile() is called
11479 ** for all archive members that should be extracted. The second time,
11480 ** only for the directories. This is because the timestamps for
11481 ** extracted directories must be reset after they are populated (as
11482 ** populating them changes the timestamp). */
11483 for(i=0; i<2; i++){
11484 sqlite3_bind_int(pSql, 2, i);
11485 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11486 if( i==0 && pAr->bVerbose ){
11487 raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
 
 
 
 
 
11488 }
11489 }
11490 shellReset(&rc, pSql);
11491 }
11492 shellFinalize(&rc, pSql);
@@ -11494,10 +11916,29 @@
11494
11495 sqlite3_free(zDir);
11496 sqlite3_free(zWhere);
11497 return rc;
11498 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11499
11500
11501 /*
11502 ** Implementation of .ar "create" and "update" commands.
11503 **
@@ -11507,116 +11948,60 @@
11507 ** printed on stdout for each file archived.
11508 **
11509 ** The create command is the same as update, except that it drops
11510 ** any existing "sqlar" table before beginning.
11511 */
11512 static int arCreateUpdate(
11513 ShellState *p, /* Shell state pointer */
11514 sqlite3 *db,
11515 ArCommand *pAr, /* Command arguments and options */
11516 int bUpdate
11517 ){
11518 const char *zSql = "SELECT name, mode, mtime, data FROM fsdir(?, ?)";
11519 const char *zCreate =
11520 "CREATE TABLE IF NOT EXISTS sqlar(\n"
11521 " name TEXT PRIMARY KEY, -- name of the file\n"
11522 " mode INT, -- access permissions\n"
11523 " mtime INT, -- last modification time\n"
11524 " sz INT, -- original file size\n"
11525 " data BLOB -- compressed content\n"
11526 ")";
11527 const char *zDrop = "DROP TABLE IF EXISTS sqlar";
11528 const char *zInsert = "REPLACE INTO sqlar VALUES(?,?,?,?,sqlar_compress(?))";
11529
11530 sqlite3_stmt *pStmt = 0; /* Directory traverser */
11531 sqlite3_stmt *pInsert = 0; /* Compilation of zInsert */
 
 
 
 
 
 
 
 
 
11532 int i; /* For iterating through azFile[] */
11533 int rc; /* Return code */
11534
11535 assert( pAr->bZip==0 );
11536
11537 rc = sqlite3_exec(db, "SAVEPOINT ar;", 0, 0, 0);
11538 if( rc!=SQLITE_OK ) return rc;
11539
11540 if( bUpdate==0 ){
11541 rc = sqlite3_exec(db, zDrop, 0, 0, 0);
11542 if( rc!=SQLITE_OK ) return rc;
11543 }
11544
11545 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
11546 shellPrepare(db, &rc, zInsert, &pInsert);
11547 shellPrepare(db, &rc, zSql, &pStmt);
11548 sqlite3_bind_text(pStmt, 2, pAr->zDir, -1, SQLITE_STATIC);
11549
11550 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11551 sqlite3_bind_text(pStmt, 1, pAr->azArg[i], -1, SQLITE_STATIC);
11552 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
11553 int sz;
11554 const char *zName = (const char*)sqlite3_column_text(pStmt, 0);
11555 int mode = sqlite3_column_int(pStmt, 1);
11556 unsigned int mtime = sqlite3_column_int(pStmt, 2);
11557
11558 if( pAr->bVerbose ){
11559 raw_printf(p->out, "%s\n", zName);
11560 }
11561
11562 sqlite3_bind_text(pInsert, 1, zName, -1, SQLITE_STATIC);
11563 sqlite3_bind_int(pInsert, 2, mode);
11564 sqlite3_bind_int64(pInsert, 3, (sqlite3_int64)mtime);
11565
11566 if( S_ISDIR(mode) ){
11567 sz = 0;
11568 sqlite3_bind_null(pInsert, 5);
11569 }else{
11570 sqlite3_bind_value(pInsert, 5, sqlite3_column_value(pStmt, 3));
11571 if( S_ISLNK(mode) ){
11572 sz = -1;
11573 }else{
11574 sz = sqlite3_column_bytes(pStmt, 3);
11575 }
11576 }
11577
11578 sqlite3_bind_int(pInsert, 4, sz);
11579 sqlite3_step(pInsert);
11580 rc = sqlite3_reset(pInsert);
11581 }
11582 shellReset(&rc, pStmt);
11583 }
11584
11585 if( rc!=SQLITE_OK ){
11586 sqlite3_exec(db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
11587 }else{
11588 rc = sqlite3_exec(db, "RELEASE ar;", 0, 0, 0);
11589 }
11590 shellFinalize(&rc, pStmt);
11591 shellFinalize(&rc, pInsert);
11592 return rc;
11593 }
11594
11595 /*
11596 ** Implementation of .ar "Create" command.
11597 **
11598 ** Create the "sqlar" table in the database if it does not already exist.
11599 ** Then add each file in the azFile[] array to the archive. Directories
11600 ** are added recursively. If argument bVerbose is non-zero, a message is
11601 ** printed on stdout for each file archived.
11602 */
11603 static int arCreateCommand(
11604 ShellState *p, /* Shell state pointer */
11605 sqlite3 *db,
11606 ArCommand *pAr /* Command arguments and options */
11607 ){
11608 return arCreateUpdate(p, db, pAr, 0);
11609 }
11610
11611 /*
11612 ** Implementation of .ar "Update" command.
11613 */
11614 static int arUpdateCmd(ShellState *p, sqlite3 *db, ArCommand *pAr){
11615 return arCreateUpdate(p, db, pAr, 1);
11616 }
11617
11618
11619 /*
11620 ** Implementation of ".ar" dot command.
11621 */
11622 static int arDotCommand(
@@ -11624,138 +12009,108 @@
11624 char **azArg, /* Array of arguments passed to dot command */
11625 int nArg /* Number of entries in azArg[] */
11626 ){
11627 ArCommand cmd;
11628 int rc;
 
11629 rc = arParseCommand(azArg, nArg, &cmd);
11630 if( rc==SQLITE_OK ){
11631 sqlite3 *db = 0; /* Database handle to use as archive */
11632
11633 if( cmd.bZip ){
 
 
 
 
 
 
11634 if( cmd.zFile==0 ){
11635 raw_printf(stderr, "zip format requires a --file switch\n");
11636 return SQLITE_ERROR;
11637 }else
 
11638 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11639 raw_printf(stderr, "zip archives are read-only\n");
11640 return SQLITE_ERROR;
 
11641 }
11642 db = pState->db;
11643 }else if( cmd.zFile ){
11644 int flags;
 
11645 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11646 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
11647 }else{
11648 flags = SQLITE_OPEN_READONLY;
11649 }
11650 rc = sqlite3_open_v2(cmd.zFile, &db, flags, 0);
 
 
 
 
 
 
11651 if( rc!=SQLITE_OK ){
11652 raw_printf(stderr, "cannot open file: %s (%s)\n",
11653 cmd.zFile, sqlite3_errmsg(db)
11654 );
11655 sqlite3_close(db);
11656 return rc;
11657 }
11658 sqlite3_fileio_init(db, 0, 0);
11659 #ifdef SQLITE_HAVE_ZLIB
11660 sqlite3_sqlar_init(db, 0, 0);
11661 #endif
11662 }else{
11663 db = pState->db;
 
 
 
 
 
 
 
 
 
 
 
11664 }
11665
11666 switch( cmd.eCmd ){
11667 case AR_CMD_CREATE:
11668 rc = arCreateCommand(pState, db, &cmd);
11669 break;
11670
11671 case AR_CMD_EXTRACT:
11672 rc = arExtractCommand(pState, db, &cmd);
11673 break;
11674
11675 case AR_CMD_LIST:
11676 rc = arListCommand(pState, db, &cmd);
11677 break;
11678
11679 case AR_CMD_HELP:
11680 arUsage(pState->out);
11681 break;
11682
11683 default:
11684 assert( cmd.eCmd==AR_CMD_UPDATE );
11685 rc = arUpdateCmd(pState, db, &cmd);
11686 break;
11687 }
11688
11689 if( cmd.zFile ){
11690 sqlite3_close(db);
11691 }
11692 }
 
11693
11694 return rc;
11695 }
11696 /* End of the ".archive" or ".ar" command logic
11697 **********************************************************************************/
11698 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
11699
11700 /*
11701 ** Implementation of ".expert" dot command.
11702 */
11703 static int expertDotCommand(
11704 ShellState *pState, /* Current shell tool state */
11705 char **azArg, /* Array of arguments passed to dot command */
11706 int nArg /* Number of entries in azArg[] */
11707 ){
11708 int rc = SQLITE_OK;
11709 char *zErr = 0;
11710 int i;
11711 int iSample = 0;
11712
11713 assert( pState->expert.pExpert==0 );
11714 memset(&pState->expert, 0, sizeof(ExpertInfo));
11715
11716 for(i=1; rc==SQLITE_OK && i<nArg; i++){
11717 char *z = azArg[i];
11718 int n;
11719 if( z[0]=='-' && z[1]=='-' ) z++;
11720 n = strlen30(z);
11721 if( n>=2 && 0==strncmp(z, "-verbose", n) ){
11722 pState->expert.bVerbose = 1;
11723 }
11724 else if( n>=2 && 0==strncmp(z, "-sample", n) ){
11725 if( i==(nArg-1) ){
11726 raw_printf(stderr, "option requires an argument: %s\n", z);
11727 rc = SQLITE_ERROR;
11728 }else{
11729 iSample = (int)integerValue(azArg[++i]);
11730 if( iSample<0 || iSample>100 ){
11731 raw_printf(stderr, "value out of range: %s\n", azArg[i]);
11732 rc = SQLITE_ERROR;
11733 }
11734 }
11735 }
11736 else{
11737 raw_printf(stderr, "unknown option: %s\n", z);
11738 rc = SQLITE_ERROR;
11739 }
11740 }
11741
11742 if( rc==SQLITE_OK ){
11743 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
11744 if( pState->expert.pExpert==0 ){
11745 raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
11746 rc = SQLITE_ERROR;
11747 }else{
11748 sqlite3_expert_config(
11749 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
11750 );
11751 }
11752 }
11753
11754 return rc;
11755 }
11756
11757
11758 /*
11759 ** If an input line begins with "." then invoke this routine to
11760 ** process that line.
11761 **
@@ -11766,13 +12121,15 @@
11766 int nArg = 0;
11767 int n, c;
11768 int rc = 0;
11769 char *azArg[50];
11770
 
11771 if( p->expert.pExpert ){
11772 expertFinish(p, 1, 0);
11773 }
 
11774
11775 /* Parse the input line into tokens.
11776 */
11777 while( zLine[h] && nArg<ArraySize(azArg) ){
11778 while( IsSpace(zLine[h]) ){ h++; }
@@ -11799,10 +12156,11 @@
11799 /* Process the input line.
11800 */
11801 if( nArg==0 ) return 0; /* no tokens, no error */
11802 n = strlen30(azArg[0]);
11803 c = azArg[0][0];
 
11804
11805 #ifndef SQLITE_OMIT_AUTHORIZATION
11806 if( c=='a' && strncmp(azArg[0], "auth", n)==0 ){
11807 if( nArg!=2 ){
11808 raw_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -12133,14 +12491,16 @@
12133 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
12134 p->autoExplain = 1;
12135 }
12136 }else
12137
 
12138 if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
12139 open_db(p, 0);
12140 expertDotCommand(p, azArg, nArg);
12141 }else
 
12142
12143 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
12144 ShellState data;
12145 char *zErrMsg = 0;
12146 int doStats = 0;
@@ -12592,11 +12952,11 @@
12592 raw_printf(stderr, "Usage: .log FILENAME\n");
12593 rc = 1;
12594 }else{
12595 const char *zFile = azArg[1];
12596 output_file_close(p->pLog);
12597 p->pLog = output_file_open(zFile);
12598 }
12599 }else
12600
12601 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
12602 const char *zMode = nArg>=2 ? azArg[1] : "";
@@ -12701,30 +13061,54 @@
12701 p->zDbFilename = 0;
12702 open_db(p, 0);
12703 }
12704 }else
12705
12706 if( c=='o'
12707 && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
 
12708 ){
12709 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
 
 
 
 
 
 
 
 
12710 if( nArg>2 ){
12711 utf8_printf(stderr, "Usage: .%s FILE\n", azArg[0]);
12712 rc = 1;
12713 goto meta_command_exit;
12714 }
12715 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
12716 if( nArg<2 ){
12717 raw_printf(stderr, "Usage: .once FILE\n");
12718 rc = 1;
12719 goto meta_command_exit;
12720 }
12721 p->outCount = 2;
12722 }else{
12723 p->outCount = 0;
12724 }
12725 output_reset(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12726 if( zFile[0]=='|' ){
12727 #ifdef SQLITE_OMIT_POPEN
12728 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
12729 rc = 1;
12730 p->out = stdout;
@@ -12737,11 +13121,11 @@
12737 }else{
12738 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
12739 }
12740 #endif
12741 }else{
12742 p->out = output_file_open(zFile);
12743 if( p->out==0 ){
12744 if( strcmp(zFile,"off")!=0 ){
12745 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
12746 }
12747 p->out = stdout;
@@ -13614,11 +13998,11 @@
13614 }else
13615
13616 /* Begin redirecting output to the file "testcase-out.txt" */
13617 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
13618 output_reset(p);
13619 p->out = output_file_open("testcase-out.txt");
13620 if( p->out==0 ){
13621 raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
13622 }
13623 if( nArg>=2 ){
13624 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -13820,11 +14204,11 @@
13820 raw_printf(stderr, "Usage: .trace FILE|off\n");
13821 rc = 1;
13822 goto meta_command_exit;
13823 }
13824 output_file_close(p->traceOut);
13825 p->traceOut = output_file_open(azArg[1]);
13826 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
13827 if( p->traceOut==0 ){
13828 sqlite3_trace_v2(p->db, 0, 0, 0);
13829 }else{
13830 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
@@ -14150,10 +14534,12 @@
14150 errCnt += runOneSqlLine(p, zSql, in, startline);
14151 nSql = 0;
14152 if( p->outCount ){
14153 output_reset(p);
14154 p->outCount = 0;
 
 
14155 }
14156 }else if( nSql && _all_whitespace(zSql) ){
14157 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
14158 nSql = 0;
14159 }
@@ -14772,11 +15158,14 @@
14772 session_close_all(&data);
14773 sqlite3_close(data.db);
14774 }
14775 sqlite3_free(data.zFreeOnClose);
14776 find_home_dir(1);
 
 
 
14777 #if !SQLITE_SHELL_IS_UTF8
14778 for(i=0; i<argc; i++) sqlite3_free(argv[i]);
14779 sqlite3_free(argv);
14780 #endif
14781 return rc;
14782 }
14783
--- src/shell.c
+++ src/shell.c
@@ -92,14 +92,14 @@
92 # include <signal.h>
93 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
94 # include <pwd.h>
95 # endif
96 #endif
97 #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__)
98 # include <unistd.h>
99 # include <dirent.h>
100 # if defined(__MINGW32__)
101 # define DIRENT dirent
102 # ifndef S_ISLNK
103 # define S_ISLNK(mode) (0)
104 # endif
105 # endif
@@ -368,10 +368,15 @@
368 /*
369 ** Used to prevent warnings about unused parameters
370 */
371 #define UNUSED_PARAMETER(x) (void)(x)
372
373 /*
374 ** Number of elements in an array
375 */
376 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
377
378 /*
379 ** If the following flag is set, then command execution stops
380 ** at an error if we are not interactive.
381 */
382 static int bail_on_error = 0;
@@ -640,10 +645,69 @@
645 if( zResult && *zResult ) shell_add_history(zResult);
646 #endif
647 }
648 return zResult;
649 }
650
651
652 /*
653 ** Return the value of a hexadecimal digit. Return -1 if the input
654 ** is not a hex digit.
655 */
656 static int hexDigitValue(char c){
657 if( c>='0' && c<='9' ) return c - '0';
658 if( c>='a' && c<='f' ) return c - 'a' + 10;
659 if( c>='A' && c<='F' ) return c - 'A' + 10;
660 return -1;
661 }
662
663 /*
664 ** Interpret zArg as an integer value, possibly with suffixes.
665 */
666 static sqlite3_int64 integerValue(const char *zArg){
667 sqlite3_int64 v = 0;
668 static const struct { char *zSuffix; int iMult; } aMult[] = {
669 { "KiB", 1024 },
670 { "MiB", 1024*1024 },
671 { "GiB", 1024*1024*1024 },
672 { "KB", 1000 },
673 { "MB", 1000000 },
674 { "GB", 1000000000 },
675 { "K", 1000 },
676 { "M", 1000000 },
677 { "G", 1000000000 },
678 };
679 int i;
680 int isNeg = 0;
681 if( zArg[0]=='-' ){
682 isNeg = 1;
683 zArg++;
684 }else if( zArg[0]=='+' ){
685 zArg++;
686 }
687 if( zArg[0]=='0' && zArg[1]=='x' ){
688 int x;
689 zArg += 2;
690 while( (x = hexDigitValue(zArg[0]))>=0 ){
691 v = (v<<4) + x;
692 zArg++;
693 }
694 }else{
695 while( IsDigit(zArg[0]) ){
696 v = v*10 + zArg[0] - '0';
697 zArg++;
698 }
699 }
700 for(i=0; i<ArraySize(aMult); i++){
701 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
702 v *= aMult[i].iMult;
703 break;
704 }
705 }
706 return isNeg? -v : v;
707 }
708
709 /*
710 ** A variable length string to which one can append text.
711 */
712 typedef struct ShellText ShellText;
713 struct ShellText {
@@ -818,12 +882,13 @@
882 sqlite3_value **apVal
883 ){
884 const char *zName = (const char*)sqlite3_value_text(apVal[0]);
885 char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
886 if( zFake ){
887 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
888 -1, sqlite3_free);
889 free(zFake);
890 }
891 }
892
893 /*
894 ** SQL function: shell_add_schema(S,X)
@@ -879,14 +944,15 @@
944 if( zName
945 && aPrefix[i][0]=='V'
946 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
947 ){
948 if( z==0 ){
949 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
950 }else{
951 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
952 }
953 free(zFake);
954 }
955 if( z ){
956 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
957 return;
958 }
@@ -2068,14 +2134,15 @@
2134 # include "windows.h"
2135 # include <io.h>
2136 # include <direct.h>
2137 /* # include "test_windirent.h" */
2138 # define dirent DIRENT
2139 # ifndef stat
2140 # define stat _stat
2141 # endif
2142 # define mkdir(path,mode) _mkdir(path)
2143 # define lstat(path,buf) stat(path,buf)
2144 #endif
2145 #include <time.h>
2146 #include <errno.h>
2147
2148
@@ -2331,10 +2398,44 @@
2398 }else{
2399 ctxErrorMsg(context, "failed to write file: %s", zFile);
2400 }
2401 }
2402 }
2403
2404 /*
2405 ** SQL function: lsmode(MODE)
2406 **
2407 ** Given a numberic st_mode from stat(), convert it into a human-readable
2408 ** text string in the style of "ls -l".
2409 */
2410 static void lsModeFunc(
2411 sqlite3_context *context,
2412 int argc,
2413 sqlite3_value **argv
2414 ){
2415 int i;
2416 int iMode = sqlite3_value_int(argv[0]);
2417 char z[16];
2418 if( S_ISLNK(iMode) ){
2419 z[0] = 'l';
2420 }else if( S_ISREG(iMode) ){
2421 z[0] = '-';
2422 }else if( S_ISDIR(iMode) ){
2423 z[0] = 'd';
2424 }else{
2425 z[0] = '?';
2426 }
2427 for(i=0; i<3; i++){
2428 int m = (iMode >> ((2-i)*3));
2429 char *a = &z[1 + i*3];
2430 a[0] = (m & 0x4) ? 'r' : '-';
2431 a[1] = (m & 0x2) ? 'w' : '-';
2432 a[2] = (m & 0x1) ? 'x' : '-';
2433 }
2434 z[10] = '\0';
2435 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
2436 }
2437
2438 #ifndef SQLITE_OMIT_VIRTUALTABLE
2439
2440 /*
2441 ** Cursor type for recursively iterating through a directory structure.
@@ -2743,10 +2844,14 @@
2844 readfileFunc, 0, 0);
2845 if( rc==SQLITE_OK ){
2846 rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
2847 writefileFunc, 0, 0);
2848 }
2849 if( rc==SQLITE_OK ){
2850 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
2851 lsModeFunc, 0, 0);
2852 }
2853 if( rc==SQLITE_OK ){
2854 rc = fsdirRegister(db);
2855 }
2856 return rc;
2857 }
@@ -3885,21 +3990,22 @@
3990 typedef unsigned short u16;
3991 typedef unsigned long u32;
3992 #define MIN(a,b) ((a)<(b) ? (a) : (b))
3993 #endif
3994
3995 #define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3996 "name, /* 0: Name of file in zip archive */" \
3997 "mode, /* 1: POSIX mode for file */" \
3998 "mtime, /* 2: Last modification time in seconds since epoch */" \
3999 "sz, /* 3: Size of object */" \
4000 "rawdata, /* 4: Raw data */" \
4001 "data, /* 5: Uncompressed data */" \
4002 "method, /* 6: Compression method (integer) */" \
4003 "file HIDDEN /* Name of zip file */" \
4004 ");"
4005
4006 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "f" in the above */
4007 #define ZIPFILE_BUFFER_SIZE (64*1024)
4008
4009
4010 /*
4011 ** Magic numbers used to read and write zip files.
@@ -4513,10 +4619,84 @@
4619 pCds->mDate = (u16)(
4620 (res.tm_mday-1) +
4621 ((res.tm_mon+1) << 5) +
4622 ((res.tm_year-80) << 9));
4623 }
4624
4625 static void zipfileInflate(
4626 sqlite3_context *pCtx, /* Store error here, if any */
4627 const u8 *aIn, /* Compressed data */
4628 int nIn, /* Size of buffer aIn[] in bytes */
4629 int nOut /* Expected output size */
4630 ){
4631 u8 *aRes = sqlite3_malloc(nOut);
4632 if( aRes==0 ){
4633 sqlite3_result_error_nomem(pCtx);
4634 }else{
4635 int err;
4636 z_stream str;
4637 memset(&str, 0, sizeof(str));
4638
4639 str.next_in = (Byte*)aIn;
4640 str.avail_in = nIn;
4641 str.next_out = (Byte*)aRes;
4642 str.avail_out = nOut;
4643
4644 err = inflateInit2(&str, -15);
4645 if( err!=Z_OK ){
4646 zipfileCtxErrorMsg(pCtx, "inflateInit2() failed (%d)", err);
4647 }else{
4648 err = inflate(&str, Z_NO_FLUSH);
4649 if( err!=Z_STREAM_END ){
4650 zipfileCtxErrorMsg(pCtx, "inflate() failed (%d)", err);
4651 }else{
4652 sqlite3_result_blob(pCtx, aRes, nOut, SQLITE_TRANSIENT);
4653 }
4654 }
4655 sqlite3_free(aRes);
4656 inflateEnd(&str);
4657 }
4658 }
4659
4660 static int zipfileDeflate(
4661 ZipfileTab *pTab, /* Set error message here */
4662 const u8 *aIn, int nIn, /* Input */
4663 u8 **ppOut, int *pnOut /* Output */
4664 ){
4665 int nAlloc = (int)compressBound(nIn);
4666 u8 *aOut;
4667 int rc = SQLITE_OK;
4668
4669 aOut = (u8*)sqlite3_malloc(nAlloc);
4670 if( aOut==0 ){
4671 rc = SQLITE_NOMEM;
4672 }else{
4673 int res;
4674 z_stream str;
4675 memset(&str, 0, sizeof(str));
4676 str.next_in = (z_const Bytef*)aIn;
4677 str.avail_in = nIn;
4678 str.next_out = aOut;
4679 str.avail_out = nAlloc;
4680
4681 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
4682 res = deflate(&str, Z_FINISH);
4683
4684 if( res==Z_STREAM_END ){
4685 *ppOut = aOut;
4686 *pnOut = (int)str.total_out;
4687 }else{
4688 sqlite3_free(aOut);
4689 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
4690 rc = SQLITE_ERROR;
4691 }
4692 deflateEnd(&str);
4693 }
4694
4695 return rc;
4696 }
4697
4698
4699 /*
4700 ** Return values of columns for the row at which the series_cursor
4701 ** is currently pointing.
4702 */
@@ -4546,30 +4726,37 @@
4726 }
4727 case 3: { /* sz */
4728 sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4729 break;
4730 }
4731 case 4: /* rawdata */
4732 case 5: { /* data */
4733 if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
4734 int sz = pCsr->cds.szCompressed;
4735 if( sz>0 ){
4736 u8 *aBuf = sqlite3_malloc(sz);
4737 if( aBuf==0 ){
4738 rc = SQLITE_NOMEM;
4739 }else{
4740 FILE *pFile = zipfileGetFd(pCsr);
4741 rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4742 &pCsr->base.pVtab->zErrMsg
4743 );
4744 }
4745 if( rc==SQLITE_OK ){
4746 if( i==5 && pCsr->cds.iCompression ){
4747 zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed);
4748 }else{
4749 sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4750 }
4751 sqlite3_free(aBuf);
4752 }
4753 }
4754 }
4755 break;
4756 }
4757 case 6: /* method */
4758 sqlite3_result_int(ctx, pCsr->cds.iCompression);
4759 break;
4760 }
4761
4762 return SQLITE_OK;
@@ -4794,11 +4981,11 @@
4981 if( pNew==0 ){
4982 rc = SQLITE_NOMEM;
4983 }else{
4984 memset(pNew, 0, sizeof(ZipfileEntry));
4985 pNew->zPath = (char*)&pNew[1];
4986 memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
4987 pNew->zPath[nFile] = '\0';
4988 pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
4989 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4990 memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4991 zipfileAddEntry(pTab, pNew);
@@ -4913,15 +5100,22 @@
5100 }
5101
5102 return rc;
5103 }
5104
5105 static int zipfileGetMode(
5106 ZipfileTab *pTab,
5107 sqlite3_value *pVal,
5108 u32 defaultMode, /* Value to use if pVal IS NULL */
5109 u32 *pMode
5110 ){
5111 const char *z = (const char*)sqlite3_value_text(pVal);
5112 u32 mode = 0;
5113 if( z==0 ){
5114 mode = defaultMode;
5115 }else if( z[0]>=0 && z[0]<=9 ){
5116 mode = (unsigned int)sqlite3_value_int(pVal);
5117 }else{
5118 const char zTemplate[11] = "-rwxrwxrwx";
5119 int i;
5120 if( strlen(z)!=10 ) goto parse_error;
5121 switch( z[0] ){
@@ -4942,10 +5136,22 @@
5136
5137 parse_error:
5138 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: parse error in mode: %s", z);
5139 return SQLITE_ERROR;
5140 }
5141
5142 /*
5143 ** Both (const char*) arguments point to nul-terminated strings. Argument
5144 ** nB is the value of strlen(zB). This function returns 0 if the strings are
5145 ** identical, ignoring any trailing '/' character in either path. */
5146 static int zipfileComparePath(const char *zA, const char *zB, int nB){
5147 int nA = (int)strlen(zA);
5148 if( zA[nA-1]=='/' ) nA--;
5149 if( zB[nB-1]=='/' ) nB--;
5150 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
5151 return 1;
5152 }
5153
5154 /*
5155 ** xUpdate method.
5156 */
5157 static int zipfileUpdate(
@@ -4956,79 +5162,138 @@
5162 ){
5163 ZipfileTab *pTab = (ZipfileTab*)pVtab;
5164 int rc = SQLITE_OK; /* Return Code */
5165 ZipfileEntry *pNew = 0; /* New in-memory CDS entry */
5166
5167 u32 mode = 0; /* Mode for new entry */
5168 i64 mTime = 0; /* Modification time for new entry */
5169 i64 sz = 0; /* Uncompressed size */
5170 const char *zPath = 0; /* Path for new entry */
5171 int nPath = 0; /* strlen(zPath) */
5172 const u8 *pData = 0; /* Pointer to buffer containing content */
5173 int nData = 0; /* Size of pData buffer in bytes */
5174 int iMethod = 0; /* Compression method for new entry */
5175 u8 *pFree = 0; /* Free this */
5176 char *zFree = 0; /* Also free this */
5177 ZipfileCDS cds; /* New Central Directory Structure entry */
5178
5179 int bIsDir = 0;
5180
5181 int mNull;
5182
5183 assert( pTab->zFile );
5184 assert( pTab->pWriteFd );
5185
5186 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5187 if( nVal>1 ){
5188 return SQLITE_CONSTRAINT;
5189 }else{
5190 i64 iDelete = sqlite3_value_int64(apVal[0]);
5191 ZipfileEntry *p;
5192 for(p=pTab->pFirstEntry; p; p=p->pNext){
5193 if( p->iRowid==iDelete ){
5194 p->bDeleted = 1;
5195 break;
5196 }
5197 }
5198 return SQLITE_OK;
5199 }
5200 }
5201
5202 mNull = (sqlite3_value_type(apVal[5])==SQLITE_NULL ? 0x0 : 0x8) /* sz */
5203 + (sqlite3_value_type(apVal[6])==SQLITE_NULL ? 0x0 : 0x4) /* rawdata */
5204 + (sqlite3_value_type(apVal[7])==SQLITE_NULL ? 0x0 : 0x2) /* data */
5205 + (sqlite3_value_type(apVal[8])==SQLITE_NULL ? 0x0 : 0x1); /* method */
5206 if( mNull==0x00 ){
5207 /* All four are NULL - this must be a directory */
5208 bIsDir = 1;
5209 }
5210 else if( mNull==0x2 || mNull==0x3 ){
5211 /* Value specified for "data", and possibly "method". This must be
5212 ** a regular file or a symlink. */
5213 const u8 *aIn = sqlite3_value_blob(apVal[7]);
5214 int nIn = sqlite3_value_bytes(apVal[7]);
5215 int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
5216
5217 iMethod = sqlite3_value_int(apVal[8]);
5218 sz = nIn;
5219 if( iMethod!=0 && iMethod!=8 ){
5220 rc = SQLITE_CONSTRAINT;
5221 }else if( bAuto || iMethod ){
5222 rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData);
5223 if( rc==SQLITE_OK ){
5224 if( iMethod || nData<nIn ){
5225 iMethod = 8;
5226 pData = pFree;
5227 }else{
5228 pData = aIn;
5229 nData = nIn;
5230 }
5231 }
5232 }
5233 }
5234 else if( mNull==0x0D ){
5235 /* Values specified for "sz", "rawdata" and "method". In other words,
5236 ** pre-compressed data is being inserted. */
5237 pData = sqlite3_value_blob(apVal[6]);
5238 nData = sqlite3_value_bytes(apVal[6]);
5239 sz = sqlite3_value_int(apVal[5]);
5240 iMethod = sqlite3_value_int(apVal[8]);
5241 if( iMethod<0 || iMethod>65535 ){
5242 pTab->base.zErrMsg = sqlite3_mprintf(
5243 "zipfile: invalid compression method: %d", iMethod
5244 );
5245 rc = SQLITE_ERROR;
5246 }
5247 }
5248 else{
5249 rc = SQLITE_CONSTRAINT;
5250 }
5251
5252 if( rc==SQLITE_OK ){
5253 rc = zipfileGetMode(pTab, apVal[3],
5254 (bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
5255 );
5256 if( rc==SQLITE_OK && (bIsDir == ((mode & S_IFDIR)==0)) ){
5257 /* The "mode" attribute is a directory, but data has been specified.
5258 ** Or vice-versa - no data but "mode" is a file or symlink. */
5259 rc = SQLITE_CONSTRAINT;
5260 }
5261 }
5262
5263 if( rc==SQLITE_OK ){
5264 zPath = (const char*)sqlite3_value_text(apVal[2]);
5265 nPath = (int)strlen(zPath);
5266 if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){
5267 mTime = (sqlite3_int64)time(0);
5268 }else{
5269 mTime = sqlite3_value_int64(apVal[4]);
5270 }
5271 }
5272
5273 if( rc==SQLITE_OK && bIsDir ){
5274 /* For a directory, check that the last character in the path is a
5275 ** '/'. This appears to be required for compatibility with info-zip
5276 ** (the unzip command on unix). It does not create directories
5277 ** otherwise. */
5278 if( zPath[nPath-1]!='/' ){
5279 zFree = sqlite3_mprintf("%s/", zPath);
5280 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5281 zPath = (const char*)zFree;
5282 nPath++;
5283 }
5284 }
5285
5286 /* Check that we're not inserting a duplicate entry */
5287 if( rc==SQLITE_OK ){
5288 ZipfileEntry *p;
5289 for(p=pTab->pFirstEntry; p; p=p->pNext){
5290 if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
5291 rc = SQLITE_CONSTRAINT;
5292 break;
5293 }
5294 }
5295 }
5296
5297 if( rc==SQLITE_OK ){
5298 /* Create the new CDS record. */
5299 memset(&cds, 0, sizeof(cds));
@@ -5054,10 +5319,11 @@
5319 if( rc==SQLITE_OK ){
5320 rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
5321 }
5322
5323 sqlite3_free(pFree);
5324 sqlite3_free(zFree);
5325 return rc;
5326 }
5327
5328 static int zipfileAppendEOCD(ZipfileTab *pTab, ZipfileEOCD *p){
5329 u8 *aBuf = pTab->aBuffer;
@@ -5195,74 +5461,22 @@
5461 }
5462 #else /* SQLITE_OMIT_VIRTUALTABLE */
5463 # define zipfileRegister(x) SQLITE_OK
5464 #endif
5465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5466 #ifdef _WIN32
5467
5468 #endif
5469 int sqlite3_zipfile_init(
5470 sqlite3 *db,
5471 char **pzErrMsg,
5472 const sqlite3_api_routines *pApi
5473 ){
 
5474 SQLITE_EXTENSION_INIT2(pApi);
5475 (void)pzErrMsg; /* Unused parameter */
 
 
 
 
5476 return zipfileRegister(db);
5477 }
 
5478
5479 /************************* End ../ext/misc/zipfile.c ********************/
5480 /************************* Begin ../ext/misc/sqlar.c ******************/
5481 /*
5482 ** 2017-12-17
@@ -5571,10 +5785,12 @@
5785 *************************************************************************
5786 */
5787 #include <assert.h>
5788 #include <string.h>
5789 #include <stdio.h>
5790
5791 #ifndef SQLITE_OMIT_VIRTUALTABLE
5792
5793 /* typedef sqlite3_int64 i64; */
5794 /* typedef sqlite3_uint64 u64; */
5795
5796 typedef struct IdxColumn IdxColumn;
@@ -6052,11 +6268,11 @@
6268 }
6269 }
6270 }
6271 }
6272
6273 pIdxInfo->estimatedCost = 1000000.0 / (n+1);
6274 return rc;
6275 }
6276
6277 static int expertUpdate(
6278 sqlite3_vtab *pVtab,
@@ -6311,11 +6527,11 @@
6527 if( zAppend ){
6528 nAppend = STRLEN(zAppend);
6529 zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
6530 }
6531 if( zAppend && zRet ){
6532 if( nIn ) memcpy(zRet, zIn, nIn);
6533 memcpy(&zRet[nIn], zAppend, nAppend+1);
6534 }else{
6535 sqlite3_free(zRet);
6536 zRet = 0;
6537 *pRc = SQLITE_NOMEM;
@@ -6465,11 +6681,11 @@
6681 if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
6682 IdxTable *pTab = pScan->pTab;
6683 char *zCols = 0;
6684 char *zIdx = 0;
6685 IdxConstraint *pCons;
6686 unsigned int h = 0;
6687 const char *zFmt;
6688
6689 for(pCons=pEq; pCons; pCons=pCons->pLink){
6690 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6691 }
@@ -7080,10 +7296,11 @@
7296 zCols = idxAppendText(&rc, zCols,
7297 "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
7298 );
7299 zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
7300 }
7301 sqlite3_reset(pIndexXInfo);
7302 if( rc==SQLITE_OK ){
7303 if( p->iSample==100 ){
7304 zQuery = sqlite3_mprintf(
7305 "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
7306 );
@@ -7489,10 +7706,12 @@
7706 idxHashClear(&p->hIdx);
7707 sqlite3_free(p->zCandidates);
7708 sqlite3_free(p);
7709 }
7710 }
7711
7712 #endif /* ifndef SQLITE_OMIT_VIRTUAL_TABLE */
7713
7714 /************************* End ../ext/expert/sqlite3expert.c ********************/
7715
7716 #if defined(SQLITE_ENABLE_SESSION)
7717 /*
@@ -7535,26 +7754,31 @@
7754 u8 autoExplain; /* Automatically turn on .explain mode */
7755 u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
7756 u8 statsOn; /* True to display memory stats before each finalize */
7757 u8 scanstatsOn; /* True to display scan stats before each finalize */
7758 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
7759 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
7760 int outCount; /* Revert to stdout when reaching zero */
7761 int cnt; /* Number of records displayed so far */
7762 FILE *out; /* Write results here */
7763 FILE *traceOut; /* Output for sqlite3_trace() */
7764 int nErr; /* Number of errors seen */
7765 int mode; /* An output mode setting */
7766 int modePrior; /* Saved mode */
7767 int cMode; /* temporary output mode for the current query */
7768 int normalMode; /* Output mode before ".explain on" */
7769 int writableSchema; /* True if PRAGMA writable_schema=ON */
7770 int showHeader; /* True to show column names in List or Column mode */
7771 int nCheck; /* Number of ".check" commands run */
7772 unsigned shellFlgs; /* Various flags */
7773 char *zDestTable; /* Name of destination table when MODE_Insert */
7774 char *zTempFile; /* Temporary file that might need deleting */
7775 char zTestcase[30]; /* Name of current test case */
7776 char colSeparator[20]; /* Column separator character for several modes */
7777 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
7778 char colSepPrior[20]; /* Saved column separator */
7779 char rowSepPrior[20]; /* Saved row separator */
7780 int colWidth[100]; /* Requested width of each column when in column mode*/
7781 int actualWidth[100]; /* Actual width of each column */
7782 char nullValue[20]; /* The text to print when a NULL comes back from
7783 ** the database */
7784 char outfile[FILENAME_MAX]; /* Filename for *out */
@@ -7648,24 +7872,175 @@
7872 #define SEP_Comma ","
7873 #define SEP_CrLf "\r\n"
7874 #define SEP_Unit "\x1F"
7875 #define SEP_Record "\x1E"
7876
 
 
 
 
 
7877 /*
7878 ** A callback for the sqlite3_log() interface.
7879 */
7880 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
7881 ShellState *p = (ShellState*)pArg;
7882 if( p->pLog==0 ) return;
7883 utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
7884 fflush(p->pLog);
7885 }
7886
7887 /*
7888 ** SQL function: shell_putsnl(X)
7889 **
7890 ** Write the text X to the screen (or whatever output is being directed)
7891 ** adding a newline at the end, and then return X.
7892 */
7893 static void shellPutsFunc(
7894 sqlite3_context *pCtx,
7895 int nVal,
7896 sqlite3_value **apVal
7897 ){
7898 ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
7899 utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0]));
7900 sqlite3_result_value(pCtx, apVal[0]);
7901 }
7902
7903 /*
7904 ** SQL function: edit(VALUE)
7905 ** edit(VALUE,EDITOR)
7906 **
7907 ** These steps:
7908 **
7909 ** (1) Write VALUE into a temporary file.
7910 ** (2) Run program EDITOR on that temporary file.
7911 ** (3) Read the temporary file back and return its content as the result.
7912 ** (4) Delete the temporary file
7913 **
7914 ** If the EDITOR argument is omitted, use the value in the VISUAL
7915 ** environment variable. If still there is no EDITOR, through an error.
7916 **
7917 ** Also throw an error if the EDITOR program returns a non-zero exit code.
7918 */
7919 static void editFunc(
7920 sqlite3_context *context,
7921 int argc,
7922 sqlite3_value **argv
7923 ){
7924 const char *zEditor;
7925 char *zTempFile = 0;
7926 sqlite3 *db;
7927 char *zCmd = 0;
7928 int bBin;
7929 int rc;
7930 FILE *f = 0;
7931 sqlite3_int64 sz;
7932 sqlite3_int64 x;
7933 unsigned char *p = 0;
7934
7935 if( argc==2 ){
7936 zEditor = (const char*)sqlite3_value_text(argv[1]);
7937 }else{
7938 zEditor = getenv("VISUAL");
7939 }
7940 if( zEditor==0 ){
7941 sqlite3_result_error(context, "no editor for edit()", -1);
7942 return;
7943 }
7944 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
7945 sqlite3_result_error(context, "NULL input to edit()", -1);
7946 return;
7947 }
7948 db = sqlite3_context_db_handle(context);
7949 zTempFile = 0;
7950 sqlite3_file_control(db, 0, SQLITE_FCNTL_TEMPFILENAME, &zTempFile);
7951 if( zTempFile==0 ){
7952 sqlite3_uint64 r = 0;
7953 sqlite3_randomness(sizeof(r), &r);
7954 zTempFile = sqlite3_mprintf("temp%llx", r);
7955 if( zTempFile==0 ){
7956 sqlite3_result_error_nomem(context);
7957 return;
7958 }
7959 }
7960 bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB;
7961 f = fopen(zTempFile, bBin ? "wb" : "w");
7962 if( f==0 ){
7963 sqlite3_result_error(context, "edit() cannot open temp file", -1);
7964 goto edit_func_end;
7965 }
7966 sz = sqlite3_value_bytes(argv[0]);
7967 if( bBin ){
7968 x = fwrite(sqlite3_value_blob(argv[0]), 1, sz, f);
7969 }else{
7970 x = fwrite(sqlite3_value_text(argv[0]), 1, sz, f);
7971 }
7972 fclose(f);
7973 f = 0;
7974 if( x!=sz ){
7975 sqlite3_result_error(context, "edit() could not write the whole file", -1);
7976 goto edit_func_end;
7977 }
7978 zCmd = sqlite3_mprintf("%s \"%s\"", zEditor, zTempFile);
7979 if( zCmd==0 ){
7980 sqlite3_result_error_nomem(context);
7981 goto edit_func_end;
7982 }
7983 rc = system(zCmd);
7984 sqlite3_free(zCmd);
7985 if( rc ){
7986 sqlite3_result_error(context, "EDITOR returned non-zero", -1);
7987 goto edit_func_end;
7988 }
7989 f = fopen(zTempFile, bBin ? "rb" : "r");
7990 if( f==0 ){
7991 sqlite3_result_error(context,
7992 "edit() cannot reopen temp file after edit", -1);
7993 goto edit_func_end;
7994 }
7995 fseek(f, 0, SEEK_END);
7996 sz = ftell(f);
7997 rewind(f);
7998 p = sqlite3_malloc64( sz+(bBin==0) );
7999 if( p==0 ){
8000 sqlite3_result_error_nomem(context);
8001 goto edit_func_end;
8002 }
8003 if( bBin ){
8004 x = fread(p, 1, sz, f);
8005 }else{
8006 x = fread(p, 1, sz, f);
8007 p[sz] = 0;
8008 }
8009 fclose(f);
8010 f = 0;
8011 if( x!=sz ){
8012 sqlite3_result_error(context, "could not read back the whole file", -1);
8013 goto edit_func_end;
8014 }
8015 if( bBin ){
8016 sqlite3_result_blob(context, p, sz, sqlite3_free);
8017 }else{
8018 sqlite3_result_text(context, (const char*)p, sz, sqlite3_free);
8019 }
8020 p = 0;
8021
8022 edit_func_end:
8023 if( f ) fclose(f);
8024 unlink(zTempFile);
8025 sqlite3_free(zTempFile);
8026 sqlite3_free(p);
8027 }
8028
8029 /*
8030 ** Save or restore the current output mode
8031 */
8032 static void outputModePush(ShellState *p){
8033 p->modePrior = p->mode;
8034 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
8035 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
8036 }
8037 static void outputModePop(ShellState *p){
8038 p->mode = p->modePrior;
8039 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
8040 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
8041 }
8042
8043 /*
8044 ** Output the given string as a hex-encoded blob (eg. X'1234' )
8045 */
8046 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
@@ -8987,10 +9362,11 @@
9362 } while( rc == SQLITE_ROW );
9363 }
9364 }
9365 }
9366
9367 #ifndef SQLITE_OMIT_VIRTUALTABLE
9368 /*
9369 ** This function is called to process SQL if the previous shell command
9370 ** was ".expert". It passes the SQL in the second argument directly to
9371 ** the sqlite3expert object.
9372 **
@@ -9059,10 +9435,67 @@
9435 sqlite3_expert_destroy(p);
9436 pState->expert.pExpert = 0;
9437 return rc;
9438 }
9439
9440 /*
9441 ** Implementation of ".expert" dot command.
9442 */
9443 static int expertDotCommand(
9444 ShellState *pState, /* Current shell tool state */
9445 char **azArg, /* Array of arguments passed to dot command */
9446 int nArg /* Number of entries in azArg[] */
9447 ){
9448 int rc = SQLITE_OK;
9449 char *zErr = 0;
9450 int i;
9451 int iSample = 0;
9452
9453 assert( pState->expert.pExpert==0 );
9454 memset(&pState->expert, 0, sizeof(ExpertInfo));
9455
9456 for(i=1; rc==SQLITE_OK && i<nArg; i++){
9457 char *z = azArg[i];
9458 int n;
9459 if( z[0]=='-' && z[1]=='-' ) z++;
9460 n = strlen30(z);
9461 if( n>=2 && 0==strncmp(z, "-verbose", n) ){
9462 pState->expert.bVerbose = 1;
9463 }
9464 else if( n>=2 && 0==strncmp(z, "-sample", n) ){
9465 if( i==(nArg-1) ){
9466 raw_printf(stderr, "option requires an argument: %s\n", z);
9467 rc = SQLITE_ERROR;
9468 }else{
9469 iSample = (int)integerValue(azArg[++i]);
9470 if( iSample<0 || iSample>100 ){
9471 raw_printf(stderr, "value out of range: %s\n", azArg[i]);
9472 rc = SQLITE_ERROR;
9473 }
9474 }
9475 }
9476 else{
9477 raw_printf(stderr, "unknown option: %s\n", z);
9478 rc = SQLITE_ERROR;
9479 }
9480 }
9481
9482 if( rc==SQLITE_OK ){
9483 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
9484 if( pState->expert.pExpert==0 ){
9485 raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
9486 rc = SQLITE_ERROR;
9487 }else{
9488 sqlite3_expert_config(
9489 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
9490 );
9491 }
9492 }
9493
9494 return rc;
9495 }
9496 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
9497
9498 /*
9499 ** Execute a statement or set of statements. Print
9500 ** any result rows/columns depending on the current mode
9501 ** set via the supplied callback.
@@ -9086,14 +9519,16 @@
9519
9520 if( pzErrMsg ){
9521 *pzErrMsg = NULL;
9522 }
9523
9524 #ifndef SQLITE_OMIT_VIRTUALTABLE
9525 if( pArg->expert.pExpert ){
9526 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
9527 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
9528 }
9529 #endif
9530
9531 while( zSql[0] && (SQLITE_OK == rc) ){
9532 static const char *zStmtSql;
9533 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
9534 if( SQLITE_OK != rc ){
@@ -9516,10 +9951,11 @@
9951 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
9952 " If TABLE specified, only dump tables matching\n"
9953 " LIKE pattern TABLE.\n"
9954 ".echo on|off Turn command echo on or off\n"
9955 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
9956 ".excel Display the output of next command in a spreadsheet\n"
9957 ".exit Exit this program\n"
9958 ".expert EXPERIMENTAL. Suggest indexes for specified queries\n"
9959 /* Because explain mode comes on automatically now, the ".explain" mode
9960 ** is removed from the help screen. It is still supported for legacy, however */
9961 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
@@ -9553,14 +9989,16 @@
9989 " list Values delimited by \"|\"\n"
9990 " quote Escape answers as for SQL\n"
9991 " tabs Tab-separated values\n"
9992 " tcl TCL list elements\n"
9993 ".nullvalue STRING Use STRING in place of NULL values\n"
9994 ".once (-e|-x|FILE) Output for the next SQL command only to FILE\n"
9995 " or invoke system text editor (-e) or spreadsheet (-x)\n"
9996 " on the output.\n"
9997 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE\n"
9998 " The --new option starts with an empty file\n"
9999 ".output ?FILE? Send output to FILE or stdout\n"
10000 ".print STRING... Print literal STRING\n"
10001 ".prompt MAIN CONTINUE Replace the standard prompts\n"
10002 ".quit Exit this program\n"
10003 ".read FILENAME Execute SQL in FILENAME\n"
10004 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
@@ -9775,10 +10213,16 @@
10213 #endif
10214 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
10215 shellAddSchemaName, 0, 0);
10216 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
10217 shellModuleSchema, 0, 0);
10218 sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
10219 shellPutsFunc, 0, 0);
10220 sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
10221 editFunc, 0, 0);
10222 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
10223 editFunc, 0, 0);
10224 if( p->openMode==SHELL_OPEN_ZIPFILE ){
10225 char *zSql = sqlite3_mprintf(
10226 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
10227 sqlite3_exec(p->db, zSql, 0, 0, 0);
10228 sqlite3_free(zSql);
@@ -9908,67 +10352,10 @@
10352 z[j] = c;
10353 }
10354 if( j<i ) z[j] = 0;
10355 }
10356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10357 /*
10358 ** Interpret zArg as either an integer or a boolean value. Return 1 or 0
10359 ** for TRUE and FALSE. Return the integer value if appropriate.
10360 */
10361 static int booleanValue(const char *zArg){
@@ -10011,20 +10398,20 @@
10398 /*
10399 ** Try to open an output file. The names "stdout" and "stderr" are
10400 ** recognized and do the right thing. NULL is returned if the output
10401 ** filename is "off".
10402 */
10403 static FILE *output_file_open(const char *zFile, int bTextMode){
10404 FILE *f;
10405 if( strcmp(zFile,"stdout")==0 ){
10406 f = stdout;
10407 }else if( strcmp(zFile, "stderr")==0 ){
10408 f = stderr;
10409 }else if( strcmp(zFile, "off")==0 ){
10410 f = 0;
10411 }else{
10412 f = fopen(zFile, bTextMode ? "w" : "wb");
10413 if( f==0 ){
10414 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
10415 }
10416 }
10417 return f;
@@ -10433,19 +10820,41 @@
10820 }
10821 sqlite3_close(newDb);
10822 }
10823
10824 /*
10825 ** Change the output file back to stdout.
10826 **
10827 ** If the p->doXdgOpen flag is set, that means the output was being
10828 ** redirected to a temporary file named by p->zTempFile. In that case,
10829 ** launch start/open/xdg-open on that temporary file.
10830 */
10831 static void output_reset(ShellState *p){
10832 if( p->outfile[0]=='|' ){
10833 #ifndef SQLITE_OMIT_POPEN
10834 pclose(p->out);
10835 #endif
10836 }else{
10837 output_file_close(p->out);
10838 if( p->doXdgOpen ){
10839 const char *zXdgOpenCmd =
10840 #if defined(_WIN32)
10841 "start";
10842 #elif defined(__APPLE__)
10843 "open";
10844 #else
10845 "xdg-open";
10846 #endif
10847 char *zCmd;
10848 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
10849 if( system(zCmd) ){
10850 utf8_printf(stderr, "Failed: [%s]\n", zCmd);
10851 }
10852 sqlite3_free(zCmd);
10853 outputModePop(p);
10854 p->doXdgOpen = 0;
10855 }
10856 }
10857 p->outfile[0] = 0;
10858 p->out = stdout;
10859 }
10860
@@ -10699,10 +11108,45 @@
11108 #else
11109 rc = unlink(zFilename);
11110 #endif
11111 return rc;
11112 }
11113
11114 /*
11115 ** Try to delete the temporary file (if there is one) and free the
11116 ** memory used to hold the name of the temp file.
11117 */
11118 static void clearTempFile(ShellState *p){
11119 if( p->zTempFile==0 ) return;
11120 if( p->doXdgOpen ) return;
11121 if( shellDeleteFile(p->zTempFile) ) return;
11122 sqlite3_free(p->zTempFile);
11123 p->zTempFile = 0;
11124 }
11125
11126 /*
11127 ** Create a new temp file name with the given suffix.
11128 */
11129 static void newTempFile(ShellState *p, const char *zSuffix){
11130 clearTempFile(p);
11131 sqlite3_free(p->zTempFile);
11132 p->zTempFile = 0;
11133 if( p->db ){
11134 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
11135 }
11136 if( p->zTempFile==0 ){
11137 sqlite3_uint64 r;
11138 sqlite3_randomness(sizeof(r), &r);
11139 p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
11140 }else{
11141 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
11142 }
11143 if( p->zTempFile==0 ){
11144 raw_printf(stderr, "out of memory\n");
11145 exit(1);
11146 }
11147 }
11148
11149
11150 /*
11151 ** The implementation of SQL scalar function fkey_collate_clause(), used
11152 ** by the ".lint fkey-indexes" command. This scalar function is always
@@ -11028,17 +11472,22 @@
11472 /*
11473 ** Structure representing a single ".ar" command.
11474 */
11475 typedef struct ArCommand ArCommand;
11476 struct ArCommand {
11477 u8 eCmd; /* An AR_CMD_* value */
11478 u8 bVerbose; /* True if --verbose */
11479 u8 bZip; /* True if the archive is a ZIP */
11480 u8 bDryRun; /* True if --dry-run */
11481 u8 bAppend; /* True if --append */
11482 int nArg; /* Number of command arguments */
11483 char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
11484 const char *zFile; /* --file argument, or NULL */
11485 const char *zDir; /* --directory argument, or NULL */
 
 
 
11486 char **azArg; /* Array of command arguments */
11487 ShellState *p; /* Shell state */
11488 sqlite3 *db; /* Database containing the archive */
11489 };
11490
11491 /*
11492 ** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
11493 */
@@ -11060,11 +11509,13 @@
11509 " -x, --extract Extract files from archive\n"
11510 "\n"
11511 "And zero or more optional options:\n"
11512 " -v, --verbose Print each filename as it is processed\n"
11513 " -f FILE, --file FILE Operate on archive FILE (default is current db)\n"
11514 " -a FILE, --append FILE Operate on FILE opened using the apndvfs VFS\n"
11515 " -C DIR, --directory DIR Change to directory DIR to read/extract files\n"
11516 " -n, --dryrun Show the SQL that would have occurred\n"
11517 "\n"
11518 "See also: http://sqlite.org/cli.html#sqlar_archive_support\n"
11519 "\n"
11520 );
11521 return SQLITE_ERROR;
@@ -11095,14 +11546,15 @@
11546 #define AR_CMD_HELP 5
11547
11548 /*
11549 ** Other (non-command) switches.
11550 */
11551 #define AR_SWITCH_VERBOSE 6
11552 #define AR_SWITCH_FILE 7
11553 #define AR_SWITCH_DIRECTORY 8
11554 #define AR_SWITCH_APPEND 9
11555 #define AR_SWITCH_DRYRUN 10
11556
11557 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
11558 switch( eSwitch ){
11559 case AR_CMD_CREATE:
11560 case AR_CMD_EXTRACT:
@@ -11113,17 +11565,19 @@
11565 return arErrorMsg("multiple command options");
11566 }
11567 pAr->eCmd = eSwitch;
11568 break;
11569
11570 case AR_SWITCH_DRYRUN:
11571 pAr->bDryRun = 1;
11572 break;
11573 case AR_SWITCH_VERBOSE:
11574 pAr->bVerbose = 1;
11575 break;
11576 case AR_SWITCH_APPEND:
11577 pAr->bAppend = 1;
11578 /* Fall thru into --file */
 
11579 case AR_SWITCH_FILE:
11580 pAr->zFile = zArg;
11581 break;
11582 case AR_SWITCH_DIRECTORY:
11583 pAr->zDir = zArg;
@@ -11143,24 +11597,25 @@
11597 char **azArg, /* Array of arguments passed to dot command */
11598 int nArg, /* Number of entries in azArg[] */
11599 ArCommand *pAr /* Populate this object */
11600 ){
11601 struct ArSwitch {
 
11602 const char *zLong;
11603 char cShort;
11604 u8 eSwitch;
11605 u8 bArg;
11606 } aSwitch[] = {
11607 { "create", 'c', AR_CMD_CREATE, 0 },
11608 { "extract", 'x', AR_CMD_EXTRACT, 0 },
11609 { "list", 't', AR_CMD_LIST, 0 },
11610 { "update", 'u', AR_CMD_UPDATE, 0 },
11611 { "help", 'h', AR_CMD_HELP, 0 },
11612 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
11613 { "file", 'f', AR_SWITCH_FILE, 1 },
11614 { "append", 'a', AR_SWITCH_APPEND, 1 },
11615 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
11616 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
11617 };
11618 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
11619 struct ArSwitch *pEnd = &aSwitch[nSwitch];
11620
11621 if( nArg<=1 ){
@@ -11283,41 +11738,39 @@
11738 **
11739 ** This function strips any trailing '/' characters from each argument.
11740 ** This is consistent with the way the [tar] command seems to work on
11741 ** Linux.
11742 */
11743 static int arCheckEntries(ArCommand *pAr){
11744 int rc = SQLITE_OK;
11745 if( pAr->nArg ){
11746 int i, j;
11747 sqlite3_stmt *pTest = 0;
11748
11749 shellPreparePrintf(pAr->db, &rc, &pTest,
11750 "SELECT name FROM %s WHERE name=$name",
11751 pAr->zSrcTable
11752 );
11753 j = sqlite3_bind_parameter_index(pTest, "$name");
 
 
11754 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11755 char *z = pAr->azArg[i];
11756 int n = strlen30(z);
11757 int bOk = 0;
11758 while( n>0 && z[n-1]=='/' ) n--;
11759 z[n] = '\0';
11760 sqlite3_bind_text(pTest, j, z, -1, SQLITE_STATIC);
11761 if( SQLITE_ROW==sqlite3_step(pTest) ){
11762 bOk = 1;
11763 }
11764 shellReset(&rc, pTest);
11765 if( rc==SQLITE_OK && bOk==0 ){
11766 utf8_printf(stderr, "not found in archive: %s\n", z);
11767 rc = SQLITE_ERROR;
11768 }
11769 }
11770 shellFinalize(&rc, pTest);
11771 }
 
11772 return rc;
11773 }
11774
11775 /*
11776 ** Format a WHERE clause that can be used against the "sqlar" table to
@@ -11339,13 +11792,13 @@
11792 int i;
11793 const char *zSep = "";
11794 for(i=0; i<pAr->nArg; i++){
11795 const char *z = pAr->azArg[i];
11796 zWhere = sqlite3_mprintf(
11797 "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
11798 zWhere, zSep, z, strlen30(z)+1, z
11799 );
11800 if( zWhere==0 ){
11801 *pRc = SQLITE_NOMEM;
11802 break;
11803 }
11804 zSep = " OR ";
@@ -11353,109 +11806,75 @@
11806 }
11807 }
11808 *pzWhere = zWhere;
11809 }
11810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11811 /*
11812 ** Implementation of .ar "lisT" command.
11813 */
11814 static int arListCommand(ArCommand *pAr){
11815 const char *zSql = "SELECT %s FROM %s WHERE %s";
 
11816 const char *azCols[] = {
11817 "name",
11818 "lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
11819 };
11820
11821 char *zWhere = 0;
11822 sqlite3_stmt *pSql = 0;
11823 int rc;
11824
11825 rc = arCheckEntries(pAr);
11826 arWhereClause(&rc, pAr, &zWhere);
11827
11828 shellPreparePrintf(pAr->db, &rc, &pSql, zSql, azCols[pAr->bVerbose],
11829 pAr->zSrcTable, zWhere);
11830 if( pAr->bDryRun ){
11831 utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql));
11832 }else{
11833 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11834 if( pAr->bVerbose ){
11835 utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
11836 sqlite3_column_text(pSql, 0),
11837 sqlite3_column_int(pSql, 1),
11838 sqlite3_column_text(pSql, 2),
11839 sqlite3_column_text(pSql, 3)
11840 );
11841 }else{
11842 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
11843 }
11844 }
11845 }
 
11846 shellFinalize(&rc, pSql);
11847 return rc;
11848 }
11849
11850
11851 /*
11852 ** Implementation of .ar "eXtract" command.
11853 */
11854 static int arExtractCommand(ArCommand *pAr){
11855 const char *zSql1 =
11856 "SELECT "
11857 " ($dir || name),"
11858 " writefile(($dir || name), %s, mode, mtime) "
11859 "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)";
11860
11861 const char *azExtraArg[] = {
11862 "sqlar_uncompress(data, sz)",
11863 "data"
11864 };
 
 
 
 
 
11865
11866 sqlite3_stmt *pSql = 0;
11867 int rc = SQLITE_OK;
11868 char *zDir = 0;
11869 char *zWhere = 0;
11870 int i, j;
11871
11872 /* If arguments are specified, check that they actually exist within
11873 ** the archive before proceeding. And formulate a WHERE clause to
11874 ** match them. */
11875 rc = arCheckEntries(pAr);
11876 arWhereClause(&rc, pAr, &zWhere);
11877
11878 if( rc==SQLITE_OK ){
11879 if( pAr->zDir ){
11880 zDir = sqlite3_mprintf("%s/", pAr->zDir);
@@ -11463,30 +11882,33 @@
11882 zDir = sqlite3_mprintf("");
11883 }
11884 if( zDir==0 ) rc = SQLITE_NOMEM;
11885 }
11886
11887 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
11888 azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
11889 );
11890
11891 if( rc==SQLITE_OK ){
11892 j = sqlite3_bind_parameter_index(pSql, "$dir");
11893 sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
 
 
11894
11895 /* Run the SELECT statement twice. The first time, writefile() is called
11896 ** for all archive members that should be extracted. The second time,
11897 ** only for the directories. This is because the timestamps for
11898 ** extracted directories must be reset after they are populated (as
11899 ** populating them changes the timestamp). */
11900 for(i=0; i<2; i++){
11901 j = sqlite3_bind_parameter_index(pSql, "$dirOnly");
11902 sqlite3_bind_int(pSql, j, i);
11903 if( pAr->bDryRun ){
11904 utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql));
11905 }else{
11906 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11907 if( i==0 && pAr->bVerbose ){
11908 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0));
11909 }
11910 }
11911 }
11912 shellReset(&rc, pSql);
11913 }
11914 shellFinalize(&rc, pSql);
@@ -11494,10 +11916,29 @@
11916
11917 sqlite3_free(zDir);
11918 sqlite3_free(zWhere);
11919 return rc;
11920 }
11921
11922 /*
11923 ** Run the SQL statement in zSql. Or if doing a --dryrun, merely print it out.
11924 */
11925 static int arExecSql(ArCommand *pAr, const char *zSql){
11926 int rc;
11927 if( pAr->bDryRun ){
11928 utf8_printf(pAr->p->out, "%s\n", zSql);
11929 rc = SQLITE_OK;
11930 }else{
11931 char *zErr = 0;
11932 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr);
11933 if( zErr ){
11934 utf8_printf(stdout, "ERROR: %s\n", zErr);
11935 sqlite3_free(zErr);
11936 }
11937 }
11938 return rc;
11939 }
11940
11941
11942 /*
11943 ** Implementation of .ar "create" and "update" commands.
11944 **
@@ -11507,116 +11948,60 @@
11948 ** printed on stdout for each file archived.
11949 **
11950 ** The create command is the same as update, except that it drops
11951 ** any existing "sqlar" table before beginning.
11952 */
11953 static int arCreateOrUpdateCommand(
 
 
11954 ArCommand *pAr, /* Command arguments and options */
11955 int bUpdate /* true for a --create. false for --update */
11956 ){
 
11957 const char *zCreate =
11958 "CREATE TABLE IF NOT EXISTS sqlar(\n"
11959 " name TEXT PRIMARY KEY, -- name of the file\n"
11960 " mode INT, -- access permissions\n"
11961 " mtime INT, -- last modification time\n"
11962 " sz INT, -- original file size\n"
11963 " data BLOB -- compressed content\n"
11964 ")";
11965 const char *zDrop = "DROP TABLE IF EXISTS sqlar";
11966 const char *zInsertFmt =
11967 "REPLACE INTO sqlar(name,mode,mtime,sz,data)\n"
11968 " SELECT\n"
11969 " %s,\n"
11970 " mode,\n"
11971 " mtime,\n"
11972 " CASE substr(lsmode(mode),1,1)\n"
11973 " WHEN '-' THEN length(data)\n"
11974 " WHEN 'd' THEN 0\n"
11975 " ELSE -1 END,\n"
11976 " CASE WHEN lsmode(mode) LIKE 'd%%' THEN NULL else data END\n"
11977 " FROM fsdir(%Q,%Q)\n"
11978 " WHERE lsmode(mode) NOT LIKE '?%%';";
11979 int i; /* For iterating through azFile[] */
11980 int rc; /* Return code */
11981
11982 rc = arExecSql(pAr, "SAVEPOINT ar;");
11983 if( rc!=SQLITE_OK ) return rc;
11984 if( bUpdate==0 ){
11985 rc = arExecSql(pAr, zDrop);
11986 if( rc!=SQLITE_OK ) return rc;
11987 }
11988 rc = arExecSql(pAr, zCreate);
11989 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11990 char *zSql = sqlite3_mprintf(zInsertFmt,
11991 pAr->bVerbose ? "shell_putsnl(name)" : "name",
11992 pAr->azArg[i], pAr->zDir);
11993 rc = arExecSql(pAr, zSql);
11994 sqlite3_free(zSql);
11995 }
11996 if( rc!=SQLITE_OK ){
11997 arExecSql(pAr, "ROLLBACK TO ar; RELEASE ar;");
11998 }else{
11999 rc = arExecSql(pAr, "RELEASE ar;");
12000 }
12001 return rc;
12002 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12003
12004 /*
12005 ** Implementation of ".ar" dot command.
12006 */
12007 static int arDotCommand(
@@ -11624,138 +12009,108 @@
12009 char **azArg, /* Array of arguments passed to dot command */
12010 int nArg /* Number of entries in azArg[] */
12011 ){
12012 ArCommand cmd;
12013 int rc;
12014 memset(&cmd, 0, sizeof(cmd));
12015 rc = arParseCommand(azArg, nArg, &cmd);
12016 if( rc==SQLITE_OK ){
12017 int eDbType = SHELL_OPEN_UNSPEC;
12018 cmd.p = pState;
12019 cmd.db = pState->db;
12020 if( cmd.zFile ){
12021 eDbType = deduceDatabaseType(cmd.zFile);
12022 }else{
12023 eDbType = pState->openMode;
12024 }
12025 if( eDbType==SHELL_OPEN_ZIPFILE ){
12026 if( cmd.zFile==0 ){
12027 cmd.zSrcTable = sqlite3_mprintf("zip");
12028 }else{
12029 cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile);
12030 }
12031 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
12032 utf8_printf(stderr, "zip archives are read-only\n");
12033 rc = SQLITE_ERROR;
12034 goto end_ar_command;
12035 }
12036 cmd.bZip = 1;
12037 }else if( cmd.zFile ){
12038 int flags;
12039 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
12040 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
12041 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
12042 }else{
12043 flags = SQLITE_OPEN_READONLY;
12044 }
12045 cmd.db = 0;
12046 if( cmd.bDryRun ){
12047 utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
12048 eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
12049 }
12050 rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
12051 eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
12052 if( rc!=SQLITE_OK ){
12053 utf8_printf(stderr, "cannot open file: %s (%s)\n",
12054 cmd.zFile, sqlite3_errmsg(cmd.db)
12055 );
12056 goto end_ar_command;
 
12057 }
12058 sqlite3_fileio_init(cmd.db, 0, 0);
12059 #ifdef SQLITE_HAVE_ZLIB
12060 sqlite3_sqlar_init(cmd.db, 0, 0);
12061 #endif
12062 sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p,
12063 shellPutsFunc, 0, 0);
12064
12065 }
12066 if( cmd.zSrcTable==0 ){
12067 if( cmd.eCmd!=AR_CMD_CREATE
12068 && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0)
12069 ){
12070 utf8_printf(stderr, "database does not contain an 'sqlar' table\n");
12071 rc = SQLITE_ERROR;
12072 goto end_ar_command;
12073 }
12074 cmd.zSrcTable = sqlite3_mprintf("sqlar");
12075 }
12076
12077 switch( cmd.eCmd ){
12078 case AR_CMD_CREATE:
12079 rc = arCreateOrUpdateCommand(&cmd, 0);
12080 break;
12081
12082 case AR_CMD_EXTRACT:
12083 rc = arExtractCommand(&cmd);
12084 break;
12085
12086 case AR_CMD_LIST:
12087 rc = arListCommand(&cmd);
12088 break;
12089
12090 case AR_CMD_HELP:
12091 arUsage(pState->out);
12092 break;
12093
12094 default:
12095 assert( cmd.eCmd==AR_CMD_UPDATE );
12096 rc = arCreateOrUpdateCommand(&cmd, 1);
12097 break;
12098 }
12099 }
12100 end_ar_command:
12101 if( cmd.db!=pState->db ){
12102 sqlite3_close(cmd.db);
12103 }
12104 sqlite3_free(cmd.zSrcTable);
12105
12106 return rc;
12107 }
12108 /* End of the ".archive" or ".ar" command logic
12109 **********************************************************************************/
12110 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
12111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12112
12113 /*
12114 ** If an input line begins with "." then invoke this routine to
12115 ** process that line.
12116 **
@@ -11766,13 +12121,15 @@
12121 int nArg = 0;
12122 int n, c;
12123 int rc = 0;
12124 char *azArg[50];
12125
12126 #ifndef SQLITE_OMIT_VIRTUALTABLE
12127 if( p->expert.pExpert ){
12128 expertFinish(p, 1, 0);
12129 }
12130 #endif
12131
12132 /* Parse the input line into tokens.
12133 */
12134 while( zLine[h] && nArg<ArraySize(azArg) ){
12135 while( IsSpace(zLine[h]) ){ h++; }
@@ -11799,10 +12156,11 @@
12156 /* Process the input line.
12157 */
12158 if( nArg==0 ) return 0; /* no tokens, no error */
12159 n = strlen30(azArg[0]);
12160 c = azArg[0][0];
12161 clearTempFile(p);
12162
12163 #ifndef SQLITE_OMIT_AUTHORIZATION
12164 if( c=='a' && strncmp(azArg[0], "auth", n)==0 ){
12165 if( nArg!=2 ){
12166 raw_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -12133,14 +12491,16 @@
12491 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
12492 p->autoExplain = 1;
12493 }
12494 }else
12495
12496 #ifndef SQLITE_OMIT_VIRTUALTABLE
12497 if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
12498 open_db(p, 0);
12499 expertDotCommand(p, azArg, nArg);
12500 }else
12501 #endif
12502
12503 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
12504 ShellState data;
12505 char *zErrMsg = 0;
12506 int doStats = 0;
@@ -12592,11 +12952,11 @@
12952 raw_printf(stderr, "Usage: .log FILENAME\n");
12953 rc = 1;
12954 }else{
12955 const char *zFile = azArg[1];
12956 output_file_close(p->pLog);
12957 p->pLog = output_file_open(zFile, 0);
12958 }
12959 }else
12960
12961 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
12962 const char *zMode = nArg>=2 ? azArg[1] : "";
@@ -12701,30 +13061,54 @@
13061 p->zDbFilename = 0;
13062 open_db(p, 0);
13063 }
13064 }else
13065
13066 if( (c=='o'
13067 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
13068 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
13069 ){
13070 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
13071 int bTxtMode = 0;
13072 if( azArg[0][0]=='e' ){
13073 /* Transform the ".excel" command into ".once -x" */
13074 nArg = 2;
13075 azArg[0] = "once";
13076 zFile = azArg[1] = "-x";
13077 n = 4;
13078 }
13079 if( nArg>2 ){
13080 utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
13081 rc = 1;
13082 goto meta_command_exit;
13083 }
13084 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
13085 if( nArg<2 ){
13086 raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
13087 rc = 1;
13088 goto meta_command_exit;
13089 }
13090 p->outCount = 2;
13091 }else{
13092 p->outCount = 0;
13093 }
13094 output_reset(p);
13095 if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
13096 if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
13097 p->doXdgOpen = 1;
13098 outputModePush(p);
13099 if( zFile[1]=='x' ){
13100 newTempFile(p, "csv");
13101 p->mode = MODE_Csv;
13102 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
13103 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
13104 }else{
13105 newTempFile(p, "txt");
13106 bTxtMode = 1;
13107 }
13108 zFile = p->zTempFile;
13109 }
13110 if( zFile[0]=='|' ){
13111 #ifdef SQLITE_OMIT_POPEN
13112 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
13113 rc = 1;
13114 p->out = stdout;
@@ -12737,11 +13121,11 @@
13121 }else{
13122 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
13123 }
13124 #endif
13125 }else{
13126 p->out = output_file_open(zFile, bTxtMode);
13127 if( p->out==0 ){
13128 if( strcmp(zFile,"off")!=0 ){
13129 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
13130 }
13131 p->out = stdout;
@@ -13614,11 +13998,11 @@
13998 }else
13999
14000 /* Begin redirecting output to the file "testcase-out.txt" */
14001 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
14002 output_reset(p);
14003 p->out = output_file_open("testcase-out.txt", 0);
14004 if( p->out==0 ){
14005 raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
14006 }
14007 if( nArg>=2 ){
14008 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -13820,11 +14204,11 @@
14204 raw_printf(stderr, "Usage: .trace FILE|off\n");
14205 rc = 1;
14206 goto meta_command_exit;
14207 }
14208 output_file_close(p->traceOut);
14209 p->traceOut = output_file_open(azArg[1], 0);
14210 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
14211 if( p->traceOut==0 ){
14212 sqlite3_trace_v2(p->db, 0, 0, 0);
14213 }else{
14214 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
@@ -14150,10 +14534,12 @@
14534 errCnt += runOneSqlLine(p, zSql, in, startline);
14535 nSql = 0;
14536 if( p->outCount ){
14537 output_reset(p);
14538 p->outCount = 0;
14539 }else{
14540 clearTempFile(p);
14541 }
14542 }else if( nSql && _all_whitespace(zSql) ){
14543 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
14544 nSql = 0;
14545 }
@@ -14772,11 +15158,14 @@
15158 session_close_all(&data);
15159 sqlite3_close(data.db);
15160 }
15161 sqlite3_free(data.zFreeOnClose);
15162 find_home_dir(1);
15163 output_reset(&data);
15164 data.doXdgOpen = 0;
15165 clearTempFile(&data);
15166 #if !SQLITE_SHELL_IS_UTF8
15167 for(i=0; i<argc; i++) sqlite3_free(argv[i]);
15168 sqlite3_free(argv);
15169 #endif
15170 return rc;
15171 }
15172
+29 -21
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.22.0"
11511151
#define SQLITE_VERSION_NUMBER 3022000
1152
-#define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"
1152
+#define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -25706,11 +25706,11 @@
2570625706
*/
2570725707
SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
2570825708
int n;
2570925709
while( sqlite3Isspace(zStart[0]) ) zStart++;
2571025710
n = (int)(zEnd - zStart);
25711
- while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
25711
+ while( ALWAYS(n>0) && sqlite3Isspace(zStart[n-1]) ) n--;
2571225712
return sqlite3DbStrNDup(db, zStart, n);
2571325713
}
2571425714
2571525715
/*
2571625716
** Free any prior content in *pz and replace it with a copy of zNew.
@@ -36557,24 +36557,28 @@
3655736557
return rc;
3655836558
}
3655936559
fd = robust_open(zName, openFlags, openMode);
3656036560
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
3656136561
assert( !isExclusive || (openFlags & O_CREAT)!=0 );
36562
- if( fd<0 && errno!=EISDIR && isReadWrite ){
36563
- /* Failed to open the file for read/write access. Try read-only. */
36564
- flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
36565
- openFlags &= ~(O_RDWR|O_CREAT);
36566
- flags |= SQLITE_OPEN_READONLY;
36567
- openFlags |= O_RDONLY;
36568
- isReadonly = 1;
36569
- fd = robust_open(zName, openFlags, openMode);
36562
+ if( fd<0 ){
36563
+ if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
36564
+ /* If unable to create a journal because the directory is not
36565
+ ** writable, change the error code to indicate that. */
36566
+ rc = SQLITE_READONLY_DIRECTORY;
36567
+ }else if( errno!=EISDIR && isReadWrite ){
36568
+ /* Failed to open the file for read/write access. Try read-only. */
36569
+ flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
36570
+ openFlags &= ~(O_RDWR|O_CREAT);
36571
+ flags |= SQLITE_OPEN_READONLY;
36572
+ openFlags |= O_RDONLY;
36573
+ isReadonly = 1;
36574
+ fd = robust_open(zName, openFlags, openMode);
36575
+ }
3657036576
}
3657136577
if( fd<0 ){
36572
- rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
36573
- /* If unable to create a journal, change the error code to
36574
- ** indicate that the directory permissions are wrong. */
36575
- if( isNewJrnl && osAccess(zName, F_OK) ) rc = SQLITE_READONLY_DIRECTORY;
36578
+ int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
36579
+ if( rc==SQLITE_OK ) rc = rc2;
3657636580
goto open_finished;
3657736581
}
3657836582
3657936583
/* If this process is running as root and if creating a new rollback
3658036584
** journal or WAL file, set the ownership of the journal or WAL to be
@@ -103560,11 +103564,11 @@
103560103564
103561103565
/* Locate the end of the CREATE VIEW statement. Make sEnd point to
103562103566
** the end.
103563103567
*/
103564103568
sEnd = pParse->sLastToken;
103565
- assert( sEnd.z[0]!=0 );
103569
+ assert( sEnd.z[0]!=0 || sEnd.n==0 );
103566103570
if( sEnd.z[0]!=';' ){
103567103571
sEnd.z += sEnd.n;
103568103572
}
103569103573
sEnd.n = 0;
103570103574
n = (int)(sEnd.z - pBegin->z);
@@ -141612,12 +141616,15 @@
141612141616
sqlite3ParserARG_FETCH;
141613141617
#define TOKEN yyminor
141614141618
/************ Begin %syntax_error code ****************************************/
141615141619
141616141620
UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
141617
- assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
141618
- sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
141621
+ if( TOKEN.z[0] ){
141622
+ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
141623
+ }else{
141624
+ sqlite3ErrorMsg(pParse, "incomplete input");
141625
+ }
141619141626
/************ End %syntax_error code ******************************************/
141620141627
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
141621141628
}
141622141629
141623141630
/*
@@ -142658,11 +142665,11 @@
142658142665
}else if( lastTokenParsed==0 ){
142659142666
break;
142660142667
}else{
142661142668
tokenType = TK_SEMI;
142662142669
}
142663
- zSql -= n;
142670
+ n = 0;
142664142671
}
142665142672
if( tokenType>=TK_SPACE ){
142666142673
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
142667142674
if( db->u1.isInterrupted ){
142668142675
pParse->rc = SQLITE_INTERRUPT;
@@ -144453,10 +144460,11 @@
144453144460
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
144454144461
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
144455144462
case SQLITE_READONLY_CANTINIT: zName = "SQLITE_READONLY_CANTINIT"; break;
144456144463
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
144457144464
case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
144465
+ case SQLITE_READONLY_DIRECTORY: zName = "SQLITE_READONLY_DIRECTORY";break;
144458144466
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
144459144467
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
144460144468
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
144461144469
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
144462144470
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -202941,11 +202949,11 @@
202941202949
int nArg, /* Number of args */
202942202950
sqlite3_value **apUnused /* Function arguments */
202943202951
){
202944202952
assert( nArg==0 );
202945202953
UNUSED_PARAM2(nArg, apUnused);
202946
- sqlite3_result_text(pCtx, "fts5: 2018-01-06 15:49:57 252ee55a7fc0b068b707af27bd912e684c28320996e78f0675217046b8c2fb49", -1, SQLITE_TRANSIENT);
202954
+ sqlite3_result_text(pCtx, "fts5: 2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f", -1, SQLITE_TRANSIENT);
202947202955
}
202948202956
202949202957
static int fts5Init(sqlite3 *db){
202950202958
static const sqlite3_module fts5Mod = {
202951202959
/* iVersion */ 2,
@@ -207209,12 +207217,12 @@
207209207217
}
207210207218
#endif /* SQLITE_CORE */
207211207219
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207212207220
207213207221
/************** End of stmt.c ************************************************/
207214
-#if __LINE__!=207214
207222
+#if __LINE__!=207222
207215207223
#undef SQLITE_SOURCE_ID
207216
-#define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8alt2"
207224
+#define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ecalt2"
207217207225
#endif
207218207226
/* Return the source-id for this library */
207219207227
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207220207228
/************************** End of sqlite3.c ******************************/
207221207229
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -25706,11 +25706,11 @@
25706 */
25707 SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
25708 int n;
25709 while( sqlite3Isspace(zStart[0]) ) zStart++;
25710 n = (int)(zEnd - zStart);
25711 while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
25712 return sqlite3DbStrNDup(db, zStart, n);
25713 }
25714
25715 /*
25716 ** Free any prior content in *pz and replace it with a copy of zNew.
@@ -36557,24 +36557,28 @@
36557 return rc;
36558 }
36559 fd = robust_open(zName, openFlags, openMode);
36560 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
36561 assert( !isExclusive || (openFlags & O_CREAT)!=0 );
36562 if( fd<0 && errno!=EISDIR && isReadWrite ){
36563 /* Failed to open the file for read/write access. Try read-only. */
36564 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
36565 openFlags &= ~(O_RDWR|O_CREAT);
36566 flags |= SQLITE_OPEN_READONLY;
36567 openFlags |= O_RDONLY;
36568 isReadonly = 1;
36569 fd = robust_open(zName, openFlags, openMode);
 
 
 
 
 
 
36570 }
36571 if( fd<0 ){
36572 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
36573 /* If unable to create a journal, change the error code to
36574 ** indicate that the directory permissions are wrong. */
36575 if( isNewJrnl && osAccess(zName, F_OK) ) rc = SQLITE_READONLY_DIRECTORY;
36576 goto open_finished;
36577 }
36578
36579 /* If this process is running as root and if creating a new rollback
36580 ** journal or WAL file, set the ownership of the journal or WAL to be
@@ -103560,11 +103564,11 @@
103560
103561 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
103562 ** the end.
103563 */
103564 sEnd = pParse->sLastToken;
103565 assert( sEnd.z[0]!=0 );
103566 if( sEnd.z[0]!=';' ){
103567 sEnd.z += sEnd.n;
103568 }
103569 sEnd.n = 0;
103570 n = (int)(sEnd.z - pBegin->z);
@@ -141612,12 +141616,15 @@
141612 sqlite3ParserARG_FETCH;
141613 #define TOKEN yyminor
141614 /************ Begin %syntax_error code ****************************************/
141615
141616 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
141617 assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
141618 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
 
 
 
141619 /************ End %syntax_error code ******************************************/
141620 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
141621 }
141622
141623 /*
@@ -142658,11 +142665,11 @@
142658 }else if( lastTokenParsed==0 ){
142659 break;
142660 }else{
142661 tokenType = TK_SEMI;
142662 }
142663 zSql -= n;
142664 }
142665 if( tokenType>=TK_SPACE ){
142666 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
142667 if( db->u1.isInterrupted ){
142668 pParse->rc = SQLITE_INTERRUPT;
@@ -144453,10 +144460,11 @@
144453 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
144454 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
144455 case SQLITE_READONLY_CANTINIT: zName = "SQLITE_READONLY_CANTINIT"; break;
144456 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
144457 case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
 
144458 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
144459 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
144460 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
144461 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
144462 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -202941,11 +202949,11 @@
202941 int nArg, /* Number of args */
202942 sqlite3_value **apUnused /* Function arguments */
202943 ){
202944 assert( nArg==0 );
202945 UNUSED_PARAM2(nArg, apUnused);
202946 sqlite3_result_text(pCtx, "fts5: 2018-01-06 15:49:57 252ee55a7fc0b068b707af27bd912e684c28320996e78f0675217046b8c2fb49", -1, SQLITE_TRANSIENT);
202947 }
202948
202949 static int fts5Init(sqlite3 *db){
202950 static const sqlite3_module fts5Mod = {
202951 /* iVersion */ 2,
@@ -207209,12 +207217,12 @@
207209 }
207210 #endif /* SQLITE_CORE */
207211 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207212
207213 /************** End of stmt.c ************************************************/
207214 #if __LINE__!=207214
207215 #undef SQLITE_SOURCE_ID
207216 #define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8alt2"
207217 #endif
207218 /* Return the source-id for this library */
207219 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207220 /************************** End of sqlite3.c ******************************/
207221
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -25706,11 +25706,11 @@
25706 */
25707 SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
25708 int n;
25709 while( sqlite3Isspace(zStart[0]) ) zStart++;
25710 n = (int)(zEnd - zStart);
25711 while( ALWAYS(n>0) && sqlite3Isspace(zStart[n-1]) ) n--;
25712 return sqlite3DbStrNDup(db, zStart, n);
25713 }
25714
25715 /*
25716 ** Free any prior content in *pz and replace it with a copy of zNew.
@@ -36557,24 +36557,28 @@
36557 return rc;
36558 }
36559 fd = robust_open(zName, openFlags, openMode);
36560 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
36561 assert( !isExclusive || (openFlags & O_CREAT)!=0 );
36562 if( fd<0 ){
36563 if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
36564 /* If unable to create a journal because the directory is not
36565 ** writable, change the error code to indicate that. */
36566 rc = SQLITE_READONLY_DIRECTORY;
36567 }else if( errno!=EISDIR && isReadWrite ){
36568 /* Failed to open the file for read/write access. Try read-only. */
36569 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
36570 openFlags &= ~(O_RDWR|O_CREAT);
36571 flags |= SQLITE_OPEN_READONLY;
36572 openFlags |= O_RDONLY;
36573 isReadonly = 1;
36574 fd = robust_open(zName, openFlags, openMode);
36575 }
36576 }
36577 if( fd<0 ){
36578 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
36579 if( rc==SQLITE_OK ) rc = rc2;
 
 
36580 goto open_finished;
36581 }
36582
36583 /* If this process is running as root and if creating a new rollback
36584 ** journal or WAL file, set the ownership of the journal or WAL to be
@@ -103560,11 +103564,11 @@
103564
103565 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
103566 ** the end.
103567 */
103568 sEnd = pParse->sLastToken;
103569 assert( sEnd.z[0]!=0 || sEnd.n==0 );
103570 if( sEnd.z[0]!=';' ){
103571 sEnd.z += sEnd.n;
103572 }
103573 sEnd.n = 0;
103574 n = (int)(sEnd.z - pBegin->z);
@@ -141612,12 +141616,15 @@
141616 sqlite3ParserARG_FETCH;
141617 #define TOKEN yyminor
141618 /************ Begin %syntax_error code ****************************************/
141619
141620 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
141621 if( TOKEN.z[0] ){
141622 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
141623 }else{
141624 sqlite3ErrorMsg(pParse, "incomplete input");
141625 }
141626 /************ End %syntax_error code ******************************************/
141627 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
141628 }
141629
141630 /*
@@ -142658,11 +142665,11 @@
142665 }else if( lastTokenParsed==0 ){
142666 break;
142667 }else{
142668 tokenType = TK_SEMI;
142669 }
142670 n = 0;
142671 }
142672 if( tokenType>=TK_SPACE ){
142673 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
142674 if( db->u1.isInterrupted ){
142675 pParse->rc = SQLITE_INTERRUPT;
@@ -144453,10 +144460,11 @@
144460 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
144461 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
144462 case SQLITE_READONLY_CANTINIT: zName = "SQLITE_READONLY_CANTINIT"; break;
144463 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
144464 case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
144465 case SQLITE_READONLY_DIRECTORY: zName = "SQLITE_READONLY_DIRECTORY";break;
144466 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
144467 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
144468 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
144469 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
144470 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -202941,11 +202949,11 @@
202949 int nArg, /* Number of args */
202950 sqlite3_value **apUnused /* Function arguments */
202951 ){
202952 assert( nArg==0 );
202953 UNUSED_PARAM2(nArg, apUnused);
202954 sqlite3_result_text(pCtx, "fts5: 2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f", -1, SQLITE_TRANSIENT);
202955 }
202956
202957 static int fts5Init(sqlite3 *db){
202958 static const sqlite3_module fts5Mod = {
202959 /* iVersion */ 2,
@@ -207209,12 +207217,12 @@
207217 }
207218 #endif /* SQLITE_CORE */
207219 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207220
207221 /************** End of stmt.c ************************************************/
207222 #if __LINE__!=207222
207223 #undef SQLITE_SOURCE_ID
207224 #define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ecalt2"
207225 #endif
207226 /* Return the source-id for this library */
207227 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207228 /************************** End of sqlite3.c ******************************/
207229
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.22.0"
127127
#define SQLITE_VERSION_NUMBER 3022000
128
-#define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"
128
+#define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-11 00:38:39 b8d92d8dc239597c6f01a6e572b047f98ce374a8f48257683fa839dde3ec993f"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
8383
8484
# define the SQLite files, which need special flags on compile
8585
SQLITESRC=sqlite3.c
8686
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
8787
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88
-SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_WIN32_NO_ANSI
88
+SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_USE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_WIN32_NO_ANSI
8989
9090
# define the SQLite shell files, which need special flags on compile
9191
SQLITESHELLSRC=shell.c
9292
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
9393
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
9494
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
83
84 # define the SQLite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_WIN32_NO_ANSI
89
90 # define the SQLite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
83
84 # define the SQLite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_USE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_WIN32_NO_ANSI
89
90 # define the SQLite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
2424
CFLAGS = -o
2525
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
29
-SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB
29
+SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_USE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB
3030
3131
SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3232
3333
SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c foci_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3434
3535
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c foci_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_USE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c foci_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2275,10 +2275,13 @@
22752275
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
22762276
-DSQLITE_ENABLE_DBSTAT_VTAB \
22772277
-DSQLITE_ENABLE_JSON1 \
22782278
-DSQLITE_ENABLE_FTS5 \
22792279
-DSQLITE_ENABLE_STMTVTAB \
2280
+ -DSQLITE_USE_ZLIB \
2281
+ -DSQLITE_INTROSPECTION_PRAGMAS \
2282
+ -DSQLITE_ENABLE_DBPAGE_VTAB \
22802283
-DSQLITE_WIN32_NO_ANSI \
22812284
$(MINGW_OPTIONS) \
22822285
-DSQLITE_USE_MALLOC_H \
22832286
-DSQLITE_USE_MSIZE
22842287
22852288
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2275,10 +2275,13 @@
2275 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
2276 -DSQLITE_ENABLE_DBSTAT_VTAB \
2277 -DSQLITE_ENABLE_JSON1 \
2278 -DSQLITE_ENABLE_FTS5 \
2279 -DSQLITE_ENABLE_STMTVTAB \
 
 
 
2280 -DSQLITE_WIN32_NO_ANSI \
2281 $(MINGW_OPTIONS) \
2282 -DSQLITE_USE_MALLOC_H \
2283 -DSQLITE_USE_MSIZE
2284
2285
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2275,10 +2275,13 @@
2275 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
2276 -DSQLITE_ENABLE_DBSTAT_VTAB \
2277 -DSQLITE_ENABLE_JSON1 \
2278 -DSQLITE_ENABLE_FTS5 \
2279 -DSQLITE_ENABLE_STMTVTAB \
2280 -DSQLITE_USE_ZLIB \
2281 -DSQLITE_INTROSPECTION_PRAGMAS \
2282 -DSQLITE_ENABLE_DBPAGE_VTAB \
2283 -DSQLITE_WIN32_NO_ANSI \
2284 $(MINGW_OPTIONS) \
2285 -DSQLITE_USE_MALLOC_H \
2286 -DSQLITE_USE_MSIZE
2287
2288
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -333,10 +333,13 @@
333333
/DSQLITE_ENABLE_FTS3_PARENTHESIS \
334334
/DSQLITE_ENABLE_DBSTAT_VTAB \
335335
/DSQLITE_ENABLE_JSON1 \
336336
/DSQLITE_ENABLE_FTS5 \
337337
/DSQLITE_ENABLE_STMTVTAB \
338
+ /DSQLITE_USE_ZLIB \
339
+ /DSQLITE_INTROSPECTION_PRAGMAS \
340
+ /DSQLITE_ENABLE_DBPAGE_VTAB \
338341
/DSQLITE_WIN32_NO_ANSI
339342
340343
SHELL_OPTIONS = /Dmain=sqlite3_shell \
341344
/DSQLITE_SHELL_IS_UTF8=1 \
342345
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
343346
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -333,10 +333,13 @@
333 /DSQLITE_ENABLE_FTS3_PARENTHESIS \
334 /DSQLITE_ENABLE_DBSTAT_VTAB \
335 /DSQLITE_ENABLE_JSON1 \
336 /DSQLITE_ENABLE_FTS5 \
337 /DSQLITE_ENABLE_STMTVTAB \
 
 
 
338 /DSQLITE_WIN32_NO_ANSI
339
340 SHELL_OPTIONS = /Dmain=sqlite3_shell \
341 /DSQLITE_SHELL_IS_UTF8=1 \
342 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
343
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -333,10 +333,13 @@
333 /DSQLITE_ENABLE_FTS3_PARENTHESIS \
334 /DSQLITE_ENABLE_DBSTAT_VTAB \
335 /DSQLITE_ENABLE_JSON1 \
336 /DSQLITE_ENABLE_FTS5 \
337 /DSQLITE_ENABLE_STMTVTAB \
338 /DSQLITE_USE_ZLIB \
339 /DSQLITE_INTROSPECTION_PRAGMAS \
340 /DSQLITE_ENABLE_DBPAGE_VTAB \
341 /DSQLITE_WIN32_NO_ANSI
342
343 SHELL_OPTIONS = /Dmain=sqlite3_shell \
344 /DSQLITE_SHELL_IS_UTF8=1 \
345 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
346
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -127,10 +127,18 @@
127127
128128
<h2>On Git Versus Fossil</h2>
129129
130130
<ol>
131131
<li value=15>
132
+After prolonged exposure to fossil, i tend to get the jitters when I work with git...
133
+
134
+<blockquote>
135
+<i>sriku - at [https://news.ycombinator.com/item?id=16104427]</i>
136
+</blockquote>
137
+
138
+
139
+<li>
132140
Just want to say thanks for fossil making my life easier....
133141
Also <nowiki>[for]</nowiki> not having a misanthropic command line interface.
134142
135143
<blockquote>
136144
<i>Joshua Paine at [http://www.mail-archive.com/[email protected]/msg02736.html]</i>
137145
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -127,10 +127,18 @@
127
128 <h2>On Git Versus Fossil</h2>
129
130 <ol>
131 <li value=15>
 
 
 
 
 
 
 
 
132 Just want to say thanks for fossil making my life easier....
133 Also <nowiki>[for]</nowiki> not having a misanthropic command line interface.
134
135 <blockquote>
136 <i>Joshua Paine at [http://www.mail-archive.com/[email protected]/msg02736.html]</i>
137
--- www/quotes.wiki
+++ www/quotes.wiki
@@ -127,10 +127,18 @@
127
128 <h2>On Git Versus Fossil</h2>
129
130 <ol>
131 <li value=15>
132 After prolonged exposure to fossil, i tend to get the jitters when I work with git...
133
134 <blockquote>
135 <i>sriku - at [https://news.ycombinator.com/item?id=16104427]</i>
136 </blockquote>
137
138
139 <li>
140 Just want to say thanks for fossil making my life easier....
141 Also <nowiki>[for]</nowiki> not having a misanthropic command line interface.
142
143 <blockquote>
144 <i>Joshua Paine at [http://www.mail-archive.com/[email protected]/msg02736.html]</i>
145

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button