*** ./doc/src/sgml/ref/psql-ref.sgml.orig Wed Feb 6 14:29:27 2002 --- ./doc/src/sgml/ref/psql-ref.sgml Wed Feb 6 14:31:40 2002 *************** *** 103,109 **** In normal operation, psql provides a prompt with the name of the database to which psql is currently ! connected, followed by the string =>. For example, $ psql testdb Welcome to psql, the PostgreSQL interactive terminal. --- 103,113 ---- In normal operation, psql provides a prompt with the name of the database to which psql is currently ! connected, followed by the string =>. An asterick ! at the beginning of the prompt inicates that you are currently inside of a ! transaction. ! ! For example, $ psql testdb Welcome to psql, the PostgreSQL interactive terminal. *************** *** 213,218 **** --- 217,237 ---- If it is not unaligned, set it to unaligned. This command is kept for backwards compatibility. See \pset for a general solution. + + + + + + \b + + + Toggles the creation of automatic transactions. When this is enabled, + a BEGIN TRANSACTION command is automatically issued + so that every command is automatically inside a transaction. When a + COMMIT or a ROLLBACK is issued, + a BEGIN TRANSACTION is automatically issued afterwards. + The prompt will begin with an asterick (*) when you are inside a + transaction. *** ./src/bin/psql/command.c.orig Wed Feb 6 14:09:11 2002 --- ./src/bin/psql/command.c Wed Feb 6 14:08:15 2002 *************** *** 218,223 **** --- 218,242 ---- success = do_pset("format", "unaligned", &pset.popt, quiet); } + /* + * \b -- toggle automatic BEGIN TRANSACTION + */ + if (strcmp(cmd, "b") == 0) + { + pset.begin = !pset.begin; + if (!quiet) + { + if (pset.begin) + { + puts(gettext(("Transactions will be started automatically."))); + } + else + { + puts(gettext(("Transactions will not be started automatically."))); + } + } + } + /* \C -- override table title (formerly change HTML caption) */ else if (strcmp(cmd, "C") == 0) { *** ./src/bin/psql/common.c.orig Wed Feb 6 14:10:28 2002 --- ./src/bin/psql/common.c Wed Feb 6 14:15:55 2002 *************** *** 495,505 **** --- 495,515 ---- case PGRES_COMMAND_OK: { char buf[10]; + char notice[9]; success = true; sprintf(buf, "%u", (unsigned int) PQoidValue(results)); if (!QUIET()) fprintf(pset.queryFout, "%s\n", PQcmdStatus(results)); + strncpy(notice, PQcmdStatus(results), 8); + notice[8] = '\0'; + if (strcmp(notice,"BEGIN") == 0) { + pset.intrans = true; + } + else if (strcmp(notice,"ROLLBACK") == 0 || + strcmp(notice,"COMMIT") == 0) { + pset.intrans = false; + } SetVariable(pset.vars, "LASTOID", buf); break; } *************** *** 535,540 **** --- 543,549 ---- } fputs(gettext("The connection to the server was lost. Attempting reset: "), stderr); PQreset(pset.db); + pset.intrans = false; if (PQstatus(pset.db) == CONNECTION_BAD) { fputs(gettext("Failed.\n"), stderr); *** ./src/bin/psql/help.c.orig Wed Feb 6 14:12:33 2002 --- ./src/bin/psql/help.c Wed Feb 6 14:23:58 2002 *************** *** 34,41 **** /* * PLEASE: * If you change something in this file, also make the same changes ! * in the DocBook documentation, file ref/psql-ref.sgml. If you don't ! * know how to do it, please find someone who can help you. */ --- 34,41 ---- /* * PLEASE: * If you change something in this file, also make the same changes ! * in the DocBook documentation, file doc/src/sgml/ref/psql-ref.sgml. ! * If you don't know how to do it, please find someone who can help you. */ *************** *** 81,86 **** --- 81,87 ---- puts(_("Options:")); puts(_(" -a Echo all input from script")); puts(_(" -A Unaligned table output mode (-P format=unaligned)")); + puts(_(" -b Automatically begin transactions")); puts(_(" -c COMMAND Run only single command (SQL or internal) and exit")); /* Display default database */ *************** *** 177,183 **** if (pset.notty == 0 && (pagerenv = getenv("PAGER")) && (pagerenv[0] != '\0') && ! screen_size.ws_row <= 39 && (fout = popen(pagerenv, "w"))) { usePipe = true; --- 178,184 ---- if (pset.notty == 0 && (pagerenv = getenv("PAGER")) && (pagerenv[0] != '\0') && ! screen_size.ws_row <= 40 && (fout = popen(pagerenv, "w"))) { usePipe = true; *************** *** 193,198 **** --- 194,201 ---- fprintf(fout, _(" \\c[onnect] [DBNAME|- [USER]]\n" " connect to new database (currently \"%s\")\n"), PQdb(pset.db)); + fprintf(fout, _(" \\b toggle automatic BEGIN TRANSACTION (currently %s)\n"), + ON(pset.begin)); fprintf(fout, _(" \\C TITLE set table title\n")); fprintf(fout, _(" \\cd [DIRNAME] change the current working directory\n")); fprintf(fout, _(" \\copy ... perform SQL COPY with data stream to the client host\n")); *** ./src/bin/psql/mainloop.c.orig Wed Feb 6 14:11:37 2002 --- ./src/bin/psql/mainloop.c Wed Feb 6 14:19:23 2002 *************** *** 161,166 **** --- 161,175 ---- { fflush(stdout); + /* Issue a begin if in "auto-transaction" mode */ + if (!pset.intrans && pset.begin) { + PGresult *results; + results = PSQLexec("BEGIN"); + if (!QUIET()) + fprintf(pset.queryFout, "%s\n", PQcmdStatus(results)); + pset.intrans=true; + } + /* * otherwise, set interactive prompt if necessary and get * another line *** ./src/bin/psql/prompt.c.orig Wed Feb 6 14:11:11 2002 --- ./src/bin/psql/prompt.c Wed Feb 6 14:17:47 2002 *************** *** 80,87 **** else prompt_string = "? "; ! ! destination[0] = '\0'; for (p = prompt_string; p && *p && strlen(destination) < MAX_PROMPT_SIZE; --- 80,89 ---- else prompt_string = "? "; ! if (pset.intrans) ! strcpy(destination, "*"); ! else ! destination[0] = '\0'; for (p = prompt_string; p && *p && strlen(destination) < MAX_PROMPT_SIZE; *** ./src/bin/psql/settings.h.orig Wed Feb 6 14:12:58 2002 --- ./src/bin/psql/settings.h Wed Feb 6 14:25:13 2002 *************** *** 50,55 **** --- 50,58 ---- bool issuper; /* is the current user a superuser? (used * to form the prompt) */ + + bool intrans; /* are we in a transaction? */ + bool begin; /* force BEGIN TRANSACTION */ } PsqlSettings; extern PsqlSettings pset; *** ./src/bin/psql/startup.c.orig Wed Feb 6 14:12:13 2002 --- ./src/bin/psql/startup.c Wed Feb 6 14:21:45 2002 *************** *** 279,284 **** --- 279,285 ---- else { pset.issuper = test_superuser(PQuser(pset.db)); + pset.intrans = false; if (!QUIET() && !pset.notty) { printf(gettext("Welcome to %s, the PostgreSQL interactive terminal.\n\n" *************** *** 374,387 **** memset(options, 0, sizeof *options); #ifdef HAVE_GETOPT_LONG ! while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) #else /* not HAVE_GETOPT_LONG */ /* * Be sure to leave the '-' in here, so we can catch accidental long * options. */ ! while ((c = getopt(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1) #endif /* not HAVE_GETOPT_LONG */ { switch (c) --- 375,388 ---- memset(options, 0, sizeof *options); #ifdef HAVE_GETOPT_LONG ! while ((c = getopt_long(argc, argv, "aAc:bd:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) #else /* not HAVE_GETOPT_LONG */ /* * Be sure to leave the '-' in here, so we can catch accidental long * options. */ ! while ((c = getopt(argc, argv, "aAc:bd:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1) #endif /* not HAVE_GETOPT_LONG */ { switch (c) *************** *** 392,397 **** --- 393,400 ---- case 'A': pset.popt.topt.format = PRINT_UNALIGNED; break; + case 'b': + pset.begin = true; case 'c': options->action_string = optarg; if (optarg[0] == '\\')