summaryrefslogtreecommitdiff
path: root/ext/pdo_dblib/dblib_driver.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2014-11-18 21:18:52 +0100
committerAnatol Belski <ab@php.net>2014-11-18 21:18:52 +0100
commitc6bad96f306df8e8b656472e618283ced5083cdb (patch)
tree7e5b52aa07777f0336b0944a228bf66f8f56b31f /ext/pdo_dblib/dblib_driver.c
parent4262663e4caa82ba17666781a95bdcb872b4e109 (diff)
parent64a39dc7b07d4b54d050a3a5c15045fe91c0b651 (diff)
downloadphp-git-c6bad96f306df8e8b656472e618283ced5083cdb.tar.gz
Merge remote-tracking branch 'origin/master' into native-tls
* origin/master: (398 commits) NEWS add test for bug #68381 Fixed bug #68381 Set FPM log level earlier during init proper dllexport move to size_t where zend_string is used internally fix some datatype mismatches return after the warning, to fix uninitialized salt usage fix datatype mismatches add missing type specifier fix datatype mismatches fix unsigned check "extern" shouldn't be used for definitions joined identical conditional blocks simplify fpm tests SEND_VAR_NO_REF optimization Add test for bug #68442 Add various tests for FPM - covering recent bugs (68420, 68421, 68423, 68428) - for UDS - for ping and status URI - for multi pool and multi mode Include small MIT FastCGI client library from https://github.com/adoy/PHP-FastCGI-Client Get rid of zend_free_op structure (use zval* instead). Get rid of useless TSRMLS arguments. Add new FPM test for IPv4/IPv6 ... Conflicts: win32/build/config.w32
Diffstat (limited to 'ext/pdo_dblib/dblib_driver.c')
-rw-r--r--ext/pdo_dblib/dblib_driver.c69
1 files changed, 48 insertions, 21 deletions
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<unquotedlen;i++) {
+ if( 32 > 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<unquotedlen;i++) {
+ *q++ = hex[ (*unquoted>>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;i<unquotedlen;i++) {
+ if (unquoted[i] == '\'') {
+ *q++ = '\'';
+ *q++ = '\'';
+ } else {
+ *q++ = unquoted[i];
+ }
}
- unquoted++;
+ *q++ = '\'';
}
- *q++ = '\'';
- *q++ = '\0';
- *quotedlen = l+1;
+ *q = 0;
return 1;
}
@@ -240,7 +268,7 @@ char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, unsigned int *len T
}
id = emalloc(32);
- *len = dbconvert(NULL, (dbcoltype(H->link, 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}