|
51 | 51 | #define FETCH_ROW 1 |
52 | 52 | #define FETCH_ARRAY 2 |
53 | 53 |
|
54 | | -typedef struct { |
55 | | - unsigned short vary_length; |
56 | | - char vary_string[1]; |
57 | | -} IBVARY; |
58 | | - |
59 | 54 | static int le_query; |
60 | 55 |
|
61 | 56 | static void _php_ibase_alloc_xsqlda_vars(XSQLDA *sqlda, ISC_SHORT *nullinds); |
@@ -96,6 +91,7 @@ static void _php_ibase_free_query(ibase_query *ib_query) /* {{{ */ |
96 | 91 | if(ib_query->query)efree(ib_query->query); |
97 | 92 | if(ib_query->ht_aliases)zend_array_destroy(ib_query->ht_aliases); |
98 | 93 | if(ib_query->ht_ind)zend_array_destroy(ib_query->ht_ind); |
| 94 | + if(ib_query->sql_types)efree(ib_query->sql_types); |
99 | 95 |
|
100 | 96 | efree(ib_query); |
101 | 97 | } |
@@ -314,12 +310,18 @@ static int _php_ibase_prepare(ibase_query **new_query, ibase_db_link *link, /* { |
314 | 310 | ib_query->in_sqlda->sqln = ib_query->in_fields_count; |
315 | 311 | ib_query->in_sqlda->version = SQLDA_CURRENT_VERSION; |
316 | 312 |
|
| 313 | + ib_query->sql_types = emalloc(sizeof(*ib_query->sql_types) * ib_query->in_fields_count); |
| 314 | + |
317 | 315 | if (isc_dsql_describe_bind(IB_STATUS, &ib_query->stmt, SQLDA_CURRENT_VERSION, ib_query->in_sqlda)) { |
318 | 316 | IBDEBUG("isc_dsql_describe_bind() failed\n"); |
319 | 317 | _php_ibase_error(); |
320 | 318 | goto _php_ibase_alloc_query_error; |
321 | 319 | } |
322 | 320 |
|
| 321 | + for (int i = 0; i < ib_query->in_fields_count; i++) { |
| 322 | + ib_query->sql_types[i] = ib_query->in_sqlda->sqlvar[i].sqltype; |
| 323 | + } |
| 324 | + |
323 | 325 | assert(ib_query->in_sqlda->sqln == ib_query->in_sqlda->sqld); |
324 | 326 | assert(ib_query->in_sqlda->sqld == ib_query->in_fields_count); |
325 | 327 |
|
@@ -567,10 +569,12 @@ static int _php_ibase_bind(ibase_query *ib_query, zval *b_vars) /* {{{ */ |
567 | 569 | int i, array_cnt = 0, rv = SUCCESS; |
568 | 570 |
|
569 | 571 | for (i = 0; i < sqlda->sqld; ++i) { /* bound vars */ |
570 | | - |
571 | 572 | zval *b_var = &b_vars[i]; |
572 | 573 | XSQLVAR *var = &sqlda->sqlvar[i]; |
573 | 574 |
|
| 575 | + // We need keep track of original type because XSQLVAR type could get modified |
| 576 | + var->sqltype = ib_query->sql_types[i]; |
| 577 | + |
574 | 578 | var->sqlind = &buf[i].nullind; |
575 | 579 | var->sqldata = (void*)&buf[i].val; |
576 | 580 |
|
@@ -742,7 +746,7 @@ static int _php_ibase_bind(ibase_query *ib_query, zval *b_vars) /* {{{ */ |
742 | 746 | rv = FAILURE; |
743 | 747 | continue; |
744 | 748 | } |
745 | | - var->sqltype = SQL_BOOLEAN; |
| 749 | + // var->sqltype = SQL_BOOLEAN; |
746 | 750 | continue; |
747 | 751 | #endif |
748 | 752 | case SQL_ARRAY: |
@@ -781,13 +785,13 @@ static int _php_ibase_bind(ibase_query *ib_query, zval *b_vars) /* {{{ */ |
781 | 785 | } |
782 | 786 | ++array_cnt; |
783 | 787 | continue; |
784 | | - } /* switch */ |
| 788 | + } /* switch */ |
785 | 789 |
|
786 | | - /* we end up here if none of the switch cases handled the field */ |
787 | | - convert_to_string(b_var); |
788 | | - var->sqldata = Z_STRVAL_P(b_var); |
789 | | - var->sqllen = (ISC_SHORT)Z_STRLEN_P(b_var); |
790 | | - var->sqltype = SQL_TEXT; |
| 790 | + /* we end up here if none of the switch cases handled the field */ |
| 791 | + convert_to_string(b_var); |
| 792 | + var->sqldata = Z_STRVAL_P(b_var); |
| 793 | + var->sqllen = (ISC_SHORT)Z_STRLEN_P(b_var); |
| 794 | + var->sqltype = SQL_TEXT; // Here: sqltype is modfied, can't rely on it for next calls |
791 | 795 | } /* for */ |
792 | 796 | return rv; |
793 | 797 | } |
|
0 commit comments