From d339ebd96314aefd59285b054e9e0a36de81e708 Mon Sep 17 00:00:00 2001 From: Dima Koltsov <dkoltsov@picodata.io> Date: Tue, 16 Aug 2022 15:12:55 +0300 Subject: [PATCH] fix(pest grammar): support empty string as value Closes #229 --- src/frontend/sql/query.pest | 2 +- test_app/test/integration/api_test.lua | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/frontend/sql/query.pest b/src/frontend/sql/query.pest index 6eb4c9b0d9..cd74e2ed33 100644 --- a/src/frontend/sql/query.pest +++ b/src/frontend/sql/query.pest @@ -72,7 +72,7 @@ Expr = _{ Or | And | Unary | Between | Cmp | Primary | Parentheses } NameString = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ ('Ð' .. 'Я' | 'а' .. 'Ñ' | 'A' .. 'Z' | 'a'..'z' | "-" | "_" | ASCII_DIGIT)+ } -String = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ (Character | ("'" ~ "'") | "\"")+ } +String = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ (Character | ("'" ~ "'") | "\"")* } Keyword = { ^"except" | ^"union" | ^"where" } Character = _{ ASCII_ALPHANUMERIC | 'Ð' .. 'Я' | 'а' .. 'Ñ' | Other | Punctuation | SYMBOL } Punctuation = _{ diff --git a/test_app/test/integration/api_test.lua b/test_app/test/integration/api_test.lua index 4278b23d4b..a93b6d33a4 100644 --- a/test_app/test/integration/api_test.lua +++ b/test_app/test/integration/api_test.lua @@ -694,6 +694,34 @@ g.test_insert_6 = function() }) end +-- check empty string +g.test_insert_7 = function() + local api = cluster:server("api-1").net_box + + local r, err = api:call("sbroad.execute", { [[INSERT INTO "space_simple_shard_key" + ("sysOp", "id", "name") VALUES (8, 8, '')]], {} }) + + t.assert_equals(err, nil) + t.assert_equals(r, {row_count = 1}) + + r, err = api:call("sbroad.execute", { [[SELECT *, "bucket_id" FROM "space_simple_shard_key"]], {} }) + + t.assert_equals(err, nil) + t.assert_equals(r, { + metadata = { + {name = "id", type = "integer"}, + {name = "name", type = "string"}, + {name = "sysOp", type = "integer"}, + {name = "bucket_id", type = "unsigned"}, + }, + rows = { + {1, "ok", 1, 3940}, + {8, "", 8, 12104}, + {10, box.NULL, 0, 11520} + }, + }) +end + g.test_decimal_double = function() local api = cluster:server("api-1").net_box -- GitLab