mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-04 13:10:31 +00:00
Merge pull request #53 from thomas-jeepe/master
Fix qualified wildcard stringifying
This commit is contained in:
commit
07d66a93ef
4 changed files with 47 additions and 3 deletions
|
@ -111,7 +111,7 @@ impl ToString for ASTNode {
|
|||
match self {
|
||||
ASTNode::SQLIdentifier(s) => s.to_string(),
|
||||
ASTNode::SQLWildcard => "*".to_string(),
|
||||
ASTNode::SQLQualifiedWildcard(q) => q.join(".") + "*",
|
||||
ASTNode::SQLQualifiedWildcard(q) => q.join(".") + ".*",
|
||||
ASTNode::SQLCompoundIdentifier(s) => s.join("."),
|
||||
ASTNode::SQLIsNull(ast) => format!("{} IS NULL", ast.as_ref().to_string()),
|
||||
ASTNode::SQLIsNotNull(ast) => format!("{} IS NOT NULL", ast.as_ref().to_string()),
|
||||
|
|
|
@ -35,7 +35,7 @@ impl ToString for Value {
|
|||
Value::Long(v) => v.to_string(),
|
||||
Value::Double(v) => v.to_string(),
|
||||
Value::Uuid(v) => v.to_string(),
|
||||
Value::SingleQuotedString(v) => format!("'{}'", v),
|
||||
Value::SingleQuotedString(v) => format!("'{}'", escape_single_quote_string(v)),
|
||||
Value::NationalStringLiteral(v) => format!("N'{}'", v),
|
||||
Value::Boolean(v) => v.to_string(),
|
||||
Value::Date(v) => v.to_string(),
|
||||
|
@ -46,3 +46,15 @@ impl ToString for Value {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn escape_single_quote_string(s: &str) -> String {
|
||||
let mut escaped = String::new();
|
||||
for c in s.chars() {
|
||||
if c == '\'' {
|
||||
escaped.push_str("\'\'");
|
||||
} else {
|
||||
escaped.push(c);
|
||||
}
|
||||
}
|
||||
escaped
|
||||
}
|
||||
|
|
|
@ -462,7 +462,13 @@ impl<'a> Tokenizer<'a> {
|
|||
match ch {
|
||||
'\'' => {
|
||||
chars.next(); // consume
|
||||
break;
|
||||
let escaped_quote = chars.peek().map(|c| *c == '\'').unwrap_or(false);
|
||||
if escaped_quote {
|
||||
s.push('\'');
|
||||
chars.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
chars.next(); // consume
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue