LCOV - code coverage report
Current view: top level - src/test/modules/test_copy_callbacks - test_copy_callbacks.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17beta1 Lines: 13 13 100.0 %
Date: 2024-05-29 12:11:05 Functions: 4 4 100.0 %
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-2024, 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           2 : PG_MODULE_MAGIC;
      23             : 
      24             : static void
      25           6 : to_cb(void *data, int len)
      26             : {
      27           6 :     ereport(NOTICE,
      28             :             (errmsg("COPY TO callback called with data \"%s\" and length %d",
      29             :                     (char *) data, len)));
      30           6 : }
      31             : 
      32           4 : PG_FUNCTION_INFO_V1(test_copy_to_callback);
      33             : Datum
      34           2 : test_copy_to_callback(PG_FUNCTION_ARGS)
      35             : {
      36           2 :     Relation    rel = table_open(PG_GETARG_OID(0), AccessShareLock);
      37             :     CopyToState cstate;
      38             :     int64       processed;
      39             : 
      40           2 :     cstate = BeginCopyTo(NULL, rel, NULL, RelationGetRelid(rel), NULL, false,
      41             :                          to_cb, NIL, NIL);
      42           2 :     processed = DoCopyTo(cstate);
      43           2 :     EndCopyTo(cstate);
      44             : 
      45           2 :     ereport(NOTICE, (errmsg("COPY TO callback has processed %lld rows",
      46             :                             (long long) processed)));
      47             : 
      48           2 :     table_close(rel, NoLock);
      49             : 
      50           2 :     PG_RETURN_VOID();
      51             : }

Generated by: LCOV version 1.14