Created
April 26, 2021 12:18
-
-
Save little-brother/074047adcca02a0845fdc4d7db0491dc to your computer and use it in GitHub Desktop.
SQLite scalar function example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void square (sqlite3_context *ctx, int argc, sqlite3_value **argv) { | |
| int type = sqlite3_value_type(argv[0]); | |
| double d = sqlite3_value_double(argv[0]); | |
| switch (type) { | |
| case SQLITE_NULL: | |
| sqlite3_result_null(ctx); | |
| break; | |
| case SQLITE_INTEGER: | |
| case SQLITE_FLOAT: | |
| sqlite3_result_double(ctx, d * d); | |
| break; | |
| case SQLITE_TEXT: | |
| case SQLITE_BLOB: | |
| sqlite3_result_error(ctx, "Unsupported", -1); | |
| break; | |
| default: | |
| sqlite3_result_error(ctx, "Impossible", -1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment