The soundex function don't return results of your processing.
My output is below:
bash-3.1# gcc -shared labsinf.c -o inf.so
bash-3.1# sqlite3
SQLite version 3.5.7
Enter ".help" for instructions
sqlite> select load_extension('/root/inf.so')
...> select inf(savio)
...>
I don't understand where is the problem? in sqlite3_result_text function or in
sqlite3_create_function
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
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,(const char*)result, strlen(result),
SQLITE_TRANSIENT);
}
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);
return 0;
}
Thank you in advance to help
---------------------------------
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