yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Support Request for SQLT_BOL or OCI_B_BOL in oci_bind_by_name #127

Closed sge-kawa closed 1 year ago

sge-kawa commented 1 year ago

Summary of problem or feature request

I'd like to bring to your attention an issue regarding the conversion of PDO::PARAM_BOOLEAN to SQLT_INT in the bindParam function within Statement.php. This conversion is causing type mismatch errors.

I kindly request that you consider either converting PDO::PARAM_BOOLEAN to SQLT_BOL or OCI_B_BOL, or adding a case statement to handle SQLT_BOL or OCI_BO_BOL specifically.

By implementing this change, it would ensure proper type compatibility and prevent errors when working with Boolean values.

Code snippet of problem

PL/SQL

CREATE OR REPLACE FUNCTION FUNC_BOOL 
(
  PARAM1 IN BOOLEAN 
, PARAM2 OUT BOOLEAN 
) RETURN BOOLEAN AS 
BEGIN
  PARAM2 := PARAM1;
  RETURN PARAM1;
END FUNC_BOOL;

for Laravel

$outparam = null;
$bindings = [
    'p1' => [
        'value' => true,
        'type' => PDO::PARAM_BOOL,
    ],
    'p2' => [
        'value' => &$outparam,
        'type' => PDO::PARAM_BOOL,
    ],
];

$result = DB::connection()->executeFunction('FUNC_BOOL', $bindings, PDO::PARAM_BOOL);

output error

   Yajra\Pdo\Oci8\Exceptions\Oci8Exception 

  Error Code    : 6550
Error Message : ORA-06550: line 1, column 18:
PLS-00306: wrong number or types of arguments in call to 'FUNC_BOOL'
ORA-06550: line 1, column 18:
PLS-00306: wrong number or types of arguments in call to 'FUNC_BOOL'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Position      : 17
Statement     : begin :result := FUNC_BOOL(:p1, :p2); end;
Bindings      : [1,0,0]

Modification for Statement.php

  1. Convert PDO::PARAM_BOOLEAN to SQLT_BOL or OCI_B_BOL instead of SQLT_INT.
    public function bindParam(..) 
    {
        ...
        switch ($dataType) {
            case PDO::PARAM_BOOL:
                    $ociType = SQLT_BOL;   // change SQLT_INT to  SQLT_BOL or OCI_B_BOL
                    break;
            ...
    }
  2. Add a case statement specifically for SQLT_BOL or OCI_B_BOL
    public function bindParam(..) 
    {
        ...
        switch ($dataType) {
            ...
            // add 
            case SQLT_BOL :
                $ociType = SQLT_BOL;
                break;
            ...
    }

System details

yajra commented 1 year ago

Thanks for reporting, would you able to send a PR please for the proposed changes?

sge-kawa commented 1 year ago

Thank you for taking the time to contact us. Please review the PR.