LCOV - code coverage report
Current view: top level - src/test/modules/test_copy_callbacks - test_copy_callbacks.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 13 13
Test Date: 2026-03-03 14:15:12 Functions: 100.0 % 4 4
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*--------------------------------------------------------------------------
       2              :  *
       3              :  * test_copy_callbacks.c
       4              :  *      Code for testing COPY callbacks.
       5              :  *
       6              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7              :  * Portions Copyright (c) 1994, Regents of the University of California
       8              :  *
       9              :  * IDENTIFICATION
      10              :  *      src/test/modules/test_copy_callbacks/test_copy_callbacks.c
      11              :  *
      12              :  * -------------------------------------------------------------------------
      13              :  */
      14              : 
      15              : #include "postgres.h"
      16              : 
      17              : #include "access/table.h"
      18              : #include "commands/copy.h"
      19              : #include "fmgr.h"
      20              : #include "utils/rel.h"
      21              : 
      22            1 : PG_MODULE_MAGIC;
      23              : 
      24              : static void
      25            3 : to_cb(void *data, int len)
      26              : {
      27            3 :     ereport(NOTICE,
      28              :             (errmsg("COPY TO callback called with data \"%s\" and length %d",
      29              :                     (char *) data, len)));
      30            3 : }
      31              : 
      32            2 : PG_FUNCTION_INFO_V1(test_copy_to_callback);
      33              : Datum
      34            1 : test_copy_to_callback(PG_FUNCTION_ARGS)
      35              : {
      36            1 :     Relation    rel = table_open(PG_GETARG_OID(0), AccessShareLock);
      37              :     CopyToState cstate;
      38              :     int64       processed;
      39              : 
      40            1 :     cstate = BeginCopyTo(NULL, rel, NULL, RelationGetRelid(rel), NULL, false,
      41              :                          to_cb, NIL, NIL);
      42            1 :     processed = DoCopyTo(cstate);
      43            1 :     EndCopyTo(cstate);
      44              : 
      45            1 :     ereport(NOTICE, (errmsg("COPY TO callback has processed %" PRId64 " rows",
      46              :                             processed)));
      47              : 
      48            1 :     table_close(rel, NoLock);
      49              : 
      50            1 :     PG_RETURN_VOID();
      51              : }
        

Generated by: LCOV version 2.0-1