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 #include "tclsqlite.h"
15 #include "sqlite3ext.h"
17 #ifndef SQLITE_OMIT_LOAD_EXTENSION
18 SQLITE_EXTENSION_INIT1
21 ** The sqr() SQL function returns the square of its input value.
24 sqlite3_context
*context
,
28 double r
= sqlite3_value_double(argv
[0]);
29 sqlite3_result_double(context
, r
*r
);
33 ** This is the entry point to register the extension for the sqr() function.
38 const sqlite3_api_routines
*pApi
40 SQLITE_EXTENSION_INIT2(pApi
);
41 sqlite3_create_function(db
, "sqr", 1, SQLITE_ANY
, 0, sqrFunc
, 0, 0);
46 ** The cube() SQL function returns the cube of its input value.
49 sqlite3_context
*context
,
53 double r
= sqlite3_value_double(argv
[0]);
54 sqlite3_result_double(context
, r
*r
*r
);
58 ** This is the entry point to register the extension for the cube() function.
63 const sqlite3_api_routines
*pApi
65 SQLITE_EXTENSION_INIT2(pApi
);
66 sqlite3_create_function(db
, "cube", 1, SQLITE_ANY
, 0, cubeFunc
, 0, 0);
71 ** This is a broken extension entry point
73 static int broken_init(
76 const sqlite3_api_routines
*pApi
79 SQLITE_EXTENSION_INIT2(pApi
);
80 zErr
= sqlite3_mprintf("broken autoext!");
86 ** tclcmd: sqlite3_auto_extension_sqr
88 ** Register the "sqr" extension to be loaded automatically.
90 static int SQLITE_TCLAPI
autoExtSqrObjCmd(
96 int rc
= sqlite3_auto_extension((void(*)(void))sqr_init
);
97 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
102 ** tclcmd: sqlite3_cancel_auto_extension_sqr
104 ** Unregister the "sqr" extension.
106 static int SQLITE_TCLAPI
cancelAutoExtSqrObjCmd(
110 Tcl_Obj
*CONST objv
[]
112 int rc
= sqlite3_cancel_auto_extension((void(*)(void))sqr_init
);
113 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
118 ** tclcmd: sqlite3_auto_extension_cube
120 ** Register the "cube" extension to be loaded automatically.
122 static int SQLITE_TCLAPI
autoExtCubeObjCmd(
126 Tcl_Obj
*CONST objv
[]
128 int rc
= sqlite3_auto_extension((void(*)(void))cube_init
);
129 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
134 ** tclcmd: sqlite3_cancel_auto_extension_cube
136 ** Unregister the "cube" extension.
138 static int SQLITE_TCLAPI
cancelAutoExtCubeObjCmd(
142 Tcl_Obj
*CONST objv
[]
144 int rc
= sqlite3_cancel_auto_extension((void(*)(void))cube_init
);
145 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
150 ** tclcmd: sqlite3_auto_extension_broken
152 ** Register the broken extension to be loaded automatically.
154 static int SQLITE_TCLAPI
autoExtBrokenObjCmd(
158 Tcl_Obj
*CONST objv
[]
160 int rc
= sqlite3_auto_extension((void(*)(void))broken_init
);
161 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
166 ** tclcmd: sqlite3_cancel_auto_extension_broken
168 ** Unregister the broken extension.
170 static int SQLITE_TCLAPI
cancelAutoExtBrokenObjCmd(
174 Tcl_Obj
*CONST objv
[]
176 int rc
= sqlite3_cancel_auto_extension((void(*)(void))broken_init
);
177 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
181 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
185 ** tclcmd: sqlite3_reset_auto_extension
187 ** Reset all auto-extensions
189 static int SQLITE_TCLAPI
resetAutoExtObjCmd(
193 Tcl_Obj
*CONST objv
[]
195 sqlite3_reset_auto_extension();
201 ** This procedure registers the TCL procs defined in this file.
203 int Sqlitetest_autoext_Init(Tcl_Interp
*interp
){
204 #ifndef SQLITE_OMIT_LOAD_EXTENSION
205 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_sqr",
206 autoExtSqrObjCmd
, 0, 0);
207 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_cube",
208 autoExtCubeObjCmd
, 0, 0);
209 Tcl_CreateObjCommand(interp
, "sqlite3_auto_extension_broken",
210 autoExtBrokenObjCmd
, 0, 0);
211 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_sqr",
212 cancelAutoExtSqrObjCmd
, 0, 0);
213 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_cube",
214 cancelAutoExtCubeObjCmd
, 0, 0);
215 Tcl_CreateObjCommand(interp
, "sqlite3_cancel_auto_extension_broken",
216 cancelAutoExtBrokenObjCmd
, 0, 0);
218 Tcl_CreateObjCommand(interp
, "sqlite3_reset_auto_extension",
219 resetAutoExtObjCmd
, 0, 0);