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/mysqlnd - mysqlnd_driver.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 96 130 73.8 %
Date: 2014-10-24 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-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             :   | Authors: Andrey Hristov <andrey@mysql.com>                           |
      16             :   |          Ulf Wendel <uwendel@mysql.com>                              |
      17             :   |          Georg Richter <georg@mysql.com>                             |
      18             :   +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id: mysqlnd.c 317989 2011-10-10 20:49:28Z andrey $ */
      22             : #include "php.h"
      23             : #include "mysqlnd.h"
      24             : #include "mysqlnd_wireprotocol.h"
      25             : #include "mysqlnd_priv.h"
      26             : #include "mysqlnd_result.h"
      27             : #include "mysqlnd_statistics.h"
      28             : #include "mysqlnd_charset.h"
      29             : #include "mysqlnd_debug.h"
      30             : #include "mysqlnd_reverse_api.h"
      31             : #include "mysqlnd_ext_plugin.h"
      32             : 
      33             : static zend_bool mysqlnd_library_initted = FALSE;
      34             : 
      35             : static struct st_mysqlnd_plugin_core mysqlnd_plugin_core =
      36             : {
      37             :         {
      38             :                 MYSQLND_PLUGIN_API_VERSION,
      39             :                 "mysqlnd",
      40             :                 MYSQLND_VERSION_ID,
      41             :                 MYSQLND_VERSION,
      42             :                 "PHP License 3.01",
      43             :                 "Andrey Hristov <andrey@mysql.com>,  Ulf Wendel <uwendel@mysql.com>, Georg Richter <georg@mysql.com>",
      44             :                 {
      45             :                         NULL, /* will be filled later */
      46             :                         mysqlnd_stats_values_names,
      47             :                 },
      48             :                 {
      49             :                         NULL /* plugin shutdown */
      50             :                 }
      51             :         }
      52             : };
      53             : 
      54             : 
      55             : /* {{{ mysqlnd_library_end */
      56       20261 : PHPAPI void mysqlnd_library_end(TSRMLS_D)
      57             : {
      58       20261 :         if (mysqlnd_library_initted == TRUE) {
      59       20261 :                 mysqlnd_plugin_subsystem_end(TSRMLS_C);
      60       20261 :                 mysqlnd_stats_end(mysqlnd_global_stats);
      61       20261 :                 mysqlnd_global_stats = NULL;
      62       20261 :                 mysqlnd_library_initted = FALSE;
      63       20261 :                 mysqlnd_reverse_api_end(TSRMLS_C);
      64             :         }
      65       20261 : }
      66             : /* }}} */
      67             : 
      68             : 
      69             : /* {{{ mysqlnd_library_init */
      70       20225 : PHPAPI void mysqlnd_library_init(TSRMLS_D)
      71             : {
      72       20225 :         if (mysqlnd_library_initted == FALSE) {
      73       20225 :                 mysqlnd_library_initted = TRUE;
      74       20225 :                 mysqlnd_conn_set_methods(&MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_conn));
      75       20225 :                 mysqlnd_conn_data_set_methods(&MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_conn_data));
      76       20225 :                 _mysqlnd_init_ps_subsystem();
      77             :                 /* Should be calloc, as mnd_calloc will reference LOCK_access*/
      78       20225 :                 mysqlnd_stats_init(&mysqlnd_global_stats, STAT_LAST);
      79       20225 :                 mysqlnd_plugin_subsystem_init(TSRMLS_C);
      80             :                 {
      81       20225 :                         mysqlnd_plugin_core.plugin_header.plugin_stats.values = mysqlnd_global_stats;
      82       20225 :                         mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_plugin_core TSRMLS_CC);
      83             :                 }
      84       20225 :                 mysqlnd_example_plugin_register(TSRMLS_C);
      85       20225 :                 mysqlnd_debug_trace_plugin_register(TSRMLS_C);
      86       20225 :                 mysqlnd_register_builtin_authentication_plugins(TSRMLS_C);
      87             : 
      88       20225 :                 mysqlnd_reverse_api_init(TSRMLS_C);
      89             :         }
      90       20225 : }
      91             : /* }}} */
      92             : 
      93             : 
      94             : /* {{{ mysqlnd_error_list_pdtor */
      95             : static void
      96        2110 : mysqlnd_error_list_pdtor(void * pDest)
      97             : {
      98        2110 :         MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
      99             : #ifdef ZTS
     100             :         TSRMLS_FETCH();
     101             : #endif
     102        2110 :         DBG_ENTER("mysqlnd_error_list_pdtor");
     103        2110 :         if (element->error) {
     104        2110 :                 mnd_pefree(element->error, TRUE);
     105             :         }
     106        2110 :         DBG_VOID_RETURN;
     107             : }
     108             : /* }}} */
     109             : 
     110             : 
     111             : /* {{{ mysqlnd_object_factory::get_connection */
     112             : static MYSQLND *
     113        1916 : MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent TSRMLS_DC)
     114             : {
     115        1916 :         size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
     116        1916 :         size_t alloc_size_ret_data = sizeof(MYSQLND_CONN_DATA) + mysqlnd_plugin_count() * sizeof(void *);
     117             :         MYSQLND * new_object;
     118             :         MYSQLND_CONN_DATA * data;
     119             : 
     120        1916 :         DBG_ENTER("mysqlnd_driver::get_connection");
     121        1916 :         DBG_INF_FMT("persistent=%u", persistent);
     122        1916 :         new_object = mnd_pecalloc(1, alloc_size_ret, persistent);
     123        1916 :         if (!new_object) {
     124           0 :                 DBG_RETURN(NULL);
     125             :         }
     126        1916 :         new_object->data = mnd_pecalloc(1, alloc_size_ret_data, persistent);
     127        1916 :         if (!new_object->data) {
     128           0 :                 mnd_pefree(new_object, persistent);
     129           0 :                 DBG_RETURN(NULL);
     130             :         }
     131        1916 :         new_object->persistent = persistent;
     132        1916 :         new_object->m = mysqlnd_conn_get_methods();
     133        1916 :         data = new_object->data;
     134             : 
     135        1916 :         data->error_info = &(data->error_info_impl);
     136        1916 :         data->options = &(data->options_impl);
     137        1916 :         data->upsert_status = &(data->upsert_status_impl);
     138             : 
     139        1916 :         data->persistent = persistent;
     140        1916 :         data->m = mysqlnd_conn_data_get_methods();
     141        1916 :         CONN_SET_STATE(data, CONN_ALLOCED);
     142        1916 :         data->m->get_reference(data TSRMLS_CC);
     143             : 
     144        1916 :         if (PASS != data->m->init(data TSRMLS_CC)) {
     145           0 :                 new_object->m->dtor(new_object TSRMLS_CC);
     146           0 :                 DBG_RETURN(NULL);
     147             :         }
     148             : 
     149        1916 :         data->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
     150        1916 :         if (!data->error_info->error_list) {
     151           0 :                 new_object->m->dtor(new_object TSRMLS_CC);
     152           0 :                 DBG_RETURN(NULL);
     153             :         } else {
     154        1916 :                 zend_llist_init(data->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
     155             :         }
     156             : 
     157        1916 :         DBG_RETURN(new_object);
     158             : }
     159             : /* }}} */
     160             : 
     161             : 
     162             : /* {{{ mysqlnd_object_factory::clone_connection_object */
     163             : static MYSQLND *
     164           0 : MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object)(MYSQLND * to_be_cloned TSRMLS_DC)
     165             : {
     166           0 :         size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
     167             :         MYSQLND * new_object;
     168             : 
     169           0 :         DBG_ENTER("mysqlnd_driver::clone_connection_object");
     170           0 :         DBG_INF_FMT("persistent=%u", to_be_cloned->persistent);
     171           0 :         if (!to_be_cloned || !to_be_cloned->data) {
     172           0 :                 DBG_RETURN(NULL);
     173             :         }
     174           0 :         new_object = mnd_pecalloc(1, alloc_size_ret, to_be_cloned->persistent);
     175           0 :         if (!new_object) {
     176           0 :                 DBG_RETURN(NULL);
     177             :         }
     178           0 :         new_object->persistent = to_be_cloned->persistent;
     179           0 :         new_object->m = to_be_cloned->m;
     180             : 
     181           0 :         new_object->data = to_be_cloned->data->m->get_reference(to_be_cloned->data TSRMLS_CC);
     182           0 :         if (!new_object->data) {
     183           0 :                 new_object->m->dtor(new_object TSRMLS_CC);
     184           0 :                 new_object = NULL;
     185             :         }
     186           0 :         DBG_RETURN(new_object);
     187             : }
     188             : /* }}} */
     189             : 
     190             : 
     191             : /* {{{ mysqlnd_object_factory::get_prepared_statement */
     192             : static MYSQLND_STMT *
     193        4243 : MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA * const conn TSRMLS_DC)
     194             : {
     195        4243 :         size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
     196        4243 :         MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
     197        4243 :         MYSQLND_STMT_DATA * stmt = NULL;
     198             : 
     199        4243 :         DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
     200             :         do {
     201        4243 :                 if (!ret) {
     202           0 :                         break;
     203             :                 }
     204        4243 :                 ret->m = mysqlnd_stmt_get_methods();
     205        4243 :                 ret->persistent = conn->persistent;
     206             : 
     207        4243 :                 stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
     208        4243 :                 DBG_INF_FMT("stmt=%p", stmt);
     209        4243 :                 if (!stmt) {
     210           0 :                         break;
     211             :                 }
     212        4243 :                 stmt->persistent = conn->persistent;
     213        4243 :                 stmt->error_info = &(stmt->error_info_impl);
     214        4243 :                 stmt->upsert_status = &(stmt->upsert_status_impl);
     215        4243 :                 stmt->state = MYSQLND_STMT_INITTED;
     216        4243 :                 stmt->execute_cmd_buffer.length = 4096;
     217        4243 :                 stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
     218        4243 :                 if (!stmt->execute_cmd_buffer.buffer) {
     219           0 :                         break;
     220             :                 }
     221             : 
     222        4243 :                 stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
     223             :                 /*
     224             :                   Mark that we reference the connection, thus it won't be
     225             :                   be destructed till there is open statements. The last statement
     226             :                   or normal query result will close it then.
     227             :                 */
     228        4243 :                 stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
     229        4243 :                 stmt->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
     230        4243 :                 if (!stmt->error_info->error_list) {
     231           0 :                         break;
     232             :                 }
     233             : 
     234        4243 :                 zend_llist_init(stmt->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_error_list_pdtor, conn->persistent);
     235             : 
     236        4243 :                 DBG_RETURN(ret);
     237             :         } while (0);
     238             : 
     239           0 :         SET_OOM_ERROR(*conn->error_info);
     240           0 :         if (ret) {
     241           0 :                 ret->m->dtor(ret, TRUE TSRMLS_CC);
     242           0 :                 ret = NULL;
     243             :         }
     244           0 :         DBG_RETURN(NULL);
     245             : }
     246             : /* }}} */
     247             : 
     248             : 
     249             : /* {{{ mysqlnd_object_factory::get_io_channel */
     250             : PHPAPI MYSQLND_NET *
     251        1916 : MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
     252             : {
     253        1916 :         size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
     254        1916 :         MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
     255             : 
     256        1916 :         DBG_ENTER("mysqlnd_object_factory::get_io_channel");
     257        1916 :         DBG_INF_FMT("persistent=%u", persistent);
     258        1916 :         if (net) {
     259        1916 :                 net->persistent = persistent;
     260        1916 :                 net->m = *mysqlnd_net_get_methods();
     261             : 
     262        1916 :                 if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
     263           0 :                         net->m.dtor(net, stats, error_info TSRMLS_CC);
     264           0 :                         net = NULL;
     265             :                 }
     266             :         }
     267        1916 :         DBG_RETURN(net);
     268             : }
     269             : /* }}} */
     270             : 
     271             : 
     272             : /* {{{ mysqlnd_object_factory::get_protocol_decoder */
     273             : PHPAPI MYSQLND_PROTOCOL *
     274        1916 : MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)(zend_bool persistent TSRMLS_DC)
     275             : {
     276        1916 :         size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
     277        1916 :         MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);
     278             : 
     279        1916 :         DBG_ENTER("mysqlnd_object_factory::get_protocol_decoder");
     280        1916 :         DBG_INF_FMT("persistent=%u", persistent);
     281        1916 :         if (ret) {
     282        1916 :                 ret->persistent = persistent;
     283        1916 :                 ret->m = mysqlnd_mysqlnd_protocol_methods;
     284             :         }
     285             : 
     286        1916 :         DBG_RETURN(ret);
     287             : }
     288             : /* }}} */
     289             : 
     290             : 
     291             : MYSQLND_CLASS_METHODS_START(mysqlnd_object_factory)
     292             :         MYSQLND_METHOD(mysqlnd_object_factory, get_connection),
     293             :         MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object),
     294             :         MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement),
     295             :         MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel),
     296             :         MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)
     297             : MYSQLND_CLASS_METHODS_END;
     298             : 
     299             : /*
     300             :  * Local variables:
     301             :  * tab-width: 4
     302             :  * c-basic-offset: 4
     303             :  * End:
     304             :  * vim600: noet sw=4 ts=4 fdm=marker
     305             :  * vim<600: noet sw=4 ts=4
     306             :  */

Generated by: LCOV version 1.10

Generated at Fri, 24 Oct 2014 05:21:50 +0000 (7 days ago)

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