4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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 *************************************************************************
12 ** Test extension for testing the sqlite3_auto_extension() function.
14 #if defined(INCLUDE_SQLITE_TCL_H)
15 # include "sqlite_tcl.h"
18 # ifndef SQLITE_TCLAPI
19 # define SQLITE_TCLAPI
22 #include "sqlite3ext.h"
24 #ifndef SQLITE_OMIT_LOAD_EXTENSION
25 SQLITE_EXTENSION_INIT1
28 ** The sqr() SQL function returns the square of its input value.
31 sqlite3_context
*context
,
35 double r
= sqlite3_value_double(argv
[0]);
36 sqlite3_result_double(context
, r
*r
);
40 ** This is the entry point to register the extension for the sqr() function.
45 const sqlite3_api_routines
*pApi
47 SQLITE_EXTENSION_INIT2(pApi
);
48 sqlite3_create_function(db
, "sqr", 1, SQLITE_ANY
, 0, sqrFunc
, 0, 0);
53 ** The cube() SQL function returns the cube of its input value.
56 sqlite3_context
*context
,
60 double r
= sqlite3_value_double(argv
[0]);
61 sqlite3_result_double(context
, r
*r
*r
);
65 ** This is the entry point to register the extension for the cube() function.
70 const sqlite3_api_routines
*pApi
72 SQLITE_EXTENSION_INIT2(pApi
);
73 sqlite3_create_function(db
, "cube", 1, SQLITE_ANY
, 0, cubeFunc
, 0, 0);
78 ** This is a broken extension entry point
80 static int broken_init(
83 const sqlite3_api_routines
*pApi
86 SQLITE_EXTENSION_INIT2(pApi
);
87 zErr
= sqlite3_mprintf("broken autoext!");
93 ** tclcmd: sqlite3_auto_extension_sqr
95 ** Register the "sqr" extension to be loaded automatically.
97 static int SQLITE_TCLAPI
autoExtSqrObjCmd(
101 Tcl_Obj
*CONST objv
[]
103 int rc
= sqlite3_auto_extension((void(*)(void))sqr_init
);
104 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
109 ** tclcmd: sqlite3_cancel_auto_extension_sqr
111 ** Unregister the "sqr" extension.
113 static int SQLITE_TCLAPI
cancelAutoExtSqrObjCmd(
117 Tcl_Obj
*CONST objv
[]
119 int rc
= sqlite3_cancel_auto_extension((void(*)(void))sqr_init
);
120 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
125 ** tclcmd: sqlite3_auto_extension_cube
127 ** Register the "cube" extension to be loaded automatically.
129 static int SQLITE_TCLAPI
autoExtCubeObjCmd(
133 Tcl_Obj
*CONST objv
[]
135 int rc
= sqlite3_auto_extension((void(*)(void))cube_init
);
136 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
141 ** tclcmd: sqlite3_cancel_auto_extension_cube
143 ** Unregister the "cube" extension.
145 static int SQLITE_TCLAPI
cancelAutoExtCubeObjCmd(
149 Tcl_Obj
*CONST objv
[]
151 int rc
= sqlite3_cancel_auto_extension((void(*)(void))cube_init
);
152 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
157 ** tclcmd: sqlite3_auto_extension_broken
159 ** Register the broken extension to be loaded automatically.
161 static int SQLITE_TCLAPI
autoExtBrokenObjCmd(
165 Tcl_Obj
*CONST objv
[]
167 int rc
= sqlite3_auto_extension((void(*)(void))broken_init
);
168 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
173 ** tclcmd: sqlite3_cancel_auto_extension_broken
175 ** Unregister the broken extension.
177 static int SQLITE_TCLAPI
cancelAutoExtBrokenObjCmd(
181 Tcl_Obj
*CONST objv
[]
183 int rc
= sqlite3_cancel_auto_extension((void(*)(void))broken_init
);
184 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
188 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
192 ** tclcmd: sqlite3_reset_auto_extension
194 ** Reset all auto-extensions
196 static int SQLITE_TCLAPI
resetAutoExtObjCmd(
200 Tcl_Obj
*CONST objv
[]
202 sqlite3_reset_auto_extension();
208 ** This procedure registers the TCL procs defined in this file.
210 int Sqlitetest_autoext_Init(Tcl_Interp
*interp
){
211 #ifndef SQLITE_OMIT_LOAD_EXTENSION
212 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_sqr",
213 autoExtSqrObjCmd
, 0, 0);
214 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_cube",
215 autoExtCubeObjCmd
, 0, 0);
216 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_broken",
217 autoExtBrokenObjCmd
, 0, 0);
218 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_sqr",
219 cancelAutoExtSqrObjCmd
, 0, 0);
220 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_cube",
221 cancelAutoExtCubeObjCmd
, 0, 0);
222 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_broken",
223 cancelAutoExtBrokenObjCmd
, 0, 0);
225 Tcl_CreateObjCommand(interp
, "sqlite3_reset_auto_extension",
226 resetAutoExtObjCmd
, 0, 0);