Skip to content

Commit 39ace8b

Browse files
author
Martin Köditz
committed
Added Boolean-Support. New Version 1.1.0-beta
1 parent 77f37cc commit 39ace8b

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

ibase_query.c

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct {
8282
*/
8383
typedef struct {
8484
union {
85-
bool bval;
85+
zend_bool bval;
8686
short sval;
8787
float fval;
8888
ISC_LONG lval;
@@ -244,7 +244,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
244244
break;
245245
case blr_bool:
246246
a->el_type = SQL_BOOLEAN;
247-
a->el_size = sizeof(bool);
247+
a->el_size = sizeof(zend_bool);
248248
break;
249249
case blr_short:
250250
a->el_type = SQL_SHORT;
@@ -582,8 +582,8 @@ static int _php_ibase_bind_array(zval *val, char *buf, zend_ulong buf_size, /* {
582582
*(float*) buf = (float) Z_DVAL_P(val);
583583
break;
584584
case SQL_BOOLEAN:
585-
//convert_to_bool(val);
586-
*(bool*) buf = Z_DVAL_P(val);
585+
convert_to_boolean(val);
586+
*(zend_bool*) buf = Z_BVAL_P(val);
587587
break;
588588
case SQL_DOUBLE:
589589
convert_to_double(val);
@@ -671,7 +671,6 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
671671

672672
/* for these types, an empty string can be handled like a NULL value */
673673
switch (var->sqltype & ~1) {
674-
case SQL_BOOLEAN:
675674
case SQL_SHORT:
676675
case SQL_LONG:
677676
case SQL_INT64:
@@ -773,6 +772,37 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
773772
}
774773
continue;
775774

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

778808
if (Z_TYPE_P(b_var) != IS_ARRAY) {
@@ -836,7 +866,7 @@ static void _php_ibase_alloc_xsqlda(XSQLDA *sqlda) /* {{{ */
836866
var->sqldata = safe_emalloc(sizeof(char), var->sqllen + sizeof(short), 0);
837867
break;
838868
case SQL_BOOLEAN:
839-
var->sqldata = emalloc(sizeof(bool));
869+
var->sqldata = emalloc(sizeof(zend_bool));
840870
break;
841871
case SQL_SHORT:
842872
var->sqldata = emalloc(sizeof(short));
@@ -1338,11 +1368,9 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
13381368
case SQL_TEXT:
13391369
ZVAL_STRINGL(val, (char*)data, len);
13401370
break;
1371+
// The query's field value is boolean
13411372
case SQL_BOOLEAN:
1342-
if(val)
1343-
ZVAL_BOOL(val,1);
1344-
else
1345-
ZVAL_BOOL(val,0);
1373+
ZVAL_BOOL(val, *(bool *) data);
13461374
break;
13471375
case SQL_SHORT:
13481376
n = *(short *) data;
@@ -1931,6 +1959,10 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */
19311959
add_index_stringl(return_value, 3, buf, len);
19321960
add_assoc_stringl(return_value, "length", buf, len);
19331961

1962+
/*
1963+
* SQL_ consts are part of Firebird-API.
1964+
*/
1965+
19341966
if (var->sqlscale < 0) {
19351967
unsigned short precision = 0;
19361968

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-beta"
2929

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

0 commit comments

Comments
 (0)