use crate::to_rust_str;
#[cfg(doc)]
use crate::Connection;
use crate::Error;
use crate::Result;
use odpic_sys::*;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum CloseMode<'a> {
Default,
Drop,
Retag(&'a str),
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Purity {
New,
Self_,
}
impl Purity {
pub(crate) fn to_dpi(self) -> dpiPurity {
match self {
Purity::New => DPI_PURITY_NEW,
Purity::Self_ => DPI_PURITY_SELF,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ServerType {
Dedicated,
Pooled,
Shared,
Unknown,
}
impl ServerType {
pub(crate) fn from_dpi(server_type: u8) -> Result<ServerType> {
match server_type as u32 {
DPI_SERVER_TYPE_DEDICATED => Ok(ServerType::Dedicated),
DPI_SERVER_TYPE_POOLED => Ok(ServerType::Pooled),
DPI_SERVER_TYPE_SHARED => Ok(ServerType::Shared),
DPI_SERVER_TYPE_UNKNOWN => Ok(ServerType::Unknown),
_ => Err(Error::internal_error(format!(
"Unknown dpiServerType {}",
server_type
))),
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct Info {
pub db_domain: String,
pub db_name: String,
pub instance_name: String,
pub service_name: String,
pub max_identifier_length: u32,
pub max_open_cursors: u32,
pub server_type: ServerType,
}
impl Info {
pub(crate) fn from_dpi(info: &dpiConnInfo) -> Result<Info> {
Ok(Info {
db_domain: to_rust_str(info.dbDomain, info.dbDomainLength),
db_name: to_rust_str(info.dbName, info.dbNameLength),
instance_name: to_rust_str(info.instanceName, info.instanceNameLength),
service_name: to_rust_str(info.serviceName, info.serviceNameLength),
max_identifier_length: info.maxIdentifierLength,
max_open_cursors: info.maxOpenCursors,
server_type: ServerType::from_dpi(info.serverType)?,
})
}
}