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: 54 82 65.9 %
Date: 2016-09-18 Functions: 7 8 87.5 %
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          73 : 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          73 :         char *state = "HY000";
      88             : 
      89          73 :         if(dbproc) {
      90          73 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
      91          73 :                 if (!einfo) einfo = &DBLIB_G(err);
      92             :         } else {
      93           0 :                 einfo = &DBLIB_G(err);
      94             :         }
      95             : 
      96          73 :         einfo->severity = severity;
      97          73 :         einfo->oserr = oserr;
      98          73 :         einfo->dberr = dberr;
      99             : 
     100          73 :         if (einfo->oserrstr) {
     101           0 :                 efree(einfo->oserrstr);
     102             :         }
     103          73 :         if (einfo->dberrstr) {
     104           0 :                 efree(einfo->dberrstr);
     105             :         }
     106          73 :         if (oserrstr) {
     107          73 :                 einfo->oserrstr = estrdup(oserrstr);
     108             :         } else {
     109           0 :                 einfo->oserrstr = NULL;
     110             :         }
     111          73 :         if (dberrstr) {
     112          73 :                 einfo->dberrstr = estrdup(dberrstr);
     113             :         } else {
     114           0 :                 einfo->dberrstr = NULL;
     115             :         }
     116             : 
     117          73 :         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          73 :         strcpy(einfo->sqlstate, state);
     124             : 
     125          73 :         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          73 : void pdo_dblib_err_dtor(pdo_dblib_err *err)
     150             : {
     151          73 :         if (!err) {
     152           0 :                 return;
     153             :         }
     154             : 
     155          73 :         if (err->dberrstr) {
     156           0 :                 efree(err->dberrstr);
     157           0 :                 err->dberrstr = NULL;
     158             :         }
     159          73 :         if (err->lastmsg) {
     160           0 :                 efree(err->lastmsg);
     161           0 :                 err->lastmsg = NULL;
     162             :         }
     163          73 :         if (err->oserrstr) {
     164           0 :                 efree(err->oserrstr);
     165           0 :                 err->oserrstr = NULL;
     166             :         }
     167             : }
     168             : 
     169       23922 : static PHP_GINIT_FUNCTION(dblib)
     170             : {
     171       23922 :         memset(dblib_globals, 0, sizeof(*dblib_globals));
     172       23922 :         dblib_globals->err.sqlstate = dblib_globals->sqlstate;
     173       23922 : }
     174             : 
     175       23919 : PHP_RSHUTDOWN_FUNCTION(pdo_dblib)
     176             : {
     177       23919 :         if (DBLIB_G(err).oserrstr) {
     178          73 :                 efree(DBLIB_G(err).oserrstr);
     179          73 :                 DBLIB_G(err).oserrstr = NULL;
     180             :         }
     181       23919 :         if (DBLIB_G(err).dberrstr) {
     182          73 :                 efree(DBLIB_G(err).dberrstr);
     183          73 :                 DBLIB_G(err).dberrstr = NULL;
     184             :         }
     185       23919 :         if (DBLIB_G(err).lastmsg) {
     186           0 :                 efree(DBLIB_G(err).lastmsg);
     187           0 :                 DBLIB_G(err).lastmsg = NULL;
     188             :         }
     189       23919 :         return SUCCESS;
     190             : }
     191             : 
     192       23922 : PHP_MINIT_FUNCTION(pdo_dblib)
     193             : {
     194       23922 :         REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_CONNECTION_TIMEOUT", (long) PDO_DBLIB_ATTR_CONNECTION_TIMEOUT);
     195       23922 :         REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_QUERY_TIMEOUT", (long) PDO_DBLIB_ATTR_QUERY_TIMEOUT);
     196       23922 :         REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER", (long) PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER);
     197             : 
     198       23922 :         if (FAIL == dbinit()) {
     199           0 :                 return FAILURE;
     200             :         }
     201             : 
     202       23922 :         if (FAILURE == php_pdo_register_driver(&pdo_dblib_driver)) {
     203           0 :                 return FAILURE;
     204             :         }
     205             : 
     206             : #if !PHP_DBLIB_IS_MSSQL
     207       23922 :         dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
     208       23922 :         dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
     209             : #endif
     210             : 
     211       23922 :         return SUCCESS;
     212             : }
     213             : 
     214       23963 : PHP_MSHUTDOWN_FUNCTION(pdo_dblib)
     215             : {
     216       23963 :         php_pdo_unregister_driver(&pdo_dblib_driver);
     217       23963 :         dbexit();
     218       23963 :         return SUCCESS;
     219             : }
     220             : 
     221         150 : PHP_MINFO_FUNCTION(pdo_dblib)
     222             : {
     223         150 :         php_info_print_table_start();
     224         150 :         php_info_print_table_header(2, "PDO Driver for "
     225             : #if PDO_DBLIB_IS_MSSQL
     226             :                 "MSSQL"
     227             : #elif defined(PHP_WIN32)
     228             :                 "FreeTDS/Sybase/MSSQL"
     229             : #else
     230             :                 "FreeTDS/Sybase"
     231             : #endif
     232             :                 " DB-lib", "enabled");
     233         150 :         php_info_print_table_row(2, "Flavour", PDO_DBLIB_FLAVOUR);
     234         150 :         php_info_print_table_end();
     235         150 : }
     236             : 

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:12 +0000 (8 days ago)

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