如何从自定义sqlite扩展函数中调用内置的sqlite函数



我正在尝试在我的自定义sqlite扩展函数中调用time('now')。time()是一个标准的sqlite函数。我在下面包含了一个示例扩展函数。

#include <sqlite3ext.h>
#include <stdio.h>
#include <string.h>
SQLITE_EXTENSION_INIT1
/*
** The gettime() SQL function returns the current time.
*/
static void timeFunc(sqlite3_context *context,int argc,sqlite3_value **argv){
  sqlite3_result_text(context, time("now"),strlen(time("now")),SQLITE_TRANSIENT);
}
/* SQLite invokes this routine once when it loads the extension.
** Create new functions, collating sequences, and virtual table
** modules here.  This is usually the only exported symbol in
** the shared library.sdaffsd
*/
int sqlite3_extension_init(sqlite3 *db,char **pzErrMsg,const sqlite3_api_routines *pApi){
  SQLITE_EXTENSION_INIT2(pApi)
  sqlite3_create_function(db, "gettime", 1, SQLITE_UTF8, 0, timeFunc, NULL, NULL);
  return 0;
}

您必须执行SQL查询SELECT time('now')

最新更新