mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Change CREATE DATABASE to use DefElem instead of constructing structure
members in gram.y. This is the prefered method for WITH and arbitrary param/value pairs.
This commit is contained in:
parent
3d564953cd
commit
71fd49e28d
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.92 2002/05/25 16:30:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.93 2002/06/18 17:27:57 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -58,9 +58,7 @@ static bool remove_dbdirs(const char *real_loc, const char *altloc);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
createdb(const char *dbname, const char *dbowner,
|
createdb(CreatedbStmt *stmt)
|
||||||
const char *dbpath, const char *dbtemplate,
|
|
||||||
int encoding)
|
|
||||||
{
|
{
|
||||||
char *nominal_loc;
|
char *nominal_loc;
|
||||||
char *alt_loc;
|
char *alt_loc;
|
||||||
@ -82,6 +80,59 @@ createdb(const char *dbname, const char *dbowner,
|
|||||||
char new_record_nulls[Natts_pg_database];
|
char new_record_nulls[Natts_pg_database];
|
||||||
Oid dboid;
|
Oid dboid;
|
||||||
int32 datdba;
|
int32 datdba;
|
||||||
|
List *option;
|
||||||
|
DefElem *downer = NULL;
|
||||||
|
DefElem *dpath = NULL;
|
||||||
|
DefElem *dtemplate = NULL;
|
||||||
|
DefElem *dencoding = NULL;
|
||||||
|
char *dbname = stmt->dbname;
|
||||||
|
char *dbowner = NULL;
|
||||||
|
char *dbpath = NULL;
|
||||||
|
char *dbtemplate = NULL;
|
||||||
|
int encoding = -1;
|
||||||
|
|
||||||
|
/* Extract options from the statement node tree */
|
||||||
|
foreach(option, stmt->options)
|
||||||
|
{
|
||||||
|
DefElem *defel = (DefElem *) lfirst(option);
|
||||||
|
|
||||||
|
if (strcmp(defel->defname, "owner") == 0)
|
||||||
|
{
|
||||||
|
if (downer)
|
||||||
|
elog(ERROR, "CREATE DATABASE: conflicting options");
|
||||||
|
downer = defel;
|
||||||
|
}
|
||||||
|
else if (strcmp(defel->defname, "location") == 0)
|
||||||
|
{
|
||||||
|
if (dpath)
|
||||||
|
elog(ERROR, "CREATE DATABASE: conflicting options");
|
||||||
|
dpath = defel;
|
||||||
|
}
|
||||||
|
else if (strcmp(defel->defname, "template") == 0)
|
||||||
|
{
|
||||||
|
if (dtemplate)
|
||||||
|
elog(ERROR, "CREATE DATABASE: conflicting options");
|
||||||
|
dtemplate = defel;
|
||||||
|
}
|
||||||
|
else if (strcmp(defel->defname, "encoding") == 0)
|
||||||
|
{
|
||||||
|
if (dencoding)
|
||||||
|
elog(ERROR, "CREATE DATABASE: conflicting options");
|
||||||
|
dencoding = defel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
elog(ERROR, "CREATE DATABASE: option \"%s\" not recognized",
|
||||||
|
defel->defname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (downer)
|
||||||
|
dbowner = strVal(downer->arg);
|
||||||
|
if (dpath)
|
||||||
|
dbpath = strVal(dpath->arg);
|
||||||
|
if (dtemplate)
|
||||||
|
dbtemplate = strVal(dtemplate->arg);
|
||||||
|
if (dencoding)
|
||||||
|
encoding = intVal(dencoding->arg);
|
||||||
|
|
||||||
/* obtain sysid of proposed owner */
|
/* obtain sysid of proposed owner */
|
||||||
if (dbowner)
|
if (dbowner)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.188 2002/05/22 17:20:58 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.189 2002/06/18 17:27:57 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2258,13 +2258,7 @@ _copyCreatedbStmt(CreatedbStmt *from)
|
|||||||
|
|
||||||
if (from->dbname)
|
if (from->dbname)
|
||||||
newnode->dbname = pstrdup(from->dbname);
|
newnode->dbname = pstrdup(from->dbname);
|
||||||
if (from->dbowner)
|
Node_Copy(from, newnode, options);
|
||||||
newnode->dbowner = pstrdup(from->dbowner);
|
|
||||||
if (from->dbpath)
|
|
||||||
newnode->dbpath = pstrdup(from->dbpath);
|
|
||||||
if (from->dbtemplate)
|
|
||||||
newnode->dbtemplate = pstrdup(from->dbtemplate);
|
|
||||||
newnode->encoding = from->encoding;
|
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.135 2002/05/22 17:20:59 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.136 2002/06/18 17:27:57 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1085,13 +1085,7 @@ _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
|
|||||||
{
|
{
|
||||||
if (!equalstr(a->dbname, b->dbname))
|
if (!equalstr(a->dbname, b->dbname))
|
||||||
return false;
|
return false;
|
||||||
if (!equalstr(a->dbowner, b->dbowner))
|
if (!equal(a->options, b->options))
|
||||||
return false;
|
|
||||||
if (!equalstr(a->dbpath, b->dbpath))
|
|
||||||
return false;
|
|
||||||
if (!equalstr(a->dbtemplate, b->dbtemplate))
|
|
||||||
return false;
|
|
||||||
if (a->encoding != b->encoding)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.328 2002/06/18 00:28:11 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.329 2002/06/18 17:27:57 momjian Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -154,7 +154,8 @@ static void doNegateFloat(Value *v);
|
|||||||
%type <node> alter_column_default
|
%type <node> alter_column_default
|
||||||
%type <ival> add_drop, drop_behavior, opt_drop_behavior
|
%type <ival> add_drop, drop_behavior, opt_drop_behavior
|
||||||
|
|
||||||
%type <list> createdb_opt_list, createdb_opt_item
|
%type <list> createdb_opt_list
|
||||||
|
%type <defelt> createdb_opt_item
|
||||||
%type <boolean> opt_equal
|
%type <boolean> opt_equal
|
||||||
|
|
||||||
%type <ival> opt_lock, lock_type
|
%type <ival> opt_lock, lock_type
|
||||||
@ -3351,35 +3352,8 @@ CreatedbStmt:
|
|||||||
CREATE DATABASE database_name opt_with createdb_opt_list
|
CREATE DATABASE database_name opt_with createdb_opt_list
|
||||||
{
|
{
|
||||||
CreatedbStmt *n = makeNode(CreatedbStmt);
|
CreatedbStmt *n = makeNode(CreatedbStmt);
|
||||||
List *l;
|
|
||||||
|
|
||||||
n->dbname = $3;
|
n->dbname = $3;
|
||||||
/* set default options */
|
n->options = $5;
|
||||||
n->dbowner = NULL;
|
|
||||||
n->dbpath = NULL;
|
|
||||||
n->dbtemplate = NULL;
|
|
||||||
n->encoding = -1;
|
|
||||||
/* process additional options */
|
|
||||||
foreach(l, $5)
|
|
||||||
{
|
|
||||||
List *optitem = (List *) lfirst(l);
|
|
||||||
|
|
||||||
switch (lfirsti(optitem))
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
n->dbpath = (char *) lsecond(optitem);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
n->dbtemplate = (char *) lsecond(optitem);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
n->encoding = lfirsti(lnext(optitem));
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
n->dbowner = (char *) lsecond(optitem);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -3396,19 +3370,27 @@ createdb_opt_list:
|
|||||||
createdb_opt_item:
|
createdb_opt_item:
|
||||||
LOCATION opt_equal Sconst
|
LOCATION opt_equal Sconst
|
||||||
{
|
{
|
||||||
$$ = lconsi(1, makeList1($3));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "location";
|
||||||
|
$$->arg = (Node *)makeString($3);
|
||||||
}
|
}
|
||||||
| LOCATION opt_equal DEFAULT
|
| LOCATION opt_equal DEFAULT
|
||||||
{
|
{
|
||||||
$$ = lconsi(1, makeList1(NULL));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "location";
|
||||||
|
$$->arg = NULL;
|
||||||
}
|
}
|
||||||
| TEMPLATE opt_equal name
|
| TEMPLATE opt_equal name
|
||||||
{
|
{
|
||||||
$$ = lconsi(2, makeList1($3));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "template";
|
||||||
|
$$->arg = (Node *)makeString($3);
|
||||||
}
|
}
|
||||||
| TEMPLATE opt_equal DEFAULT
|
| TEMPLATE opt_equal DEFAULT
|
||||||
{
|
{
|
||||||
$$ = lconsi(2, makeList1(NULL));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "template";
|
||||||
|
$$->arg = NULL;
|
||||||
}
|
}
|
||||||
| ENCODING opt_equal Sconst
|
| ENCODING opt_equal Sconst
|
||||||
{
|
{
|
||||||
@ -3422,7 +3404,9 @@ createdb_opt_item:
|
|||||||
elog(ERROR, "Multi-byte support is not enabled");
|
elog(ERROR, "Multi-byte support is not enabled");
|
||||||
encoding = GetStandardEncoding();
|
encoding = GetStandardEncoding();
|
||||||
#endif
|
#endif
|
||||||
$$ = lconsi(3, makeListi1(encoding));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "encoding";
|
||||||
|
$$->arg = (Node *)makeInteger(encoding);
|
||||||
}
|
}
|
||||||
| ENCODING opt_equal Iconst
|
| ENCODING opt_equal Iconst
|
||||||
{
|
{
|
||||||
@ -3433,19 +3417,27 @@ createdb_opt_item:
|
|||||||
if ($3 != GetStandardEncoding())
|
if ($3 != GetStandardEncoding())
|
||||||
elog(ERROR, "Multi-byte support is not enabled");
|
elog(ERROR, "Multi-byte support is not enabled");
|
||||||
#endif
|
#endif
|
||||||
$$ = lconsi(3, makeListi1($3));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "encoding";
|
||||||
|
$$->arg = (Node *)makeInteger($3);
|
||||||
}
|
}
|
||||||
| ENCODING opt_equal DEFAULT
|
| ENCODING opt_equal DEFAULT
|
||||||
{
|
{
|
||||||
$$ = lconsi(3, makeListi1(-1));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "encoding";
|
||||||
|
$$->arg = (Node *)makeInteger(-1);
|
||||||
}
|
}
|
||||||
| OWNER opt_equal name
|
| OWNER opt_equal name
|
||||||
{
|
{
|
||||||
$$ = lconsi(4, makeList1($3));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "owner";
|
||||||
|
$$->arg = (Node *)makeString($3);
|
||||||
}
|
}
|
||||||
| OWNER opt_equal DEFAULT
|
| OWNER opt_equal DEFAULT
|
||||||
{
|
{
|
||||||
$$ = lconsi(4, makeList1(NULL));
|
$$ = makeNode(DefElem);
|
||||||
|
$$->defname = "owner";
|
||||||
|
$$->arg = NULL;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.156 2002/05/21 22:18:08 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.157 2002/06/18 17:27:58 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -630,10 +630,7 @@ ProcessUtility(Node *parsetree,
|
|||||||
case T_CreatedbStmt:
|
case T_CreatedbStmt:
|
||||||
{
|
{
|
||||||
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
|
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
|
||||||
|
createdb(stmt);
|
||||||
createdb(stmt->dbname, stmt->dbowner,
|
|
||||||
stmt->dbpath, stmt->dbtemplate,
|
|
||||||
stmt->encoding);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: dbcommands.h,v 1.21 2002/03/01 22:45:17 petere Exp $
|
* $Id: dbcommands.h,v 1.22 2002/06/18 17:27:58 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
#include <nodes/parsenodes.h>
|
#include <nodes/parsenodes.h>
|
||||||
|
|
||||||
extern void createdb(const char *dbname, const char *dbowner,
|
extern void createdb(CreatedbStmt *stmt);
|
||||||
const char *dbpath, const char *dbtemplate,
|
|
||||||
int encoding);
|
|
||||||
extern void dropdb(const char *dbname);
|
extern void dropdb(const char *dbname);
|
||||||
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
|
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* 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.179 2002/05/22 17:21:01 petere Exp $
|
* $Id: parsenodes.h,v 1.180 2002/06/18 17:27:58 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1350,10 +1350,7 @@ typedef struct CreatedbStmt
|
|||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
char *dbname; /* name of database to create */
|
char *dbname; /* name of database to create */
|
||||||
char *dbowner; /* name of owner (NULL = default) */
|
List *options; /* List of DefElem nodes */
|
||||||
char *dbpath; /* location of database (NULL = default) */
|
|
||||||
char *dbtemplate; /* template to use (NULL = default) */
|
|
||||||
int encoding; /* MULTIBYTE encoding (-1 = use default) */
|
|
||||||
} CreatedbStmt;
|
} CreatedbStmt;
|
||||||
|
|
||||||
/* ----------------------
|
/* ----------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user