Skip to content

Commit a97752e

Browse files
committed
Make long column buffer size single define
Could be configurable maybe, but best to avoid magic numbers even for a compile-time constant.
1 parent c4f8b0b commit a97752e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ext/pdo_odbc/odbc_stmt.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "php_pdo_odbc.h"
2727
#include "php_pdo_odbc_int.h"
2828

29+
/* Buffer size; bigger columns than this become a "long column" */
30+
#define LONG_COLUMN_BUFFER_SIZE 2048
31+
2932
enum pdo_odbc_conv_result {
3033
PDO_ODBC_CONV_NOT_REQUIRED,
3134
PDO_ODBC_CONV_OK,
@@ -615,7 +618,7 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
615618
/* tell ODBC to put it straight into our buffer, but only if it
616619
* isn't "long" data, and only if we haven't already bound a long
617620
* column. */
618-
if (colsize < 2048 && !S->going_long) {
621+
if (colsize < LONG_COLUMN_BUFFER_SIZE && !S->going_long) {
619622
S->cols[colno].data = emalloc(colsize+1);
620623
S->cols[colno].is_long = 0;
621624

@@ -631,7 +634,7 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
631634
} else {
632635
/* allocate a smaller buffer to keep around for smaller
633636
* "long" columns */
634-
S->cols[colno].data = emalloc(2048);
637+
S->cols[colno].data = emalloc(LONG_COLUMN_BUFFER_SIZE);
635638
S->going_long = 1;
636639
S->cols[colno].is_long = 1;
637640
}
@@ -661,10 +664,10 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
661664
* bigger buffer for the caller to free */
662665

663666
rc = SQLGetData(S->stmt, colno+1, C->is_unicode ? SQL_C_BINARY : SQL_C_CHAR, C->data,
664-
2048, &C->fetched_len);
667+
LONG_COLUMN_BUFFER_SIZE, &C->fetched_len);
665668
orig_fetched_len = C->fetched_len;
666669

667-
if (rc == SQL_SUCCESS && C->fetched_len < 2048) {
670+
if (rc == SQL_SUCCESS && C->fetched_len < LONG_COLUMN_BUFFER_SIZE) {
668671
/* all the data fit into our little buffer;
669672
* jump down to the generic bound data case */
670673
goto in_data;
@@ -694,7 +697,7 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
694697
*/
695698
ssize_t to_fetch_len;
696699
if (orig_fetched_len == SQL_NO_TOTAL) {
697-
to_fetch_len = C->datalen > 2047 ? 2047 : C->datalen;
700+
to_fetch_len = C->datalen > (LONG_COLUMN_BUFFER_SIZE - 1) ? (LONG_COLUMN_BUFFER_SIZE - 1) : C->datalen;
698701
} else {
699702
to_fetch_len = orig_fetched_len;
700703
}

0 commit comments

Comments
 (0)