OLD | NEW |
1 /* | 1 /* |
2 ** 2006 August 23 | 2 ** 2006 August 23 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** Test extension for testing the sqlite3_auto_extension() function. | 12 ** Test extension for testing the sqlite3_auto_extension() function. |
13 */ | 13 */ |
14 #include "tcl.h" | 14 #include "tcl.h" |
15 #include "sqlite3ext.h" | 15 #include "sqlite3ext.h" |
16 | 16 |
17 #ifndef SQLITE_OMIT_LOAD_EXTENSION | 17 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
18 static SQLITE_EXTENSION_INIT1 | 18 SQLITE_EXTENSION_INIT1 |
19 | 19 |
20 /* | 20 /* |
21 ** The sqr() SQL function returns the square of its input value. | 21 ** The sqr() SQL function returns the square of its input value. |
22 */ | 22 */ |
23 static void sqrFunc( | 23 static void sqrFunc( |
24 sqlite3_context *context, | 24 sqlite3_context *context, |
25 int argc, | 25 int argc, |
26 sqlite3_value **argv | 26 sqlite3_value **argv |
27 ){ | 27 ){ |
28 double r = sqlite3_value_double(argv[0]); | 28 double r = sqlite3_value_double(argv[0]); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 Tcl_Interp *interp, | 92 Tcl_Interp *interp, |
93 int objc, | 93 int objc, |
94 Tcl_Obj *CONST objv[] | 94 Tcl_Obj *CONST objv[] |
95 ){ | 95 ){ |
96 int rc = sqlite3_auto_extension((void*)sqr_init); | 96 int rc = sqlite3_auto_extension((void*)sqr_init); |
97 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); | 97 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
98 return SQLITE_OK; | 98 return SQLITE_OK; |
99 } | 99 } |
100 | 100 |
101 /* | 101 /* |
| 102 ** tclcmd: sqlite3_cancel_auto_extension_sqr |
| 103 ** |
| 104 ** Unregister the "sqr" extension. |
| 105 */ |
| 106 static int cancelAutoExtSqrObjCmd( |
| 107 void * clientData, |
| 108 Tcl_Interp *interp, |
| 109 int objc, |
| 110 Tcl_Obj *CONST objv[] |
| 111 ){ |
| 112 int rc = sqlite3_cancel_auto_extension((void*)sqr_init); |
| 113 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 114 return SQLITE_OK; |
| 115 } |
| 116 |
| 117 /* |
102 ** tclcmd: sqlite3_auto_extension_cube | 118 ** tclcmd: sqlite3_auto_extension_cube |
103 ** | 119 ** |
104 ** Register the "cube" extension to be loaded automatically. | 120 ** Register the "cube" extension to be loaded automatically. |
105 */ | 121 */ |
106 static int autoExtCubeObjCmd( | 122 static int autoExtCubeObjCmd( |
107 void * clientData, | 123 void * clientData, |
108 Tcl_Interp *interp, | 124 Tcl_Interp *interp, |
109 int objc, | 125 int objc, |
110 Tcl_Obj *CONST objv[] | 126 Tcl_Obj *CONST objv[] |
111 ){ | 127 ){ |
112 int rc = sqlite3_auto_extension((void*)cube_init); | 128 int rc = sqlite3_auto_extension((void*)cube_init); |
113 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); | 129 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
114 return SQLITE_OK; | 130 return SQLITE_OK; |
115 } | 131 } |
116 | 132 |
117 /* | 133 /* |
| 134 ** tclcmd: sqlite3_cancel_auto_extension_cube |
| 135 ** |
| 136 ** Unregister the "cube" extension. |
| 137 */ |
| 138 static int cancelAutoExtCubeObjCmd( |
| 139 void * clientData, |
| 140 Tcl_Interp *interp, |
| 141 int objc, |
| 142 Tcl_Obj *CONST objv[] |
| 143 ){ |
| 144 int rc = sqlite3_cancel_auto_extension((void*)cube_init); |
| 145 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 146 return SQLITE_OK; |
| 147 } |
| 148 |
| 149 /* |
118 ** tclcmd: sqlite3_auto_extension_broken | 150 ** tclcmd: sqlite3_auto_extension_broken |
119 ** | 151 ** |
120 ** Register the broken extension to be loaded automatically. | 152 ** Register the broken extension to be loaded automatically. |
121 */ | 153 */ |
122 static int autoExtBrokenObjCmd( | 154 static int autoExtBrokenObjCmd( |
123 void * clientData, | 155 void * clientData, |
124 Tcl_Interp *interp, | 156 Tcl_Interp *interp, |
125 int objc, | 157 int objc, |
126 Tcl_Obj *CONST objv[] | 158 Tcl_Obj *CONST objv[] |
127 ){ | 159 ){ |
128 int rc = sqlite3_auto_extension((void*)broken_init); | 160 int rc = sqlite3_auto_extension((void*)broken_init); |
129 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); | 161 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
130 return SQLITE_OK; | 162 return SQLITE_OK; |
131 } | 163 } |
132 | 164 |
| 165 /* |
| 166 ** tclcmd: sqlite3_cancel_auto_extension_broken |
| 167 ** |
| 168 ** Unregister the broken extension. |
| 169 */ |
| 170 static int cancelAutoExtBrokenObjCmd( |
| 171 void * clientData, |
| 172 Tcl_Interp *interp, |
| 173 int objc, |
| 174 Tcl_Obj *CONST objv[] |
| 175 ){ |
| 176 int rc = sqlite3_cancel_auto_extension((void*)broken_init); |
| 177 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 178 return SQLITE_OK; |
| 179 } |
| 180 |
133 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ | 181 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ |
134 | 182 |
135 | 183 |
136 /* | 184 /* |
137 ** tclcmd: sqlite3_reset_auto_extension | 185 ** tclcmd: sqlite3_reset_auto_extension |
138 ** | 186 ** |
139 ** Reset all auto-extensions | 187 ** Reset all auto-extensions |
140 */ | 188 */ |
141 static int resetAutoExtObjCmd( | 189 static int resetAutoExtObjCmd( |
142 void * clientData, | 190 void * clientData, |
(...skipping 10 matching lines...) Expand all Loading... |
153 ** This procedure registers the TCL procs defined in this file. | 201 ** This procedure registers the TCL procs defined in this file. |
154 */ | 202 */ |
155 int Sqlitetest_autoext_Init(Tcl_Interp *interp){ | 203 int Sqlitetest_autoext_Init(Tcl_Interp *interp){ |
156 #ifndef SQLITE_OMIT_LOAD_EXTENSION | 204 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
157 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_sqr", | 205 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_sqr", |
158 autoExtSqrObjCmd, 0, 0); | 206 autoExtSqrObjCmd, 0, 0); |
159 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_cube", | 207 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_cube", |
160 autoExtCubeObjCmd, 0, 0); | 208 autoExtCubeObjCmd, 0, 0); |
161 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken", | 209 Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken", |
162 autoExtBrokenObjCmd, 0, 0); | 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); |
163 #endif | 217 #endif |
164 Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension", | 218 Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension", |
165 resetAutoExtObjCmd, 0, 0); | 219 resetAutoExtObjCmd, 0, 0); |
166 return TCL_OK; | 220 return TCL_OK; |
167 } | 221 } |
OLD | NEW |