@@ -32,6 +32,18 @@ enum pdo_odbc_conv_result {
32
32
PDO_ODBC_CONV_FAIL
33
33
};
34
34
35
+ /*
36
+ * Used for determing if we should use SQL_C_BINARY on binary columns
37
+ * XXX: Callers use what ODBC returns, rather that what user told PDO,
38
+ * need to propagate
39
+ */
40
+ static bool php_odbc_sqltype_is_binary (SWORD sqltype ) {
41
+ if (sqltype == SQL_BINARY || sqltype == SQL_VARBINARY || sqltype == SQL_LONGVARBINARY ) {
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+
35
47
static int pdo_odbc_sqltype_is_unicode (pdo_odbc_stmt * S , SWORD sqltype )
36
48
{
37
49
if (!S -> assume_utf8 ) return 0 ;
@@ -621,7 +633,7 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
621
633
S -> cols [colno ].is_long = 0 ;
622
634
623
635
rc = SQLBindCol (S -> stmt , colno + 1 ,
624
- S -> cols [colno ].is_unicode ? SQL_C_BINARY : SQL_C_CHAR ,
636
+ ( php_odbc_sqltype_is_binary ( S -> cols [colno ].coltype ) || S -> cols [ colno ]. is_unicode ) ? SQL_C_BINARY : SQL_C_CHAR ,
625
637
S -> cols [colno ].data ,
626
638
S -> cols [colno ].datalen + 1 , & S -> cols [colno ].fetched_len );
627
639
@@ -642,8 +654,15 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
642
654
643
655
static int odbc_stmt_get_column_meta (pdo_stmt_t * stmt , zend_long colno , zval * return_value )
644
656
{
657
+ pdo_odbc_stmt * S = (pdo_odbc_stmt * )stmt -> driver_data ;
658
+ pdo_odbc_column * C = & S -> cols [colno ];
659
+
645
660
array_init (return_value );
646
- add_assoc_long (return_value , "pdo_type" , PDO_PARAM_STR );
661
+ if (php_odbc_sqltype_is_binary (C -> coltype )) {
662
+ add_assoc_long (return_value , "pdo_type" , PDO_PARAM_BINARY );
663
+ } else {
664
+ add_assoc_long (return_value , "pdo_type" , PDO_PARAM_STR );
665
+ }
647
666
return 1 ;
648
667
}
649
668
@@ -652,6 +671,7 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
652
671
pdo_odbc_stmt * S = (pdo_odbc_stmt * )stmt -> driver_data ;
653
672
pdo_odbc_column * C = & S -> cols [colno ];
654
673
674
+ SQLSMALLINT c_type = (php_odbc_sqltype_is_binary (C -> coltype ) || C -> is_unicode ) ? SQL_C_BINARY : SQL_C_CHAR ;
655
675
/* if it is a column containing "long" data, perform late binding now */
656
676
if (C -> is_long ) {
657
677
SQLLEN orig_fetched_len = SQL_NULL_DATA ;
@@ -661,7 +681,7 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
661
681
* of 256 bytes; if there is more to be had, we then allocate
662
682
* bigger buffer for the caller to free */
663
683
664
- rc = SQLGetData (S -> stmt , colno + 1 , C -> is_unicode ? SQL_C_BINARY : SQL_C_CHAR , C -> data ,
684
+ rc = SQLGetData (S -> stmt , colno + 1 , c_type , C -> data ,
665
685
256 , & C -> fetched_len );
666
686
orig_fetched_len = C -> fetched_len ;
667
687
@@ -688,7 +708,7 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
688
708
do {
689
709
C -> fetched_len = 0 ;
690
710
/* read block. 256 bytes => 255 bytes are actually read, the last 1 is NULL */
691
- rc = SQLGetData (S -> stmt , colno + 1 , C -> is_unicode ? SQL_C_BINARY : SQL_C_CHAR , buf2 , 256 , & C -> fetched_len );
711
+ rc = SQLGetData (S -> stmt , colno + 1 , c_type , buf2 , 256 , & C -> fetched_len );
692
712
693
713
/* adjust `used` in case we have length info from the driver */
694
714
if (orig_fetched_len >= 0 && C -> fetched_len >= 0 ) {
0 commit comments