Skip to content

Commit 7bc86bc

Browse files
committed
Bump mysql_common and mysql
This is a breaking change, since mysql_common is exposed in the API, and we just bumped its major version.
1 parent 87474f0 commit 7bc86bc

File tree

6 files changed

+52
-61
lines changed

6 files changed

+52
-61
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "msql-srv"
3-
version = "0.8.8"
3+
version = "0.9.0"
44
edition = "2018"
55

66
description = "Bindings for emulating a MySQL/MariaDB server"
@@ -23,15 +23,15 @@ codecov = { repository = "jonhoo/msql-srv", branch = "master", service = "github
2323
maintenance = { status = "experimental" }
2424

2525
[dependencies]
26-
nom = "5.0.0"
27-
mysql_common = "0.19"
26+
nom = "5"
27+
mysql_common = "0.22"
2828
byteorder = "1"
2929
chrono = "0.4"
3030
time = "=0.2.7"
3131

3232
[dev-dependencies]
33-
postgres = "0.15.2"
34-
mysql = "17.0.0"
33+
postgres = "0.15"
34+
mysql = "18"
3535
mysql_async = "0.20.0"
3636
slab = "0.4.2"
3737
tokio = "0.1.19"

examples/psql_as_mysql.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate postgres;
88
extern crate slab;
99

1010
use msql_srv::*;
11+
use mysql::prelude::*;
1112
use slab::Slab;
1213

1314
use std::io;
@@ -34,10 +35,11 @@ fn main() {
3435
assert_eq!(db.ping(), true);
3536
{
3637
let mut results = db
37-
.query("SELECT INT4(1) AS foo, INT8(1) AS bar, 'BAZ' AS baz")
38+
.query_iter("SELECT INT4(1) AS foo, INT8(1) AS bar, 'BAZ' AS baz")
3839
.unwrap();
3940
{
40-
let cols = results.columns_ref();
41+
let cols = results.columns();
42+
let cols = cols.as_ref();
4143
assert_eq!(cols.len(), 3);
4244
assert_eq!(cols[0].name_str(), "foo");
4345
assert_eq!(cols[1].name_str(), "bar");
@@ -59,10 +61,11 @@ fn main() {
5961
}
6062
{
6163
let mut results = db
62-
.prep_exec("SELECT INT4(1) AS foo, INT8(1) AS bar, 'BAZ' AS baz", ())
64+
.exec_iter("SELECT INT4(1) AS foo, INT8(1) AS bar, 'BAZ' AS baz", ())
6365
.unwrap();
6466
{
65-
let cols = results.columns_ref();
67+
let cols = results.columns();
68+
let cols = cols.as_ref();
6669
assert_eq!(cols.len(), 3);
6770
assert_eq!(cols[0].name_str(), "foo");
6871
assert_eq!(cols[1].name_str(), "bar");

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! # use std::net;
2020
//! # use std::thread;
2121
//! use msql_srv::*;
22+
//! use mysql::prelude::*;
2223
//!
2324
//! struct Backend;
2425
//! impl<W: io::Write> MysqlShim<W> for Backend {
@@ -74,7 +75,7 @@
7475
//!
7576
//! let mut db = mysql::Conn::new(&format!("mysql://127.0.0.1:{}", port)).unwrap();
7677
//! assert_eq!(db.ping(), true);
77-
//! assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 1);
78+
//! assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 1);
7879
//! drop(db);
7980
//! jh.join().unwrap();
8081
//! }

src/value/decode.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,7 @@ mod tests {
374374
rt!(u64_one, u64, 1, ColumnType::MYSQL_TYPE_LONGLONG, false);
375375
rt!(i64_one, i64, 1, ColumnType::MYSQL_TYPE_LONGLONG, true);
376376

377-
// NOTE:
378-
// this test currently doesn't work since `mysql` *always* encodes floats as doubles.
379-
// it gets away with this in practice by forcing the parameter types on every query:
380-
// https://github.com/blackbeam/rust-mysql-simple/blob/47b7883a7e0eb47a45b06d726a55e89e78c0477e/src/conn/mod.rs#L994
381-
// however, since we don't take parameter type forcing into account here, the test won't pass
382-
//
383-
// rt!(f32_one_float, f32, 1.0, ColumnType::MYSQL_TYPE_FLOAT, false);
384-
385-
rt!(
386-
f32_one_double,
387-
f32,
388-
1.0,
389-
ColumnType::MYSQL_TYPE_DOUBLE,
390-
false
391-
);
377+
rt!(f32_one_float, f32, 1.0, ColumnType::MYSQL_TYPE_FLOAT, false);
392378
rt!(f64_one, f64, 1.0, ColumnType::MYSQL_TYPE_DOUBLE, false);
393379

394380
rt!(

src/value/encode.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ pub trait ToMysqlValue {
2222
macro_rules! mysql_text_trivial {
2323
() => {
2424
fn to_mysql_text<W: Write>(&self, w: &mut W) -> io::Result<()> {
25-
w.write_lenenc_str(format!("{}", self).as_bytes()).map(|_| ())
25+
w.write_lenenc_str(format!("{}", self).as_bytes())
26+
.map(|_| ())
2627
}
27-
}
28+
};
2829
}
2930

3031
use std::fmt;
@@ -557,6 +558,7 @@ impl ToMysqlValue for myc::value::Value {
557558
myc::value::Value::Int(n) => n.to_mysql_text(w),
558559
myc::value::Value::UInt(n) => n.to_mysql_text(w),
559560
myc::value::Value::Float(f) => f.to_mysql_text(w),
561+
myc::value::Value::Double(f) => f.to_mysql_text(w),
560562
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
561563
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
562564
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
@@ -621,6 +623,7 @@ impl ToMysqlValue for myc::value::Value {
621623
n.to_mysql_bin(w, c)
622624
}
623625
myc::value::Value::Float(f) => f.to_mysql_bin(w, c),
626+
myc::value::Value::Double(f) => f.to_mysql_bin(w, c),
624627
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
625628
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
626629
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
@@ -812,13 +815,6 @@ mod tests {
812815
rt!(i64_one, i64, 1, ColumnType::MYSQL_TYPE_LONGLONG, true);
813816

814817
rt!(f32_one, f32, 1.0, ColumnType::MYSQL_TYPE_FLOAT, false);
815-
rt!(
816-
f32_one_double,
817-
f32,
818-
1.0,
819-
ColumnType::MYSQL_TYPE_DOUBLE,
820-
false
821-
);
822818
rt!(f64_one, f64, 1.0, ColumnType::MYSQL_TYPE_DOUBLE, false);
823819

824820
rt!(

tests/main.rs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate mysql;
44
extern crate mysql_common as myc;
55
extern crate nom;
66

7+
use mysql::prelude::*;
78
use std::io;
89
use std::net;
910
use std::thread;
@@ -174,7 +175,7 @@ fn empty_response() {
174175
|_, _| unreachable!(),
175176
)
176177
.test(|db| {
177-
assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 0);
178+
assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 0);
178179
})
179180
}
180181

@@ -193,7 +194,7 @@ fn no_rows() {
193194
|_, _| unreachable!(),
194195
)
195196
.test(|db| {
196-
assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 0);
197+
assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 0);
197198
})
198199
}
199200

@@ -206,7 +207,7 @@ fn no_columns() {
206207
|_, _| unreachable!(),
207208
)
208209
.test(|db| {
209-
assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 0);
210+
assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 0);
210211
})
211212
}
212213

@@ -219,7 +220,7 @@ fn no_columns_but_rows() {
219220
|_, _| unreachable!(),
220221
)
221222
.test(|db| {
222-
assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 0);
223+
assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 0);
223224
})
224225
}
225226

