Skip to content

ODBC bug fix for varchars returning with length zero #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down