LCOV - code coverage report
Current view: top level - src/pl/plperl - SPI.xs Coverage Total Hit
Test: PostgreSQL 19devel Lines: 91.5 % 59 54
Test Date: 2026-02-28 11:14:57 Functions: - 0 0
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /**********************************************************************
       2              :  * PostgreSQL::InServer::SPI
       3              :  *
       4              :  * SPI interface for plperl.
       5              :  *
       6              :  *    src/pl/plperl/SPI.xs
       7              :  *
       8              :  **********************************************************************/
       9              : 
      10              : /* this must be first: */
      11              : #include "postgres.h"
      12              : 
      13              : /* perl stuff */
      14              : #define PG_NEED_PERL_XSUB_H
      15              : #include "plperl.h"
      16              : 
      17              : 
      18              : MODULE = PostgreSQL::InServer::SPI PREFIX = spi_
      19              : 
      20              : PROTOTYPES: ENABLE
      21              : VERSIONCHECK: DISABLE
      22              : 
      23              : SV*
      24              : spi_spi_exec_query(sv, ...)
      25              :     SV* sv;
      26              :     PREINIT:
      27              :         HV *ret_hash;
      28           57 :         int limit = 0;
      29              :         char *query;
      30              :     CODE:
      31           57 :         if (items > 2)
      32            0 :             croak("Usage: spi_exec_query(query, limit) "
      33              :                   "or spi_exec_query(query)");
      34           57 :         if (items == 2)
      35            0 :             limit = SvIV(ST(1));
      36           57 :         query = sv2cstr(sv);
      37           57 :         ret_hash = plperl_spi_exec(query, limit);
      38           51 :         pfree(query);
      39           51 :         RETVAL = newRV_noinc((SV*) ret_hash);
      40              :     OUTPUT:
      41              :         RETVAL
      42              : 
      43              : void
      44              : spi_return_next(rv)
      45              :     SV *rv;
      46              :     CODE:
      47           87 :         plperl_return_next(rv);
      48              : 
      49              : SV *
      50              : spi_spi_query(sv)
      51              :     SV *sv;
      52              :     CODE:
      53            9 :         char* query = sv2cstr(sv);
      54            9 :         RETVAL = plperl_spi_query(query);
      55            9 :         pfree(query);
      56              :     OUTPUT:
      57              :         RETVAL
      58              : 
      59              : SV *
      60              : spi_spi_fetchrow(sv)
      61              :     SV* sv;
      62              :     CODE:
      63           36 :         char* cursor = sv2cstr(sv);
      64           36 :         RETVAL = plperl_spi_fetchrow(cursor);
      65           36 :         pfree(cursor);
      66              :     OUTPUT:
      67              :         RETVAL
      68              : 
      69              : SV*
      70              : spi_spi_prepare(sv, ...)
      71              :     SV* sv;
      72              :     CODE:
      73              :         int i;
      74              :         SV** argv;
      75            8 :         char* query = sv2cstr(sv);
      76            8 :         if (items < 1)
      77            0 :             Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
      78            8 :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
      79           16 :         for ( i = 1; i < items; i++)
      80            8 :             argv[i - 1] = ST(i);
      81            8 :         RETVAL = plperl_spi_prepare(query, items - 1, argv);
      82            7 :         pfree( argv);
      83            7 :         pfree(query);
      84              :     OUTPUT:
      85              :         RETVAL
      86              : 
      87              : SV*
      88              : spi_spi_exec_prepared(sv, ...)
      89              :     SV* sv;
      90              :     PREINIT:
      91              :         HV *ret_hash;
      92              :     CODE:
      93            6 :         HV *attr = NULL;
      94            6 :         int i, offset = 1, argc;
      95              :         SV ** argv;
      96            6 :         char *query = sv2cstr(sv);
      97            6 :         if ( items < 1)
      98            0 :             Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
      99              :                        "[\\@bind_values])");
     100            6 :         if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
     101              :         {
     102            2 :             attr = ( HV*) SvRV(ST(1));
     103            2 :             offset++;
     104              :         }
     105            6 :         argc = items - offset;
     106            6 :         argv = ( SV**) palloc( argc * sizeof(SV*));
     107           10 :         for ( i = 0; offset < items; offset++, i++)
     108            4 :             argv[i] = ST(offset);
     109            6 :         ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
     110            6 :         RETVAL = newRV_noinc((SV*)ret_hash);
     111            6 :         pfree( argv);
     112            6 :         pfree(query);
     113              :     OUTPUT:
     114              :         RETVAL
     115              : 
     116              : SV*
     117              : spi_spi_query_prepared(sv, ...)
     118              :     SV * sv;
     119              :     CODE:
     120              :         int i;
     121              :         SV ** argv;
     122            2 :         char *query = sv2cstr(sv);
     123            2 :         if ( items < 1)
     124            0 :             Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
     125              :                        "[\\@bind_values])");
     126            2 :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
     127            5 :         for ( i = 1; i < items; i++)
     128            3 :             argv[i - 1] = ST(i);
     129            2 :         RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
     130            2 :         pfree( argv);
     131            2 :         pfree(query);
     132              :     OUTPUT:
     133              :         RETVAL
     134              : 
     135              : void
     136              : spi_spi_freeplan(sv)
     137              :     SV *sv;
     138              :     CODE:
     139            5 :         char *query = sv2cstr(sv);
     140            5 :         plperl_spi_freeplan(query);
     141            5 :         pfree(query);
     142              : 
     143              : void
     144              : spi_spi_cursor_close(sv)
     145              :     SV *sv;
     146              :     CODE:
     147            1 :         char *cursor = sv2cstr(sv);
     148            1 :         plperl_spi_cursor_close(cursor);
     149            1 :         pfree(cursor);
     150              : 
     151              : void
     152              : spi_spi_commit()
     153              :     CODE:
     154           25 :         plperl_spi_commit();
     155              : 
     156              : void
     157              : spi_spi_rollback()
     158              :     CODE:
     159           17 :         plperl_spi_rollback();
     160              : 
     161              : BOOT:
     162           23 :     items = 0;  /* avoid 'unused variable' warning */
        

Generated by: LCOV version 2.0-1