aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-03 14:45:35 +0000
committerdrh <drh@noemail.net>2017-01-03 14:45:35 +0000
commit5c41d00f42c577f54eb78bab974345cc8d92aeac (patch)
treead85ab50266feda5027d804abb79dcb6a8a77ff6 /src
parent2710b14c45f8cfb15d6d774cfdec19ff5d838f59 (diff)
parent542407513770711e5dfc1c0194c3269df25b0f5c (diff)
downloadsqlite-5c41d00f42c577f54eb78bab974345cc8d92aeac.tar.gz
sqlite-5c41d00f42c577f54eb78bab974345cc8d92aeac.zip
Add the experimental affinity() SQL function when SQLITE_DEBUG is defined.
FossilOrigin-Name: bed0eaa5f50112e64fc97a2afdc9d56cf8f5026a
Diffstat (limited to 'src')
-rw-r--r--src/expr.c16
-rw-r--r--src/func.c3
-rw-r--r--src/sqliteInt.h1
3 files changed, 20 insertions, 0 deletions
diff --git a/src/expr.c b/src/expr.c
index bc394caa7..3bb0ca03f 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -3660,6 +3660,22 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
}
+#ifdef SQLITE_DEBUG
+ /* The AFFINITY() function evaluates to a string that describes
+ ** the type affinity of the argument. This is used for testing of
+ ** the SQLite type logic.
+ */
+ if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){
+ const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
+ char aff;
+ assert( nFarg==1 );
+ aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
+ sqlite3VdbeLoadString(v, target,
+ aff ? azAff[aff-SQLITE_AFF_BLOB] : "none");
+ return target;
+ }
+#endif
+
for(i=0; i<nFarg; i++){
if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
testcase( i==31 );
diff --git a/src/func.c b/src/func.c
index 4afb25ad6..885725bc6 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1775,6 +1775,9 @@ void sqlite3RegisterBuiltinFunctions(void){
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
+#ifdef SQLITE_DEBUG
+ FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
+#endif
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 655d51783..31cedf40e 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -1565,6 +1565,7 @@ struct FuncDestructor {
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
** single query - might change over time */
+#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are