*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
void
-createdb(const char *dbname, const char *dbowner,
- const char *dbpath, const char *dbtemplate,
- int encoding)
+createdb(CreatedbStmt *stmt)
{
char *nominal_loc;
char *alt_loc;
char new_record_nulls[Natts_pg_database];
Oid dboid;
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 */
if (dbowner)
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
if (from->dbname)
newnode->dbname = pstrdup(from->dbname);
- if (from->dbowner)
- 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;
+ Node_Copy(from, newnode, options);
return newnode;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
{
if (!equalstr(a->dbname, b->dbname))
return false;
- if (!equalstr(a->dbowner, b->dbowner))
- return false;
- if (!equalstr(a->dbpath, b->dbpath))
- return false;
- if (!equalstr(a->dbtemplate, b->dbtemplate))
- return false;
- if (a->encoding != b->encoding)
+ if (!equal(a->options, b->options))
return false;
return true;
*
*
* 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
* AUTHOR DATE MAJOR EVENT
%type alter_column_default
%type add_drop, drop_behavior, opt_drop_behavior
-%type createdb_opt_list, createdb_opt_item
+%type createdb_opt_list
+%type createdb_opt_item
%type opt_equal
%type opt_lock, lock_type
CREATE DATABASE database_name opt_with createdb_opt_list
{
CreatedbStmt *n = makeNode(CreatedbStmt);
- List *l;
-
n->dbname = $3;
- /* set default options */
- 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;
- }
- }
+ n->options = $5;
$$ = (Node *)n;
}
;
createdb_opt_item:
LOCATION opt_equal Sconst
{
- $$ = lconsi(1, makeList1($3));
+ $$ = makeNode(DefElem);
+ $$->defname = "location";
+ $$->arg = (Node *)makeString($3);
}
| LOCATION opt_equal DEFAULT
{
- $$ = lconsi(1, makeList1(NULL));
+ $$ = makeNode(DefElem);
+ $$->defname = "location";
+ $$->arg = NULL;
}
| TEMPLATE opt_equal name
{
- $$ = lconsi(2, makeList1($3));
+ $$ = makeNode(DefElem);
+ $$->defname = "template";
+ $$->arg = (Node *)makeString($3);
}
| TEMPLATE opt_equal DEFAULT
{
- $$ = lconsi(2, makeList1(NULL));
+ $$ = makeNode(DefElem);
+ $$->defname = "template";
+ $$->arg = NULL;
}
| ENCODING opt_equal Sconst
{
elog(ERROR, "Multi-byte support is not enabled");
encoding = GetStandardEncoding();
#endif
- $$ = lconsi(3, makeListi1(encoding));
+ $$ = makeNode(DefElem);
+ $$->defname = "encoding";
+ $$->arg = (Node *)makeInteger(encoding);
}
| ENCODING opt_equal Iconst
{
if ($3 != GetStandardEncoding())
elog(ERROR, "Multi-byte support is not enabled");
#endif
- $$ = lconsi(3, makeListi1($3));
+ $$ = makeNode(DefElem);
+ $$->defname = "encoding";
+ $$->arg = (Node *)makeInteger($3);
}
| ENCODING opt_equal DEFAULT
{
- $$ = lconsi(3, makeListi1(-1));
+ $$ = makeNode(DefElem);
+ $$->defname = "encoding";
+ $$->arg = (Node *)makeInteger(-1);
}
| OWNER opt_equal name
{
- $$ = lconsi(4, makeList1($3));
+ $$ = makeNode(DefElem);
+ $$->defname = "owner";
+ $$->arg = (Node *)makeString($3);
}
| OWNER opt_equal DEFAULT
{
- $$ = lconsi(4, makeList1(NULL));
+ $$ = makeNode(DefElem);
+ $$->defname = "owner";
+ $$->arg = NULL;
}
;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
case T_CreatedbStmt:
{
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
-
- createdb(stmt->dbname, stmt->dbowner,
- stmt->dbpath, stmt->dbtemplate,
- stmt->encoding);
+ createdb(stmt);
}
break;
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
#include
-extern void createdb(const char *dbname, const char *dbowner,
- const char *dbpath, const char *dbtemplate,
- int encoding);
+extern void createdb(CreatedbStmt *stmt);
extern void dropdb(const char *dbname);
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
{
NodeTag type;
char *dbname; /* name of database to create */
- char *dbowner; /* name of owner (NULL = default) */
- char *dbpath; /* location of database (NULL = default) */
- char *dbtemplate; /* template to use (NULL = default) */
- int encoding; /* MULTIBYTE encoding (-1 = use default) */
+ List *options; /* List of DefElem nodes */
} CreatedbStmt;
/* ----------------------