Index: Makefile =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/Makefile,v retrieving revision 1.51 diff -c -r1.51 Makefile *** Makefile 5 Oct 2004 19:30:24 -0000 1.51 --- Makefile 2 Jan 2005 00:29:21 -0000 *************** *** 26,35 **** FLEXFLAGS = -Cfe ! all: submake-libpq submake-libpgport psql ! psql: $(OBJS) $(libpq_builddir)/libpq.a ! $(CC) $(CFLAGS) $(OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@$(X) help.o: $(srcdir)/sql_help.h --- 26,35 ---- FLEXFLAGS = -Cfe ! all: submake-libpq submake-libpgport psql$(X) ! psql$(X): $(OBJS) $(libpq_builddir)/libpq.a ! $(CC) $(CFLAGS) $(OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@ help.o: $(srcdir)/sql_help.h Index: common.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/common.c,v retrieving revision 1.94 diff -c -r1.94 common.c *** common.c 1 Nov 2004 19:21:50 -0000 1.94 --- common.c 2 Jan 2005 00:29:22 -0000 *************** *** 724,729 **** --- 724,736 ---- "%s\n" "**************************\n\n", query); fflush(stdout); + if (pset.logsession) + { + fprintf(pset.logfile, "********* QUERY **********\n" + "%s\n" + "**************************\n\n", query); + fflush(pset.logfile); + } if (echo_hidden == 1) /* noexec? */ return NULL; *************** *** 902,907 **** --- 909,918 ---- else fprintf(pset.queryFout, "%s\n", PQcmdStatus(results)); } + if (pset.logsession) + { + fprintf(pset.logfile, "%s\n", PQcmdStatus(results)); + } SetVariable(pset.vars, "LASTOID", buf); break; } *************** *** 971,976 **** --- 982,996 ---- fflush(stdout); } + /* log query */ + if (pset.logsession) + { + fprintf(pset.logfile, "********* QUERY **********\n" + "%s\n" + "**************************\n\n", query); + fflush(pset.logfile); + } + SetCancelConn(); if (PQtransactionStatus(pset.db) == PQTRANS_IDLE && Index: help.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/help.c,v retrieving revision 1.98 diff -c -r1.98 help.c *** help.c 31 Dec 2004 22:03:15 -0000 1.98 --- help.c 2 Jan 2005 00:29:22 -0000 *************** *** 63,68 **** --- 63,69 ---- if (!user) { #ifndef WIN32 + #ifndef __OS2__ /* this does not work on OS/2 */ pw = getpwuid(geteuid()); if (pw) user = pw->pw_name; *************** *** 71,76 **** --- 72,78 ---- psql_error("could not get current user name: %s\n", strerror(errno)); exit(EXIT_FAILURE); } + #endif #else /* WIN32 */ char buf[128]; DWORD bufsize = sizeof(buf) - 1; *************** *** 109,114 **** --- 111,117 ---- puts(_(" -n disable enhanced command line editing (readline)")); puts(_(" -s single-step mode (confirm each query)")); puts(_(" -S single-line mode (end of line terminates SQL command)")); + puts(_(" -L FILENAME send session log to file")); puts(_("\nOutput format options:")); puts(_(" -A unaligned table output mode (-P format=unaligned)")); Index: print.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/print.c,v retrieving revision 1.53 diff -c -r1.53 print.c *** print.c 9 Nov 2004 15:57:53 -0000 1.53 --- print.c 2 Jan 2005 00:29:22 -0000 *************** *** 29,34 **** --- 29,36 ---- #include "mbprint.h" + #include "settings.h" + /*************************/ /* Unaligned text */ /*************************/ *************** *** 1094,1099 **** --- 1096,1107 ---- /* print the stuff */ + /* session log output */ + if (pset.logsession) + { + print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->encoding, pset.logfile); + } + switch (opt->format) { case PRINT_UNALIGNED: Index: settings.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/settings.h,v retrieving revision 1.22 diff -c -r1.22 settings.h *** settings.h 17 Nov 2004 18:32:31 -0000 1.22 --- settings.h 2 Jan 2005 00:29:22 -0000 *************** *** 25,30 **** --- 25,31 ---- #define DEFAULT_PROMPT1 "%/%R%# " #define DEFAULT_PROMPT2 "%/%R%# " #define DEFAULT_PROMPT3 ">> " + #define DEFAULT_LOGFILE "psql.log" typedef struct _psqlSettings *************** *** 54,59 **** --- 55,62 ---- bool timing; /* enable timing of all queries */ PGVerbosity verbosity; /* current error verbosity level */ + FILE *logfile; /* session log file handle */ + bool logsession; /* session log flag */ } PsqlSettings; extern PsqlSettings pset; Index: startup.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/startup.c,v retrieving revision 1.107 diff -c -r1.107 startup.c *** startup.c 28 Dec 2004 23:17:41 -0000 1.107 --- startup.c 2 Jan 2005 00:29:23 -0000 *************** *** 103,110 **** set_pglocale_pgservice(argv[0], "psql"); - pset.progname = get_progname(argv[0]); - if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) --- 103,108 ---- *************** *** 119,124 **** --- 117,124 ---- } } + pset.progname = get_progname(argv[0]); + #ifdef WIN32 setvbuf(stderr, NULL, _IONBF, 0); setup_win32_locks(); *************** *** 147,152 **** --- 147,153 ---- SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1); SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2); SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3); + SetVariable(pset.vars, "LOGFILE", DEFAULT_LOGFILE); pset.verbosity = PQERRORS_DEFAULT; *************** *** 158,166 **** --- 159,171 ---- #else pset.getPassword = false; #endif + /* set session logging off by default */ + pset.logsession = false; + pset.logfile = NULL; parse_psql_options(argc, argv, &options); + if (!pset.popt.topt.fieldSep) pset.popt.topt.fieldSep = pg_strdup(DEFAULT_FIELD_SEP); if (!pset.popt.topt.recordSep) *************** *** 231,236 **** --- 236,252 ---- * Now find something to do */ + /* if session logging is turned on open the log file */ + if (pset.logsession) + { + pset.logfile = fopen(GetVariable(pset.vars, "LOGFILE"), "a"); + if (!pset.logfile) + { + pset.logsession = false; + fprintf(stderr, gettext("logfile open failed for %s\n\n"), GetVariable(pset.vars, "LOGFILE")); + } + } + /* * process file given by -f */ *************** *** 298,303 **** --- 314,322 ---- #ifdef WIN32 checkWin32Codepage(); #endif + if (pset.logsession) + printf(gettext( "Logfile name %s\n"), GetVariable(pset.vars, "LOGFILE")); + } if (!pset.notty) *************** *** 309,314 **** --- 328,335 ---- } /* clean up */ + if (pset.logsession) + fclose(pset.logfile); PQfinish(pset.db); setQFout(NULL); *************** *** 337,342 **** --- 358,364 ---- {"host", required_argument, NULL, 'h'}, {"html", no_argument, NULL, 'H'}, {"list", no_argument, NULL, 'l'}, + {"log", required_argument, NULL, 'L'}, {"no-readline", no_argument, NULL, 'n'}, {"output", required_argument, NULL, 'o'}, {"port", required_argument, NULL, 'p'}, *************** *** 366,372 **** memset(options, 0, sizeof *options); ! while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) { switch (c) --- 388,394 ---- memset(options, 0, sizeof *options); ! while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:L:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) { switch (c) *************** *** 412,417 **** --- 434,443 ---- case 'l': options->action = ACT_LIST_DB; break; + case 'L': + SetVariable(pset.vars, "LOGFILE", optarg); + pset.logsession = true; + break; case 'n': options->no_readline = true; break;