Lines Matching refs:dbh

38 static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value);
67 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
69 pdo_error_type *pdo_err = &dbh->error_code; in pdo_raise_impl_error()
73 if (dbh && dbh->error_mode == PDO_ERRMODE_SILENT) { in pdo_raise_impl_error()
100 if (dbh && dbh->error_mode != PDO_ERRMODE_EXCEPTION) { in pdo_raise_impl_error()
127 PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ in pdo_handle_error() argument
129 pdo_error_type *pdo_err = &dbh->error_code; in pdo_handle_error()
136 if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) { in pdo_handle_error()
151 if (dbh->methods->fetch_err) { in pdo_handle_error()
156 if (dbh->methods->fetch_err(dbh, stmt, &info)) { in pdo_handle_error()
175 if (dbh->error_mode == PDO_ERRMODE_WARNING) { in pdo_handle_error()
226 pdo_dbh_t *dbh = NULL; in PHP_METHOD() local
292 dbh = Z_PDO_DBH_P(object); in PHP_METHOD()
346 pdbh->def_stmt_ce = dbh->def_stmt_ce; in PHP_METHOD()
351 efree(dbh); in PHP_METHOD()
355 dbh = pdbh; in PHP_METHOD()
364 dbh->data_source_len = strlen(colon + 1); in PHP_METHOD()
365 dbh->data_source = (const char*)pestrdup(colon + 1, is_persistent); in PHP_METHOD()
366 dbh->username = username ? pestrdup(username, is_persistent) : NULL; in PHP_METHOD()
367 dbh->password = password ? pestrdup(password, is_persistent) : NULL; in PHP_METHOD()
368 dbh->default_fetch_type = PDO_FETCH_BOTH; in PHP_METHOD()
371 dbh->auto_commit = pdo_attr_lval(options, PDO_ATTR_AUTOCOMMIT, 1); in PHP_METHOD()
373 if (!dbh->data_source || (username && !dbh->username) || (password && !dbh->password)) { in PHP_METHOD()
384 if (driver->db_handle_factory(dbh, options)) { in PHP_METHOD()
392 (char*)dbh->persistent_id, dbh->persistent_id_len, dbh, php_pdo_list_entry())) == NULL) { in PHP_METHOD()
397 dbh->driver = driver; in PHP_METHOD()
409 pdo_dbh_attribute_set(dbh, long_key, attr_value); in PHP_METHOD()
426 static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry *dbstmt_ce, zval *… in pdo_stmt_instantiate() argument
430 pdo_raise_impl_error(dbh, NULL, "HY000", "constructor arguments must be passed as an array"); in pdo_stmt_instantiate()
434 …pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement does not accept constructor argu… in pdo_stmt_instantiate()
495 pdo_dbh_t *dbh = dbh_obj->inner; in PHP_METHOD() local
511 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
520 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
526 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
533 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
545 dbstmt_ce = dbh->def_stmt_ce; in PHP_METHOD()
546 ZVAL_COPY_VALUE(&ctor_args, &dbh->def_stmt_ctor_args); in PHP_METHOD()
549 if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, &ctor_args)) { in PHP_METHOD()
551 pdo_raise_impl_error(dbh, NULL, "HY000", in PHP_METHOD()
563 stmt->default_fetch_type = dbh->default_fetch_type; in PHP_METHOD()
564 stmt->dbh = dbh; in PHP_METHOD()
571 if (dbh->methods->preparer(dbh, statement, statement_len, stmt, options)) { in PHP_METHOD()
589 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
596 if (dbh->in_txn) { in PHP_METHOD()
601 if (!dbh->methods->begin) { in PHP_METHOD()
608 if (dbh->methods->begin(dbh)) { in PHP_METHOD()
609 dbh->in_txn = 1; in PHP_METHOD()
622 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
629 if (!dbh->in_txn) { in PHP_METHOD()
634 if (dbh->methods->commit(dbh)) { in PHP_METHOD()
635 dbh->in_txn = 0; in PHP_METHOD()
648 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
655 if (!dbh->in_txn) { in PHP_METHOD()
660 if (dbh->methods->rollback(dbh)) { in PHP_METHOD()
661 dbh->in_txn = 0; in PHP_METHOD()
674 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
681 if (!dbh->methods->in_transaction) { in PHP_METHOD()
682 RETURN_BOOL(dbh->in_txn); in PHP_METHOD()
685 RETURN_BOOL(dbh->methods->in_transaction(dbh)); in PHP_METHOD()
689 static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /* {{{ */ in pdo_dbh_attribute_set() argument
695 pdo_raise_impl_error(dbh, NULL, "HY000", "attribute value must be an integer"); \ in pdo_dbh_attribute_set()
708 dbh->error_mode = lval; in pdo_dbh_attribute_set()
711 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid error mode"); in pdo_dbh_attribute_set()
724 dbh->desired_case = lval; in pdo_dbh_attribute_set()
727 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid case folding mode"); in pdo_dbh_attribute_set()
735 dbh->oracle_nulls = zval_get_long(value); in pdo_dbh_attribute_set()
743 …pdo_raise_impl_error(dbh, NULL, "HY000", "FETCH_INTO and FETCH_CLASS are not yet supported as defa… in pdo_dbh_attribute_set()
752 pdo_raise_impl_error(dbh, NULL, "HY000", "invalid fetch mode type"); in pdo_dbh_attribute_set()
755 dbh->default_fetch_type = lval; in pdo_dbh_attribute_set()
760 dbh->stringify = zval_get_long(value) ? 1 : 0; in pdo_dbh_attribute_set()
768 if (dbh->is_persistent) { in pdo_dbh_attribute_set()
769 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
780 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
788 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
794 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
799 dbh->def_stmt_ce = pce; in pdo_dbh_attribute_set()
800 if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) { in pdo_dbh_attribute_set()
801 zval_ptr_dtor(&dbh->def_stmt_ctor_args); in pdo_dbh_attribute_set()
802 ZVAL_UNDEF(&dbh->def_stmt_ctor_args); in pdo_dbh_attribute_set()
806 pdo_raise_impl_error(dbh, NULL, "HY000", in pdo_dbh_attribute_set()
813 ZVAL_COPY(&dbh->def_stmt_ctor_args, item); in pdo_dbh_attribute_set()
822 if (!dbh->methods->set_attribute) { in pdo_dbh_attribute_set()
827 if (dbh->methods->set_attribute(dbh, attr, value)) { in pdo_dbh_attribute_set()
832 if (!dbh->methods->set_attribute) { in pdo_dbh_attribute_set()
833 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support setting attributes"); in pdo_dbh_attribute_set()
845 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
857 if (pdo_dbh_attribute_set(dbh, attr, value) != FAILURE) { in PHP_METHOD()
868 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
881 RETURN_BOOL(dbh->is_persistent); in PHP_METHOD()
884 RETURN_LONG(dbh->desired_case); in PHP_METHOD()
887 RETURN_LONG(dbh->oracle_nulls); in PHP_METHOD()
890 RETURN_LONG(dbh->error_mode); in PHP_METHOD()
893 RETURN_STRINGL((char*)dbh->driver->driver_name, dbh->driver->driver_name_len); in PHP_METHOD()
897 add_next_index_str(return_value, zend_string_copy(dbh->def_stmt_ce->name)); in PHP_METHOD()
898 if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) { in PHP_METHOD()
899 Z_TRY_ADDREF(dbh->def_stmt_ctor_args); in PHP_METHOD()
900 add_next_index_zval(return_value, &dbh->def_stmt_ctor_args); in PHP_METHOD()
904 RETURN_LONG(dbh->default_fetch_type); in PHP_METHOD()
909 if (!dbh->methods->get_attribute) { in PHP_METHOD()
910 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support getting attributes"); in PHP_METHOD()
914 switch (dbh->methods->get_attribute(dbh, attr, return_value)) { in PHP_METHOD()
920 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute"); in PHP_METHOD()
933 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
943 pdo_raise_impl_error(dbh, NULL, "HY000", "trying to execute an empty query"); in PHP_METHOD()
948 ret = dbh->methods->doer(dbh, statement, statement_len); in PHP_METHOD()
962 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
973 if (!dbh->methods->last_id) { in PHP_METHOD()
974 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support lastInsertId()"); in PHP_METHOD()
979 id = dbh->methods->last_id(dbh, name, &id_len); in PHP_METHOD()
996 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
1003 if (dbh->query_stmt) { in PHP_METHOD()
1004 RETURN_STRING(dbh->query_stmt->error_code); in PHP_METHOD()
1007 if (dbh->error_code[0] == '\0') { in PHP_METHOD()
1015 RETURN_STRING(dbh->error_code); in PHP_METHOD()
1027 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
1037 if (dbh->query_stmt) { in PHP_METHOD()
1038 add_next_index_string(return_value, dbh->query_stmt->error_code); in PHP_METHOD()
1039 if(!strncmp(dbh->query_stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array; in PHP_METHOD()
1041 add_next_index_string(return_value, dbh->error_code); in PHP_METHOD()
1042 if(!strncmp(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array; in PHP_METHOD()
1045 if (dbh->methods->fetch_err) { in PHP_METHOD()
1046 dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value); in PHP_METHOD()
1076 pdo_dbh_t *dbh = dbh_obj->inner; in PHP_METHOD() local
1092 if (!pdo_stmt_instantiate(dbh, return_value, dbh->def_stmt_ce, &dbh->def_stmt_ctor_args)) { in PHP_METHOD()
1094 pdo_raise_impl_error(dbh, NULL, "HY000", "failed to instantiate user supplied statement class"); in PHP_METHOD()
1104 stmt->default_fetch_type = dbh->default_fetch_type; in PHP_METHOD()
1107 stmt->dbh = dbh; in PHP_METHOD()
1114 if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL)) { in PHP_METHOD()
1123 if (stmt->dbh->alloc_own_columns) { in PHP_METHOD()
1129 … pdo_stmt_construct(execute_data, stmt, return_value, dbh->def_stmt_ce, &dbh->def_stmt_ctor_args); in PHP_METHOD()
1135 dbh->query_stmt = stmt; in PHP_METHOD()
1136 ZVAL_OBJ(&dbh->query_stmt_zval, Z_OBJ_P(return_value)); in PHP_METHOD()
1153 pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); in PHP_METHOD() local
1168 if (!dbh->methods->quoter) { in PHP_METHOD()
1169 pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support quoting"); in PHP_METHOD()
1173 if (dbh->methods->quoter(dbh, str, str_len, &qstr, &qlen, paramtype)) { in PHP_METHOD()
1285 pdo_dbh_t *dbh = dbh_obj->inner; in pdo_hash_methods() local
1287 if (!dbh || !dbh->methods || !dbh->methods->get_driver_methods) { in pdo_hash_methods()
1290 funcs = dbh->methods->get_driver_methods(dbh, kind); in pdo_hash_methods()
1295 dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent); in pdo_hash_methods()
1296 zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL, in pdo_hash_methods()
1297 dbh->is_persistent? cls_method_pdtor : cls_method_dtor, dbh->is_persistent, 0); in pdo_hash_methods()
1304 func.function_name = zend_string_init(funcs->fname, strlen(funcs->fname), dbh->is_persistent); in pdo_hash_methods()
1339 zend_hash_str_add_mem(dbh->cls_methods[kind], lc_name, namelen, &func, sizeof(func)); in pdo_hash_methods()
1380 pdo_dbh_t *dbh = Z_PDO_DBH_P(object); in dbh_get_gc() local
1381 *gc_data = &dbh->def_stmt_ctor_args; in dbh_get_gc()
1494 static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent) in dbh_free() argument
1498 if (dbh->query_stmt) { in dbh_free()
1499 zval_ptr_dtor(&dbh->query_stmt_zval); in dbh_free()
1500 dbh->query_stmt = NULL; in dbh_free()
1503 if (dbh->is_persistent) { in dbh_free()
1505 ZEND_ASSERT(!free_persistent || (dbh->refcount == 1)); in dbh_free()
1507 if (!free_persistent && (--dbh->refcount)) { in dbh_free()
1512 if (dbh->methods) { in dbh_free()
1513 dbh->methods->closer(dbh); in dbh_free()
1516 if (dbh->data_source) { in dbh_free()
1517 pefree((char *)dbh->data_source, dbh->is_persistent); in dbh_free()
1519 if (dbh->username) { in dbh_free()
1520 pefree(dbh->username, dbh->is_persistent); in dbh_free()
1522 if (dbh->password) { in dbh_free()
1523 pefree(dbh->password, dbh->is_persistent); in dbh_free()
1526 if (dbh->persistent_id) { in dbh_free()
1527 pefree((char *)dbh->persistent_id, dbh->is_persistent); in dbh_free()
1530 if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) { in dbh_free()
1531 zval_ptr_dtor(&dbh->def_stmt_ctor_args); in dbh_free()
1535 if (dbh->cls_methods[i]) { in dbh_free()
1536 zend_hash_destroy(dbh->cls_methods[i]); in dbh_free()
1537 pefree(dbh->cls_methods[i], dbh->is_persistent); in dbh_free()
1541 pefree(dbh, dbh->is_persistent); in dbh_free()
1546 pdo_dbh_t *dbh = php_pdo_dbh_fetch_inner(std); in pdo_dbh_free_storage() local
1547 if (dbh->in_txn && dbh->methods && dbh->methods->rollback) { in pdo_dbh_free_storage()
1548 dbh->methods->rollback(dbh); in pdo_dbh_free_storage()
1549 dbh->in_txn = 0; in pdo_dbh_free_storage()
1552 if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) { in pdo_dbh_free_storage()
1553 dbh->methods->persistent_shutdown(dbh); in pdo_dbh_free_storage()
1556 dbh_free(dbh, 0); in pdo_dbh_free_storage()
1561 pdo_dbh_object_t *dbh; in pdo_dbh_new() local
1563 dbh = zend_object_alloc(sizeof(pdo_dbh_object_t), ce); in pdo_dbh_new()
1564 zend_object_std_init(&dbh->std, ce); in pdo_dbh_new()
1565 object_properties_init(&dbh->std, ce); in pdo_dbh_new()
1566 rebuild_object_properties(&dbh->std); in pdo_dbh_new()
1567 dbh->inner = ecalloc(1, sizeof(pdo_dbh_t)); in pdo_dbh_new()
1568 dbh->inner->def_stmt_ce = pdo_dbstmt_ce; in pdo_dbh_new()
1570 dbh->std.handlers = &pdo_dbh_object_handlers; in pdo_dbh_new()
1572 return &dbh->std; in pdo_dbh_new()
1580 pdo_dbh_t *dbh = (pdo_dbh_t*)res->ptr; in ZEND_RSRC_DTOR_FUNC() local
1581 dbh_free(dbh, 1); in ZEND_RSRC_DTOR_FUNC()