Repository: codenotary/immudb (language: go)

Issue:
Table names can't start with x
**What happened**

See the tests below: apparently that table can be created only if its name doesn't start with x.

**How to reproduce it (as minimally and precisely as possible)**

```
immuclient>exec CREATE TABLE z (a INTEGER, PRIMARY KEY a)
INFO: Redunant argument(s) | [TABLE z (a INTEGER, PRIMARY KEY a)] 
sql ok, Ctxs: 1 Dtxs: 0 
immuclient>exec CREATE TABLE x (a INTEGER, PRIMARY KEY a)
INFO: Redunant argument(s) | [TABLE x (a INTEGER, PRIMARY KEY a)] 
ERROR: rpc error: code = Unknown desc = syntax error: unexpected ERROR, expecting IDENTIFIER 
immuclient>exec CREATE TABLE xtest (a INTEGER, PRIMARY KEY a)
INFO: Redunant argument(s) | [TABLE xtest (a INTEGER, PRIMARY KEY a)] 
ERROR: rpc error: code = Unknown desc = syntax error: unexpected ERROR, expecting IDENTIFIER
```

**Environment**

1.0.0

**Additional info (any other context about the problem)**

- Note that the table definitions above are identical, except for the name.
- I didn't check if all other characters are fine.



Discussion / hints:
The same applies to column names. Using `xtest` as a column name returns the same error.

Fix patch:
diff --git a/embedded/sql/parser.go b/embedded/sql/parser.go
index a5547ff068..6e1ef182aa 100644
--- a/embedded/sql/parser.go
+++ b/embedded/sql/parser.go
@@ -222,12 +222,7 @@ func (l *lexer) Lex(lval *yySymType) int {
 		return STMT_SEPARATOR
 	}
 
-	if isBLOBPrefix(ch) {
-		if !isQuote(l.r.nextChar) {
-			lval.err = fmt.Errorf("syntax error: unexpected char %c, expecting quote", l.r.nextChar)
-			return ERROR
-		}
-
+	if isBLOBPrefix(ch) && isQuote(l.r.nextChar) {
 		l.r.ReadByte() // consume starting quote
 
 		tail, err := l.readString()
@@ -236,6 +231,11 @@ func (l *lexer) Lex(lval *yySymType) int {
 			return ERROR
 		}
 
+		if !isQuote(l.r.nextChar) {
+			lval.err = fmt.Errorf("syntax error: unexpected char %c, expecting quote", l.r.nextChar)
+			return ERROR
+		}
+
 		l.r.ReadByte() // consume closing quote
 
 		val, err := hex.DecodeString(tail)


Test patch:
diff --git a/embedded/sql/parser_test.go b/embedded/sql/parser_test.go
index f57d842178..c3c45ddc3b 100644
--- a/embedded/sql/parser_test.go
+++ b/embedded/sql/parser_test.go
@@ -132,6 +132,17 @@ func TestCreateTableStmt(t *testing.T) {
 				}},
 			expectedError: nil,
 		},
+		{
+			input: "CREATE TABLE xtable1 (xid INTEGER, PRIMARY KEY xid)",
+			expectedOutput: []SQLStmt{
+				&CreateTableStmt{
+					table:       "xtable1",
+					ifNotExists: false,
+					colsSpec:    []*ColSpec{{colName: "xid", colType: IntegerType}},
+					pk:          "xid",
+				}},
+			expectedError: nil,
+		},
 		{
 			input: "CREATE TABLE IF NOT EXISTS table1 (id INTEGER, PRIMARY KEY id)",
 			expectedOutput: []SQLStmt{