Patch computed_column_name.diff for PDO DBlib Bug #71667
Patch version 2016-02-25 23:21 UTC
Return to Bug #71667 |
Download this patch
Patch Revisions:
Developer: adam.baratz@gmail.com
diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c
index 26ee139d2d08d2ea16ec2ad8831e0ebd38d5c1f8..32430883c53aeb8f0b1b1288d63a92421852b4cf 100644
--- a/ext/pdo_dblib/dblib_driver.c
+++ b/ext/pdo_dblib/dblib_driver.c
@@ -100,6 +100,7 @@ static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
stmt->driver_data = S;
stmt->methods = &dblib_stmt_methods;
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
+ S->computed_column_name_count = 0;
S->err.sqlstate = stmt->error_code;
return 1;
diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c
index 19967ef7dad5573428649cf99c55c4dbc4b1db20..f8489ef4bb91774233cac367775a7c36626e73bb 100644
--- a/ext/pdo_dblib/dblib_stmt.c
+++ b/ext/pdo_dblib/dblib_stmt.c
@@ -103,9 +103,6 @@ static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC)
/* Cancel any pending results */
dbcancel(H->link);
- efree(stmt->columns);
- stmt->columns = NULL;
-
return 1;
}
@@ -113,9 +110,6 @@ static int pdo_dblib_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
{
pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
- efree(stmt->columns);
- stmt->columns = NULL;
-
efree(S);
return 1;
@@ -203,6 +197,10 @@ static int pdo_dblib_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
if(colno >= stmt->column_count || colno < 0) {
return FAILURE;
}
+
+ if (colno == 0) {
+ S->computed_column_name_count = 0;
+ }
col = &stmt->columns[colno];
fname = (char*)dbcolname(H->link, colno+1);
@@ -211,7 +209,14 @@ static int pdo_dblib_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
col->name = estrdup(fname);
col->namelen = strlen(col->name);
} else {
- col->namelen = spprintf(&col->name, NULL, "computed%d", colno);
+ if (S->computed_column_name_count > 0) {
+ col->namelen = spprintf(&col->name, 0, "computed%d", S->computed_column_name_count);
+ } else {
+ col->name = estrdup("computed");
+ col->namelen = strlen("computed");
+ }
+
+ S->computed_column_name_count++;
}
col->maxlen = dbcollen(H->link, colno+1);
col->param_type = PDO_PARAM_STR;
diff --git a/ext/pdo_dblib/php_pdo_dblib_int.h b/ext/pdo_dblib/php_pdo_dblib_int.h
index e31d31de4d1395c069f3601386e6cc90e2cc4c7b..71aec80e4aa706b2a5b6e9fd205c3f35a28d338d 100644
--- a/ext/pdo_dblib/php_pdo_dblib_int.h
+++ b/ext/pdo_dblib/php_pdo_dblib_int.h
@@ -118,6 +118,7 @@ typedef struct {
typedef struct {
pdo_dblib_db_handle *H;
pdo_dblib_err err;
+ unsigned int computed_column_name_count;
} pdo_dblib_stmt;
typedef struct {
diff --git a/ext/pdo_dblib/tests/computed_column_name.phpt b/ext/pdo_dblib/tests/computed_column_name.phpt
new file mode 100644
index 0000000000000000000000000000000000000000..959d01f9201f54007e55d648f0b63d5aed6c96cb
--- /dev/null
+++ b/ext/pdo_dblib/tests/computed_column_name.phpt
@@ -0,0 +1,34 @@
+--TEST--
+PDO_DBLIB: Set query timeouts
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+
+$stmt = $db->prepare("SELECT 1, 2 AS named, 3");
+$stmt->execute();
+var_dump($stmt->fetchAll());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(6) {
+ ["computed"]=>
+ int(1)
+ [0]=>
+ int(1)
+ ["named"]=>
+ int(2)
+ [1]=>
+ int(2)
+ ["computed1"]=>
+ int(3)
+ [2]=>
+ int(3)
+ }
+}
|