refactor auto conversion
[m6w6/ext-pq] / src / php_pqres.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: pq |
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 +--------------------------------------------------------------------+
11 */
12
13
14 #ifndef PHP_PQRES_H
15 #define PHP_PQRES_H
16
17 #include "php_pqconn.h"
18
19 typedef enum php_pqres_fetch {
20 PHP_PQRES_FETCH_ARRAY,
21 PHP_PQRES_FETCH_ASSOC,
22 PHP_PQRES_FETCH_OBJECT
23 } php_pqres_fetch_t;
24
25 #define PHP_PQRES_CONV_BOOL 0x01
26 #define PHP_PQRES_CONV_INT 0x02
27 #define PHP_PQRES_CONV_FLOAT 0x04
28 #define PHP_PQRES_CONV_SCALAR 0x0f
29 #define PHP_PQRES_CONV_ARRAY 0x10
30 #define PHP_PQRES_CONV_DATETIME 0x20
31 #define PHP_PQRES_CONV_ALL 0xff
32
33 typedef struct php_pqres_iterator {
34 zend_object_iterator zi;
35 zval *current_val;
36 unsigned index;
37 php_pqres_fetch_t fetch_type;
38 } php_pqres_iterator_t;
39
40 typedef struct php_pqres {
41 PGresult *res;
42 php_pqres_iterator_t *iter;
43 HashTable bound;
44 HashTable converters;
45 unsigned auto_convert;
46 php_pqres_fetch_t default_fetch_type;
47 } php_pqres_t;
48
49 typedef struct php_pqres_object {
50 zend_object zo;
51 zend_object_value zv;
52 HashTable *prophandler;
53 php_pqres_t *intern;
54 } php_pqres_object_t;
55
56 STATUS php_pqres_success(PGresult *res TSRMLS_DC);
57 void php_pqres_init_instance_data(PGresult *res, php_pqconn_object_t *obj, php_pqres_object_t **ptr TSRMLS_DC);
58 zval *php_pqres_row_to_zval(PGresult *res, unsigned row, php_pqres_fetch_t fetch_type, zval **data_ptr TSRMLS_DC);
59 zval *php_pqres_typed_zval(php_pqres_t *res, char *val, size_t len, Oid typ TSRMLS_DC);
60
61 #include "php_pq_object.h"
62 #include "php_pqconn_event.h"
63 #define PHP_PQclear(_r) do { \
64 php_pqres_object_t *_o = PQresultInstanceData((_r), php_pqconn_event); \
65 if (_o) { \
66 php_pq_object_delref(_o TSRMLS_CC); \
67 } else { \
68 PQclear(_r); \
69 } \
70 } while(0)
71
72 zend_class_entry *php_pqres_class_entry;
73 zend_object_value php_pqres_create_object_ex(zend_class_entry *ce, php_pqres_t *intern, php_pqres_object_t **ptr TSRMLS_DC);
74
75 PHP_MINIT_FUNCTION(pqres);
76 PHP_MSHUTDOWN_FUNCTION(pqres);
77
78 #endif
79
80 /*
81 * Local variables:
82 * tab-width: 4
83 * c-basic-offset: 4
84 * End:
85 * vim600: noet sw=4 ts=4 fdm=marker
86 * vim<600: noet sw=4 ts=4
87 */