Yes, you are correct and I am wrong.  The function should indeed be a void 
function and should not return a status code.  There is presently no way to 
indicate an "error" or "exception" condition other that via the sqlite3_result 
values (and there are specific ones for indicating that there was an error).  
So both the header file and the c source should declare the function as a void 
function.

If you want a terminating error (ie, an exception) you use sqlite3_result_error 
to return the error string (same as sqlite3_result_text).  The difference is 
that setting the result using the sqlite3_result_error will signal an error 
condition and terminate the execution of the SQL statement being processed.  
sqlite3_result_error also always makes a copy of the message text, so you can 
deallocate it immediately after it returns.

The other thing is that the final parameters for the sqlite3_result_text needs 
to be set correctly.  Where you are returning a value allocated from the stack, 
this should be SQLITE_TRANSIENT.  This tells sqlite3 to make its own copy of 
the string that it will keep for as long as it needs -- you are free to modify 
or de-allocate such results immediately after the call to sqlite3_result_text 
returns.  

For return values which you have allocated (with malloc) you need to pass the 
function which will deallocate the memory when sqlite3 is finished with it (in 
that case, free).

>Hi Keith,
>thx for hints.
>I have apply all of them.
>
>The only one I like to explain:
>
>I know the warning for the void insted of int declaration of
>stringmetricsFunc.
>But if I put it as "int" I had a warning in the create_function that
>want a void function.
>So I preferred to maintain the warning on  return from stringmetricsFunc.
>
>However to have a compile without any warning,
>I adopt this "hard" workaround:
>
>I define in wrapper_functions.h a
>void stringmetricsFunc
>and instead I declare a
>int stringmetricFunc in wrapper_function.c
>Thx again,
>
>A.
>
>
>
>Il 28/09/2014 22:20, Keith Medcalf ha scritto:
>> src\wrapper_functions.c: In function 'stringmetricsFunc':
>> src\wrapper_functions.c:350:16: warning: 'return' with a value, in
>function returning void [enabled by default]
>>                  return (1);
>>                  ^
>>
>> This is easy.  SQLite scalar functions are supposed to return an int
>status code.  That code is either SQLITE_ERR if there was an error, or
>SQLITE_OK if everything is OK.  So change the function definition to
>return an int, and the two return statements to return SQLITE_ERR (not 1)
>and SQLITE_OK (not nothing).
>
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@sqlite.org
>http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to