Fixes default log output to console for macOS
[sqlcipher.git] / ext / misc / noop.c
blob18c25e10f798769bf129621dbf383008ebfad7b5
1 /*
2 ** 2020-01-08
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 ******************************************************************************
13 ** This SQLite extension implements a noop() function used for testing.
15 ** Variants:
17 ** noop(X) The default. Deterministic.
18 ** noop_i(X) Deterministic and innocuous.
19 ** noop_do(X) Deterministic and direct-only.
20 ** noop_nd(X) Non-deterministic.
22 #include "sqlite3ext.h"
23 SQLITE_EXTENSION_INIT1
24 #include <assert.h>
25 #include <string.h>
28 ** Implementation of the noop() function.
30 ** The function returns its argument, unchanged.
32 static void noopfunc(
33 sqlite3_context *context,
34 int argc,
35 sqlite3_value **argv
37 assert( argc==1 );
38 sqlite3_result_value(context, argv[0]);
42 ** Implementation of the multitype_text() function.
44 ** The function returns its argument. The result will always have a
45 ** TEXT value. But if the original input is numeric, it will also
46 ** have that numeric value.
48 static void multitypeTextFunc(
49 sqlite3_context *context,
50 int argc,
51 sqlite3_value **argv
53 assert( argc==1 );
54 (void)argc;
55 (void)sqlite3_value_text(argv[0]);
56 sqlite3_result_value(context, argv[0]);
59 #ifdef _WIN32
60 __declspec(dllexport)
61 #endif
62 int sqlite3_noop_init(
63 sqlite3 *db,
64 char **pzErrMsg,
65 const sqlite3_api_routines *pApi
67 int rc = SQLITE_OK;
68 SQLITE_EXTENSION_INIT2(pApi);
69 (void)pzErrMsg; /* Unused parameter */
70 rc = sqlite3_create_function(db, "noop", 1,
71 SQLITE_UTF8 | SQLITE_DETERMINISTIC,
72 0, noopfunc, 0, 0);
73 if( rc ) return rc;
74 rc = sqlite3_create_function(db, "noop_i", 1,
75 SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS,
76 0, noopfunc, 0, 0);
77 if( rc ) return rc;
78 rc = sqlite3_create_function(db, "noop_do", 1,
79 SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY,
80 0, noopfunc, 0, 0);
81 if( rc ) return rc;
82 rc = sqlite3_create_function(db, "noop_nd", 1,
83 SQLITE_UTF8,
84 0, noopfunc, 0, 0);
85 if( rc ) return rc;
86 rc = sqlite3_create_function(db, "multitype_text", 1,
87 SQLITE_UTF8,
88 0, multitypeTextFunc, 0, 0);
89 return rc;