From 4c728cc02e0dbc91da4616b7117586b2e5ce03e5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Batels Date: Tue, 10 Oct 2023 22:16:43 -0300 Subject: [PATCH] Custom blob subtypes Support for custom blob subtypes added. Blob subtypes supported now: - 1: TEXT - 0: binary - <= -1: custom Issue #146 --- rsfbclient-native/src/row.rs | 7 ++++--- rsfbclient-rust/src/xsqlda.rs | 2 +- src/tests/row.rs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/rsfbclient-native/src/row.rs b/rsfbclient-native/src/row.rs index bcb3faf..6e8adf9 100644 --- a/rsfbclient-native/src/row.rs +++ b/rsfbclient-native/src/row.rs @@ -76,8 +76,7 @@ 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, @@ -85,7 +84,9 @@ impl ColumnBuffer { 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) diff --git a/rsfbclient-rust/src/xsqlda.rs b/rsfbclient-rust/src/xsqlda.rs index f23dd4b..a22f1f6 100644 --- a/rsfbclient-rust/src/xsqlda.rs +++ b/rsfbclient-rust/src/xsqlda.rs @@ -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; } diff --git a/src/tests/row.rs b/src/tests/row.rs index 9c29d9b..a8ed52b 100644 --- a/src/tests/row.rs +++ b/src/tests/row.rs @@ -202,6 +202,18 @@ mk_tests_default! { Ok(()) } + #[test] + fn blob_custom_subtype() -> Result<(), FbError> { + let mut conn = cbuilder().connect()?; + + let (a,): (Option>,) = 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()?;