LCOV - code coverage report
Current view: top level - src/pl/plperl - SPI.xs (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 54 59 91.5 %
Date: 2024-04-25 00:11:39 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         112 :         int limit = 0;
      29             :         char *query;
      30             :     CODE:
      31         112 :         if (items > 2)
      32           0 :             croak("Usage: spi_exec_query(query, limit) "
      33             :                   "or spi_exec_query(query)");
      34         112 :         if (items == 2)
      35           0 :             limit = SvIV(ST(1));
      36         112 :         query = sv2cstr(sv);
      37         112 :         ret_hash = plperl_spi_exec(query, limit);
      38         100 :         pfree(query);
      39         100 :         RETVAL = newRV_noinc((SV*) ret_hash);
      40             :     OUTPUT:
      41             :         RETVAL
      42             : 
      43             : void
      44             : spi_return_next(rv)
      45             :     SV *rv;
      46             :     CODE:
      47         174 :         plperl_return_next(rv);
      48             : 
      49             : SV *
      50             : spi_spi_query(sv)
      51             :     SV *sv;
      52             :     CODE:
      53          18 :         char* query = sv2cstr(sv);
      54          18 :         RETVAL = plperl_spi_query(query);
      55          18 :         pfree(query);
      56             :     OUTPUT:
      57             :         RETVAL
      58             : 
      59             : SV *
      60             : spi_spi_fetchrow(sv)
      61             :     SV* sv;
      62             :     CODE:
      63          72 :         char* cursor = sv2cstr(sv);
      64          72 :         RETVAL = plperl_spi_fetchrow(cursor);
      65          72 :         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          16 :         char* query = sv2cstr(sv);
      76          16 :         if (items < 1)
      77           0 :             Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
      78          16 :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
      79          32 :         for ( i = 1; i < items; i++)
      80          16 :             argv[i - 1] = ST(i);
      81          16 :         RETVAL = plperl_spi_prepare(query, items - 1, argv);
      82          14 :         pfree( argv);
      83          14 :         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          12 :         HV *attr = NULL;
      94          12 :         int i, offset = 1, argc;
      95             :         SV ** argv;
      96          12 :         char *query = sv2cstr(sv);
      97          12 :         if ( items < 1)
      98           0 :             Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
      99             :                        "[\\@bind_values])");
     100          12 :         if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
     101             :         {
     102           4 :             attr = ( HV*) SvRV(ST(1));
     103           4 :             offset++;
     104             :         }
     105          12 :         argc = items - offset;
     106          12 :         argv = ( SV**) palloc( argc * sizeof(SV*));
     107          20 :         for ( i = 0; offset < items; offset++, i++)
     108           8 :             argv[i] = ST(offset);
     109          12 :         ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
     110          12 :         RETVAL = newRV_noinc((SV*)ret_hash);
     111          12 :         pfree( argv);
     112          12 :         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           4 :         char *query = sv2cstr(sv);
     123           4 :         if ( items < 1)
     124           0 :             Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
     125             :                        "[\\@bind_values])");
     126           4 :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
     127          10 :         for ( i = 1; i < items; i++)
     128           6 :             argv[i - 1] = ST(i);
     129           4 :         RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
     130           4 :         pfree( argv);
     131           4 :         pfree(query);
     132             :     OUTPUT:
     133             :         RETVAL
     134             : 
     135             : void
     136             : spi_spi_freeplan(sv)
     137             :     SV *sv;
     138             :     CODE:
     139          10 :         char *query = sv2cstr(sv);
     140          10 :         plperl_spi_freeplan(query);
     141          10 :         pfree(query);
     142             : 
     143             : void
     144             : spi_spi_cursor_close(sv)
     145             :     SV *sv;
     146             :     CODE:
     147           2 :         char *cursor = sv2cstr(sv);
     148           2 :         plperl_spi_cursor_close(cursor);
     149           2 :         pfree(cursor);
     150             : 
     151             : void
     152             : spi_spi_commit()
     153             :     CODE:
     154          50 :         plperl_spi_commit();
     155             : 
     156             : void
     157             : spi_spi_rollback()
     158             :     CODE:
     159          34 :         plperl_spi_rollback();
     160             : 
     161             : BOOT:
     162          42 :     items = 0;  /* avoid 'unused variable' warning */

Generated by: LCOV version 1.14