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

Commit7ee27d4

Browse files
committed
Fix pg_dump/pg_restore's ExecuteSqlCommand() to behave suitably if PQexec
returns NULL instead of a PGresult. The former coding would fail, whichis OK, but it neglected to give you the PQerrorMessage that might tellyou why. In the oldest branches, there was another problem: it'd sometimesreport PQerrorMessage from the wrong connection.
1 parentef270fb commit7ee27d4

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.79 2008/04/13 03:49:22 tgl Exp $
8+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.80 2008/08/16 02:25:06 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -266,27 +266,31 @@ notice_processor(void *arg, const char *message)
266266

267267
/* Public interface */
268268
/* Convenience function to send a query. Monitors result to handle COPY statements */
269-
staticint
270-
ExecuteSqlCommand(ArchiveHandle*AH,PQExpBufferqry,char*desc)
269+
staticvoid
270+
ExecuteSqlCommand(ArchiveHandle*AH,constchar*qry,constchar*desc)
271271
{
272272
PGconn*conn=AH->connection;
273273
PGresult*res;
274274
charerrStmt[DB_MAX_ERR_STMT];
275275

276-
/* fprintf(stderr, "Executing: '%s'\n\n", qry->data); */
277-
res=PQexec(conn,qry->data);
278-
if (!res)
279-
die_horribly(AH,modulename,"%s: no result from server\n",desc);
276+
#ifdefNOT_USED
277+
fprintf(stderr,"Executing: '%s'\n\n",qry);
278+
#endif
279+
res=PQexec(conn,qry);
280280

281-
if (PQresultStatus(res)!=PGRES_COMMAND_OK&&PQresultStatus(res)!=PGRES_TUPLES_OK)
281+
switch (PQresultStatus(res))
282282
{
283-
if (PQresultStatus(res)==PGRES_COPY_IN)
284-
{
283+
casePGRES_COMMAND_OK:
284+
casePGRES_TUPLES_OK:
285+
/* A-OK */
286+
break;
287+
casePGRES_COPY_IN:
288+
/* Assume this is an expected result */
285289
AH->pgCopyIn= true;
286-
}
287-
else
288-
{
289-
strncpy(errStmt,qry->data,DB_MAX_ERR_STMT);
290+
break;
291+
default:
292+
/* trouble */
293+
strncpy(errStmt,qry,DB_MAX_ERR_STMT);
290294
if (errStmt[DB_MAX_ERR_STMT-1]!='\0')
291295
{
292296
errStmt[DB_MAX_ERR_STMT-4]='.';
@@ -295,14 +299,11 @@ ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
295299
errStmt[DB_MAX_ERR_STMT-1]='\0';
296300
}
297301
warn_or_die_horribly(AH,modulename,"%s: %s Command was: %s\n",
298-
desc,PQerrorMessage(AH->connection),
299-
errStmt);
300-
}
302+
desc,PQerrorMessage(conn),errStmt);
303+
break;
301304
}
302305

303306
PQclear(res);
304-
305-
returnstrlen(qry->data);
306307
}
307308

308309
/*
@@ -427,7 +428,7 @@ _sendSQLLine(ArchiveHandle *AH, char *qry, char *eos)
427428
* the buffer.
428429
*/
429430
appendPQExpBufferChar(AH->sqlBuf,';');/* inessential */
430-
ExecuteSqlCommand(AH,AH->sqlBuf,
431+
ExecuteSqlCommand(AH,AH->sqlBuf->data,
431432
"could not execute query");
432433
resetPQExpBuffer(AH->sqlBuf);
433434
AH->sqlparse.lastChar='\0';
@@ -626,25 +627,13 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, size_t bufLen)
626627
void
627628
StartTransaction(ArchiveHandle*AH)
628629
{
629-
PQExpBufferqry=createPQExpBuffer();
630-
631-
appendPQExpBuffer(qry,"BEGIN");
632-
633-
ExecuteSqlCommand(AH,qry,"could not start database transaction");
634-
635-
destroyPQExpBuffer(qry);
630+
ExecuteSqlCommand(AH,"BEGIN","could not start database transaction");
636631
}
637632

638633
void
639634
CommitTransaction(ArchiveHandle*AH)
640635
{
641-
PQExpBufferqry=createPQExpBuffer();
642-
643-
appendPQExpBuffer(qry,"COMMIT");
644-
645-
ExecuteSqlCommand(AH,qry,"could not commit database transaction");
646-
647-
destroyPQExpBuffer(qry);
636+
ExecuteSqlCommand(AH,"COMMIT","could not commit database transaction");
648637
}
649638

650639
staticbool

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp