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: 2014-11-22 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-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             :   | 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             : #if ZEND_MODULE_API_NO >= 20050922
      43             : static const zend_module_dep pdo_dblib_deps[] = {
      44             :         ZEND_MOD_REQUIRED("pdo")
      45             :         ZEND_MOD_END
      46             : };
      47             : #endif
      48             : 
      49             : #if PDO_DBLIB_IS_MSSQL
      50             : zend_module_entry pdo_mssql_module_entry = {
      51             : #else
      52             : zend_module_entry pdo_dblib_module_entry = {
      53             : #endif
      54             : #if ZEND_MODULE_API_NO >= 20050922
      55             :         STANDARD_MODULE_HEADER_EX, NULL,
      56             :         pdo_dblib_deps,
      57             : #else
      58             :         STANDARD_MODULE_HEADER,
      59             : #endif
      60             : #if PDO_DBLIB_IS_MSSQL
      61             :         "pdo_mssql",
      62             : #elif defined(PHP_WIN32)
      63             :         "pdo_sybase",
      64             : #else
      65             :         "pdo_dblib",
      66             : #endif
      67             :         pdo_dblib_functions,
      68             :         PHP_MINIT(pdo_dblib),
      69             :         PHP_MSHUTDOWN(pdo_dblib),
      70             :         NULL,
      71             :         PHP_RSHUTDOWN(pdo_dblib),
      72             :         PHP_MINFO(pdo_dblib),
      73             :         "1.0.1",
      74             :         PHP_MODULE_GLOBALS(dblib),
      75             :         PHP_GINIT(dblib),
      76             :         NULL,
      77             :         NULL,
      78             :         STANDARD_MODULE_PROPERTIES_EX
      79             : };
      80             : 
      81             : #if defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL)
      82             : #if PDO_DBLIB_IS_MSSQL
      83             : ZEND_GET_MODULE(pdo_mssql)
      84             : #else
      85             : ZEND_GET_MODULE(pdo_dblib)
      86             : #endif
      87             : #endif
      88             : 
      89           4 : int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
      90             :         int oserr, char *dberrstr, char *oserrstr)
      91             : {
      92             :         pdo_dblib_err *einfo;
      93           4 :         char *state = "HY000";
      94             :         TSRMLS_FETCH();
      95             : 
      96           4 :         if(dbproc) {
      97           4 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
      98           4 :                 if (!einfo) einfo = &DBLIB_G(err);
      99             :         } else {
     100           0 :                 einfo = &DBLIB_G(err);
     101             :         }       
     102             : 
     103           4 :         einfo->severity = severity;
     104           4 :         einfo->oserr = oserr;
     105           4 :         einfo->dberr = dberr;
     106             :         
     107           4 :         if (einfo->oserrstr) {
     108           0 :                 efree(einfo->oserrstr);
     109             :         }
     110           4 :         if (einfo->dberrstr) {
     111           0 :                 efree(einfo->dberrstr);
     112             :         }
     113           4 :         if (oserrstr) {
     114           4 :                 einfo->oserrstr = estrdup(oserrstr);
     115             :         } else {
     116           0 :                 einfo->oserrstr = NULL;
     117             :         }
     118           4 :         if (dberrstr) {
     119           4 :                 einfo->dberrstr = estrdup(dberrstr);
     120             :         } else {
     121           0 :                 einfo->dberrstr = NULL;
     122             :         }
     123             : 
     124           4 :         switch (dberr) {
     125             :                 case SYBESEOF:
     126           0 :                 case SYBEFCON:  state = "01002"; break;
     127           0 :                 case SYBEMEM:   state = "HY001"; break;
     128           0 :                 case SYBEPWD:   state = "28000"; break;
     129             :         }
     130           4 :         strcpy(einfo->sqlstate, state);
     131             : 
     132           4 :         return INT_CANCEL;
     133             : }
     134             : 
     135           0 : int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
     136             :         int severity, char *msgtext, char *srvname, char *procname, DBUSMALLINT line)
     137             : {
     138             :         pdo_dblib_err *einfo;
     139             :         TSRMLS_FETCH();
     140             : 
     141           0 :         if (severity) {
     142           0 :                 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
     143           0 :                 if (!einfo) {
     144           0 :                         einfo = &DBLIB_G(err);
     145             :                 }
     146             : 
     147           0 :                 if (einfo->lastmsg) {
     148           0 :                         efree(einfo->lastmsg);
     149             :                 }
     150             : 
     151           0 :                 einfo->lastmsg = estrdup(msgtext);
     152             :         }
     153             : 
     154           0 :         return 0;
     155             : }
     156             : 
     157       20507 : static PHP_GINIT_FUNCTION(dblib)
     158             : {
     159       20507 :         memset(dblib_globals, 0, sizeof(*dblib_globals));
     160       20507 :         dblib_globals->err.sqlstate = dblib_globals->sqlstate;
     161       20507 : }
     162             : 
     163       20500 : PHP_RSHUTDOWN_FUNCTION(pdo_dblib)
     164             : {
     165       20500 :         if (DBLIB_G(err).oserrstr) {
     166           4 :                 efree(DBLIB_G(err).oserrstr);
     167           4 :                 DBLIB_G(err).oserrstr = NULL;
     168             :         }
     169       20500 :         if (DBLIB_G(err).dberrstr) {
     170           4 :                 efree(DBLIB_G(err).dberrstr);
     171           4 :                 DBLIB_G(err).dberrstr = NULL;
     172             :         }
     173       20500 :         if (DBLIB_G(err).lastmsg) {
     174           0 :                 efree(DBLIB_G(err).lastmsg);
     175           0 :                 DBLIB_G(err).lastmsg = NULL;
     176             :         }
     177       20500 :         return SUCCESS;
     178             : }
     179             : 
     180       20507 : PHP_MINIT_FUNCTION(pdo_dblib)
     181             : {
     182       20507 :         if (FAIL == dbinit()) {
     183           0 :                 return FAILURE;
     184             :         }
     185             :         
     186       20507 :         if (FAILURE == php_pdo_register_driver(&pdo_dblib_driver)) {
     187           0 :                 return FAILURE;
     188             :         }
     189             :         
     190             : #if !PHP_DBLIB_IS_MSSQL
     191       20507 :         dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
     192       20507 :         dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
     193             : #endif
     194             : 
     195       20507 :         return SUCCESS;
     196             : }
     197             : 
     198       20541 : PHP_MSHUTDOWN_FUNCTION(pdo_dblib)
     199             : {
     200       20541 :         php_pdo_unregister_driver(&pdo_dblib_driver);
     201       20541 :         dbexit();
     202       20541 :         return SUCCESS;
     203             : }
     204             : 
     205         143 : PHP_MINFO_FUNCTION(pdo_dblib)
     206             : {
     207         143 :         php_info_print_table_start();
     208         143 :         php_info_print_table_header(2, "PDO Driver for "
     209             : #if PDO_DBLIB_IS_MSSQL
     210             :                 "MSSQL"
     211             : #elif defined(PHP_WIN32)
     212             :                 "FreeTDS/Sybase/MSSQL"
     213             : #else
     214             :                 "FreeTDS/Sybase"
     215             : #endif
     216             :                 " DB-lib", "enabled");
     217         143 :         php_info_print_table_row(2, "Flavour", PDO_DBLIB_FLAVOUR);
     218         143 :         php_info_print_table_end();
     219         143 : }
     220             : 

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:20 +0000 (47 hours ago)

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