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 - dblib_driver.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 50 280 17.9 %
Date: 2022-01-18 Functions: 2 14 14.3 %
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             : /* Cache of the server supported datatypes, initialized in handle_factory */
      34             : zval* pdo_dblib_datatypes;
      35             : 
      36           0 : static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
      37             : {
      38           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
      39           0 :         pdo_dblib_err *einfo = &H->err;
      40           0 :         pdo_dblib_stmt *S = NULL;
      41             :         char *message;
      42             :         char *msg;
      43             : 
      44           0 :         if (stmt) {
      45           0 :                 S = (pdo_dblib_stmt*)stmt->driver_data;
      46           0 :                 einfo = &S->err;
      47             :         }
      48             : 
      49           0 :         if (einfo->lastmsg) {
      50           0 :                 msg = einfo->lastmsg;
      51           0 :         } else if (DBLIB_G(err).lastmsg) {
      52           0 :                 msg = DBLIB_G(err).lastmsg;
      53           0 :                 DBLIB_G(err).lastmsg = NULL;
      54             :         } else {
      55           0 :                 msg = einfo->dberrstr;
      56             :         }
      57             : 
      58             :         /* don't return anything if there's nothing to return */
      59           0 :         if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
      60           0 :                 return 0;
      61             :         }
      62             : 
      63           0 :         spprintf(&message, 0, "%s [%d] (severity %d) [%s]",
      64             :                 msg, einfo->dberr, einfo->severity, stmt ? stmt->active_query_string : "");
      65             : 
      66           0 :         add_next_index_long(info, einfo->dberr);
      67           0 :         add_next_index_string(info, message);
      68           0 :         efree(message);
      69           0 :         add_next_index_long(info, einfo->oserr);
      70           0 :         add_next_index_long(info, einfo->severity);
      71           0 :         if (einfo->oserrstr) {
      72           0 :                 add_next_index_string(info, einfo->oserrstr);
      73             :         }
      74             : 
      75           0 :         return 1;
      76             : }
      77             : 
      78             : 
      79          93 : static int dblib_handle_closer(pdo_dbh_t *dbh)
      80             : {
      81          93 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
      82             : 
      83          93 :         if (H) {
      84          93 :                 pdo_dblib_err_dtor(&H->err);
      85          93 :                 if (H->link) {
      86           0 :                         dbclose(H->link);
      87           0 :                         H->link = NULL;
      88             :                 }
      89          93 :                 if (H->login) {
      90          93 :                         dbfreelogin(H->login);
      91          93 :                         H->login = NULL;
      92             :                 }
      93          93 :                 pefree(H, dbh->is_persistent);
      94          93 :                 dbh->driver_data = NULL;
      95             :         }
      96          93 :         return 0;
      97             : }
      98             : 
      99           0 : static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options)
     100             : {
     101           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     102           0 :         pdo_dblib_stmt *S = ecalloc(1, sizeof(*S));
     103             : 
     104           0 :         S->H = H;
     105           0 :         stmt->driver_data = S;
     106           0 :         stmt->methods = &dblib_stmt_methods;
     107           0 :         stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
     108           0 :         S->computed_column_name_count = 0;
     109           0 :         S->err.sqlstate = stmt->error_code;
     110             : 
     111           0 :         return 1;
     112             : }
     113             : 
     114           0 : static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)
     115             : {
     116           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     117             :         RETCODE ret, resret;
     118             : 
     119           0 :         dbsetuserdata(H->link, (BYTE*)&H->err);
     120             : 
     121           0 :         if (FAIL == dbcmd(H->link, sql)) {
     122           0 :                 return -1;
     123             :         }
     124             : 
     125           0 :         if (FAIL == dbsqlexec(H->link)) {
     126           0 :                 return -1;
     127             :         }
     128             : 
     129           0 :         resret = dbresults(H->link);
     130             : 
     131           0 :         if (resret == FAIL) {
     132           0 :                 return -1;
     133             :         }
     134             : 
     135           0 :         ret = dbnextrow(H->link);
     136           0 :         if (ret == FAIL) {
     137           0 :                 return -1;
     138             :         }
     139             : 
     140           0 :         if (dbnumcols(H->link) <= 0) {
     141           0 :                 return DBCOUNT(H->link);
     142             :         }
     143             : 
     144             :         /* throw away any rows it might have returned */
     145           0 :         dbcanquery(H->link);
     146             : 
     147           0 :         return DBCOUNT(H->link);
     148             : }
     149             : 
     150           0 : static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
     151             : {
     152           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     153           0 :         zend_bool use_national_character_set = 0;
     154             : 
     155             :         size_t i;
     156             :         char * q;
     157           0 :         *quotedlen = 0;
     158             : 
     159           0 :         if (H->assume_national_character_set_strings) {
     160           0 :                 use_national_character_set = 1;
     161             :         }
     162           0 :         if ((paramtype & PDO_PARAM_STR_NATL) == PDO_PARAM_STR_NATL) {
     163           0 :                 use_national_character_set = 1;
     164             :         }
     165           0 :         if ((paramtype & PDO_PARAM_STR_CHAR) == PDO_PARAM_STR_CHAR) {
     166           0 :                 use_national_character_set = 0;
     167             :         }
     168             : 
     169             :         /* Detect quoted length, adding extra char for doubled single quotes */
     170           0 :         for (i = 0; i < unquotedlen; i++) {
     171           0 :                 if (unquoted[i] == '\'') ++*quotedlen;
     172           0 :                 ++*quotedlen;
     173             :         }
     174             : 
     175           0 :         *quotedlen += 2; /* +2 for opening, closing quotes */
     176           0 :         if (use_national_character_set) {
     177           0 :                 ++*quotedlen; /* N prefix */
     178             :         }
     179           0 :         q = *quoted = emalloc(*quotedlen + 1); /* Add byte for terminal null */
     180           0 :         if (use_national_character_set) {
     181           0 :                 *q++ = 'N';
     182             :         }
     183           0 :         *q++ = '\'';
     184             : 
     185           0 :         for (i = 0; i < unquotedlen; i++) {
     186           0 :                 if (unquoted[i] == '\'') {
     187           0 :                         *q++ = '\'';
     188           0 :                         *q++ = '\'';
     189             :                 } else {
     190           0 :                         *q++ = unquoted[i];
     191             :                 }
     192             :         }
     193           0 :         *q++ = '\'';
     194             : 
     195           0 :         *q = 0;
     196             : 
     197           0 :         return 1;
     198             : }
     199             : 
     200           0 : static int pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh)
     201             : {
     202           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     203             : 
     204           0 :         if (FAIL == dbcmd(H->link, cmd)) {
     205           0 :                 return 0;
     206             :         }
     207             : 
     208           0 :         if (FAIL == dbsqlexec(H->link)) {
     209           0 :                 return 0;
     210             :         }
     211             : 
     212           0 :         return 1;
     213             : }
     214             : 
     215           0 : static int dblib_handle_begin(pdo_dbh_t *dbh)
     216             : {
     217           0 :         return pdo_dblib_transaction_cmd("BEGIN TRANSACTION", dbh);
     218             : }
     219             : 
     220           0 : static int dblib_handle_commit(pdo_dbh_t *dbh)
     221             : {
     222           0 :         return pdo_dblib_transaction_cmd("COMMIT TRANSACTION", dbh);
     223             : }
     224             : 
     225           0 : static int dblib_handle_rollback(pdo_dbh_t *dbh)
     226             : {
     227           0 :         return pdo_dblib_transaction_cmd("ROLLBACK TRANSACTION", dbh);
     228             : }
     229             : 
     230           0 : char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, size_t *len)
     231             : {
     232           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     233             : 
     234             :         RETCODE ret;
     235           0 :         char *id = NULL;
     236             : 
     237             :         /*
     238             :          * Would use scope_identity() but it's not implemented on Sybase
     239             :          */
     240             : 
     241           0 :         if (FAIL == dbcmd(H->link, "SELECT @@IDENTITY")) {
     242           0 :                 return NULL;
     243             :         }
     244             : 
     245           0 :         if (FAIL == dbsqlexec(H->link)) {
     246           0 :                 return NULL;
     247             :         }
     248             : 
     249           0 :         ret = dbresults(H->link);
     250           0 :         if (ret == FAIL || ret == NO_MORE_RESULTS) {
     251           0 :                 dbcancel(H->link);
     252           0 :                 return NULL;
     253             :         }
     254             : 
     255           0 :         ret = dbnextrow(H->link);
     256             : 
     257           0 :         if (ret == FAIL || ret == NO_MORE_ROWS) {
     258           0 :                 dbcancel(H->link);
     259           0 :                 return NULL;
     260             :         }
     261             : 
     262           0 :         if (dbdatlen(H->link, 1) == 0) {
     263           0 :                 dbcancel(H->link);
     264           0 :                 return NULL;
     265             :         }
     266             : 
     267           0 :         id = emalloc(32);
     268           0 :         *len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)-1);
     269             : 
     270           0 :         dbcancel(H->link);
     271           0 :         return id;
     272             : }
     273             : 
     274           0 : static int dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
     275             : {
     276           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     277             : 
     278           0 :         switch(attr) {
     279           0 :                 case PDO_ATTR_DEFAULT_STR_PARAM:
     280           0 :                         H->assume_national_character_set_strings = zval_get_long(val) == PDO_PARAM_STR_NATL ? 1 : 0;
     281           0 :                         return 1;
     282           0 :                 case PDO_ATTR_TIMEOUT:
     283             :                 case PDO_DBLIB_ATTR_QUERY_TIMEOUT:
     284           0 :                         return SUCCEED == dbsettime(zval_get_long(val)) ? 1 : 0;
     285           0 :                 case PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER:
     286           0 :                         H->stringify_uniqueidentifier = zval_get_long(val);
     287           0 :                         return 1;
     288           0 :                 case PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS:
     289           0 :                         H->skip_empty_rowsets = zval_is_true(val);
     290           0 :                         return 1;
     291           0 :                 case PDO_DBLIB_ATTR_DATETIME_CONVERT:
     292           0 :                         H->datetime_convert = zval_get_long(val);
     293           0 :                         return 1;
     294           0 :                 default:
     295           0 :                         return 0;
     296             :         }
     297             : }
     298             : 
     299           0 : static void dblib_get_tds_version(zval *return_value, int tds)
     300             : {
     301           0 :         switch (tds) {
     302           0 :                 case DBTDS_2_0:
     303           0 :                         ZVAL_STRING(return_value, "2.0");
     304           0 :                         break;
     305             : 
     306           0 :                 case DBTDS_3_4:
     307           0 :                         ZVAL_STRING(return_value, "3.4");
     308           0 :                         break;
     309             : 
     310           0 :                 case DBTDS_4_0:
     311           0 :                         ZVAL_STRING(return_value, "4.0");
     312           0 :                         break;
     313             : 
     314           0 :                 case DBTDS_4_2:
     315           0 :                         ZVAL_STRING(return_value, "4.2");
     316           0 :                         break;
     317             : 
     318           0 :                 case DBTDS_4_6:
     319           0 :                         ZVAL_STRING(return_value, "4.6");
     320           0 :                         break;
     321             : 
     322           0 :                 case DBTDS_4_9_5:
     323           0 :                         ZVAL_STRING(return_value, "4.9.5");
     324           0 :                         break;
     325             : 
     326           0 :                 case DBTDS_5_0:
     327           0 :                         ZVAL_STRING(return_value, "5.0");
     328           0 :                         break;
     329             : 
     330             : #ifdef DBTDS_7_0
     331           0 :                 case DBTDS_7_0:
     332           0 :                         ZVAL_STRING(return_value, "7.0");
     333           0 :                         break;
     334             : #endif
     335             : 
     336             : #ifdef DBTDS_7_1
     337           0 :                 case DBTDS_7_1:
     338           0 :                         ZVAL_STRING(return_value, "7.1");
     339           0 :                         break;
     340             : #endif
     341             : 
     342             : #ifdef DBTDS_7_2
     343           0 :                 case DBTDS_7_2:
     344           0 :                         ZVAL_STRING(return_value, "7.2");
     345           0 :                         break;
     346             : #endif
     347             : 
     348             : #ifdef DBTDS_7_3
     349             :                 case DBTDS_7_3:
     350             :                         ZVAL_STRING(return_value, "7.3");
     351             :                         break;
     352             : #endif
     353             : 
     354             : #ifdef DBTDS_7_4
     355             :                 case DBTDS_7_4:
     356             :                         ZVAL_STRING(return_value, "7.4");
     357             :                         break;
     358             : #endif
     359             : 
     360           0 :                 default:
     361           0 :                         ZVAL_FALSE(return_value);
     362           0 :                         break;
     363             :         }
     364           0 : }
     365             : 
     366           0 : static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value)
     367             : {
     368           0 :         pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
     369             : 
     370           0 :         switch (attr) {
     371           0 :                 case PDO_ATTR_DEFAULT_STR_PARAM:
     372           0 :                         ZVAL_LONG(return_value, H->assume_national_character_set_strings ? PDO_PARAM_STR_NATL : PDO_PARAM_STR_CHAR);
     373           0 :                         break;
     374             : 
     375           0 :                 case PDO_ATTR_EMULATE_PREPARES:
     376             :                         /* this is the only option available, but expose it so common tests and whatever else can introspect */
     377           0 :                         ZVAL_TRUE(return_value);
     378           0 :                         break;
     379             : 
     380           0 :                 case PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER:
     381           0 :                         ZVAL_BOOL(return_value, H->stringify_uniqueidentifier);
     382           0 :                         break;
     383             : 
     384           0 :                 case PDO_DBLIB_ATTR_VERSION:
     385           0 :                         ZVAL_STRING(return_value, dbversion());
     386           0 :                         break;
     387             : 
     388           0 :                 case PDO_DBLIB_ATTR_TDS_VERSION:
     389           0 :                         dblib_get_tds_version(return_value, dbtds(H->link));
     390           0 :                         break;
     391             : 
     392           0 :                 case PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS:
     393           0 :                         ZVAL_BOOL(return_value, H->skip_empty_rowsets);
     394           0 :                         break;
     395             : 
     396           0 :                 case PDO_DBLIB_ATTR_DATETIME_CONVERT:
     397           0 :                         ZVAL_BOOL(return_value, H->datetime_convert);
     398           0 :                         break;
     399             : 
     400           0 :                 default:
     401           0 :                         return 0;
     402             :         }
     403             : 
     404           0 :         return 1;
     405             : }
     406             : 
     407             : static const struct pdo_dbh_methods dblib_methods = {
     408             :         dblib_handle_closer,
     409             :         dblib_handle_preparer,
     410             :         dblib_handle_doer,
     411             :         dblib_handle_quoter,
     412             :         dblib_handle_begin, /* begin */
     413             :         dblib_handle_commit, /* commit */
     414             :         dblib_handle_rollback, /* rollback */
     415             :         dblib_set_attr, /*set attr */
     416             :         dblib_handle_last_id, /* last insert id */
     417             :         dblib_fetch_error, /* fetch error */
     418             :         dblib_get_attribute, /* get attr */
     419             :         NULL, /* check liveness */
     420             :         NULL, /* get driver methods */
     421             :         NULL, /* request shutdown */
     422             :         NULL  /* in transaction */
     423             : };
     424             : 
     425          93 : static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
     426             : {
     427             :         pdo_dblib_db_handle *H;
     428          93 :         int i, nvars, nvers, ret = 0;
     429             : 
     430          93 :         const pdo_dblib_keyval tdsver[] = {
     431             :                  {"4.2",DBVERSION_42}
     432             :                 ,{"4.6",DBVERSION_46}
     433             :                 ,{"5.0",DBVERSION_70} /* FIXME: This does not work with Sybase, but environ will */
     434             :                 ,{"6.0",DBVERSION_70}
     435             :                 ,{"7.0",DBVERSION_70}
     436             : #ifdef DBVERSION_71
     437             :                 ,{"7.1",DBVERSION_71}
     438             : #endif
     439             : #ifdef DBVERSION_72
     440             :                 ,{"7.2",DBVERSION_72}
     441             :                 ,{"8.0",DBVERSION_72}
     442             : #endif
     443             : #ifdef DBVERSION_73
     444             :                 ,{"7.3",DBVERSION_73}
     445             : #endif
     446             : #ifdef DBVERSION_74
     447             :                 ,{"7.4",DBVERSION_74}
     448             : #endif
     449             :                 ,{"10.0",DBVERSION_100}
     450             :                 ,{"auto",0} /* Only works with FreeTDS. Other drivers will bork */
     451             : 
     452             :         };
     453             : 
     454          93 :         struct pdo_data_src_parser vars[] = {
     455             :                 { "charset",  NULL,   0 }
     456             :                 ,{ "appname", "PHP " PDO_DBLIB_FLAVOUR,     0 }
     457             :                 ,{ "host",            "127.0.0.1", 0 }
     458             :                 ,{ "dbname",  NULL,   0 }
     459             :                 ,{ "secure",  NULL,   0 } /* DBSETLSECURE */
     460             :                 ,{ "version", NULL,   0 } /* DBSETLVERSION */
     461             :         };
     462             : 
     463          93 :         nvars = sizeof(vars)/sizeof(vars[0]);
     464          93 :         nvers = sizeof(tdsver)/sizeof(tdsver[0]);
     465             : 
     466          93 :         php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, nvars);
     467             : 
     468          93 :         H = pecalloc(1, sizeof(*H), dbh->is_persistent);
     469          93 :         H->login = dblogin();
     470          93 :         H->err.sqlstate = dbh->error_code;
     471          93 :         H->assume_national_character_set_strings = 0;
     472          93 :         H->stringify_uniqueidentifier = 0;
     473          93 :         H->skip_empty_rowsets = 0;
     474          93 :         H->datetime_convert = 0;
     475             : 
     476          93 :         if (!H->login) {
     477           0 :                 goto cleanup;
     478             :         }
     479             : 
     480          93 :         if (driver_options) {
     481           0 :                 int connect_timeout = pdo_attr_lval(driver_options, PDO_DBLIB_ATTR_CONNECTION_TIMEOUT, -1);
     482           0 :                 int query_timeout = pdo_attr_lval(driver_options, PDO_DBLIB_ATTR_QUERY_TIMEOUT, -1);
     483           0 :                 int timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30);
     484             : 
     485           0 :                 if (connect_timeout == -1) {
     486           0 :                         connect_timeout = timeout;
     487             :                 }
     488           0 :                 if (query_timeout == -1) {
     489           0 :                         query_timeout = timeout;
     490             :                 }
     491             : 
     492           0 :                 dbsetlogintime(connect_timeout); /* Connection/Login Timeout */
     493           0 :                 dbsettime(query_timeout); /* Statement Timeout */
     494             : 
     495           0 :                 H->assume_national_character_set_strings = pdo_attr_lval(driver_options, PDO_ATTR_DEFAULT_STR_PARAM, 0) == PDO_PARAM_STR_NATL ? 1 : 0;
     496           0 :                 H->stringify_uniqueidentifier = pdo_attr_lval(driver_options, PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, 0);
     497           0 :                 H->skip_empty_rowsets = pdo_attr_lval(driver_options, PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS, 0);
     498           0 :                 H->datetime_convert = pdo_attr_lval(driver_options, PDO_DBLIB_ATTR_DATETIME_CONVERT, 0);
     499             :         }
     500             : 
     501          93 :         DBERRHANDLE(H->login, (EHANDLEFUNC) pdo_dblib_error_handler);
     502          93 :         DBMSGHANDLE(H->login, (MHANDLEFUNC) pdo_dblib_msg_handler);
     503             : 
     504          93 :         if(vars[5].optval) {
     505           0 :                 for(i=0;i<nvers;i++) {
     506           0 :                         if(strcmp(vars[5].optval,tdsver[i].key) == 0) {
     507           0 :                                 if(FAIL==dbsetlversion(H->login, tdsver[i].value)) {
     508           0 :                                         pdo_raise_impl_error(dbh, NULL, "HY000", "PDO_DBLIB: Failed to set version specified in connection string.");
     509           0 :                                         goto cleanup;
     510             :                                 }
     511           0 :                                 break;
     512             :                         }
     513             :                 }
     514             : 
     515           0 :                 if (i==nvers) {
     516           0 :                         printf("Invalid version '%s'\n", vars[5].optval);
     517           0 :                         pdo_raise_impl_error(dbh, NULL, "HY000", "PDO_DBLIB: Invalid version specified in connection string.");
     518           0 :                         goto cleanup; /* unknown version specified */
     519             :                 }
     520             :         }
     521             : 
     522          93 :         if (dbh->username) {
     523          93 :                 if(FAIL == DBSETLUSER(H->login, dbh->username)) {
     524           0 :                         goto cleanup;
     525             :                 }
     526             :         }
     527             : 
     528          93 :         if (dbh->password) {
     529          93 :                 if(FAIL == DBSETLPWD(H->login, dbh->password)) {
     530           0 :                         goto cleanup;
     531             :                 }
     532             :         }
     533             : 
     534             : #if !PHP_DBLIB_IS_MSSQL
     535          93 :         if (vars[0].optval) {
     536           0 :                 DBSETLCHARSET(H->login, vars[0].optval);
     537             :         }
     538             : #endif
     539             : 
     540          93 :         DBSETLAPP(H->login, vars[1].optval);
     541             : 
     542             : /* DBSETLDBNAME is only available in FreeTDS 0.92 or above */
     543             : #ifdef DBSETLDBNAME
     544          93 :         if (vars[3].optval) {
     545          93 :                 if(FAIL == DBSETLDBNAME(H->login, vars[3].optval)) goto cleanup;
     546             :         }
     547             : #endif
     548             : 
     549          93 :         H->link = dbopen(H->login, vars[2].optval);
     550             : 
     551          93 :         if (!H->link) {
     552          93 :                 goto cleanup;
     553             :         }
     554             : 
     555             : /*
     556             :  * FreeTDS < 0.92 does not support the DBSETLDBNAME option
     557             :  * Send use database here after login (Will not work with SQL Azure)
     558             :  */
     559             : #ifndef DBSETLDBNAME
     560             :         if (vars[3].optval) {
     561             :                 if(FAIL == dbuse(H->link, vars[3].optval)) goto cleanup;
     562             :         }
     563             : #endif
     564             : 
     565             : #if PHP_DBLIB_IS_MSSQL
     566             :         /* dblib do not return more than this length from text/image */
     567             :         DBSETOPT(H->link, DBTEXTLIMIT, "2147483647");
     568             : #endif
     569             : 
     570             :         /* limit text/image from network */
     571           0 :         DBSETOPT(H->link, DBTEXTSIZE, "2147483647");
     572             : 
     573             :         /* allow double quoted indentifiers */
     574           0 :         DBSETOPT(H->link, DBQUOTEDIDENT, "1");
     575             : 
     576           0 :         ret = 1;
     577           0 :         dbh->max_escaped_char_length = 2;
     578           0 :         dbh->alloc_own_columns = 1;
     579             : 
     580          93 : cleanup:
     581         651 :         for (i = 0; i < nvars; i++) {
     582         558 :                 if (vars[i].freeme) {
     583         186 :                         efree(vars[i].optval);
     584             :                 }
     585             :         }
     586             : 
     587          93 :         dbh->methods = &dblib_methods;
     588          93 :         dbh->driver_data = H;
     589             : 
     590          93 :         if (!ret) {
     591          93 :                 zend_throw_exception_ex(php_pdo_get_exception(), DBLIB_G(err).dberr,
     592             :                         "SQLSTATE[%s] %s (severity %d)",
     593             :                         DBLIB_G(err).sqlstate,
     594             :                         DBLIB_G(err).dberrstr,
     595             :                         DBLIB_G(err).severity);
     596             :         }
     597             : 
     598          93 :         return ret;
     599             : }
     600             : 
     601             : const pdo_driver_t pdo_dblib_driver = {
     602             : #if PDO_DBLIB_IS_MSSQL
     603             :         PDO_DRIVER_HEADER(mssql),
     604             : #elif defined(PHP_WIN32)
     605             : #define PDO_DBLIB_IS_SYBASE
     606             :         PDO_DRIVER_HEADER(sybase),
     607             : #else
     608             :         PDO_DRIVER_HEADER(dblib),
     609             : #endif
     610             :         pdo_dblib_handle_factory
     611             : };

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.