Skip to content

add raw_type to column #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rsfbclient-core/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ impl Row {
#[derive(Debug, Clone)]
pub struct Column {
pub value: SqlType,
pub raw_type: u32,
pub name: String,
}

impl Column {
pub fn new(name: String, value: SqlType) -> Self {
Column { name, value }
pub fn new(name: String, raw_type: u32, value: SqlType) -> Self {
Column {
name,
raw_type,
value,
}
}
}

Expand Down
15 changes: 13 additions & 2 deletions rsfbclient-native/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub struct ColumnBuffer {

/// Column name
col_name: String,

raw_type: i16,
}

impl ColumnBuffer {
Expand Down Expand Up @@ -154,6 +156,7 @@ impl ColumnBuffer {
buffer,
nullind,
col_name,
raw_type: sqltype,
})
}

Expand All @@ -166,7 +169,11 @@ impl ColumnBuffer {
charset: &Charset,
) -> Result<Column, FbError> {
if *self.nullind != 0 {
return Ok(Column::new(self.col_name.clone(), SqlType::Null));
return Ok(Column::new(
self.col_name.clone(),
self.raw_type as u32,
SqlType::Null,
));
}

let col_type = match &self.buffer {
Expand All @@ -185,7 +192,11 @@ impl ColumnBuffer {
Boolean(b) => SqlType::Boolean(**b != 0),
};

Ok(Column::new(self.col_name.clone(), col_type))
Ok(Column::new(
self.col_name.clone(),
self.raw_type as u32,
col_type,
))
}
}

Expand Down
19 changes: 16 additions & 3 deletions rsfbclient-rust/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,19 @@
let mut data = Vec::with_capacity(xsqlda.len());

for (col_index, var) in xsqlda.iter().enumerate() {
// Remove nullable type indicator
let sqltype = var.sqltype as u32 & (!1);

if version >= ProtocolVersion::V13 && read_null(resp, col_index)? {
// There is no data in protocol 13 if null, so just continue
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)));
continue;
}

// Remove nullable type indicator
let sqltype = var.sqltype as u32 & (!1);

match sqltype {
ibase::SQL_VARYING => {
let d = resp.get_wire_bytes()?;
Expand All @@ -606,11 +607,13 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Text(charset.decode(&d[..])?),
)))
}
Expand All @@ -623,11 +626,13 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Integer(i),
)))
}
Expand All @@ -640,11 +645,13 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Floating(f),
)))
}
Expand All @@ -660,11 +667,13 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Timestamp(rsfbclient_core::date_time::decode_timestamp(ts)),
)))
}
Expand All @@ -677,6 +686,7 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
Expand All @@ -697,11 +707,13 @@
if null {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Null,
)))
} else {
data.push(ParsedColumn::Complete(Column::new(
var.alias_name.clone(),
sqltype,
SqlType::Boolean(b),
)))
}
Expand Down Expand Up @@ -767,6 +779,7 @@

Column::new(
col_name,
ibase::SQL_BLOB,
if binary {
SqlType::Binary(data)
} else {
Expand Down Expand Up @@ -869,7 +882,7 @@
pub struct AuthPlugin {
pub kind: AuthPluginType,
pub data: Option<SrpAuthData>,
pub keys: Bytes,

Check warning on line 885 in rsfbclient-rust/src/wire.rs

View workflow job for this annotation

GitHub Actions / testing (macos-latest, v3, pure_rust)

field `keys` is never read

Check warning on line 885 in rsfbclient-rust/src/wire.rs

View workflow job for this annotation

GitHub Actions / testing (macos-latest, v3, pure_rust)

field `keys` is never read

Check warning on line 885 in rsfbclient-rust/src/wire.rs

View workflow job for this annotation

GitHub Actions / testing (macos-latest, v3, pure_rust)

field `keys` is never read

Check warning on line 885 in rsfbclient-rust/src/wire.rs

View workflow job for this annotation

GitHub Actions / testing (windows-latest, v5, pure_rust)

field `keys` is never read

Check warning on line 885 in rsfbclient-rust/src/wire.rs

View workflow job for this annotation

GitHub Actions / testing (windows-latest, v5, pure_rust)

field `keys` is never read
}

/// Parse the connect response response (`WireOp::Accept`, `WireOp::AcceptData`, `WireOp::CondAccept` )
Expand Down
16 changes: 16 additions & 0 deletions src/tests/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
(),
)?
.unwrap();
assert_eq!(NaiveDate::from_ymd(2010, 10, 10), a);

Check warning on line 227 in src/tests/row.rs

View workflow job for this annotation

GitHub Actions / testing (windows-latest, v5, dynamic_loading)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead

Check warning on line 227 in src/tests/row.rs

View workflow job for this annotation

GitHub Actions / testing (windows-latest, v5, linking)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead
assert_eq!(NaiveDate::from_ymd(2010, 10, 10).and_hms(10, 10, 10), b);
assert_eq!(NaiveTime::from_hms(10, 10, 10), c);

Expand Down Expand Up @@ -411,6 +411,22 @@
assert_eq!(res, col);
}

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

let row: Row = conn
.query_first(
"select cast('firebird' as varchar(8)), cast('firebird' as char(8)) from rdb$database",
(),
)?
.unwrap();
assert_eq!(2, row.cols.len());

assert_eq!(448, row.cols.first().unwrap().raw_type);

Ok(())
}
}
Loading