3
3
*
4
4
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
5
5
*
6
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.171 2006/07/18 17:42:01 momjian Exp $
6
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.172 2006/08/29 15:19:50 tgl Exp $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "command.h"
@@ -55,8 +55,6 @@ static backslashResult exec_command(const char *cmd,
55
55
static bool do_edit (const char * filename_arg , PQExpBuffer query_buf );
56
56
static bool do_connect (char * dbname , char * user , char * host , char * port );
57
57
static bool do_shell (const char * command );
58
- static void SyncVerbosityVariable (void );
59
-
60
58
61
59
62
60
/*----------
@@ -196,7 +194,6 @@ exec_command(const char *cmd,
196
194
{
197
195
bool success = true; /* indicate here if the command ran ok or
198
196
* failed */
199
- bool quiet = QUIET ();
200
197
backslashResult status = PSQL_CMD_SKIP_LINE ;
201
198
202
199
/*
@@ -206,9 +203,9 @@ exec_command(const char *cmd,
206
203
if (strcmp (cmd , "a" ) == 0 )
207
204
{
208
205
if (pset .popt .topt .format != PRINT_ALIGNED )
209
- success = do_pset ("format" , "aligned" , & pset .popt , quiet );
206
+ success = do_pset ("format" , "aligned" , & pset .popt , pset . quiet );
210
207
else
211
- success = do_pset ("format" , "unaligned" , & pset .popt , quiet );
208
+ success = do_pset ("format" , "unaligned" , & pset .popt , pset . quiet );
212
209
}
213
210
214
211
/* \C -- override table title (formerly change HTML caption) */
@@ -217,7 +214,7 @@ exec_command(const char *cmd,
217
214
char * opt = psql_scan_slash_option (scan_state ,
218
215
OT_NORMAL , NULL , true);
219
216
220
- success = do_pset ("title" , opt , & pset .popt , quiet );
217
+ success = do_pset ("title" , opt , & pset .popt , pset . quiet );
221
218
free (opt );
222
219
}
223
220
@@ -493,7 +490,7 @@ exec_command(const char *cmd,
493
490
char * fname = psql_scan_slash_option (scan_state ,
494
491
OT_NORMAL , NULL , false);
495
492
496
- success = do_pset ("fieldsep" , fname , & pset .popt , quiet );
493
+ success = do_pset ("fieldsep" , fname , & pset .popt , pset . quiet );
497
494
free (fname );
498
495
}
499
496
@@ -528,9 +525,9 @@ exec_command(const char *cmd,
528
525
else if (strcmp (cmd , "H" ) == 0 || strcmp (cmd , "html" ) == 0 )
529
526
{
530
527
if (pset .popt .topt .format != PRINT_HTML )
531
- success = do_pset ("format" , "html" , & pset .popt , quiet );
528
+ success = do_pset ("format" , "html" , & pset .popt , pset . quiet );
532
529
else
533
- success = do_pset ("format" , "aligned" , & pset .popt , quiet );
530
+ success = do_pset ("format" , "aligned" , & pset .popt , pset . quiet );
534
531
}
535
532
536
533
@@ -638,7 +635,7 @@ exec_command(const char *cmd,
638
635
{
639
636
if (query_buf && query_buf -> len > 0 )
640
637
puts (query_buf -> data );
641
- else if (!quiet )
638
+ else if (!pset . quiet )
642
639
puts (_ ("Query buffer is empty." ));
643
640
fflush (stdout );
644
641
}
@@ -712,7 +709,7 @@ exec_command(const char *cmd,
712
709
success = false;
713
710
}
714
711
else
715
- success = do_pset (opt0 , opt1 , & pset .popt , quiet );
712
+ success = do_pset (opt0 , opt1 , & pset .popt , pset . quiet );
716
713
717
714
free (opt0 );
718
715
free (opt1 );
@@ -727,7 +724,7 @@ exec_command(const char *cmd,
727
724
{
728
725
resetPQExpBuffer (query_buf );
729
726
psql_scan_reset (scan_state );
730
- if (!quiet )
727
+ if (!pset . quiet )
731
728
puts (_ ("Query buffer reset (cleared)." ));
732
729
}
733
730
@@ -740,7 +737,7 @@ exec_command(const char *cmd,
740
737
expand_tilde (& fname );
741
738
/* This scrolls off the screen when using /dev/tty */
742
739
success = saveHistory (fname ? fname : DEVTTY , false);
743
- if (success && !quiet && fname )
740
+ if (success && !pset . quiet && fname )
744
741
printf (gettext ("Wrote history to file \"%s/%s\".\n" ),
745
742
pset .dirname ? pset .dirname : "." , fname );
746
743
if (!fname )
@@ -786,13 +783,7 @@ exec_command(const char *cmd,
786
783
free (opt );
787
784
}
788
785
789
- if (SetVariable (pset .vars , opt0 , newval ))
790
- {
791
- /* Check for special variables */
792
- if (strcmp (opt0 , "VERBOSITY" ) == 0 )
793
- SyncVerbosityVariable ();
794
- }
795
- else
786
+ if (!SetVariable (pset .vars , opt0 , newval ))
796
787
{
797
788
psql_error ("\\%s: error\n" , cmd );
798
789
success = false;
@@ -804,7 +795,7 @@ exec_command(const char *cmd,
804
795
805
796
/* \t -- turn off headers and row count */
806
797
else if (strcmp (cmd , "t" ) == 0 )
807
- success = do_pset ("tuples_only" , NULL , & pset .popt , quiet );
798
+ success = do_pset ("tuples_only" , NULL , & pset .popt , pset . quiet );
808
799
809
800
810
801
/* \T -- define html <table ...> attributes */
@@ -813,15 +804,15 @@ exec_command(const char *cmd,
813
804
char * value = psql_scan_slash_option (scan_state ,
814
805
OT_NORMAL , NULL , false);
815
806
816
- success = do_pset ("tableattr" , value , & pset .popt , quiet );
807
+ success = do_pset ("tableattr" , value , & pset .popt , pset . quiet );
817
808
free (value );
818
809
}
819
810
820
811
/* \timing -- toggle timing of queries */
821
812
else if (strcmp (cmd , "timing" ) == 0 )
822
813
{
823
814
pset .timing = !pset .timing ;
824
- if (!quiet )
815
+ if (!pset . quiet )
825
816
{
826
817
if (pset .timing )
827
818
puts (_ ("Timing is on." ));
@@ -916,7 +907,7 @@ exec_command(const char *cmd,
916
907
917
908
/* \x -- toggle expanded table representation */
918
909
else if (strcmp (cmd , "x" ) == 0 )
919
- success = do_pset ("expanded" , NULL , & pset .popt , quiet );
910
+ success = do_pset ("expanded" , NULL , & pset .popt , pset . quiet );
920
911
921
912
/* \z -- list table rights (equivalent to \dp) */
922
913
else if (strcmp (cmd , "z" ) == 0 )
@@ -1114,7 +1105,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
1114
1105
SyncVariables ();
1115
1106
1116
1107
/* Tell the user about the new connection */
1117
- if (!QUIET () )
1108
+ if (!pset . quiet )
1118
1109
{
1119
1110
printf (_ ("You are now connected to database \"%s\"" ), PQdb (pset .db ));
1120
1111
@@ -1148,6 +1139,7 @@ SyncVariables(void)
1148
1139
/* get stuff from connection */
1149
1140
pset .encoding = PQclientEncoding (pset .db );
1150
1141
pset .popt .topt .encoding = pset .encoding ;
1142
+ pset .sversion = PQserverVersion (pset .db );
1151
1143
1152
1144
SetVariable (pset .vars , "DBNAME" , PQdb (pset .db ));
1153
1145
SetVariable (pset .vars , "USER" , PQuser (pset .db ));
@@ -1156,7 +1148,7 @@ SyncVariables(void)
1156
1148
SetVariable (pset .vars , "ENCODING" , pg_encoding_to_char (pset .encoding ));
1157
1149
1158
1150
/* send stuff to it, too */
1159
- SyncVerbosityVariable ( );
1151
+ PQsetErrorVerbosity ( pset . db , pset . verbosity );
1160
1152
}
1161
1153
1162
1154
/*
@@ -1174,32 +1166,6 @@ UnsyncVariables(void)
1174
1166
SetVariable (pset .vars , "ENCODING" , NULL );
1175
1167
}
1176
1168
1177
- /*
1178
- * Update connection state from VERBOSITY variable
1179
- */
1180
- static void
1181
- SyncVerbosityVariable (void )
1182
- {
1183
- switch (SwitchVariable (pset .vars , "VERBOSITY" ,
1184
- "default" , "terse" , "verbose" , NULL ))
1185
- {
1186
- case 1 : /* default */
1187
- pset .verbosity = PQERRORS_DEFAULT ;
1188
- break ;
1189
- case 2 : /* terse */
1190
- pset .verbosity = PQERRORS_TERSE ;
1191
- break ;
1192
- case 3 : /* verbose */
1193
- pset .verbosity = PQERRORS_VERBOSE ;
1194
- break ;
1195
- default : /* not set or unrecognized value */
1196
- pset .verbosity = PQERRORS_DEFAULT ;
1197
- break ;
1198
- }
1199
-
1200
- PQsetErrorVerbosity (pset .db , pset .verbosity );
1201
- }
1202
-
1203
1169
1204
1170
/*
1205
1171
* do_edit -- handler for \e
0 commit comments