@@ -233,7 +234,7 @@ fn error_response() {
233234
|_, _| unreachable!(),
234235
)
235236
.test(|db| {
236-
if let mysql::Error::MySqlError(e) = db.query("SELECT a, b FROM foo").unwrap_err() {
237+
if let mysql::Error::MySqlError(e) = db.query_iter("SELECT a, b FROM foo").unwrap_err() {
237238
assert_eq!(
238239
e,
239240
mysql::error::MySqlError {
@@ -263,7 +264,7 @@ fn empty_on_drop() {
263264
|_, _| unreachable!(),
264265
)
265266
.test(|db| {
266-
assert_eq!(db.query("SELECT a, b FROM foo").unwrap().count(), 0);
267+
assert_eq!(db.query_iter("SELECT a, b FROM foo").unwrap().count(), 0);
267268
})
268269
}
269270

@@ -287,7 +288,7 @@ fn it_queries_nulls() {
287288
)
288289
.test(|db| {
289290
let row = db
290-
.query("SELECT a, b FROM foo")
291+
.query_iter("SELECT a, b FROM foo")
291292
.unwrap()
292293
.next()
293294
.unwrap()
@@ -316,7 +317,7 @@ fn it_queries() {
316317
)
317318
.test(|db| {
318319
let row = db
319-
.query("SELECT a, b FROM foo")
320+
.query_iter("SELECT a, b FROM foo")
320321
.unwrap()
321322
.next()
322323
.unwrap()
@@ -347,20 +348,24 @@ fn multi_result() {
347348
|_, _| unreachable!(),
348349
)
349350
.test(|db| {
350-
let mut result = db.query("SELECT a FROM foo; SELECT a FROM foo").unwrap();
351-
assert!(result.more_results_exists());
352-
let row1: Vec<_> = result
351+
let mut result = db
352+
.query_iter("SELECT a FROM foo; SELECT a FROM foo")
353+
.unwrap();
354+
let mut set = result.next_set().unwrap().unwrap();
355+
let row1: Vec<_> = set
353356
.by_ref()
354357
.filter_map(|row| row.unwrap().get::<i16, _>(0))
355358
.collect();
356359
assert_eq!(row1, vec![1024]);
357-
assert!(result.more_results_exists());
358-
let row2: Vec<_> = result
360+
drop(set);
361+
let mut set = result.next_set().unwrap().unwrap();
362+
let row2: Vec<_> = set
359363
.by_ref()
360364
.filter_map(|row| row.unwrap().get::<i16, _>(0))
361365
.collect();
362366
assert_eq!(row2, vec![1025]);
363-
assert!(!result.more_results_exists());
367+
drop(set);
368+
assert!(result.next_set().is_none());
364369
})
365370
}
366371

@@ -395,7 +400,7 @@ fn it_queries_many_rows() {
395400
)
396401
.test(|db| {
397402
let mut rows = 0;
398-
for row in db.query("SELECT a, b FROM foo").unwrap() {
403+
for row in db.query_iter("SELECT a, b FROM foo").unwrap() {
399404
let row = row.unwrap();
400405
assert_eq!(row.get::<i16, _>(0), Some(1024));
401406
assert_eq!(row.get::<i16, _>(1), Some(1025));
@@ -447,7 +452,7 @@ fn it_prepares() {
447452
.with_columns(cols2)
448453
.test(|db| {
449454
let row = db
450-
.prep_exec("SELECT a FROM b WHERE c = ?", (42i16,))
455+
.exec_iter("SELECT a FROM b WHERE c = ?", (42i16,))
451456
.unwrap()
452457
.next()
453458
.unwrap()
@@ -557,7 +562,7 @@ fn insert_exec() {
557562
.with_params(params)
558563
.test(|db| {
559564
let res = db
560-
.prep_exec(
565+
.exec_iter(
561566
"INSERT INTO `users` \
562567
(`username`, `email`, `password_digest`, `created_at`, \
563568
`session_token`, `rss_token`, `mailing_list_token`) \
@@ -574,7 +579,7 @@ fn insert_exec() {
574579
)
575580
.unwrap();
576581
assert_eq!(res.affected_rows(), 42);
577-
assert_eq!(res.last_insert_id(), 1);
582+
assert_eq!(res.last_insert_id(), Some(1));
578583
})
579584
}
580585

@@ -620,7 +625,7 @@ fn send_long() {
620625
.with_columns(cols2)
621626
.test(|db| {
622627
let row = db
623-
.prep_exec("SELECT a FROM b WHERE c = ?", (b"Hello world",))
628+
.exec_iter("SELECT a FROM b WHERE c = ?", (b"Hello world",))
624629
.unwrap()
625630
.next()
626631
.unwrap()
@@ -670,7 +675,7 @@ fn it_prepares_many() {
670675
.with_columns(cols2)
671676
.test(|db| {
672677
let mut rows = 0;
673-
for row in db.prep_exec("SELECT a, b FROM x", ()).unwrap() {
678+
for row in db.exec_iter("SELECT a, b FROM x", ()).unwrap() {
674679
let row = row.unwrap();
675680
assert_eq!(row.get::<i16, _>(0), Some(1024));
676681
assert_eq!(row.get::<i16, _>(1), Some(1025));
@@ -709,7 +714,7 @@ fn prepared_empty() {
709714
.with_columns(cols2)
710715
.test(|db| {
711716
assert_eq!(
712-
db.prep_exec("SELECT a FROM b WHERE c = ?", (42i16,))
717+
db.exec_iter("SELECT a FROM b WHERE c = ?", (42i16,))
713718
.unwrap()
714719
.count(),
715720
0
@@ -742,7 +747,7 @@ fn prepared_no_params() {
742747
.with_params(params)
743748
.with_columns(cols2)
744749
.test(|db| {
745-
let row = db.prep_exec("foo", ()).unwrap().next().unwrap().unwrap();
750+
let row = db.exec_iter("foo", ()).unwrap().next().unwrap().unwrap();
746751
assert_eq!(row.get::<i16, _>(0), Some(1024i16));
747752
})
748753
}
@@ -807,7 +812,7 @@ fn prepared_nulls() {
807812
.with_columns(cols2)
808813
.test(|db| {
809814
let row = db
810-
.prep_exec(
815+
.exec_iter(
811816
"SELECT a, b FROM x WHERE c = ? AND d = ?",
812817
(mysql::Value::NULL, 42),
813818
)
@@ -837,7 +842,7 @@ fn prepared_no_rows() {
837842
)
838843
.with_columns(cols2)
839844
.test(|db| {
840-
assert_eq!(db.prep_exec("SELECT a, b FROM foo", ()).unwrap().count(), 0);
845+
assert_eq!(db.exec_iter("SELECT a, b FROM foo", ()).unwrap().count(), 0);
841846
})
842847
}
843848

@@ -850,7 +855,7 @@ fn prepared_no_cols_but_rows() {
850855
|_, _| unreachable!(),
851856
)
852857
.test(|db| {
853-
assert_eq!(db.prep_exec("SELECT a, b FROM foo", ()).unwrap().count(), 0);
858+
assert_eq!(db.exec_iter("SELECT a, b FROM foo", ()).unwrap().count(), 0);
854859
})
855860
}
856861

@@ -863,7 +868,7 @@ fn prepared_no_cols() {
863868
|_, _| unreachable!(),
864869
)
865870
.test(|db| {
866-
assert_eq!(db.prep_exec("SELECT a, b FROM foo", ()).unwrap().count(), 0);
871+
assert_eq!(db.exec_iter("SELECT a, b FROM foo", ()).unwrap().count(), 0);
867872
})
868873
}
869874

@@ -880,6 +885,6 @@ fn really_long_query() {
880885
|_, _| unreachable!(),
881886
)
882887
.test(move |db| {
883-
db.query(long).unwrap();
888+
db.query_iter(long).unwrap();
884889
})
885890
}

0 commit comments

Comments
 (0)