LCOV - differential code coverage report
Current view: top level - src/fe_utils - query_utils.c (source / functions) Coverage Total Hit UBC CBC
Current: ba12a202ce1b5581dc0ed149cf3f637d7897ad5d vs 2866d8c7dbfc9d882a7d80fef93fbbe763709932 Lines: 87.5 % 32 28 4 28
Current Date: 2026-08-27 14:31:44 +0300 Functions: 100.0 % 3 3 3
Baseline: lcov-20260827-baseline Branches: 72.2 % 18 13 5 13
Baseline Date: 2026-08-27 14:31:58 +0300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 87.5 % 32 28 4 28
Function coverage date bins:
(360..) days: 100.0 % 3 3 3
Branch coverage date bins:
(360..) days: 72.2 % 18 13 5 13

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * Facilities for frontend code to query a databases.
                                  4                 :                :  *
                                  5                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  6                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  7                 :                :  *
                                  8                 :                :  * src/fe_utils/query_utils.c
                                  9                 :                :  *
                                 10                 :                :  *-------------------------------------------------------------------------
                                 11                 :                :  */
                                 12                 :                : #include "postgres_fe.h"
                                 13                 :                : 
                                 14                 :                : #include "common/logging.h"
                                 15                 :                : #include "fe_utils/cancel.h"
                                 16                 :                : #include "fe_utils/query_utils.h"
                                 17                 :                : 
                                 18                 :                : /*
                                 19                 :                :  * Run a query, return the results, exit program on failure.
                                 20                 :                :  */
                                 21                 :                : PGresult *
 2029 rhaas@postgresql.org       22                 :CBC         865 : executeQuery(PGconn *conn, const char *query, bool echo)
                                 23                 :                : {
                                 24                 :                :     PGresult   *res;
                                 25                 :                : 
                                 26         [ +  + ]:            865 :     if (echo)
                                 27                 :             42 :         printf("%s\n", query);
                                 28                 :                : 
                                 29                 :            865 :     res = PQexec(conn, query);
                                 30   [ +  -  +  + ]:           1730 :     if (!res ||
                                 31                 :            865 :         PQresultStatus(res) != PGRES_TUPLES_OK)
                                 32                 :                :     {
                                 33                 :              2 :         pg_log_error("query failed: %s", PQerrorMessage(conn));
 1602 tgl@sss.pgh.pa.us          34                 :              2 :         pg_log_error_detail("Query was: %s", query);
 2029 rhaas@postgresql.org       35                 :              2 :         PQfinish(conn);
                                 36                 :              2 :         exit(1);
                                 37                 :                :     }
                                 38                 :                : 
                                 39                 :            863 :     return res;
                                 40                 :                : }
                                 41                 :                : 
                                 42                 :                : 
                                 43                 :                : /*
                                 44                 :                :  * As above for a SQL command (which returns nothing).
                                 45                 :                :  */
                                 46                 :                : void
                                 47                 :            171 : executeCommand(PGconn *conn, const char *query, bool echo)
                                 48                 :                : {
                                 49                 :                :     PGresult   *res;
                                 50                 :                : 
                                 51         [ +  + ]:            171 :     if (echo)
                                 52                 :              7 :         printf("%s\n", query);
                                 53                 :                : 
                                 54                 :            171 :     res = PQexec(conn, query);
                                 55   [ +  -  -  + ]:            342 :     if (!res ||
                                 56                 :            171 :         PQresultStatus(res) != PGRES_COMMAND_OK)
                                 57                 :                :     {
 2029 rhaas@postgresql.org       58                 :UBC           0 :         pg_log_error("query failed: %s", PQerrorMessage(conn));
 1602 tgl@sss.pgh.pa.us          59                 :              0 :         pg_log_error_detail("Query was: %s", query);
 2029 rhaas@postgresql.org       60                 :              0 :         PQfinish(conn);
                                 61                 :              0 :         exit(1);
                                 62                 :                :     }
                                 63                 :                : 
 2029 rhaas@postgresql.org       64                 :CBC         171 :     PQclear(res);
                                 65                 :            171 : }
                                 66                 :                : 
                                 67                 :                : 
                                 68                 :                : /*
                                 69                 :                :  * As above for a SQL maintenance command (returns command success).
                                 70                 :                :  * Command is executed with a cancel handler set, so Ctrl-C can
                                 71                 :                :  * interrupt it.
                                 72                 :                :  */
                                 73                 :                : bool
                                 74                 :             15 : executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
                                 75                 :                : {
                                 76                 :                :     PGresult   *res;
                                 77                 :                :     bool        r;
                                 78                 :                : 
                                 79         [ +  + ]:             15 :     if (echo)
                                 80                 :              7 :         printf("%s\n", query);
                                 81                 :                : 
                                 82                 :             15 :     SetCancelConn(conn);
                                 83                 :             15 :     res = PQexec(conn, query);
                                 84                 :             15 :     ResetCancelConn();
                                 85                 :                : 
                                 86   [ +  -  +  - ]:             15 :     r = (res && PQresultStatus(res) == PGRES_COMMAND_OK);
                                 87                 :                : 
 1516 peter@eisentraut.org       88                 :             15 :     PQclear(res);
                                 89                 :                : 
 2029 rhaas@postgresql.org       90                 :             15 :     return r;
                                 91                 :                : }
        

Generated by: LCOV version 2.0-1