This source file includes following definitions.
- sqrFunc
- sqr_init
- cubeFunc
- cube_init
- broken_init
- autoExtSqrObjCmd
- autoExtCubeObjCmd
- autoExtBrokenObjCmd
- resetAutoExtObjCmd
- Sqlitetest_autoext_Init
#include "tcl.h"
#include "sqlite3ext.h"
#ifndef SQLITE_OMIT_LOAD_EXTENSION
static SQLITE_EXTENSION_INIT1
static void sqrFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
double r = sqlite3_value_double(argv[0]);
sqlite3_result_double(context, r*r);
}
static int sqr_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
SQLITE_EXTENSION_INIT2(pApi);
sqlite3_create_function(db, "sqr", 1, SQLITE_ANY, 0, sqrFunc, 0, 0);
return 0;
}
static void cubeFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
double r = sqlite3_value_double(argv[0]);
sqlite3_result_double(context, r*r*r);
}
static int cube_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
SQLITE_EXTENSION_INIT2(pApi);
sqlite3_create_function(db, "cube", 1, SQLITE_ANY, 0, cubeFunc, 0, 0);
return 0;
}
static int broken_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
char *zErr;
SQLITE_EXTENSION_INIT2(pApi);
zErr = sqlite3_mprintf("broken autoext!");
*pzErrMsg = zErr;
return 1;
}
static int autoExtSqrObjCmd(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int rc = sqlite3_auto_extension((void*)sqr_init);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
static int autoExtCubeObjCmd(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int rc = sqlite3_auto_extension((void*)cube_init);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
static int autoExtBrokenObjCmd(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int rc = sqlite3_auto_extension((void*)broken_init);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
#endif
static int resetAutoExtObjCmd(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3_reset_auto_extension();
return SQLITE_OK;
}
int Sqlitetest_autoext_Init(Tcl_Interp *interp){
#ifndef SQLITE_OMIT_LOAD_EXTENSION
Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_sqr",
autoExtSqrObjCmd, 0, 0);
Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_cube",
autoExtCubeObjCmd, 0, 0);
Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken",
autoExtBrokenObjCmd, 0, 0);
#endif
Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension",
resetAutoExtObjCmd, 0, 0);
return TCL_OK;
}