"dark0s dark0s" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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')
You need to end the statement with a semicolon. > ...> select inf(savio) This one too. "...>" is a continuation prompt - it means you are continuing the previous statement on the new line. This allows you to enter a large statement on multiple lines, but you have to eventually teminate the query with a semicolon, to let SQLite know you are done typing it in. Also, your extension creates a function named "soundex", not "inf". Why do you expect inf() to work? In addition, "savio" is an unknown identifier. You probably meant to pass a string literal, as in select soundex('savio'); Note apostrophes around the literal, and the terminating semicolon. > 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]; You have never initialized str2, nor allocated memory for it. Had you managed to actually run your code, it would likely crash at this point. > for (i=0;i<=dim;i++) str2[i] = toupper(str2[i]); > for (i=0;i<=dim;i++) > switch (str[i]) { Curious: you have just capitalized the text in str2, but here you are still looking at the original text in str. Is this intentional? > 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]; You copy the data into ret, but never use it afterwards. > sqlite3_result_text(ctx,(const char*)result, strlen(result), > SQLITE_TRANSIENT); You have not added terminating NUL character to result: strlen will either crash or return garbage. On the other hand, you already know the length of string in result - it's in the variable "count". Just use that. Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users