]> granicus.if.org Git - php/commitdiff
Fix for PECL #7755; use the displayable column width as the basis for our
authorWez Furlong <wez@php.net>
Wed, 11 Oct 2006 03:07:29 +0000 (03:07 +0000)
committerWez Furlong <wez@php.net>
Wed, 11 Oct 2006 03:07:29 +0000 (03:07 +0000)
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.

ext/pdo_odbc/odbc_stmt.c
ext/pdo_odbc/tests/long_columns.phpt

index ae751cb5ec3ce30dc6861e6987bb50151292ca97..d3ef4d3288ba2d728f4b5bb6103cc45c47636bd3 100755 (executable)
@@ -359,7 +359,10 @@ static int odbc_stmt_fetch(pdo_stmt_t *stmt,
        }
        rc = SQLFetchScroll(S->stmt, odbcori, offset);
 
-       if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
+       if (rc == SQL_SUCCESS) {
+               return 1;
+       }
+       if (rc == SQL_SUCCESS_WITH_INFO) {
                pdo_odbc_stmt_error("SQLFetchScroll");
                return 1;
        }
@@ -381,16 +384,30 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
        zend_bool dyn = FALSE;
        RETCODE rc;
        SWORD   colnamelen;
-       SDWORD  colsize;
+       SDWORD  colsize, displaysize;
 
        rc = SQLDescribeCol(S->stmt, colno+1, S->cols[colno].colname,
                        sizeof(S->cols[colno].colname)-1, &colnamelen,
                        &S->cols[colno].coltype, &colsize, NULL, NULL);
 
        if (rc != SQL_SUCCESS) {
-               pdo_odbc_stmt_error("SQLBindCol");
-               return 0;
+               pdo_odbc_stmt_error("SQLDescribeCol");
+               if (rc != SQL_SUCCESS_WITH_INFO) {
+                       return 0;
+               }
+       }
+
+       rc = SQLColAttribute(S->stmt, colno+1,
+                       SQL_DESC_DISPLAY_SIZE,
+                       NULL, 0, NULL, &displaysize);
+
+       if (rc != SQL_SUCCESS) {
+               pdo_odbc_stmt_error("SQLColAttribute");
+               if (rc != SQL_SUCCESS_WITH_INFO) {
+                       return 0;
+               }
        }
+       colsize = displaysize;
 
        col->maxlen = S->cols[colno].datalen = colsize;
        col->namelen = colnamelen;
index bc3abe94cac496a1d4a3e6eca1f58184d9896524..65ec2f96e90d6c18b7776c33341843860daa550f 100644 (file)
@@ -12,7 +12,9 @@ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
 
 if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data CLOB)')) {
        if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data longtext)')) {
-               die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
+               if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data varchar(4000))')) {
+                       die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
+               }
        }
 }