Skip to content

Commit 3028f74

Browse files
committed
Fix for PECL php#7755; use the displayable column width as the basis for our
buffer size, as the raw column size can be too small when requesting a string representation. Also fix up bogus error output when fetching, and another one of the test cases to make it run against SQL Server 2005.
1 parent 897b9ff commit 3028f74

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

ext/pdo_odbc/odbc_stmt.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ static int odbc_stmt_fetch(pdo_stmt_t *stmt,
359359
}
360360
rc = SQLFetchScroll(S->stmt, odbcori, offset);
361361

362-
if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
362+
if (rc == SQL_SUCCESS) {
363+
return 1;
364+
}
365+
if (rc == SQL_SUCCESS_WITH_INFO) {
363366
pdo_odbc_stmt_error("SQLFetchScroll");
364367
return 1;
365368
}
@@ -381,16 +384,30 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
381384
zend_bool dyn = FALSE;
382385
RETCODE rc;
383386
SWORD colnamelen;
384-
SDWORD colsize;
387+
SDWORD colsize, displaysize;
385388

386389
rc = SQLDescribeCol(S->stmt, colno+1, S->cols[colno].colname,
387390
sizeof(S->cols[colno].colname)-1, &colnamelen,
388391
&S->cols[colno].coltype, &colsize, NULL, NULL);
389392

390393
if (rc != SQL_SUCCESS) {
391-
pdo_odbc_stmt_error("SQLBindCol");
392-
return 0;
394+
pdo_odbc_stmt_error("SQLDescribeCol");
395+
if (rc != SQL_SUCCESS_WITH_INFO) {
396+
return 0;
397+
}
398+
}
399+
400+
rc = SQLColAttribute(S->stmt, colno+1,
401+
SQL_DESC_DISPLAY_SIZE,
402+
NULL, 0, NULL, &displaysize);
403+
404+
if (rc != SQL_SUCCESS) {
405+
pdo_odbc_stmt_error("SQLColAttribute");
406+
if (rc != SQL_SUCCESS_WITH_INFO) {
407+
return 0;
408+
}
393409
}
410+
colsize = displaysize;
394411

395412
col->maxlen = S->cols[colno].datalen = colsize;
396413
col->namelen = colnamelen;

ext/pdo_odbc/tests/long_columns.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
1212

1313
if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data CLOB)')) {
1414
if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data longtext)')) {
15-
die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
15+
if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data varchar(4000))')) {
16+
die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
17+
}
1618
}
1719
}
1820

0 commit comments

Comments
 (0)