mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-07 10:14:21 +01:00
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:
@@ -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()),
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user