55 *Implements the basic DB functions used by the archiver.
66 *
77 * IDENTIFICATION
8- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.30 2002/01/18 17:13:51 tgl Exp $
8+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.31 2002/01/1819: 17:05 momjian Exp $
99 *
1010 * NOTES
1111 *
2020 *
2121 * Modifications - 18-Jan-2002 - pjw@rhyme.com.au
2222 *
23- * - Split ExecuteSqlCommandBuf into 3 routines for (slightly) improved
23+ * - Split ExecuteSqlCommandBuf into 3 routines for (slightly) improved
2424 *clarity. Modify loop to cater for COPY commands buried in the SQL
2525 *command buffer (prev version assumed COPY command was executed
2626 *in prior call). This was to fix the buf in the 'set max oid' code.
@@ -51,8 +51,8 @@ static void _check_database_version(ArchiveHandle *AH, bool ignoreVersion);
5151static PGconn * _connectDB (ArchiveHandle * AH ,const char * newdbname ,const char * newUser );
5252static int _executeSqlCommand (ArchiveHandle * AH ,PGconn * conn ,PQExpBuffer qry ,char * desc );
5353static void notice_processor (void * arg ,const char * message );
54- static char * _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos );
55- static char * _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos );
54+ static char * _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos );
55+ static char * _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos );
5656
5757
5858/*
@@ -544,23 +544,24 @@ _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
544544return strlen (qry -> data );
545545}
546546
547- /*
547+ /*
548548 * Used by ExecuteSqlCommandBuf to send one buffered line when running a COPY command.
549549 */
550- static char *
551- _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos )
550+ static char *
551+ _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos )
552552{
553- int loc ;/* Location of next newline */
554- int pos = 0 ;/* Current position */
555- int sPos = 0 ;/* Last pos of a slash char */
556- int isEnd = 0 ;
553+ int loc ;/* Location of next newline */
554+ int pos = 0 ;/* Current position */
555+ int sPos = 0 ;/* Last pos of a slash char */
556+ int isEnd = 0 ;
557557
558558/* loop to find unquoted newline ending the line of COPY data */
559- for (;;) {
559+ for (;;)
560+ {
560561loc = strcspn (& qry [pos ],"\n" )+ pos ;
561562
562563/* If no match, then wait */
563- if (loc >= (eos - qry ))/* None found */
564+ if (loc >= (eos - qry ))/* None found */
564565{
565566appendBinaryPQExpBuffer (AH -> pgCopyBuf ,qry , (eos - qry ));
566567return eos ;
@@ -579,8 +580,8 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
579580sPos = loc - sPos ;
580581
581582/*
582- * If an odd number of preceding slashes, then \n was escaped
583- *so set the next search pos, and loop (if any left).
583+ * If an odd number of preceding slashes, then \n was escaped so
584+ * set the next search pos, and loop (if any left).
584585 */
585586if ((sPos & 1 )== 1 )
586587{
@@ -591,9 +592,9 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
591592appendBinaryPQExpBuffer (AH -> pgCopyBuf ,qry , (eos - qry ));
592593return eos ;
593594}
594- }else {
595- break ;
596595}
596+ else
597+ break ;
597598}
598599
599600/* We found an unquoted newline */
@@ -613,8 +614,7 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
613614resetPQExpBuffer (AH -> pgCopyBuf );
614615
615616/*
616- * fprintf(stderr, "Buffer is '%s'\n",
617- * AH->pgCopyBuf->data);
617+ * fprintf(stderr, "Buffer is '%s'\n", AH->pgCopyBuf->data);
618618 */
619619
620620if (isEnd )
@@ -628,24 +628,23 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
628628return qry + loc + 1 ;
629629}
630630
631- /*
631+ /*
632632 * Used by ExecuteSqlCommandBuf to send one buffered line of SQL (not data for the copy command).
633633 */
634- static char *
635- _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos )
634+ static char *
635+ _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos )
636636{
637- int pos = 0 ;/* Current position */
637+ int pos = 0 ;/* Current position */
638638
639639/*
640- * The following is a mini state machine to assess the end of an
641- *SQL statement. It really only needs to parse good SQL, or at
642- *least that's the theory... End-of-statement is assumed to be an
643- *unquoted, un commented semi-colon.
640+ * The following is a mini state machine to assess the end of an SQL
641+ * statement. It really only needs to parse good SQL, or at least
642+ * that's the theory... End-of-statement is assumed to be an unquoted,
643+ * un commented semi-colon.
644644 */
645645
646646/*
647- * fprintf(stderr, "Buffer at start is: '%s'\n\n",
648- * AH->sqlBuf->data);
647+ * fprintf(stderr, "Buffer at start is: '%s'\n\n", AH->sqlBuf->data);
649648 */
650649
651650for (pos = 0 ;pos < (eos - qry );pos ++ )
@@ -656,7 +655,7 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
656655switch (AH -> sqlparse .state )
657656{
658657
659- case SQL_SCAN :/* Default state == 0, set in _allocAH */
658+ case SQL_SCAN :/* Default state == 0, set in _allocAH */
660659
661660if (qry [pos ]== ';' && AH -> sqlparse .braceDepth == 0 )
662661{
@@ -670,11 +669,12 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
670669resetPQExpBuffer (AH -> sqlBuf );
671670AH -> sqlparse .lastChar = '\0' ;
672671
673- /* Remove any following newlines - so that embedded COPY commands don't get a
674- * starting newline.
672+ /*
673+ * Remove any following newlines - so that embedded
674+ * COPY commands don't get a starting newline.
675675 */
676676pos ++ ;
677- for ( ;pos < (eos - qry )&& qry [pos ]== '\n' ;pos ++ ) ;
677+ for (;pos < (eos - qry )&& qry [pos ]== '\n' ;pos ++ ) ;
678678
679679/* We've got our line, so exit */
680680return qry + pos ;
@@ -741,8 +741,11 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
741741/* fprintf(stderr, "\n"); */
742742}
743743
744- /* If we get here, we've processed entire string with no complete SQL stmt */
745- return eos ;
744+ /*
745+ * If we get here, we've processed entire string with no complete SQL
746+ * stmt
747+ */
748+ return eos ;
746749
747750}
748751
@@ -762,11 +765,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
762765/* Could switch between command and COPY IN mode at each line */
763766while (qry < eos )
764767{
765- if (AH -> pgCopyIn ) {
768+ if (AH -> pgCopyIn )
766769qry = _sendCopyLine (AH ,qry ,eos );
767- } else {
770+ else
768771qry = _sendSQLLine (AH ,qry ,eos );
769- }
770772}
771773
772774return 1 ;