24381820d75cd407fc1d55b333a400e633f38d4f
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 switch (Z_TYPE_PP(zparam
)) {
96 **params
= Z_BVAL_PP(zparam
) ? "t" : "f";
101 SEPARATE_ZVAL(zparam
);
102 Z_TYPE_PP(zparam
) = IS_STRING
;
103 Z_STRLEN_PP(zparam
) = spprintf(&Z_STRVAL_PP(zparam
), 0, "%F", Z_DVAL_PP((zval
**)p
));
107 convert_to_string_ex(zparam
);
111 **params
= Z_STRVAL_PP(zparam
);
114 if (*zparam
!= *(zval
**)p
) {
115 zend_hash_next_index_insert(zdtor
, zparam
, sizeof(zval
*), NULL
);
120 return ZEND_HASH_APPLY_KEEP
;
123 int php_pq_types_to_array(HashTable
*ht
, Oid
**types TSRMLS_DC
)
125 int count
= zend_hash_num_elements(ht
);
132 /* +1 for when less types than params are specified */
133 *types
= tmp
= ecalloc(count
+ 1, sizeof(**types
));
134 zend_hash_apply_with_argument(ht
, apply_to_oid
, &tmp TSRMLS_CC
);
140 int php_pq_params_to_array(HashTable
*ht
, char ***params
, HashTable
*zdtor TSRMLS_DC
)
142 int count
= zend_hash_num_elements(ht
);
149 *params
= tmp
= ecalloc(count
, sizeof(char *));
150 zend_hash_apply_with_arguments(ht TSRMLS_CC
, apply_to_param
, 2, &tmp
, zdtor
);
157 Oid *php_pq_ntypes_to_array(zend_bool fill, int argc, ...)
160 Oid *oids = ecalloc(argc + 1, sizeof(*oids));
163 va_start(argv, argc);
164 for (i = 0; i < argc; ++i) {
166 oids[i] = va_arg(argv, Oid);
182 * vim600: noet sw=4 ts=4 fdm=marker
183 * vim<600: noet sw=4 ts=4