diff --git a/src/drivers.rs b/src/drivers.rs index dce6283..d92be86 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -39,11 +39,11 @@ pub trait DatabaseDriver: fmt::Debug { } /// Vector version of `quote_identifier` - fn quote_identifiers(&self, identifiers: Vec) -> Vec { + fn quote_identifiers<'a>(&self, identifiers: Vec<&'a str>) -> Vec { let mut output: Vec = vec![]; for identifier in identifiers { - output.push(self.quote_identifier(&identifier).to_string()); + output.push(self.quote_identifier(identifier).to_string()); } output @@ -54,7 +54,7 @@ pub trait DatabaseDriver: fmt::Debug { fn quote_identifier(&self, identifier: &str) -> String { let mut identifier = &mut String::from(identifier); - // If the identifier is actually a list, + // If the identifier is actually a comma-separated list, // recurse to quote each identifier in the list if identifier.contains(",") { let mut quoted_parts: Vec = vec![]; @@ -72,18 +72,22 @@ pub trait DatabaseDriver: fmt::Debug { let (open_char, close_char) = self._quotes(); - let mut trimmed_hiers: Vec = vec![]; - for hier in identifier.split(".") { - let mut hier = &mut hier.trim(); + let mut trimmed_tiers: Vec = vec![]; + for tier in identifier.split(".") { + let mut tier = &mut tier.trim(); - if hier.starts_with(open_char) && hier.ends_with(close_char) { - trimmed_hiers.push(hier.to_string()); + // Here where the quoting actually happens. Everything + // else is breaking down the identifier list for this. + if tier.starts_with(open_char) && tier.ends_with(close_char) { + trimmed_tiers.push(tier.to_string()); } else { - let mut hier = format!("{}{}{}", open_char, hier, close_char); - trimmed_hiers.push(hier.to_string()); + let mut tier = format!("{}{}{}", open_char, tier, close_char); + trimmed_tiers.push(tier.to_string()); } } - trimmed_hiers.join(".") + trimmed_tiers.join(".") + + // @TODO Fix functional calls in 'select' queries } /// Runs a basic sql query on the database @@ -122,11 +126,7 @@ mod tests { let driver = TestDriver {}; assert_eq!( - driver.quote_identifiers(vec![ - "\tfoo. bar".to_string(), - "baz".to_string(), - "fizz.\n\tbuzz.baz".to_string(), - ]), + driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]), vec![ r#""foo"."bar""#.to_string(), r#""baz""#.to_string(), diff --git a/src/drivers/mssql.rs b/src/drivers/mssql.rs index 8954568..280d2d4 100644 --- a/src/drivers/mssql.rs +++ b/src/drivers/mssql.rs @@ -38,11 +38,7 @@ mod tests { let driver = MSSQL {}; assert_eq!( - driver.quote_identifiers(vec![ - "\tfoo. bar".to_string(), - "baz".to_string(), - "fizz.\n\tbuzz.baz".to_string(), - ]), + driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]), vec![ "[foo].[bar]".to_string(), "[baz]".to_string(), diff --git a/src/drivers/mysql.rs b/src/drivers/mysql.rs index 6f20aef..d6ed429 100644 --- a/src/drivers/mysql.rs +++ b/src/drivers/mysql.rs @@ -38,11 +38,7 @@ mod tests { let driver = MySQL {}; assert_eq!( - driver.quote_identifiers(vec![ - "\tfoo. bar".to_string(), - "baz".to_string(), - "fizz.\n\tbuzz.baz".to_string(), - ]), + driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]), vec![ "`foo`.`bar`".to_string(), "`baz`".to_string(),