Repository: proullon/ramsql (go)

Issue:
Sometimes ORM wrap columns with quotes
Hi @proullon ,

Some ORM wrap columns with quotes as in the example of GORM:
```sql
UPDATE "challenges" SET "deleted_at"='2022-07-11 14:52:45.804' WHERE "challenges"."deleted_at" IS NULL
```

But I get this error:
```
Syntax error near . \" deleted_at
```

Note that when testing the followings it works perfectly:

```sql
UPDATE "challenges" SET "deleted_at"='2022-07-11 14:52:45.804' WHERE "challenges".deleted_at IS NULL
```

```sql
UPDATE "challenges" SET "deleted_at"='2022-07-11 14:52:45.804' WHERE challenges.deleted_at IS NULL
```

Is it possible you accept quotes for columns as you do for tables?

Thank you,


Pull request:
fix (close #62): parse quoted table"."column

Patch:
diff --git a/engine/parser/parser.go b/engine/parser/parser.go
index a2f1cbf..e9b1367 100644
--- a/engine/parser/parser.go
+++ b/engine/parser/parser.go
@@ -470,6 +470,7 @@ func (p *parser) parseBuiltinFunc() (*Decl, error) {
 // table.foo
 // table.*
 // "table".foo
+// "table"."foo"
 // foo
 func (p *parser) parseAttribute() (*Decl, error) {
 	quoted := false
@@ -498,6 +499,8 @@ func (p *parser) parseAttribute() (*Decl, error) {
 			return nil, err
 		}
 	}
+	quoted = false
+
 	// If no next token,and not quoted, then is was the atribute name
 	if err := p.next(); err != nil {
 		return decl, nil
@@ -509,12 +512,28 @@ func (p *parser) parseAttribute() (*Decl, error) {
 		if err != nil {
 			return nil, err
 		}
+
+		// mayby attribute is quoted as well (see #62)
+		if p.is(DoubleQuoteToken) || p.is(BacktickToken) {
+			quoteToken = p.cur().Token
+			quoted = true
+			if err := p.next(); err != nil {
+				return nil, err
+			}
+		}
 		// if so, next must be the attribute name or a star
 		attributeDecl, err := p.consumeToken(StringToken, StarToken)
 		if err != nil {
 			return nil, err
 		}
 		attributeDecl.Add(decl)
+
+		if quoted {
+			// Check there is a closing quote
+			if _, err := p.consumeToken(quoteToken); err != nil {
+				return nil, fmt.Errorf("expected closing quote: %s", err)
+			}
+		}
 		return attributeDecl, nil
 	}
 
@@ -722,8 +741,6 @@ func (p *parser) parseIn() (*Decl, error) {
 }
 
 func (p *parser) parseValue() (*Decl, error) {
-	debug("parseValue")
-	defer debug("~parseValue")
 	quoted := false
 
 	if p.is(SimpleQuoteToken) || p.is(DoubleQuoteToken) {


Test patch:
diff --git a/engine/parser/parser_test.go b/engine/parser/parser_test.go
index 9840e85..7c4a1a8 100644
--- a/engine/parser/parser_test.go
+++ b/engine/parser/parser_test.go
@@ -208,6 +208,12 @@ func TestSelectForUpdate(t *testing.T) {
 	parse(query, 1, t)
 }
 
+func TestUpdateWithQuotedColumns(t *testing.T) {
+	query := `UPDATE "challenges" SET "deleted_at"='2022-07-11 14:52:45.804' WHERE "challenges"."deleted_at" IS NULL`
+
+	parse(query, 1, t)
+}
+
 func TestCreateDefault(t *testing.T) {
 	query := `CREATE TABLE foo (bar BIGINT, riri TEXT, fifi BOOLEAN NOT NULL DEFAULT false)`