5
5
*Implements the basic DB functions used by the archiver.
6
6
*
7
7
* 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 $
9
9
*
10
10
* NOTES
11
11
*
20
20
*
21
21
* Modifications - 18-Jan-2002 - pjw@rhyme.com.au
22
22
*
23
- * - Split ExecuteSqlCommandBuf into 3 routines for (slightly) improved
23
+ * - Split ExecuteSqlCommandBuf into 3 routines for (slightly) improved
24
24
*clarity. Modify loop to cater for COPY commands buried in the SQL
25
25
*command buffer (prev version assumed COPY command was executed
26
26
*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);
51
51
static PGconn * _connectDB (ArchiveHandle * AH ,const char * newdbname ,const char * newUser );
52
52
static int _executeSqlCommand (ArchiveHandle * AH ,PGconn * conn ,PQExpBuffer qry ,char * desc );
53
53
static 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 );
56
56
57
57
58
58
/*
@@ -544,23 +544,24 @@ _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
544
544
return strlen (qry -> data );
545
545
}
546
546
547
- /*
547
+ /*
548
548
* Used by ExecuteSqlCommandBuf to send one buffered line when running a COPY command.
549
549
*/
550
- static char *
551
- _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos )
550
+ static char *
551
+ _sendCopyLine (ArchiveHandle * AH ,char * qry ,char * eos )
552
552
{
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 ;
557
557
558
558
/* loop to find unquoted newline ending the line of COPY data */
559
- for (;;) {
559
+ for (;;)
560
+ {
560
561
loc = strcspn (& qry [pos ],"\n" )+ pos ;
561
562
562
563
/* If no match, then wait */
563
- if (loc >= (eos - qry ))/* None found */
564
+ if (loc >= (eos - qry ))/* None found */
564
565
{
565
566
appendBinaryPQExpBuffer (AH -> pgCopyBuf ,qry , (eos - qry ));
566
567
return eos ;
@@ -579,8 +580,8 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
579
580
sPos = loc - sPos ;
580
581
581
582
/*
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).
584
585
*/
585
586
if ((sPos & 1 )== 1 )
586
587
{
@@ -591,9 +592,9 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
591
592
appendBinaryPQExpBuffer (AH -> pgCopyBuf ,qry , (eos - qry ));
592
593
return eos ;
593
594
}
594
- }else {
595
- break ;
596
595
}
596
+ else
597
+ break ;
597
598
}
598
599
599
600
/* We found an unquoted newline */
@@ -613,8 +614,7 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
613
614
resetPQExpBuffer (AH -> pgCopyBuf );
614
615
615
616
/*
616
- * fprintf(stderr, "Buffer is '%s'\n",
617
- * AH->pgCopyBuf->data);
617
+ * fprintf(stderr, "Buffer is '%s'\n", AH->pgCopyBuf->data);
618
618
*/
619
619
620
620
if (isEnd )
@@ -628,24 +628,23 @@ _sendCopyLine( ArchiveHandle *AH, char *qry, char *eos)
628
628
return qry + loc + 1 ;
629
629
}
630
630
631
- /*
631
+ /*
632
632
* Used by ExecuteSqlCommandBuf to send one buffered line of SQL (not data for the copy command).
633
633
*/
634
- static char *
635
- _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos )
634
+ static char *
635
+ _sendSQLLine (ArchiveHandle * AH ,char * qry ,char * eos )
636
636
{
637
- int pos = 0 ;/* Current position */
637
+ int pos = 0 ;/* Current position */
638
638
639
639
/*
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.
644
644
*/
645
645
646
646
/*
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);
649
648
*/
650
649
651
650
for (pos = 0 ;pos < (eos - qry );pos ++ )
@@ -656,7 +655,7 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
656
655
switch (AH -> sqlparse .state )
657
656
{
658
657
659
- case SQL_SCAN :/* Default state == 0, set in _allocAH */
658
+ case SQL_SCAN :/* Default state == 0, set in _allocAH */
660
659
661
660
if (qry [pos ]== ';' && AH -> sqlparse .braceDepth == 0 )
662
661
{
@@ -670,11 +669,12 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
670
669
resetPQExpBuffer (AH -> sqlBuf );
671
670
AH -> sqlparse .lastChar = '\0' ;
672
671
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.
675
675
*/
676
676
pos ++ ;
677
- for ( ;pos < (eos - qry )&& qry [pos ]== '\n' ;pos ++ ) ;
677
+ for (;pos < (eos - qry )&& qry [pos ]== '\n' ;pos ++ ) ;
678
678
679
679
/* We've got our line, so exit */
680
680
return qry + pos ;
@@ -741,8 +741,11 @@ _sendSQLLine( ArchiveHandle *AH, char *qry, char *eos)
741
741
/* fprintf(stderr, "\n"); */
742
742
}
743
743
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 ;
746
749
747
750
}
748
751
@@ -762,11 +765,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
762
765
/* Could switch between command and COPY IN mode at each line */
763
766
while (qry < eos )
764
767
{
765
- if (AH -> pgCopyIn ) {
768
+ if (AH -> pgCopyIn )
766
769
qry = _sendCopyLine (AH ,qry ,eos );
767
- } else {
770
+ else
768
771
qry = _sendSQLLine (AH ,qry ,eos );
769
- }
770
772
}
771
773
772
774
return 1 ;