~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/pl/plperl/SPI.xs

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* this must be first: */
 
2
#include "postgres.h"
 
3
 
 
4
/* perl stuff */
 
5
#include "EXTERN.h"
 
6
#include "perl.h"
 
7
#include "XSUB.h"
 
8
#include "ppport.h"
 
9
 
 
10
#include "spi_internal.h"
 
11
 
 
12
 
 
13
/*
 
14
 * Implementation of plperl's elog() function
 
15
 *
 
16
 * If the error level is less than ERROR, we'll just emit the message and
 
17
 * return.  When it is ERROR, elog() will longjmp, which we catch and
 
18
 * turn into a Perl croak().  Note we are assuming that elog() can't have
 
19
 * any internal failures that are so bad as to require a transaction abort.
 
20
 *
 
21
 * This is out-of-line to suppress "might be clobbered by longjmp" warnings.
 
22
 */
 
23
static void
 
24
do_spi_elog(int level, char *message)
 
25
{
 
26
        MemoryContext oldcontext = CurrentMemoryContext;
 
27
 
 
28
        PG_TRY();
 
29
        {
 
30
                elog(level, "%s", message);
 
31
        }
 
32
        PG_CATCH();
 
33
        {
 
34
                ErrorData  *edata;
 
35
 
 
36
                /* Must reset elog.c's state */
 
37
                MemoryContextSwitchTo(oldcontext);
 
38
                edata = CopyErrorData();
 
39
                FlushErrorState();
 
40
 
 
41
                /* Punt the error to Perl */
 
42
                croak("%s", edata->message);
 
43
        }
 
44
        PG_END_TRY();
 
45
}
 
46
 
 
47
 
 
48
MODULE = SPI PREFIX = spi_
 
49
 
 
50
PROTOTYPES: ENABLE
 
51
VERSIONCHECK: DISABLE
 
52
 
 
53
void
 
54
spi_elog(level, message)
 
55
        int level
 
56
        char* message
 
57
        CODE:
 
58
                if (level > ERROR)              /* no PANIC allowed thanks */
 
59
                        level = ERROR;
 
60
                if (level < DEBUG5)
 
61
                        level = DEBUG5;
 
62
                do_spi_elog(level, message);
 
63
 
 
64
int
 
65
spi_DEBUG()
 
66
 
 
67
int
 
68
spi_LOG()
 
69
 
 
70
int
 
71
spi_INFO()
 
72
 
 
73
int
 
74
spi_NOTICE()
 
75
 
 
76
int
 
77
spi_WARNING()
 
78
 
 
79
int
 
80
spi_ERROR()
 
81
 
 
82
SV*
 
83
spi_spi_exec_query(query, ...)
 
84
        char* query;
 
85
        PREINIT:
 
86
                HV *ret_hash;
 
87
                int limit = 0;
 
88
        CODE:
 
89
                if (items > 2)
 
90
                        croak("Usage: spi_exec_query(query, limit) or spi_exec_query(query)");
 
91
                if (items == 2)
 
92
                        limit = SvIV(ST(1));
 
93
                ret_hash = plperl_spi_exec(query, limit);
 
94
                RETVAL = newRV_noinc((SV*) ret_hash);
 
95
        OUTPUT:
 
96
                RETVAL
 
97
 
 
98
 
 
99
BOOT:
 
100
    items = 0;  /* avoid 'unused variable' warning */