Fix minor problems with the sqlite3_str interface.

FossilOrigin-Name: 43ea8a6836ccb9910314d35e07d881694200c97ef5969629f62e49f7a2a42f92
This commit is contained in:
drh 2018-05-09 14:29:40 +00:00
parent 0cdbe1aee0
commit 446135d724
4 changed files with 46 additions and 44 deletions

View File

@ -1,5 +1,5 @@
C Make\sthe\sinternal\sdynamic\sstring\sinterface\savailable\sto\sextensions\susing\nthe\snew\ssqlite3_str\sobject\sand\sits\sassociated\smethods.\s\sThis\sis\smostly\sjust\na\srenaming\sof\sinternal\sobjects\sand\smethods\sto\suse\sexternal\snames,\sthrough\nthere\sare\sa\sfew\ssmall\swrapper\sfunctions.
D 2018-05-09T13:46:26.086
C Fix\sminor\sproblems\swith\sthe\ssqlite3_str\sinterface.
D 2018-05-09T14:29:40.085
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
@ -489,13 +489,13 @@ F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880
F src/pragma.c c0d13c0e82a9197aef5533d63300c5b0c8a216ae1fd14ada64e1f12f398d7e82
F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324
F src/prepare.c 95a9dba7a5d032039a77775188cb3b6fb17f2fa1a0b7cd915b30b4b823383ffa
F src/printf.c fb76c433bb01c93a0be63c12794540ce830c93947132ee1446cdc131da81ef42
F src/printf.c 74ca0348796b490cdc56c85a8fb1abaa423c15c869712f54bf49fca65aa1dda1
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 6415381a0e9d22c0e7cba33ca4a53f81474190862f5d4838190f5eb5b0b47bc9
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c a35d462ee7a3c0856ad7a9d9c8921fbf3d91d911a8f39ad9d61302eb43b24a71
F src/shell.c.in df233d5556008e330570da3dc4aa837af1df01d95ca5a15beb67b8515302c36a
F src/sqlite.h.in 934a3e0e1e581efcd3b7c463c89fd8658ebd25bf38f6c7e700ba2e8d1c4cb632
F src/sqlite.h.in ef7e6fae65cb40ba004abf090ea491751295c11e64b1446322813d3b473b9400
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d
F src/sqliteInt.h 5abdade4744cf3bd567afb65bb144bb3c61f6132f86813b995a5ca79c7b584e8
@ -1728,7 +1728,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P b866693e6a50b5c41ca54b56bb20753efb94980ad3365c511cccf23ac43a1c23
R 68264eb483f86d69689e19bb38cf694a
P 87f261f0cb800b06ad786f6df16f2c4dddd0d93dfdcc77b4a4eaa22920b56bf1
R 49d1b2d51ef077394ee5b5fe7c9141e7
U drh
Z 4acceaf152c7a58a98e5d6dcf41cb498
Z 4cea265c4571f106ecaa372877866c59

View File

@ -1 +1 @@
87f261f0cb800b06ad786f6df16f2c4dddd0d93dfdcc77b4a4eaa22920b56bf1
43ea8a6836ccb9910314d35e07d881694200c97ef5969629f62e49f7a2a42f92

View File

