diff options
author | drh <> | 2023-06-03 11:22:30 +0000 |
---|---|---|
committer | drh <> | 2023-06-03 11:22:30 +0000 |
commit | b3d7f1c2db60a94639d0f5be204f947d4e56b475 (patch) | |
tree | bbd05b5535550283f86dc7943b51f0f5d776512d /src/func.c | |
parent | f1967a70189eaee5914012da39d5dfb7ced77c1d (diff) | |
download | sqlite-b3d7f1c2db60a94639d0f5be204f947d4e56b475.tar.gz sqlite-b3d7f1c2db60a94639d0f5be204f947d4e56b475.zip |
Prototype implementation of the octet_length() SQL function.
FossilOrigin-Name: 2db989c8635f7e89b3ea58d1fde94787fced039ac1a118d9b6362811eda73f87
Diffstat (limited to 'src/func.c')
-rw-r--r-- | src/func.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/func.c b/src/func.c index 4d0da5ded..bcd75ff67 100644 --- a/src/func.c +++ b/src/func.c @@ -150,6 +150,42 @@ static void lengthFunc( } /* +** Implementation of the octet_length() function +*/ +static void bytelengthFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + assert( argc==1 ); + UNUSED_PARAMETER(argc); + switch( sqlite3_value_type(argv[0]) ){ + case SQLITE_BLOB: { + sqlite3_result_int(context, sqlite3_value_bytes(argv[0])); + break; + } + case SQLITE_INTEGER: + case SQLITE_FLOAT: { + i64 m = sqlite3_context_db_handle(context)->enc<=SQLITE_UTF8 ? 1 : 2; + sqlite3_result_int64(context, sqlite3_value_bytes(argv[0])*m); + break; + } + case SQLITE_TEXT: { + if( sqlite3_value_encoding(argv[0])<=SQLITE_UTF8 ){ + sqlite3_result_int(context, sqlite3_value_bytes(argv[0])); + }else{ + sqlite3_result_int(context, sqlite3_value_bytes16(argv[0])); + } + break; + } + default: { + sqlite3_result_null(context); + break; + } + } +} + +/* ** Implementation of the abs() function. ** ** IMP: R-23979-26855 The abs(X) function returns the absolute value of @@ -2376,6 +2412,7 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF), FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), + FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_LENGTH), FUNCTION(instr, 2, 0, 0, instrFunc ), FUNCTION(printf, -1, 0, 0, printfFunc ), FUNCTION(format, -1, 0, 0, printfFunc ), |