From 752bb7a83222c3daa87d447842c01305d24eaae6 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Fri, 6 Sep 2024 10:57:10 -0700 Subject: [PATCH 1/4] refactor: remove unnecessary string hashes --- src/token.rs | 10 +-- src/types.rs | 6 +- tests/mysql/query.rs | 180 +++++++++++++++++++++--------------------- tests/mysql/table.rs | 4 +- tests/sqlite/query.rs | 30 +++---- tests/sqlite/table.rs | 20 ++--- 6 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/token.rs b/src/token.rs index 44ddf62b1..1d0ee9714 100644 --- a/src/token.rs +++ b/src/token.rs @@ -454,7 +454,7 @@ mod tests { #[test] fn test_9() { - let string = r#"[ab] "#; + let string = r"[ab] "; let tokenizer = Tokenizer::new(string); let tokens: Vec = tokenizer.iter().collect(); assert_eq!( @@ -491,7 +491,7 @@ mod tests { #[test] fn test_11() { - let string = r#" `a``b` "#; + let string = r" `a``b` "; let tokenizer = Tokenizer::new(string); let tokens: Vec = tokenizer.iter().collect(); assert_eq!( @@ -510,7 +510,7 @@ mod tests { #[test] fn test_12() { - let string = r#" 'a''b' "#; + let string = r" 'a''b' "; let tokenizer = Tokenizer::new(string); let tokens: Vec = tokenizer.iter().collect(); assert_eq!( @@ -529,7 +529,7 @@ mod tests { #[test] fn test_13() { - let string = r#"(?)"#; + let string = r"(?)"; let tokenizer = Tokenizer::new(string); let tokens: Vec = tokenizer.iter().collect(); assert_eq!( @@ -548,7 +548,7 @@ mod tests { #[test] fn test_14() { - let string = r#"($1 = $2)"#; + let string = r"($1 = $2)"; let tokenizer = Tokenizer::new(string); let tokens: Vec = tokenizer.iter().collect(); assert_eq!( diff --git a/src/types.rs b/src/types.rs index a58c751ba..e3ddfdea7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -625,7 +625,7 @@ mod tests { #[cfg(feature = "backend-mysql")] assert_eq!( query.to_string(MysqlQueryBuilder), - r#"SELECT `hello-World_`"# + r"SELECT `hello-World_`" ); #[cfg(feature = "backend-postgres")] assert_eq!( @@ -644,7 +644,7 @@ mod tests { let query = Query::select().column(Alias::new("hel`lo")).to_owned(); #[cfg(feature = "backend-mysql")] - assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT `hel``lo`"#); + assert_eq!(query.to_string(MysqlQueryBuilder), r"SELECT `hel``lo`"); #[cfg(feature = "backend-sqlite")] assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT "hel`lo""#); @@ -659,7 +659,7 @@ mod tests { let query = Query::select().column(Alias::new("hel``lo")).to_owned(); #[cfg(feature = "backend-mysql")] - assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT `hel````lo`"#); + assert_eq!(query.to_string(MysqlQueryBuilder), r"SELECT `hel````lo`"); #[cfg(feature = "backend-sqlite")] assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT "hel``lo""#); diff --git a/tests/mysql/query.rs b/tests/mysql/query.rs index a9e46525b..dc33d8762 100644 --- a/tests/mysql/query.rs +++ b/tests/mysql/query.rs @@ -518,7 +518,7 @@ fn select_35() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL"# + r"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL" ); assert_eq!(values.0, vec![]); } @@ -533,7 +533,7 @@ fn select_36() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL"# + r"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL" ); assert_eq!(values.0, vec![]); } @@ -546,7 +546,7 @@ fn select_37() { .cond_where(Cond::any().add(Cond::all()).add(Cond::any())) .build(MysqlQueryBuilder); - assert_eq!(statement, r#"SELECT `id` FROM `glyph` WHERE TRUE OR FALSE"#); + assert_eq!(statement, r"SELECT `id` FROM `glyph` WHERE TRUE OR FALSE"); assert_eq!(values.0, vec![]); } @@ -565,7 +565,7 @@ fn select_37a() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE NOT ((NOT TRUE) AND (NOT FALSE))"# + r"SELECT `id` FROM `glyph` WHERE NOT ((NOT TRUE) AND (NOT FALSE))" ); assert_eq!(values.0, vec![]); } @@ -584,7 +584,7 @@ fn select_38() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL OR `aspect` IS NOT NULL"# + r"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL OR `aspect` IS NOT NULL" ); assert_eq!(values.0, vec![]); } @@ -603,7 +603,7 @@ fn select_39() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL AND `aspect` IS NOT NULL"# + r"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL AND `aspect` IS NOT NULL" ); assert_eq!(values.0, vec![]); } @@ -624,7 +624,7 @@ fn select_40() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL OR (`aspect` IS NOT NULL AND `aspect` < 8)"# + r"SELECT `id` FROM `glyph` WHERE `aspect` IS NULL OR (`aspect` IS NOT NULL AND `aspect` < 8)" ); } @@ -656,7 +656,7 @@ fn select_42() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE `aspect` < 8 AND `aspect` IS NOT NULL"# + r"SELECT `id` FROM `glyph` WHERE `aspect` < 8 AND `aspect` IS NOT NULL" ); } @@ -685,7 +685,7 @@ fn select_44() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE NOT `aspect` < 8"# + r"SELECT `id` FROM `glyph` WHERE NOT `aspect` < 8" ); } @@ -704,7 +704,7 @@ fn select_45() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE NOT (`aspect` < 8 OR `aspect` IS NOT NULL)"# + r"SELECT `id` FROM `glyph` WHERE NOT (`aspect` < 8 OR `aspect` IS NOT NULL)" ); } @@ -722,7 +722,7 @@ fn select_46() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE NOT `aspect` < 8"# + r"SELECT `id` FROM `glyph` WHERE NOT `aspect` < 8" ); } @@ -741,7 +741,7 @@ fn select_47() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE NOT (`aspect` < 8 AND `aspect` IS NOT NULL)"# + r"SELECT `id` FROM `glyph` WHERE NOT (`aspect` < 8 AND `aspect` IS NOT NULL)" ); } @@ -760,7 +760,7 @@ fn select_48() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE (`aspect`, 100) < (8, 100)"# + r"SELECT `id` FROM `glyph` WHERE (`aspect`, 100) < (8, 100)" ); } @@ -782,7 +782,7 @@ fn select_48a() { assert_eq!( statement, - r#"SELECT `id` FROM `glyph` WHERE (`aspect`, '100') IN ((8, '100'))"# + r"SELECT `id` FROM `glyph` WHERE (`aspect`, '100') IN ((8, '100'))" ); } @@ -793,7 +793,7 @@ fn select_49() { .from(Char::Table) .to_string(MysqlQueryBuilder); - assert_eq!(statement, r#"SELECT * FROM `character`"#); + assert_eq!(statement, r"SELECT * FROM `character`"); } #[test] @@ -810,7 +810,7 @@ fn select_50() { assert_eq!( statement, - r#"SELECT `character`.*, `font`.`name` FROM `character` INNER JOIN `font` ON `character`.`font_id` = `font`.`id`"# + r"SELECT `character`.*, `font`.`name` FROM `character` INNER JOIN `font` ON `character`.`font_id` = `font`.`id`" ) } @@ -829,13 +829,13 @@ fn select_51() { ) .to_string(MysqlQueryBuilder), [ - r#"SELECT `aspect`"#, - r#"FROM `glyph`"#, - r#"WHERE IFNULL(`aspect`, 0) > 2"#, - r#"ORDER BY `image` IS NULL DESC,"#, - r#"`image` DESC,"#, - r#"`glyph`.`aspect` IS NULL ASC,"#, - r#"`glyph`.`aspect` ASC"#, + r"SELECT `aspect`", + r"FROM `glyph`", + r"WHERE IFNULL(`aspect`, 0) > 2", + r"ORDER BY `image` IS NULL DESC,", + r"`image` DESC,", + r"`glyph`.`aspect` IS NULL ASC,", + r"`glyph`.`aspect` ASC", ] .join(" ") ); @@ -854,13 +854,13 @@ fn select_52() { ]) .to_string(MysqlQueryBuilder), [ - r#"SELECT `aspect`"#, - r#"FROM `glyph`"#, - r#"WHERE IFNULL(`aspect`, 0) > 2"#, - r#"ORDER BY `id` IS NULL DESC,"#, - r#"`id` ASC,"#, - r#"`aspect` IS NULL ASC,"#, - r#"`aspect` DESC"#, + r"SELECT `aspect`", + r"FROM `glyph`", + r"WHERE IFNULL(`aspect`, 0) > 2", + r"ORDER BY `id` IS NULL DESC,", + r"`id` ASC,", + r"`aspect` IS NULL ASC,", + r"`aspect` DESC", ] .join(" ") ); @@ -883,13 +883,13 @@ fn select_53() { ]) .to_string(MysqlQueryBuilder), [ - r#"SELECT `aspect`"#, - r#"FROM `glyph`"#, - r#"WHERE IFNULL(`aspect`, 0) > 2"#, - r#"ORDER BY `glyph`.`id` IS NULL DESC,"#, - r#"`glyph`.`id` ASC,"#, - r#"`glyph`.`aspect` IS NULL ASC,"#, - r#"`glyph`.`aspect` DESC"#, + r"SELECT `aspect`", + r"FROM `glyph`", + r"WHERE IFNULL(`aspect`, 0) > 2", + r"ORDER BY `glyph`.`id` IS NULL DESC,", + r"`glyph`.`id` ASC,", + r"`glyph`.`aspect` IS NULL ASC,", + r"`glyph`.`aspect` DESC", ] .join(" ") ); @@ -906,7 +906,7 @@ fn select_54() { assert_eq!( statement, - r#"SELECT * FROM `character`, `font` WHERE `font`.`id` = `character`.`font_id`"# + r"SELECT * FROM `character`, `font` WHERE `font`.`id` = `character`.`font_id`" ); } @@ -924,16 +924,16 @@ fn select_55() { .order_by((Glyph::Table, Glyph::Aspect), Order::Asc) .to_string(MysqlQueryBuilder), [ - r#"SELECT `aspect`"#, - r#"FROM `glyph`"#, - r#"WHERE IFNULL(`aspect`, 0) > 2"#, - r#"ORDER BY CASE"#, - r#"WHEN `id`=4 THEN 0"#, - r#"WHEN `id`=5 THEN 1"#, - r#"WHEN `id`=1 THEN 2"#, - r#"WHEN `id`=3 THEN 3"#, - r#"ELSE 4 END,"#, - r#"`glyph`.`aspect` ASC"#, + r"SELECT `aspect`", + r"FROM `glyph`", + r"WHERE IFNULL(`aspect`, 0) > 2", + r"ORDER BY CASE", + r"WHEN `id`=4 THEN 0", + r"WHEN `id`=5 THEN 1", + r"WHEN `id`=1 THEN 2", + r"WHEN `id`=3 THEN 3", + r"ELSE 4 END,", + r"`glyph`.`aspect` ASC", ] .join(" ") ); @@ -953,15 +953,15 @@ fn select_56() { ) .to_string(MysqlQueryBuilder), [ - r#"SELECT `aspect`"#, - r#"FROM `glyph`"#, - r#"WHERE IFNULL(`aspect`, 0) > 2"#, - r#"ORDER BY `glyph`.`aspect` ASC,"#, - r#"CASE WHEN `id`=4 THEN 0"#, - r#"WHEN `id`=5 THEN 1"#, - r#"WHEN `id`=1 THEN 2"#, - r#"WHEN `id`=3 THEN 3"#, - r#"ELSE 4 END"#, + r"SELECT `aspect`", + r"FROM `glyph`", + r"WHERE IFNULL(`aspect`, 0) > 2", + r"ORDER BY `glyph`.`aspect` ASC,", + r"CASE WHEN `id`=4 THEN 0", + r"WHEN `id`=5 THEN 1", + r"WHEN `id`=1 THEN 2", + r"WHEN `id`=3 THEN 3", + r"ELSE 4 END", ] .join(" ") ); @@ -982,7 +982,7 @@ fn select_57() { assert_eq!( query.to_string(MysqlQueryBuilder), - r#"SELECT (CASE WHEN (`glyph`.`aspect` > 0) THEN 'positive' WHEN (`glyph`.`aspect` < 0) THEN 'negative' ELSE 'zero' END) AS `polarity` FROM `glyph`"# + r"SELECT (CASE WHEN (`glyph`.`aspect` > 0) THEN 'positive' WHEN (`glyph`.`aspect` < 0) THEN 'negative' ELSE 'zero' END) AS `polarity` FROM `glyph`" ); } @@ -1049,13 +1049,13 @@ fn select_61() { .offset(100) .to_string(MysqlQueryBuilder), [ - r#"SELECT `character`, `size_w`, `size_h`"#, - r#"FROM `character`"#, - r#"IGNORE INDEX FOR JOIN (`IDX_123456`)"#, - r#"USE INDEX FOR GROUP BY (`IDX_789ABC`)"#, - r#"FORCE INDEX FOR ORDER BY (`IDX_DEFGHI`)"#, - r#"LIMIT 10"#, - r#"OFFSET 100"#, + r"SELECT `character`, `size_w`, `size_h`", + r"FROM `character`", + r"IGNORE INDEX FOR JOIN (`IDX_123456`)", + r"USE INDEX FOR GROUP BY (`IDX_789ABC`)", + r"FORCE INDEX FOR ORDER BY (`IDX_DEFGHI`)", + r"LIMIT 10", + r"OFFSET 100", ] .join(" ") ); @@ -1193,7 +1193,7 @@ fn insert_from_select() { .unwrap() .to_owned() .to_string(MysqlQueryBuilder), - r#"INSERT INTO `glyph` (`aspect`, `image`) SELECT `aspect`, `image` FROM `glyph` WHERE `image` LIKE '%'"# + r"INSERT INTO `glyph` (`aspect`, `image`) SELECT `aspect`, `image` FROM `glyph` WHERE `image` LIKE '%'" ); } @@ -1215,9 +1215,9 @@ fn insert_on_conflict_0() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = VALUES(`image`)"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = VALUES(`image`)", ] .join(" ") ); @@ -1241,9 +1241,9 @@ fn insert_on_conflict_1() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`)"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`)", ] .join(" ") ); @@ -1267,9 +1267,9 @@ fn insert_on_conflict_2() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = VALUES(`image`)"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = VALUES(`image`)", ] .join(" ") ); @@ -1296,9 +1296,9 @@ fn insert_on_conflict_3() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = '04108048005887010020060000204E0180400400', `image` = 3.1415"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = '04108048005887010020060000204E0180400400', `image` = 3.1415", ] .join(" ") ); @@ -1322,9 +1322,9 @@ fn insert_on_conflict_4() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `image` = 1 + 2"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `image` = 1 + 2", ] .join(" ") ); @@ -1349,9 +1349,9 @@ fn insert_on_conflict_5() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = '04108048005887010020060000204E0180400400', `image` = VALUES(`image`)"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = '04108048005887010020060000204E0180400400', `image` = VALUES(`image`)", ] .join(" ") ); @@ -1376,9 +1376,9 @@ fn insert_on_conflict_6() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = 1 + 2"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = 1 + 2", ] .join(" ") ); @@ -1399,9 +1399,9 @@ fn insert_on_conflict_do_nothing_on() { ) .to_string(MysqlQueryBuilder), [ - r#"INSERT INTO `glyph` (`aspect`, `image`)"#, - r#"VALUES ('abcd', 3.1415)"#, - r#"ON DUPLICATE KEY UPDATE `id` = `id`"#, + r"INSERT INTO `glyph` (`aspect`, `image`)", + r"VALUES ('abcd', 3.1415)", + r"ON DUPLICATE KEY UPDATE `id` = `id`", ] .join(" ") ); diff --git a/tests/mysql/table.rs b/tests/mysql/table.rs index 0d3a7d091..5f71f4e72 100644 --- a/tests/mysql/table.rs +++ b/tests/mysql/table.rs @@ -359,7 +359,7 @@ fn create_with_check_constraint() { .check(Expr::col(Glyph::Id).lt(20)) .check(Expr::col(Glyph::Id).ne(15)) .to_string(MysqlQueryBuilder), - r#"CREATE TABLE `glyph` ( `id` int NOT NULL CHECK (`id` > 10), CHECK (`id` < 20), CHECK (`id` <> 15) )"#, + r"CREATE TABLE `glyph` ( `id` int NOT NULL CHECK (`id` > 10), CHECK (`id` < 20), CHECK (`id` <> 15) )", ); } @@ -376,6 +376,6 @@ fn alter_with_check_constraint() { .check(Expr::col(Glyph::Aspect).gt(100)) ) .to_string(MysqlQueryBuilder), - r#"ALTER TABLE `glyph` ADD COLUMN `aspect` int NOT NULL DEFAULT 101 CHECK (`aspect` > 100)"#, + r"ALTER TABLE `glyph` ADD COLUMN `aspect` int NOT NULL DEFAULT 101 CHECK (`aspect` > 100)", ); } diff --git a/tests/sqlite/query.rs b/tests/sqlite/query.rs index 9a9c8fcf5..3214bad8b 100644 --- a/tests/sqlite/query.rs +++ b/tests/sqlite/query.rs @@ -434,7 +434,7 @@ fn select_31() { Query::select() .expr((1..10_i32).fold(Expr::value(0), |expr, i| { expr.add(i) })) .to_string(SqliteQueryBuilder), - r#"SELECT 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9"# + r"SELECT 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9" ); } @@ -910,12 +910,12 @@ fn select_55() { r#"SELECT "aspect""#, r#"FROM "glyph""#, r#"WHERE IFNULL("aspect", 0) > 2"#, - r#"ORDER BY CASE"#, + r"ORDER BY CASE", r#"WHEN "id"=4 THEN 0"#, r#"WHEN "id"=5 THEN 1"#, r#"WHEN "id"=1 THEN 2"#, r#"WHEN "id"=3 THEN 3"#, - r#"ELSE 4 END,"#, + r"ELSE 4 END,", r#""glyph"."aspect" ASC"#, ] .join(" ") @@ -949,7 +949,7 @@ fn select_56() { r#"WHEN "id"=5 THEN 1"#, r#"WHEN "id"=1 THEN 2"#, r#"WHEN "id"=3 THEN 3"#, - r#"ELSE 4 END"#, + r"ELSE 4 END", ] .join(" ") ); @@ -1248,7 +1248,7 @@ fn insert_on_conflict_1() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1274,7 +1274,7 @@ fn insert_on_conflict_2() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = "excluded"."image""#, ] .join(" ") @@ -1303,7 +1303,7 @@ fn insert_on_conflict_3() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = 3.1415"#, ] .join(" ") @@ -1329,7 +1329,7 @@ fn insert_on_conflict_4() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "image" = 1 + 2"#, ] .join(" ") @@ -1356,7 +1356,7 @@ fn insert_on_conflict_5() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = "excluded"."image""#, ] .join(" ") @@ -1383,7 +1383,7 @@ fn insert_on_conflict_6() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#, ] .join(" ") @@ -1410,7 +1410,7 @@ fn insert_on_conflict_7() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1437,7 +1437,7 @@ fn insert_on_conflict_8() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1464,7 +1464,7 @@ fn insert_on_conflict_9() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, + r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", r#"ON CONFLICT ("id", LOWER("tokens")) DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1487,7 +1487,7 @@ fn insert_on_conflict_do_nothing() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('abcd', 3.1415)"#, + r"VALUES ('abcd', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO NOTHING"#, ] .join(" ") @@ -1510,7 +1510,7 @@ fn insert_on_conflict_do_nothing_on() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r#"VALUES ('abcd', 3.1415)"#, + r"VALUES ('abcd', 3.1415)", r#"ON CONFLICT ("id", "aspect") DO NOTHING"#, ] .join(" ") diff --git a/tests/sqlite/table.rs b/tests/sqlite/table.rs index 12f2be7c7..5a360004b 100644 --- a/tests/sqlite/table.rs +++ b/tests/sqlite/table.rs @@ -21,7 +21,7 @@ fn create_1() { r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#, r#""aspect" double NOT NULL,"#, r#""image" text"#, - r#")"#, + r")", ] .join(" ") ); @@ -49,7 +49,7 @@ fn create_2() { r#""name" varchar NOT NULL,"#, r#""variant" varchar NOT NULL,"#, r#""language" varchar NOT NULL"#, - r#")"#, + r")", ] .join(" ") ); @@ -94,7 +94,7 @@ fn create_3() { r#""size_h" integer NOT NULL,"#, r#""font_id" integer DEFAULT NULL,"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r#")"#, + r")", ] .join(" ") ); @@ -112,7 +112,7 @@ fn create_4() { r#"CREATE TABLE "binary_type" ("#, r#""binlen" blob(32),"#, r#""bin" blob(1)"#, - r#")"#, + r")", ] .join(" ") ); @@ -132,7 +132,7 @@ fn create_5() { r#""character" blob(1),"#, r#""font_size" blob(10),"#, r#""size_w" varbinary_blob(10)"#, - r#")"#, + r")", ] .join(" ") ); @@ -156,7 +156,7 @@ fn create_6() { r#"CREATE TABLE "task" ("#, r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#, r#""is_done" boolean NOT NULL"#, - r#")"#, + r")", ] .join(" ") ); @@ -178,7 +178,7 @@ fn create_7() { [ r#"CREATE TABLE "task" ("#, r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT"#, - r#")"#, + r")", ] .join(" ") ); @@ -225,7 +225,7 @@ fn create_with_unique_index() { r#""font_id" integer DEFAULT NULL,"#, r#"UNIQUE ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r#")"#, + r")", ] .join(" ") ); @@ -270,7 +270,7 @@ fn create_with_primary_unique_index() { r#""font_id" integer DEFAULT NULL,"#, r#"PRIMARY KEY ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r#")"#, + r")", ] .join(" ") ); @@ -324,7 +324,7 @@ fn create_with_unique_index_constraint() { r#""font_id" integer DEFAULT NULL,"#, r#"CONSTRAINT "idx-sizehw" UNIQUE ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r#")"#, + r")", ].join(" ") ); } From 9d464d8f0fac5c26491aeddf2dec59380a59b161 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Fri, 6 Sep 2024 11:05:42 -0700 Subject: [PATCH 2/4] fix: formatting in `src/types.rs` --- src/types.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/types.rs b/src/types.rs index e3ddfdea7..e12919bb2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -623,10 +623,7 @@ mod tests { .to_owned(); #[cfg(feature = "backend-mysql")] - assert_eq!( - query.to_string(MysqlQueryBuilder), - r"SELECT `hello-World_`" - ); + assert_eq!(query.to_string(MysqlQueryBuilder), r"SELECT `hello-World_`"); #[cfg(feature = "backend-postgres")] assert_eq!( query.to_string(PostgresQueryBuilder), From 65deaee9b47f8d02a30b851846f5e6b614b1cda4 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Mon, 7 Oct 2024 10:30:13 -0700 Subject: [PATCH 3/4] refactor: restore `#` for consistent formatting in specific spots --- tests/sqlite/query.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/sqlite/query.rs b/tests/sqlite/query.rs index 3214bad8b..57f0a774c 100644 --- a/tests/sqlite/query.rs +++ b/tests/sqlite/query.rs @@ -910,12 +910,12 @@ fn select_55() { r#"SELECT "aspect""#, r#"FROM "glyph""#, r#"WHERE IFNULL("aspect", 0) > 2"#, - r"ORDER BY CASE", + r#"ORDER BY CASE"#, r#"WHEN "id"=4 THEN 0"#, r#"WHEN "id"=5 THEN 1"#, r#"WHEN "id"=1 THEN 2"#, r#"WHEN "id"=3 THEN 3"#, - r"ELSE 4 END,", + r#"ELSE 4 END,"#, r#""glyph"."aspect" ASC"#, ] .join(" ") @@ -949,7 +949,7 @@ fn select_56() { r#"WHEN "id"=5 THEN 1"#, r#"WHEN "id"=1 THEN 2"#, r#"WHEN "id"=3 THEN 3"#, - r"ELSE 4 END", + r#"ELSE 4 END"#, ] .join(" ") ); @@ -1248,7 +1248,7 @@ fn insert_on_conflict_1() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1274,7 +1274,7 @@ fn insert_on_conflict_2() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = "excluded"."image""#, ] .join(" ") @@ -1303,7 +1303,7 @@ fn insert_on_conflict_3() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = 3.1415"#, ] .join(" ") @@ -1329,7 +1329,7 @@ fn insert_on_conflict_4() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "image" = 1 + 2"#, ] .join(" ") @@ -1356,7 +1356,7 @@ fn insert_on_conflict_5() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = "excluded"."image""#, ] .join(" ") @@ -1383,7 +1383,7 @@ fn insert_on_conflict_6() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#, ] .join(" ") @@ -1410,7 +1410,7 @@ fn insert_on_conflict_7() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1437,7 +1437,7 @@ fn insert_on_conflict_8() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1464,7 +1464,7 @@ fn insert_on_conflict_9() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('04108048005887010020060000204E0180400400', 3.1415)", + r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#, r#"ON CONFLICT ("id", LOWER("tokens")) DO UPDATE SET "aspect" = "excluded"."aspect""#, ] .join(" ") @@ -1487,7 +1487,7 @@ fn insert_on_conflict_do_nothing() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('abcd', 3.1415)", + r#"VALUES ('abcd', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO NOTHING"#, ] .join(" ") @@ -1510,7 +1510,7 @@ fn insert_on_conflict_do_nothing_on() { .to_string(SqliteQueryBuilder), [ r#"INSERT INTO "glyph" ("aspect", "image")"#, - r"VALUES ('abcd', 3.1415)", + r#"VALUES ('abcd', 3.1415)"#, r#"ON CONFLICT ("id", "aspect") DO NOTHING"#, ] .join(" ") From 185dd217049622f2f5276b99b55090f26f98401e Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Tue, 8 Oct 2024 14:21:22 -0700 Subject: [PATCH 4/4] refactor: restore stylistic changes in `table.rs` --- tests/sqlite/table.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/sqlite/table.rs b/tests/sqlite/table.rs index 5a360004b..12f2be7c7 100644 --- a/tests/sqlite/table.rs +++ b/tests/sqlite/table.rs @@ -21,7 +21,7 @@ fn create_1() { r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#, r#""aspect" double NOT NULL,"#, r#""image" text"#, - r")", + r#")"#, ] .join(" ") ); @@ -49,7 +49,7 @@ fn create_2() { r#""name" varchar NOT NULL,"#, r#""variant" varchar NOT NULL,"#, r#""language" varchar NOT NULL"#, - r")", + r#")"#, ] .join(" ") ); @@ -94,7 +94,7 @@ fn create_3() { r#""size_h" integer NOT NULL,"#, r#""font_id" integer DEFAULT NULL,"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r")", + r#")"#, ] .join(" ") ); @@ -112,7 +112,7 @@ fn create_4() { r#"CREATE TABLE "binary_type" ("#, r#""binlen" blob(32),"#, r#""bin" blob(1)"#, - r")", + r#")"#, ] .join(" ") ); @@ -132,7 +132,7 @@ fn create_5() { r#""character" blob(1),"#, r#""font_size" blob(10),"#, r#""size_w" varbinary_blob(10)"#, - r")", + r#")"#, ] .join(" ") ); @@ -156,7 +156,7 @@ fn create_6() { r#"CREATE TABLE "task" ("#, r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#, r#""is_done" boolean NOT NULL"#, - r")", + r#")"#, ] .join(" ") ); @@ -178,7 +178,7 @@ fn create_7() { [ r#"CREATE TABLE "task" ("#, r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT"#, - r")", + r#")"#, ] .join(" ") ); @@ -225,7 +225,7 @@ fn create_with_unique_index() { r#""font_id" integer DEFAULT NULL,"#, r#"UNIQUE ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r")", + r#")"#, ] .join(" ") ); @@ -270,7 +270,7 @@ fn create_with_primary_unique_index() { r#""font_id" integer DEFAULT NULL,"#, r#"PRIMARY KEY ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r")", + r#")"#, ] .join(" ") ); @@ -324,7 +324,7 @@ fn create_with_unique_index_constraint() { r#""font_id" integer DEFAULT NULL,"#, r#"CONSTRAINT "idx-sizehw" UNIQUE ("size_h", "size_w"),"#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#, - r")", + r#")"#, ].join(" ") ); }