Merge 'Fix: length function characters counting' from Kacper Kołodziej

`String::len()` function returns number of bytes. Here we need to use
`chars().count()` to count real characters as specified in
https://www.sqlite.org/lang_corefunc.html#length

Fixes #431

Closes #429
This commit is contained in:
Pekka Enberg
2024-12-11 07:42:35 +02:00
2 changed files with 5 additions and 1 deletions

View File

@@ -2537,7 +2537,7 @@ fn exec_lower(reg: &OwnedValue) -> Option<OwnedValue> {
fn exec_length(reg: &OwnedValue) -> OwnedValue {
match reg {
OwnedValue::Text(_) | OwnedValue::Integer(_) | OwnedValue::Float(_) => {
OwnedValue::Integer(reg.to_string().len() as i64)
OwnedValue::Integer(reg.to_string().chars().count() as i64)
}
OwnedValue::Blob(blob) => OwnedValue::Integer(blob.len() as i64),
OwnedValue::Agg(aggctx) => exec_length(aggctx.final_value()),

View File

@@ -343,6 +343,10 @@ do_execsql_test length-text {
SELECT length('limbo');
} {5}
do_execsql_test lenght-text-utf8-chars {
SELECT length('ąłóżźć');
} {6}
do_execsql_test length-integer {
SELECT length(12345);
} {5}