이것은 하나의 문자열 매개 변수를 받아 문자열 결과를 반환하는 sqlite 함수를 보여줍니다. 네 개의 수레를 읽고 float를 반환하지만 원칙은 동일 기능을 필요 귀하의 경우에는
(당신은
sqlite3_result_double와
sqlite3_value_double 및
sqlite3_result_text와
sqlite3_value_text를 대체 할) :
#include <stdlib.h>
#include <sqlite3.h>
#include <stdio.h>
void haver(sqlite3_context* ctx,int cnt,sqlite3_value** val)
{
printf("In SQLite haver implementation, called for value: %s\n", sqlite3_value_text(*val));
char * resultOfCall = "Result of function call"; //this would call the distance function
sqlite3_result_text(ctx, resultOfCall, strlen(resultOfCall), NULL);
}
int cback (void* udata,int ncol,char** value,char** colname)
{
int i=0;
for(;i<ncol;i++)
printf("Result column: %s value: %s \n", colname[i], value[i]);
return 0;
}
int main()
{
sqlite3 * handle;
int res = sqlite3_open("./test.sql", &handle);
res = sqlite3_create_function(handle, "haver", 1, SQLITE_UTF8, NULL, &haver, NULL, NULL);
char * errmsg = NULL;
res = sqlite3_exec(handle, "select haver(w) from t", &cback, NULL, &errmsg);
printf("sqlite3_exec result: %d %s\n", res, errmsg != NULL ? errmsg : "No error");
sqlite3_close(handle);
}