mirror of
https://github.com/sqlite/sqlite.git
synced 2026-10-23 21:49:02 +03:00
extension. [bugs:/info/2026-07-29T06:31:22Z|Bug 2026-07-29T06:31:22Z]. FossilOrigin-Name: c9bb594059c5e7ad6fd04f1b8087910833d89f05ddf1b6eea6bd5590c851c790
103 lines
2.8 KiB
C
103 lines
2.8 KiB
C
/*
|
|
** 2020-01-08
|
|
**
|
|
** 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 SQLite extension implements a noop() function originally intended
|
|
** to be used for testing purposes only, but never actually used for anything
|
|
** beyond interactive testing.
|
|
**
|
|
** Variants:
|
|
**
|
|
** noop(X) The default. Deterministic.
|
|
** noop_i(X) Deterministic and innocuous.
|
|
** noop_do(X) Deterministic and direct-only.
|
|
** noop_nd(X) Non-deterministic.
|
|
*/
|
|
#include "sqlite3ext.h"
|
|
SQLITE_EXTENSION_INIT1
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
/*
|
|
** Implementation of the noop() function.
|
|
**
|
|
** The function returns its argument, unchanged.
|
|
*/
|
|
static void noopfunc(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
assert( argc==1 );
|
|
sqlite3_result_value(context, argv[0]);
|
|
}
|
|
|
|
/*
|
|
** Implementation of the multitype_text() function.
|
|
**
|
|
** The function returns its argument as text.
|
|
**
|
|
** * TEXT inputs are passed through unchanged
|
|
**
|
|
** * BLOB inputs return TEXT that is the original BLOB
|
|
** interpreted as UTF-8. If the BLOB contains a 0x00
|
|
** byte, that byte is interpreted as the string
|
|
** terminator.
|
|
**
|
|
** * INTEGER or REAL inputs return a TEXT representation of
|
|
** the number.
|
|
**
|
|
** * NULL inputs return NULL
|
|
*/
|
|
static void multitypeTextFunc(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
assert( argc==1 );
|
|
(void)argc;
|
|
(void)sqlite3_value_text(argv[0]);
|
|
sqlite3_result_value(context, argv[0]);
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
__declspec(dllexport)
|
|
#endif
|
|
int sqlite3_noop_init(
|
|
sqlite3 *db,
|
|
char **pzErrMsg,
|
|
const sqlite3_api_routines *pApi
|
|
){
|
|
int rc = SQLITE_OK;
|
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
(void)pzErrMsg; /* Unused parameter */
|
|
rc = sqlite3_create_function(db, "noop", 1,
|
|
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
|
0, noopfunc, 0, 0);
|
|
if( rc ) return rc;
|
|
rc = sqlite3_create_function(db, "noop_i", 1,
|
|
SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS,
|
|
0, noopfunc, 0, 0);
|
|
if( rc ) return rc;
|
|
rc = sqlite3_create_function(db, "noop_do", 1,
|
|
SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY,
|
|
0, noopfunc, 0, 0);
|
|
if( rc ) return rc;
|
|
rc = sqlite3_create_function(db, "noop_nd", 1,
|
|
SQLITE_UTF8,
|
|
0, noopfunc, 0, 0);
|
|
if( rc ) return rc;
|
|
rc = sqlite3_create_function(db, "multitype_text", 1,
|
|
SQLITE_UTF8,
|
|
0, multitypeTextFunc, 0, 0);
|
|
return rc;
|
|
}
|