Answer the question
In order to leave comments, you need to log in
How to add your own function to qsqlitedriver?
I made the money() function. Through .load in the shell it works. Now I'm trying to push it into qsqltedriver. Crashes on SELECT money(100) query. I read that you need to add sqlite3_create_fuction to open().
static void moneyFunc(
sqlite3_context *context,
int agrc,
sqlite3_value **argv
){
char *result = NULL;
int sum = sqlite3_value_int(argv[0]);
int full = sum / 100;
int dec = sum % 100;
if (dec == 0){
snprintf(result, 8, "%d,00", full);
} else if (dec > 0 && dec < 10){
snprintf(result, 8, "%d,0%d", full, dec);
} else if (dec >= 10 && dec <= 99){
snprintf(result, 8, "%d,%d", full, dec);
} else return;
sqlite3_result_text(context, result, 8, 0);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question