Commit be703cd9 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Implement nested block comments in the backend and in psql.

 Include updates for the comment.sql regression test.
Implement SET SESSION CHARACTERISTICS and SET DefaultXactIsoLevel.
Implement SET SESSION CHARACTERISTICS TRANSACTION COMMIT
 and SET AutoCommit in the parser only.
 Need to add code to actually do something.
Implement WITHOUT TIME ZONE type qualifier.
Define SCHEMA keyword, along with stubbed-out grammar.
Implement "[IN|INOUT|OUT] [varname] type" function arguments
 in parser only; INOUT and OUT throws an elog(ERROR).
Add PATH as a type-specific token, since PATH is in SQL99
 to support schema resource search and resolution.
parent 1e901bbe
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: analyze.c,v 1.149 2000/07/02 04:04:09 tgl Exp $ * $Id: analyze.c,v 1.150 2000/07/14 15:43:32 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -200,6 +200,38 @@ transformStmt(ParseState *pstate, Node *parseTree) ...@@ -200,6 +200,38 @@ transformStmt(ParseState *pstate, Node *parseTree)
result = transformAlterTableStmt(pstate, (AlterTableStmt *) parseTree); result = transformAlterTableStmt(pstate, (AlterTableStmt *) parseTree);
break; break;
case T_SetSessionStmt:
{
List *l;
/* Session is a list of SetVariable nodes
* so just run through the list.
*/
SetSessionStmt *stmt = (SetSessionStmt *) parseTree;
l = stmt->args;
/* First check for duplicate keywords (disallowed by SQL99) */
while (l != NULL)
{
VariableSetStmt *v = (VariableSetStmt *) lfirst(l);
List *ll = lnext(l);
while (ll != NULL)
{
VariableSetStmt *vv = (VariableSetStmt *) lfirst(ll);
if (strcmp(v->name, vv->name) == 0)
elog(ERROR, "SET SESSION CHARACTERISTICS duplicated entry not allowed");
ll = lnext(ll);
}
l = lnext(l);
}
l = stmt->args;
result = transformStmt(pstate, lfirst(l));
l = lnext(l);
if (l != NULL)
extras_after = lappend(extras_after, lfirst(l));
}
break;
/*------------------------ /*------------------------
* Optimizable statements * Optimizable statements
*------------------------ *------------------------
......
This diff is collapsed.
...@@ -8,11 +8,7 @@ ...@@ -8,11 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
<<<<<<< keywords.c * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.79 2000/07/14 15:43:32 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.78 2000/07/03 23:09:43 wieck Exp $
=======
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.78 2000/07/03 23:09:43 wieck Exp $
>>>>>>> 1.73
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,6 +57,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -61,6 +57,7 @@ static ScanKeyword ScanKeywords[] = {
{"cast", CAST}, {"cast", CAST},
{"char", CHAR}, {"char", CHAR},
{"character", CHARACTER}, {"character", CHARACTER},
{"characteristics", CHARACTERISTICS},
{"check", CHECK}, {"check", CHECK},
{"close", CLOSE}, {"close", CLOSE},
{"cluster", CLUSTER}, {"cluster", CLUSTER},
...@@ -134,6 +131,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -134,6 +131,7 @@ static ScanKeyword ScanKeywords[] = {
{"inherits", INHERITS}, {"inherits", INHERITS},
{"initially", INITIALLY}, {"initially", INITIALLY},
{"inner", INNER_P}, {"inner", INNER_P},
{"inout", INOUT},
{"insensitive", INSENSITIVE}, {"insensitive", INSENSITIVE},
{"insert", INSERT}, {"insert", INSERT},
{"instead", INSTEAD}, {"instead", INSTEAD},
...@@ -192,10 +190,12 @@ static ScanKeyword ScanKeywords[] = { ...@@ -192,10 +190,12 @@ static ScanKeyword ScanKeywords[] = {
{"option", OPTION}, {"option", OPTION},
{"or", OR}, {"or", OR},
{"order", ORDER}, {"order", ORDER},
{"out", OUT},
{"outer", OUTER_P}, {"outer", OUTER_P},
{"overlaps", OVERLAPS}, {"overlaps", OVERLAPS},
{"partial", PARTIAL}, {"partial", PARTIAL},
{"password", PASSWORD}, {"password", PASSWORD},
{"path", PATH_P},
{"pendant", PENDANT}, {"pendant", PENDANT},
{"position", POSITION}, {"position", POSITION},
{"precision", PRECISION}, {"precision", PRECISION},
...@@ -218,12 +218,14 @@ static ScanKeyword ScanKeywords[] = { ...@@ -218,12 +218,14 @@ static ScanKeyword ScanKeywords[] = {
{"rollback", ROLLBACK}, {"rollback", ROLLBACK},
{"row", ROW}, {"row", ROW},
{"rule", RULE}, {"rule", RULE},
{"schema", SCHEMA},
{"scroll", SCROLL}, {"scroll", SCROLL},
{"second", SECOND_P}, {"second", SECOND_P},
{"select", SELECT}, {"select", SELECT},
{"sequence", SEQUENCE}, {"sequence", SEQUENCE},
{"serial", SERIAL}, {"serial", SERIAL},
{"serializable", SERIALIZABLE}, {"serializable", SERIALIZABLE},
{"session", SESSION},
{"session_user", SESSION_USER}, {"session_user", SESSION_USER},
{"set", SET}, {"set", SET},
{"setof", SETOF}, {"setof", SETOF},
...@@ -273,6 +275,7 @@ static ScanKeyword ScanKeywords[] = { ...@@ -273,6 +275,7 @@ static ScanKeyword ScanKeywords[] = {
{"when", WHEN}, {"when", WHEN},
{"where", WHERE}, {"where", WHERE},
{"with", WITH}, {"with", WITH},
{"without", WITHOUT},
{"work", WORK}, {"work", WORK},
{"year", YEAR_P}, {"year", YEAR_P},
{"zone", ZONE}, {"zone", ZONE},
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.72 2000/06/14 18:17:37 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.73 2000/07/14 15:43:32 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,6 +72,8 @@ static char *literalbuf; /* expandable buffer */ ...@@ -72,6 +72,8 @@ static char *literalbuf; /* expandable buffer */
static int literallen; /* actual current length */ static int literallen; /* actual current length */
static int literalalloc; /* current allocated buffer size */ static int literalalloc; /* current allocated buffer size */
static int xcdepth = 0;
#define startlit() (literalbuf[0] = '\0', literallen = 0) #define startlit() (literalbuf[0] = '\0', literallen = 0)
static void addlit(char *ytext, int yleng); static void addlit(char *ytext, int yleng);
...@@ -157,7 +159,7 @@ xdinside [^"]+ ...@@ -157,7 +159,7 @@ xdinside [^"]+
*/ */
xcstart \/\*{op_chars}* xcstart \/\*{op_chars}*
xcstop \*+\/ xcstop \*+\/
xcinside ([^*]+)|(\*+[^/]) xcinside [^*/]+
digit [0-9] digit [0-9]
letter [\200-\377_A-Za-z] letter [\200-\377_A-Za-z]
...@@ -247,15 +249,29 @@ other . ...@@ -247,15 +249,29 @@ other .
{whitespace} { /* ignore */ } {whitespace} { /* ignore */ }
{xcstart} { {xcstart} {
xcdepth = 0;
BEGIN(xc); BEGIN(xc);
/* Put back any characters past slash-star; see above */ /* Put back any characters past slash-star; see above */
yyless(2); yyless(2);
} }
<xc>{xcstop} { BEGIN(INITIAL); } <xc>{xcstart} {
xcdepth++;
/* Put back any characters past slash-star; see above */
yyless(2);
}
<xc>{xcstop} {
if (xcdepth <= 0)
BEGIN(INITIAL);
else
xcdepth--;
}
<xc>{xcinside} { /* ignore */ } <xc>{xcinside} { /* ignore */ }
<xc>{op_chars} { /* ignore */ }
<xc><<EOF>> { elog(ERROR, "Unterminated /* comment"); } <xc><<EOF>> { elog(ERROR, "Unterminated /* comment"); }
{xbstart} { {xbstart} {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET * Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options. * command, configuration file, and command line options.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.6 2000/07/12 17:38:48 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.7 2000/07/14 15:43:47 thomas Exp $
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -508,7 +508,7 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -508,7 +508,7 @@ set_config_option(const char * name, const char * value, GucContext
type = find_option(name, &record); type = find_option(name, &record);
if (type == PGC_NONE) if (type == PGC_NONE)
{ {
elog(elevel, "not a valid option name: %s", name); elog(elevel, "'%s' is not a valid option name", name);
return false; return false;
} }
...@@ -520,14 +520,14 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -520,14 +520,14 @@ set_config_option(const char * name, const char * value, GucContext
if (record->context == PGC_POSTMASTER && context != PGC_POSTMASTER) if (record->context == PGC_POSTMASTER && context != PGC_POSTMASTER)
{ {
if (context != PGC_SIGHUP) if (context != PGC_SIGHUP)
elog(ERROR, "%s cannot be changed after server start", name); elog(ERROR, "'%s' cannot be changed after server start", name);
else else
return true; return true;
} }
else if (record->context == PGC_SIGHUP && context != PGC_SIGHUP && else if (record->context == PGC_SIGHUP && context != PGC_SIGHUP &&
context != PGC_POSTMASTER) context != PGC_POSTMASTER)
{ {
elog(ERROR, "%s cannot be changed now", name); elog(ERROR, "'%s' cannot be changed now", name);
/* Hmm, the idea of the SIGHUP context is "ought to be global, /* Hmm, the idea of the SIGHUP context is "ought to be global,
* but can be changed after postmaster start". But there's * but can be changed after postmaster start". But there's
* nothing that prevents a crafty administrator from sending * nothing that prevents a crafty administrator from sending
...@@ -537,7 +537,7 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -537,7 +537,7 @@ set_config_option(const char * name, const char * value, GucContext
&& context != PGC_POSTMASTER) && context != PGC_POSTMASTER)
{ {
if (context != PGC_SIGHUP) if (context != PGC_SIGHUP)
elog(ERROR, "%s cannot be set after connection start", name); elog(ERROR, "'%s' cannot be set after connection start", name);
else else
return true; return true;
} }
...@@ -562,7 +562,7 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -562,7 +562,7 @@ set_config_option(const char * name, const char * value, GucContext
bool boolval; bool boolval;
if (!parse_bool(value, &boolval)) if (!parse_bool(value, &boolval))
{ {
elog(elevel, "expected boolean value for option %s", name); elog(elevel, "Option '%s' requires a boolean value", name);
return false; return false;
} }
if (DoIt) if (DoIt)
...@@ -583,12 +583,14 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -583,12 +583,14 @@ set_config_option(const char * name, const char * value, GucContext
if (!parse_int(value, &intval)) if (!parse_int(value, &intval))
{ {
elog(elevel, "expected integer value for option %s", name); elog(elevel, "Option '%s' expects an integer value", name);
return false; return false;
} }
if (intval < conf->min || intval > conf->max) if (intval < conf->min || intval > conf->max)
{ {
elog(elevel, "value out of permissible range %d .. %d", conf->min, conf->max); elog(elevel, "Option '%s' value %d is outside"
" of permissible range [%d .. %d]",
name, intval, conf->min, conf->max);
return false; return false;
} }
if (DoIt) if (DoIt)
...@@ -609,12 +611,14 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -609,12 +611,14 @@ set_config_option(const char * name, const char * value, GucContext
if (!parse_real(value, &dval)) if (!parse_real(value, &dval))
{ {
elog(elevel, "expected real number for option %s", name); elog(elevel, "Option '%s' expects a real number", name);
return false; return false;
} }
if (dval < conf->min || dval > conf->max) if (dval < conf->min || dval > conf->max)
{ {
elog(elevel, "value out of permissible range %g .. %g", conf->min, conf->max); elog(elevel, "Option '%s' value %g is outside"
" of permissible range [%g .. %g]",
name, dval, conf->min, conf->max);
return false; return false;
} }
if (DoIt) if (DoIt)
...@@ -633,7 +637,7 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -633,7 +637,7 @@ set_config_option(const char * name, const char * value, GucContext
{ {
if (conf->parse_hook && !(conf->parse_hook)(value)) if (conf->parse_hook && !(conf->parse_hook)(value))
{ {
elog(elevel, "value '%s' not accepted for option %s", value, name); elog(elevel, "Option '%s' rejects value '%s'", name, value);
return false; return false;
} }
if (DoIt) if (DoIt)
...@@ -705,7 +709,7 @@ GetConfigOption(const char * name) ...@@ -705,7 +709,7 @@ GetConfigOption(const char * name)
opttype = find_option(name, &record); opttype = find_option(name, &record);
if (opttype == PGC_NONE) if (opttype == PGC_NONE)
elog(ERROR, "not a valid option name: %s", name); elog(ERROR, "Option '%s' is not recognized", name);
switch(opttype) switch(opttype)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.32 2000/06/30 18:03:40 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.33 2000/07/14 15:43:49 thomas Exp $
*/ */
#include "postgres.h" #include "postgres.h"
#include "mainloop.h" #include "mainloop.h"
...@@ -45,6 +45,7 @@ MainLoop(FILE *source) ...@@ -45,6 +45,7 @@ MainLoop(FILE *source)
bool success; bool success;
volatile char in_quote; /* == 0 for no in_quote */ volatile char in_quote; /* == 0 for no in_quote */
volatile bool in_xcomment; /* in extended comment */ volatile bool in_xcomment; /* in extended comment */
volatile int xcdepth;
volatile int paren_level; volatile int paren_level;
unsigned int query_start; unsigned int query_start;
volatile int count_eof = 0; volatile int count_eof = 0;
...@@ -315,15 +316,27 @@ MainLoop(FILE *source) ...@@ -315,15 +316,27 @@ MainLoop(FILE *source)
else if (in_xcomment) else if (in_xcomment)
{ {
if (line[i] == '*' && line[i + thislen] == '/') if (line[i] == '*' && line[i + thislen] == '/')
{
if (xcdepth > 0)
{
xcdepth--;
}
else
{ {
in_xcomment = false; in_xcomment = false;
ADVANCE_1; ADVANCE_1;
} }
} }
else if (line[i] == '/' && line[i + thislen] == '*')
{
xcdepth++;
}
}
/* start of extended comment? */ /* start of extended comment? */
else if (line[i] == '/' && line[i + thislen] == '*') else if (line[i] == '/' && line[i + thislen] == '*')
{ {
xcdepth = 0;
in_xcomment = true; in_xcomment = true;
ADVANCE_1; ADVANCE_1;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: nodes.h,v 1.70 2000/06/28 03:33:15 tgl Exp $ * $Id: nodes.h,v 1.71 2000/07/14 15:43:51 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -193,6 +193,7 @@ typedef enum NodeTag ...@@ -193,6 +193,7 @@ typedef enum NodeTag
T_AlterGroupStmt, T_AlterGroupStmt,
T_DropGroupStmt, T_DropGroupStmt,
T_ReindexStmt, T_ReindexStmt,
T_SetSessionStmt,
T_A_Expr = 700, T_A_Expr = 700,
T_Attr, T_Attr,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.108 2000/06/12 03:41:03 momjian Exp $ * $Id: parsenodes.h,v 1.109 2000/07/14 15:43:51 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -688,6 +688,16 @@ typedef struct ExplainStmt ...@@ -688,6 +688,16 @@ typedef struct ExplainStmt
bool verbose; /* print plan info */ bool verbose; /* print plan info */
} ExplainStmt; } ExplainStmt;
/* ----------------------
* Set Session Statement
* ----------------------
*/
typedef struct SetSessionStmt
{
NodeTag type;
List *args;
} SetSessionStmt;
/* ---------------------- /* ----------------------
* Set Statement * Set Statement
* ---------------------- * ----------------------
......
...@@ -34,4 +34,32 @@ SELECT 'after multi-line' AS fifth; ...@@ -34,4 +34,32 @@ SELECT 'after multi-line' AS fifth;
after multi-line after multi-line
(1 row) (1 row)
--
-- Nested comments
--
/*
SELECT 'trailing' as x1; -- inside block comment
*/
/* This block comment surrounds a query which itself has a block comment...
SELECT /* embedded single line */ 'embedded' AS x2;
*/
SELECT -- continued after the following block comments...
/* Deeply nested comment.
This includes a single apostrophe to make sure we aren't decoding this part as a string.
SELECT 'deep nest' AS n1;
/* Second level of nesting...
SELECT 'deeper nest' as n2;
/* Third level of nesting...
SELECT 'deepest nest' as n3;
*/
Hoo boy. Still two deep...
*/
Now just one deep...
*/
'deeply nested example' AS sixth;
sixth
-----------------------
deeply nested example
(1 row)
/* and this is the end of the file */ /* and this is the end of the file */
...@@ -12,5 +12,31 @@ SELECT 'before multi-line' AS fourth; ...@@ -12,5 +12,31 @@ SELECT 'before multi-line' AS fourth;
*/ */
SELECT 'after multi-line' AS fifth; SELECT 'after multi-line' AS fifth;
/* and this is the end of the file */ --
-- Nested comments
--
/*
SELECT 'trailing' as x1; -- inside block comment
*/
/* This block comment surrounds a query which itself has a block comment...
SELECT /* embedded single line */ 'embedded' AS x2;
*/
SELECT -- continued after the following block comments...
/* Deeply nested comment.
This includes a single apostrophe to make sure we aren't decoding this part as a string.
SELECT 'deep nest' AS n1;
/* Second level of nesting...
SELECT 'deeper nest' as n2;
/* Third level of nesting...
SELECT 'deepest nest' as n3;
*/
Hoo boy. Still two deep...
*/
Now just one deep...
*/
'deeply nested example' AS sixth;
/* and this is the end of the file */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment