@@ -248,31 +248,37 @@ exec_command(const char *cmd,
248
248
* opt2 ,
249
249
* opt3 ,
250
250
* opt4 ;
251
- enum trivalue reuse_previous ;
251
+ enum trivalue reuse_previous = TRI_DEFAULT ;
252
252
253
253
opt1 = read_connect_arg (scan_state );
254
254
if (opt1 != NULL && strncmp (opt1 , prefix , sizeof (prefix ) - 1 ) == 0 )
255
255
{
256
- reuse_previous =
257
- ParseVariableBool (opt1 + sizeof (prefix ) - 1 , prefix ) ?
258
- TRI_YES : TRI_NO ;
256
+ bool on_off ;
259
257
260
- free (opt1 );
261
- opt1 = read_connect_arg (scan_state );
258
+ success = ParseVariableBool (opt1 + sizeof (prefix ) - 1 ,
259
+ "-reuse-previous" ,
260
+ & on_off );
261
+ if (success )
262
+ {
263
+ reuse_previous = on_off ? TRI_YES : TRI_NO ;
264
+ free (opt1 );
265
+ opt1 = read_connect_arg (scan_state );
266
+ }
262
267
}
263
- else
264
- reuse_previous = TRI_DEFAULT ;
265
268
266
- opt2 = read_connect_arg (scan_state );
267
- opt3 = read_connect_arg (scan_state );
268
- opt4 = read_connect_arg (scan_state );
269
+ if (success ) /* give up if reuse_previous was invalid */
270
+ {
271
+ opt2 = read_connect_arg (scan_state );
272
+ opt3 = read_connect_arg (scan_state );
273
+ opt4 = read_connect_arg (scan_state );
269
274
270
- success = do_connect (reuse_previous , opt1 , opt2 , opt3 , opt4 );
275
+ success = do_connect (reuse_previous , opt1 , opt2 , opt3 , opt4 );
271
276
277
+ free (opt2 );
278
+ free (opt3 );
279
+ free (opt4 );
280
+ }
272
281
free (opt1 );
273
- free (opt2 );
274
- free (opt3 );
275
- free (opt4 );
276
282
}
277
283
278
284
/* \cd */
@@ -1208,10 +1214,7 @@ exec_command(const char *cmd,
1208
1214
1209
1215
if (result &&
1210
1216
!SetVariable (pset .vars , opt , result ))
1211
- {
1212
- psql_error ("\\%s: error while setting variable\n" , cmd );
1213
1217
success = false;
1214
- }
1215
1218
1216
1219
if (result )
1217
1220
free (result );
@@ -1325,10 +1328,8 @@ exec_command(const char *cmd,
1325
1328
}
1326
1329
1327
1330
if (!SetVariable (pset .vars , opt0 , newval ))
1328
- {
1329
- psql_error ("\\%s: error while setting variable\n" , cmd );
1330
1331
success = false;
1331
- }
1332
+
1332
1333
free (newval );
1333
1334
}
1334
1335
free (opt0 );
@@ -1564,7 +1565,7 @@ exec_command(const char *cmd,
1564
1565
OT_NORMAL , NULL , false);
1565
1566
1566
1567
if (opt )
1567
- pset . timing = ParseVariableBool (opt , "\\timing" );
1568
+ success = ParseVariableBool (opt , "\\timing" , & pset . timing );
1568
1569
else
1569
1570
pset .timing = !pset .timing ;
1570
1571
if (!pset .quiet )
@@ -1589,10 +1590,8 @@ exec_command(const char *cmd,
1589
1590
success = false;
1590
1591
}
1591
1592
else if (!SetVariable (pset .vars , opt , NULL ))
1592
- {
1593
- psql_error ("\\%s: error while setting variable\n" , cmd );
1594
1593
success = false;
1595
- }
1594
+
1596
1595
free (opt );
1597
1596
}
1598
1597
@@ -2593,7 +2592,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2593
2592
psql_error ("\\pset: allowed formats are unaligned, aligned, wrapped, html, asciidoc, latex, latex-longtable, troff-ms\n" );
2594
2593
return false;
2595
2594
}
2596
-
2597
2595
}
2598
2596
2599
2597
/* set table line style */
@@ -2612,7 +2610,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2612
2610
psql_error ("\\pset: allowed line styles are ascii, old-ascii, unicode\n" );
2613
2611
return false;
2614
2612
}
2615
-
2616
2613
}
2617
2614
2618
2615
/* set unicode border line style */
@@ -2665,7 +2662,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2665
2662
{
2666
2663
if (value )
2667
2664
popt -> topt .border = atoi (value );
2668
-
2669
2665
}
2670
2666
2671
2667
/* set expanded/vertical mode */
@@ -2676,7 +2672,17 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2676
2672
if (value && pg_strcasecmp (value , "auto" ) == 0 )
2677
2673
popt -> topt .expanded = 2 ;
2678
2674
else if (value )
2679
- popt -> topt .expanded = ParseVariableBool (value , param );
2675
+ {
2676
+ bool on_off ;
2677
+
2678
+ if (ParseVariableBool (value , NULL , & on_off ))
2679
+ popt -> topt .expanded = on_off ? 1 : 0 ;
2680
+ else
2681
+ {
2682
+ PsqlVarEnumError (param , value , "on, off, auto" );
2683
+ return false;
2684
+ }
2685
+ }
2680
2686
else
2681
2687
popt -> topt .expanded = !popt -> topt .expanded ;
2682
2688
}
@@ -2685,7 +2691,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2685
2691
else if (strcmp (param , "numericlocale" ) == 0 )
2686
2692
{
2687
2693
if (value )
2688
- popt -> topt . numericLocale = ParseVariableBool (value , param );
2694
+ return ParseVariableBool (value , param , & popt -> topt . numericLocale );
2689
2695
else
2690
2696
popt -> topt .numericLocale = !popt -> topt .numericLocale ;
2691
2697
}
@@ -2740,7 +2746,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2740
2746
else if (strcmp (param , "t" ) == 0 || strcmp (param , "tuples_only" ) == 0 )
2741
2747
{
2742
2748
if (value )
2743
- popt -> topt . tuples_only = ParseVariableBool (value , param );
2749
+ return ParseVariableBool (value , param , & popt -> topt . tuples_only );
2744
2750
else
2745
2751
popt -> topt .tuples_only = !popt -> topt .tuples_only ;
2746
2752
}
@@ -2772,10 +2778,14 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2772
2778
popt -> topt .pager = 2 ;
2773
2779
else if (value )
2774
2780
{
2775
- if (ParseVariableBool (value , param ))
2776
- popt -> topt .pager = 1 ;
2777
- else
2778
- popt -> topt .pager = 0 ;
2781
+ bool on_off ;
2782
+
2783
+ if (!ParseVariableBool (value , NULL , & on_off ))
2784
+ {
2785
+ PsqlVarEnumError (param , value , "on, off, always" );
2786
+ return false;
2787
+ }
2788
+ popt -> topt .pager = on_off ? 1 : 0 ;
2779
2789
}
2780
2790
else if (popt -> topt .pager == 1 )
2781
2791
popt -> topt .pager = 0 ;
@@ -2794,7 +2804,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
2794
2804
else if (strcmp (param , "footer" ) == 0 )
2795
2805
{
2796
2806
if (value )
2797
- popt -> topt . default_footer = ParseVariableBool (value , param );
2807
+ return ParseVariableBool (value , param , & popt -> topt . default_footer );
2798
2808
else
2799
2809
popt -> topt .default_footer = !popt -> topt .default_footer ;
2800
2810
}
0 commit comments