yajra / pdo-via-oci8

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

fetchAll also checks if fetch() returning object #30

Closed apit closed 8 years ago

apit commented 8 years ago

in laravel-oci8, DB::select() of function returning SYS_REFCURSOR will returns

array (size=1)
  0 => 
    object(stdClass)[395]
      public 'rc' => resource(30, oci8 statement)
yajra commented 8 years ago

@apit thanks for the PR. Can you please provide some snippet on how to test this?

apit commented 8 years ago
CREATE TABLE test_maintable(
    name nvarchar2(100),
    kind nvarchar2(8)
)
/

INSERT INTO test_maintable VALUES ('lorem ipsum', 'A');
INSERT INTO test_maintable VALUES ('dolores anum', 'A');
INSERT INTO test_maintable VALUES ('lazy fox', 'B');

CREATE OR REPLACE FUNCTION func_test_refcursor(k in nvarchar2)
RETURN SYS_REFCURSOR AS
      rc SYS_REFCURSOR;
  BEGIN
      OPEN rc FOR select * from test_maintable where kind=k;
      RETURN rc;
  END;

/
-> % ./artisan tinker
Psy Shell v0.7.2 (PHP 5.6.21 — cli) by Justin Hileman
>>> $rows = DB::select('select func_test_refcursor(:kind) as rc from dual', [':kind'=>'A']);
>>> // Expected/with this patch
=> [
     {#817
       +"name": "lorem ipsum",
       +"kind": "A",
     },
     {#818
       +"name": "dolores anum",
       +"kind": "A",
     }
   ]

>>> // Actual result
=> [
     {#812
       +"rc": oci8 statement resource #521,
     },
   ]
yajra commented 8 years ago

Thanks a lot @apit. Merged and released on v1.0.5.