use crate::error::{Error, Result};
use crate::spec::{Backend, OracleCollation, OracleProvider};
pub(crate) fn validate(spec: &OracleCollation) -> Result<Backend> {
if !spec.charset().eq_ignore_ascii_case("AL32UTF8") {
return Err(Error::unsupported(
"oracle",
spec.nls_sort(),
"only the AL32UTF8 character set is reproducible",
));
}
if spec.blank_padded() {
return Err(Error::unsupported(
"oracle",
spec.nls_sort(),
"blank-padded CHAR/NCHAR comparison differs from VARCHAR2 and is not modelled",
));
}
match spec.provider() {
OracleProvider::Binary => {
if spec.nls_sort().eq_ignore_ascii_case("BINARY") {
Ok(Backend::Binary)
} else {
Err(Error::unsupported(
"oracle",
spec.nls_sort(),
"only NLS_SORT=BINARY is modelled for the binary provider",
))
}
}
OracleProvider::Uca => {
#[cfg(feature = "oracle-uca")]
{
let version = spec.uca_version().ok_or_else(|| {
Error::unsupported("oracle", spec.nls_sort(), "UCA collation has no version")
})?;
if spec.nls_sort() != version.collation_name() {
return Err(Error::unsupported(
"oracle",
spec.nls_sort(),
"only UCA0700_DUCET and UCA1210_DUCET are reproducible",
));
}
Ok(Backend::Oracle(spec.clone()))
}
#[cfg(not(feature = "oracle-uca"))]
{
let _ = spec;
Err(Error::FeatureDisabled {
feature: "oracle-uca",
})
}
}
}
}
#[cfg(feature = "oracle-uca")]
pub(crate) fn compare(spec: &OracleCollation, a: &str, b: &str) -> Result<core::cmp::Ordering> {
match spec.provider() {
OracleProvider::Uca => {
let version = spec
.uca_version()
.ok_or_else(|| Error::unsupported("oracle", spec.nls_sort(), "no UCA version"))?;
uca::compare(version, a, b).ok_or_else(|| {
Error::input_limit(
"oracle",
"input exceeds Oracle's 2000-byte UCA sort-key limit; \
Oracle truncates the key there and is no longer pure DUCET",
)
})
}
OracleProvider::Binary => Err(Error::unsupported(
"oracle",
spec.nls_sort(),
"binary provider is dispatched to the binary backend",
)),
}
}
#[cfg(feature = "oracle-uca")]
mod uca;
#[cfg(feature = "oracle-uca")]
mod table_uca0700;
#[cfg(feature = "oracle-uca")]
mod table_uca1210;