2019-04-09 18:55:53 -04:00
|
|
|
//! Database Driver for MSSQL
|
|
|
|
//!
|
2019-04-12 17:09:59 -04:00
|
|
|
//! Note:
|
|
|
|
//! **This driver will probably never be fully implemented**
|
|
|
|
//!
|
2019-04-09 18:55:53 -04:00
|
|
|
//! Contains database-specific query data
|
2019-04-05 20:46:07 -04:00
|
|
|
use super::*;
|
|
|
|
|
2019-04-09 18:55:53 -04:00
|
|
|
/// The struct implementing the `DatabaseDriver` trait
|
2019-04-05 20:46:07 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MSSQL;
|
|
|
|
|
2019-04-09 14:13:37 -04:00
|
|
|
impl MSSQL {
|
2019-04-10 14:03:28 -04:00
|
|
|
/// Create a MSSQL Driver
|
2019-04-09 14:13:37 -04:00
|
|
|
pub fn new() -> Self {
|
|
|
|
MSSQL {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 20:46:07 -04:00
|
|
|
impl DatabaseDriver for MSSQL {
|
|
|
|
/// Get which characters are used to delimit identifiers
|
|
|
|
/// such as tables, and columns
|
|
|
|
fn _quotes(&self) -> (char, char) {
|
|
|
|
('[', ']')
|
|
|
|
}
|
2019-04-12 17:09:59 -04:00
|
|
|
|
|
|
|
fn explain(&self, sql: &str) -> String {
|
|
|
|
sql.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn random(&self) -> String {
|
|
|
|
String::from(" RANDOM")
|
|
|
|
}
|
2019-04-05 20:46:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_quote_identifier_bracket_quote() {
|
2019-04-09 14:13:37 -04:00
|
|
|
let driver = MSSQL::new();
|
2019-04-05 20:46:07 -04:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
driver.quote_identifier("foo, bar, baz"),
|
|
|
|
"[foo],[bar],[baz]"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
driver.quote_identifier("foo.bar, baz, fizz"),
|
|
|
|
"[foo].[bar],[baz],[fizz]"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_quote_identifiers_bracket_quote() {
|
2019-04-09 14:13:37 -04:00
|
|
|
let driver = MSSQL::new();
|
2019-04-05 20:46:07 -04:00
|
|
|
|
|
|
|
assert_eq!(
|
2019-04-11 11:44:06 -04:00
|
|
|
driver.quote_identifiers(vec![
|
|
|
|
"\tfoo. bar".to_string(),
|
|
|
|
"baz".to_string(),
|
|
|
|
"fizz.\n\tbuzz.baz".to_string(),
|
|
|
|
]),
|
2019-04-05 20:46:07 -04:00
|
|
|
vec![
|
|
|
|
"[foo].[bar]".to_string(),
|
|
|
|
"[baz]".to_string(),
|
|
|
|
"[fizz].[buzz].[baz]".to_string(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|