Ensure UUIDs and Datetimes can be converted to strings correctly
Closes #1338
This commit is contained in:
parent
16638561a2
commit
214971cb86
5 changed files with 25 additions and 19 deletions
|
@ -1,16 +1,18 @@
|
||||||
use crate::sql::common::{take_digits, take_digits_range, take_u32_len};
|
use crate::sql::common::{take_digits, take_digits_range, take_u32_len};
|
||||||
use crate::sql::duration::Duration;
|
use crate::sql::duration::Duration;
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
|
use crate::sql::escape::escape_str;
|
||||||
use crate::sql::serde::is_internal_serialization;
|
use crate::sql::serde::is_internal_serialization;
|
||||||
use chrono::{DateTime, FixedOffset, TimeZone, Utc};
|
use chrono::{DateTime, FixedOffset, SecondsFormat, TimeZone, Utc};
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::character::complete::char;
|
use nom::character::complete::char;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
use nom::sequence::delimited;
|
use nom::sequence::delimited;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
use std::ops;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::{fmt, ops};
|
|
||||||
|
|
||||||
const SINGLE: char = '\'';
|
const SINGLE: char = '\'';
|
||||||
const DOUBLE: char = '"';
|
const DOUBLE: char = '"';
|
||||||
|
@ -52,9 +54,15 @@ impl Deref for Datetime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Datetime {
|
impl Datetime {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
pub fn to_raw(&self) -> String {
|
||||||
write!(f, "\"{:?}\"", self.0)
|
self.0.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Datetime {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
|
Display::fmt(&escape_str(&self.0.to_rfc3339_opts(SecondsFormat::AutoSi, true)), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ const BACKTICK: char = '`';
|
||||||
const BACKTICK_ESC: &str = r#"\`"#;
|
const BACKTICK_ESC: &str = r#"\`"#;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_strand(s: &str) -> String {
|
pub fn escape_str(s: &str) -> String {
|
||||||
format!("{}{}{}", DOUBLE, s, DOUBLE)
|
format!("{}{}{}", DOUBLE, s, DOUBLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::sql::base::{base, base_or_scope, Base};
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
use crate::sql::duration::{duration, Duration};
|
use crate::sql::duration::{duration, Duration};
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
use crate::sql::escape::escape_strand;
|
use crate::sql::escape::escape_str;
|
||||||
use crate::sql::ident::{ident, Ident};
|
use crate::sql::ident::{ident, Ident};
|
||||||
use crate::sql::idiom;
|
use crate::sql::idiom;
|
||||||
use crate::sql::idiom::{Idiom, Idioms};
|
use crate::sql::idiom::{Idiom, Idioms};
|
||||||
|
@ -262,13 +262,7 @@ impl DefineLoginStatement {
|
||||||
|
|
||||||
impl fmt::Display for DefineLoginStatement {
|
impl fmt::Display for DefineLoginStatement {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(f, "DEFINE LOGIN {} ON {} PASSHASH {}", self.name, self.base, escape_str(&self.hash))
|
||||||
f,
|
|
||||||
"DEFINE LOGIN {} ON {} PASSHASH {}",
|
|
||||||
self.name,
|
|
||||||
self.base,
|
|
||||||
escape_strand(&self.hash)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +409,7 @@ impl fmt::Display for DefineTokenStatement {
|
||||||
self.name,
|
self.name,
|
||||||
self.base,
|
self.base,
|
||||||
self.kind,
|
self.kind,
|
||||||
escape_strand(&self.code)
|
escape_str(&self.code)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
use crate::sql::escape::escape_strand;
|
use crate::sql::escape::escape_str;
|
||||||
use crate::sql::serde::is_internal_serialization;
|
use crate::sql::serde::is_internal_serialization;
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::escaped_transform;
|
use nom::bytes::complete::escaped_transform;
|
||||||
|
@ -55,7 +55,7 @@ impl Strand {
|
||||||
|
|
||||||
impl Display for Strand {
|
impl Display for Strand {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
Display::fmt(&escape_strand(&self.0), f)
|
Display::fmt(&escape_str(&self.0), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -656,7 +656,9 @@ impl Value {
|
||||||
pub fn as_strand(self) -> Strand {
|
pub fn as_strand(self) -> Strand {
|
||||||
match self {
|
match self {
|
||||||
Value::Strand(v) => v,
|
Value::Strand(v) => v,
|
||||||
_ => Strand::from(self.to_string()),
|
Value::Uuid(v) => v.to_raw().into(),
|
||||||
|
Value::Datetime(v) => v.to_raw().into(),
|
||||||
|
_ => self.to_string().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +703,9 @@ impl Value {
|
||||||
pub fn to_strand(&self) -> Strand {
|
pub fn to_strand(&self) -> Strand {
|
||||||
match self {
|
match self {
|
||||||
Value::Strand(v) => v.clone(),
|
Value::Strand(v) => v.clone(),
|
||||||
_ => Strand::from(self.to_string()),
|
Value::Uuid(v) => v.to_raw().into(),
|
||||||
|
Value::Datetime(v) => v.to_raw().into(),
|
||||||
|
_ => self.to_string().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue