A little bit of tweaking for the identifier quoting
This commit is contained in:
parent
5b2f8eaf9c
commit
f9979e9470
@ -39,11 +39,11 @@ pub trait DatabaseDriver: fmt::Debug {
|
||||
}
|
||||
|
||||
/// Vector version of `quote_identifier`
|
||||
fn quote_identifiers(&self, identifiers: Vec<String>) -> Vec<String> {
|
||||
fn quote_identifiers<'a>(&self, identifiers: Vec<&'a str>) -> Vec<String> {
|
||||
let mut output: Vec<String> = 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<String> = vec![];
|
||||
@ -72,18 +72,22 @@ pub trait DatabaseDriver: fmt::Debug {
|
||||
|
||||
let (open_char, close_char) = self._quotes();
|
||||
|
||||
let mut trimmed_hiers: Vec<String> = vec![];
|
||||
for hier in identifier.split(".") {
|
||||
let mut hier = &mut hier.trim();
|
||||
let mut trimmed_tiers: Vec<String> = 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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user