Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71fd49e

Browse files
committed
Change CREATE DATABASE to use DefElem instead of constructing structure
members in gram.y. This is the prefered method for WITH and arbitraryparam/value pairs.
1 parent3d56495 commit71fd49e

File tree

7 files changed

+96
-73
lines changed

7 files changed

+96
-73
lines changed

‎src/backend/commands/dbcommands.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.92 2002/05/25 16:30:59 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.93 2002/06/18 17:27:57 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -58,9 +58,7 @@ static bool remove_dbdirs(const char *real_loc, const char *altloc);
5858
*/
5959

6060
void
61-
createdb(constchar*dbname,constchar*dbowner,
62-
constchar*dbpath,constchar*dbtemplate,
63-
intencoding)
61+
createdb(CreatedbStmt*stmt)
6462
{
6563
char*nominal_loc;
6664
char*alt_loc;
@@ -82,6 +80,59 @@ createdb(const char *dbname, const char *dbowner,
8280
charnew_record_nulls[Natts_pg_database];
8381
Oiddboid;
8482
int32datdba;
83+
List*option;
84+
DefElem*downer=NULL;
85+
DefElem*dpath=NULL;
86+
DefElem*dtemplate=NULL;
87+
DefElem*dencoding=NULL;
88+
char*dbname=stmt->dbname;
89+
char*dbowner=NULL;
90+
char*dbpath=NULL;
91+
char*dbtemplate=NULL;
92+
intencoding=-1;
93+
94+
/* Extract options from the statement node tree */
95+
foreach(option,stmt->options)
96+
{
97+
DefElem*defel= (DefElem*)lfirst(option);
98+
99+
if (strcmp(defel->defname,"owner")==0)
100+
{
101+
if (downer)
102+
elog(ERROR,"CREATE DATABASE: conflicting options");
103+
downer=defel;
104+
}
105+
elseif (strcmp(defel->defname,"location")==0)
106+
{
107+
if (dpath)
108+
elog(ERROR,"CREATE DATABASE: conflicting options");
109+
dpath=defel;
110+
}
111+
elseif (strcmp(defel->defname,"template")==0)
112+
{
113+
if (dtemplate)
114+
elog(ERROR,"CREATE DATABASE: conflicting options");
115+
dtemplate=defel;
116+
}
117+
elseif (strcmp(defel->defname,"encoding")==0)
118+
{
119+
if (dencoding)
120+
elog(ERROR,"CREATE DATABASE: conflicting options");
121+
dencoding=defel;
122+
}
123+
else
124+
elog(ERROR,"CREATE DATABASE: option \"%s\" not recognized",
125+
defel->defname);
126+
}
127+
128+
if (downer)
129+
dbowner=strVal(downer->arg);
130+
if (dpath)
131+
dbpath=strVal(dpath->arg);
132+
if (dtemplate)
133+
dbtemplate=strVal(dtemplate->arg);
134+
if (dencoding)
135+
encoding=intVal(dencoding->arg);
85136

86137
/* obtain sysid of proposed owner */
87138
if (dbowner)

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.188 2002/05/22 17:20:58 petere Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.189 2002/06/18 17:27:57 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2258,13 +2258,7 @@ _copyCreatedbStmt(CreatedbStmt *from)
22582258

22592259
if (from->dbname)
22602260
newnode->dbname=pstrdup(from->dbname);
2261-
if (from->dbowner)
2262-
newnode->dbowner=pstrdup(from->dbowner);
2263-
if (from->dbpath)
2264-
newnode->dbpath=pstrdup(from->dbpath);
2265-
if (from->dbtemplate)
2266-
newnode->dbtemplate=pstrdup(from->dbtemplate);
2267-
newnode->encoding=from->encoding;
2261+
Node_Copy(from,newnode,options);
22682262

22692263
returnnewnode;
22702264
}

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.135 2002/05/22 17:20:59 petere Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.136 2002/06/18 17:27:57 momjian Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -1085,13 +1085,7 @@ _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
10851085
{
10861086
if (!equalstr(a->dbname,b->dbname))
10871087
return false;
1088-
if (!equalstr(a->dbowner,b->dbowner))
1089-
return false;
1090-
if (!equalstr(a->dbpath,b->dbpath))
1091-
return false;
1092-
if (!equalstr(a->dbtemplate,b->dbtemplate))
1093-
return false;
1094-
if (a->encoding!=b->encoding)
1088+
if (!equal(a->options,b->options))
10951089
return false;
10961090

10971091
return true;

‎src/backend/parser/gram.y

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.328 2002/06/1800:28:11 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.329 2002/06/1817:27:57 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -154,7 +154,8 @@ static void doNegateFloat(Value *v);
154154
%type<node>alter_column_default
155155
%type<ival>add_drop,drop_behavior,opt_drop_behavior
156156

157-
%type<list>createdb_opt_list,createdb_opt_item
157+
%type<list>createdb_opt_list
158+
%type<defelt>createdb_opt_item
158159
%type<boolean>opt_equal
159160

160161
%type<ival>opt_lock,lock_type
@@ -3351,35 +3352,8 @@ CreatedbStmt:
33513352
CREATEDATABASEdatabase_nameopt_withcreatedb_opt_list
33523353
{
33533354
CreatedbStmt *n = makeNode(CreatedbStmt);
3354-
List *l;
3355-
33563355
n->dbname =$3;
3357-
/* set default options*/
3358-
n->dbowner =NULL;
3359-
n->dbpath =NULL;
3360-
n->dbtemplate =NULL;
3361-
n->encoding = -1;
3362-
/* process additional options*/
3363-
foreach(l, $5)
3364-
{
3365-
List *optitem = (List *)lfirst(l);
3366-
3367-
switch (lfirsti(optitem))
3368-
{
3369-
case1:
3370-
n->dbpath = (char *)lsecond(optitem);
3371-
break;
3372-
case2:
3373-
n->dbtemplate = (char *)lsecond(optitem);
3374-
break;
3375-
case3:
3376-
n->encoding =lfirsti(lnext(optitem));
3377-
break;
3378-
case4:
3379-
n->dbowner = (char *)lsecond(optitem);
3380-
break;
3381-
}
3382-
}
3356+
n->options =$5;
33833357
$$ = (Node *)n;
33843358
}
33853359
;
@@ -3396,19 +3370,27 @@ createdb_opt_list:
33963370
createdb_opt_item:
33973371
LOCATIONopt_equalSconst
33983372
{
3399-
$$ = lconsi(1, makeList1($3));
3373+
$$ = makeNode(DefElem);
3374+
$$->defname ="location";
3375+
$$->arg = (Node *)makeString($3);
34003376
}
34013377
|LOCATIONopt_equalDEFAULT
34023378
{
3403-
$$ = lconsi(1, makeList1(NULL));
3379+
$$ = makeNode(DefElem);
3380+
$$->defname ="location";
3381+
$$->arg =NULL;
34043382
}
34053383
|TEMPLATEopt_equalname
34063384
{
3407-
$$ = lconsi(2, makeList1($3));
3385+
$$ = makeNode(DefElem);
3386+
$$->defname ="template";
3387+
$$->arg = (Node *)makeString($3);
34083388
}
34093389
|TEMPLATEopt_equalDEFAULT
34103390
{
3411-
$$ = lconsi(2, makeList1(NULL));
3391+
$$ = makeNode(DefElem);
3392+
$$->defname ="template";
3393+
$$->arg =NULL;
34123394
}
34133395
|ENCODINGopt_equalSconst
34143396
{
@@ -3422,7 +3404,9 @@ createdb_opt_item:
34223404
elog(ERROR,"Multi-byte support is not enabled");
34233405
encoding = GetStandardEncoding();
34243406
#endif
3425-
$$ = lconsi(3, makeListi1(encoding));
3407+
$$ = makeNode(DefElem);
3408+
$$->defname ="encoding";
3409+
$$->arg = (Node *)makeInteger(encoding);
34263410
}
34273411
|ENCODINGopt_equalIconst
34283412
{
@@ -3433,19 +3417,27 @@ createdb_opt_item:
34333417
if ($3 != GetStandardEncoding())
34343418
elog(ERROR,"Multi-byte support is not enabled");
34353419
#endif
3436-
$$ = lconsi(3, makeListi1($3));
3420+
$$ = makeNode(DefElem);
3421+
$$->defname ="encoding";
3422+
$$->arg = (Node *)makeInteger($3);
34373423
}
34383424
|ENCODINGopt_equalDEFAULT
34393425
{
3440-
$$ = lconsi(3, makeListi1(-1));
3426+
$$ = makeNode(DefElem);
3427+
$$->defname ="encoding";
3428+
$$->arg = (Node *)makeInteger(-1);
34413429
}
34423430
|OWNERopt_equalname
34433431
{
3444-
$$ = lconsi(4, makeList1($3));
3432+
$$ = makeNode(DefElem);
3433+
$$->defname ="owner";
3434+
$$->arg = (Node *)makeString($3);
34453435
}
34463436
|OWNERopt_equalDEFAULT
34473437
{
3448-
$$ = lconsi(4, makeList1(NULL));
3438+
$$ = makeNode(DefElem);
3439+
$$->defname ="owner";
3440+
$$->arg =NULL;
34493441
}
34503442
;
34513443

‎src/backend/tcop/utility.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.156 2002/05/21 22:18:08 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.157 2002/06/18 17:27:58 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -630,10 +630,7 @@ ProcessUtility(Node *parsetree,
630630
caseT_CreatedbStmt:
631631
{
632632
CreatedbStmt*stmt= (CreatedbStmt*)parsetree;
633-
634-
createdb(stmt->dbname,stmt->dbowner,
635-
stmt->dbpath,stmt->dbtemplate,
636-
stmt->encoding);
633+
createdb(stmt);
637634
}
638635
break;
639636

‎src/include/commands/dbcommands.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: dbcommands.h,v 1.21 2002/03/01 22:45:17 petere Exp $
10+
* $Id: dbcommands.h,v 1.22 2002/06/18 17:27:58 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,9 +16,7 @@
1616

1717
#include<nodes/parsenodes.h>
1818

19-
externvoidcreatedb(constchar*dbname,constchar*dbowner,
20-
constchar*dbpath,constchar*dbtemplate,
21-
intencoding);
19+
externvoidcreatedb(CreatedbStmt*stmt);
2220
externvoiddropdb(constchar*dbname);
2321
externvoidAlterDatabaseSet(AlterDatabaseSetStmt*stmt);
2422

‎src/include/nodes/parsenodes.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parsenodes.h,v 1.179 2002/05/22 17:21:01 petere Exp $
10+
* $Id: parsenodes.h,v 1.180 2002/06/18 17:27:58 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1350,10 +1350,7 @@ typedef struct CreatedbStmt
13501350
{
13511351
NodeTagtype;
13521352
char*dbname;/* name of database to create */
1353-
char*dbowner;/* name of owner (NULL = default) */
1354-
char*dbpath;/* location of database (NULL = default) */
1355-
char*dbtemplate;/* template to use (NULL = default) */
1356-
intencoding;/* MULTIBYTE encoding (-1 = use default) */
1353+
List*options;/* List of DefElem nodes */
13571354
}CreatedbStmt;
13581355

13591356
/* ----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp