Skip to content

Commit dfabcaa

Browse files
committed
Fixed Strings
1 parent 90001cf commit dfabcaa

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

internal/codegen/golang/ydb_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col
215215
return "*uint64"
216216
}
217217
return "*uint64"
218-
218+
219219
default:
220220
if strings.HasPrefix(columnType, "decimal") {
221221
if notNull {
@@ -227,7 +227,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col
227227
}
228228
return "*types.Decimal"
229229
}
230-
230+
231231
if debug.Active {
232232
log.Printf("unknown YDB type: %s\n", columnType)
233233
}

internal/engine/ydb/convert.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,11 +3523,14 @@ func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} {
35233523
return &ast.A_Const{Val: &ast.Float{Str: text}, Location: c.pos(n.GetStart())}
35243524

35253525
case n.STRING_VALUE() != nil: // !!! debug !!! (problem with quoted strings)
3526-
val := n.STRING_VALUE().GetText()
3527-
if len(val) >= 2 {
3528-
val = val[1 : len(val)-1]
3526+
originalText := n.STRING_VALUE().GetText()
3527+
content, hasSuffix := parseStringValue(originalText)
3528+
3529+
if hasSuffix {
3530+
return &ast.A_Const{Val: &ast.String{Str: originalText}, Location: c.pos(n.GetStart())}
3531+
} else {
3532+
return &ast.A_Const{Val: &ast.String{Str: content}, Location: c.pos(n.GetStart())}
35293533
}
3530-
return &ast.A_Const{Val: &ast.String{Str: val}, Location: c.pos(n.GetStart())}
35313534

35323535
case n.Bool_value() != nil:
35333536
var i bool

internal/engine/ydb/utils.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,48 @@ func (c *cc) collectEqualityOps(ctx parser.ICond_exprContext) []antlr.TerminalNo
295295
}
296296
return ops
297297
}
298+
299+
300+
func parseStringValue(s string) (value string, hasSuffix bool) {
301+
if len(s) < 2 {
302+
return s, false
303+
}
304+
305+
quote := s[0]
306+
if quote != '\'' && quote != '"' {
307+
return s, false
308+
}
309+
310+
quotePos := -1
311+
for i := len(s) - 1; i >= 0; i-- {
312+
if s[i] == quote {
313+
quotePos = i
314+
break
315+
}
316+
}
317+
318+
if quotePos == -1 || quotePos == 0 {
319+
return s, false
320+
}
321+
322+
content := s[1:quotePos]
323+
324+
if quotePos < len(s)-1 {
325+
suffix := s[quotePos+1:]
326+
if isValidYDBStringSuffix(suffix) {
327+
return content, true
328+
}
329+
}
330+
331+
return content, false
332+
}
333+
334+
func isValidYDBStringSuffix(suffix string) bool {
335+
switch suffix {
336+
case "s", "S", "u", "U", "y", "Y", "j", "J",
337+
"pt", "PT", "pb", "PB", "pv", "PV":
338+
return true
339+
default:
340+
return false
341+
}
342+
}

0 commit comments

Comments
 (0)