public inbox for [email protected]help / color / mirror / Atom feed
[PATCH] cfe-12-gist_over_cfe-11-persistent squash commit 2+ messages / 2 participants [nested] [flat]
* [PATCH] cfe-12-gist_over_cfe-11-persistent squash commit @ 2021-03-12 01:02 Bruce Momjian <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Bruce Momjian @ 2021-03-12 01:02 UTC (permalink / raw) --- src/backend/access/gist/README | 10 ++++++++++ src/backend/access/gist/gist.c | 21 +++++++++++++++------ src/backend/access/gist/gistbuild.c | 9 ++++++--- src/backend/access/gist/gistvacuum.c | 18 ++++++++++++------ 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/backend/access/gist/README b/src/backend/access/gist/README index 25cab0047b..6b1f84634f 100644 --- a/src/backend/access/gist/README +++ b/src/backend/access/gist/README @@ -461,6 +461,16 @@ value. The page is not recycled, until that XID is no longer visible to anyone. That's much more conservative than necessary, but let's keep it simple. +GiST and Encryption +------------------- + +GiST uses LSNs and NSNs for concurrency. This means that unlogged and +temporary relations also need LSNs. GiST has a mechanism to assign LSNs +to such relations, but sometimes uses fixed LSNs and or calls +gistGetFakeLSN(), which can cause duplicate LSNs to be used. Therefore, +when encryption is enabled and fake LSNs are needed, the GiST code calls +LSNForEncryption(). See src/backend/crypto/README for more details. + Authors: Teodor Sigaev <[email protected]> diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 0683f42c25..5ca5f17db3 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -501,13 +501,16 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, * we don't need to be able to detect concurrent splits yet.) */ if (is_build) - recptr = GistBuildLSN; + recptr = !FileEncryptionEnabled ? GistBuildLSN : + LSNForEncryption(RelationIsPermanent(rel)); else { if (RelationNeedsWAL(rel)) recptr = gistXLogSplit(is_leaf, dist, oldrlink, oldnsn, leftchildbuf, markfollowright); + else if (FileEncryptionEnabled) + recptr = LSNForEncryption(RelationIsPermanent(rel)); else recptr = gistGetFakeLSN(rel); } @@ -568,7 +571,8 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, MarkBufferDirty(leftchildbuf); if (is_build) - recptr = GistBuildLSN; + recptr = !FileEncryptionEnabled ? GistBuildLSN : + LSNForEncryption(RelationIsPermanent(rel)); else { if (RelationNeedsWAL(rel)) @@ -586,6 +590,8 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, deloffs, ndeloffs, itup, ntup, leftchildbuf); } + else if (FileEncryptionEnabled) + recptr = LSNForEncryption(RelationIsPermanent(rel)); else recptr = gistGetFakeLSN(rel); } @@ -1665,6 +1671,8 @@ gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel) if (ndeletable > 0) { + XLogRecPtr recptr; + TransactionId latestRemovedXid = InvalidTransactionId; if (XLogStandbyInfoActive() && RelationNeedsWAL(rel)) @@ -1690,16 +1698,17 @@ gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel) /* XLOG stuff */ if (RelationNeedsWAL(rel)) { - XLogRecPtr recptr; - recptr = gistXLogDelete(buffer, deletable, ndeletable, latestRemovedXid); - PageSetLSN(page, recptr); } + else if (FileEncryptionEnabled) + recptr = LSNForEncryption(RelationIsPermanent(rel)); else - PageSetLSN(page, gistGetFakeLSN(rel)); + recptr = gistGetFakeLSN(rel); + + PageSetLSN(page, recptr); END_CRIT_SECTION(); } diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index 1054f6f1f2..a8b82483e8 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -299,7 +299,8 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo) GISTInitBuffer(buffer, F_LEAF); MarkBufferDirty(buffer); - PageSetLSN(page, GistBuildLSN); + PageSetLSN(page, !FileEncryptionEnabled ? GistBuildLSN : + LSNForEncryption(RelationIsPermanent(index))); UnlockReleaseBuffer(buffer); @@ -451,7 +452,8 @@ gist_indexsortbuild(GISTBuildState *state) /* Write out the root */ RelationOpenSmgr(state->indexrel); - PageSetLSN(pagestate->page, GistBuildLSN); + PageSetLSN(pagestate->page, !FileEncryptionEnabled ? GistBuildLSN : + LSNForEncryption(RelationIsPermanent(state->indexrel))); PageSetChecksumInplace(pagestate->page, GIST_ROOT_BLKNO); smgrwrite(state->indexrel->rd_smgr, MAIN_FORKNUM, GIST_ROOT_BLKNO, pagestate->page, true); @@ -573,7 +575,8 @@ gist_indexsortbuild_flush_ready_pages(GISTBuildState *state) if (blkno != state->pages_written) elog(ERROR, "unexpected block number to flush GiST sorting build"); - PageSetLSN(page, GistBuildLSN); + PageSetLSN(page, !FileEncryptionEnabled ? GistBuildLSN : + LSNForEncryption(RelationIsPermanent(state->indexrel))); PageSetChecksumInplace(page, blkno); smgrextend(state->indexrel->rd_smgr, MAIN_FORKNUM, blkno, page, true); diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c index 0663193531..f783edd627 100644 --- a/src/backend/access/gist/gistvacuum.c +++ b/src/backend/access/gist/gistvacuum.c @@ -174,6 +174,8 @@ gistvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, vstate.callback_state = callback_state; if (RelationNeedsWAL(rel)) vstate.startNSN = GetInsertRecPtr(); + else if (FileEncryptionEnabled) + vstate.startNSN = LSNForEncryption(RelationIsPermanent(rel)); else vstate.startNSN = gistGetFakeLSN(rel); @@ -353,6 +355,8 @@ restart: */ if (ntodelete > 0) { + XLogRecPtr recptr; + START_CRIT_SECTION(); MarkBufferDirty(buffer); @@ -361,16 +365,15 @@ restart: GistMarkTuplesDeleted(page); if (RelationNeedsWAL(rel)) - { - XLogRecPtr recptr; - recptr = gistXLogUpdate(buffer, todelete, ntodelete, NULL, 0, InvalidBuffer); - PageSetLSN(page, recptr); - } + else if (FileEncryptionEnabled) + recptr = LSNForEncryption(RelationIsPermanent(rel)); else - PageSetLSN(page, gistGetFakeLSN(rel)); + recptr = gistGetFakeLSN(rel); + + PageSetLSN(page, recptr); END_CRIT_SECTION(); @@ -657,8 +660,11 @@ gistdeletepage(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, if (RelationNeedsWAL(info->index)) recptr = gistXLogPageDelete(leafBuffer, txid, parentBuffer, downlink); + else if (FileEncryptionEnabled) + recptr = LSNForEncryption(RelationIsPermanent(info->index)); else recptr = gistGetFakeLSN(info->index); + PageSetLSN(parentPage, recptr); PageSetLSN(leafPage, recptr); -- 2.20.1 --LQksG6bCIzRHxTLp Content-Type: application/gzip Content-Disposition: attachment; filename="cfe-13-rel_over_cfe-12-gist.diff.gz" Content-Transfer-Encoding: base64 H4sICMS9SmAAA2NmZS0xMy1yZWxfb3Zlcl9jZmUtMTItZ2lzdC5kaWZmAOQ8aXfbRpKfpV/R 9mw8pHiBN+msneigZI51ragk3mTz8BpAg0QEAgwOU0qc+e1T1d0AcZKUk+xk3/LZPIDq6q6j 6+qCzj13SQbUGHdNpvUVY6z0espgyGjbHPU6w06HKkaHDoZDpa0MyZXrkBlbkfaQKMpr/o90 FKV9eA5oXpMTL9QZAC1/sqhD/lPDn18vxc9m6L89PKMBe03uF2GdtNvkinowutOGt9dKF3E1 lL6iHM5C7SemB6/JD7fH96fvfiS6yRrtbsNjtup+ZJ7Kf3cac8sPiP9zSP0F0d3l0goODxuN xiH8cALP0lqa7bpLeLccn3lBUyep1yf43yW1Q+J7ekuj+gNzjBbVdeb7LUTN3zaDALzfJjV4 Nfgk20ZpoWUbfCiMandgVCH8AlbO31Z0zsRMuKh2yaIWjK5aHlt7VsDwO4xA8GEZekcLPMbk xwZ9Gc0bcN+V3ELwHqkVU+uvOL34EfEX4Qcl6AOPOj5dth5tdy65iuCdLLjmuoEPwKvNtwR4 jjc6DShgbPmB68VcjMGHucXr3tMqcFtX9IGZls0y+pBHL8C10GSODsgrDltXJXh72OP6UPxK 41m5frCkfsC8xNeYxzkmSGpwXhOGwMdyHoN3UKGydGVG2K5ObfguhTLK8SGCRya0dHf1ZFhe rCOd4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GDQSCIL/S1THWeTEhfENCIAlbBekpt50fW vykmDf1Xq+ExnrwH6B39cDJ13v82uSQfg/UcUIn1HzMxTB9kNKuk0yvnzeTkAyXEKjTN9tPW tVTUIMiuuVdifTPSNXCNqsyu8rBDK1zlW9I+m6rMGroFAHlspxZLX1Ljd7uEP7sDCXt9RdYN 9krBgnWnxgQstDX1+VipbNiaWa/j7pa+ouLhHsgjCADZZeda96gTwyDtUZh57IDxvrlofo+N +cV+U7KgtfWJllS9iu+YW8FxPEVo3GHBLzE5p26bJVRNlvpeMyzSie9PYQUrKiZet3B5Uy2I jWmi51RmkfFHo/DdlDX+eB2sUVSS3ueE3trrdxp9DDQ5atg2fbdCtmlxs6EY/u/VvDcLnS3T Is2rpzoBFKVv6qJawR/KcS6v4iNrxgqctbsW7bi5cflYK7IeSboMu9t9k85/pCw2g0IebT/T 760curu9+VFGrKe82VIklRQ8YgCxEz7SX0NcjFmS+0k4+O64O/DavttqDQZjwEZ+f2Rvx0c6 n3J8pNOwT4OwBv408RE64M+ml4yPzHZ/NFtMr5/J8zswQzK9/USqWGEPJlUkClHT2u+0Ou2W vb//X+BdTqWQfwAA --LQksG6bCIzRHxTLp-- ^ permalink raw reply [nested|flat] 2+ messages in thread
* psql: Rename results to result when only a single one is meant @ 2022-01-27 11:34 Peter Eisentraut <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Peter Eisentraut @ 2022-01-27 11:34 UTC (permalink / raw) To: pgsql-hackers; +Cc: Fabien COELHO <[email protected]> While reviewing code related to supporting multiple result sets in psql, it is always confusing that in psql many variables of type PGresult* are named "results" (plural), as if there could be multiple. While it is ok in casual talk to consider a return from a query to be a bunch of stuff, this plural naming is inconsistent with how other code and the libpq API uses these terms. And if we're going to get to multiple result sets support, I think we need to be more precise throughout the code. The attached patch renames these variables and functions to singular where appropriate. From 0dc7b7f39ca82265448e4e7676841344d7fc9db1 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <[email protected]> Date: Thu, 27 Jan 2022 12:21:24 +0100 Subject: [PATCH] psql: Rename results to result when only a single one is meant This makes the naming more consistent with the libpq API and the rest of the code, and makes actually supporting multiple result sets in the future less confusing. --- src/bin/psql/command.c | 6 +- src/bin/psql/common.c | 230 ++++++++++++++++++------------------ src/bin/psql/crosstabview.c | 28 ++--- src/bin/psql/crosstabview.h | 2 +- src/bin/psql/help.c | 6 +- src/bin/psql/settings.h | 6 +- src/bin/psql/tab-complete.c | 4 +- src/bin/psql/variables.c | 2 +- 8 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index f590474855..292cff5df9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -279,7 +279,7 @@ HandleSlashCmds(PsqlScanState scan_state, * Subroutine to actually try to execute a backslash command. * * The typical "success" result code is PSQL_CMD_SKIP_LINE, although some - * commands return something else. Failure results are PSQL_CMD_ERROR, + * commands return something else. Failure result code is PSQL_CMD_ERROR, * unless PSQL_CMD_UNKNOWN is more appropriate. */ static backslashResult @@ -683,7 +683,7 @@ exec_command_copyright(PsqlScanState scan_state, bool active_branch) } /* - * \crosstabview -- execute a query and display results in crosstab + * \crosstabview -- execute a query and display result in crosstab */ static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch) @@ -5084,7 +5084,7 @@ do_watch(PQExpBuffer query_buf, double sleep) timebuf, sleep); myopt.title = title; - /* Run the query and print out the results */ + /* Run the query and print out the result */ res = PSQLexecWatch(query_buf->data, &myopt, pagerpipe); /* diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 3503605a7d..d65b9a124f 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -411,11 +411,11 @@ AcceptResult(const PGresult *result) * entered by the user, not queries generated by slash commands. */ static void -SetResultVariables(PGresult *results, bool success) +SetResultVariables(PGresult *result, bool success) { if (success) { - const char *ntuples = PQcmdTuples(results); + const char *ntuples = PQcmdTuples(result); SetVariable(pset.vars, "ERROR", "false"); SetVariable(pset.vars, "SQLSTATE", "00000"); @@ -423,8 +423,8 @@ SetResultVariables(PGresult *results, bool success) } else { - const char *code = PQresultErrorField(results, PG_DIAG_SQLSTATE); - const char *mesg = PQresultErrorField(results, PG_DIAG_MESSAGE_PRIMARY); + const char *code = PQresultErrorField(result, PG_DIAG_SQLSTATE); + const char *mesg = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY); SetVariable(pset.vars, "ERROR", "true"); @@ -587,7 +587,7 @@ PSQLexec(const char *query) * PSQLexecWatch * * This function is used for \watch command to send the query to - * the server and print out the results. + * the server and print out the result. * * Returns 1 if the query executed successfully, 0 if it cannot be repeated, * e.g., because of the interrupt, -1 on error. @@ -714,9 +714,9 @@ PrintNotifications(void) * Returns true if successful, false otherwise. */ static bool -PrintQueryTuples(const PGresult *results) +PrintQueryTuples(const PGresult *result) { - bool result = true; + bool ok = true; /* write output to \g argument, if any */ if (pset.gfname) @@ -729,11 +729,11 @@ PrintQueryTuples(const PGresult *results) if (is_pipe) disable_sigpipe_trap(); - printQuery(results, &pset.popt, fout, false, pset.logfile); + printQuery(result, &pset.popt, fout, false, pset.logfile); if (ferror(fout)) { pg_log_error("could not print result table: %m"); - result = false; + ok = false; } if (is_pipe) @@ -746,15 +746,15 @@ PrintQueryTuples(const PGresult *results) } else { - printQuery(results, &pset.popt, pset.queryFout, false, pset.logfile); + printQuery(result, &pset.popt, pset.queryFout, false, pset.logfile); if (ferror(pset.queryFout)) { pg_log_error("could not print result table: %m"); - result = false; + ok = false; } } - return result; + return ok; } @@ -912,7 +912,7 @@ ExecQueryTuples(const PGresult *result) * server-side opinion. */ static bool -ProcessResult(PGresult **results) +ProcessResult(PGresult **resultp) { bool success = true; bool first_cycle = true; @@ -923,7 +923,7 @@ ProcessResult(PGresult **results) bool is_copy; PGresult *next_result; - if (!AcceptResult(*results)) + if (!AcceptResult(*resultp)) { /* * Failure at this point is always a server-side failure or a @@ -934,7 +934,7 @@ ProcessResult(PGresult **results) break; } - result_status = PQresultStatus(*results); + result_status = PQresultStatus(*resultp); switch (result_status) { case PGRES_EMPTY_QUERY: @@ -1037,7 +1037,7 @@ ProcessResult(PGresult **results) copystream = pset.copyStream ? pset.copyStream : pset.cur_cmd_source; success = handleCopyIn(pset.db, copystream, - PQbinaryTuples(*results), + PQbinaryTuples(*resultp), ©_result) && success; } ResetCancelConn(); @@ -1046,8 +1046,8 @@ ProcessResult(PGresult **results) * Replace the PGRES_COPY_OUT/IN result with COPY command's exit * status, or with NULL if we want to suppress printing anything. */ - PQclear(*results); - *results = copy_result; + PQclear(*resultp); + *resultp = copy_result; } else if (first_cycle) { @@ -1064,12 +1064,12 @@ ProcessResult(PGresult **results) if (!next_result) break; - PQclear(*results); - *results = next_result; + PQclear(*resultp); + *resultp = next_result; first_cycle = false; } - SetResultVariables(*results, success); + SetResultVariables(*resultp, success); /* may need this to recover from conn loss during COPY */ if (!first_cycle && !CheckConnection()) @@ -1082,10 +1082,10 @@ ProcessResult(PGresult **results) /* * PrintQueryStatus: report command status as required * - * Note: Utility function for use by PrintQueryResults() only. + * Note: Utility function for use by PrintQueryResult() only. */ static void -PrintQueryStatus(PGresult *results) +PrintQueryStatus(PGresult *result) { char buf[16]; @@ -1094,59 +1094,59 @@ PrintQueryStatus(PGresult *results) if (pset.popt.topt.format == PRINT_HTML) { fputs("<p>", pset.queryFout); - html_escaped_print(PQcmdStatus(results), pset.queryFout); + html_escaped_print(PQcmdStatus(result), pset.queryFout); fputs("</p>\n", pset.queryFout); } else - fprintf(pset.queryFout, "%s\n", PQcmdStatus(results)); + fprintf(pset.queryFout, "%s\n", PQcmdStatus(result)); } if (pset.logfile) - fprintf(pset.logfile, "%s\n", PQcmdStatus(results)); + fprintf(pset.logfile, "%s\n", PQcmdStatus(result)); - snprintf(buf, sizeof(buf), "%u", (unsigned int) PQoidValue(results)); + snprintf(buf, sizeof(buf), "%u", (unsigned int) PQoidValue(result)); SetVariable(pset.vars, "LASTOID", buf); } /* - * PrintQueryResults: print out (or store or execute) query results as required + * PrintQueryResult: print out (or store or execute) query result as required * * Note: Utility function for use by SendQuery() only. * * Returns true if the query executed successfully, false otherwise. */ static bool -PrintQueryResults(PGresult *results) +PrintQueryResult(PGresult *result) { bool success; const char *cmdstatus; - if (!results) + if (!result) return false; - switch (PQresultStatus(results)) + switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: /* store or execute or print the data ... */ if (pset.gset_prefix) - success = StoreQueryTuple(results); + success = StoreQueryTuple(result); else if (pset.gexec_flag) - success = ExecQueryTuples(results); + success = ExecQueryTuples(result); else if (pset.crosstab_flag) - success = PrintResultsInCrosstab(results); + success = PrintResultInCrosstab(result); else - success = PrintQueryTuples(results); + success = PrintQueryTuples(result); /* if it's INSERT/UPDATE/DELETE RETURNING, also print status */ - cmdstatus = PQcmdStatus(results); + cmdstatus = PQcmdStatus(result); if (strncmp(cmdstatus, "INSERT", 6) == 0 || strncmp(cmdstatus, "UPDATE", 6) == 0 || strncmp(cmdstatus, "DELETE", 6) == 0) - PrintQueryStatus(results); + PrintQueryStatus(result); break; case PGRES_COMMAND_OK: - PrintQueryStatus(results); + PrintQueryStatus(result); success = true; break; @@ -1169,7 +1169,7 @@ PrintQueryResults(PGresult *results) default: success = false; pg_log_error("unexpected PQresultStatus: %d", - PQresultStatus(results)); + PQresultStatus(result)); break; } @@ -1181,7 +1181,7 @@ PrintQueryResults(PGresult *results) /* * SendQuery: send the query string to the backend - * (and print out results) + * (and print out result) * * Note: This is the "front door" way to send a query. That is, use it to * send queries actually entered by the user. These queries will be subject to @@ -1195,7 +1195,7 @@ bool SendQuery(const char *query) { bool timing = pset.timing; - PGresult *results; + PGresult *result; PGTransactionStatusType transaction_status; double elapsed_msec = 0; bool OK = false; @@ -1247,15 +1247,15 @@ SendQuery(const char *query) !pset.autocommit && !command_no_begin(query)) { - results = PQexec(pset.db, "BEGIN"); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQexec(pset.db, "BEGIN"); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - ClearOrSaveResult(results); + ClearOrSaveResult(result); ResetCancelConn(); goto sendquery_cleanup; } - ClearOrSaveResult(results); + ClearOrSaveResult(result); transaction_status = PQtransactionStatus(pset.db); } @@ -1264,15 +1264,15 @@ SendQuery(const char *query) (pset.cur_cmd_interactive || pset.on_error_rollback == PSQL_ERROR_ROLLBACK_ON)) { - results = PQexec(pset.db, "SAVEPOINT pg_psql_temporary_savepoint"); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQexec(pset.db, "SAVEPOINT pg_psql_temporary_savepoint"); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - ClearOrSaveResult(results); + ClearOrSaveResult(result); ResetCancelConn(); goto sendquery_cleanup; } - ClearOrSaveResult(results); + ClearOrSaveResult(result); on_error_rollback_savepoint = true; } @@ -1281,7 +1281,7 @@ SendQuery(const char *query) /* Describe query's result columns, without executing it */ OK = DescribeQuery(query, &elapsed_msec); ResetCancelConn(); - results = NULL; /* PQclear(NULL) does nothing */ + result = NULL; /* PQclear(NULL) does nothing */ } else if (pset.fetch_count <= 0 || pset.gexec_flag || pset.crosstab_flag || !is_select_command(query)) @@ -1293,11 +1293,11 @@ SendQuery(const char *query) if (timing) INSTR_TIME_SET_CURRENT(before); - results = PQexec(pset.db, query); + result = PQexec(pset.db, query); /* these operations are included in the timing result: */ ResetCancelConn(); - OK = ProcessResult(&results); + OK = ProcessResult(&result); if (timing) { @@ -1306,16 +1306,16 @@ SendQuery(const char *query) elapsed_msec = INSTR_TIME_GET_MILLISEC(after); } - /* but printing results isn't: */ - if (OK && results) - OK = PrintQueryResults(results); + /* but printing result isn't: */ + if (OK && result) + OK = PrintQueryResult(result); } else { /* Fetch-in-segments mode */ OK = ExecQueryUsingCursor(query, &elapsed_msec); ResetCancelConn(); - results = NULL; /* PQclear(NULL) does nothing */ + result = NULL; /* PQclear(NULL) does nothing */ } if (!OK && pset.echo == PSQL_ECHO_ERRORS) @@ -1347,11 +1347,11 @@ SendQuery(const char *query) * savepoint is gone. If they issued a SAVEPOINT, releasing * ours would remove theirs. */ - if (results && - (strcmp(PQcmdStatus(results), "COMMIT") == 0 || - strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 || - strcmp(PQcmdStatus(results), "RELEASE") == 0 || - strcmp(PQcmdStatus(results), "ROLLBACK") == 0)) + if (result && + (strcmp(PQcmdStatus(result), "COMMIT") == 0 || + strcmp(PQcmdStatus(result), "SAVEPOINT") == 0 || + strcmp(PQcmdStatus(result), "RELEASE") == 0 || + strcmp(PQcmdStatus(result), "ROLLBACK") == 0)) svptcmd = NULL; else svptcmd = "RELEASE pg_psql_temporary_savepoint"; @@ -1379,7 +1379,7 @@ SendQuery(const char *query) ClearOrSaveResult(svptres); OK = false; - PQclear(results); + PQclear(result); ResetCancelConn(); goto sendquery_cleanup; } @@ -1387,7 +1387,7 @@ SendQuery(const char *query) } } - ClearOrSaveResult(results); + ClearOrSaveResult(result); /* Possible microtiming output */ if (timing) @@ -1462,7 +1462,7 @@ static bool DescribeQuery(const char *query, double *elapsed_msec) { bool timing = pset.timing; - PGresult *results; + PGresult *result; bool OK; instr_time before, after; @@ -1480,22 +1480,22 @@ DescribeQuery(const char *query, double *elapsed_msec) * anyway. (So there's no great need to clear it when done, which is a * good thing because libpq provides no easy way to do that.) */ - results = PQprepare(pset.db, "", query, 0, NULL); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQprepare(pset.db, "", query, 0, NULL); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - SetResultVariables(results, false); - ClearOrSaveResult(results); + SetResultVariables(result, false); + ClearOrSaveResult(result); return false; } - PQclear(results); + PQclear(result); - results = PQdescribePrepared(pset.db, ""); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - if (OK && results) + result = PQdescribePrepared(pset.db, ""); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + if (OK && result) { - if (PQnfields(results) > 0) + if (PQnfields(result) > 0) { PQExpBufferData buf; int i; @@ -1508,7 +1508,7 @@ DescribeQuery(const char *query, double *elapsed_msec) gettext_noop("Column"), gettext_noop("Type")); - for (i = 0; i < PQnfields(results); i++) + for (i = 0; i < PQnfields(result); i++) { const char *name; char *escname; @@ -1516,30 +1516,30 @@ DescribeQuery(const char *query, double *elapsed_msec) if (i > 0) appendPQExpBufferStr(&buf, ","); - name = PQfname(results, i); + name = PQfname(result, i); escname = PQescapeLiteral(pset.db, name, strlen(name)); if (escname == NULL) { pg_log_info("%s", PQerrorMessage(pset.db)); - PQclear(results); + PQclear(result); termPQExpBuffer(&buf); return false; } appendPQExpBuffer(&buf, "(%s, '%u'::pg_catalog.oid, %d)", escname, - PQftype(results, i), - PQfmod(results, i)); + PQftype(result, i), + PQfmod(result, i)); PQfreemem(escname); } appendPQExpBufferStr(&buf, ") s(name, tp, tpm)"); - PQclear(results); + PQclear(result); - results = PQexec(pset.db, buf.data); - OK = AcceptResult(results); + result = PQexec(pset.db, buf.data); + OK = AcceptResult(result); if (timing) { @@ -1548,8 +1548,8 @@ DescribeQuery(const char *query, double *elapsed_msec) *elapsed_msec += INSTR_TIME_GET_MILLISEC(after); } - if (OK && results) - OK = PrintQueryResults(results); + if (OK && result) + OK = PrintQueryResult(result); termPQExpBuffer(&buf); } @@ -1558,8 +1558,8 @@ DescribeQuery(const char *query, double *elapsed_msec) _("The command has no result, or the result has no columns.\n")); } - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); return OK; } @@ -1579,7 +1579,7 @@ static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec) { bool OK = true; - PGresult *results; + PGresult *result; PQExpBufferData buf; printQueryOpt my_popt = pset.popt; bool timing = pset.timing; @@ -1608,10 +1608,10 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) /* if we're not in a transaction, start one */ if (PQtransactionStatus(pset.db) == PQTRANS_IDLE) { - results = PQexec(pset.db, "BEGIN"); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + result = PQexec(pset.db, "BEGIN"); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); if (!OK) return false; started_txn = true; @@ -1622,12 +1622,12 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) appendPQExpBuffer(&buf, "DECLARE _psql_cursor NO SCROLL CURSOR FOR\n%s", query); - results = PQexec(pset.db, buf.data); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); + result = PQexec(pset.db, buf.data); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); if (!OK) - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); termPQExpBuffer(&buf); if (!OK) goto cleanup; @@ -1678,7 +1678,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) INSTR_TIME_SET_CURRENT(before); /* get fetch_count tuples at a time */ - results = PQexec(pset.db, fetch_cmd); + result = PQexec(pset.db, fetch_cmd); if (timing) { @@ -1687,7 +1687,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) *elapsed_msec += INSTR_TIME_GET_MILLISEC(after); } - if (PQresultStatus(results) != PGRES_TUPLES_OK) + if (PQresultStatus(result) != PGRES_TUPLES_OK) { /* shut down pager before printing error message */ if (is_pager) @@ -1696,18 +1696,18 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) is_pager = false; } - OK = AcceptResult(results); + OK = AcceptResult(result); Assert(!OK); - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); break; } if (pset.gset_prefix) { /* StoreQueryTuple will complain if not exactly one row */ - OK = StoreQueryTuple(results); - ClearOrSaveResult(results); + OK = StoreQueryTuple(result); + ClearOrSaveResult(result); break; } @@ -1715,7 +1715,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) * Note we do not deal with \gdesc, \gexec or \crosstabview modes here */ - ntuples = PQntuples(results); + ntuples = PQntuples(result); total_tuples += ntuples; if (ntuples < fetch_count) @@ -1733,9 +1733,9 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) is_pager = true; } - printQuery(results, &my_popt, fout, is_pager, pset.logfile); + printQuery(result, &my_popt, fout, is_pager, pset.logfile); - ClearOrSaveResult(results); + ClearOrSaveResult(result); /* after the first result set, disallow header decoration */ my_popt.topt.start_table = false; @@ -1802,22 +1802,22 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) * ignore the result (it's probably just a bleat about being in an aborted * transaction) */ - results = PQexec(pset.db, "CLOSE _psql_cursor"); + result = PQexec(pset.db, "CLOSE _psql_cursor"); if (OK) { - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); } else - PQclear(results); + PQclear(result); if (started_txn) { - results = PQexec(pset.db, OK ? "COMMIT" : "ROLLBACK"); - OK &= AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + result = PQexec(pset.db, OK ? "COMMIT" : "ROLLBACK"); + OK &= AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); } if (timing) diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index 5628db2ce6..2c29138d98 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -77,7 +77,7 @@ typedef struct _avl_tree } avl_tree; -static bool printCrosstab(const PGresult *results, +static bool printCrosstab(const PGresult *result, int num_columns, pivot_field *piv_columns, int field_for_columns, int num_rows, pivot_field *piv_rows, int field_for_rows, int field_for_data); @@ -100,7 +100,7 @@ static int rankCompare(const void *a, const void *b); * then call printCrosstab() for the actual output. */ bool -PrintResultsInCrosstab(const PGresult *res) +PrintResultInCrosstab(const PGresult *res) { bool retval = false; avl_tree piv_columns; @@ -261,7 +261,7 @@ PrintResultsInCrosstab(const PGresult *res) rankSort(num_columns, array_columns); /* - * Fourth part: print the crosstab'ed results. + * Fourth part: print the crosstab'ed result. */ retval = printCrosstab(res, num_columns, array_columns, field_for_columns, @@ -282,7 +282,7 @@ PrintResultsInCrosstab(const PGresult *res) * if successful, false otherwise. */ static bool -printCrosstab(const PGresult *results, +printCrosstab(const PGresult *result, int num_columns, pivot_field *piv_columns, int field_for_columns, int num_rows, pivot_field *piv_rows, int field_for_rows, int field_for_data) @@ -301,9 +301,9 @@ printCrosstab(const PGresult *results, /* The name of the first column is kept unchanged by the pivoting */ printTableAddHeader(&cont, - PQfname(results, field_for_rows), + PQfname(result, field_for_rows), false, - column_type_alignment(PQftype(results, + column_type_alignment(PQftype(result, field_for_rows))); /* @@ -318,7 +318,7 @@ printCrosstab(const PGresult *results, /* * The display alignment depends on its PQftype(). */ - col_align = column_type_alignment(PQftype(results, field_for_data)); + col_align = column_type_alignment(PQftype(result, field_for_data)); for (i = 0; i < num_columns; i++) { @@ -346,7 +346,7 @@ printCrosstab(const PGresult *results, /* * Step 3: fill in the content cells. */ - for (rn = 0; rn < PQntuples(results); rn++) + for (rn = 0; rn < PQntuples(result); rn++) { int row_number; int col_number; @@ -355,8 +355,8 @@ printCrosstab(const PGresult *results, pivot_field elt; /* Find target row */ - if (!PQgetisnull(results, rn, field_for_rows)) - elt.name = PQgetvalue(results, rn, field_for_rows); + if (!PQgetisnull(result, rn, field_for_rows)) + elt.name = PQgetvalue(result, rn, field_for_rows); else elt.name = NULL; rp = (pivot_field *) bsearch(&elt, @@ -368,8 +368,8 @@ printCrosstab(const PGresult *results, row_number = rp->rank; /* Find target column */ - if (!PQgetisnull(results, rn, field_for_columns)) - elt.name = PQgetvalue(results, rn, field_for_columns); + if (!PQgetisnull(result, rn, field_for_columns)) + elt.name = PQgetvalue(result, rn, field_for_columns); else elt.name = NULL; @@ -402,8 +402,8 @@ printCrosstab(const PGresult *results, goto error; } - cont.cells[idx] = !PQgetisnull(results, rn, field_for_data) ? - PQgetvalue(results, rn, field_for_data) : + cont.cells[idx] = !PQgetisnull(result, rn, field_for_data) ? + PQgetvalue(result, rn, field_for_data) : (popt.nullPrint ? popt.nullPrint : ""); } } diff --git a/src/bin/psql/crosstabview.h b/src/bin/psql/crosstabview.h index 84208f6e57..3b96906c94 100644 --- a/src/bin/psql/crosstabview.h +++ b/src/bin/psql/crosstabview.h @@ -24,6 +24,6 @@ #define CROSSTABVIEW_MAX_COLUMNS 1600 /* prototypes */ -extern bool PrintResultsInCrosstab(const PGresult *res); +extern bool PrintResultInCrosstab(const PGresult *res); #endif /* CROSSTABVIEW_H */ diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 937d6e9d49..56afa6817e 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -170,13 +170,13 @@ slashUsage(unsigned short int pager) fprintf(output, _("General\n")); fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n")); - fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display results in crosstab\n")); + fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n")); fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n")); - fprintf(output, _(" \\g [(OPTIONS)] [FILE] execute query (and send results to file or |pipe);\n" + fprintf(output, _(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n" " \\g with no arguments is equivalent to a semicolon\n")); fprintf(output, _(" \\gdesc describe result of query, without executing it\n")); fprintf(output, _(" \\gexec execute query, then execute each value in its result\n")); - fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n")); + fprintf(output, _(" \\gset [PREFIX] execute query and store result in psql variables\n")); fprintf(output, _(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n")); fprintf(output, _(" \\q quit psql\n")); fprintf(output, _(" \\watch [SEC] execute query every SEC seconds\n")); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index f614b26e2c..80dbea9efd 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -94,9 +94,9 @@ typedef struct _psqlSettings printQueryOpt *gsavepopt; /* if not null, saved print format settings */ char *gset_prefix; /* one-shot prefix argument for \gset */ - bool gdesc_flag; /* one-shot request to describe query results */ - bool gexec_flag; /* one-shot request to execute query results */ - bool crosstab_flag; /* one-shot request to crosstab results */ + bool gdesc_flag; /* one-shot request to describe query result */ + bool gexec_flag; /* one-shot request to execute query result */ + bool crosstab_flag; /* one-shot request to crosstab result */ char *ctv_args[4]; /* \crosstabview arguments */ bool notty; /* stdin or stdout is not a tty (as determined diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 502b5c5751..cc77eda51d 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -184,9 +184,9 @@ static bool completion_force_quote; /* true to force-quote filenames */ /* * A few macros to ease typing. You can use these to complete the given * string with - * 1) The results from a query you pass it. (Perhaps one of those below?) + * 1) The result from a query you pass it. (Perhaps one of those below?) * We support both simple and versioned queries. - * 2) The results from a schema query you pass it. + * 2) The result from a schema query you pass it. * We support both simple and versioned schema queries. * 3) The items from a null-pointer-terminated list (with or without * case-sensitive comparison); if the list is constant you can build it diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index b141aac8eb..47c58d2be9 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -45,7 +45,7 @@ valid_variable_name(const char *name) * that serves as list header. * * The list entries are kept in name order (according to strcmp). This - * is mainly to make the results of PrintVariables() more pleasing. + * is mainly to make the output of PrintVariables() more pleasing. */ VariableSpace CreateVariableSpace(void) -- 2.34.1 Attachments: [text/plain] 0001-psql-Rename-results-to-result-when-only-a-single-one.patch (27.9K, ../../[email protected]/2-0001-psql-Rename-results-to-result-when-only-a-single-one.patch) download | inline diff: From 0dc7b7f39ca82265448e4e7676841344d7fc9db1 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <[email protected]> Date: Thu, 27 Jan 2022 12:21:24 +0100 Subject: [PATCH] psql: Rename results to result when only a single one is meant This makes the naming more consistent with the libpq API and the rest of the code, and makes actually supporting multiple result sets in the future less confusing. --- src/bin/psql/command.c | 6 +- src/bin/psql/common.c | 230 ++++++++++++++++++------------------ src/bin/psql/crosstabview.c | 28 ++--- src/bin/psql/crosstabview.h | 2 +- src/bin/psql/help.c | 6 +- src/bin/psql/settings.h | 6 +- src/bin/psql/tab-complete.c | 4 +- src/bin/psql/variables.c | 2 +- 8 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index f590474855..292cff5df9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -279,7 +279,7 @@ HandleSlashCmds(PsqlScanState scan_state, * Subroutine to actually try to execute a backslash command. * * The typical "success" result code is PSQL_CMD_SKIP_LINE, although some - * commands return something else. Failure results are PSQL_CMD_ERROR, + * commands return something else. Failure result code is PSQL_CMD_ERROR, * unless PSQL_CMD_UNKNOWN is more appropriate. */ static backslashResult @@ -683,7 +683,7 @@ exec_command_copyright(PsqlScanState scan_state, bool active_branch) } /* - * \crosstabview -- execute a query and display results in crosstab + * \crosstabview -- execute a query and display result in crosstab */ static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch) @@ -5084,7 +5084,7 @@ do_watch(PQExpBuffer query_buf, double sleep) timebuf, sleep); myopt.title = title; - /* Run the query and print out the results */ + /* Run the query and print out the result */ res = PSQLexecWatch(query_buf->data, &myopt, pagerpipe); /* diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 3503605a7d..d65b9a124f 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -411,11 +411,11 @@ AcceptResult(const PGresult *result) * entered by the user, not queries generated by slash commands. */ static void -SetResultVariables(PGresult *results, bool success) +SetResultVariables(PGresult *result, bool success) { if (success) { - const char *ntuples = PQcmdTuples(results); + const char *ntuples = PQcmdTuples(result); SetVariable(pset.vars, "ERROR", "false"); SetVariable(pset.vars, "SQLSTATE", "00000"); @@ -423,8 +423,8 @@ SetResultVariables(PGresult *results, bool success) } else { - const char *code = PQresultErrorField(results, PG_DIAG_SQLSTATE); - const char *mesg = PQresultErrorField(results, PG_DIAG_MESSAGE_PRIMARY); + const char *code = PQresultErrorField(result, PG_DIAG_SQLSTATE); + const char *mesg = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY); SetVariable(pset.vars, "ERROR", "true"); @@ -587,7 +587,7 @@ PSQLexec(const char *query) * PSQLexecWatch * * This function is used for \watch command to send the query to - * the server and print out the results. + * the server and print out the result. * * Returns 1 if the query executed successfully, 0 if it cannot be repeated, * e.g., because of the interrupt, -1 on error. @@ -714,9 +714,9 @@ PrintNotifications(void) * Returns true if successful, false otherwise. */ static bool -PrintQueryTuples(const PGresult *results) +PrintQueryTuples(const PGresult *result) { - bool result = true; + bool ok = true; /* write output to \g argument, if any */ if (pset.gfname) @@ -729,11 +729,11 @@ PrintQueryTuples(const PGresult *results) if (is_pipe) disable_sigpipe_trap(); - printQuery(results, &pset.popt, fout, false, pset.logfile); + printQuery(result, &pset.popt, fout, false, pset.logfile); if (ferror(fout)) { pg_log_error("could not print result table: %m"); - result = false; + ok = false; } if (is_pipe) @@ -746,15 +746,15 @@ PrintQueryTuples(const PGresult *results) } else { - printQuery(results, &pset.popt, pset.queryFout, false, pset.logfile); + printQuery(result, &pset.popt, pset.queryFout, false, pset.logfile); if (ferror(pset.queryFout)) { pg_log_error("could not print result table: %m"); - result = false; + ok = false; } } - return result; + return ok; } @@ -912,7 +912,7 @@ ExecQueryTuples(const PGresult *result) * server-side opinion. */ static bool -ProcessResult(PGresult **results) +ProcessResult(PGresult **resultp) { bool success = true; bool first_cycle = true; @@ -923,7 +923,7 @@ ProcessResult(PGresult **results) bool is_copy; PGresult *next_result; - if (!AcceptResult(*results)) + if (!AcceptResult(*resultp)) { /* * Failure at this point is always a server-side failure or a @@ -934,7 +934,7 @@ ProcessResult(PGresult **results) break; } - result_status = PQresultStatus(*results); + result_status = PQresultStatus(*resultp); switch (result_status) { case PGRES_EMPTY_QUERY: @@ -1037,7 +1037,7 @@ ProcessResult(PGresult **results) copystream = pset.copyStream ? pset.copyStream : pset.cur_cmd_source; success = handleCopyIn(pset.db, copystream, - PQbinaryTuples(*results), + PQbinaryTuples(*resultp), ©_result) && success; } ResetCancelConn(); @@ -1046,8 +1046,8 @@ ProcessResult(PGresult **results) * Replace the PGRES_COPY_OUT/IN result with COPY command's exit * status, or with NULL if we want to suppress printing anything. */ - PQclear(*results); - *results = copy_result; + PQclear(*resultp); + *resultp = copy_result; } else if (first_cycle) { @@ -1064,12 +1064,12 @@ ProcessResult(PGresult **results) if (!next_result) break; - PQclear(*results); - *results = next_result; + PQclear(*resultp); + *resultp = next_result; first_cycle = false; } - SetResultVariables(*results, success); + SetResultVariables(*resultp, success); /* may need this to recover from conn loss during COPY */ if (!first_cycle && !CheckConnection()) @@ -1082,10 +1082,10 @@ ProcessResult(PGresult **results) /* * PrintQueryStatus: report command status as required * - * Note: Utility function for use by PrintQueryResults() only. + * Note: Utility function for use by PrintQueryResult() only. */ static void -PrintQueryStatus(PGresult *results) +PrintQueryStatus(PGresult *result) { char buf[16]; @@ -1094,59 +1094,59 @@ PrintQueryStatus(PGresult *results) if (pset.popt.topt.format == PRINT_HTML) { fputs("<p>", pset.queryFout); - html_escaped_print(PQcmdStatus(results), pset.queryFout); + html_escaped_print(PQcmdStatus(result), pset.queryFout); fputs("</p>\n", pset.queryFout); } else - fprintf(pset.queryFout, "%s\n", PQcmdStatus(results)); + fprintf(pset.queryFout, "%s\n", PQcmdStatus(result)); } if (pset.logfile) - fprintf(pset.logfile, "%s\n", PQcmdStatus(results)); + fprintf(pset.logfile, "%s\n", PQcmdStatus(result)); - snprintf(buf, sizeof(buf), "%u", (unsigned int) PQoidValue(results)); + snprintf(buf, sizeof(buf), "%u", (unsigned int) PQoidValue(result)); SetVariable(pset.vars, "LASTOID", buf); } /* - * PrintQueryResults: print out (or store or execute) query results as required + * PrintQueryResult: print out (or store or execute) query result as required * * Note: Utility function for use by SendQuery() only. * * Returns true if the query executed successfully, false otherwise. */ static bool -PrintQueryResults(PGresult *results) +PrintQueryResult(PGresult *result) { bool success; const char *cmdstatus; - if (!results) + if (!result) return false; - switch (PQresultStatus(results)) + switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: /* store or execute or print the data ... */ if (pset.gset_prefix) - success = StoreQueryTuple(results); + success = StoreQueryTuple(result); else if (pset.gexec_flag) - success = ExecQueryTuples(results); + success = ExecQueryTuples(result); else if (pset.crosstab_flag) - success = PrintResultsInCrosstab(results); + success = PrintResultInCrosstab(result); else - success = PrintQueryTuples(results); + success = PrintQueryTuples(result); /* if it's INSERT/UPDATE/DELETE RETURNING, also print status */ - cmdstatus = PQcmdStatus(results); + cmdstatus = PQcmdStatus(result); if (strncmp(cmdstatus, "INSERT", 6) == 0 || strncmp(cmdstatus, "UPDATE", 6) == 0 || strncmp(cmdstatus, "DELETE", 6) == 0) - PrintQueryStatus(results); + PrintQueryStatus(result); break; case PGRES_COMMAND_OK: - PrintQueryStatus(results); + PrintQueryStatus(result); success = true; break; @@ -1169,7 +1169,7 @@ PrintQueryResults(PGresult *results) default: success = false; pg_log_error("unexpected PQresultStatus: %d", - PQresultStatus(results)); + PQresultStatus(result)); break; } @@ -1181,7 +1181,7 @@ PrintQueryResults(PGresult *results) /* * SendQuery: send the query string to the backend - * (and print out results) + * (and print out result) * * Note: This is the "front door" way to send a query. That is, use it to * send queries actually entered by the user. These queries will be subject to @@ -1195,7 +1195,7 @@ bool SendQuery(const char *query) { bool timing = pset.timing; - PGresult *results; + PGresult *result; PGTransactionStatusType transaction_status; double elapsed_msec = 0; bool OK = false; @@ -1247,15 +1247,15 @@ SendQuery(const char *query) !pset.autocommit && !command_no_begin(query)) { - results = PQexec(pset.db, "BEGIN"); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQexec(pset.db, "BEGIN"); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - ClearOrSaveResult(results); + ClearOrSaveResult(result); ResetCancelConn(); goto sendquery_cleanup; } - ClearOrSaveResult(results); + ClearOrSaveResult(result); transaction_status = PQtransactionStatus(pset.db); } @@ -1264,15 +1264,15 @@ SendQuery(const char *query) (pset.cur_cmd_interactive || pset.on_error_rollback == PSQL_ERROR_ROLLBACK_ON)) { - results = PQexec(pset.db, "SAVEPOINT pg_psql_temporary_savepoint"); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQexec(pset.db, "SAVEPOINT pg_psql_temporary_savepoint"); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - ClearOrSaveResult(results); + ClearOrSaveResult(result); ResetCancelConn(); goto sendquery_cleanup; } - ClearOrSaveResult(results); + ClearOrSaveResult(result); on_error_rollback_savepoint = true; } @@ -1281,7 +1281,7 @@ SendQuery(const char *query) /* Describe query's result columns, without executing it */ OK = DescribeQuery(query, &elapsed_msec); ResetCancelConn(); - results = NULL; /* PQclear(NULL) does nothing */ + result = NULL; /* PQclear(NULL) does nothing */ } else if (pset.fetch_count <= 0 || pset.gexec_flag || pset.crosstab_flag || !is_select_command(query)) @@ -1293,11 +1293,11 @@ SendQuery(const char *query) if (timing) INSTR_TIME_SET_CURRENT(before); - results = PQexec(pset.db, query); + result = PQexec(pset.db, query); /* these operations are included in the timing result: */ ResetCancelConn(); - OK = ProcessResult(&results); + OK = ProcessResult(&result); if (timing) { @@ -1306,16 +1306,16 @@ SendQuery(const char *query) elapsed_msec = INSTR_TIME_GET_MILLISEC(after); } - /* but printing results isn't: */ - if (OK && results) - OK = PrintQueryResults(results); + /* but printing result isn't: */ + if (OK && result) + OK = PrintQueryResult(result); } else { /* Fetch-in-segments mode */ OK = ExecQueryUsingCursor(query, &elapsed_msec); ResetCancelConn(); - results = NULL; /* PQclear(NULL) does nothing */ + result = NULL; /* PQclear(NULL) does nothing */ } if (!OK && pset.echo == PSQL_ECHO_ERRORS) @@ -1347,11 +1347,11 @@ SendQuery(const char *query) * savepoint is gone. If they issued a SAVEPOINT, releasing * ours would remove theirs. */ - if (results && - (strcmp(PQcmdStatus(results), "COMMIT") == 0 || - strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 || - strcmp(PQcmdStatus(results), "RELEASE") == 0 || - strcmp(PQcmdStatus(results), "ROLLBACK") == 0)) + if (result && + (strcmp(PQcmdStatus(result), "COMMIT") == 0 || + strcmp(PQcmdStatus(result), "SAVEPOINT") == 0 || + strcmp(PQcmdStatus(result), "RELEASE") == 0 || + strcmp(PQcmdStatus(result), "ROLLBACK") == 0)) svptcmd = NULL; else svptcmd = "RELEASE pg_psql_temporary_savepoint"; @@ -1379,7 +1379,7 @@ SendQuery(const char *query) ClearOrSaveResult(svptres); OK = false; - PQclear(results); + PQclear(result); ResetCancelConn(); goto sendquery_cleanup; } @@ -1387,7 +1387,7 @@ SendQuery(const char *query) } } - ClearOrSaveResult(results); + ClearOrSaveResult(result); /* Possible microtiming output */ if (timing) @@ -1462,7 +1462,7 @@ static bool DescribeQuery(const char *query, double *elapsed_msec) { bool timing = pset.timing; - PGresult *results; + PGresult *result; bool OK; instr_time before, after; @@ -1480,22 +1480,22 @@ DescribeQuery(const char *query, double *elapsed_msec) * anyway. (So there's no great need to clear it when done, which is a * good thing because libpq provides no easy way to do that.) */ - results = PQprepare(pset.db, "", query, 0, NULL); - if (PQresultStatus(results) != PGRES_COMMAND_OK) + result = PQprepare(pset.db, "", query, 0, NULL); + if (PQresultStatus(result) != PGRES_COMMAND_OK) { pg_log_info("%s", PQerrorMessage(pset.db)); - SetResultVariables(results, false); - ClearOrSaveResult(results); + SetResultVariables(result, false); + ClearOrSaveResult(result); return false; } - PQclear(results); + PQclear(result); - results = PQdescribePrepared(pset.db, ""); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - if (OK && results) + result = PQdescribePrepared(pset.db, ""); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + if (OK && result) { - if (PQnfields(results) > 0) + if (PQnfields(result) > 0) { PQExpBufferData buf; int i; @@ -1508,7 +1508,7 @@ DescribeQuery(const char *query, double *elapsed_msec) gettext_noop("Column"), gettext_noop("Type")); - for (i = 0; i < PQnfields(results); i++) + for (i = 0; i < PQnfields(result); i++) { const char *name; char *escname; @@ -1516,30 +1516,30 @@ DescribeQuery(const char *query, double *elapsed_msec) if (i > 0) appendPQExpBufferStr(&buf, ","); - name = PQfname(results, i); + name = PQfname(result, i); escname = PQescapeLiteral(pset.db, name, strlen(name)); if (escname == NULL) { pg_log_info("%s", PQerrorMessage(pset.db)); - PQclear(results); + PQclear(result); termPQExpBuffer(&buf); return false; } appendPQExpBuffer(&buf, "(%s, '%u'::pg_catalog.oid, %d)", escname, - PQftype(results, i), - PQfmod(results, i)); + PQftype(result, i), + PQfmod(result, i)); PQfreemem(escname); } appendPQExpBufferStr(&buf, ") s(name, tp, tpm)"); - PQclear(results); + PQclear(result); - results = PQexec(pset.db, buf.data); - OK = AcceptResult(results); + result = PQexec(pset.db, buf.data); + OK = AcceptResult(result); if (timing) { @@ -1548,8 +1548,8 @@ DescribeQuery(const char *query, double *elapsed_msec) *elapsed_msec += INSTR_TIME_GET_MILLISEC(after); } - if (OK && results) - OK = PrintQueryResults(results); + if (OK && result) + OK = PrintQueryResult(result); termPQExpBuffer(&buf); } @@ -1558,8 +1558,8 @@ DescribeQuery(const char *query, double *elapsed_msec) _("The command has no result, or the result has no columns.\n")); } - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); return OK; } @@ -1579,7 +1579,7 @@ static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec) { bool OK = true; - PGresult *results; + PGresult *result; PQExpBufferData buf; printQueryOpt my_popt = pset.popt; bool timing = pset.timing; @@ -1608,10 +1608,10 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) /* if we're not in a transaction, start one */ if (PQtransactionStatus(pset.db) == PQTRANS_IDLE) { - results = PQexec(pset.db, "BEGIN"); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + result = PQexec(pset.db, "BEGIN"); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); if (!OK) return false; started_txn = true; @@ -1622,12 +1622,12 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) appendPQExpBuffer(&buf, "DECLARE _psql_cursor NO SCROLL CURSOR FOR\n%s", query); - results = PQexec(pset.db, buf.data); - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); + result = PQexec(pset.db, buf.data); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); if (!OK) - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); termPQExpBuffer(&buf); if (!OK) goto cleanup; @@ -1678,7 +1678,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) INSTR_TIME_SET_CURRENT(before); /* get fetch_count tuples at a time */ - results = PQexec(pset.db, fetch_cmd); + result = PQexec(pset.db, fetch_cmd); if (timing) { @@ -1687,7 +1687,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) *elapsed_msec += INSTR_TIME_GET_MILLISEC(after); } - if (PQresultStatus(results) != PGRES_TUPLES_OK) + if (PQresultStatus(result) != PGRES_TUPLES_OK) { /* shut down pager before printing error message */ if (is_pager) @@ -1696,18 +1696,18 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) is_pager = false; } - OK = AcceptResult(results); + OK = AcceptResult(result); Assert(!OK); - SetResultVariables(results, OK); - ClearOrSaveResult(results); + SetResultVariables(result, OK); + ClearOrSaveResult(result); break; } if (pset.gset_prefix) { /* StoreQueryTuple will complain if not exactly one row */ - OK = StoreQueryTuple(results); - ClearOrSaveResult(results); + OK = StoreQueryTuple(result); + ClearOrSaveResult(result); break; } @@ -1715,7 +1715,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) * Note we do not deal with \gdesc, \gexec or \crosstabview modes here */ - ntuples = PQntuples(results); + ntuples = PQntuples(result); total_tuples += ntuples; if (ntuples < fetch_count) @@ -1733,9 +1733,9 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) is_pager = true; } - printQuery(results, &my_popt, fout, is_pager, pset.logfile); + printQuery(result, &my_popt, fout, is_pager, pset.logfile); - ClearOrSaveResult(results); + ClearOrSaveResult(result); /* after the first result set, disallow header decoration */ my_popt.topt.start_table = false; @@ -1802,22 +1802,22 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) * ignore the result (it's probably just a bleat about being in an aborted * transaction) */ - results = PQexec(pset.db, "CLOSE _psql_cursor"); + result = PQexec(pset.db, "CLOSE _psql_cursor"); if (OK) { - OK = AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + OK = AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); } else - PQclear(results); + PQclear(result); if (started_txn) { - results = PQexec(pset.db, OK ? "COMMIT" : "ROLLBACK"); - OK &= AcceptResult(results) && - (PQresultStatus(results) == PGRES_COMMAND_OK); - ClearOrSaveResult(results); + result = PQexec(pset.db, OK ? "COMMIT" : "ROLLBACK"); + OK &= AcceptResult(result) && + (PQresultStatus(result) == PGRES_COMMAND_OK); + ClearOrSaveResult(result); } if (timing) diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index 5628db2ce6..2c29138d98 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -77,7 +77,7 @@ typedef struct _avl_tree } avl_tree; -static bool printCrosstab(const PGresult *results, +static bool printCrosstab(const PGresult *result, int num_columns, pivot_field *piv_columns, int field_for_columns, int num_rows, pivot_field *piv_rows, int field_for_rows, int field_for_data); @@ -100,7 +100,7 @@ static int rankCompare(const void *a, const void *b); * then call printCrosstab() for the actual output. */ bool -PrintResultsInCrosstab(const PGresult *res) +PrintResultInCrosstab(const PGresult *res) { bool retval = false; avl_tree piv_columns; @@ -261,7 +261,7 @@ PrintResultsInCrosstab(const PGresult *res) rankSort(num_columns, array_columns); /* - * Fourth part: print the crosstab'ed results. + * Fourth part: print the crosstab'ed result. */ retval = printCrosstab(res, num_columns, array_columns, field_for_columns, @@ -282,7 +282,7 @@ PrintResultsInCrosstab(const PGresult *res) * if successful, false otherwise. */ static bool -printCrosstab(const PGresult *results, +printCrosstab(const PGresult *result, int num_columns, pivot_field *piv_columns, int field_for_columns, int num_rows, pivot_field *piv_rows, int field_for_rows, int field_for_data) @@ -301,9 +301,9 @@ printCrosstab(const PGresult *results, /* The name of the first column is kept unchanged by the pivoting */ printTableAddHeader(&cont, - PQfname(results, field_for_rows), + PQfname(result, field_for_rows), false, - column_type_alignment(PQftype(results, + column_type_alignment(PQftype(result, field_for_rows))); /* @@ -318,7 +318,7 @@ printCrosstab(const PGresult *results, /* * The display alignment depends on its PQftype(). */ - col_align = column_type_alignment(PQftype(results, field_for_data)); + col_align = column_type_alignment(PQftype(result, field_for_data)); for (i = 0; i < num_columns; i++) { @@ -346,7 +346,7 @@ printCrosstab(const PGresult *results, /* * Step 3: fill in the content cells. */ - for (rn = 0; rn < PQntuples(results); rn++) + for (rn = 0; rn < PQntuples(result); rn++) { int row_number; int col_number; @@ -355,8 +355,8 @@ printCrosstab(const PGresult *results, pivot_field elt; /* Find target row */ - if (!PQgetisnull(results, rn, field_for_rows)) - elt.name = PQgetvalue(results, rn, field_for_rows); + if (!PQgetisnull(result, rn, field_for_rows)) + elt.name = PQgetvalue(result, rn, field_for_rows); else elt.name = NULL; rp = (pivot_field *) bsearch(&elt, @@ -368,8 +368,8 @@ printCrosstab(const PGresult *results, row_number = rp->rank; /* Find target column */ - if (!PQgetisnull(results, rn, field_for_columns)) - elt.name = PQgetvalue(results, rn, field_for_columns); + if (!PQgetisnull(result, rn, field_for_columns)) + elt.name = PQgetvalue(result, rn, field_for_columns); else elt.name = NULL; @@ -402,8 +402,8 @@ printCrosstab(const PGresult *results, goto error; } - cont.cells[idx] = !PQgetisnull(results, rn, field_for_data) ? - PQgetvalue(results, rn, field_for_data) : + cont.cells[idx] = !PQgetisnull(result, rn, field_for_data) ? + PQgetvalue(result, rn, field_for_data) : (popt.nullPrint ? popt.nullPrint : ""); } } diff --git a/src/bin/psql/crosstabview.h b/src/bin/psql/crosstabview.h index 84208f6e57..3b96906c94 100644 --- a/src/bin/psql/crosstabview.h +++ b/src/bin/psql/crosstabview.h @@ -24,6 +24,6 @@ #define CROSSTABVIEW_MAX_COLUMNS 1600 /* prototypes */ -extern bool PrintResultsInCrosstab(const PGresult *res); +extern bool PrintResultInCrosstab(const PGresult *res); #endif /* CROSSTABVIEW_H */ diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 937d6e9d49..56afa6817e 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -170,13 +170,13 @@ slashUsage(unsigned short int pager) fprintf(output, _("General\n")); fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n")); - fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display results in crosstab\n")); + fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n")); fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n")); - fprintf(output, _(" \\g [(OPTIONS)] [FILE] execute query (and send results to file or |pipe);\n" + fprintf(output, _(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n" " \\g with no arguments is equivalent to a semicolon\n")); fprintf(output, _(" \\gdesc describe result of query, without executing it\n")); fprintf(output, _(" \\gexec execute query, then execute each value in its result\n")); - fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n")); + fprintf(output, _(" \\gset [PREFIX] execute query and store result in psql variables\n")); fprintf(output, _(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n")); fprintf(output, _(" \\q quit psql\n")); fprintf(output, _(" \\watch [SEC] execute query every SEC seconds\n")); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index f614b26e2c..80dbea9efd 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -94,9 +94,9 @@ typedef struct _psqlSettings printQueryOpt *gsavepopt; /* if not null, saved print format settings */ char *gset_prefix; /* one-shot prefix argument for \gset */ - bool gdesc_flag; /* one-shot request to describe query results */ - bool gexec_flag; /* one-shot request to execute query results */ - bool crosstab_flag; /* one-shot request to crosstab results */ + bool gdesc_flag; /* one-shot request to describe query result */ + bool gexec_flag; /* one-shot request to execute query result */ + bool crosstab_flag; /* one-shot request to crosstab result */ char *ctv_args[4]; /* \crosstabview arguments */ bool notty; /* stdin or stdout is not a tty (as determined diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 502b5c5751..cc77eda51d 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -184,9 +184,9 @@ static bool completion_force_quote; /* true to force-quote filenames */ /* * A few macros to ease typing. You can use these to complete the given * string with - * 1) The results from a query you pass it. (Perhaps one of those below?) + * 1) The result from a query you pass it. (Perhaps one of those below?) * We support both simple and versioned queries. - * 2) The results from a schema query you pass it. + * 2) The result from a schema query you pass it. * We support both simple and versioned schema queries. * 3) The items from a null-pointer-terminated list (with or without * case-sensitive comparison); if the list is constant you can build it diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index b141aac8eb..47c58d2be9 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -45,7 +45,7 @@ valid_variable_name(const char *name) * that serves as list header. * * The list entries are kept in name order (according to strcmp). This - * is mainly to make the results of PrintVariables() more pleasing. + * is mainly to make the output of PrintVariables() more pleasing. */ VariableSpace CreateVariableSpace(void) -- 2.34.1 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-01-27 11:34 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-03-12 01:02 [PATCH] cfe-12-gist_over_cfe-11-persistent squash commit Bruce Momjian <[email protected]> 2022-01-27 11:34 psql: Rename results to result when only a single one is meant Peter Eisentraut <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox