Skip to content

Commit abb5d2a

Browse files
committed
add support for unicode in the lower and upper functions in the built-in sqlite
closes #155
1 parent f259d76 commit abb5d2a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/webserver/database/connect.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{app_config::AppConfig, ON_CONNECT_FILE};
55
use sqlx::{
66
any::{Any, AnyConnectOptions, AnyKind},
77
pool::PoolOptions,
8+
sqlite::{Function, SqliteFunctionCtx},
89
ConnectOptions, Executor,
910
};
1011

@@ -128,6 +129,18 @@ fn set_custom_connect_options(options: &mut AnyConnectOptions, config: &AppConfi
128129
*sqlite_options = std::mem::take(sqlite_options).extension(extension_name.clone());
129130
}
130131
*sqlite_options = std::mem::take(sqlite_options)
131-
.collation("NOCASE", |a, b| a.to_lowercase().cmp(&b.to_lowercase()));
132+
.collation("NOCASE", |a, b| a.to_lowercase().cmp(&b.to_lowercase()))
133+
.function(Function::new("upper", |ctx: &SqliteFunctionCtx| match ctx
134+
.try_get_arg::<String>(0)
135+
{
136+
Ok(s) => ctx.set_result(s.to_uppercase()),
137+
Err(e) => ctx.set_error(&e.to_string()),
138+
}))
139+
.function(Function::new("lower", |ctx: &SqliteFunctionCtx| match ctx
140+
.try_get_arg::<String>(0)
141+
{
142+
Ok(s) => ctx.set_result(s.to_lowercase()),
143+
Err(e) => ctx.set_error(&e.to_string()),
144+
}));
132145
}
133146
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Checks that the UPPER function is working correctly with unicode characters.
2+
select 'text' as component,
3+
case
4+
when UPPER('é') = 'É' then 'It works !'
5+
else 'It failed ! Expected É, got ' || UPPER('é') || '.'
6+
end as contents;

0 commit comments

Comments
 (0)