summaryrefslogtreecommitdiff
path: root/ext/pdo/php_pdo_driver.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo/php_pdo_driver.h')
-rw-r--r--ext/pdo/php_pdo_driver.h151
1 files changed, 90 insertions, 61 deletions
diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h
index ede2d6fb76..de9780e226 100644
--- a/ext/pdo/php_pdo_driver.h
+++ b/ext/pdo/php_pdo_driver.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -24,8 +24,10 @@
#include "php_pdo.h"
/* forward declarations */
-typedef struct _pdo_dbh_t pdo_dbh_t;
-typedef struct _pdo_stmt_t pdo_stmt_t;
+typedef struct _pdo_dbh_t pdo_dbh_t;
+typedef struct _pdo_dbh_object_t pdo_dbh_object_t;
+typedef struct _pdo_stmt_t pdo_stmt_t;
+typedef struct _pdo_row_t pdo_row_t;
struct pdo_bound_param_data;
#ifdef PHP_WIN32
@@ -192,23 +194,23 @@ enum pdo_null_handling {
};
/* {{{ utils for reading attributes set as driver_options */
-static inline long pdo_attr_lval(zval *options, enum pdo_attribute_type option_name, long defval TSRMLS_DC)
+static inline zend_long pdo_attr_lval(zval *options, enum pdo_attribute_type option_name, zend_long defval TSRMLS_DC)
{
- zval **v;
+ zval *v;
- if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
+ if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
convert_to_long_ex(v);
- return Z_LVAL_PP(v);
+ return Z_LVAL_P(v);
}
return defval;
}
static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type option_name, char *defval TSRMLS_DC)
{
- zval **v;
+ zval *v;
- if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
+ if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
convert_to_string_ex(v);
- return estrndup(Z_STRVAL_PP(v), Z_STRLEN_PP(v));
+ return estrndup(Z_STRVAL_P(v), Z_STRLEN_P(v));
}
return defval ? estrdup(defval) : NULL;
}
@@ -218,8 +220,8 @@ static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type optio
* initialized */
typedef struct {
const char *driver_name;
- unsigned long driver_name_len;
- unsigned long api_version; /* needs to be compatible with PDO */
+ zend_ulong driver_name_len;
+ zend_ulong api_version; /* needs to be compatible with PDO */
#define PDO_DRIVER_HEADER(name) \
#name, sizeof(#name)-1, \
@@ -242,10 +244,10 @@ typedef struct {
typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh TSRMLS_DC);
/* prepare a statement and stash driver specific portion into stmt */
-typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC);
+typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC);
/* execute a statement (that does not return a result set) */
-typedef long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC);
+typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, zend_long sql_len TSRMLS_DC);
/* quote a string */
typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC);
@@ -254,7 +256,7 @@ typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unqu
typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh TSRMLS_DC);
/* setting of attributes */
-typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
+typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val TSRMLS_DC);
/* return last insert id. NULL indicates error condition, otherwise, the return value
* MUST be an emalloc'd NULL terminated string. */
@@ -269,7 +271,7 @@ typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, unsigned
typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC);
/* fetching of attributes */
-typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
+typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val TSRMLS_DC);
/* checking/pinging persistent connections; return SUCCESS if the connection
* is still alive and ready to be used, FAILURE otherwise.
@@ -327,7 +329,7 @@ typedef int (*pdo_stmt_execute_func)(pdo_stmt_t *stmt TSRMLS_DC);
* more rows. The ori and offset params modify which row should be returned,
* if the stmt represents a scrollable cursor */
typedef int (*pdo_stmt_fetch_func)(pdo_stmt_t *stmt,
- enum pdo_fetch_orientation ori, long offset TSRMLS_DC);
+ enum pdo_fetch_orientation ori, zend_long offset TSRMLS_DC);
/* queries information about the type of a column, by index (0 based).
* Driver should populate stmt->columns[colno] with appropriate info */
@@ -339,7 +341,7 @@ typedef int (*pdo_stmt_describe_col_func)(pdo_stmt_t *stmt, int colno TSRMLS_DC)
* If the driver sets caller_frees, ptr should point to emalloc'd memory
* and PDO will free it as soon as it is done using it.
*/
-typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC);
+typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees TSRMLS_DC);
/* hook for bound params */
enum pdo_param_event {
@@ -355,10 +357,10 @@ enum pdo_param_event {
typedef int (*pdo_stmt_param_hook_func)(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type TSRMLS_DC);
/* setting of attributes */
-typedef int (*pdo_stmt_set_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC);
+typedef int (*pdo_stmt_set_attr_func)(pdo_stmt_t *stmt, zend_long attr, zval *val TSRMLS_DC);
/* fetching of attributes */
-typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC);
+typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, zend_long attr, zval *val TSRMLS_DC);
/* retrieves meta data for a numbered column.
* Returns SUCCESS/FAILURE.
@@ -388,7 +390,7 @@ typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSR
* or
* 'flags' => array('not_null', 'mysql:some_flag'); // to add data to an existing key
*/
-typedef int (*pdo_stmt_get_column_meta_func)(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC);
+typedef int (*pdo_stmt_get_column_meta_func)(pdo_stmt_t *stmt, zend_long colno, zval *return_value TSRMLS_DC);
/* advances the statement to the next rowset of the batch.
* If it returns 1, PDO will tear down its idea of columns
@@ -424,15 +426,7 @@ enum pdo_placeholder_support {
PDO_PLACEHOLDER_POSITIONAL=2
};
-/* represents a connection to a database */
struct _pdo_dbh_t {
- /* these items must appear in this order at the beginning of the
- struct so that this can be cast as a zend_object. we need this
- to allow the extending class to escape all the custom handlers
- that PDO declares.
- */
- zend_object std;
-
/* driver specific methods */
struct pdo_dbh_methods *methods;
/* driver specific data */
@@ -475,7 +469,7 @@ struct _pdo_dbh_t {
/* data source string used to open this handle */
const char *data_source;
- unsigned long data_source_len;
+ zend_ulong data_source_len;
/* the global error code. */
pdo_error_type error_code;
@@ -496,7 +490,7 @@ struct _pdo_dbh_t {
zend_class_entry *def_stmt_ce;
- zval *def_stmt_ctor_args;
+ zval def_stmt_ctor_args;
/* when calling PDO::query(), we need to keep the error
* context from the statement around until we next clear it.
@@ -509,13 +503,35 @@ struct _pdo_dbh_t {
enum pdo_fetch_type default_fetch_type;
};
+/* represents a connection to a database */
+struct _pdo_dbh_object_t {
+ pdo_dbh_t *inner;
+ /* these items must appear in this order at the beginning of the
+ struct so that this can be cast as a zend_object. we need this
+ to allow the extending class to escape all the custom handlers
+ that PDO declares.
+ */
+ zend_object std;
+};
+
+static inline pdo_dbh_t *php_pdo_dbh_fetch_inner(zend_object *obj) {
+ return (pdo_dbh_t *)(((pdo_dbh_object_t *)((char*)(obj) - XtOffsetOf(pdo_dbh_object_t, std)))->inner);
+}
+
+static inline pdo_dbh_object_t *php_pdo_dbh_fetch_object(zend_object *obj) {
+ return (pdo_dbh_object_t *)((char*)(obj) - XtOffsetOf(pdo_dbh_object_t, std));
+}
+
+#define Z_PDO_DBH_P(zv) php_pdo_dbh_fetch_inner(Z_OBJ_P((zv)))
+#define Z_PDO_OBJECT_P(zv) php_pdo_dbh_fetch_object(Z_OBJ_P((zv)))
+
/* describes a column */
struct pdo_column_data {
char *name;
- int namelen;
- unsigned long maxlen;
+ zend_ulong maxlen;
+ zend_ulong precision;
enum pdo_param_type param_type;
- unsigned long precision;
+ int namelen;
/* don't touch this unless your name is dbdo */
void *dbdo_data;
@@ -523,31 +539,26 @@ struct pdo_column_data {
/* describes a bound parameter */
struct pdo_bound_param_data {
- long paramno; /* if -1, then it has a name, and we don't know the index *yet* */
- char *name;
- int namelen;
+ zval parameter; /* the variable itself */
- long max_value_len; /* as a hint for pre-allocation */
-
- zval *parameter; /* the variable itself */
- enum pdo_param_type param_type; /* desired or suggested type */
+ zval driver_params; /* optional parameter(s) for the driver */
+
+ zend_long paramno; /* if -1, then it has a name, and we don't know the index *yet* */
+ zend_string *name;
+
+ zend_long max_value_len; /* as a hint for pre-allocation */
- zval *driver_params; /* optional parameter(s) for the driver */
void *driver_data;
pdo_stmt_t *stmt; /* for convenience in dtor */
+
+ enum pdo_param_type param_type; /* desired or suggested variable type */
+
int is_param; /* parameter or column ? */
};
/* represents a prepared statement */
struct _pdo_stmt_t {
- /* these items must appear in this order at the beginning of the
- struct so that this can be cast as a zend_object. we need this
- to allow the extending class to escape all the custom handlers
- that PDO declares.
- */
- zend_object std;
-
/* driver specifics */
struct pdo_stmt_methods *methods;
void *driver_data;
@@ -583,7 +594,7 @@ struct _pdo_stmt_t {
HashTable *bound_columns;
/* not always meaningful */
- long row_count;
+ zend_long row_count;
/* used to hold the statement's current query */
char *query_string;
@@ -599,33 +610,51 @@ struct _pdo_stmt_t {
/* for lazy fetches, we always return the same lazy object handle.
* Let's keep it here. */
zval lazy_object_ref;
- unsigned long refcount;
+ zend_ulong refcount;
/* defaults for fetches */
enum pdo_fetch_type default_fetch_type;
union {
int column;
struct {
- zend_class_entry *ce;
- zval *ctor_args; /* freed */
- zval *retval_ptr;
+ zval ctor_args; /* freed */
zend_fcall_info fci;
zend_fcall_info_cache fcc;
+ zval retval;
+ zend_class_entry *ce;
} cls;
struct {
- zval *function;
- zval *fetch_args; /* freed */
- zval *object;
+ zval fetch_args; /* freed */
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval **values; /* freed */
+ zval object;
+ zval function;
+ zval *values; /* freed */
} func;
- zval *into;
+ zval into;
} fetch;
/* used by the query parser for driver specific
* parameter naming (see pgsql driver for example) */
const char *named_rewrite_template;
+
+ /* these items must appear in this order at the beginning of the
+ struct so that this can be cast as a zend_object. we need this
+ to allow the extending class to escape all the custom handlers
+ that PDO declares.
+ */
+ zend_object std;
+};
+
+static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
+ return (pdo_stmt_t *)((char*)(obj) - XtOffsetOf(pdo_stmt_t, std));
+}
+
+#define Z_PDO_STMT_P(zv) php_pdo_stmt_fetch_object(Z_OBJ_P((zv)))
+
+struct _pdo_row_t {
+ zend_object std;
+ pdo_stmt_t *stmt;
};
/* call this in MINIT to register your PDO driver */
@@ -643,7 +672,7 @@ struct pdo_data_src_parser {
};
PDO_API int php_pdo_parse_data_source(const char *data_source,
- unsigned long data_source_len, struct pdo_data_src_parser *parsed,
+ zend_ulong data_source_len, struct pdo_data_src_parser *parsed,
int nparams);
PDO_API zend_class_entry *php_pdo_get_dbh_ce(void);