Skip to content

Commit c5df143

Browse files
committed
Fix for #36342; ODBC won't let you bind variables by buffer after "long"
columns. We simply add a flag that indicates if we've seen any long columns and will continue to bind the columns the slow way. While we're at it, increase the maximum length of the column names that we can handle.
1 parent fb7d5bd commit c5df143

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ext/pdo_odbc/odbc_stmt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
146146

147147
stmt->column_count = (int)colcount;
148148
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
149+
S->going_long = 0;
149150
}
150151

151152
return 1;
@@ -399,8 +400,9 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
399400
col->param_type = PDO_PARAM_STR;
400401

401402
/* tell ODBC to put it straight into our buffer, but only if it
402-
* isn't "long" data */
403-
if (colsize < 256) {
403+
* isn't "long" data, and only if we haven't already bound a long
404+
* column. */
405+
if (colsize < 256 && !S->going_long) {
404406
S->cols[colno].data = emalloc(colsize+1);
405407

406408
rc = SQLBindCol(S->stmt, colno+1, SQL_C_CHAR, S->cols[colno].data,
@@ -414,6 +416,7 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
414416
/* allocate a smaller buffer to keep around for smaller
415417
* "long" columns */
416418
S->cols[colno].data = emalloc(256);
419+
S->going_long = 1;
417420
}
418421

419422
return 1;
@@ -589,6 +592,7 @@ static int odbc_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC)
589592
SQLNumResultCols(S->stmt, &colcount);
590593
stmt->column_count = (int)colcount;
591594
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
595+
S->going_long = 0;
592596

593597
return 1;
594598
}

ext/pdo_odbc/php_pdo_odbc_int.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,16 @@ typedef struct {
136136
unsigned long datalen;
137137
long fetched_len;
138138
SWORD coltype;
139-
char colname[32];
139+
char colname[128];
140140
} pdo_odbc_column;
141141

142142
typedef struct {
143143
PDO_ODBC_HSTMT stmt;
144144
pdo_odbc_column *cols;
145145
pdo_odbc_db_handle *H;
146146
pdo_odbc_errinfo einfo;
147+
unsigned going_long:1;
148+
unsigned _spare:31;
147149
} pdo_odbc_stmt;
148150

149151
typedef struct {

0 commit comments

Comments
 (0)