I am using wxSQLite3 (part of wxWidgets) to access a SQLite database. Everything works fine, but now I need to add a cutsom function to SQLite. Since everything in the code is done through wxSQLite3, I'd like to use wxSQLite3 interface to add the function and not the normal C SQLite API. Following the documentation, I've declared a class that inherits wxSQLite3ScalarFunction:
class checkDateFun : public wxSQLite3ScalarFunction {
public:
void Execute(wxSQLite3FunctionContext& ctx);
};
and override the pure virtual wxSQLite3ScalarFunction::Execute() method as follows
void checkDateFun::Execute(wxSQLite3FunctionContext& ctx)
{
wxString date1 = ctx.GetString(0);
wxString date2 = ctx.GetString(1);
//some checks on dates
ctx.SetResult(1);
return;
}
Then, during database creation, I register the function doing
checkDateFun fun;
bool regOk = m_db->CreateFunction("CheckDate", 2, fun);
but when I later try to make a query that uses the function, I get this error: "Exception thrown: read access violation. func-> was 0xFFFFFFFFFFFF7".
What am I doing wrong? Thanks for your help and time.
wxSQLite3
is a component built using wxWidgets, not part of wxWidgets.