summaryrefslogtreecommitdiff
path: root/ext/pdo_odbc
diff options
context:
space:
mode:
authorAaron Piotrowski <aaron@trowski.com>2016-06-10 22:02:23 -0500
committerAaron Piotrowski <aaron@trowski.com>2016-06-10 22:02:23 -0500
commite3c681aa5cc71122a8d2fae42e6513fc413ccac8 (patch)
tree5f1df62f7b666028edb0ee1adf083a52d63df45a /ext/pdo_odbc
parentfb4e3085cbaa76eb8f28eebf848a81d1c0190067 (diff)
parent792e89385ca6fc722a03590722eb7745a2374720 (diff)
downloadphp-git-e3c681aa5cc71122a8d2fae42e6513fc413ccac8.tar.gz
Merge branch 'master' into throw-error-in-extensions
Diffstat (limited to 'ext/pdo_odbc')
-rw-r--r--ext/pdo_odbc/odbc_driver.c4
-rw-r--r--ext/pdo_odbc/odbc_stmt.c20
-rw-r--r--ext/pdo_odbc/pdo_odbc.c8
-rw-r--r--ext/pdo_odbc/php_pdo_odbc.h12
-rw-r--r--ext/pdo_odbc/php_pdo_odbc_int.h6
-rw-r--r--ext/pdo_odbc/tests/max_columns.phpt46
6 files changed, 74 insertions, 22 deletions
diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c
index 54440d0068..3a9300c5cd 100644
--- a/ext/pdo_odbc/odbc_driver.c
+++ b/ext/pdo_odbc/odbc_driver.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -393,7 +393,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
pdo_odbc_db_handle *H;
RETCODE rc;
int use_direct = 0;
- SQLUINTEGER cursor_lib;
+ zend_ulong cursor_lib;
H = pecalloc(1, sizeof(*H), dbh->is_persistent);
diff --git a/ext/pdo_odbc/odbc_stmt.c b/ext/pdo_odbc/odbc_stmt.c
index 6421cb6701..904c345f1b 100644
--- a/ext/pdo_odbc/odbc_stmt.c
+++ b/ext/pdo_odbc/odbc_stmt.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -574,6 +574,24 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
sizeof(S->cols[colno].colname)-1, &colnamelen,
&S->cols[colno].coltype, &colsize, NULL, NULL);
+ /* This fixes a known issue with SQL Server and (max) lengths,
+ may affect others as well. If we are SQL_VARCHAR,
+ SQL_VARBINARY, or SQL_WVARCHAR (or any of the long variations)
+ and zero is returned from colsize then consider it long */
+ if (0 == colsize &&
+ (S->cols[colno].coltype == SQL_VARCHAR ||
+ S->cols[colno].coltype == SQL_LONGVARCHAR ||
+#ifdef SQL_WVARCHAR
+ S->cols[colno].coltype == SQL_WVARCHAR ||
+#endif
+#ifdef SQL_WLONGVARCHAR
+ S->cols[colno].coltype == SQL_WLONGVARCHAR ||
+#endif
+ S->cols[colno].coltype == SQL_VARBINARY ||
+ S->cols[colno].coltype == SQL_LONGVARBINARY)) {
+ S->going_long = 1;
+ }
+
if (rc != SQL_SUCCESS) {
pdo_odbc_stmt_error("SQLDescribeCol");
if (rc != SQL_SUCCESS_WITH_INFO) {
diff --git a/ext/pdo_odbc/pdo_odbc.c b/ext/pdo_odbc/pdo_odbc.c
index aa40462da4..61f6fcc62b 100644
--- a/ext/pdo_odbc/pdo_odbc.c
+++ b/ext/pdo_odbc/pdo_odbc.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -37,12 +37,10 @@ const zend_function_entry pdo_odbc_functions[] = {
/* }}} */
/* {{{ pdo_odbc_deps[] */
-#if ZEND_MODULE_API_NO >= 20050922
static const zend_module_dep pdo_odbc_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
-#endif
/* }}} */
/* {{{ pdo_odbc_module_entry */
@@ -66,8 +64,8 @@ ZEND_GET_MODULE(pdo_odbc)
#endif
#ifdef SQL_ATTR_CONNECTION_POOLING
-SQLUINTEGER pdo_odbc_pool_on = SQL_CP_OFF;
-SQLUINTEGER pdo_odbc_pool_mode = SQL_CP_ONE_PER_HENV;
+zend_ulong pdo_odbc_pool_on = SQL_CP_OFF;
+zend_ulong pdo_odbc_pool_mode = SQL_CP_ONE_PER_HENV;
#endif
#if defined(DB2CLI_VER) && !defined(PHP_WIN32)
diff --git a/ext/pdo_odbc/php_pdo_odbc.h b/ext/pdo_odbc/php_pdo_odbc.h
index fb0be1b0b9..6686bef368 100644
--- a/ext/pdo_odbc/php_pdo_odbc.h
+++ b/ext/pdo_odbc/php_pdo_odbc.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -47,16 +47,6 @@ ZEND_BEGIN_MODULE_GLOBALS(pdo_odbc)
ZEND_END_MODULE_GLOBALS(pdo_odbc)
*/
-/* In every utility function you add that needs to use variables
- in php_pdo_odbc_globals, call TSRMLS_FETCH(); after declaring other
- variables used by that function, or better yet, pass in
- after the last function argument and declare your utility function
- with after the last declared argument. Always refer to
- the globals in your function as PDO_ODBC_G(variable). You are
- encouraged to rename these macros something shorter, see
- examples in any other php module directory.
-*/
-
#ifdef ZTS
#define PDO_ODBC_G(v) TSRMG(pdo_odbc_globals_id, zend_pdo_odbc_globals *, v)
#else
diff --git a/ext/pdo_odbc/php_pdo_odbc_int.h b/ext/pdo_odbc/php_pdo_odbc_int.h
index 1e51e71264..5306c96822 100644
--- a/ext/pdo_odbc/php_pdo_odbc_int.h
+++ b/ext/pdo_odbc/php_pdo_odbc_int.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -176,8 +176,8 @@ void pdo_odbc_init_error_table(void);
void pdo_odbc_fini_error_table(void);
#ifdef SQL_ATTR_CONNECTION_POOLING
-extern SQLUINTEGER pdo_odbc_pool_on;
-extern SQLUINTEGER pdo_odbc_pool_mode;
+extern zend_ulong pdo_odbc_pool_on;
+extern zend_ulong pdo_odbc_pool_mode;
#endif
enum {
diff --git a/ext/pdo_odbc/tests/max_columns.phpt b/ext/pdo_odbc/tests/max_columns.phpt
new file mode 100644
index 0000000000..301fa764ca
--- /dev/null
+++ b/ext/pdo_odbc/tests/max_columns.phpt
@@ -0,0 +1,46 @@
+--TEST--
+PDO ODBC varying character with max/no length
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo_odbc')) print 'skip not loaded';
+?>
+--FILE--
+<?php
+require 'ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory('ext/pdo_odbc/tests/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
+
+if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data varchar(max))')) {
+ if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data longtext)')) {
+ if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data CLOB)')) {
+ die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
+ }
+ }
+}
+
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$sizes = array(32, 64, 128, 253, 254, 255, 256, 257, 258, 512, 1024, 2048, 3998, 3999, 4000);
+
+$db->beginTransaction();
+$insert = $db->prepare('INSERT INTO TEST VALUES (?, ?)');
+foreach ($sizes as $num) {
+ $insert->execute(array($num, str_repeat('i', $num)));
+}
+$insert = null;
+$db->commit();
+
+foreach ($db->query('SELECT id, data from TEST') as $row) {
+ $expect = str_repeat('i', $row[0]);
+ if (strcmp($expect, $row[1])) {
+ echo "Failed on size $row[id]:\n";
+ printf("Expected %d bytes, got %d\n", strlen($expect), strlen($row['data']));
+ echo bin2hex($expect) . "\n";
+ echo bin2hex($row['data']) . "\n";
+ }
+}
+
+echo "Finished\n";
+
+--EXPECT--
+Finished