@ -973,7 +973,7 @@ char *sqlite3_str_finish(sqlite3_str *p){
char *z;
if( p ){
z = sqlite3StrAccumFinish(p);
sqlite3DbFree(p->db, p);
sqlite3_free(p);
}else{
z = 0;
}
@ -992,7 +992,9 @@ int sqlite3_str_length(sqlite3_str *p){
/* Return the current value for p */
char *sqlite3_str_value(sqlite3_str *p){
return p ? p->zText : 0;
if( p==0 || p->nChar==0 ) return 0;
p->zText[p->nChar] = 0;
return p->zText;
}
/*
@ -1003,6 +1005,8 @@ void sqlite3_str_reset(StrAccum *p){
sqlite3DbFree(p->db, p->zText);
p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
}
p->nAlloc = 0;
p->nChar = 0;
p->zText = 0;
}
@ -1032,9 +1036,10 @@ void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
/* Allocate and initialize a new dynamic string object */
sqlite3_str *sqlite3_str_new(sqlite3 *db){
sqlite3_str *p = sqlite3DbMallocRaw(db, sizeof(*p));
sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
if( p ){
sqlite3StrAccumInit(p, db, 0, 0, SQLITE_MAX_LENGTH);
sqlite3StrAccumInit(p, 0, 0, 0,
db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
}
return p;
}

View File

@ -7141,10 +7141,10 @@ int sqlite3_keyword_check(const char*,int);
**
** The lifecycle of an sqlite3_str object is as follows:
** <ol>
** <li> The sqlite3_str object is created using [sqlite3_str_new()].
** <li> Text is appended to the sqlite3_str object using various
** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
** <li> ^Text is appended to the sqlite3_str object using various
** methods, such as [sqlite3_str_appendf()].
** <li> The sqlite3_str object is destroyed and the string it created
** <li> ^The sqlite3_str object is destroyed and the string it created
** is returned using the [sqlite3_str_finish()] interface.
** </ol>
*/
@ -7154,21 +7154,18 @@ typedef struct sqlite3_str sqlite3_str;
** CAPI3REF: Create A New Dynamic String Object
** CONSTRUCTOR: sqlite3_str
**
** The [sqlite3_str_new(D)] allocates and initializes a new [sqlite3_str]
** object. The [sqlite3_str_new(D)] interface returns NULL on an out-of-memory
** ^The [sqlite3_str_new(D)] interface allocates and initializes
** a new [sqlite3_str]
** object. ^The [sqlite3_str_new()] interface returns NULL on an out-of-memory
** condition. To avoid memory leaks, the object returned by
** [sqlite3_str_new(D)] must be freed by a subsequent call to
** [sqlite3_str_finish(S)].
** [sqlite3_str_new()] must be freed by a subsequent call to
** [sqlite3_str_finish(X)].
**
** If the D argument to [sqlite3_str_new(D)] is NULL then memory used to
** construct the string is always taken from the global memory pool used
** by [sqlite3_malloc64()]. If D is not NULL, then a private memory pool
** used by connection D might also be used. This private memory pool is
** faster, but is limited in space, and should only be used for transient
** allocations. The final string returned by [sqlite3_str_finish(X)] is
** always stored in space obtained from [sqlite3_malloc64()] regardless
** of whether or not the private per-connection memory pool is used during
** its construction.
** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
** length of the string contained in the [sqlite3_str] object will be
** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
** of [SQLITE_MAX_LENGTH].
*/
sqlite3_str *sqlite3_str_new(sqlite3*);
@ -7176,12 +7173,12 @@ sqlite3_str *sqlite3_str_new(sqlite3*);
** CAPI3REF: Finalize A Dynamic String
** DESTRUCTOR: sqlite3_str
**
** The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
** that contains the constructed string. The calling application should
** pass the returned value to [sqlite3_free()] to avoid a memory leak.
** The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
** errors were encountered during construction of the string. The
** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
** errors were encountered during construction of the string. ^The
** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
** string in [sqlite3_str] object X is zero bytes long.
*/
@ -7194,28 +7191,28 @@ char *sqlite3_str_finish(sqlite3_str*);
** These interfaces add content to an sqlite3_str object previously obtained
** from [sqlite3_str_new()].
**
** The [sqlite3_str_appendf(X,F,...)] and
** ^The [sqlite3_str_appendf(X,F,...)] and
** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
** functionality of SQLite to append formatted text onto the end of
** [sqlite3_str] object X.
**
** The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
** onto the end of the [sqlite3_str] object X. N must be non-negative.
** S must contain at least N non-zero bytes of content. To append a
** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
** method instead.
**
** The [sqlite3_str_appendall(X,S)] method the complete content of
** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
** zero-terminated string S onto the end of [sqlite3_str] object X.
**
** The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
** single-byte character C onto the end of [sqlite3_str] object X.
** This method can be used, for example, to add whitespace indentation.
** ^This method can be used, for example, to add whitespace indentation.
**
** The [sqlite3_str_reset(X)] method resets the string under construction
** ^The [sqlite3_str_reset(X)] method resets the string under construction
** inside [sqlite3_str] object X back to zero bytes in length.
**
** These methods do not return a result code. If an error occurs, that fact
** These methods do not return a result code. ^If an error occurs, that fact
** is recorded in the [sqlite3_str] object and can be recovered by a
** subsequent call to [sqlite3_str_errcode(X)].
*/
@ -7232,25 +7229,25 @@ void sqlite3_str_reset(sqlite3_str*);
**
** These interfaces return the current status of an [sqlite3_str] object.
**
** If any prior errors have occurred while constructing the dynamic string
** ^If any prior errors have occurred while constructing the dynamic string
** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
** an appropriate error code. The [sqlite3_str_errcode(X)] method returns
** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
** [SQLITE_NOMEM] following any out-of-memory error, or
** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
**
** The [sqlite3_str_length(X)] method returns the current length, in bytes,
** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
** of the dynamic string under construction in [sqlite3_str] object X.
** The length returned by [sqlite3_str_length(X)] does not include the
** ^The length returned by [sqlite3_str_length(X)] does not include the
** zero-termination byte.
**
** The [sqlite3_str_value(X)] method returns a pointer to the current
** ^The [sqlite3_str_value(X)] method returns a pointer to the current
** content of the dynamic string under construction in X. The value
** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
** and might be freed or altered by any subsequent method on the same
** [sqlite3_str] object. Applications must not used the pointer returned
** [sqlite3_str_value(X)] after any subsequent method call on the same
** object. Applications may change the content of the string returned
** object. ^Applications may change the content of the string returned
** by [sqlite3_str_value(X)] as long as they do not write into any bytes
** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
** write any byte after any subsequent sqlite3_str method call.