Skip to content

Commit

Permalink
Merge pull request #147 from fernandobatels/feature-146
Browse files Browse the repository at this point in the history
Custom blob subtypes
  • Loading branch information
fernandobatels authored Oct 22, 2023
2 parents f7b007e + 13b6d24 commit 674a9d1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rsfbclient-diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "2.0.0", default-features = false, features = ["chrono", "i-implement-a-third-party-backend-and-opt-into-breaking-changes"]}
diesel = { version = "=2.0.0", default-features = false, features = ["chrono", "i-implement-a-third-party-backend-and-opt-into-breaking-changes"]}
rsfbclient = { version = "0.23.0", path = "../", default-features = false }
byteorder = "1.4.3"
bytes = "1.0.1"
Expand Down
7 changes: 4 additions & 3 deletions rsfbclient-native/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ impl ColumnBuffer {
Boolean(Box::new(0))
}

// BLOB sql_type text are considered a normal text on read
ibase::SQL_BLOB if (sqlsubtype == 0 || sqlsubtype == 1) => {
ibase::SQL_BLOB if (sqlsubtype <= 1) => {
let blob_id = Box::new(ibase::GDS_QUAD_t {
gds_quad_high: 0,
gds_quad_low: 0,
});

var.sqltype = ibase::SQL_BLOB as i16 + 1;

if sqlsubtype == 0 {
// subtype 0: binary
// subtype <= -1: custom
if sqlsubtype <= 0 {
BlobBinary(blob_id)
} else {
BlobText(blob_id)
Expand Down
2 changes: 1 addition & 1 deletion rsfbclient-rust/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ pub fn parse_sql_response(
}
}

ibase::SQL_BLOB if var.sqlsubtype == 0 || var.sqlsubtype == 1 => {
ibase::SQL_BLOB if var.sqlsubtype <= 1 => {
let id = resp.get_u64()?;

let null = read_null(resp, col_index)?;
Expand Down
2 changes: 1 addition & 1 deletion rsfbclient-rust/src/xsqlda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl XSqlVar {
self.sqltype = ibase::SQL_TIMESTAMP as i16 + 1;
}

ibase::SQL_BLOB if (sqlsubtype == 0 || sqlsubtype == 1) => {
ibase::SQL_BLOB if sqlsubtype <= 1 => {
self.sqltype = ibase::SQL_BLOB as i16 + 1;
}

Expand Down
12 changes: 12 additions & 0 deletions src/tests/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ mk_tests_default! {
Ok(())
}

#[test]
fn blob_custom_subtype() -> Result<(), FbError> {
let mut conn = cbuilder().connect()?;

let (a,): (Option<Vec<u8>>,) = conn.query_first("select cast(null as blob SUB_TYPE -1) from rdb$database;", ())?
.unwrap();

assert_eq!(None, a);

Ok(())
}

#[test]
fn dates() -> Result<(), FbError> {
let mut conn = cbuilder().connect()?;
Expand Down

0 comments on commit 674a9d1

Please sign in to comment.