return;
#endif
}
-
+
if (stmt) {
pdo_err = &stmt->error_code;
}
zend_update_property_string(def_ex, ex, "message", sizeof("message")-1, message TSRMLS_CC);
zend_update_property_string(def_ex, ex, "code", sizeof("code")-1, *pdo_err TSRMLS_CC);
-
+
MAKE_STD_ZVAL(info);
array_init(info);
zend_throw_exception_object(ex TSRMLS_CC);
}
-
+
if (message) {
efree(message);
}
if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) {
return;
}
-
+
if (stmt) {
pdo_err = &stmt->error_code;
}
array_init(info);
add_next_index_string(info, *pdo_err, 1);
-
+
if (dbh->methods->fetch_err(dbh, stmt, info TSRMLS_CC)) {
zval **item;
if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(info), 1, (void**)&item)) {
native_code = Z_LVAL_PP(item);
}
-
+
if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(info), 2, (void**)&item)) {
supp = estrndup(Z_STRVAL_PP(item), Z_STRLEN_PP(item));
}
zend_update_property_string(def_ex, ex, "message", sizeof("message")-1, message TSRMLS_CC);
zend_update_property_string(def_ex, ex, "code", sizeof("code")-1, *pdo_err TSRMLS_CC);
-
+
if (info) {
zend_update_property(pdo_ex, ex, "errorInfo", sizeof("errorInfo")-1, info TSRMLS_CC);
}
data_source = ini_dsn;
colon = strchr(data_source, ':');
-
+
if (!colon) {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "invalid data source name (via INI: %s)", alt_dsn);
ZVAL_NULL(object);
ZVAL_NULL(object);
return;
}
-
+
dbh = (pdo_dbh_t *) zend_object_store_get_object(object TSRMLS_CC);
/* is this supposed to be a persistent connection ? */
if (pdbh) {
/* let's copy the emalloc bits over from the other handle */
if (pdbh->std.properties) {
- zend_hash_destroy(dbh->std.properties);
+ zend_hash_destroy(dbh->std.properties);
efree(dbh->std.properties);
if (dbh->std.properties_table) {
efree(dbh->std.properties_table);
efree(hashkey);
}
}
-
+
if (call_factory) {
dbh->data_source_len = strlen(colon + 1);
dbh->data_source = (const char*)pestrdup(colon + 1, is_persistent);
dbh->username = username ? pestrdup(username, is_persistent) : NULL;
dbh->password = password ? pestrdup(password, is_persistent) : NULL;
dbh->default_fetch_type = PDO_FETCH_BOTH;
- }
+ }
dbh->auto_commit = pdo_attr_lval(options, PDO_ATTR_AUTOCOMMIT, 1 TSRMLS_CC);
zval **attr_value;
char *str_key;
ulong long_key;
-
+
zend_hash_internal_pointer_reset(Z_ARRVAL_P(options));
- while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(options), (void**)&attr_value)
+ while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(options), (void**)&attr_value)
&& HASH_KEY_IS_LONG == zend_hash_get_current_key(Z_ARRVAL_P(options), &str_key, &long_key, 0)) {
-
+
pdo_dbh_attribute_set(dbh, long_key, *attr_value TSRMLS_CC);
zend_hash_move_forward(Z_ARRVAL_P(options));
}
object_init_ex(object, dbstmt_ce);
Z_SET_REFCOUNT_P(object, 1);
Z_SET_ISREF_P(object);
-
+
return object;
} /* }}} */
static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry *dbstmt_ce, zval *ctor_args TSRMLS_DC) /* {{{ */
-{
+{
zval *query_string;
zval z_key;
} else if (retval) {
zval_ptr_dtor(&retval);
}
-
+
if (fci.params) {
efree(fci.params);
}
&statement_len, &options)) {
RETURN_FALSE;
}
-
+
PDO_DBH_CLEAR_ERR();
PDO_CONSTRUCT_CHECK;
|| Z_TYPE_PP(item) != IS_STRING
|| zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), &pce TSRMLS_CC) == FAILURE
) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
"the classname must be a string specifying an existing class"
TSRMLS_CC);
}
dbstmt_ce = *pce;
if (!instanceof_function(dbstmt_ce, pdo_dbstmt_ce TSRMLS_CC)) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"user-supplied statement class must be derived from PDOStatement" TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
if (dbstmt_ce->constructor && !(dbstmt_ce->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"user-supplied statement class cannot have a public constructor" TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
if (zend_hash_index_find(Z_ARRVAL_PP(opt), 1, (void**)&item) == SUCCESS) {
if (Z_TYPE_PP(item) != IS_ARRAY) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); "
"ctor_args must be an array"
TSRMLS_CC);
}
if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, ctor_args TSRMLS_CC)) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"failed to instantiate user-supplied statement class"
TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
stmt = (pdo_stmt_t*)zend_object_store_get_object(return_value TSRMLS_CC);
-
+
/* unconditionally keep this for later reference */
stmt->query_string = estrndup(statement, statement_len);
stmt->query_stringlen = statement_len;
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "There is already an active transaction");
RETURN_FALSE;
}
-
+
if (!dbh->methods->begin) {
/* TODO: this should be an exception; see the auto-commit mode
* comments below */
dbh->in_txn = 0;
RETURN_TRUE;
}
-
+
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
dbh->in_txn = 0;
RETURN_TRUE;
}
-
+
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
if (!dbh->methods->in_transaction) {
RETURN_BOOL(dbh->in_txn);
- }
+ }
RETURN_BOOL(dbh->methods->in_transaction(dbh TSRMLS_CC));
}
convert_to_long(value);
dbh->stringify = Z_LVAL_P(value) ? 1 : 0;
return SUCCESS;
-
+
case PDO_ATTR_STATEMENT_CLASS: {
/* array(string classname, array(mixed ctor_args)) */
zend_class_entry **pce;
zval **item;
if (dbh->is_persistent) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances"
TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
|| Z_TYPE_PP(item) != IS_STRING
|| zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), &pce TSRMLS_CC) == FAILURE
) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
"the classname must be a string specifying an existing class"
TSRMLS_CC);
return FAILURE;
}
if (!instanceof_function(*pce, pdo_dbstmt_ce TSRMLS_CC)) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"user-supplied statement class must be derived from PDOStatement" TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
return FAILURE;
}
if ((*pce)->constructor && !((*pce)->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"user-supplied statement class cannot have a public constructor" TSRMLS_CC);
PDO_HANDLE_DBH_ERR();
return FAILURE;
}
if (zend_hash_index_find(Z_ARRVAL_P(value), 1, (void**)&item) == SUCCESS) {
if (Z_TYPE_PP(item) != IS_ARRAY) {
- pdo_raise_impl_error(dbh, NULL, "HY000",
+ pdo_raise_impl_error(dbh, NULL, "HY000",
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
"ctor_args must be an array"
TSRMLS_CC);
}
return SUCCESS;
}
-
+
default:
;
}
return FAILURE;
}
/* }}} */
-
+
/* {{{ proto bool PDO::setAttribute(long attribute, mixed value)
Set an attribute */
static PHP_METHOD(PDO, setAttribute)
switch (attr) {
case PDO_ATTR_PERSISTENT:
RETURN_BOOL(dbh->is_persistent);
-
+
case PDO_ATTR_CASE:
RETURN_LONG(dbh->desired_case);
RETURN_LONG(dbh->default_fetch_type);
}
-
+
if (!dbh->methods->get_attribute) {
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support getting attributes" TSRMLS_CC);
RETURN_FALSE;
if (dbh->query_stmt) {
RETURN_STRING(dbh->query_stmt->error_code, 1);
}
-
+
if (dbh->error_code[0] == '\0') {
RETURN_NULL();
}
if (dbh->query_stmt) {
add_next_index_string(return_value, dbh->query_stmt->error_code, 1);
+ if(!strncmp(dbh->query_stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array;
} else {
add_next_index_string(return_value, dbh->error_code, 1);
+ if(!strncmp(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array;
}
if (dbh->methods->fetch_err) {
dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value TSRMLS_CC);
}
-
+
+fill_array:
/**
* In order to be consistent, we have to make sure we add the good amount
* of nulls depending on the current number of elements. We make a simple
zend_parse_parameters(0 TSRMLS_CC, "z|z", NULL, NULL);
RETURN_FALSE;
}
-
+
if (FAILURE == zend_parse_parameters(1 TSRMLS_CC, "s", &statement,
&statement_len)) {
RETURN_FALSE;
}
-
+
PDO_DBH_CLEAR_ERR();
PDO_CONSTRUCT_CHECK;
return;
}
stmt = (pdo_stmt_t*)zend_object_store_get_object(return_value TSRMLS_CC);
-
+
/* unconditionally keep this for later reference */
stmt->query_string = estrndup(statement, statement_len);
stmt->query_stringlen = statement_len;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, ¶mtype)) {
RETURN_FALSE;
}
-
+
PDO_DBH_CLEAR_ERR();
PDO_CONSTRUCT_CHECK;
if (!dbh->methods->quoter) {
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
+
array_init(return_value);
zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos);
memcpy(&pdo_dbh_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
pdo_dbh_object_handlers.get_method = dbh_method_get;
pdo_dbh_object_handlers.compare_objects = dbh_compare;
-
+
REGISTER_PDO_CLASS_CONST_LONG("PARAM_BOOL", (long)PDO_PARAM_BOOL);
REGISTER_PDO_CLASS_CONST_LONG("PARAM_NULL", (long)PDO_PARAM_NULL);
REGISTER_PDO_CLASS_CONST_LONG("PARAM_INT", (long)PDO_PARAM_INT);
REGISTER_PDO_CLASS_CONST_LONG("ATTR_MAX_COLUMN_LEN",(long)PDO_ATTR_MAX_COLUMN_LEN);
REGISTER_PDO_CLASS_CONST_LONG("ATTR_EMULATE_PREPARES",(long)PDO_ATTR_EMULATE_PREPARES);
REGISTER_PDO_CLASS_CONST_LONG("ATTR_DEFAULT_FETCH_MODE",(long)PDO_ATTR_DEFAULT_FETCH_MODE);
-
+
REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT);
REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING);
REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_EXCEPTION", (long)PDO_ERRMODE_EXCEPTION);
REGISTER_PDO_CLASS_CONST_LONG("NULL_NATURAL", (long)PDO_NULL_NATURAL);
REGISTER_PDO_CLASS_CONST_LONG("NULL_EMPTY_STRING", (long)PDO_NULL_EMPTY_STRING);
REGISTER_PDO_CLASS_CONST_LONG("NULL_TO_STRING", (long)PDO_NULL_TO_STRING);
-
+
REGISTER_PDO_CLASS_CONST_STRING("ERR_NONE", PDO_ERR_NONE);
REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_NEXT", (long)PDO_FETCH_ORI_NEXT);
REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_LAST", (long)PDO_FETCH_ORI_LAST);
REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_ABS", (long)PDO_FETCH_ORI_ABS);
REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_REL", (long)PDO_FETCH_ORI_REL);
-
+
REGISTER_PDO_CLASS_CONST_LONG("CURSOR_FWDONLY", (long)PDO_CURSOR_FWDONLY);
REGISTER_PDO_CLASS_CONST_LONG("CURSOR_SCROLL", (long)PDO_CURSOR_SCROLL);
if (dbh->password) {
pefree(dbh->password, dbh->is_persistent);
}
-
+
if (dbh->persistent_id) {
pefree((char *)dbh->persistent_id, dbh->is_persistent);
}
if (dbh->def_stmt_ctor_args) {
zval_ptr_dtor(&dbh->def_stmt_ctor_args);
}
-
+
for (i = 0; i < PDO_DBH_DRIVER_METHOD_KIND__MAX; i++) {
if (dbh->cls_methods[i]) {
zend_hash_destroy(dbh->cls_methods[i]);
dbh->methods->rollback(dbh TSRMLS_CC);
dbh->in_txn = 0;
}
-
+
if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) {
dbh->methods->persistent_shutdown(dbh TSRMLS_CC);
}
rebuild_object_properties(&dbh->std);
dbh->refcount = 1;
dbh->def_stmt_ce = pdo_dbstmt_ce;
-
+
retval.handle = zend_objects_store_put(dbh, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbh_free_storage, NULL TSRMLS_CC);
retval.handlers = &pdo_dbh_object_handlers;
-
+
return retval;
}