psql command setting

Simon Riggs <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.patches
Message-ID <[email protected]>
Recent patch allowed \timing [on|off]

This patch allows same option on all remaining toggles, so every option
works in the same way. We now have the ability to do
\a [on|off]
\H [on|off]

Patch also corrects help, which didn't show that \x and \t could already
be directly set, even though help said they were toggles.

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


-- 
Sent via pgsql-patches mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches
psql_toggle_or_set.v1.patch (text/x-patch, 5.5 KB)
Index: src/bin/psql/command.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/psql/command.c,v
retrieving revision 1.190
diff -c -r1.190 command.c
*** src/bin/psql/command.c	11 Jun 2008 10:48:17 -0000	1.190
--- src/bin/psql/command.c	5 Jul 2008 12:15:02 -0000
***************
*** 182,191 ****
  	 */
  	if (strcmp(cmd, "a") == 0)
  	{
! 		if (pset.popt.topt.format != PRINT_ALIGNED)
! 			success = do_pset("format", "aligned", &pset.popt, pset.quiet);
  		else
! 			success = do_pset("format", "unaligned", &pset.popt, pset.quiet);
  	}
  
  	/* \C -- override table title (formerly change HTML caption) */
--- 182,203 ----
  	 */
  	if (strcmp(cmd, "a") == 0)
  	{
! 		char	   *opt = psql_scan_slash_option(scan_state,
! 											     OT_NORMAL, NULL, false);
! 		if (opt)
! 		{
! 			if (ParseVariableBool(opt))
! 				success = do_pset("format", "aligned", &pset.popt, pset.quiet);
! 			else
! 				success = do_pset("format", "unaligned", &pset.popt, pset.quiet);
! 		}
  		else
! 		{
! 			if (pset.popt.topt.format != PRINT_ALIGNED)
! 				success = do_pset("format", "aligned", &pset.popt, pset.quiet);
! 			else
! 				success = do_pset("format", "unaligned", &pset.popt, pset.quiet);
! 		}
  	}
  
  	/* \C -- override table title (formerly change HTML caption) */
***************
*** 538,547 ****
  	/* HTML mode */
  	else if (strcmp(cmd, "H") == 0 || strcmp(cmd, "html") == 0)
  	{
! 		if (pset.popt.topt.format != PRINT_HTML)
! 			success = do_pset("format", "html", &pset.popt, pset.quiet);
  		else
! 			success = do_pset("format", "aligned", &pset.popt, pset.quiet);
  	}
  
  
--- 550,571 ----
  	/* HTML mode */
  	else if (strcmp(cmd, "H") == 0 || strcmp(cmd, "html") == 0)
  	{
! 		char	   *opt = psql_scan_slash_option(scan_state,
! 											     OT_NORMAL, NULL, false);
! 		if (opt)
! 		{
! 			if (ParseVariableBool(opt))
! 				success = do_pset("format", "html", &pset.popt, pset.quiet);
! 			else
! 				success = do_pset("format", "aligned", &pset.popt, pset.quiet);
! 		}
  		else
! 		{
! 			if (pset.popt.topt.format != PRINT_HTML)
! 				success = do_pset("format", "html", &pset.popt, pset.quiet);
! 			else
! 				success = do_pset("format", "aligned", &pset.popt, pset.quiet);
! 		}
  	}
  
  
Index: src/bin/psql/help.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/psql/help.c,v
retrieving revision 1.129
diff -c -r1.129 help.c
*** src/bin/psql/help.c	11 Jun 2008 10:55:43 -0000	1.129
--- src/bin/psql/help.c	5 Jul 2008 12:30:39 -0000
***************
*** 220,237 ****
  	fprintf(output, "\n");
  
  	fprintf(output, _("Formatting\n"));
! 	fprintf(output, _("  \\a             toggle between unaligned and aligned output mode\n"));
  	fprintf(output, _("  \\C [STRING]    set table title, or unset if none\n"));
  	fprintf(output, _("  \\f [STRING]    show or set field separator for unaligned query output\n"));
! 	fprintf(output, _("  \\H             toggle HTML output mode (currently %s)\n"),
  			ON(pset.popt.topt.format == PRINT_HTML));
  	fprintf(output, _("  \\pset NAME [VALUE]  set table output option\n"
  					  "                 (NAME := {format|border|expanded|fieldsep|footer|null|\n"
  					  "                 numericlocale|recordsep|tuples_only|title|tableattr|pager})\n"));
! 	fprintf(output, _("  \\t             show only rows (currently %s)\n"),
  			ON(pset.popt.topt.tuples_only));
  	fprintf(output, _("  \\T [STRING]    set HTML <table> tag attributes, or unset if none\n"));
! 	fprintf(output, _("  \\x             toggle expanded output (currently %s)\n"),
  			ON(pset.popt.topt.expanded));
  	fprintf(output, "\n");
  
--- 220,237 ----
  	fprintf(output, "\n");
  
  	fprintf(output, _("Formatting\n"));
! 	fprintf(output, _("  \\a [on|off]    toggle between unaligned and aligned output mode\n"));
  	fprintf(output, _("  \\C [STRING]    set table title, or unset if none\n"));
  	fprintf(output, _("  \\f [STRING]    show or set field separator for unaligned query output\n"));
! 	fprintf(output, _("  \\H [on|off]    toggle or set HTML output mode (currently %s)\n"),
  			ON(pset.popt.topt.format == PRINT_HTML));
  	fprintf(output, _("  \\pset NAME [VALUE]  set table output option\n"
  					  "                 (NAME := {format|border|expanded|fieldsep|footer|null|\n"
  					  "                 numericlocale|recordsep|tuples_only|title|tableattr|pager})\n"));
! 	fprintf(output, _("  \\t [on|off]    toggle or set showing rows only (currently %s)\n"),
  			ON(pset.popt.topt.tuples_only));
  	fprintf(output, _("  \\T [STRING]    set HTML <table> tag attributes, or unset if none\n"));
! 	fprintf(output, _("  \\x [on|off]    toggle or set expanded output (currently %s)\n"),
  			ON(pset.popt.topt.expanded));
  	fprintf(output, "\n");
  
***************
*** 245,251 ****
  
  	fprintf(output, _("External\n"));
  	fprintf(output, _("  \\cd [DIR]         change the current working directory\n"));
! 	fprintf(output, _("  \\timing [on|off]  toggle timing of commands (currently %s)\n"),
  			ON(pset.timing));
  	fprintf(output, _("  \\! [COMMAND]      execute command in shell or start interactive shell\n"));
  	fprintf(output, "\n");
--- 245,251 ----
  
  	fprintf(output, _("External\n"));
  	fprintf(output, _("  \\cd [DIR]         change the current working directory\n"));
! 	fprintf(output, _("  \\timing [on|off]  toggle or set timing of commands (currently %s)\n"),
  			ON(pset.timing));
  	fprintf(output, _("  \\! [COMMAND]      execute command in shell or start interactive shell\n"));
  	fprintf(output, "\n");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.