diff --git a/modules/data/Cargo.toml b/modules/data/Cargo.toml index 4b96178e..2882ab55 100644 --- a/modules/data/Cargo.toml +++ b/modules/data/Cargo.toml @@ -15,7 +15,7 @@ sqlite = ["assembly-fdb/sqlite"] serde-derives = ["assembly-fdb/serde-derives", "assembly-xml/serialize"] [dependencies.assembly-fdb] -version = "0.1.0" +version = "0.2.0" path = "../fdb" [dependencies.assembly-xml] diff --git a/modules/data/examples/xmldb-to-fdb.rs b/modules/data/examples/xmldb-to-fdb.rs index 81fc61cc..800843a4 100644 --- a/modules/data/examples/xmldb-to-fdb.rs +++ b/modules/data/examples/xmldb-to-fdb.rs @@ -68,25 +68,22 @@ fn main() -> color_eyre::Result<()> { while let Some(col) = expect_column_or_end_columns(xml, buf)? { let data_type = match col.r#type { - ValueType::Bit => common::ValueType::Boolean, - ValueType::Float => common::ValueType::Float, - ValueType::Real => common::ValueType::Float, - ValueType::Int => common::ValueType::Integer, - ValueType::BigInt => common::ValueType::BigInt, - ValueType::SmallInt => common::ValueType::Integer, - ValueType::TinyInt => common::ValueType::Integer, - ValueType::Binary => common::ValueType::Text, - ValueType::VarBinary => common::ValueType::Text, - ValueType::Char => common::ValueType::Text, - ValueType::VarChar => common::ValueType::Text, - ValueType::NChar => common::ValueType::Text, - ValueType::NVarChar => common::ValueType::Text, - ValueType::NText => common::ValueType::VarChar, - ValueType::Text => common::ValueType::VarChar, - ValueType::Image => common::ValueType::VarChar, - ValueType::DateTime => common::ValueType::BigInt, - ValueType::Xml => common::ValueType::VarChar, ValueType::Null => common::ValueType::Nothing, + ValueType::Bit => common::ValueType::Boolean, + ValueType::Float | ValueType::Real => common::ValueType::Float, + ValueType::Int | ValueType::SmallInt | ValueType::TinyInt => { + common::ValueType::Integer + } + ValueType::BigInt | ValueType::DateTime => common::ValueType::BigInt, + ValueType::Binary + | ValueType::VarBinary + | ValueType::Char + | ValueType::VarChar + | ValueType::NChar + | ValueType::NVarChar => common::ValueType::Text, + ValueType::NText | ValueType::Text | ValueType::Image | ValueType::Xml => { + common::ValueType::Xml + } }; if col_map.is_empty() { // first col @@ -121,7 +118,7 @@ fn main() -> color_eyre::Result<()> { common::ValueType::Text => core::Field::Text(src_value), common::ValueType::Boolean => core::Field::Boolean(&src_value != "0"), common::ValueType::BigInt => core::Field::BigInt(src_value.parse().unwrap()), - common::ValueType::VarChar => core::Field::VarChar(src_value), + common::ValueType::Xml => core::Field::Xml(src_value), }; if col_index == 0 { @@ -136,7 +133,7 @@ fn main() -> color_eyre::Result<()> { let lat1 = Latin1String::encode(text); pk = Some((lat1.hash() % 128) as usize); } - core::Field::VarChar(var_char) => { + core::Field::Xml(var_char) => { let lat1 = Latin1String::encode(var_char); pk = Some((lat1.hash() % 128) as usize); } diff --git a/modules/fdb/Cargo.toml b/modules/fdb/Cargo.toml index 8ae95945..fe40bfe5 100644 --- a/modules/fdb/Cargo.toml +++ b/modules/fdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "assembly-fdb" -version = "0.1.0" +version = "0.2.0" edition = "2018" license = "MIT or Apache-2.0" diff --git a/modules/fdb/examples/fdb-index.rs b/modules/fdb/examples/fdb-index.rs index 3cce6887..d9fd20ee 100644 --- a/modules/fdb/examples/fdb-index.rs +++ b/modules/fdb/examples/fdb-index.rs @@ -28,7 +28,7 @@ fn field_to_cell(field: mem::Field) -> PCell { Field::Text(v) => PCell::new(&format!("{:?}", v)), Field::Boolean(v) => PCell::new(if v { "true" } else { "false" }), Field::BigInt(v) => PCell::new(&format!("{} (i64)", v)), - Field::VarChar(v) => PCell::new(&format!("{:?}", v)), + Field::Xml(v) => PCell::new(&format!("{:?}", v)), } } diff --git a/modules/fdb/examples/fdb-stat.rs b/modules/fdb/examples/fdb-stat.rs index 40a858c1..02824994 100644 --- a/modules/fdb/examples/fdb-stat.rs +++ b/modules/fdb/examples/fdb-stat.rs @@ -61,7 +61,7 @@ fn main() -> color_eyre::Result<()> { ValueType::Text => text_column_count += 1, ValueType::Boolean => bool_column_count += 1, ValueType::BigInt => bigint_column_count += 1, - ValueType::VarChar => xml_column_count += 1, + ValueType::Xml => xml_column_count += 1, } } @@ -81,7 +81,7 @@ fn main() -> color_eyre::Result<()> { Value::Text(_) => text_field_count += 1, Value::Boolean(_) => bool_field_count += 1, Value::BigInt(_) => bigint_field_count += 1, - Value::VarChar(_) => xml_field_count += 1, + Value::Xml(_) => xml_field_count += 1, } } } diff --git a/modules/fdb/examples/sqlite-to-fdb.rs b/modules/fdb/examples/sqlite-to-fdb.rs index 2106879d..eb6597d5 100644 --- a/modules/fdb/examples/sqlite-to-fdb.rs +++ b/modules/fdb/examples/sqlite-to-fdb.rs @@ -124,7 +124,7 @@ fn main() -> eyre::Result<()> { ValueRef::Real(f) => Field::Float(f as f32), ValueRef::Text(t) => match target_types[index] { ValueType::Text => Field::Text(String::from(std::str::from_utf8(t)?)), - ValueType::VarChar => Field::VarChar(String::from(std::str::from_utf8(t)?)), + ValueType::Xml => Field::Xml(String::from(std::str::from_utf8(t)?)), _ => { return Err(eyre!( "Invalid target datatype; cannot store SQLite Text as FDB {:?}", diff --git a/modules/fdb/src/common.rs b/modules/fdb/src/common.rs index 9f6a13f4..ceb7ba37 100644 --- a/modules/fdb/src/common.rs +++ b/modules/fdb/src/common.rs @@ -210,7 +210,7 @@ pub enum Value { /// A 64 bit integer BigInt(T::I64), /// A (XML?) string - VarChar(T::XML), + Xml(T::XML), } impl Clone for Value @@ -227,7 +227,7 @@ where Value::Text(v) => Value::Text(v.clone()), Value::Boolean(v) => Value::Boolean(*v), Value::BigInt(v) => Value::BigInt(v.clone()), - Value::VarChar(v) => Value::VarChar(v.clone()), + Value::Xml(v) => Value::Xml(v.clone()), } } } @@ -254,7 +254,7 @@ impl Value { Value::Text(v) => Value::Text(mapper.map_string(v)), Value::Boolean(v) => Value::Boolean(*v), Value::BigInt(v) => Value::BigInt(mapper.map_i64(v)), - Value::VarChar(v) => Value::VarChar(mapper.map_xml(v)), + Value::Xml(v) => Value::Xml(mapper.map_xml(v)), } } @@ -305,7 +305,7 @@ impl Value { /// Returns `Some` with the value if the field contains a [`Value::VarChar`]. pub fn into_opt_varchar(self) -> Option { - if let Self::VarChar(value) = self { + if let Self::Xml(value) = self { Some(value) } else { None @@ -322,7 +322,7 @@ impl From<&Value> for ValueType { Value::Text(_) => ValueType::Text, Value::Boolean(_) => ValueType::Boolean, Value::BigInt(_) => ValueType::BigInt, - Value::VarChar(_) => ValueType::VarChar, + Value::Xml(_) => ValueType::Xml, } } } @@ -344,7 +344,7 @@ pub enum ValueType { /// A 64 bit integer BigInt, /// An (XML?) string - VarChar, + Xml, } impl ValueType { @@ -357,7 +357,7 @@ impl ValueType { ValueType::Text => "TEXT", ValueType::Boolean => "BOOLEAN", ValueType::BigInt => "BIGINT", - ValueType::VarChar => "VARCHAR", + ValueType::Xml => "VARCHAR", } } } @@ -377,7 +377,7 @@ impl From for u8 { ValueType::Text => 4, ValueType::Boolean => 5, ValueType::BigInt => 6, - ValueType::VarChar => 8, + ValueType::Xml => 8, } } } @@ -417,7 +417,7 @@ impl TryFrom for ValueType { 4 => Ok(ValueType::Text), 5 => Ok(ValueType::Boolean), 6 => Ok(ValueType::BigInt), - 8 => Ok(ValueType::VarChar), + 8 => Ok(ValueType::Xml), _ => Err(UnknownValueType(value_type)), } } diff --git a/modules/fdb/src/core/mod.rs b/modules/fdb/src/core/mod.rs index 7e61580e..ee83dc10 100644 --- a/modules/fdb/src/core/mod.rs +++ b/modules/fdb/src/core/mod.rs @@ -48,7 +48,7 @@ impl From> for Field { MemField::Text(v) => Field::Text(v.decode().into_owned()), MemField::Boolean(v) => Field::Boolean(v), MemField::BigInt(v) => Field::BigInt(v), - MemField::VarChar(v) => Field::VarChar(v.decode().into_owned()), + MemField::Xml(v) => Field::Xml(v.decode().into_owned()), } } } @@ -62,7 +62,7 @@ impl PartialEq> for Field { Value::Text(x) => matches!(self, Self::Text(y) if x.decode().as_ref() == y), Value::Boolean(x) => matches!(self, Self::Boolean(y) if x == y), Value::BigInt(x) => matches!(self, Self::BigInt(y) if x == y), - Value::VarChar(x) => matches!(self, Self::VarChar(y) if x.decode().as_ref() == y), + Value::Xml(x) => matches!(self, Self::Xml(y) if x.decode().as_ref() == y), } } } @@ -76,7 +76,7 @@ impl fmt::Display for Field { Field::Text(t) => write!(f, "{:?}", t), Field::Boolean(b) => write!(f, "{}", b), Field::BigInt(i) => write!(f, "{}", i), - Field::VarChar(v) => write!(f, "{:?}", v), + Field::Xml(v) => write!(f, "{:?}", v), } } } diff --git a/modules/fdb/src/file/mod.rs b/modules/fdb/src/file/mod.rs index a48a2944..001a0043 100644 --- a/modules/fdb/src/file/mod.rs +++ b/modules/fdb/src/file/mod.rs @@ -233,7 +233,7 @@ impl TryFrom for FDBFieldValue { ValueType::BigInt => FDBFieldValue::BigInt(IndirectValue { addr: u32::from_le_bytes(value.value), }), - ValueType::VarChar => FDBFieldValue::VarChar(IndirectValue { + ValueType::Xml => FDBFieldValue::Xml(IndirectValue { addr: u32::from_le_bytes(value.value), }), }) diff --git a/modules/fdb/src/mem/c.rs b/modules/fdb/src/mem/c.rs index 33603fe5..bd92501a 100644 --- a/modules/fdb/src/mem/c.rs +++ b/modules/fdb/src/mem/c.rs @@ -196,7 +196,7 @@ impl Repr for FDBFieldDataC { ValueType::BigInt => FDBFieldValue::BigInt(IndirectValue { addr: u32::from_le_bytes(self.value.0), }), - ValueType::VarChar => FDBFieldValue::VarChar(IndirectValue { + ValueType::Xml => FDBFieldValue::Xml(IndirectValue { addr: u32::from_le_bytes(self.value.0), }), } diff --git a/modules/fdb/src/mem/mod.rs b/modules/fdb/src/mem/mod.rs index 72e6d24c..ad3bb94b 100644 --- a/modules/fdb/src/mem/mod.rs +++ b/modules/fdb/src/mem/mod.rs @@ -377,10 +377,10 @@ fn get_field_raw(buf: Buffer, data_type: ValueType, bytes: [u8; 4]) -> Field { let val = buf.cast::(addr).extract(); Field::BigInt(val) } - ValueType::VarChar => { + ValueType::Xml => { let addr = u32::from_le_bytes(bytes); let text = get_latin1_str(buf.as_bytes(), addr); - Field::VarChar(text) + Field::Xml(text) } } } diff --git a/modules/fdb/src/reader/builder.rs b/modules/fdb/src/reader/builder.rs index a8f07cdc..841ebe7d 100644 --- a/modules/fdb/src/reader/builder.rs +++ b/modules/fdb/src/reader/builder.rs @@ -54,10 +54,10 @@ where .and_then(|addr| self.get_i64(addr)) .map(Field::BigInt) .map_err(Into::into), - ValueType::VarChar => Ok(bytes) + ValueType::Xml => Ok(bytes) .map(u32::from_le_bytes) .and_then(|addr| self.get_string(addr)) - .map(Field::VarChar) + .map(Field::Xml) .map_err(Into::into), } } diff --git a/modules/fdb/src/sqlite.rs b/modules/fdb/src/sqlite.rs index 5655f1ff..c6507f14 100644 --- a/modules/fdb/src/sqlite.rs +++ b/modules/fdb/src/sqlite.rs @@ -20,7 +20,7 @@ impl<'a> ToSql for Field<'a> { Field::Text(s) => Value::Text(s.decode().into_owned()), Field::Boolean(b) => Value::Integer(if b { 1 } else { 0 }), Field::BigInt(i) => Value::Integer(i), - Field::VarChar(b) => Value::Text(b.decode().into_owned()), + Field::Xml(b) => Value::Text(b.decode().into_owned()), }; Ok(ToSqlOutput::Owned(r)) } @@ -36,7 +36,7 @@ impl ValueType { ValueType::Text => "TEXT4", ValueType::Boolean => "INT_BOOL", ValueType::BigInt => "INT64", - ValueType::VarChar => "TEXT_XML", + ValueType::Xml => "TEXT_XML", } } @@ -77,9 +77,7 @@ impl ValueType { "TEXT4" | "text_4" | "TEXT" => Some(ValueType::Text), "BIT" | "INT_BOOL" | "int_bool" => Some(ValueType::Boolean), "INT64" | "int64" | "BIGINT" | "INTEGER" => Some(ValueType::BigInt), - "XML" | "TEXT_XML" | "xml" | "text_8" | "text_xml" | "VARCHAR" => { - Some(ValueType::VarChar) - } + "XML" | "TEXT_XML" | "xml" | "text_8" | "text_xml" | "VARCHAR" => Some(ValueType::Xml), _ => None, } } diff --git a/modules/fdb/src/store/mod.rs b/modules/fdb/src/store/mod.rs index 2f7787f3..79f97942 100644 --- a/modules/fdb/src/store/mod.rs +++ b/modules/fdb/src/store/mod.rs @@ -379,7 +379,7 @@ impl Table { let v = i64s_base_offset + (i64_ref.index * size_of::()) as u32; v.to_le_bytes() }), - Field::VarChar(text_ref) => (8, { + Field::Xml(text_ref) => (8, { let v = string_len_offsets.get(&text_ref.outer).unwrap() + (text_ref.inner * text_ref.outer * 4) as u32; v.to_le_bytes() diff --git a/modules/sysdiagram/Cargo.toml b/modules/sysdiagram/Cargo.toml index 67d71ceb..617ac117 100644 --- a/modules/sysdiagram/Cargo.toml +++ b/modules/sysdiagram/Cargo.toml @@ -20,6 +20,6 @@ displaydoc = "0.1" thiserror = "1.0" [dev-dependencies] -assembly-fdb = { path = "../fdb", version = "0.1.0" } +assembly-fdb = { path = "../fdb", version = "0.2.0" } anyhow = "1.0" getopts = "0.2"