Browse Source

Properly escape column names when filtering; also normalize use of `.

Kestrel 1 year ago
parent
commit
4c8ebf6180

+ 1 - 1
microrm/src/query.rs

@@ -169,7 +169,7 @@ impl<'l> QueryInterface<'l> {
                 self.db
                     .conn
                     .prepare(&format!(
-                        "INSERT INTO \"{}\" VALUES (NULL, {}) RETURNING \"id\"",
+                        "INSERT INTO `{}` VALUES (NULL, {}) RETURNING \"id\"",
                         <T as Entity>::table_name(),
                         placeholders
                     ))

+ 1 - 1
microrm/src/query/filter.rs

@@ -93,7 +93,7 @@ where
     fn derive(&self) -> DerivedQuery {
         self.wrap.derive().add(
             QueryPart::Where,
-            format!("{} {} ?", self.col.name(), self.op.ch()),
+            format!("`{}` {} ?", self.col.name(), self.op.ch()),
         )
     }
 

+ 1 - 1
microrm/src/query/update.rs

@@ -41,7 +41,7 @@ impl<'r, 'q, T: Entity> QueryComponent for Update<'r, 'q, T> {
     }
 
     fn contribute<H: Hasher>(&self, hasher: &mut H) {
-        "select".hash(hasher);
+        "update".hash(hasher);
         std::any::TypeId::of::<T>().hash(hasher);
     }
 

+ 2 - 2
microrm/src/schema/create.rs

@@ -24,9 +24,9 @@ pub fn sql_for_table<T: Entity>() -> (String, String) {
     }
 
     (
-        format!("DROP TABLE IF EXISTS \"{}\"", <T as Entity>::table_name()),
+        format!("DROP TABLE IF EXISTS `{}`", <T as Entity>::table_name()),
         format!(
-            "CREATE TABLE IF NOT EXISTS \"{}\" ({})",
+            "CREATE TABLE IF NOT EXISTS `{}` ({})",
             <T as Entity>::table_name(),
             columns.join(",")
         ),