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

Commitc24e5dd

Browse files
committed
Don't try to hack pg_description if not superuser. (Really want a
COMMENT ON LARGE OBJECT command instead, but no time for it now.)Fix some code that would not work with OIDs > 2G.
1 parenta50696c commitc24e5dd

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

‎src/bin/psql/large_obj.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.16 2001/08/10 18:57:39 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.17 2001/10/04 22:39:34 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"large_obj.h"
@@ -16,6 +16,9 @@
1616
#include"print.h"
1717

1818

19+
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
20+
21+
1922
/*
2023
* Since all large object ops must be in a transaction, we must do some magic
2124
* here. You can set the variable lo_transaction to one of commit|rollback|
@@ -107,7 +110,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
107110
PQclear(res);
108111
}
109112

110-
status=lo_export(pset.db,atol(loid_arg),filename_arg);
113+
status=lo_export(pset.db,atooid(loid_arg),filename_arg);
111114
if (status!=1)
112115
{/* of course this status is documented
113116
* nowhere :( */
@@ -187,7 +190,9 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
187190
}
188191

189192
/* insert description if given */
190-
if (comment_arg)
193+
/* XXX don't try to hack pg_description if not superuser */
194+
/* XXX ought to replace this with some kind of COMMENT command */
195+
if (comment_arg&&pset.issuper)
191196
{
192197
char*cmdbuf;
193198
char*bufptr;
@@ -204,7 +209,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
204209
return false;
205210
}
206211
sprintf(cmdbuf,
207-
"INSERT INTO pg_description VALUES (%u, "
212+
"INSERT INTO pg_description VALUES ('%u', "
208213
"(SELECT oid FROM pg_class WHERE relname = 'pg_largeobject'),"
209214
" 0, '",loid);
210215
bufptr=cmdbuf+strlen(cmdbuf);
@@ -263,7 +268,7 @@ do_lo_unlink(const char *loid_arg)
263268
{
264269
PGresult*res;
265270
intstatus;
266-
Oidloid=(Oid)atol(loid_arg);
271+
Oidloid=atooid(loid_arg);
267272
charbuf[256];
268273
boolown_transaction= true;
269274
constchar*var=GetVariable(pset.vars,"LO_TRANSACTION");
@@ -301,20 +306,24 @@ do_lo_unlink(const char *loid_arg)
301306
}
302307

303308
/* remove the comment as well */
304-
sprintf(buf,"DELETE FROM pg_description WHERE objoid = %u "
305-
"AND classoid = (SELECT oid FROM pg_class WHERE relname = 'pg_largeobject')",
306-
loid);
307-
if (!(res=PSQLexec(buf)))
309+
/* XXX don't try to hack pg_description if not superuser */
310+
/* XXX ought to replace this with some kind of COMMENT command */
311+
if (pset.issuper)
308312
{
309-
if (own_transaction)
313+
sprintf(buf,"DELETE FROM pg_description WHERE objoid = '%u' "
314+
"AND classoid = (SELECT oid FROM pg_class WHERE relname = 'pg_largeobject')",
315+
loid);
316+
if (!(res=PSQLexec(buf)))
310317
{
311-
res=PQexec(pset.db,"ROLLBACK");
312-
PQclear(res);
318+
if (own_transaction)
319+
{
320+
res=PQexec(pset.db,"ROLLBACK");
321+
PQclear(res);
322+
}
323+
return false;
313324
}
314-
return false;
315325
}
316326

317-
318327
if (own_transaction)
319328
{
320329
if (!(res=PSQLexec("COMMIT")))
@@ -327,7 +336,7 @@ do_lo_unlink(const char *loid_arg)
327336
}
328337

329338

330-
fprintf(pset.queryFout,"lo_unlink %d\n",loid);
339+
fprintf(pset.queryFout,"lo_unlink %u\n",loid);
331340

332341
return true;
333342
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp