1
1
/*
2
2
+----------------------------------------------------------------------+
3
- | PHP Version 7 |
3
+ | PHP Version 7, 8 |
4
4
+----------------------------------------------------------------------+
5
5
| Copyright (c) The PHP Group |
6
6
+----------------------------------------------------------------------+
12
12
| obtain it through the world-wide-web, please send a note to |
13
13
| [email protected] so we can mail you a copy immediately. |
14
14
+----------------------------------------------------------------------+
15
- | Authors: Ard Biesheuvel <[email protected] > |
15
+ | Authors: Jouni Ahto <[email protected] > |
16
+ | Andrew Avdeev <[email protected] > |
17
+ | Ard Biesheuvel <[email protected] > |
18
+ | Martin Koeditz <[email protected] > |
19
+ | others |
20
+ +----------------------------------------------------------------------+
21
+ | You'll find history on Github |
22
+ | https://github.com/FirebirdSQL/php-firebird/commits/master |
16
23
+----------------------------------------------------------------------+
17
24
*/
18
25
@@ -87,7 +94,10 @@ typedef struct {
87
94
*/
88
95
typedef struct {
89
96
union {
90
- zend_bool bval ;
97
+ // Boolean data type exists since FB 3.0
98
+ #ifdef SQL_BOOLEAN
99
+ FB_BOOLEAN bval ;
100
+ #endif
91
101
short sval ;
92
102
float fval ;
93
103
ISC_LONG lval ;
@@ -250,10 +260,13 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
250
260
a -> el_type = SQL_TEXT ;
251
261
a -> el_size = ar_desc -> array_desc_length ;
252
262
break ;
253
- case blr_bool :
254
- a -> el_type = SQL_BOOLEAN ;
255
- a -> el_size = sizeof (zend_bool );
256
- break ;
263
+ // Boolean data type exists since FB 3.0
264
+ #ifdef SQL_BOOLEAN
265
+ case blr_bool :
266
+ a -> el_type = SQL_BOOLEAN ;
267
+ a -> el_size = sizeof (FB_BOOLEAN );
268
+ break ;
269
+ #endif
257
270
case blr_short :
258
271
a -> el_type = SQL_SHORT ;
259
272
a -> el_size = sizeof (short );
@@ -595,11 +608,14 @@ static int _php_ibase_bind_array(zval *val, char *buf, zend_ulong buf_size, /* {
595
608
convert_to_double (val );
596
609
* (float * ) buf = (float ) Z_DVAL_P (val );
597
610
break ;
598
- case SQL_BOOLEAN :
599
- convert_to_boolean (val );
600
- // On Windows error unresolved symbol Z_BVAL_P is thrown, so we use Z_LVAL_P
601
- * (zend_bool * ) buf = Z_LVAL_P (val );
602
- break ;
611
+ // Boolean data type exists since FB 3.0
612
+ #ifdef SQL_BOOLEAN
613
+ case SQL_BOOLEAN :
614
+ convert_to_boolean (val );
615
+ // On Windows error unresolved symbol Z_BVAL_P is thrown, so we use Z_LVAL_P
616
+ * (FB_BOOLEAN * ) buf = Z_LVAL_P (val );
617
+ break ;
618
+ #endif
603
619
case SQL_DOUBLE :
604
620
convert_to_double (val );
605
621
* (double * ) buf = Z_DVAL_P (val );
@@ -786,38 +802,39 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
786
802
buf [i ].val .qval = ib_blob .bl_qd ;
787
803
}
788
804
continue ;
789
-
805
+ // Boolean data type exists since FB 3.0
806
+ #ifdef SQL_BOOLEAN
790
807
case SQL_BOOLEAN :
791
808
792
809
switch (Z_TYPE_P (b_var )) {
793
810
case IS_LONG :
794
811
case IS_DOUBLE :
795
812
case IS_TRUE :
796
813
case IS_FALSE :
797
- * (bool * )var -> sqldata = zend_is_true (b_var ) ? 1 : 0 ;
814
+ * (FB_BOOLEAN * )var -> sqldata = zend_is_true (b_var ) ? FB_TRUE : FB_FALSE ;
798
815
break ;
799
816
case IS_STRING :
800
817
{
801
818
zend_long lval ;
802
819
double dval ;
803
820
804
821
if ((Z_STRLEN_P (b_var ) == 0 )) {
805
- * (bool * )var -> sqldata = 0 ;
822
+ * (FB_BOOLEAN * )var -> sqldata = FB_FALSE ;
806
823
break ;
807
824
}
808
825
809
826
switch (is_numeric_string (Z_STRVAL_P (b_var ), Z_STRLEN_P (b_var ), & lval , & dval , 0 )) {
810
827
case IS_LONG :
811
- * (bool * )var -> sqldata = (lval != 0 ) ? 1 : 0 ;
828
+ * (FB_BOOLEAN * )var -> sqldata = (lval != 0 ) ? FB_TRUE : FB_FALSE ;
812
829
break ;
813
830
case IS_DOUBLE :
814
- * (bool * )var -> sqldata = (dval != 0 ) ? 1 : 0 ;
831
+ * (FB_BOOLEAN * )var -> sqldata = (dval != 0 ) ? FB_TRUE : FB_FALSE ;
815
832
break ;
816
833
default :
817
834
if (!zend_binary_strncasecmp (Z_STRVAL_P (b_var ), Z_STRLEN_P (b_var ), "true" , 4 , 4 )) {
818
- * (bool * )var -> sqldata = 1 ;
835
+ * (FB_BOOLEAN * )var -> sqldata = FB_TRUE ;
819
836
} else if (!zend_binary_strncasecmp (Z_STRVAL_P (b_var ), Z_STRLEN_P (b_var ), "false" , 5 , 5 )) {
820
- * (bool * )var -> sqldata = 1 ;
837
+ * (FB_BOOLEAN * )var -> sqldata = FB_FALSE ;
821
838
} else {
822
839
_php_ibase_module_error ("Parameter %d: cannot convert string to boolean" , i + 1 );
823
840
rv = FAILURE ;
@@ -836,7 +853,7 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
836
853
}
837
854
var -> sqltype = SQL_BOOLEAN ;
838
855
continue ;
839
-
856
+ #endif
840
857
case SQL_ARRAY :
841
858
842
859
if (Z_TYPE_P (b_var ) != IS_ARRAY ) {
@@ -899,9 +916,12 @@ static void _php_ibase_alloc_xsqlda(XSQLDA *sqlda) /* {{{ */
899
916
case SQL_VARYING :
900
917
var -> sqldata = safe_emalloc (sizeof (char ), var -> sqllen + sizeof (short ), 0 );
901
918
break ;
902
- case SQL_BOOLEAN :
903
- var -> sqldata = emalloc (sizeof (zend_bool ));
904
- break ;
919
+ // Boolean data type exists since FB 3.0
920
+ #ifdef SQL_BOOLEAN
921
+ case SQL_BOOLEAN :
922
+ var -> sqldata = emalloc (sizeof (FB_BOOLEAN ));
923
+ break ;
924
+ #endif
905
925
case SQL_SHORT :
906
926
var -> sqldata = emalloc (sizeof (short ));
907
927
break ;
@@ -1401,10 +1421,12 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
1401
1421
case SQL_TEXT :
1402
1422
ZVAL_STRINGL (val , (char * )data , len );
1403
1423
break ;
1404
- // The query's field value is boolean
1405
- case SQL_BOOLEAN :
1406
- ZVAL_BOOL (val , * (bool * ) data );
1407
- break ;
1424
+ // Boolean data type exists since FB 3.0
1425
+ #ifdef SQL_BOOLEAN
1426
+ case SQL_BOOLEAN :
1427
+ ZVAL_BOOL (val , * (FB_BOOLEAN * ) data );
1428
+ break ;
1429
+ #endif
1408
1430
case SQL_SHORT :
1409
1431
n = * (short * ) data ;
1410
1432
goto _sql_long ;
@@ -2000,10 +2022,12 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */
2000
2022
unsigned short precision = 0 ;
2001
2023
2002
2024
switch (var -> sqltype & ~1 ) {
2003
-
2004
- case SQL_BOOLEAN :
2005
- precision = 1 ;
2006
- break ;
2025
+ // Boolean data type exists since FB 3.0
2026
+ #ifdef SQL_BOOLEAN
2027
+ case SQL_BOOLEAN :
2028
+ precision = 1 ;
2029
+ break ;
2030
+ #endif
2007
2031
case SQL_SHORT :
2008
2032
precision = 4 ;
2009
2033
break ;
@@ -2028,9 +2052,12 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */
2028
2052
case SQL_SHORT :
2029
2053
s = "SMALLINT" ;
2030
2054
break ;
2031
- case SQL_BOOLEAN :
2032
- s = "BOOLEAN" ;
2033
- break ;
2055
+ // Boolean data type exists since FB 3.0
2056
+ #ifdef SQL_BOOLEAN
2057
+ case SQL_BOOLEAN :
2058
+ s = "BOOLEAN" ;
2059
+ break ;
2060
+ #endif
2034
2061
case SQL_LONG :
2035
2062
s = "INTEGER" ;
2036
2063
break ;
0 commit comments