use crate::{Result, oci::{self, *, attr::AttrGetInto}};
use libc::c_void;
mod tosql;
pub(crate) fn to_string(rowid: &OCIRowid, err: &OCIError) -> Result<String> {
if !is_initialized(rowid) {
return Err(crate::Error::new("RowID is not initialized"));
}
let mut text = String::with_capacity(20);
let txt = unsafe { text.as_mut_vec() };
let mut len = txt.capacity();
oci::rowid_to_char(rowid, txt.as_mut_ptr(), &mut len as *mut usize as _, err)?;
unsafe {
txt.set_len(len);
}
Ok( text )
}
pub(crate) fn is_initialized(rowid: &OCIRowid) -> bool {
let ptr: *const u8 = (rowid as *const OCIRowid).cast();
let mem = std::ptr::slice_from_raw_parts(ptr, 32);
let mem = unsafe { &*mem };
mem[16..26].iter().any(|&b| b != 0)
}
pub struct RowID (Descriptor<OCIRowid>);
impl RowID {
pub fn new(env: &impl AsRef<OCIEnv>) -> Result<Self> {
let desc = Descriptor::new(env)?;
Ok( Self(desc) )
}
pub(crate) fn from(rowid: Descriptor<OCIRowid>) -> Self {
Self(rowid)
}
pub fn to_string(&self, err: &impl AsRef<OCIError>) -> Result<String> {
to_string(&self.0, err.as_ref())
}
}
impl AttrGetInto for RowID {
fn as_mut_ptr(&mut self) -> *mut c_void {
self.0.get_ptr().get() as _
}
}