c1f83337b13ef6a68fc6c9cb94e5ea99921c55b4
2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
19 #include <libpq/libpq-fs.h>
22 #include "php_pq_misc.h"
28 while (l
-- > 0 && e
[l
] == '\n') {
34 const char *strmode(long mode
)
36 switch (mode
& (INV_READ
|INV_WRITE
)) {
37 case INV_READ
|INV_WRITE
:
48 int compare_index(const void *lptr
, const void *rptr TSRMLS_DC
)
50 const Bucket
*l
= *(const Bucket
**) lptr
;
51 const Bucket
*r
= *(const Bucket
**) rptr
;
62 static int apply_to_oid(void *p
, void *arg TSRMLS_DC
)
67 if (Z_TYPE_PP(ztype
) != IS_LONG
) {
68 convert_to_long_ex(ztype
);
71 **types
= Z_LVAL_PP(ztype
);
74 if (*ztype
!= *(zval
**)p
) {
77 return ZEND_HASH_APPLY_KEEP
;
80 static int apply_to_param(void *p TSRMLS_DC
, int argc
, va_list argv
, zend_hash_key
*key
)
86 params
= (char ***) va_arg(argv
, char ***);
87 zdtor
= (HashTable
*) va_arg(argv
, HashTable
*);
89 if (Z_TYPE_PP(zparam
) == IS_NULL
) {
93 if (Z_TYPE_PP(zparam
) != IS_STRING
) {
94 convert_to_string_ex(zparam
);
97 **params
= Z_STRVAL_PP(zparam
);
100 if (*zparam
!= *(zval
**)p
) {
101 zend_hash_next_index_insert(zdtor
, zparam
, sizeof(zval
*), NULL
);
104 return ZEND_HASH_APPLY_KEEP
;
107 int php_pq_types_to_array(HashTable
*ht
, Oid
**types TSRMLS_DC
)
109 int count
= zend_hash_num_elements(ht
);
116 /* +1 for when less types than params are specified */
117 *types
= tmp
= ecalloc(count
+ 1, sizeof(**types
));
118 zend_hash_apply_with_argument(ht
, apply_to_oid
, &tmp TSRMLS_CC
);
124 int php_pq_params_to_array(HashTable
*ht
, char ***params
, HashTable
*zdtor TSRMLS_DC
)
126 int count
= zend_hash_num_elements(ht
);
133 *params
= tmp
= ecalloc(count
, sizeof(char *));
134 zend_hash_apply_with_arguments(ht TSRMLS_CC
, apply_to_param
, 2, &tmp
, zdtor
);
141 Oid *php_pq_ntypes_to_array(zend_bool fill, int argc, ...)
144 Oid *oids = ecalloc(argc + 1, sizeof(*oids));
147 va_start(argv, argc);
148 for (i = 0; i < argc; ++i) {
150 oids[i] = va_arg(argv, Oid);
166 * vim600: noet sw=4 ts=4 fdm=marker
167 * vim<600: noet sw=4 ts=4