Hello again,
thanks for your reply yesterday. I'm limited in my mailing possibilites,
therefore no reply yesterday, but this new issue today.
I did not yet try to write a collation function but began with simple
user defined functions.
My first try was an IIF function similar to MySQL's IF-Function.
sqlite3_create_function(DB, "iif", 3, SQLITE_UTF8, NULL, &funcIIF, NULL,
NULL);
static void funcIIF(sqlite3_context *context, int argc, sqlite3_value
**argv) {
if(argc!=3) {
sqlite3_result_null(context);
return;
}
sqlite3_value_int(argv[0])?sqlite3_result_value(context,
argv[1]):sqlite3_result_value(context, argv[2]);
return;
}
That worked fine. My second try was a LEFT function which was intended
to return a specified number of characters from a given string.
It looked like so:
sqlite3_create_function(DB, "left", 2, SQLITE_UTF8, NULL, &funcLEFT,
NULL, NULL);
static void funcLEFT(sqlite3_context *context, int argc, sqlite3_value
**argv) {
if(argc!=2) {
sqlite3_result_null(context);
return;
}
const char *inString=(const char *)sqlite3_value_text(argv[0]);
sqlite_int64 iLen=sqlite3_value_int64(argv[1]);
sqlite3_result_text(context, inString, iLen, NULL);
return;
}
The sqlite3_result_text(...) function is very good for my goal but when
I tried to use my function with a statement like:
SELECT left('Hallo Du!', 5);
I got: "near "(" : syntax error"
This is - I assume - because LEFT is already a keyword with a special
meaning as stated in http://www.sqlite.org/lang.html#keywords and can
therefore not be used as a function name.
Is that true? Is there a possibility to check whether a string is a
possible function name?
All the best,
Bernhard