Skip to content

Commit 50ee7b8

Browse files
authored
Revert "Unsigned types support for mysql."
1 parent 192e733 commit 50ee7b8

9 files changed

Lines changed: 10 additions & 106 deletions

File tree

diesel/src/mysql/types/mod.rs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#[cfg(feature = "chrono")]
22
mod date_and_time;
33

4-
use byteorder::{WriteBytesExt};
5-
use mysql::{Mysql, MysqlType, backend};
4+
use mysql::{Mysql, MysqlType};
65
use std::error::Error as StdError;
76
use std::io::Write;
8-
use types::{ToSql, IsNull, FromSql, HasSqlType, Unsigned};
9-
use backend::Backend;
7+
use types::{ToSql, IsNull, FromSql, HasSqlType};
108

119
impl ToSql<::types::Bool, Mysql> for bool {
1210
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<StdError+Send+Sync>> {
@@ -42,49 +40,3 @@ impl HasSqlType<::types::Timestamp> for Mysql {
4240
MysqlType::Timestamp
4341
}
4442
}
45-
46-
impl FromSql<Unsigned<::types::SmallInt>, Mysql> for u16 {
47-
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<StdError+Send+Sync>> {
48-
let value: i16 = FromSql::<::types::SmallInt, Mysql>::from_sql(bytes)?;
49-
Ok(value as u16)
50-
}
51-
}
52-
53-
impl ToSql<Unsigned<::types::SmallInt>, Mysql> for u16 {
54-
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<StdError+Send+Sync>> {
55-
out.write_u16::<<backend::Mysql as Backend>::ByteOrder>(*self)
56-
.map(|_| IsNull::No)
57-
.map_err(|e| Box::new(e) as Box<StdError+Send+Sync>)
58-
}
59-
}
60-
61-
impl FromSql<Unsigned<::types::Integer>, Mysql> for u32 {
62-
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<StdError+Send+Sync>> {
63-
let value: i32 = FromSql::<::types::Integer, Mysql>::from_sql(bytes)?;
64-
Ok(value as u32)
65-
}
66-
}
67-
68-
impl ToSql<Unsigned<::types::Integer>, Mysql> for u32 {
69-
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<StdError+Send+Sync>> {
70-
out.write_u32::<<backend::Mysql as Backend>::ByteOrder>(*self)
71-
.map(|_| IsNull::No)
72-
.map_err(|e| Box::new(e) as Box<StdError+Send+Sync>)
73-
}
74-
}
75-
76-
impl FromSql<Unsigned<::types::BigInt>, Mysql> for u64 {
77-
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<StdError+Send+Sync>> {
78-
let value: i64 = FromSql::<::types::BigInt, Mysql>::from_sql(bytes)?;
79-
Ok(value as u64)
80-
}
81-
}
82-
83-
impl ToSql<Unsigned<::types::BigInt>, Mysql> for u64 {
84-
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<StdError+Send+Sync>> {
85-
out.write_u64::<<backend::Mysql as Backend>::ByteOrder>(*self)
86-
.map(|_| IsNull::No)
87-
.map_err(|e| Box::new(e) as Box<StdError+Send+Sync>)
88-
}
89-
}
90-

diesel/src/types/impls/primitives.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ primitive_impls!(Bool -> (bool, pg: (16, 1000), sqlite: (Integer), mysql: (Tiny)
99
primitive_impls!(SmallInt -> (i16, pg: (21, 1005), sqlite: (SmallInt), mysql: (Short)));
1010
primitive_impls!(Integer -> (i32, pg: (23, 1007), sqlite: (Integer), mysql: (Long)));
1111
primitive_impls!(BigInt -> (i64, pg: (20, 1016), sqlite: (Long), mysql: (LongLong)));
12-
primitive_impls!(UInt2 -> (u16, mysql: (Short)));
13-
primitive_impls!(UInt4 -> (u32, mysql: (Long)));
14-
primitive_impls!(UInt8 -> (u64, mysql: (LongLong)));
1512

1613
primitive_impls!(Float -> (f32, pg: (700, 1021), sqlite: (Float), mysql: (Float)));
1714
primitive_impls!(Double -> (f64, pg: (701, 1022), sqlite: (Double), mysql: (Double)));

diesel/src/types/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ pub type VarChar = Text;
256256
/// - `Option<T>` for any `T` which implements `FromSql<ST>`
257257
#[derive(Debug, Clone, Copy, Default)] pub struct Nullable<ST: NotNull>(ST);
258258

259-
#[derive(Debug, Clone, Copy, Default)] pub struct Unsigned<ST>(ST);
260-
261-
#[doc(hidden)] pub type UInt2 = Unsigned<SmallInt>;
262-
#[doc(hidden)] pub type UInt4 = Unsigned<Integer>;
263-
#[doc(hidden)] pub type UInt8 = Unsigned<BigInt>;
264-
265259
#[cfg(feature = "postgres")]
266260
pub use pg::types::sql_types::*;
267261

diesel_infer_schema/src/codegen.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ fn column_def_tokens(
8484
};
8585
let mut tpe = quote!(#tpe);
8686

87-
if column_type.is_unsigned {
88-
tpe = quote!(Unsigned<#tpe>);
89-
}
9087
if column_type.is_array {
9188
tpe = quote!(Array<#tpe>);
9289
}

diesel_infer_schema/src/data_structures.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub struct ColumnType {
1919
pub path: Vec<String>,
2020
pub is_array: bool,
2121
pub is_nullable: bool,
22-
pub is_unsigned: bool,
2322
}
2423

2524
impl ColumnInformation {

diesel_infer_schema/src/mysql.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ use data_structures::*;
44

55
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<Error>> {
66
let tpe = determine_type_name(&attr.type_name)?;
7-
let unsigned = determine_unsigned(&attr.type_name);
87

98
Ok(ColumnType {
10-
path: vec!["diesel".into(), "types".into(), capitalize(tpe.trim())],
9+
path: vec!["diesel".into(), "types".into(), capitalize(tpe)],
1110
is_array: false,
1211
is_nullable: attr.nullable,
13-
is_unsigned: unsigned,
1412
})
1513
}
1614

17-
fn determine_type_name(sql_type_name: &str) -> Result<String, Box<Error>> {
15+
fn determine_type_name(sql_type_name: &str) -> Result<&str, Box<Error>> {
1816
let result = if sql_type_name == "tinyint(1)" {
1917
"bool"
2018
} else if sql_type_name.starts_with("int") {
@@ -26,19 +24,14 @@ fn determine_type_name(sql_type_name: &str) -> Result<String, Box<Error>> {
2624
};
2725

2826
if result.to_lowercase().contains("unsigned") {
29-
let result = result.to_lowercase().replace("unsigned", "").trim().to_owned();
30-
Ok(result)
27+
Err("unsigned types are not yet supported".into())
3128
} else if result.contains(' ') {
3229
Err(format!("unrecognized type {:?}", result).into())
3330
} else {
34-
Ok(result.to_owned())
31+
Ok(result)
3532
}
3633
}
3734

38-
fn determine_unsigned(sql_type_name: &str) -> bool {
39-
sql_type_name.to_lowercase().contains("unsigned")
40-
}
41-
4235
fn capitalize(name: &str) -> String {
4336
name[..1].to_uppercase() + &name[1..]
4437
}
@@ -70,15 +63,10 @@ fn int_is_treated_as_integer() {
7063
}
7164

7265
#[test]
73-
fn unsigned_types_are_supported() {
74-
assert!(determine_unsigned("float unsigned"));
75-
assert!(determine_unsigned("UNSIGNED INT"));
76-
assert!(determine_unsigned("unsigned bigint"));
77-
assert!(!determine_unsigned("bigint"));
78-
assert!(!determine_unsigned("FLOAT"));
79-
assert_eq!("float", determine_type_name("float unsigned").unwrap());
80-
assert_eq!("int", determine_type_name("UNSIGNED INT").unwrap());
81-
assert_eq!("bigint", determine_type_name("unsigned bigint").unwrap());
66+
fn unsigned_types_are_not_supported() {
67+
assert!(determine_type_name("float unsigned").is_err());
68+
assert!(determine_type_name("UNSIGNED INT").is_err());
69+
assert!(determine_type_name("unsigned bigint").is_err())
8270
}
8371

8472
#[test]

diesel_infer_schema/src/pg.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
1414
path: vec!["diesel".into(), "types".into(), capitalize(tpe)],
1515
is_array: is_array,
1616
is_nullable: attr.nullable,
17-
is_unsigned: false,
1817
})
1918
}
2019

diesel_infer_schema/src/sqlite.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
122122
path: path,
123123
is_array: false,
124124
is_nullable: attr.nullable,
125-
is_unsigned: false,
126125
})
127126
}
128127

diesel_tests/tests/types.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,6 @@ fn i32_to_sql_integer() {
164164
assert!(!query_to_sql_equality::<Integer, i32>("70000", 69999));
165165
}
166166

167-
#[test]
168-
#[cfg(feature = "mysql")]
169-
fn u32_to_sql_interger(){
170-
assert!(query_to_sql_equality::<Unsigned<Integer>, u32>("-1", 4294967295));
171-
assert!(query_to_sql_equality::<Unsigned<Integer>, u32>("0", 0));
172-
assert!(query_to_sql_equality::<Unsigned<Integer>, u32>("1", 1));
173-
assert!(query_to_sql_equality::<Unsigned<Integer>, u32>("70000", 70000));
174-
assert!(!query_to_sql_equality::<Unsigned<Integer>, u32>("0", 1));
175-
assert!(!query_to_sql_equality::<Unsigned<Integer>, u32>("70000", 69999));
176-
assert!(!query_to_sql_equality::<Unsigned<Integer>, u32>("-1", 4294967294));
177-
}
178-
179-
#[test]
180-
#[cfg(feature = "mysql")]
181-
fn u32_from_sql() {
182-
assert_eq!(0, query_single_value::<Unsigned<Integer>, u32>("0"));
183-
assert_eq!(4294967295, query_single_value::<Unsigned<Integer>, u32>("-1"));
184-
assert_ne!(4294967294, query_single_value::<Unsigned<Integer>, u32>("-1"));
185-
assert_eq!(70000, query_single_value::<Unsigned<Integer>, u32>("70000"));
186-
}
187-
188167
#[test]
189168
#[cfg(feature = "postgres")]
190169
fn i64_from_sql() {

0 commit comments

Comments
 (0)