aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/loadext.c5
-rw-r--r--src/sqlite.h.in30
-rw-r--r--src/sqlite3ext.h6
-rw-r--r--src/test_func.c33
-rw-r--r--src/vdbeInt.h1
-rw-r--r--src/vdbeapi.c7
6 files changed, 79 insertions, 3 deletions
diff --git a/src/loadext.c b/src/loadext.c
index 1d398c54c..b4b981e54 100644
--- a/src/loadext.c
+++ b/src/loadext.c
@@ -407,7 +407,10 @@ static const sqlite3_api_routines sqlite3Apis = {
(sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
sqlite3_value_free,
sqlite3_result_zeroblob64,
- sqlite3_bind_zeroblob64
+ sqlite3_bind_zeroblob64,
+ /* Version 3.8.12 and later */
+ sqlite3_value_subtype,
+ sqlite3_result_subtype
};
/*
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index a7d6318e5..65a0bedb0 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -4358,6 +4358,22 @@ int sqlite3_value_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
** METHOD: sqlite3_value
**
@@ -4656,6 +4672,20 @@ void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
void sqlite3_result_zeroblob(sqlite3_context*, int 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
** METHOD: sqlite3
diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h
index 9c01241a1..9b9f610e9 100644
--- a/src/sqlite3ext.h
+++ b/src/sqlite3ext.h
@@ -272,6 +272,9 @@ struct sqlite3_api_routines {
void (*value_free)(sqlite3_value*);
int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
+ /* Version 3.8.12 and later */
+ unsigned int (*value_subtype)(sqlite3_value*);
+ void (*result_subtype)(sqlite3_context*,unsigned int);
};
/*
@@ -508,6 +511,9 @@ struct sqlite3_api_routines {
#define sqlite3_value_free sqlite3_api->value_free
#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
+/* Version 3.8.12 and later */
+#define sqlite3_value_subtype sqlite3_api->value_subtype
+#define sqlite3_result_subtype sqlite3_api->result_subtype
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
diff --git a/src/test_func.c b/src/test_func.c
index 2e34fa074..63cf18e3f 100644
--- a/src/test_func.c
+++ b/src/test_func.c
@@ -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
** 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
** 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
** similar to the built-in zeroblob() function, except that it does not
** check that the integer parameter is within range before passing it
@@ -615,6 +617,31 @@ static void test_zeroblob(
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 const struct {
char *zName;
@@ -641,6 +668,8 @@ static int registerTestFunctions(sqlite3 *db){
{ "test_decode", 1, SQLITE_UTF8, test_decode},
{ "test_extract", 2, SQLITE_UTF8, test_extract},
{ "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;
diff --git a/src/vdbeInt.h b/src/vdbeInt.h
index 4a90ed648..7884d955b 100644
--- a/src/vdbeInt.h
+++ b/src/vdbeInt.h
@@ -175,6 +175,7 @@ struct Mem {
} u;
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
+ u8 eSubtype; /* Subtype for this value */
int n; /* Number of characters in string value, excluding '\0' */
char *z; /* String or BLOB value */
/* ShallowCopy only needs to copy the information above */
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index faf97634c..06b14e127 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -187,6 +187,9 @@ int sqlite3_value_int(sqlite3_value *pVal){
sqlite_int64 sqlite3_value_int64(sqlite3_value *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){
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) );
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(
sqlite3_context *pCtx,
const char *z,