diff options
author | drh <drh@noemail.net> | 2019-05-03 21:17:28 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-05-03 21:17:28 +0000 |
commit | 0c8f40389ea950077ec8e265b4d9cb7a15e2bc58 (patch) | |
tree | 848b3349acf2624fd7f3e04e849ef1fd804ab99d /src | |
parent | f2566c4132bc85ec7a11bd2ce0bf012e24817cee (diff) | |
download | sqlite-0c8f40389ea950077ec8e265b4d9cb7a15e2bc58.tar.gz sqlite-0c8f40389ea950077ec8e265b4d9cb7a15e2bc58.zip |
Add the SQLITE_TESTCTRL_RESULT_INTREAL test-control and use it to create
the intreal() SQL function in testfixture. Write a few simple tests to
prove this all works. TH3 will hold most of the INTREAL tests, probably.
FossilOrigin-Name: c9838731325e0ca73bd8784c10c74ae043fed7861e6de269fd90e29fa4a19955
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/sqlite.h.in | 3 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 | ||||
-rw-r--r-- | src/test1.c | 22 | ||||
-rw-r--r-- | src/vdbeapi.c | 15 |
5 files changed, 58 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c index 24f7f20f3..6358457c8 100644 --- a/src/main.c +++ b/src/main.c @@ -4104,6 +4104,22 @@ int sqlite3_test_control(int op, ...){ break; } #endif /* defined(YYCOVERAGE) */ + + /* sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL, sqlite3_context*); + ** + ** This test-control causes the most recent sqlite3_result_int64() value + ** to be interpreted as a MEM_IntReal instead of as an MEM_Int. Normally, + ** MEM_IntReal values only arise during an INSERT operation of integer + ** values into a REAL column, so they can be challenging to test. This + ** test-control enables us to write an intreal() SQL function that can + ** inject an intreal() value at arbitrary places in an SQL statement, + ** for testing purposes. + */ + case SQLITE_TESTCTRL_RESULT_INTREAL: { + sqlite3_context *pCtx = va_arg(ap, sqlite3_context*); + sqlite3ResultIntReal(pCtx); + break; + } } va_end(ap); #endif /* SQLITE_UNTESTABLE */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index cf390ac37..b9c2330d4 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7319,7 +7319,8 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_SORTER_MMAP 24 #define SQLITE_TESTCTRL_IMPOSTER 25 #define SQLITE_TESTCTRL_PARSER_COVERAGE 26 -#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */ +#define SQLITE_TESTCTRL_RESULT_INTREAL 27 +#define SQLITE_TESTCTRL_LAST 27 /* Largest TESTCTRL */ /* ** CAPI3REF: SQL Keyword Checking diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 00ac00274..e6b3aeca1 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4272,6 +4272,9 @@ void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*)); void sqlite3ValueSetNull(sqlite3_value*); void sqlite3ValueFree(sqlite3_value*); +#ifndef SQLITE_UNTESTABLE +void sqlite3ResultIntReal(sqlite3_context*); +#endif sqlite3_value *sqlite3ValueNew(sqlite3 *); #ifndef SQLITE_OMIT_UTF16 char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); diff --git a/src/test1.c b/src/test1.c index dcbc9e613..be31ee110 100644 --- a/src/test1.c +++ b/src/test1.c @@ -999,6 +999,20 @@ static void nondeterministicFunction( } /* +** This SQL function returns the integer value of its argument as a MEM_IntReal +** value. +*/ +static void intrealFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + sqlite3_int64 v = sqlite3_value_int64(argv[0]); + sqlite3_result_int64(context, v); + sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL, context); +} + +/* ** Usage: sqlite3_create_function DB ** ** Call the sqlite3_create_function API on the given database in order @@ -1062,6 +1076,14 @@ static int SQLITE_TCLAPI test_create_function( 0, nondeterministicFunction, 0, 0); } + /* The intreal() function converts its argument to an integer and returns + ** it as a MEM_IntReal. + */ + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "intreal", 1, SQLITE_UTF8, + 0, intrealFunction, 0, 0); + } + #ifndef SQLITE_OMIT_UTF16 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also ** because it is not tested anywhere else. */ diff --git a/src/vdbeapi.c b/src/vdbeapi.c index df0bf65eb..f145d035c 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -563,6 +563,21 @@ void sqlite3_result_error_nomem(sqlite3_context *pCtx){ sqlite3OomFault(pCtx->pOut->db); } +#ifndef SQLITE_UNTESTABLE +/* Force the INT64 value currently stored as the result to be +** a MEM_IntReal value. See the SQLITE_TESTCTRL_RESULT_INTREAL +** test-control. +*/ +void sqlite3ResultIntReal(sqlite3_context *pCtx){ + assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); + if( pCtx->pOut->flags & MEM_Int ){ + pCtx->pOut->flags &= ~MEM_Int; + pCtx->pOut->flags |= MEM_IntReal; + } +} +#endif + + /* ** This function is called after a transaction has been committed. It ** invokes callbacks registered with sqlite3_wal_hook() as required. |