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: 46 67 68.7 %
Date: 2016-02-05 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           5 : 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           5 :         char *state = "HY000";
      88             : 
      89           5 :         if(dbproc) {
      90           5 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
      91           5 :                 if (!einfo) einfo = &DBLIB_G(err);
      92             :         } else {
      93           0 :                 einfo = &DBLIB_G(err);
      94             :         }
      95             : 
      96           5 :         einfo->severity = severity;
      97           5 :         einfo->oserr = oserr;
      98           5 :         einfo->dberr = dberr;
      99             : 
     100           5 :         if (einfo->oserrstr) {
     101           0 :                 efree(einfo->oserrstr);
     102             :         }
     103           5 :         if (einfo->dberrstr) {
     104           0 :                 efree(einfo->dberrstr);
     105             :         }
     106           5 :         if (oserrstr) {
     107           5 :                 einfo->oserrstr = estrdup(oserrstr);
     108             :         } else {
     109           0 :                 einfo->oserrstr = NULL;
     110             :         }
     111           5 :         if (dberrstr) {
     112           5 :                 einfo->dberrstr = estrdup(dberrstr);
     113             :         } else {
     114           0 :                 einfo->dberrstr = NULL;
     115             :         }
     116             : 
     117           5 :         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           5 :         strcpy(einfo->sqlstate, state);
     124             : 
     125           5 :         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       22564 : static PHP_GINIT_FUNCTION(dblib)
     150             : {
     151       22564 :         memset(dblib_globals, 0, sizeof(*dblib_globals));
     152       22564 :         dblib_globals->err.sqlstate = dblib_globals->sqlstate;
     153       22564 : }
     154             : 
     155       22556 : PHP_RSHUTDOWN_FUNCTION(pdo_dblib)
     156             : {
     157       22556 :         if (DBLIB_G(err).oserrstr) {
     158           5 :                 efree(DBLIB_G(err).oserrstr);
     159           5 :                 DBLIB_G(err).oserrstr = NULL;
     160             :         }
     161       22556 :         if (DBLIB_G(err).dberrstr) {
     162           5 :                 efree(DBLIB_G(err).dberrstr);
     163           5 :                 DBLIB_G(err).dberrstr = NULL;
     164             :         }
     165       22556 :         if (DBLIB_G(err).lastmsg) {
     166           0 :                 efree(DBLIB_G(err).lastmsg);
     167           0 :                 DBLIB_G(err).lastmsg = NULL;
     168             :         }
     169       22556 :         return SUCCESS;
     170             : }
     171             : 
     172       22564 : PHP_MINIT_FUNCTION(pdo_dblib)
     173             : {
     174       22564 :         if (FAIL == dbinit()) {
     175           0 :                 return FAILURE;
     176             :         }
     177             : 
     178       22564 :         if (FAILURE == php_pdo_register_driver(&pdo_dblib_driver)) {
     179           0 :                 return FAILURE;
     180             :         }
     181             : 
     182             : #if !PHP_DBLIB_IS_MSSQL
     183       22564 :         dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
     184       22564 :         dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
     185             : #endif
     186             : 
     187       22564 :         return SUCCESS;
     188             : }
     189             : 
     190       22600 : PHP_MSHUTDOWN_FUNCTION(pdo_dblib)
     191             : {
     192       22600 :         php_pdo_unregister_driver(&pdo_dblib_driver);
     193       22600 :         dbexit();
     194       22600 :         return SUCCESS;
     195             : }
     196             : 
     197         149 : PHP_MINFO_FUNCTION(pdo_dblib)
     198             : {
     199         149 :         php_info_print_table_start();
     200         149 :         php_info_print_table_header(2, "PDO Driver for "
     201             : #if PDO_DBLIB_IS_MSSQL
     202             :                 "MSSQL"
     203             : #elif defined(PHP_WIN32)
     204             :                 "FreeTDS/Sybase/MSSQL"
     205             : #else
     206             :                 "FreeTDS/Sybase"
     207             : #endif
     208             :                 " DB-lib", "enabled");
     209         149 :         php_info_print_table_row(2, "Flavour", PDO_DBLIB_FLAVOUR);
     210         149 :         php_info_print_table_end();
     211         149 : }
     212             : 

Generated by: LCOV version 1.10

Generated at Fri, 05 Feb 2016 08:39:20 +0000 (47 hours ago)

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