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

Generated by: LCOV version 1.10

Generated at Wed, 19 Jan 2022 00:14:19 +0000 (3 days ago)

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