Skip to content

Commit 01d50f1

Browse files
committed
fix unsigned integer decoding in mysql
fixes #678
1 parent 61cdd06 commit 01d50f1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/webserver/database/sql_to_json.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ pub fn sql_nonnull_to_json<'r>(mut get_ref: impl FnMut() -> sqlx::any::AnyValueR
6262
decode_raw::<f64>(raw_value).into()
6363
}
6464
"INT8" | "BIGINT" | "SERIAL8" | "BIGSERIAL" | "IDENTITY" | "INT64" | "INTEGER8"
65-
| "BIGINT UNSIGNED" | "BIGINT SIGNED" => decode_raw::<i64>(raw_value).into(),
66-
"INT" | "INT4" | "INTEGER" | "MEDIUMINT" | "YEAR" | "INT UNSIGNED" => {
67-
decode_raw::<i32>(raw_value).into()
68-
}
65+
| "BIGINT SIGNED" => decode_raw::<i64>(raw_value).into(),
66+
"INT" | "INT4" | "INTEGER" | "MEDIUMINT" | "YEAR" => decode_raw::<i32>(raw_value).into(),
6967
"INT2" | "SMALLINT" | "TINYINT" => decode_raw::<i16>(raw_value).into(),
68+
"BIGINT UNSIGNED" => decode_raw::<u64>(raw_value).into(),
69+
"INT UNSIGNED" | "MEDIUMINT UNSIGNED" | "SMALLINT UNSIGNED" | "TINYINT UNSIGNED" => {
70+
decode_raw::<u32>(raw_value).into()
71+
}
7072
"BOOL" | "BOOLEAN" => decode_raw::<bool>(raw_value).into(),
7173
"BIT" if matches!(*type_info, AnyTypeInfo(AnyTypeInfoKind::Mssql(_))) => {
7274
decode_raw::<bool>(raw_value).into()
@@ -223,6 +225,10 @@ mod tests {
223225
signed_int INTEGER,
224226
big_int BIGINT,
225227
unsigned_int INTEGER UNSIGNED,
228+
tiny_int_unsigned TINYINT UNSIGNED,
229+
small_int_unsigned SMALLINT UNSIGNED,
230+
medium_int_unsigned MEDIUMINT UNSIGNED,
231+
big_int_unsigned BIGINT UNSIGNED,
226232
decimal_num DECIMAL(10,2),
227233
float_num FLOAT,
228234
double_num DOUBLE,
@@ -243,6 +249,10 @@ mod tests {
243249
-1000000 as signed_int,
244250
9223372036854775807 as big_int,
245251
1000000 as unsigned_int,
252+
255 as tiny_int_unsigned,
253+
65535 as small_int_unsigned,
254+
16777215 as medium_int_unsigned,
255+
18446744073709551615 as big_int_unsigned,
246256
123.45 as decimal_num,
247257
42.25 as float_num,
248258
42.25 as double_num,
@@ -272,6 +282,10 @@ mod tests {
272282
"signed_int": -1000000,
273283
"big_int": 9223372036854775807u64,
274284
"unsigned_int": 1000000,
285+
"tiny_int_unsigned": 255,
286+
"small_int_unsigned": 65535,
287+
"medium_int_unsigned": 16777215,
288+
"big_int_unsigned": 18446744073709551615u64,
275289
"decimal_num": 123.45,
276290
"float_num": 42.25,
277291
"double_num": 42.25,

0 commit comments

Comments
 (0)