From e5fa7c3ac1dd9c514874a2a2aebf0b88abdb9ff6 Mon Sep 17 00:00:00 2001 From: dpayne Date: Tue, 14 May 2013 01:05:22 -0700 Subject: [PATCH] Fixed bug https://bugs.php.net/patch-display.php?bug_id=54169 --- ext/pdo_odbc/odbc_stmt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ext/pdo_odbc/odbc_stmt.c b/ext/pdo_odbc/odbc_stmt.c index 6ee2fcd6becb..8485af1fda91 100644 --- a/ext/pdo_odbc/odbc_stmt.c +++ b/ext/pdo_odbc/odbc_stmt.c @@ -552,6 +552,24 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) 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) {