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

Commit7f171b5

Browse files
committed
This patch implements the following command:
ALTER TABLE <tablename> OWNER TO <username>Only a superuser may execute the command.--Mark Hollomonmhh@mindspring.com
1 parent65edb54 commit7f171b5

File tree

10 files changed

+292
-208
lines changed

10 files changed

+292
-208
lines changed

‎src/backend/commands/command.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.101 2000/09/1204:49:06 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.102 2000/09/1205:09:43 momjian Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -47,6 +47,7 @@
4747
#include"utils/temprel.h"
4848
#include"executor/spi_priv.h"
4949
#include"catalog/pg_index.h"
50+
#include"catalog/pg_shadow.h"
5051
#include"utils/relcache.h"
5152

5253
#ifdef_DROP_COLUMN_HACK__
@@ -1449,6 +1450,70 @@ AlterTableDropConstraint(const char *relationName,
14491450

14501451

14511452

1453+
/*
1454+
* ALTER TABLE OWNER
1455+
*/
1456+
void
1457+
AlterTableOwner(constchar*relationName,constchar*newOwnerName)
1458+
{
1459+
Relationclass_rel;
1460+
HeapTupletuple;
1461+
int4newOwnerSysid;
1462+
Relationidescs[Num_pg_class_indices];
1463+
1464+
/*
1465+
* first check that we are a superuser
1466+
*/
1467+
if (!superuser() )
1468+
elog(ERROR,"ALTER TABLE: permission denied");
1469+
1470+
/*
1471+
* look up the new owner in pg_shadow and get the sysid
1472+
*/
1473+
tuple=SearchSysCacheTuple(SHADOWNAME,PointerGetDatum(newOwnerName),
1474+
0,0,0);
1475+
if (!HeapTupleIsValid(tuple))
1476+
elog(ERROR,"ALTER TABLE: user \"%s\" not found",newOwnerName);
1477+
1478+
newOwnerSysid= ((Form_pg_shadow)GETSTRUCT(tuple))->usesysid;
1479+
heap_freetuple(tuple);
1480+
1481+
/*
1482+
* find the table's entry in pg_class and lock it for writing
1483+
*/
1484+
class_rel=heap_openr(RelationRelationName,RowExclusiveLock);
1485+
1486+
tuple=SearchSysCacheTuple(RELNAME,PointerGetDatum(relationName),
1487+
0,0,0);
1488+
if (!HeapTupleIsValid(tuple))
1489+
elog(ERROR,"ALTER TABLE: relation \"%s\" not found",
1490+
relationName);
1491+
1492+
if (((Form_pg_class)GETSTRUCT(tuple))->relkind!=RELKIND_RELATION)
1493+
elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table",
1494+
relationName);
1495+
1496+
/*
1497+
* modify the table's entry and write to the heap
1498+
*/
1499+
((Form_pg_class)GETSTRUCT(tuple))->relowner=newOwnerSysid;
1500+
1501+
heap_update(class_rel,&tuple->t_self,tuple,NULL);
1502+
1503+
/* Keep the catalog indices up to date */
1504+
CatalogOpenIndices(Num_pg_class_indices,Name_pg_class_indices,idescs);
1505+
CatalogIndexInsert(idescs,Num_pg_class_indices,class_rel,tuple);
1506+
CatalogCloseIndices(Num_pg_class_indices,idescs);
1507+
1508+
/*
1509+
* unlock everything and return
1510+
*/
1511+
heap_freetuple(tuple);
1512+
heap_close(class_rel,RowExclusiveLock);
1513+
1514+
return;
1515+
}
1516+
14521517
/*
14531518
* ALTER TABLE CREATE TOAST TABLE
14541519
*/

‎src/backend/parser/gram.y

Lines changed: 13 additions & 2 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.187 2000/08/26 21:53:43 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.188 2000/09/12 05:09:44 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -350,7 +350,7 @@ static void doNegateFloat(Value *v);
350350
LANCOMPILER,LIMIT,LISTEN,LOAD,LOCATION,LOCK_P,
351351
MAXVALUE,MINVALUE,MODE,MOVE,
352352
NEW,NOCREATEDB,NOCREATEUSER,NONE,NOTHING,NOTIFY,NOTNULL,
353-
OFFSET,OIDS,OPERATOR,PASSWORD,PROCEDURAL,
353+
OFFSET,OIDS,OPERATOR,OWNER,PASSWORD,PROCEDURAL,
354354
REINDEX,RENAME,RESET,RETURNS,ROW,RULE,
355355
SEQUENCE,SERIAL,SETOF,SHARE,SHOW,START,STATEMENT,STDIN,STDOUT,SYSID,
356356
TEMP,TOAST,TRUNCATE,TRUSTED,
@@ -1031,6 +1031,16 @@ AlterTableStmt:
10311031
n->relname =$3;
10321032
$$ = (Node *)n;
10331033
}
1034+
1035+
/* ALTER TABLE <name> OWNER TO UserId*/
1036+
|ALTERTABLErelation_nameOWNERTOUserId
1037+
{
1038+
AlterTableStmt *n = makeNode(AlterTableStmt);
1039+
n->subtype ='U';
1040+
n->relname =$3;
1041+
n->name =$6;
1042+
$$ = (Node *)n;
1043+
}
10341044
;
10351045

