summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorPavan Deolasee2016-12-20 05:35:08 +0000
committerPavan Deolasee2017-05-05 04:59:33 +0000
commitdf13f58003d119162d9a1450ced06048e5992b67 (patch)
treed156c087800e41fd1d7089befb2f3dbdb94108e0 /src/backend/parser
parent97b8a00f0be9d6dad4a209b7979358ce4a53a3ca (diff)
Handle multi-command SQL strings correctly even when there are 'null' sql
commands. Reported by Krzysztof Nienartowicz
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 796292537f..00744a4980 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -788,17 +788,35 @@ stmtmulti: stmtmulti ';' stmt
* the ';' token, add '\0' at the corresponding offset
* to get a separated command.
*/
- last = list_tail($1->queries);
- query = palloc(@2 - $1->offset + 1);
- memcpy(query, lfirst(last), @2 - $1->offset);
- query[@2 - $1->offset] = '\0';
-
- lfirst(last) = query;
- query = scanner_get_query(@3, -1, yyscanner);
- $1->offset = @2;
- $1->parsetrees = lappend($1->parsetrees, $3);
- $1->queries = lappend($1->queries, query);
- $$ = $1;
+ if ($1 != NULL)
+ {
+ last = list_tail($1->queries);
+ query = palloc(@2 - $1->offset + 1);
+ memcpy(query, lfirst(last), @2 - $1->offset);
+ query[@2 - $1->offset] = '\0';
+ lfirst(last) = query;
+
+ query = scanner_get_query(@3, -1, yyscanner);
+ $1->offset = @2;
+ $1->parsetrees = lappend($1->parsetrees, $3);
+ $1->queries = lappend($1->queries, query);
+ $$ = $1;
+ }
+ /*
+ *
+ * If the earlier statements were all null, then we
+ * must initialise the StmtMulti structure and make
+ * singleton lists
+ */
+ else
+ {
+ StmtMulti *n = (StmtMulti *) palloc0(sizeof (StmtMulti));
+ query = scanner_get_query(@3, -1, yyscanner);
+ n->offset = @2;
+ n->parsetrees = list_make1($3);
+ n->queries = list_make1(query);
+ $$ = n;
+ }
}
else
$$ = $1;