PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
hstore_plperl.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "plperl.h"
#include "plperl_helpers.h"
#include "hstore.h"
Include dependency graph for hstore_plperl.c:

Go to the source code of this file.

Macros

#define hstoreUpgrade   hstoreUpgrade_p
 
#define hstoreUniquePairs   hstoreUniquePairs_p
 
#define hstorePairs   hstorePairs_p
 
#define hstoreCheckKeyLen   hstoreCheckKeyLen_p
 
#define hstoreCheckValLen   hstoreCheckValLen_p
 

Typedefs

typedef HStore *(* hstoreUpgrade_t )(Datum orig)
 
typedef int(* hstoreUniquePairs_t )(Pairs *a, int32 l, int32 *buflen)
 
typedef HStore *(* hstorePairs_t )(Pairs *pairs, int32 pcount, int32 buflen)
 
typedef size_t(* hstoreCheckKeyLen_t )(size_t len)
 
typedef size_t(* hstoreCheckValLen_t )(size_t len)
 

Functions

void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (hstore_to_plperl)
 
Datum hstore_to_plperl (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (plperl_to_hstore)
 
Datum plperl_to_hstore (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static hstoreUpgrade_t hstoreUpgrade_p
 
static hstoreUniquePairs_t hstoreUniquePairs_p
 
static hstorePairs_t hstorePairs_p
 
static hstoreCheckKeyLen_t hstoreCheckKeyLen_p
 
static hstoreCheckValLen_t hstoreCheckValLen_p
 

Macro Definition Documentation

#define hstoreCheckKeyLen   hstoreCheckKeyLen_p

Definition at line 61 of file hstore_plperl.c.

Referenced by _PG_init(), and plperl_to_hstore().

#define hstoreCheckValLen   hstoreCheckValLen_p

Definition at line 62 of file hstore_plperl.c.

Referenced by _PG_init(), and plperl_to_hstore().

#define hstorePairs   hstorePairs_p

Definition at line 60 of file hstore_plperl.c.

Referenced by _PG_init(), hstore_slice_to_hstore(), and plperl_to_hstore().

#define hstoreUniquePairs   hstoreUniquePairs_p

Definition at line 59 of file hstore_plperl.c.

Referenced by _PG_init(), hstoreArrayToPairs(), and plperl_to_hstore().

#define hstoreUpgrade   hstoreUpgrade_p

Definition at line 58 of file hstore_plperl.c.

Referenced by _PG_init().

Typedef Documentation

typedef size_t(* hstoreCheckKeyLen_t)(size_t len)

Definition at line 21 of file hstore_plperl.c.

typedef size_t(* hstoreCheckValLen_t)(size_t len)

Definition at line 23 of file hstore_plperl.c.

typedef HStore*(* hstorePairs_t)(Pairs *pairs, int32 pcount, int32 buflen)

Definition at line 19 of file hstore_plperl.c.

typedef int(* hstoreUniquePairs_t)(Pairs *a, int32 l, int32 *buflen)

Definition at line 17 of file hstore_plperl.c.

typedef HStore*(* hstoreUpgrade_t)(Datum orig)

Definition at line 15 of file hstore_plperl.c.

Function Documentation

void _PG_init ( void  )

Definition at line 31 of file hstore_plperl.c.

References AssertVariableIsOfType, hstoreCheckKeyLen, hstoreCheckKeyLen_p, hstoreCheckValLen, hstoreCheckValLen_p, hstorePairs, hstorePairs_p, hstoreUniquePairs, hstoreUniquePairs_p, hstoreUpgrade, hstoreUpgrade_p, load_external_function(), and NULL.

32 {
33  /* Asserts verify that typedefs above match original declarations */
36  load_external_function("$libdir/hstore", "hstoreUpgrade",
37  true, NULL);
40  load_external_function("$libdir/hstore", "hstoreUniquePairs",
41  true, NULL);
44  load_external_function("$libdir/hstore", "hstorePairs",
45  true, NULL);
48  load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
49  true, NULL);
52  load_external_function("$libdir/hstore", "hstoreCheckValLen",
53  true, NULL);
54 }
size_t(* hstoreCheckValLen_t)(size_t len)
Definition: hstore_plperl.c:23
#define hstorePairs
Definition: hstore_plperl.c:60
static hstorePairs_t hstorePairs_p
Definition: hstore_plperl.c:20
#define hstoreCheckValLen
Definition: hstore_plperl.c:62
HStore *(* hstoreUpgrade_t)(Datum orig)
Definition: hstore_plperl.c:15
static hstoreCheckValLen_t hstoreCheckValLen_p
Definition: hstore_plperl.c:24
static hstoreCheckKeyLen_t hstoreCheckKeyLen_p
Definition: hstore_plperl.c:22
int(* hstoreUniquePairs_t)(Pairs *a, int32 l, int32 *buflen)
Definition: hstore_plperl.c:17
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
#define hstoreUniquePairs
Definition: hstore_plperl.c:59
#define hstoreUpgrade
Definition: hstore_plperl.c:58
#define NULL
Definition: c.h:229
#define hstoreCheckKeyLen
Definition: hstore_plperl.c:61
static hstoreUniquePairs_t hstoreUniquePairs_p
Definition: hstore_plperl.c:18
static hstoreUpgrade_t hstoreUpgrade_p
Definition: hstore_plperl.c:16
HStore *(* hstorePairs_t)(Pairs *pairs, int32 pcount, int32 buflen)
Definition: hstore_plperl.c:19
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:783
size_t(* hstoreCheckKeyLen_t)(size_t len)
Definition: hstore_plperl.c:21
Datum hstore_to_plperl ( PG_FUNCTION_ARGS  )

Definition at line 68 of file hstore_plperl.c.

References ARRPTR, cstr2sv(), HS_COUNT, HSTORE_KEY, HSTORE_KEYLEN, HSTORE_VAL, HSTORE_VALISNULL, HSTORE_VALLEN, i, PG_GETARG_HS, pnstrdup(), PointerGetDatum, STRPTR, and value.

69 {
70  HStore *in = PG_GETARG_HS(0);
71  int i;
72  int count = HS_COUNT(in);
73  char *base = STRPTR(in);
74  HEntry *entries = ARRPTR(in);
75  HV *hv;
76 
77  hv = newHV();
78 
79  for (i = 0; i < count; i++)
80  {
81  const char *key;
82  SV *value;
83 
84  key = pnstrdup(HSTORE_KEY(entries, base, i),
85  HSTORE_KEYLEN(entries, i));
86  value = HSTORE_VALISNULL(entries, i) ? newSV(0) :
87  cstr2sv(pnstrdup(HSTORE_VAL(entries, base, i),
88  HSTORE_VALLEN(entries, i)));
89 
90  (void) hv_store(hv, key, strlen(key), value, 0);
91  }
92 
93  return PointerGetDatum(newRV((SV *) hv));
94 }
Definition: hstore.h:44
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1088
#define PointerGetDatum(X)
Definition: postgres.h:562
#define HSTORE_KEYLEN(arr_, i_)
Definition: hstore.h:81
#define HSTORE_VALLEN(arr_, i_)
Definition: hstore.h:82
#define HSTORE_VALISNULL(arr_, i_)
Definition: hstore.h:83
#define HS_COUNT(hsp_)
Definition: hstore.h:61
#define PG_GETARG_HS(x)
Definition: hstore.h:154
#define HSTORE_KEY(arr_, str_, i_)
Definition: hstore.h:79
static SV * cstr2sv(const char *str)
Definition: hstore.h:18
#define HSTORE_VAL(arr_, str_, i_)
Definition: hstore.h:80
#define STRPTR(x)
Definition: hstore.h:76
int i
#define ARRPTR(x)
Definition: cube.c:26
static struct @121 value
PG_FUNCTION_INFO_V1 ( hstore_to_plperl  )
PG_FUNCTION_INFO_V1 ( plperl_to_hstore  )
Datum plperl_to_hstore ( PG_FUNCTION_ARGS  )

Definition at line 100 of file hstore_plperl.c.

References hstoreCheckKeyLen, hstoreCheckValLen, hstorePairs, hstoreUniquePairs, i, Pairs::isnull, Pairs::key, Pairs::keylen, Pairs::needfree, NULL, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, pstrdup(), sv2cstr(), Pairs::val, val, Pairs::vallen, and value.

101 {
102  HV *hv;
103  HE *he;
104  int32 buflen;
105  int32 i;
106  int32 pcount;
107  HStore *out;
108  Pairs *pairs;
109 
110  hv = (HV *) SvRV((SV *) PG_GETARG_POINTER(0));
111 
112  pcount = hv_iterinit(hv);
113 
114  pairs = palloc(pcount * sizeof(Pairs));
115 
116  i = 0;
117  while ((he = hv_iternext(hv)))
118  {
119  char *key = sv2cstr(HeSVKEY_force(he));
120  SV *value = HeVAL(he);
121 
122  pairs[i].key = pstrdup(key);
123  pairs[i].keylen = hstoreCheckKeyLen(strlen(pairs[i].key));
124  pairs[i].needfree = true;
125 
126  if (!SvOK(value))
127  {
128  pairs[i].val = NULL;
129  pairs[i].vallen = 0;
130  pairs[i].isnull = true;
131  }
132  else
133  {
134  pairs[i].val = pstrdup(sv2cstr(value));
135  pairs[i].vallen = hstoreCheckValLen(strlen(pairs[i].val));
136  pairs[i].isnull = false;
137  }
138 
139  i++;
140  }
141 
142  pcount = hstoreUniquePairs(pairs, pcount, &buflen);
143  out = hstorePairs(pairs, pcount, buflen);
144  PG_RETURN_POINTER(out);
145 }
#define hstorePairs
Definition: hstore_plperl.c:60
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: hstore.h:44
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
size_t vallen
Definition: hstore.h:166
#define hstoreCheckValLen
Definition: hstore_plperl.c:62
bool needfree
Definition: hstore.h:168
signed int int32
Definition: c.h:256
char * val
Definition: hstore.h:164
char * key
Definition: hstore.h:163
#define hstoreUniquePairs
Definition: hstore_plperl.c:59
size_t keylen
Definition: hstore.h:165
#define NULL
Definition: c.h:229
bool isnull
Definition: hstore.h:167
#define hstoreCheckKeyLen
Definition: hstore_plperl.c:61
void * palloc(Size size)
Definition: mcxt.c:849
int i
static struct @121 value
Definition: hstore.h:161
long val
Definition: informix.c:689
static char * sv2cstr(SV *sv)

Variable Documentation

hstoreCheckKeyLen_t hstoreCheckKeyLen_p
static

Definition at line 22 of file hstore_plperl.c.

Referenced by _PG_init().

hstoreCheckValLen_t hstoreCheckValLen_p
static

Definition at line 24 of file hstore_plperl.c.

Referenced by _PG_init().

hstorePairs_t hstorePairs_p
static

Definition at line 20 of file hstore_plperl.c.

Referenced by _PG_init().

hstoreUniquePairs_t hstoreUniquePairs_p
static

Definition at line 18 of file hstore_plperl.c.

Referenced by _PG_init().

hstoreUpgrade_t hstoreUpgrade_p
static

Definition at line 16 of file hstore_plperl.c.

Referenced by _PG_init().

PG_MODULE_MAGIC

Definition at line 10 of file hstore_plperl.c.