I need help. I am doing sqlite3 extension, but something don't work at compile
time.
The output of compiler is:
bash-3.1# gcc -lsqlite3 labsinf.c -o inf
labsinf.c: In function 'soundex':
labsinf.c:16: warning: assignment discards qualifiers from pointer target type
The program is below, I am desperated:
#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* result;
int dim;
char* str;
str = sqlite3_value_text(values[0]);
dim = strlen(str);
for (i=0;i<=dim;i++) str[i] = toupper(str[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': str[i] = '0';
}
for (i=1;i<dim;i++)
switch (str[i]) {
case 'B': case 'F':
case 'P': case 'V': str[i] = '1'; break;
case 'C': case 'G':
case 'J': case 'K':
case 'Q': case 'S':
case 'X': case 'Z': str[i] = '2'; break;
case 'D': case 'T': str[i] = '3'; break;
case 'L': str[i] = '4'; break;
case 'M': case 'N': str[i] = '5'; break;
case 'R': str[i] = '6'; break;
}
count=1;
for (i=0;i<dim-1;i++)
if (str[i] != str[i+1]) count++;
result = malloc(count);
j=0;
for (i=0;i<dim-1;i++)
if (str[i] != str[i+1]) {
result[j]=str[i];
j++;
}
for (i=0;i<4;i++) printf("%c", result[i]);
printf("\n\n");
}
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