PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/pdo - php_pdo_driver.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 16 16 100.0 %
Date: 2014-10-22 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2014 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Wez Furlong <wez@php.net>                                    |
      16             :   +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifndef PHP_PDO_DRIVER_H
      22             : #define PHP_PDO_DRIVER_H
      23             : 
      24             : #include "php_pdo.h"
      25             : 
      26             : /* forward declarations */
      27             : typedef struct _pdo_dbh_t                pdo_dbh_t;
      28             : typedef struct _pdo_dbh_object_t pdo_dbh_object_t;
      29             : typedef struct _pdo_stmt_t               pdo_stmt_t;
      30             : typedef struct _pdo_row_t                pdo_row_t;
      31             : struct pdo_bound_param_data;
      32             : 
      33             : #ifdef PHP_WIN32
      34             : typedef __int64 pdo_int64_t;
      35             : typedef unsigned __int64 pdo_uint64_t;
      36             : #else
      37             : typedef long long int pdo_int64_t;
      38             : typedef unsigned long long int pdo_uint64_t;
      39             : #endif
      40             : PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
      41             : 
      42             : #ifndef TRUE
      43             : # define TRUE 1
      44             : #endif
      45             : #ifndef FALSE
      46             : # define FALSE 0
      47             : #endif
      48             : 
      49             : #define PDO_DRIVER_API  20080721
      50             : 
      51             : enum pdo_param_type {
      52             :         PDO_PARAM_NULL,
      53             : 
      54             :         /* int as in long (the php native int type).
      55             :          * If you mark a column as an int, PDO expects get_col to return
      56             :          * a pointer to a long */
      57             :         PDO_PARAM_INT,
      58             : 
      59             :         /* get_col ptr should point to start of the string buffer */
      60             :         PDO_PARAM_STR,
      61             : 
      62             :         /* get_col: when len is 0 ptr should point to a php_stream *,
      63             :          * otherwise it should behave like a string. Indicate a NULL field
      64             :          * value by setting the ptr to NULL */
      65             :         PDO_PARAM_LOB,
      66             : 
      67             :         /* get_col: will expect the ptr to point to a new PDOStatement object handle,
      68             :          * but this isn't wired up yet */
      69             :         PDO_PARAM_STMT, /* hierarchical result set */
      70             : 
      71             :         /* get_col ptr should point to a zend_bool */
      72             :         PDO_PARAM_BOOL,
      73             : 
      74             :         /* get_col ptr should point to a zval*
      75             :            and the driver is responsible for adding correct type information to get_column_meta()
      76             :          */
      77             :         PDO_PARAM_ZVAL,
      78             : 
      79             :         /* magic flag to denote a parameter as being input/output */
      80             :         PDO_PARAM_INPUT_OUTPUT = 0x80000000
      81             : };
      82             : 
      83             : #define PDO_PARAM_FLAGS                 0xFFFF0000
      84             : 
      85             : #define PDO_PARAM_TYPE(x)               ((x) & ~PDO_PARAM_FLAGS)
      86             : 
      87             : enum pdo_fetch_type {
      88             :         PDO_FETCH_USE_DEFAULT,
      89             :         PDO_FETCH_LAZY,
      90             :         PDO_FETCH_ASSOC,
      91             :         PDO_FETCH_NUM,
      92             :         PDO_FETCH_BOTH,
      93             :         PDO_FETCH_OBJ,
      94             :         PDO_FETCH_BOUND, /* return true/false only; rely on bound columns */
      95             :         PDO_FETCH_COLUMN,       /* fetch a numbered column only */
      96             :         PDO_FETCH_CLASS,        /* create an instance of named class, call ctor and set properties */
      97             :         PDO_FETCH_INTO,         /* fetch row into an existing object */
      98             :         PDO_FETCH_FUNC,         /* fetch into function and return its result */
      99             :         PDO_FETCH_NAMED,    /* like PDO_FETCH_ASSOC, but can handle duplicate names */
     100             :         PDO_FETCH_KEY_PAIR,     /* fetch into an array where the 1st column is a key and all subsequent columns are values */
     101             :         PDO_FETCH__MAX /* must be last */
     102             : };
     103             : 
     104             : #define PDO_FETCH_FLAGS     0xFFFF0000  /* fetchAll() modes or'd to PDO_FETCH_XYZ */
     105             : #define PDO_FETCH_GROUP     0x00010000  /* fetch into groups */
     106             : #define PDO_FETCH_UNIQUE    0x00030000  /* fetch into groups assuming first col is unique */
     107             : #define PDO_FETCH_CLASSTYPE 0x00040000  /* fetch class gets its class name from 1st column */
     108             : #define PDO_FETCH_SERIALIZE 0x00080000  /* fetch class instances by calling serialize */
     109             : #define PDO_FETCH_PROPS_LATE 0x00100000  /* fetch props after calling ctor */
     110             : 
     111             : /* fetch orientation for scrollable cursors */
     112             : enum pdo_fetch_orientation {
     113             :         PDO_FETCH_ORI_NEXT,             /* default: fetch the next available row */
     114             :         PDO_FETCH_ORI_PRIOR,    /* scroll back to prior row and fetch that */
     115             :         PDO_FETCH_ORI_FIRST,    /* scroll to the first row and fetch that */
     116             :         PDO_FETCH_ORI_LAST,             /* scroll to the last row and fetch that */
     117             :         PDO_FETCH_ORI_ABS,              /* scroll to an absolute numbered row and fetch that */
     118             :         PDO_FETCH_ORI_REL               /* scroll relative to the current row, and fetch that */
     119             : };
     120             : 
     121             : enum pdo_attribute_type {
     122             :         PDO_ATTR_AUTOCOMMIT,    /* use to turn on or off auto-commit mode */
     123             :         PDO_ATTR_PREFETCH,              /* configure the prefetch size for drivers that support it. Size is in KB */
     124             :         PDO_ATTR_TIMEOUT,               /* connection timeout in seconds */
     125             :         PDO_ATTR_ERRMODE,               /* control how errors are handled */
     126             :         PDO_ATTR_SERVER_VERSION,        /* database server version */
     127             :         PDO_ATTR_CLIENT_VERSION,        /* client library version */
     128             :         PDO_ATTR_SERVER_INFO,           /* server information */
     129             :         PDO_ATTR_CONNECTION_STATUS,     /* connection status */
     130             :         PDO_ATTR_CASE,                          /* control case folding for portability */
     131             :         PDO_ATTR_CURSOR_NAME,           /* name a cursor for use in "WHERE CURRENT OF <name>" */
     132             :         PDO_ATTR_CURSOR,                        /* cursor type */
     133             :         PDO_ATTR_ORACLE_NULLS,          /* convert empty strings to NULL */
     134             :         PDO_ATTR_PERSISTENT,            /* pconnect style connection */
     135             :         PDO_ATTR_STATEMENT_CLASS,       /* array(classname, array(ctor_args)) to specify the class of the constructed statement */
     136             :         PDO_ATTR_FETCH_TABLE_NAMES, /* include table names in the column names, where available */
     137             :         PDO_ATTR_FETCH_CATALOG_NAMES, /* include the catalog/db name names in the column names, where available */
     138             :         PDO_ATTR_DRIVER_NAME,             /* name of the driver (as used in the constructor) */
     139             :         PDO_ATTR_STRINGIFY_FETCHES,     /* converts integer/float types to strings during fetch */
     140             :         PDO_ATTR_MAX_COLUMN_LEN,        /* make database calculate maximum length of data found in a column */
     141             :         PDO_ATTR_DEFAULT_FETCH_MODE, /* Set the default fetch mode */
     142             :         PDO_ATTR_EMULATE_PREPARES,  /* use query emulation rather than native */
     143             : 
     144             :         /* this defines the start of the range for driver specific options.
     145             :          * Drivers should define their own attribute constants beginning with this
     146             :          * value. */
     147             :         PDO_ATTR_DRIVER_SPECIFIC = 1000
     148             : };
     149             : 
     150             : enum pdo_cursor_type {
     151             :         PDO_CURSOR_FWDONLY,             /* forward only cursor (default) */
     152             :         PDO_CURSOR_SCROLL               /* scrollable cursor */
     153             : };
     154             : 
     155             : /* SQL-92 SQLSTATE error codes.
     156             : 
     157             : The character string value returned for an SQLSTATE consists of a two-character
     158             : class value followed by a three-character subclass value. A class value of 01
     159             : indicates a warning and is accompanied by a return code of
     160             : SQL_SUCCESS_WITH_INFO.
     161             : 
     162             : Class values other than '01', except for the class 'IM',
     163             : indicate an error and are accompanied by a return code of SQL_ERROR. The class
     164             : 'IM' is specific to warnings and errors that derive from the implementation of
     165             : ODBC itself.
     166             : 
     167             : The subclass value '000' in any class indicates that there is no
     168             : subclass for that SQLSTATE. The assignment of class and subclass values is
     169             : defined by SQL-92.
     170             : */
     171             : 
     172             : typedef char pdo_error_type[6]; /* SQLSTATE */
     173             : 
     174             : 
     175             : #define PDO_ERR_NONE                            "00000"
     176             : 
     177             : enum pdo_error_mode {
     178             :         PDO_ERRMODE_SILENT,             /* just set error codes */
     179             :         PDO_ERRMODE_WARNING,    /* raise E_WARNING */
     180             :         PDO_ERRMODE_EXCEPTION   /* throw exceptions */
     181             : };
     182             : 
     183             : enum pdo_case_conversion {
     184             :         PDO_CASE_NATURAL,
     185             :         PDO_CASE_UPPER,
     186             :         PDO_CASE_LOWER
     187             : };
     188             : 
     189             : /* oracle interop settings */
     190             : enum pdo_null_handling {
     191             :         PDO_NULL_NATURAL = 0,
     192             :         PDO_NULL_EMPTY_STRING = 1,
     193             :         PDO_NULL_TO_STRING = 2
     194             : };
     195             : 
     196             : /* {{{ utils for reading attributes set as driver_options */
     197        2815 : static inline zend_long pdo_attr_lval(zval *options, enum pdo_attribute_type option_name, zend_long defval TSRMLS_DC)
     198             : {
     199             :         zval *v;
     200             : 
     201        2815 :         if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
     202          36 :                 convert_to_long_ex(v);
     203          36 :                 return Z_LVAL_P(v);
     204             :         }
     205        2779 :         return defval;
     206             : }
     207         203 : static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type option_name, char *defval TSRMLS_DC)
     208             : {
     209             :         zval *v;
     210             : 
     211         203 :         if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
     212           4 :                 convert_to_string_ex(v);
     213           4 :                 return estrndup(Z_STRVAL_P(v), Z_STRLEN_P(v));
     214             :         }
     215         199 :         return defval ? estrdup(defval) : NULL;
     216             : }
     217             : /* }}} */
     218             : 
     219             : /* This structure is registered with PDO when a PDO driver extension is
     220             :  * initialized */
     221             : typedef struct {
     222             :         const char              *driver_name;
     223             :         zend_ulong      driver_name_len;
     224             :         zend_ulong      api_version; /* needs to be compatible with PDO */
     225             : 
     226             : #define PDO_DRIVER_HEADER(name) \
     227             :         #name, sizeof(#name)-1, \
     228             :         PDO_DRIVER_API
     229             :         
     230             :         /* create driver specific portion of the database handle and stash it into
     231             :          * the dbh.  dbh contains the data source string and flags for this
     232             :          * instance.  You MUST respect dbh->is_persistent and pass that flag to
     233             :          * pemalloc() for all allocations that are stored in the dbh or your instance
     234             :          * data in the db, otherwise you will crash PHP when persistent connections
     235             :          * are used.
     236             :          */
     237             :         int (*db_handle_factory)(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC);
     238             : 
     239             : } pdo_driver_t;
     240             : 
     241             : /* {{{ methods for a database handle */
     242             : 
     243             : /* close or otherwise disconnect the database */
     244             : typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh TSRMLS_DC);
     245             : 
     246             : /* prepare a statement and stash driver specific portion into stmt */
     247             : 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);
     248             : 
     249             : /* execute a statement (that does not return a result set) */
     250             : typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, zend_long sql_len TSRMLS_DC);
     251             : 
     252             : /* quote a string */
     253             : 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             : 
     255             : /* transaction related */
     256             : typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh TSRMLS_DC);
     257             : 
     258             : /* setting of attributes */
     259             : typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val TSRMLS_DC);
     260             : 
     261             : /* return last insert id.  NULL indicates error condition, otherwise, the return value
     262             :  * MUST be an emalloc'd NULL terminated string. */
     263             : typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC);
     264             : 
     265             : /* fetch error information.  if stmt is not null, fetch information pertaining
     266             :  * to the statement, otherwise fetch global error information.  The driver
     267             :  * should add the following information to the array "info" in this order:
     268             :  * - native error code
     269             :  * - string representation of the error code ... any other optional driver
     270             :  *   specific data ...  */
     271             : typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC);
     272             : 
     273             : /* fetching of attributes */
     274             : typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val TSRMLS_DC);
     275             : 
     276             : /* checking/pinging persistent connections; return SUCCESS if the connection
     277             :  * is still alive and ready to be used, FAILURE otherwise.
     278             :  * You may set this handler to NULL, which is equivalent to returning SUCCESS. */
     279             : typedef int (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh TSRMLS_DC);
     280             : 
     281             : /* called at request end for each persistent dbh; this gives the driver
     282             :  * the opportunity to safely release resources that only have per-request
     283             :  * scope */
     284             : typedef void (*pdo_dbh_request_shutdown)(pdo_dbh_t *dbh TSRMLS_DC);
     285             : 
     286             : /* for adding methods to the dbh or stmt objects 
     287             : pointer to a list of driver specific functions. The convention is
     288             : to prefix the function names using the PDO driver name; this will
     289             : reduce the chance of collisions with future functionality in the
     290             : PDO class or in user code (they can extend the PDO object).
     291             : */
     292             : enum {
     293             :         PDO_DBH_DRIVER_METHOD_KIND_DBH = 0,
     294             :         PDO_DBH_DRIVER_METHOD_KIND_STMT,
     295             :         PDO_DBH_DRIVER_METHOD_KIND__MAX
     296             : };
     297             : 
     298             : typedef const zend_function_entry *(*pdo_dbh_get_driver_methods_func)(pdo_dbh_t *dbh, int kind TSRMLS_DC);
     299             : 
     300             : struct pdo_dbh_methods {
     301             :         pdo_dbh_close_func              closer;
     302             :         pdo_dbh_prepare_func    preparer;
     303             :         pdo_dbh_do_func                 doer;
     304             :         pdo_dbh_quote_func              quoter;
     305             :         pdo_dbh_txn_func                begin;
     306             :         pdo_dbh_txn_func                commit;
     307             :         pdo_dbh_txn_func                rollback;
     308             :         pdo_dbh_set_attr_func   set_attribute;
     309             :         pdo_dbh_last_id_func            last_id;
     310             :         pdo_dbh_fetch_error_func        fetch_err;
     311             :         pdo_dbh_get_attr_func           get_attribute;
     312             :         pdo_dbh_check_liveness_func     check_liveness;
     313             :         pdo_dbh_get_driver_methods_func get_driver_methods;
     314             :         pdo_dbh_request_shutdown        persistent_shutdown;
     315             :         pdo_dbh_txn_func                in_transaction;
     316             : };
     317             : 
     318             : /* }}} */
     319             : 
     320             : /* {{{ methods for a statement handle */
     321             : 
     322             : /* free the statement handle */
     323             : typedef int (*pdo_stmt_dtor_func)(pdo_stmt_t *stmt TSRMLS_DC);
     324             : 
     325             : /* start the query */
     326             : typedef int (*pdo_stmt_execute_func)(pdo_stmt_t *stmt TSRMLS_DC);
     327             : 
     328             : /* causes the next row in the set to be fetched; indicates if there are no
     329             :  * more rows.  The ori and offset params modify which row should be returned,
     330             :  * if the stmt represents a scrollable cursor */
     331             : typedef int (*pdo_stmt_fetch_func)(pdo_stmt_t *stmt, 
     332             :         enum pdo_fetch_orientation ori, zend_long offset TSRMLS_DC);
     333             : 
     334             : /* queries information about the type of a column, by index (0 based).
     335             :  * Driver should populate stmt->columns[colno] with appropriate info */
     336             : typedef int (*pdo_stmt_describe_col_func)(pdo_stmt_t *stmt, int colno TSRMLS_DC);
     337             : 
     338             : /* retrieves pointer and size of the value for a column.
     339             :  * Note that PDO expects the driver to manage the lifetime of this data;
     340             :  * it will copy the value into a zval on behalf of the script.
     341             :  * If the driver sets caller_frees, ptr should point to emalloc'd memory
     342             :  * and PDO will free it as soon as it is done using it.
     343             :  */
     344             : typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees TSRMLS_DC);
     345             : 
     346             : /* hook for bound params */
     347             : enum pdo_param_event {
     348             :         PDO_PARAM_EVT_ALLOC,
     349             :         PDO_PARAM_EVT_FREE,
     350             :         PDO_PARAM_EVT_EXEC_PRE,
     351             :         PDO_PARAM_EVT_EXEC_POST,
     352             :         PDO_PARAM_EVT_FETCH_PRE,
     353             :         PDO_PARAM_EVT_FETCH_POST,
     354             :         PDO_PARAM_EVT_NORMALIZE
     355             : };
     356             : 
     357             : 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);
     358             : 
     359             : /* setting of attributes */
     360             : typedef int (*pdo_stmt_set_attr_func)(pdo_stmt_t *stmt, zend_long attr, zval *val TSRMLS_DC);
     361             : 
     362             : /* fetching of attributes */
     363             : typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, zend_long attr, zval *val TSRMLS_DC);
     364             : 
     365             : /* retrieves meta data for a numbered column.
     366             :  * Returns SUCCESS/FAILURE.
     367             :  * On SUCCESS, fill in return_value with an array with the following fields.
     368             :  * If a particular field is not supported, then the driver simply does not add it to
     369             :  * the array, so that scripts can use isset() to check for it.
     370             :  *
     371             :  * ### this is just a rough first cut, and subject to change ###
     372             :  *
     373             :  * these are added by PDO itself, based on data from the describe handler:
     374             :  *   name => the column name
     375             :  *   len => the length/size of the column
     376             :  *   precision => precision of the column
     377             :  *   pdo_type => an integer, one of the PDO_PARAM_XXX values
     378             :  *
     379             :  *   scale => the floating point scale
     380             :  *   table => the table for that column
     381             :  *   type => a string representation of the type, mapped to the PHP equivalent type name
     382             :  *   native_type => a string representation of the type, native style, if different from
     383             :  *                  the mapped name.
     384             :  *   flags => an array of flags including zero or more of the following:
     385             :  *            primary_key, not_null, unique_key, multiple_key, unsigned, auto_increment, blob
     386             :  *
     387             :  * Any driver specific data should be returned using a prefixed key or value.
     388             :  * Eg: custom data for the mysql driver would use either
     389             :  *   'mysql:foobar' => 'some data' // to add a new key to the array
     390             :  * or
     391             :  *   'flags' => array('not_null', 'mysql:some_flag'); // to add data to an existing key
     392             :  */
     393             : typedef int (*pdo_stmt_get_column_meta_func)(pdo_stmt_t *stmt, zend_long colno, zval *return_value TSRMLS_DC);
     394             : 
     395             : /* advances the statement to the next rowset of the batch.
     396             :  * If it returns 1, PDO will tear down its idea of columns
     397             :  * and meta data.  If it returns 0, PDO will indicate an error
     398             :  * to the caller. */
     399             : typedef int (*pdo_stmt_next_rowset_func)(pdo_stmt_t *stmt TSRMLS_DC);
     400             : 
     401             : /* closes the active cursor on a statement, leaving the prepared
     402             :  * statement ready for re-execution.  Useful to explicitly state
     403             :  * that you are done with a given rowset, without having to explicitly
     404             :  * fetch all the rows. */
     405             : typedef int (*pdo_stmt_cursor_closer_func)(pdo_stmt_t *stmt TSRMLS_DC);
     406             : 
     407             : struct pdo_stmt_methods {
     408             :         pdo_stmt_dtor_func                      dtor;
     409             :         pdo_stmt_execute_func           executer;
     410             :         pdo_stmt_fetch_func                     fetcher;
     411             :         pdo_stmt_describe_col_func      describer;
     412             :         pdo_stmt_get_col_data_func      get_col;
     413             :         pdo_stmt_param_hook_func        param_hook;
     414             :         pdo_stmt_set_attr_func          set_attribute;
     415             :         pdo_stmt_get_attr_func          get_attribute;
     416             :         pdo_stmt_get_column_meta_func get_column_meta;
     417             :         pdo_stmt_next_rowset_func               next_rowset;
     418             :         pdo_stmt_cursor_closer_func     cursor_closer;
     419             : };
     420             : 
     421             : /* }}} */
     422             : 
     423             : enum pdo_placeholder_support {
     424             :         PDO_PLACEHOLDER_NONE=0,
     425             :         PDO_PLACEHOLDER_NAMED=1,
     426             :         PDO_PLACEHOLDER_POSITIONAL=2
     427             : };
     428             : 
     429             : struct _pdo_dbh_t {
     430             :         /* driver specific methods */
     431             :         struct pdo_dbh_methods *methods;
     432             :         /* driver specific data */
     433             :         void *driver_data;
     434             : 
     435             :         /* credentials */
     436             :         char *username, *password;
     437             :         
     438             :         /* if true, then data stored and pointed at by this handle must all be
     439             :          * persistently allocated */
     440             :         unsigned is_persistent:1;
     441             : 
     442             :         /* if true, driver should act as though a COMMIT were executed between
     443             :          * each executed statement; otherwise, COMMIT must be carried out manually
     444             :          * */
     445             :         unsigned auto_commit:1;
     446             : 
     447             :         /* if true, the handle has been closed and will not function anymore */
     448             :         unsigned is_closed:1;
     449             : 
     450             :         /* if true, the driver requires that memory be allocated explicitly for
     451             :          * the columns that are returned */
     452             :         unsigned alloc_own_columns:1;
     453             : 
     454             :         /* if true, commit or rollBack is allowed to be called */
     455             :         unsigned in_txn:1;
     456             : 
     457             :         /* max length a single character can become after correct quoting */
     458             :         unsigned max_escaped_char_length:3;
     459             : 
     460             :         /* oracle compat; see enum pdo_null_handling */
     461             :         unsigned oracle_nulls:2;
     462             : 
     463             :         /* when set, convert int/floats to strings */
     464             :         unsigned stringify:1;
     465             : 
     466             :         /* the sum of the number of bits here and the bit fields preceding should
     467             :          * equal 32 */
     468             :         unsigned _reserved_flags:21;
     469             : 
     470             :         /* data source string used to open this handle */
     471             :         const char *data_source;
     472             :         zend_ulong data_source_len;
     473             : 
     474             :         /* the global error code. */
     475             :         pdo_error_type error_code;
     476             : 
     477             :         enum pdo_error_mode error_mode;
     478             : 
     479             :         enum pdo_case_conversion native_case, desired_case;
     480             : 
     481             :         /* persistent hash key associated with this handle */
     482             :         const char *persistent_id;
     483             :         int persistent_id_len;
     484             :         unsigned int refcount;
     485             : 
     486             :         /* driver specific "class" methods for the dbh and stmt */
     487             :         HashTable *cls_methods[PDO_DBH_DRIVER_METHOD_KIND__MAX];
     488             : 
     489             :         pdo_driver_t *driver;
     490             :         
     491             :         zend_class_entry *def_stmt_ce;
     492             : 
     493             :         zval def_stmt_ctor_args;
     494             : 
     495             :         /* when calling PDO::query(), we need to keep the error
     496             :          * context from the statement around until we next clear it.
     497             :          * This will allow us to report the correct error message
     498             :          * when PDO::query() fails */
     499             :         pdo_stmt_t *query_stmt;
     500             :         zval query_stmt_zval;
     501             : 
     502             :         /* defaults for fetches */
     503             :         enum pdo_fetch_type default_fetch_type;
     504             : };
     505             : 
     506             : /* represents a connection to a database */
     507             : struct _pdo_dbh_object_t {
     508             :         pdo_dbh_t *inner;
     509             :         /* these items must appear in this order at the beginning of the
     510             :        struct so that this can be cast as a zend_object.  we need this
     511             :        to allow the extending class to escape all the custom handlers
     512             :            that PDO declares.
     513             :     */
     514             :         zend_object std;
     515             : };
     516             : 
     517        9648 : static inline pdo_dbh_t *php_pdo_dbh_fetch_inner(zend_object *obj) {
     518        9648 :         return (pdo_dbh_t *)(((pdo_dbh_object_t *)((char*)(obj) - XtOffsetOf(pdo_dbh_object_t, std)))->inner);
     519             : }
     520             : 
     521        8262 : static inline pdo_dbh_object_t *php_pdo_dbh_fetch_object(zend_object *obj) {
     522        8262 :         return (pdo_dbh_object_t *)((char*)(obj) - XtOffsetOf(pdo_dbh_object_t, std));
     523             : }
     524             : 
     525             : #define Z_PDO_DBH_P(zv) php_pdo_dbh_fetch_inner(Z_OBJ_P((zv)))
     526             : #define Z_PDO_OBJECT_P(zv) php_pdo_dbh_fetch_object(Z_OBJ_P((zv)))
     527             : 
     528             : /* describes a column */
     529             : struct pdo_column_data {
     530             :         char *name;
     531             :         zend_ulong maxlen;
     532             :         zend_ulong precision;
     533             :         enum pdo_param_type param_type;
     534             :         int namelen;
     535             : 
     536             :         /* don't touch this unless your name is dbdo */
     537             :         void *dbdo_data;
     538             : };
     539             : 
     540             : /* describes a bound parameter */
     541             : struct pdo_bound_param_data {
     542             :         zval parameter;                         /* the variable itself */
     543             : 
     544             :         zval driver_params;                     /* optional parameter(s) for the driver */
     545             : 
     546             :         zend_long paramno; /* if -1, then it has a name, and we don't know the index *yet* */
     547             :         zend_string *name;
     548             : 
     549             :         zend_long max_value_len;        /* as a hint for pre-allocation */
     550             : 
     551             :         void *driver_data;
     552             : 
     553             :         pdo_stmt_t *stmt;       /* for convenience in dtor */
     554             : 
     555             :         enum pdo_param_type param_type; /* desired or suggested variable type */
     556             : 
     557             :         int is_param;           /* parameter or column ? */
     558             : };
     559             : 
     560             : /* represents a prepared statement */
     561             : struct _pdo_stmt_t {
     562             :         /* driver specifics */
     563             :         struct pdo_stmt_methods *methods;
     564             :         void *driver_data;
     565             : 
     566             :         /* if true, we've already successfully executed this statement at least
     567             :          * once */
     568             :         unsigned executed:1;
     569             :         /* if true, the statement supports placeholders and can implement
     570             :          * bindParam() for its prepared statements, if false, PDO should
     571             :          * emulate prepare and bind on its behalf */
     572             :         unsigned supports_placeholders:2;
     573             : 
     574             :         unsigned _reserved:29;
     575             : 
     576             :         /* the number of columns in the result set; not valid until after
     577             :          * the statement has been executed at least once.  In some cases, might
     578             :          * not be valid until fetch (at the driver level) has been called at least once.
     579             :          * */
     580             :         int column_count;
     581             :         struct pdo_column_data *columns;
     582             :         
     583             :         /* we want to keep the dbh alive while we live, so we own a reference */
     584             :         zval database_object_handle;
     585             :         pdo_dbh_t *dbh;
     586             : 
     587             :         /* keep track of bound input parameters.  Some drivers support
     588             :          * input/output parameters, but you can't rely on that working */
     589             :         HashTable *bound_params;
     590             :         /* When rewriting from named to positional, this maps positions to names */
     591             :         HashTable *bound_param_map;
     592             :         /* keep track of PHP variables bound to named (or positional) columns
     593             :          * in the result set */
     594             :         HashTable *bound_columns;
     595             : 
     596             :         /* not always meaningful */
     597             :         zend_long row_count;
     598             : 
     599             :         /* used to hold the statement's current query */
     600             :         char *query_string;
     601             :         int query_stringlen;
     602             : 
     603             :         /* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
     604             :         char *active_query_string;
     605             :         int active_query_stringlen;
     606             : 
     607             :         /* the cursor specific error code. */
     608             :         pdo_error_type error_code;
     609             : 
     610             :         /* for lazy fetches, we always return the same lazy object handle.
     611             :          * Let's keep it here. */
     612             :         zval lazy_object_ref;
     613             :         zend_ulong refcount;
     614             : 
     615             :         /* defaults for fetches */
     616             :         enum pdo_fetch_type default_fetch_type;
     617             :         union {
     618             :                 int column;
     619             :                 struct {
     620             :                         zval ctor_args;            /* freed */
     621             :                         zend_fcall_info fci;
     622             :                         zend_fcall_info_cache fcc;
     623             :                         zval retval; 
     624             :                         zend_class_entry *ce;   
     625             :                 } cls;
     626             :                 struct {
     627             :                         zval fetch_args;           /* freed */
     628             :                         zend_fcall_info fci;
     629             :                         zend_fcall_info_cache fcc;
     630             :                         zval object;
     631             :                         zval function;
     632             :                         zval *values;              /* freed */
     633             :                 } func;
     634             :                 zval into;
     635             :         } fetch;
     636             : 
     637             :         /* used by the query parser for driver specific
     638             :          * parameter naming (see pgsql driver for example) */
     639             :         const char *named_rewrite_template;
     640             : 
     641             :         /* these items must appear in this order at the beginning of the
     642             :        struct so that this can be cast as a zend_object.  we need this
     643             :        to allow the extending class to escape all the custom handlers
     644             :            that PDO declares.
     645             :     */
     646             :         zend_object std;
     647             : };
     648             : 
     649       10679 : static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
     650       10679 :         return (pdo_stmt_t *)((char*)(obj) - XtOffsetOf(pdo_stmt_t, std));
     651             : }
     652             : 
     653             : #define Z_PDO_STMT_P(zv) php_pdo_stmt_fetch_object(Z_OBJ_P((zv)))
     654             : 
     655             : struct _pdo_row_t {
     656             :         zend_object std;
     657             :         pdo_stmt_t *stmt;
     658             : };
     659             : 
     660             : /* call this in MINIT to register your PDO driver */
     661             : PDO_API int php_pdo_register_driver(pdo_driver_t *driver);
     662             : /* call this in MSHUTDOWN to unregister your PDO driver */
     663             : PDO_API void php_pdo_unregister_driver(pdo_driver_t *driver);
     664             : 
     665             : /* For the convenience of drivers, this function will parse a data source
     666             :  * string, of the form "name=value; name2=value2" and populate variables
     667             :  * according to the data you pass in and array of pdo_data_src_parser structures */
     668             : struct pdo_data_src_parser {
     669             :         const char *optname;
     670             :         char *optval;
     671             :         int freeme;
     672             : };
     673             : 
     674             : PDO_API int php_pdo_parse_data_source(const char *data_source,
     675             :                 zend_ulong data_source_len, struct pdo_data_src_parser *parsed,
     676             :                 int nparams);
     677             : 
     678             : PDO_API zend_class_entry *php_pdo_get_dbh_ce(void);
     679             : PDO_API zend_class_entry *php_pdo_get_exception(void);
     680             : 
     681             : PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, 
     682             :         char **outquery, int *outquery_len TSRMLS_DC);
     683             : 
     684             : PDO_API void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt,
     685             :         const char *sqlstate, const char *supp TSRMLS_DC);
     686             : 
     687             : PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC);
     688             : PDO_API void php_pdo_dbh_delref(pdo_dbh_t *dbh TSRMLS_DC);
     689             : 
     690             : PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC);
     691             : PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC);
     692             : 
     693             : 
     694             : #endif /* PHP_PDO_DRIVER_H */
     695             : /*
     696             :  * Local variables:
     697             :  * tab-width: 4
     698             :  * c-basic-offset: 4
     699             :  * End:
     700             :  * vim600: noet sw=4 ts=4 fdm=marker
     701             :  * vim<600: noet sw=4 ts=4
     702             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:54 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.