From 560649283cdd6b2c48a8fcd9e62f3de4f92d969f Mon Sep 17 00:00:00 2001 From: STANLEY SUFFICOOL Date: Wed, 22 Oct 2014 23:14:23 -0700 Subject: Implement Bug #66062 - pdo_dblib enable timeout parameter --- ext/pdo_dblib/dblib_driver.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'ext/pdo_dblib/dblib_driver.c') diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 40d4114879..323c805fca 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -61,7 +61,6 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS msg, einfo->dberr, einfo->severity, stmt ? stmt->active_query_string : ""); add_next_index_long(info, einfo->dberr); - // TODO: avoid reallocation ??? add_next_index_string(info, message); efree(message); add_next_index_long(info, einfo->oserr); @@ -145,10 +144,12 @@ static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sq static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC) { - pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; + + /* pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; */ + char *q; int l = 1; - + *quoted = q = safe_emalloc(2, unquotedlen, 3); *q++ = '\''; @@ -174,7 +175,6 @@ static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote static int pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh TSRMLS_DC) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; - RETCODE ret; if (FAIL == dbcmd(H->link, cmd)) { return 0; @@ -246,6 +246,23 @@ char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, unsigned int *len T return id; } +static int dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val TSRMLS_DC) +{ + switch(attr) { + case PDO_ATTR_TIMEOUT: + return 0; + default: + return 1; + } + +} + +static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value TSRMLS_DC) +{ + /* dblib_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; */ + return 0; +} + static struct pdo_dbh_methods dblib_methods = { dblib_handle_closer, dblib_handle_preparer, @@ -254,10 +271,10 @@ static struct pdo_dbh_methods dblib_methods = { dblib_handle_begin, /* begin */ dblib_handle_commit, /* commit */ dblib_handle_rollback, /* rollback */ - NULL, /*set attr */ + dblib_set_attr, /*set attr */ dblib_handle_last_id, /* last insert id */ dblib_fetch_error, /* fetch error */ - NULL, /* get attr */ + dblib_get_attribute, /* get attr */ NULL, /* check liveness */ NULL, /* get driver methods */ NULL, /* request shutdown */ @@ -303,6 +320,12 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, nvars); + if (driver_options) { + int timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC); + dbsetlogintime(timeout); /* Connection/Login Timeout */ + dbsettime(timeout); /* Statement Timeout */ + } + H = pecalloc(1, sizeof(*H), dbh->is_persistent); H->login = dblogin(); H->err.sqlstate = dbh->error_code; @@ -311,8 +334,8 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ goto cleanup; } - DBERRHANDLE(H->login, (EHANDLEFUNC) error_handler); - DBMSGHANDLE(H->login, (MHANDLEFUNC) msg_handler); + DBERRHANDLE(H->login, (EHANDLEFUNC) pdo_dblib_error_handler); + DBMSGHANDLE(H->login, (MHANDLEFUNC) pdo_dblib_msg_handler); if(vars[5].optval) { for(i=0;i Date: Fri, 24 Oct 2014 20:10:04 -0700 Subject: Fixed Bug #52885 - PDO_DBLIB: Binary data may be truncated Data containing characters in conflict with the server codepage or containing null char will throw an error. Implement binary quoting to allow binding of binary values. --- ext/pdo_dblib/dblib_driver.c | 69 ++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 21 deletions(-) (limited to 'ext/pdo_dblib/dblib_driver.c') diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 323c805fca..a433e8652c 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -144,30 +144,58 @@ static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sq static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC) { + + int useBinaryEncoding = 0; + const char * hex = "0123456789abcdef"; + int i; + char * q; + *quotedlen = 0; - /* pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; */ + /* + * Detect quoted length and if we should use binary encoding + */ + for(i=0;i unquoted[i] || 127 < unquoted[i] ) { + useBinaryEncoding = 1; + break; + } + if(unquoted[i] == '\'') ++*quotedlen; + ++*quotedlen; + } - char *q; - int l = 1; - - *quoted = q = safe_emalloc(2, unquotedlen, 3); - *q++ = '\''; - - while (unquotedlen--) { - if (*unquoted == '\'') { - *q++ = '\''; - *q++ = '\''; - l += 2; - } else { - *q++ = *unquoted; - ++l; + if(useBinaryEncoding) { + /* + * Binary safe quoting + * Will implicitly convert for all data types except Text, DateTime & SmallDateTime + * + */ + *quotedlen = (unquotedlen * 2) + 2; /* 2 chars per byte +2 for "0x" prefix */ + q = *quoted = emalloc(*quotedlen); + + *q++ = '0'; + *q++ = 'x'; + for (i=0;i>4)&0xF]; + *q++ = hex[ (*unquoted++)&0xF]; + } + } else { + /* Alpha/Numeric Quoting */ + *quotedlen += 2; /* +2 for opening, closing quotes */ + q = *quoted = emalloc(*quotedlen); + *q++ = '\''; + + for (i=0;ilink, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, id, (DBINT)-1); + *len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)-1); dbcancel(H->link); return id; @@ -285,7 +313,6 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ { pdo_dblib_db_handle *H; int i, nvars, nvers, ret = 0; - int *val; const pdo_dblib_keyval tdsver[] = { {"4.2",DBVERSION_42} -- cgit v1.2.1