From 0d9e66528dfe8a58b58d0cee842d626c35530c33 Mon Sep 17 00:00:00 2001 From: Yaiba <4yaiba@gmail.com> Date: Tue, 7 Nov 2023 11:40:38 -0600 Subject: [PATCH] feat: keep string literal quote in table default --- kfparser/parser_test.go | 4 ++-- kfparser/visitor.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/kfparser/parser_test.go b/kfparser/parser_test.go index 4da50cf..dc23531 100644 --- a/kfparser/parser_test.go +++ b/kfparser/parser_test.go @@ -147,11 +147,11 @@ func TestParse_valid_syntax(t *testing.T) { genOneTableOneCol(schema.ColText), }, {"table with text column with all attrs", - `database td1; table tt1 { tc1 text minlen(3) maxlen(30) default(3) notnull primary unique }`, + `database td1; table tt1 { tc1 text minlen(3) maxlen(30) default('3') notnull primary unique }`, genOneTableOneColWithAttrs(schema.ColText, schema.Attribute{Type: schema.AttrMinLength, Value: "3"}, schema.Attribute{Type: schema.AttrMaxLength, Value: "30"}, - schema.Attribute{Type: schema.AttrDefault, Value: "3"}, + schema.Attribute{Type: schema.AttrDefault, Value: "'3'"}, schema.Attribute{Type: schema.AttrNotNull}, schema.Attribute{Type: schema.AttrPrimaryKey}, schema.Attribute{Type: schema.AttrUnique}), diff --git a/kfparser/visitor.go b/kfparser/visitor.go index ece0ba8..cc008ff 100644 --- a/kfparser/visitor.go +++ b/kfparser/visitor.go @@ -234,8 +234,7 @@ func (c *KFVisitor) VisitColumn_constraint(ctx *kfgrammar.Column_constraintConte attr.Type = schema.AttrUnique case ctx.DEFAULT_() != nil: attr.Type = schema.AttrDefault - // remove the single quote - attr.Value = strings.Trim(ctx.Literal_value().GetText(), "'") + attr.Value = ctx.Literal_value().GetText() case ctx.MIN_() != nil: attr.Type = schema.AttrMin attr.Value = ctx.Number_value().GetText()