use super::*;
use sys::*;
use std::mem::size_of;
use std::os::raw::c_void;
use std::ptr::{null, null_mut};
pub unsafe trait CDataType {
fn c_data_type() -> SqlCDataType;
fn sql_ptr(&self) -> *const c_void;
fn mut_sql_ptr(&mut self) -> SQLPOINTER;
fn buffer_len(&self) -> SQLLEN;
}
unsafe impl CDataType for [SQLCHAR] {
fn c_data_type() -> SqlCDataType {
SQL_C_BINARY
}
fn sql_ptr(&self) -> *const c_void {
if self.is_empty() {
null()
} else {
self.as_ptr() as SQLPOINTER
}
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
if self.is_empty() {
null_mut()
} else {
self.as_mut_ptr() as SQLPOINTER
}
}
fn buffer_len(&self) -> SQLLEN {
self.buf_len()
}
}
unsafe impl CDataType for SQLSMALLINT {
fn c_data_type() -> SqlCDataType {
SQL_C_SSHORT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for SQLUSMALLINT {
fn c_data_type() -> SqlCDataType {
SQL_C_USHORT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for SQLINTEGER {
fn c_data_type() -> SqlCDataType {
SQL_C_SLONG
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for SQLUINTEGER {
fn c_data_type() -> SqlCDataType {
SQL_C_ULONG
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for f32 {
fn c_data_type() -> SqlCDataType {
SQL_C_FLOAT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for f64 {
fn c_data_type() -> SqlCDataType {
SQL_C_DOUBLE
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for i8 {
fn c_data_type() -> SqlCDataType {
SQL_C_STINYINT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for SQLCHAR {
fn c_data_type() -> SqlCDataType {
SQL_C_UTINYINT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for i64 {
fn c_data_type() -> SqlCDataType {
SQL_C_SBIGINT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}
unsafe impl CDataType for u64 {
fn c_data_type() -> SqlCDataType {
SQL_C_UBIGINT
}
fn sql_ptr(&self) -> *const c_void {
let ptr: *const Self = self;
ptr as *const c_void
}
fn mut_sql_ptr(&mut self) -> SQLPOINTER {
let ptr: *mut Self = self;
ptr as SQLPOINTER
}
fn buffer_len(&self) -> SQLLEN {
size_of::<Self>() as SQLLEN
}
}