10361046
alter_column_action:
@@ -5641,6 +5651,7 @@ TokenId: ABSOLUTE{ $$ = "absolute"; }
56415651
|OIDS{$$ ="oids"; }
56425652
|OPERATOR{$$ ="operator"; }
56435653
|OPTION{$$ ="option"; }
5654+
|OWNER{$$ ="owner"; }
56445655
|PARTIAL{$$ ="partial"; }
56455656
|PASSWORD{$$ ="password"; }
56465657
|PENDANT{$$ ="pendant"; }

‎src/backend/parser/keywords.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.80 2000/08/06 18:05:22 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.81 2000/09/1205:09:44 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -196,6 +196,7 @@ static ScanKeyword ScanKeywords[] = {
196196
{"out",OUT},
197197
{"outer",OUTER_P},
198198
{"overlaps",OVERLAPS},
199+
{"owner",OWNER},
199200
{"partial",PARTIAL},
200201
{"password",PASSWORD},
201202
{"path",PATH_P},

‎src/backend/tcop/utility.c

Lines changed: 4 additions & 1 deletion
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.93 2000/09/1204:49:11 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.94 2000/09/1205:09:45 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -371,6 +371,9 @@ ProcessUtility(Node *parsetree,
371371
case'E':/* CREATE TOAST TABLE */
372372
AlterTableCreateToastTable(stmt->relname, false);
373373
break;
374+
case'U':/* ALTER OWNER */
375+
AlterTableOwner(stmt->relname,stmt->name);
376+
break;
374377
default:/* oops */
375378
elog(ERROR,"T_AlterTableStmt: unknown subtype");
376379
break;

‎src/include/commands/command.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: command.h,v 1.22 2000/07/18 03:57:32 tgl Exp $
10+
* $Id: command.h,v 1.23 2000/09/12 05:09:47 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -61,6 +61,8 @@ extern void AlterTableDropConstraint(const char *relationName,
6161
externvoidAlterTableCreateToastTable(constchar*relationName,
6262
boolsilent);
6363

64+
externvoidAlterTableOwner(constchar*relationName,constchar*newOwnerName);
65+
6466
/*
6567
* LOCK
6668
*/

‎src/include/nodes/parsenodes.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parsenodes.h,v 1.111 2000/08/11 23:46:54 tgl Exp $
10+
* $Id: parsenodes.h,v 1.112 2000/09/12 05:09:50 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -95,11 +95,13 @@ typedef struct Query
9595
typedefstructAlterTableStmt
9696
{
9797
NodeTagtype;
98-
charsubtype;/* A = add, T = alter, D = drop, C = add
99-
* constr, X = drop constr */
98+
charsubtype;/* A = add column, T = alter column, D = drop column,
99+
* C = add constraint, X = drop constraint,
100+
* E = add toast table,
101+
* U = change owner */
100102
char*relname;/* table to work on */
101103
boolinh;/* recursively on children? */
102-
char*name;/* column or constraint name to act on */
104+
char*name;/* column or constraint name to act on, or new owner */
103105
Node*def;/* definition of new column or constraint */
104106
intbehavior;/* CASCADE or RESTRICT drop behavior */
105107
}AlterTableStmt;

‎src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
importorg.postgresql.util.*;
1111

1212
/**
13-
* $Id: Connection.java,v 1.5 2000/09/1204:58:47 momjian Exp $
13+
* $Id: Connection.java,v 1.6 2000/09/1205:09:54 momjian Exp $
1414
*
1515
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1616
* JDBC2 versions of the Connection class.
@@ -112,12 +112,12 @@ protected void openConnection(String host, int port, Properties info, String dat
112112
thrownewPSQLException("postgresql.con.pass");
113113

114114
this_driver =d;
115-
this_url =newString(url);
116-
PG_DATABASE =newString(database);
117-
PG_PASSWORD =newString(info.getProperty("password"));
118-
PG_USER =newString(info.getProperty("user"));
115+
this_url =url;
116+
PG_DATABASE =database;
117+
PG_PASSWORD =info.getProperty("password");
118+
PG_USER =info.getProperty("user");
119119
PG_PORT =port;
120-
PG_HOST =newString(host);
120+
PG_HOST =host;
121121
PG_STATUS =CONNECTION_BAD;
122122

123123
encoding =info.getProperty("charSet");// could be null

‎src/interfaces/jdbc/org/postgresql/Driver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ Properties parseURL(String url,Properties defaults) throws SQLException
242242
{
243243
intstate = -1;
244244
PropertiesurlProps =newProperties(defaults);
245-
Stringkey =newString();
246-
Stringvalue =newString();
245+
Stringkey ="";
246+
Stringvalue ="";
247247

248248
StringTokenizerst =newStringTokenizer(url,":/;=&?",true);
249249
for (intcount =0; (st.hasMoreTokens());count++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp