0f74b2b65ef7aaa238179663588abaedf640d0d1
[m6w6/ext-pq] / src / php_pqstm.c
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 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #include <php.h>
18 #include <ext/standard/php_smart_str.h>
19
20 #include "php_pq.h"
21 #include "php_pq_misc.h"
22 #include "php_pq_object.h"
23 #include "php_pqexc.h"
24 #include "php_pqconn.h"
25 #include "php_pqres.h"
26 #include "php_pqstm.h"
27
28 zend_class_entry *php_pqstm_class_entry;
29 static zend_object_handlers php_pqstm_object_handlers;
30 static HashTable php_pqstm_object_prophandlers;
31
32 static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_bool silent TSRMLS_DC)
33 {
34 if (obj->intern->allocated) {
35 char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
36
37 if (quoted_name) {
38 smart_str cmd = {0};
39
40 smart_str_appends(&cmd, "DEALLOCATE ");
41 smart_str_appends(&cmd, quoted_name);
42 smart_str_0(&cmd);
43
44 if (async) {
45 if (PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
46 obj->intern->conn->intern->poller = PQconsumeInput;
47 php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
48 } else if (!silent) {
49 throw_exce(EX_IO TSRMLS_CC, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
50 }
51 } else {
52 PGresult *res;
53
54 if ((res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c))) {
55 php_pqres_clear(res);
56 } else if (!silent) {
57 throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
58 }
59 }
60
61 PQfreemem(quoted_name);
62 smart_str_free(&cmd);
63 }
64
65 obj->intern->allocated = 0;
66 zend_hash_del(&obj->intern->conn->intern->statements, obj->intern->name, strlen(obj->intern->name)+1);
67 }
68 }
69
70 static void php_pqstm_object_free(void *o TSRMLS_DC)
71 {
72 php_pqstm_object_t *obj = o;
73 #if DBG_GC
74 fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
75 #endif
76 if (obj->intern) {
77 if (obj->intern->conn->intern) {
78 php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
79 php_pqstm_deallocate(obj, 0, 1 TSRMLS_CC);
80 php_pq_object_delref(obj->intern->conn TSRMLS_CC);
81 }
82 efree(obj->intern->name);
83 efree(obj->intern->query);
84 zend_hash_destroy(&obj->intern->bound);
85 if (obj->intern->params) {
86 php_pq_params_free(&obj->intern->params);
87 }
88 efree(obj->intern);
89 obj->intern = NULL;
90 }
91 zend_object_std_dtor((zend_object *) o TSRMLS_CC);
92 efree(obj);
93 }
94
95 zend_object_value php_pqstm_create_object_ex(zend_class_entry *ce, php_pqstm_t *intern, php_pqstm_object_t **ptr TSRMLS_DC)
96 {
97 php_pqstm_object_t *o;
98
99 o = ecalloc(1, sizeof(*o));
100 zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
101 object_properties_init((zend_object *) o, ce);
102 o->prophandler = &php_pqstm_object_prophandlers;
103
104 if (ptr) {
105 *ptr = o;
106 }
107
108 if (intern) {
109 o->intern = intern;
110 }
111
112 o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqstm_object_free, NULL TSRMLS_CC);
113 o->zv.handlers = &php_pqstm_object_handlers;
114
115 return o->zv;
116 }
117
118 static zend_object_value php_pqstm_create_object(zend_class_entry *class_type TSRMLS_DC)
119 {
120 return php_pqstm_create_object_ex(class_type, NULL, NULL TSRMLS_CC);
121 }
122
123 static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value TSRMLS_DC)
124 {
125 php_pqstm_object_t *obj = o;
126
127 RETVAL_STRING(obj->intern->name, 1);
128 }
129
130 static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value TSRMLS_DC)
131 {
132 php_pqstm_object_t *obj = o;
133
134 php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC);
135 }
136
137 static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value TSRMLS_DC)
138 {
139 php_pqstm_object_t *obj = o;
140
141 RETVAL_STRING(obj->intern->query, 1);
142 }
143
144 static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value TSRMLS_DC)
145 {
146 int i;
147 php_pqstm_object_t *obj = o;
148
149 array_init_size(return_value, obj->intern->params->type.count);
150 for (i = 0; i < obj->intern->params->type.count; i++) {
151 add_next_index_long(return_value, (long)obj->intern->params->type.oids[i]);
152 }
153 }
154
155 php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
156 {
157 php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
158
159 php_pq_object_addref(conn TSRMLS_CC);
160 stm->conn = conn;
161 stm->name = estrdup(name);
162 stm->params = params;
163 stm->query = estrdup(query);
164 stm->allocated = 1;
165
166 ZEND_INIT_SYMTABLE(&stm->bound);
167
168 zend_hash_add(&conn->intern->statements, name, strlen(name)+1, &stm, sizeof(stm), NULL);
169
170 return stm;
171 }
172
173 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_construct, 0, 0, 3)
174 ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0)
175 ZEND_ARG_INFO(0, name)
176 ZEND_ARG_INFO(0, query)
177 ZEND_ARG_ARRAY_INFO(0, types, 1)
178 ZEND_ARG_INFO(0, async)
179 ZEND_END_ARG_INFO();
180 static PHP_METHOD(pqstm, __construct) {
181 zend_error_handling zeh;
182 zval *zconn, *ztypes = NULL;
183 char *name_str, *query_str;
184 int name_len, *query_len;
185 zend_bool async = 0;
186 ZEND_RESULT_CODE rv;
187
188 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
189 rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async);
190 zend_restore_error_handling(&zeh TSRMLS_CC);
191
192 if (SUCCESS == rv) {
193 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
194 php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
195
196 if (obj->intern) {
197 throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Statement already initialized");
198 } else if (!conn_obj->intern) {
199 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
200 } else {
201 php_pq_params_t *params = php_pq_params_init(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC);
202
203 if (async) {
204 rv = php_pqconn_prepare_async(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
205 } else {
206 rv = php_pqconn_prepare(zconn, conn_obj, name_str, query_str, params TSRMLS_CC);
207 }
208
209 if (SUCCESS == rv) {
210 obj->intern = php_pqstm_init(conn_obj, name_str, query_str, params TSRMLS_CC);
211 }
212 }
213 }
214 }
215 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_bind, 0, 0, 2)
216 ZEND_ARG_INFO(0, param_no)
217 ZEND_ARG_INFO(1, param_ref)
218 ZEND_END_ARG_INFO();
219 static PHP_METHOD(pqstm, bind) {
220 long param_no;
221 zval **param_ref;
222 zend_error_handling zeh;
223 ZEND_RESULT_CODE rv;
224
225 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
226 rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", &param_no, &param_ref);
227 zend_restore_error_handling(&zeh TSRMLS_CC);
228
229 if (SUCCESS == rv) {
230 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
231
232 if (!obj->intern) {
233 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
234 } else if (!obj->intern->allocated) {
235 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
236 } else {
237 SEPARATE_ZVAL_TO_MAKE_IS_REF(param_ref);
238 Z_ADDREF_PP(param_ref);
239 zend_hash_index_update(&obj->intern->bound, param_no, (void *) param_ref, sizeof(zval *), NULL);
240 zend_hash_sort(&obj->intern->bound, zend_qsort, php_pq_compare_index, 0 TSRMLS_CC);
241 }
242 }
243 }
244
245 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_exec, 0, 0, 0)
246 ZEND_ARG_ARRAY_INFO(0, params, 1)
247 ZEND_END_ARG_INFO();
248 static PHP_METHOD(pqstm, exec) {
249 zend_error_handling zeh;
250 zval *zparams = NULL;
251 ZEND_RESULT_CODE rv;
252
253 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
254 rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &zparams);
255 zend_restore_error_handling(&zeh TSRMLS_CC);
256
257 if (SUCCESS == rv) {
258 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
259
260 if (!obj->intern) {
261 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
262 } else if (!obj->intern->allocated) {
263 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
264 } else {
265 PGresult *res;
266
267 php_pq_params_set_params(obj->intern->params, zparams ? Z_ARRVAL_P(zparams) : &obj->intern->bound);
268 res = php_pq_exec_prepared(obj->intern->conn->intern->conn, obj->intern->name, obj->intern->params->param.count, (const char *const*) obj->intern->params->param.strings, NULL, NULL, 0);
269 php_pq_params_set_params(obj->intern->params, NULL);
270
271 if (!res) {
272 throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
273 } else if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
274 php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
275 php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
276 }
277 }
278 }
279 }
280
281 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_exec_async, 0, 0, 0)
282 ZEND_ARG_ARRAY_INFO(0, params, 1)
283 ZEND_ARG_INFO(0, callable)
284 ZEND_END_ARG_INFO();
285 static PHP_METHOD(pqstm, execAsync) {
286 zend_error_handling zeh;
287 zval *zparams = NULL;
288 php_pq_callback_t resolver = {{0}};
289 ZEND_RESULT_CODE rv;
290
291 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
292 rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
293 zend_restore_error_handling(&zeh TSRMLS_CC);
294
295 if (SUCCESS == rv) {
296 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
297
298 if (!obj->intern) {
299 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
300 } else if (!obj->intern->allocated) {
301 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
302 } else {
303 int rc;
304
305 php_pq_params_set_params(obj->intern->params, zparams ? Z_ARRVAL_P(zparams) : &obj->intern->bound);
306 rc = PQsendQueryPrepared(obj->intern->conn->intern->conn, obj->intern->name, obj->intern->params->param.count, (const char *const*) obj->intern->params->param.strings, NULL, NULL, 0);
307 php_pq_params_set_params(obj->intern->params, NULL);
308
309 if (!rc) {
310 throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
311 #if HAVE_PQSETSINGLEROWMODE
312 } else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
313 throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
314 #endif
315 } else {
316 php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
317 obj->intern->conn->intern->poller = PQconsumeInput;
318 }
319
320 php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
321 }
322 }
323 }
324
325 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc, 0, 0, 0)
326 ZEND_END_ARG_INFO();
327 static PHP_METHOD(pqstm, desc) {
328 zend_error_handling zeh;
329 ZEND_RESULT_CODE rv;
330
331 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
332 rv = zend_parse_parameters_none();
333 zend_restore_error_handling(&zeh TSRMLS_CC);
334
335 if (SUCCESS == rv) {
336 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
337
338 if (!obj->intern) {
339 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
340 } else if (!obj->intern->allocated) {
341 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
342 } else {
343 PGresult *res = PQdescribePrepared(obj->intern->conn->intern->conn, obj->intern->name);
344
345 if (!res) {
346 throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
347 } else {
348 if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
349 int p, params;
350
351 array_init(return_value);
352 for (p = 0, params = PQnparams(res); p < params; ++p) {
353 add_next_index_long(return_value, PQparamtype(res, p));
354 }
355 }
356 php_pqres_clear(res);
357 php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
358 }
359 }
360 }
361 }
362
363 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 1)
364 ZEND_ARG_INFO(0, callable)
365 ZEND_END_ARG_INFO();
366 static PHP_METHOD(pqstm, descAsync) {
367 zend_error_handling zeh;
368 php_pq_callback_t resolver = {{0}};
369 ZEND_RESULT_CODE rv;
370
371 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
372 rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &resolver.fci, &resolver.fcc);
373 zend_restore_error_handling(&zeh TSRMLS_CC);
374
375 if (SUCCESS == rv) {
376 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
377
378 if (!obj->intern) {
379 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
380 } else if (!obj->intern->allocated) {
381 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement has been deallocated");
382 } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
383 throw_exce(EX_IO TSRMLS_CC, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
384 } else {
385 php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
386 obj->intern->conn->intern->poller = PQconsumeInput;
387 php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
388 }
389 }
390 }
391
392 static zend_always_inline void php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PARAMETERS, zend_bool async)
393 {
394 zend_error_handling zeh;
395 ZEND_RESULT_CODE rv;
396
397 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
398 rv = zend_parse_parameters_none();
399 zend_restore_error_handling(&zeh TSRMLS_CC);
400
401 if (rv == SUCCESS) {
402 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
403
404 if (!obj->intern) {
405 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
406 } else {
407 php_pqstm_deallocate(obj, async, 0 TSRMLS_CC);
408 }
409 }
410 }
411
412 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_deallocate, 0, 0, 0)
413 ZEND_END_ARG_INFO();
414 static PHP_METHOD(pqstm, deallocate)
415 {
416 php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
417 }
418
419 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_deallocate_async, 0, 0, 0)
420 ZEND_END_ARG_INFO();
421 static PHP_METHOD(pqstm, deallocateAsync)
422 {
423 php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
424 }
425
426 static inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAMETERS, zend_bool async)
427 {
428 zend_error_handling zeh;
429 ZEND_RESULT_CODE rv;
430
431 zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
432 rv = zend_parse_parameters_none();
433 zend_restore_error_handling(&zeh TSRMLS_CC);
434
435 if (rv == SUCCESS) {
436 php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
437
438 if (!obj->intern) {
439 throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
440 } else if (!obj->intern->allocated) {
441 if (async) {
442 rv = php_pqconn_prepare_async(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
443 } else {
444 rv = php_pqconn_prepare(NULL, obj->intern->conn, obj->intern->name, obj->intern->query, obj->intern->params TSRMLS_CC);
445 }
446
447 if (SUCCESS == rv) {
448 obj->intern->allocated = 1;
449
450 zend_hash_add(&obj->intern->conn->intern->statements,
451 obj->intern->name, strlen(obj->intern->name)+1, &obj, sizeof(obj), NULL);
452 }
453 }
454 }
455 }
456
457 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_prepare, 0, 0, 0)
458 ZEND_END_ARG_INFO();
459 static PHP_METHOD(pqstm, prepare)
460 {
461 php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
462 }
463
464 ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_prepare_async, 0, 0, 0)
465 ZEND_END_ARG_INFO();
466 static PHP_METHOD(pqstm, prepareAsync)
467 {
468 php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
469 }
470
471 static zend_function_entry php_pqstm_methods[] = {
472 PHP_ME(pqstm, __construct, ai_pqstm_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
473 PHP_ME(pqstm, bind, ai_pqstm_bind, ZEND_ACC_PUBLIC)
474 PHP_ME(pqstm, deallocate, ai_pqstm_deallocate, ZEND_ACC_PUBLIC)
475 PHP_ME(pqstm, deallocateAsync, ai_pqstm_deallocate_async, ZEND_ACC_PUBLIC)
476 PHP_ME(pqstm, desc, ai_pqstm_desc, ZEND_ACC_PUBLIC)
477 PHP_ME(pqstm, descAsync, ai_pqstm_desc_async, ZEND_ACC_PUBLIC)
478 PHP_ME(pqstm, exec, ai_pqstm_exec, ZEND_ACC_PUBLIC)
479 PHP_ME(pqstm, execAsync, ai_pqstm_exec_async, ZEND_ACC_PUBLIC)
480 PHP_ME(pqstm, prepare, ai_pqstm_prepare, ZEND_ACC_PUBLIC)
481 PHP_ME(pqstm, prepareAsync, ai_pqstm_prepare_async, ZEND_ACC_PUBLIC)
482 {0}
483 };
484
485 PHP_MSHUTDOWN_FUNCTION(pqstm)
486 {
487 zend_hash_destroy(&php_pqstm_object_prophandlers);
488 return SUCCESS;
489 }
490
491 PHP_MINIT_FUNCTION(pqstm)
492 {
493 zend_class_entry ce = {0};
494 php_pq_object_prophandler_t ph = {0};
495
496 INIT_NS_CLASS_ENTRY(ce, "pq", "Statement", php_pqstm_methods);
497 php_pqstm_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
498 php_pqstm_class_entry->create_object = php_pqstm_create_object;
499
500 memcpy(&php_pqstm_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
501 php_pqstm_object_handlers.read_property = php_pq_object_read_prop;
502 php_pqstm_object_handlers.write_property = php_pq_object_write_prop;
503 php_pqstm_object_handlers.clone_obj = NULL;
504 php_pqstm_object_handlers.get_property_ptr_ptr = NULL;
505 php_pqstm_object_handlers.get_gc = NULL;
506 php_pqstm_object_handlers.get_properties = php_pq_object_properties;
507 php_pqstm_object_handlers.get_debug_info = php_pq_object_debug_info;
508
509 zend_hash_init(&php_pqstm_object_prophandlers, 2, NULL, NULL, 1);
510
511 zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
512 ph.read = php_pqstm_object_read_name;
513 zend_hash_add(&php_pqstm_object_prophandlers, "name", sizeof("name"), (void *) &ph, sizeof(ph), NULL);
514
515 zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("connection"), ZEND_ACC_PUBLIC TSRMLS_CC);
516 ph.read = php_pqstm_object_read_connection;
517 zend_hash_add(&php_pqstm_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
518
519 zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
520 ph.read = php_pqstm_object_read_query;
521 zend_hash_add(&php_pqstm_object_prophandlers, "query", sizeof("query"), (void *) &ph, sizeof(ph), NULL);
522
523 zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC TSRMLS_CC);
524 ph.read = php_pqstm_object_read_types;
525 zend_hash_add(&php_pqstm_object_prophandlers, "types", sizeof("types"), (void *) &ph, sizeof(ph), NULL);
526
527 return SUCCESS;
528 }
529
530 /*
531 * Local variables:
532 * tab-width: 4
533 * c-basic-offset: 4
534 * End:
535 * vim600: noet sw=4 ts=4 fdm=marker
536 * vim<600: noet sw=4 ts=4
537 */