Skip to content

Commit db9d568

Browse files
committed
Initial commit
1 parent 3382ee9 commit db9d568

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

oci_statement.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
581581
dyn = TRUE;
582582
break;
583583

584+
case SQLT_BOL:
585+
S->cols[colno].datalen = 1;
586+
S->cols[colno].data = emalloc(S->cols[colno].datalen + 1);
587+
break;
588+
584589
case SQLT_BIN:
585590
default:
586591
if (dtype == SQLT_DAT || dtype == SQLT_NUM || dtype == SQLT_RDD
@@ -795,6 +800,11 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo_
795800
} else if (C->indicator == 0) {
796801
/* it was stored perfectly */
797802

803+
if (C->dtype == SQLT_BOL) {
804+
ZVAL_BOOL(result, strlen(C->data));
805+
return 1;
806+
}
807+
798808
if (C->dtype == SQLT_BLOB || C->dtype == SQLT_CLOB) {
799809
if (C->data) {
800810
php_stream *stream = oci_create_lob_stream(stmt, (OCILobLocator*)C->data);
@@ -970,6 +980,10 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
970980
add_assoc_string(return_value, "oci:decl_type", "BINARY_DOUBLE");
971981
add_assoc_string(return_value, "native_type", "BINARY_DOUBLE");
972982
break;
983+
case SQLT_BOL:
984+
add_assoc_string(return_value, "oci:decl_type", "BOOLEAN");
985+
add_assoc_string(return_value, "native_type", "BOOLEAN");
986+
break;
973987
default:
974988
add_assoc_long(return_value, "oci:decl_type", dtype);
975989
add_assoc_string(return_value, "native_type", "UNKNOWN");
@@ -981,6 +995,9 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
981995
}
982996

983997
switch (dtype) {
998+
case SQLT_BOL:
999+
add_assoc_long(return_value, "pdo_type", PDO_PARAM_BOOL);
1000+
break;
9841001
case SQLT_BLOB:
9851002
case SQLT_CLOB:
9861003
add_assoc_long(return_value, "pdo_type", PDO_PARAM_LOB);
@@ -1002,6 +1019,9 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
10021019

10031020
/* PDO type */
10041021
switch (dtype) {
1022+
case SQLT_BOL:
1023+
add_assoc_long(return_value, "pdo_type", PDO_PARAM_BOOL);
1024+
break;
10051025
case SQLT_BFILE:
10061026
case SQLT_BLOB:
10071027
case SQLT_CLOB:

tests/pdo_oci_insert_boolean.phpt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
PDO_OCI: Insert BOOLEAN values into BOOLEAN column (Oracle 23ai+)
3+
--EXTENSIONS--
4+
pdo
5+
pdo_oci
6+
--SKIPIF--
7+
<?php
8+
require(getenv('PDO_TEST_DIR').'/pdo_test.inc');
9+
$db = PDOTest::factory();
10+
11+
$version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
12+
preg_match('/^(\d+)\./', $version, $matches);
13+
$majorVersion = (int)$matches[1];
14+
if ($majorVersion < 23) {
15+
die('skip BOOLEAN type supported from Oracle Database 23ai');
16+
}
17+
18+
PDOTest::skip();
19+
?>
20+
--FILE--
21+
<?php
22+
23+
require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
24+
$db = PDOTest::factory();
25+
26+
// Create table
27+
$db->exec("CREATE TABLE IF NOT EXISTS test_bool (id NUMBER, bool_val BOOLEAN)");
28+
29+
// Insert true
30+
$stmt = $db->prepare("INSERT INTO test_bool (id, bool_val) VALUES (1, :val)");
31+
$val = true;
32+
$stmt->bindParam(':val', $val, PDO::PARAM_BOOL);
33+
$stmt->execute();
34+
35+
// Insert false
36+
$stmt = $db->prepare("INSERT INTO test_bool (id, bool_val) VALUES (2, :val)");
37+
$val = false;
38+
$stmt->bindParam(':val', $val, PDO::PARAM_BOOL);
39+
$stmt->execute();
40+
41+
// Fetch and dump
42+
$stmt = $db->query("SELECT id, bool_val FROM test_bool ORDER BY id");
43+
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
44+
?>
45+
--CLEAN--
46+
<?php
47+
48+
require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
49+
$db = PDOTest::factory();
50+
51+
$db->exec("DROP TABLE test_bool PURGE");
52+
53+
?>
54+
--EXPECT--
55+
array(2) {
56+
[0]=>
57+
array(2) {
58+
["id"]=>
59+
string(1) "1"
60+
["bool_val"]=>
61+
string(1) "1"
62+
}
63+
[1]=>
64+
array(2) {
65+
["id"]=>
66+
string(1) "2"
67+
["bool_val"]=>
68+
string(1) "0"
69+
}
70+
}

0 commit comments

Comments
 (0)