1. remove main.
2. compile file with -shared (to create a .so)
3. select loadd_extension('filename.so') ; This will load your .so into the
address space.
4. Use your function in a sql statement.
Recomend getting the example from the wiki working first then move on to your
own.
HTH,
Ken
dark0s dark0s <[EMAIL PROTECTED]> wrote: Ok, but I did not understand step by
step how work. In wiki there is:
#include
SQLITE_EXTENSION_INIT1
static void halfFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
sqlite3_result_double(context, 0.5*sqlite3_value_double(argv[0]));
}
int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
SQLITE_EXTENSION_INIT2(pApi)
sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
return 0;
}
I understood that in my program I must insert sqlite3ext.h
instead sqlite3.h, but I have got a doubt:
Must I insert sqlite3_extension_init implementation,
like below?
#include
SQLITE_EXTENSION_INIT1
int main(int argc, char* argv[]) {
int rc;
char* sql;
sqlite3* db;
sqlite3_stmt* stmt;
const char* tail;
rc = sqlite3_open("dbforext.db",&db);
if (rc) {
fprintf(stderr, "E' impossibile aprire il file %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
static void soundex(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
...
}
int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
SQLITE_EXTENSION_INIT2(pApi)
sqlite3_create_function(db, "soundex", 1, SQLITE_UTF8, NULL, soundex, NULL,
NULL);
}
sql = "select soundex(saverio);";
sqlite3_prepare(db, sql, strlen(sql), &stmt, &tail);
if (rc != SQLITE_OK) {
fprintf(stderr, "Errore SQL: %s\n", sqlite3_errmsg(db));
}
rc = sqlite3_step(stmt);
sqlite3_close(db);
return 0;
}
Excuse for my ignorance with sqlite3, but I am newbye.
Savio
---------------------------------
Inviato da Yahoo! Mail.
La casella di posta intelligente.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users