I have a new problem, I am attempting add extension function to sqlite3.
My program labsinf.c now build successfully, but I didn't add my extension. I
don't understand what it is miss.
Help me please.
The program labsinf.c make inf, and after I typed ./inf, it makes dbforext.db.
Some output is below:
bash-3.1# gcc -lsqlite3 labsinf.c -o inf
bash-3.1# ./inf
bash-3.1# sqlite3 dbforext.db
SQLite version 3.5.7
Enter ".help" for instructions
sqlite> select soundex(saverio);
SQL error: no such column: saverio
sqlite> select soundex(savio);
SQL error: no such column: savio
sqlite> select soundex();
SQL error: no such function: soundex
sqlite> select soundex;
SQL error: no such column: soundex
The program is below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
void soundex(sqlite3_context* ctx, int nargs, sqlite3_value** values) {
int i,j;
char c,r;
int d;
int count;
char* str2;
char* result;
int dim;
const char* str;
char ret[4];
str = sqlite3_value_text(values[0]);
dim = strlen(str);
for (i=0;i<dim;i++) str2[i] = str[i];
for (i=0;i<=dim;i++) str2[i] = toupper(str2[i]);
for (i=0;i<=dim;i++)
switch (str[i]) {
case 'A': case 'E': case 'I': case 'O':
case 'U': case 'H': case 'W': case 'Y': str2[i] = '0';
}
for (i=1;i<dim;i++)
switch (str2[i]) {
case 'B': case 'F':
case 'P': case 'V': str2[i] = '1'; break;
case 'C': case 'G':
case 'J': case 'K':
case 'Q': case 'S':
case 'X': case 'Z': str2[i] = '2'; break;
case 'D': case 'T': str2[i] = '3'; break;
case 'L': str2[i] = '4'; break;
case 'M': case 'N': str2[i] = '5'; break;
case 'R': str2[i] = '6'; break;
}
count=1;
for (i=0;i<dim-1;i++)
if (str2[i] != str2[i+1]) count++;
result = malloc(count);
j=0;
for (i=0;i<dim-1;i++)
if (str2[i] != str2[i+1]) {
result[j]=str2[i];
j++;
}
for (i=0;i<4;i++) printf("%c", result[i]);
for (i=0;i<4;i++) ret[i] = result[i];
printf("\n\n");
sqlite3_result_text(ctx,ret, 4, SQLITE_TRANSIENT);
}
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);
}
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;
}
---------------------------------
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