Skip to content

Commit

Permalink
Add 'ColumnType::Inet' support for the prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
vponomaryov authored and pkolaczk committed Jul 5, 2024
1 parent 1e4db83 commit f74e5c0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io;
use std::io::{BufRead, BufReader, ErrorKind, Read};
use std::net::IpAddr;
use std::str::FromStr;
use std::sync::Arc;

use anyhow::anyhow;
Expand Down Expand Up @@ -635,6 +637,29 @@ mod bind {
(Value::String(v), ColumnType::Text | ColumnType::Ascii) => {
Ok(CqlValue::Text(v.borrow_ref().unwrap().as_str().to_string()))
}
(Value::StaticString(v), ColumnType::Inet) => {
let ipaddr = IpAddr::from_str(v);
match ipaddr {
Ok(ipaddr) => Ok(CqlValue::Inet(ipaddr)),
Err(e) => {
Err(CassError(CassErrorKind::WrongDataStructure(
format!("Failed to parse '{}' StaticString as IP address: {}", v.as_str(), e),
)))
}
}
}
(Value::String(v), ColumnType::Inet) => {
let ipaddr_str = v.borrow_ref().unwrap();
let ipaddr = IpAddr::from_str(ipaddr_str.as_str());
match ipaddr {
Ok(ipaddr) => Ok(CqlValue::Inet(ipaddr)),
Err(e) => {
Err(CassError(CassErrorKind::WrongDataStructure(
format!("Failed to parse '{}' String as IP address: {}", ipaddr_str.as_str(), e),
)))
}
}
}

(Value::Bytes(v), ColumnType::Blob) => {
Ok(CqlValue::Blob(v.borrow_ref().unwrap().to_vec()))
Expand Down

0 comments on commit f74e5c0

Please sign in to comment.