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_dblib - pdo_dblib.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 48 69 69.6 %
Date: 2016-08-24 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2016 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             :   |         Frank M. Kromann <frank@kromann.info>                        |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : # include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #include "php_ini.h"
      28             : #include "ext/standard/info.h"
      29             : #include "pdo/php_pdo.h"
      30             : #include "pdo/php_pdo_driver.h"
      31             : #include "php_pdo_dblib.h"
      32             : #include "php_pdo_dblib_int.h"
      33             : #include "zend_exceptions.h"
      34             : 
      35             : ZEND_DECLARE_MODULE_GLOBALS(dblib)
      36             : static PHP_GINIT_FUNCTION(dblib);
      37             : 
      38             : const zend_function_entry pdo_dblib_functions[] = {
      39             :         PHP_FE_END
      40             : };
      41             : 
      42             : static const zend_module_dep pdo_dblib_deps[] = {
      43             :         ZEND_MOD_REQUIRED("pdo")
      44             :         ZEND_MOD_END
      45             : };
      46             : 
      47             : #if PDO_DBLIB_IS_MSSQL
      48             : zend_module_entry pdo_mssql_module_entry = {
      49             : #else
      50             : zend_module_entry pdo_dblib_module_entry = {
      51             : #endif
      52             :         STANDARD_MODULE_HEADER_EX, NULL,
      53             :         pdo_dblib_deps,
      54             : #if PDO_DBLIB_IS_MSSQL
      55             :         "pdo_mssql",
      56             : #elif defined(PHP_WIN32)
      57             :         "pdo_sybase",
      58             : #else
      59             :         "pdo_dblib",
      60             : #endif
      61             :         pdo_dblib_functions,
      62             :         PHP_MINIT(pdo_dblib),
      63             :         PHP_MSHUTDOWN(pdo_dblib),
      64             :         NULL,
      65             :         PHP_RSHUTDOWN(pdo_dblib),
      66             :         PHP_MINFO(pdo_dblib),
      67             :         PHP_PDO_DBLIB_VERSION,
      68             :         PHP_MODULE_GLOBALS(dblib),
      69             :         PHP_GINIT(dblib),
      70             :         NULL,
      71             :         NULL,
      72             :         STANDARD_MODULE_PROPERTIES_EX
      73             : };
      74             : 
      75             : #if defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL)
      76             : #if PDO_DBLIB_IS_MSSQL
      77             : ZEND_GET_MODULE(pdo_mssql)
      78             : #else
      79             : ZEND_GET_MODULE(pdo_dblib)
      80             : #endif
      81             : #endif
      82             : 
      83          11 : int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
      84             :         int oserr, char *dberrstr, char *oserrstr)
      85             : {
      86             :         pdo_dblib_err *einfo;
      87          11 :         char *state = "HY000";
      88             : 
      89          11 :         if(dbproc) {
      90          11 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
      91          11 :                 if (!einfo) einfo = &DBLIB_G(err);
      92             :         } else {
      93           0 :                 einfo = &DBLIB_G(err);
      94             :         }
      95             : 
      96          11 :         einfo->severity = severity;
      97          11 :         einfo->oserr = oserr;
      98          11 :         einfo->dberr = dberr;
      99             : 
     100          11 :         if (einfo->oserrstr) {
     101           0 :                 efree(einfo->oserrstr);
     102             :         }
     103          11 :         if (einfo->dberrstr) {
     104           0 :                 efree(einfo->dberrstr);
     105             :         }
     106          11 :         if (oserrstr) {
     107          11 :                 einfo->oserrstr = estrdup(oserrstr);
     108             :         } else {
     109           0 :                 einfo->oserrstr = NULL;
     110             :         }
     111          11 :         if (dberrstr) {
     112          11 :                 einfo->dberrstr = estrdup(dberrstr);
     113             :         } else {
     114           0 :                 einfo->dberrstr = NULL;
     115             :         }
     116             : 
     117          11 :         switch (dberr) {
     118             :                 case SYBESEOF:
     119           0 :                 case SYBEFCON:  state = "01002"; break;
     120           0 :                 case SYBEMEM:   state = "HY001"; break;
     121           0 :                 case SYBEPWD:   state = "28000"; break;
     122             :         }
     123          11 :         strcpy(einfo->sqlstate, state);
     124             : 
     125          11 :         return INT_CANCEL;
     126             : }
     127             : 
     128           0 : int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
     129             :         int severity, char *msgtext, char *srvname, char *procname, DBUSMALLINT line)
     130             : {
     131             :         pdo_dblib_err *einfo;
     132             : 
     133           0 :         if (severity) {
     134           0 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
     135           0 :                 if (!einfo) {
     136           0 :                         einfo = &DBLIB_G(err);
     137             :                 }
     138             : 
     139           0 :                 if (einfo->lastmsg) {
     140           0 :                         efree(einfo->lastmsg);
     141             :                 }
     142             : 
     143           0 :                 einfo->lastmsg = estrdup(msgtext);
     144             :         }
     145             : 
     146           0 :         return 0;
     147             : }
     148             : 
     149       23504 : static PHP_GINIT_FUNCTION(dblib)
     150             : {
     151       23504 :         memset(dblib_globals, 0, sizeof(*dblib_globals));
     152       23504 :         dblib_globals->err.sqlstate = dblib_globals->sqlstate;
     153       23504 : }
     154             : 
     155       23500 : PHP_RSHUTDOWN_FUNCTION(pdo_dblib)
     156             : {
     157       23500 :         if (DBLIB_G(err).oserrstr) {
     158          11 :                 efree(DBLIB_G(err).oserrstr);
     159          11 :                 DBLIB_G(err).oserrstr = NULL;
     160             :         }
     161       23500 :         if (DBLIB_G(err).dberrstr) {
     162          11 :                 efree(DBLIB_G(err).dberrstr);
     163          11 :                 DBLIB_G(err).dberrstr = NULL;
     164             :         }
     165       23500 :         if (DBLIB_G(err).lastmsg) {
     166           0 :                 efree(DBLIB_G(err).lastmsg);
     167           0 :                 DBLIB_G(err).lastmsg = NULL;
     168             :         }
     169       23500 :         return SUCCESS;
     170             : }
     171             : 
     172       23504 : PHP_MINIT_FUNCTION(pdo_dblib)
     173             : {
     174       23504 :         REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_CONNECTION_TIMEOUT", (long) PDO_DBLIB_ATTR_CONNECTION_TIMEOUT);
     175       23504 :         REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_QUERY_TIMEOUT", (long) PDO_DBLIB_ATTR_QUERY_TIMEOUT);
     176             : 
     177       23504 :         if (FAIL == dbinit()) {
     178           0 :                 return FAILURE;
     179             :         }
     180             : 
     181       23504 :         if (FAILURE == php_pdo_register_driver(&pdo_dblib_driver)) {
     182           0 :                 return FAILURE;
     183             :         }
     184             : 
     185             : #if !PHP_DBLIB_IS_MSSQL
     186       23504 :         dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
     187       23504 :         dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
     188             : #endif
     189             : 
     190       23504 :         return SUCCESS;
     191             : }
     192             : 
     193       23544 : PHP_MSHUTDOWN_FUNCTION(pdo_dblib)
     194             : {
     195       23544 :         php_pdo_unregister_driver(&pdo_dblib_driver);
     196       23544 :         dbexit();
     197       23544 :         return SUCCESS;
     198             : }
     199             : 
     200         150 : PHP_MINFO_FUNCTION(pdo_dblib)
     201             : {
     202         150 :         php_info_print_table_start();
     203         150 :         php_info_print_table_header(2, "PDO Driver for "
     204             : #if PDO_DBLIB_IS_MSSQL
     205             :                 "MSSQL"
     206             : #elif defined(PHP_WIN32)
     207             :                 "FreeTDS/Sybase/MSSQL"
     208             : #else
     209             :                 "FreeTDS/Sybase"
     210             : #endif
     211             :                 " DB-lib", "enabled");
     212         150 :         php_info_print_table_row(2, "Flavour", PDO_DBLIB_FLAVOUR);
     213         150 :         php_info_print_table_end();
     214         150 : }
     215             : 

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:26 +0000 (39 hours ago)

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