Skip to content

Commit d65222b

Browse files
author
Martin Köditz
committed
Merge branch 'Boolean'
2 parents 9d4b7fa + b89f3d2 commit d65222b

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

ibase_query.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
+----------------------------------------------------------------------+
1717
*/
1818

19+
#include <stdbool.h>
20+
1921
#ifdef HAVE_CONFIG_H
2022
#include "config.h"
2123
#endif
@@ -80,6 +82,7 @@ typedef struct {
8082
*/
8183
typedef struct {
8284
union {
85+
zend_bool bval;
8386
short sval;
8487
float fval;
8588
ISC_LONG lval;
@@ -239,6 +242,10 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
239242
a->el_type = SQL_TEXT;
240243
a->el_size = ar_desc->array_desc_length;
241244
break;
245+
case blr_bool:
246+
a->el_type = SQL_BOOLEAN;
247+
a->el_size = sizeof(zend_bool);
248+
break;
242249
case blr_short:
243250
a->el_type = SQL_SHORT;
244251
a->el_size = sizeof(short);
@@ -574,6 +581,11 @@ static int _php_ibase_bind_array(zval *val, char *buf, zend_ulong buf_size, /* {
574581
convert_to_double(val);
575582
*(float*) buf = (float) Z_DVAL_P(val);
576583
break;
584+
case SQL_BOOLEAN:
585+
convert_to_boolean(val);
586+
// On Windows error unresolved symbol Z_BVAL_P is thrown, so we use Z_LVAL_P
587+
*(zend_bool*) buf = Z_LVAL_P(val);
588+
break;
577589
case SQL_DOUBLE:
578590
convert_to_double(val);
579591
*(double*) buf = Z_DVAL_P(val);
@@ -761,6 +773,37 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
761773
}
762774
continue;
763775

776+
case SQL_BOOLEAN:
777+
778+
convert_to_string(b_var);
779+
var->sqldata = Z_STRVAL_P(b_var);
780+
var->sqllen = Z_STRLEN_P(b_var);
781+
var->sqltype = SQL_BOOLEAN;
782+
continue;
783+
784+
if (Z_STRLEN_P(b_var) != BLOB_ID_LEN ||
785+
!_php_ibase_string_to_quad(Z_STRVAL_P(b_var), &buf[i].val.qval)) {
786+
787+
ibase_blob ib_blob = { 0, BLOB_INPUT };
788+
789+
if (isc_create_blob(IB_STATUS, &ib_query->link->handle,
790+
&ib_query->trans->handle, &ib_blob.bl_handle, &ib_blob.bl_qd)) {
791+
_php_ibase_error();
792+
return FAILURE;
793+
}
794+
795+
if (_php_ibase_blob_add(b_var, &ib_blob) != SUCCESS) {
796+
return FAILURE;
797+
}
798+
799+
if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) {
800+
_php_ibase_error();
801+
return FAILURE;
802+
}
803+
buf[i].val.qval = ib_blob.bl_qd;
804+
}
805+
continue;
806+
764807
case SQL_ARRAY:
765808

766809
if (Z_TYPE_P(b_var) != IS_ARRAY) {
@@ -823,6 +866,9 @@ static void _php_ibase_alloc_xsqlda(XSQLDA *sqlda) /* {{{ */
823866
case SQL_VARYING:
824867
var->sqldata = safe_emalloc(sizeof(char), var->sqllen + sizeof(short), 0);
825868
break;
869+
case SQL_BOOLEAN:
870+
var->sqldata = emalloc(sizeof(zend_bool));
871+
break;
826872
case SQL_SHORT:
827873
var->sqldata = emalloc(sizeof(short));
828874
break;
@@ -1323,6 +1369,10 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
13231369
case SQL_TEXT:
13241370
ZVAL_STRINGL(val, (char*)data, len);
13251371
break;
1372+
// The query's field value is boolean
1373+
case SQL_BOOLEAN:
1374+
ZVAL_BOOL(val, *(bool *) data);
1375+
break;
13261376
case SQL_SHORT:
13271377
n = *(short *) data;
13281378
goto _sql_long;
@@ -1910,11 +1960,18 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */
19101960
add_index_stringl(return_value, 3, buf, len);
19111961
add_assoc_stringl(return_value, "length", buf, len);
19121962

1963+
/*
1964+
* SQL_ consts are part of Firebird-API.
1965+
*/
1966+
19131967
if (var->sqlscale < 0) {
19141968
unsigned short precision = 0;
19151969

19161970
switch (var->sqltype & ~1) {
19171971

1972+
case SQL_BOOLEAN:
1973+
precision = 1;
1974+
break;
19181975
case SQL_SHORT:
19191976
precision = 4;
19201977
break;
@@ -1939,6 +1996,9 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */
19391996
case SQL_SHORT:
19401997
s = "SMALLINT";
19411998
break;
1999+
case SQL_BOOLEAN:
2000+
s = "BOOLEAN";
2001+
break;
19422002
case SQL_LONG:
19432003
s = "INTEGER";
19442004
break;

php_interbase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern zend_module_entry ibase_module_entry;
2525
#define phpext_interbase_ptr &ibase_module_entry
2626

2727
#include "php_version.h"
28-
#define PHP_INTERBASE_VERSION "1.0.0-dev"
28+
#define PHP_INTERBASE_VERSION "1.1.0"
2929

3030
PHP_MINIT_FUNCTION(ibase);
3131
PHP_RINIT_FUNCTION(ibase);

0 commit comments

Comments
 (0)