Lines Matching refs:dbh
39 static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_DC);
41 void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *supp … in pdo_raise_impl_error() argument
43 pdo_error_type *pdo_err = &dbh->error_code; in pdo_raise_impl_error()
47 if (dbh && dbh->error_mode == PDO_ERRMODE_SILENT) { in pdo_raise_impl_error()
74 if (dbh && dbh->error_mode != PDO_ERRMODE_EXCEPTION) { in pdo_raise_impl_error()
104 PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ in pdo_handle_error() argument
106 pdo_error_type *pdo_err = &dbh->error_code; in pdo_handle_error()
113 if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) { in pdo_handle_error()
127 if (dbh->methods->fetch_err) { in pdo_handle_error()
133 if (dbh->methods->fetch_err(dbh, stmt, info TSRMLS_CC)) { in pdo_handle_error()
152 if (dbh->error_mode == PDO_ERRMODE_WARNING) { in pdo_handle_error()
204 pdo_dbh_t *dbh = NULL; in PHP_METHOD() local
273 dbh = (pdo_dbh_t *) zend_object_store_get_object(object TSRMLS_CC); in PHP_METHOD()
345 zend_hash_destroy(dbh->std.properties); in PHP_METHOD()
346 efree(dbh->std.properties); in PHP_METHOD()
347 if (dbh->std.properties_table) { in PHP_METHOD()
348 efree(dbh->std.properties_table); in PHP_METHOD()
351 pdbh->std.ce = dbh->std.ce; in PHP_METHOD()
352 pdbh->def_stmt_ce = dbh->def_stmt_ce; in PHP_METHOD()
353 pdbh->def_stmt_ctor_args = dbh->def_stmt_ctor_args; in PHP_METHOD()
354 pdbh->std.properties = dbh->std.properties; in PHP_METHOD()
355 pdbh->std.properties_table = dbh->std.properties_table; in PHP_METHOD()
358 efree(dbh); in PHP_METHOD()
360 dbh = pdbh; in PHP_METHOD()
361 zend_object_store_set_object(object, dbh TSRMLS_CC); in PHP_METHOD()
362 dbh->refcount++; in PHP_METHOD()
371 dbh->data_source_len = strlen(colon + 1); in PHP_METHOD()
372 dbh->data_source = (const char*)pestrdup(colon + 1, is_persistent); in PHP_METHOD()
373 dbh->username = username ? pestrdup(username, is_persistent) : NULL; in PHP_METHOD()
374 dbh->password = password ? pestrdup(password, is_persistent) : NULL; in PHP_METHOD()
375 dbh->default_fetch_type = PDO_FETCH_BOTH; in PHP_METHOD()
378 dbh->auto_commit = pdo_attr_lval(options, PDO_ATTR_AUTOCOMMIT, 1 TSRMLS_CC); in PHP_METHOD()
380 if (!dbh->data_source || (username && !dbh->username) || (password && !dbh->password)) { in PHP_METHOD()
389 if (driver->db_handle_factory(dbh, options TSRMLS_CC)) { in PHP_METHOD()
400 le.ptr = dbh; in PHP_METHOD()
403 (char*)dbh->persistent_id, dbh->persistent_id_len, (void*)&le, in PHP_METHOD()
409 dbh->driver = driver; in PHP_METHOD()
420 pdo_dbh_attribute_set(dbh, long_key, *attr_value TSRMLS_CC); in PHP_METHOD()
434 static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry *dbstmt_ce, zval *… in pdo_stmt_instantiate() argument
438 …pdo_raise_impl_error(dbh, NULL, "HY000", "constructor arguments must be passed as an array" TSRMLS… in pdo_stmt_instantiate()
442 …pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement does not accept constructor argu… in pdo_stmt_instantiate()
507 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
527 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
536 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
542 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
549 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
561 dbstmt_ce = dbh->def_stmt_ce; in PHP_METHOD()
562 ctor_args = dbh->def_stmt_ctor_args; in PHP_METHOD()
565 if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, ctor_args TSRMLS_CC)) { in PHP_METHOD()
566 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
577 stmt->default_fetch_type = dbh->default_fetch_type; in PHP_METHOD()
578 stmt->dbh = dbh; in PHP_METHOD()
581 php_pdo_dbh_addref(dbh TSRMLS_CC); in PHP_METHOD()
586 if (dbh->methods->preparer(dbh, statement, statement_len, stmt, options TSRMLS_CC)) { in PHP_METHOD()
604 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
611 if (dbh->in_txn) { in PHP_METHOD()
616 if (!dbh->methods->begin) { in PHP_METHOD()
623 if (dbh->methods->begin(dbh TSRMLS_CC)) { in PHP_METHOD()
624 dbh->in_txn = 1; in PHP_METHOD()
637 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
644 if (!dbh->in_txn) { in PHP_METHOD()
649 if (dbh->methods->commit(dbh TSRMLS_CC)) { in PHP_METHOD()
650 dbh->in_txn = 0; in PHP_METHOD()
663 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
670 if (!dbh->in_txn) { in PHP_METHOD()
675 if (dbh->methods->rollback(dbh TSRMLS_CC)) { in PHP_METHOD()
676 dbh->in_txn = 0; in PHP_METHOD()
689 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
696 if (!dbh->methods->in_transaction) { in PHP_METHOD()
697 RETURN_BOOL(dbh->in_txn); in PHP_METHOD()
700 RETURN_BOOL(dbh->methods->in_transaction(dbh TSRMLS_CC)); in PHP_METHOD()
704 static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_DC) /* {{{ */ in pdo_dbh_attribute_set() argument
709 pdo_raise_impl_error(dbh, NULL, "HY000", "attribute value must be an integer" TSRMLS_CC); \ in pdo_dbh_attribute_set()
722 dbh->error_mode = Z_LVAL_P(value); in pdo_dbh_attribute_set()
725 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid error mode" TSRMLS_CC); in pdo_dbh_attribute_set()
738 dbh->desired_case = Z_LVAL_P(value); in pdo_dbh_attribute_set()
741 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid case folding mode" TSRMLS_CC); in pdo_dbh_attribute_set()
750 dbh->oracle_nulls = Z_LVAL_P(value); in pdo_dbh_attribute_set()
758 …pdo_raise_impl_error(dbh, NULL, "HY000", "FETCH_INTO and FETCH_CLASS are not yet supported as defa… in pdo_dbh_attribute_set()
767 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid fetch mode type" TSRMLS_CC); in pdo_dbh_attribute_set()
770 dbh->default_fetch_type = Z_LVAL_P(value); in pdo_dbh_attribute_set()
776 dbh->stringify = Z_LVAL_P(value) ? 1 : 0; in pdo_dbh_attribute_set()
784 if (dbh->is_persistent) { in pdo_dbh_attribute_set()
785 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
796 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
804 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
810 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
815 dbh->def_stmt_ce = *pce; in pdo_dbh_attribute_set()
816 if (dbh->def_stmt_ctor_args) { in pdo_dbh_attribute_set()
817 zval_ptr_dtor(&dbh->def_stmt_ctor_args); in pdo_dbh_attribute_set()
818 dbh->def_stmt_ctor_args = NULL; in pdo_dbh_attribute_set()
822 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
830 dbh->def_stmt_ctor_args = *item; in pdo_dbh_attribute_set()
839 if (!dbh->methods->set_attribute) { in pdo_dbh_attribute_set()
844 if (dbh->methods->set_attribute(dbh, attr, value TSRMLS_CC)) { in pdo_dbh_attribute_set()
851 } else if (!dbh->methods->set_attribute) { in pdo_dbh_attribute_set()
852 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support setting attributes" TSRMLS_CC); in pdo_dbh_attribute_set()
864 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
875 if (pdo_dbh_attribute_set(dbh, attr, value TSRMLS_CC) != FAILURE) { in PHP_METHOD()
886 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
899 RETURN_BOOL(dbh->is_persistent); in PHP_METHOD()
902 RETURN_LONG(dbh->desired_case); in PHP_METHOD()
905 RETURN_LONG(dbh->oracle_nulls); in PHP_METHOD()
908 RETURN_LONG(dbh->error_mode); in PHP_METHOD()
911 RETURN_STRINGL((char*)dbh->driver->driver_name, dbh->driver->driver_name_len, 1); in PHP_METHOD()
915 add_next_index_string(return_value, dbh->def_stmt_ce->name, 1); in PHP_METHOD()
916 if (dbh->def_stmt_ctor_args) { in PHP_METHOD()
917 Z_ADDREF_P(dbh->def_stmt_ctor_args); in PHP_METHOD()
918 add_next_index_zval(return_value, dbh->def_stmt_ctor_args); in PHP_METHOD()
922 RETURN_LONG(dbh->default_fetch_type); in PHP_METHOD()
926 if (!dbh->methods->get_attribute) { in PHP_METHOD()
927 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support getting attributes" TSRMLS_CC); in PHP_METHOD()
931 switch (dbh->methods->get_attribute(dbh, attr, return_value TSRMLS_CC)) { in PHP_METHOD()
937 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute" TSRMLS_CC); in PHP_METHOD()
950 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
960 pdo_raise_impl_error(dbh, NULL, "HY000", "trying to execute an empty query" TSRMLS_CC); in PHP_METHOD()
965 ret = dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC); in PHP_METHOD()
980 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
990 if (!dbh->methods->last_id) { in PHP_METHOD()
991 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support lastInsertId()" TSRMLS_CC); in PHP_METHOD()
994 …Z_STRVAL_P(return_value) = dbh->methods->last_id(dbh, name, (unsigned int *)&Z_STRLEN_P(return_val… in PHP_METHOD()
1009 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
1016 if (dbh->query_stmt) { in PHP_METHOD()
1017 RETURN_STRING(dbh->query_stmt->error_code, 1); in PHP_METHOD()
1020 if (dbh->error_code[0] == '\0') { in PHP_METHOD()
1028 RETURN_STRING(dbh->error_code, 1); in PHP_METHOD()
1040 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
1050 if (dbh->query_stmt) { in PHP_METHOD()
1051 add_next_index_string(return_value, dbh->query_stmt->error_code, 1); in PHP_METHOD()
1052 if(!strncmp(dbh->query_stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array; in PHP_METHOD()
1054 add_next_index_string(return_value, dbh->error_code, 1); in PHP_METHOD()
1055 if(!strncmp(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array; in PHP_METHOD()
1058 if (dbh->methods->fetch_err) { in PHP_METHOD()
1059 dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value TSRMLS_CC); in PHP_METHOD()
1085 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
1104 …if (!pdo_stmt_instantiate(dbh, return_value, dbh->def_stmt_ce, dbh->def_stmt_ctor_args TSRMLS_CC))… in PHP_METHOD()
1105 …pdo_raise_impl_error(dbh, NULL, "HY000", "failed to instantiate user supplied statement class" TSR… in PHP_METHOD()
1114 stmt->default_fetch_type = dbh->default_fetch_type; in PHP_METHOD()
1117 stmt->dbh = dbh; in PHP_METHOD()
1120 php_pdo_dbh_addref(dbh TSRMLS_CC); in PHP_METHOD()
1125 if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL TSRMLS_CC)) { in PHP_METHOD()
1134 if (stmt->dbh->alloc_own_columns) { in PHP_METHOD()
1140 pdo_stmt_construct(stmt, return_value, dbh->def_stmt_ce, dbh->def_stmt_ctor_args TSRMLS_CC); in PHP_METHOD()
1146 dbh->query_stmt = stmt; in PHP_METHOD()
1147 dbh->query_stmt_zval = *return_value; in PHP_METHOD()
1162 pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); in PHP_METHOD() local
1175 if (!dbh->methods->quoter) { in PHP_METHOD()
1176 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support quoting" TSRMLS_CC); in PHP_METHOD()
1180 if (dbh->methods->quoter(dbh, str, str_len, &qstr, &qlen, paramtype TSRMLS_CC)) { in PHP_METHOD()
1286 int pdo_hash_methods(pdo_dbh_t *dbh, int kind TSRMLS_DC) in pdo_hash_methods() argument
1294 if (!dbh || !dbh->methods || !dbh->methods->get_driver_methods) { in pdo_hash_methods()
1297 funcs = dbh->methods->get_driver_methods(dbh, kind TSRMLS_CC); in pdo_hash_methods()
1302 if (!(dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent))) { in pdo_hash_methods()
1305 zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL, NULL, dbh->is_persistent, 0); in pdo_hash_methods()
1311 ifunc->scope = dbh->std.ce; in pdo_hash_methods()
1342 zend_hash_add(dbh->cls_methods[kind], lc_name, namelen+1, &func, sizeof(func), NULL); in pdo_hash_methods()
1357 pdo_dbh_t *dbh = zend_object_store_get_object(object TSRMLS_CC); in dbh_method_get() local
1365 if (!dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_DBH]) { in dbh_method_get()
1366 if (!pdo_hash_methods(dbh, in dbh_method_get()
1368 || !dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_DBH]) { in dbh_method_get()
1373 if (zend_hash_find(dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_DBH], in dbh_method_get()
1502 static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) in dbh_free()
1506 if (--dbh->refcount) in dbh_free()
1509 if (dbh->query_stmt) { in dbh_free()
1510 zval_dtor(&dbh->query_stmt_zval); in dbh_free()
1511 dbh->query_stmt = NULL; in dbh_free()
1514 if (dbh->methods) { in dbh_free()
1515 dbh->methods->closer(dbh TSRMLS_CC); in dbh_free()
1518 if (dbh->data_source) { in dbh_free()
1519 pefree((char *)dbh->data_source, dbh->is_persistent); in dbh_free()
1521 if (dbh->username) { in dbh_free()
1522 pefree(dbh->username, dbh->is_persistent); in dbh_free()
1524 if (dbh->password) { in dbh_free()
1525 pefree(dbh->password, dbh->is_persistent); in dbh_free()
1528 if (dbh->persistent_id) { in dbh_free()
1529 pefree((char *)dbh->persistent_id, dbh->is_persistent); in dbh_free()
1532 if (dbh->def_stmt_ctor_args) { in dbh_free()
1533 zval_ptr_dtor(&dbh->def_stmt_ctor_args); in dbh_free()
1537 if (dbh->cls_methods[i]) { in dbh_free()
1538 zend_hash_destroy(dbh->cls_methods[i]); in dbh_free()
1539 pefree(dbh->cls_methods[i], dbh->is_persistent); in dbh_free()
1543 pefree(dbh, dbh->is_persistent); in dbh_free()
1546 PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC) in php_pdo_dbh_addref()
1548 dbh->refcount++; in php_pdo_dbh_addref()
1551 PDO_API void php_pdo_dbh_delref(pdo_dbh_t *dbh TSRMLS_DC) in php_pdo_dbh_delref()
1553 dbh_free(dbh TSRMLS_CC); in php_pdo_dbh_delref()
1556 static void pdo_dbh_free_storage(pdo_dbh_t *dbh TSRMLS_DC) in pdo_dbh_free_storage()
1558 if (dbh->in_txn && dbh->methods && dbh->methods->rollback) { in pdo_dbh_free_storage()
1559 dbh->methods->rollback(dbh TSRMLS_CC); in pdo_dbh_free_storage()
1560 dbh->in_txn = 0; in pdo_dbh_free_storage()
1563 if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) { in pdo_dbh_free_storage()
1564 dbh->methods->persistent_shutdown(dbh TSRMLS_CC); in pdo_dbh_free_storage()
1566 zend_object_std_dtor(&dbh->std TSRMLS_CC); in pdo_dbh_free_storage()
1567 dbh->std.properties = NULL; in pdo_dbh_free_storage()
1568 dbh->std.properties_table = NULL; in pdo_dbh_free_storage()
1569 dbh_free(dbh TSRMLS_CC); in pdo_dbh_free_storage()
1575 pdo_dbh_t *dbh; in pdo_dbh_new() local
1577 dbh = emalloc(sizeof(*dbh)); in pdo_dbh_new()
1578 memset(dbh, 0, sizeof(*dbh)); in pdo_dbh_new()
1579 zend_object_std_init(&dbh->std, ce TSRMLS_CC); in pdo_dbh_new()
1580 object_properties_init(&dbh->std, ce); in pdo_dbh_new()
1581 rebuild_object_properties(&dbh->std); in pdo_dbh_new()
1582 dbh->refcount = 1; in pdo_dbh_new()
1583 dbh->def_stmt_ce = pdo_dbstmt_ce; in pdo_dbh_new()
1585 …retval.handle = zend_objects_store_put(dbh, (zend_objects_store_dtor_t)zend_objects_destroy_object… in pdo_dbh_new()
1596 pdo_dbh_t *dbh = (pdo_dbh_t*)rsrc->ptr; in ZEND_RSRC_DTOR_FUNC() local
1597 dbh_free(dbh TSRMLS_CC); in ZEND_RSRC_DTOR_FUNC()