mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Experimental implementation of sqlite3_result_subtype() and
sqlite3_value_subtype() interfaces. FossilOrigin-Name: 7b5be299c617a3d3ed327ed30ef0a66a62c85b1f
This commit is contained in:
22
manifest
22
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Fix\sa\spotential\sNULL\spointer\sderef\sin\sthe\stesting\slogic\sof\spcache1.\nNB:\sThe\s-DSQLITE_TEST\scompile-time\soption\sis\sneeded\sto\shit\sthe\sproblem.
|
C Experimental\simplementation\sof\ssqlite3_result_subtype()\sand\nsqlite3_value_subtype()\sinterfaces.
|
||||||
D 2015-09-10T19:22:25.531
|
D 2015-09-10T20:34:56.434
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239
|
F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -342,7 +342,7 @@ F src/resolve.c 3126f7694b8ce0f97282d7dd3a5198b8fa18dce9
|
|||||||
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
|
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
|
||||||
F src/select.c c17613385bc6b095c421b1f30548814f5fd8a9b2
|
F src/select.c c17613385bc6b095c421b1f30548814f5fd8a9b2
|
||||||
F src/shell.c 6332ef06db1390ef812cfdff1fc97b4fd76cdd42
|
F src/shell.c 6332ef06db1390ef812cfdff1fc97b4fd76cdd42
|
||||||
F src/sqlite.h.in 378bebc8fe6a88bade25e5f23b7e6123fdc64b00
|
F src/sqlite.h.in 65ff1449e8c181da9ec752e8304e0a1efffaf47f
|
||||||
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
|
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
|
||||||
F src/sqlite3ext.h 5088f0b63491677da848c0d07d5711781302d362
|
F src/sqlite3ext.h 5088f0b63491677da848c0d07d5711781302d362
|
||||||
F src/sqliteInt.h 788dc0ea7ba32ec9fec06c628c1792d7b4753d86
|
F src/sqliteInt.h 788dc0ea7ba32ec9fec06c628c1792d7b4753d86
|
||||||
@@ -368,7 +368,7 @@ F src/test_config.c fb2e5d354d9a077f5fbb261652eff4787deb104f
|
|||||||
F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852
|
F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852
|
||||||
F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc
|
F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc
|
||||||
F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f
|
F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f
|
||||||
F src/test_func.c f1ac201465472e76a73e2f3695c3553c63e7322a
|
F src/test_func.c 0d9c25956152adefee8881c6fadc8354793764d0
|
||||||
F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd
|
F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd
|
||||||
F src/test_init.c 66b33120ffe9cd853b5a905ec850d51151337b32
|
F src/test_init.c 66b33120ffe9cd853b5a905ec850d51151337b32
|
||||||
F src/test_intarray.c 870124b95ec4c645d4eb84f15efb7133528fb1a5
|
F src/test_intarray.c 870124b95ec4c645d4eb84f15efb7133528fb1a5
|
||||||
@@ -405,8 +405,8 @@ F src/util.c fc612367108b74573c5fd13a85d0a23027f438bd
|
|||||||
F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
|
F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
|
||||||
F src/vdbe.c 6d85be995bd2308a5aa2a68c7b564c5d4cc1a6fb
|
F src/vdbe.c 6d85be995bd2308a5aa2a68c7b564c5d4cc1a6fb
|
||||||
F src/vdbe.h 4bc88bd0e06f8046ee6ab7487c0015e85ad949ad
|
F src/vdbe.h 4bc88bd0e06f8046ee6ab7487c0015e85ad949ad
|
||||||
F src/vdbeInt.h 8b54e01ad0463590e7cffabce0bc36da9ee4f816
|
F src/vdbeInt.h 8b867eac234e28627ffcace3cd4b4b79bbec664b
|
||||||
F src/vdbeapi.c b821d530bcb2900b4604cf5206f2177f3f881d15
|
F src/vdbeapi.c 0d890f57caf143b114a95ce699e59af51359c508
|
||||||
F src/vdbeaux.c fd00b489ab3f44f2dca1e4344faf289b7bfcf649
|
F src/vdbeaux.c fd00b489ab3f44f2dca1e4344faf289b7bfcf649
|
||||||
F src/vdbeblob.c 1d7b97115e7bbac4c318db416d2ca83fc779544a
|
F src/vdbeblob.c 1d7b97115e7bbac4c318db416d2ca83fc779544a
|
||||||
F src/vdbemem.c 19b3036aa4d676e7103b0fb5efd6327da455f915
|
F src/vdbemem.c 19b3036aa4d676e7103b0fb5efd6327da455f915
|
||||||
@@ -1036,6 +1036,7 @@ F test/subquery.test d7268d193dd33d5505df965399d3a594e76ae13f
|
|||||||
F test/subquery2.test 438f8a7da1457277b22e4176510f7659b286995f
|
F test/subquery2.test 438f8a7da1457277b22e4176510f7659b286995f
|
||||||
F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4
|
F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4
|
||||||
F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a
|
F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a
|
||||||
|
F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8
|
||||||
F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2
|
F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2
|
||||||
F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85
|
F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85
|
||||||
F test/syscall.test d2fdaad713f103ac611fe7ef9b724c7b69f8149c
|
F test/syscall.test d2fdaad713f103ac611fe7ef9b724c7b69f8149c
|
||||||
@@ -1385,7 +1386,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P 0c0c4ae971e54efc526eed7bd071c90dfadb95ff
|
P f5580f08538636ffb1367e717a33756288ccddde
|
||||||
R 3ba34701e76f91459126301401d510a6
|
R a16668bbab7e8bb266cf503c6d51d6a9
|
||||||
|
T *branch * subtypes
|
||||||
|
T *sym-subtypes *
|
||||||
|
T -sym-trunk *
|
||||||
U drh
|
U drh
|
||||||
Z c5b1b6a1894a9ad25bccddfa15233f55
|
Z 5917071f863dd81d33499ad8df67eb85
|
||||||
|
@@ -1 +1 @@
|
|||||||
f5580f08538636ffb1367e717a33756288ccddde
|
7b5be299c617a3d3ed327ed30ef0a66a62c85b1f
|
@@ -4357,6 +4357,22 @@ const void *sqlite3_value_text16be(sqlite3_value*);
|
|||||||
int sqlite3_value_type(sqlite3_value*);
|
int sqlite3_value_type(sqlite3_value*);
|
||||||
int sqlite3_value_numeric_type(sqlite3_value*);
|
int sqlite3_value_numeric_type(sqlite3_value*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** CAPI3REF: Obtaining SQL Values
|
||||||
|
** METHOD: sqlite3_value
|
||||||
|
**
|
||||||
|
** The sqlite3_value_subtype(V) function returns the subtype for
|
||||||
|
** an application-defined SQL function argument V. The subtype
|
||||||
|
** information can be used to pass a limited amount of context from
|
||||||
|
** one SQL function to another. Use the [sqlite3_result_subtype()]
|
||||||
|
** routine to set the subtype for the return value of an SQL function.
|
||||||
|
**
|
||||||
|
** SQLite makes no use of subtype itself. It merely passes the subtype
|
||||||
|
** from the result of one application-defined function to the input of
|
||||||
|
** another.
|
||||||
|
*/
|
||||||
|
unsigned int sqlite3_value_subtype(sqlite3_value*);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** CAPI3REF: Copy And Free SQL Values
|
** CAPI3REF: Copy And Free SQL Values
|
||||||
** METHOD: sqlite3_value
|
** METHOD: sqlite3_value
|
||||||
@@ -4656,6 +4672,20 @@ void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
|
|||||||
void sqlite3_result_zeroblob(sqlite3_context*, int n);
|
void sqlite3_result_zeroblob(sqlite3_context*, int n);
|
||||||
int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
|
int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** CAPI3REF: Setting The Subtype Of An SQL Function
|
||||||
|
** METHOD: sqlite3_context
|
||||||
|
**
|
||||||
|
** The sqlite3_result_subtype(C,T) function causes the subtype of
|
||||||
|
** the result from the application-defined function with context C
|
||||||
|
** to be T. Only the lower 8 bits of the subtype T are preserved
|
||||||
|
** in current versions of SQLite; higher order bits are discarded.
|
||||||
|
** The number of subtype bytes preserved by SQLite might increase
|
||||||
|
** in future releases of SQLite.
|
||||||
|
*/
|
||||||
|
void sqlite3_result_subtype(sqlite3_context*,unsigned int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** CAPI3REF: Define New Collating Sequences
|
** CAPI3REF: Define New Collating Sequences
|
||||||
** METHOD: sqlite3
|
** METHOD: sqlite3
|
||||||
|
@@ -462,7 +462,7 @@ static void real2hex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** tclcmd: test_extract(record, field)
|
** test_extract(record, field)
|
||||||
**
|
**
|
||||||
** This function implements an SQL user-function that accepts a blob
|
** This function implements an SQL user-function that accepts a blob
|
||||||
** containing a formatted database record as the first argument. The
|
** containing a formatted database record as the first argument. The
|
||||||
@@ -509,7 +509,7 @@ static void test_extract(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** tclcmd: test_decode(record)
|
** test_decode(record)
|
||||||
**
|
**
|
||||||
** This function implements an SQL user-function that accepts a blob
|
** This function implements an SQL user-function that accepts a blob
|
||||||
** containing a formatted database record as its only argument. It returns
|
** containing a formatted database record as its only argument. It returns
|
||||||
@@ -601,6 +601,8 @@ static void test_decode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
** test_zeroblob(N)
|
||||||
|
**
|
||||||
** The implementation of scalar SQL function "test_zeroblob()". This is
|
** The implementation of scalar SQL function "test_zeroblob()". This is
|
||||||
** similar to the built-in zeroblob() function, except that it does not
|
** similar to the built-in zeroblob() function, except that it does not
|
||||||
** check that the integer parameter is within range before passing it
|
** check that the integer parameter is within range before passing it
|
||||||
@@ -615,6 +617,31 @@ static void test_zeroblob(
|
|||||||
sqlite3_result_zeroblob(context, nZero);
|
sqlite3_result_zeroblob(context, nZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* test_getsubtype(V)
|
||||||
|
**
|
||||||
|
** Return the subtype for value V.
|
||||||
|
*/
|
||||||
|
static void test_getsubtype(
|
||||||
|
sqlite3_context *context,
|
||||||
|
int argc,
|
||||||
|
sqlite3_value **argv
|
||||||
|
){
|
||||||
|
sqlite3_result_int(context, (int)sqlite3_value_subtype(argv[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test_setsubtype(V, T)
|
||||||
|
**
|
||||||
|
** Return the value V with its subtype changed to T
|
||||||
|
*/
|
||||||
|
static void test_setsubtype(
|
||||||
|
sqlite3_context *context,
|
||||||
|
int argc,
|
||||||
|
sqlite3_value **argv
|
||||||
|
){
|
||||||
|
sqlite3_result_value(context, argv[0]);
|
||||||
|
sqlite3_result_subtype(context, (unsigned int)sqlite3_value_int(argv[1]));
|
||||||
|
}
|
||||||
|
|
||||||
static int registerTestFunctions(sqlite3 *db){
|
static int registerTestFunctions(sqlite3 *db){
|
||||||
static const struct {
|
static const struct {
|
||||||
char *zName;
|
char *zName;
|
||||||
@@ -641,6 +668,8 @@ static int registerTestFunctions(sqlite3 *db){
|
|||||||
{ "test_decode", 1, SQLITE_UTF8, test_decode},
|
{ "test_decode", 1, SQLITE_UTF8, test_decode},
|
||||||
{ "test_extract", 2, SQLITE_UTF8, test_extract},
|
{ "test_extract", 2, SQLITE_UTF8, test_extract},
|
||||||
{ "test_zeroblob", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, test_zeroblob},
|
{ "test_zeroblob", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, test_zeroblob},
|
||||||
|
{ "test_getsubtype", 1, SQLITE_UTF8, test_getsubtype},
|
||||||
|
{ "test_setsubtype", 2, SQLITE_UTF8, test_setsubtype},
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@@ -175,6 +175,7 @@ struct Mem {
|
|||||||
} u;
|
} u;
|
||||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||||
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
|
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
|
||||||
|
u8 eSubtype; /* Subtype for this value */
|
||||||
int n; /* Number of characters in string value, excluding '\0' */
|
int n; /* Number of characters in string value, excluding '\0' */
|
||||||
char *z; /* String or BLOB value */
|
char *z; /* String or BLOB value */
|
||||||
/* ShallowCopy only needs to copy the information above */
|
/* ShallowCopy only needs to copy the information above */
|
||||||
|
@@ -187,6 +187,9 @@ int sqlite3_value_int(sqlite3_value *pVal){
|
|||||||
sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||||
}
|
}
|
||||||
|
unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
|
||||||
|
return ((Mem*)pVal)->eSubtype;
|
||||||
|
}
|
||||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||||
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||||
}
|
}
|
||||||
@@ -365,6 +368,10 @@ void sqlite3_result_null(sqlite3_context *pCtx){
|
|||||||
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
|
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
|
||||||
sqlite3VdbeMemSetNull(pCtx->pOut);
|
sqlite3VdbeMemSetNull(pCtx->pOut);
|
||||||
}
|
}
|
||||||
|
void sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
|
||||||
|
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
|
||||||
|
pCtx->pOut->eSubtype = eSubtype & 0xff;
|
||||||
|
}
|
||||||
void sqlite3_result_text(
|
void sqlite3_result_text(
|
||||||
sqlite3_context *pCtx,
|
sqlite3_context *pCtx,
|
||||||
const char *z,
|
const char *z,
|
||||||
|
31
test/subtype1.test
Normal file
31
test/subtype1.test
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# 2015-09-10
|
||||||
|
#
|
||||||
|
# The author disclaims copyright to this source code. In place of
|
||||||
|
# a legal notice, here is a blessing:
|
||||||
|
#
|
||||||
|
# May you do good and not evil.
|
||||||
|
# May you find forgiveness for yourself and forgive others.
|
||||||
|
# May you share freely, never taking more than you give.
|
||||||
|
#
|
||||||
|
#***********************************************************************
|
||||||
|
# This file implements tests for sqlite3_value_subtype() and
|
||||||
|
# sqlite3_result_subtype() interfaces.
|
||||||
|
#
|
||||||
|
|
||||||
|
set testdir [file dirname $argv0]
|
||||||
|
source $testdir/tester.tcl
|
||||||
|
|
||||||
|
do_execsql_test subtype1-100 {
|
||||||
|
SELECT test_getsubtype('hello');
|
||||||
|
} {0}
|
||||||
|
do_execsql_test subtype1-110 {
|
||||||
|
SELECT test_getsubtype(test_setsubtype('hello',123));
|
||||||
|
} {123}
|
||||||
|
do_execsql_test subtype1-120 {
|
||||||
|
SELECT typeof(test_setsubtype('hello',123));
|
||||||
|
} {text}
|
||||||
|
do_execsql_test subtype1-130 {
|
||||||
|
SELECT test_setsubtype('hello',123);
|
||||||
|
} {hello}
|
||||||
|
|
||||||
|
finish_test
|
Reference in New Issue
Block a user