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`
|
/// 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![];
|
let mut output: Vec<String> = vec![];
|
||||||
|
|
||||||
for identifier in identifiers {
|
for identifier in identifiers {
|
||||||
output.push(self.quote_identifier(&identifier).to_string());
|
output.push(self.quote_identifier(identifier).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
output
|
output
|
||||||
@ -54,7 +54,7 @@ pub trait DatabaseDriver: fmt::Debug {
|
|||||||
fn quote_identifier(&self, identifier: &str) -> String {
|
fn quote_identifier(&self, identifier: &str) -> String {
|
||||||
let mut identifier = &mut String::from(identifier);
|
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
|
// recurse to quote each identifier in the list
|
||||||
if identifier.contains(",") {
|
if identifier.contains(",") {
|
||||||
let mut quoted_parts: Vec<String> = vec![];
|
let mut quoted_parts: Vec<String> = vec![];
|
||||||
@ -72,18 +72,22 @@ pub trait DatabaseDriver: fmt::Debug {
|
|||||||
|
|
||||||
let (open_char, close_char) = self._quotes();
|
let (open_char, close_char) = self._quotes();
|
||||||
|
|
||||||
let mut trimmed_hiers: Vec<String> = vec![];
|
let mut trimmed_tiers: Vec<String> = vec![];
|
||||||
for hier in identifier.split(".") {
|
for tier in identifier.split(".") {
|
||||||
let mut hier = &mut hier.trim();
|
let mut tier = &mut tier.trim();
|
||||||
|
|
||||||
if hier.starts_with(open_char) && hier.ends_with(close_char) {
|
// Here where the quoting actually happens. Everything
|
||||||
trimmed_hiers.push(hier.to_string());
|
// 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 {
|
} else {
|
||||||
let mut hier = format!("{}{}{}", open_char, hier, close_char);
|
let mut tier = format!("{}{}{}", open_char, tier, close_char);
|
||||||
trimmed_hiers.push(hier.to_string());
|
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
|
/// Runs a basic sql query on the database
|
||||||
@ -122,11 +126,7 @@ mod tests {
|
|||||||
let driver = TestDriver {};
|
let driver = TestDriver {};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
driver.quote_identifiers(vec![
|
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||||
"\tfoo. bar".to_string(),
|
|
||||||
"baz".to_string(),
|
|
||||||
"fizz.\n\tbuzz.baz".to_string(),
|
|
||||||
]),
|
|
||||||
vec![
|
vec![
|
||||||
r#""foo"."bar""#.to_string(),
|
r#""foo"."bar""#.to_string(),
|
||||||
r#""baz""#.to_string(),
|
r#""baz""#.to_string(),
|
||||||
|
@ -38,11 +38,7 @@ mod tests {
|
|||||||
let driver = MSSQL {};
|
let driver = MSSQL {};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
driver.quote_identifiers(vec![
|
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||||
"\tfoo. bar".to_string(),
|
|
||||||
"baz".to_string(),
|
|
||||||
"fizz.\n\tbuzz.baz".to_string(),
|
|
||||||
]),
|
|
||||||
vec![
|
vec![
|
||||||
"[foo].[bar]".to_string(),
|
"[foo].[bar]".to_string(),
|
||||||
"[baz]".to_string(),
|
"[baz]".to_string(),
|
||||||
|
@ -38,11 +38,7 @@ mod tests {
|
|||||||
let driver = MySQL {};
|
let driver = MySQL {};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
driver.quote_identifiers(vec![
|
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||||
"\tfoo. bar".to_string(),
|
|
||||||
"baz".to_string(),
|
|
||||||
"fizz.\n\tbuzz.baz".to_string(),
|
|
||||||
]),
|
|
||||||
vec![
|
vec![
|
||||||
"`foo`.`bar`".to_string(),
|
"`foo`.`bar`".to_string(),
|
||||||
"`baz`".to_string(),
|
"`baz`".to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user