Skip to content

Commit

Permalink
sql (fix): Quote digit QName parts to generate SQL properly
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe committed Apr 20, 2024
1 parent 0087b55 commit 738b632
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ object Expression {
QuotedIdentifier(x.stripPrefix("\"").stripSuffix("\""), None)
} else if (x.matches("[0-9]+")) {
DigitId(x, None)
} else if (!x.matches("[0-9a-zA-Z_]*")) {
// Quotations are needed with special characters to generate valid SQL
QuotedIdentifier(x, None)
} else {
UnquotedIdentifier(x, None)
}
Expand All @@ -479,7 +476,17 @@ object Expression {
case class QName(parts: List[String], nodeLocation: Option[NodeLocation]) extends LeafExpression {
def fullName: String = parts.mkString(".")
override def toString: String = fullName
override def sqlExpr: String = parts.map(Expression.newIdentifier).map(_.sqlExpr).mkString(".")
override def sqlExpr: String = parts.map { part =>
if (part.matches("[0-9]+")) {
// Quotations are needed for digits to generate valid SQL
Expression.newIdentifier(s""""$part"""")
} else if (!part.matches("[0-9a-zA-Z_]*")) {
// Quotations are needed with special characters to generate valid SQL
Expression.newIdentifier(s""""$part"""")
} else {
Expression.newIdentifier(part)
}
}.map(_.sqlExpr).mkString(".")
}
object QName {
def apply(s: String, nodeLocation: Option[NodeLocation]): QName = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,5 @@
select user_agent || 'x', count(*) from impression group by 1
- sql: |
select * FROM "café"
- sql: |
select * FROM "café"."123"

0 comments on commit 738b632

Please sign in to comment.