yajra / pdo-via-oci8

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

CLOBS that have more than 32.767 characters #24

Closed dejan-babic closed 8 years ago

dejan-babic commented 8 years ago

It seems that the driver does not support CLOBS that have more than 32.767 characters. As far as I can see the problem is within src/yajra/Pdo/Oci8/Statement.php. The case of CLOBS is not covered so a possible solution is:

case SQLT_CLOB:
                $oci_type = OCI_B_CLOB;
                $this->_returnLobs = true;
                // create a new descriptor for lob-type
                $variable = $this->_pdoOci8->getNewDescriptor();
                break;

The solution is not tested through, and it needs more investigation.

yajra commented 8 years ago

@dejan-babic Are you using the package as stand alone or via Laravel framework using Laravel-OCI8 package?

Anyways, you are correct that we currently don't create a descriptor for CLOB and was not aware that it has a limit of 32,767 when saving to it directly. Will try to test your proposed solution as soon as I can. Thanks for the info.

dejan-babic commented 8 years ago

@yajra Thank you for taking a look. I am using it with Lumen framework, but i guess it comes down to that.

yajra commented 8 years ago

@dejan-babic, I just tested saving clob and it works well for me saving 1million chars using Laravel 5.2 and Laravel-OCI8 5.2. Snippet used:

$router->get('demo', function () {
    Demo::unguard();

    $demo = Demo::create([
        'c_string' => 'test',
        'c_clob' => str_repeat('A', 1000000),
    ]);

    return $demo->fresh();
});
yajra commented 8 years ago

@dejan-babic I think the issue above might be same thing that's happening to your case?

ORA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column Cause: A Bind value of length potentially > 4000 bytes follows binding for LOB or LONG. Action: Re-order the binds so that the LONG bind or LOB binds are all at the end of the bind list.

Like is mentioned above, to solve this is simply needed to put the clob column at the end of the insert statement.

dejan-babic commented 8 years ago

@yajra The workaround you suggested does not suit our needs, so in our specific case we needed to patch the file like described on: https://github.com/yajra/pdo-via-oci8/issues/24#issue-136625104 Cheers

yajra commented 8 years ago

@dejan-babic, do you mean by adding the CLOB support on Statement.php? We can add it but the thing is how can we identify that a given column in laravel model is a clob?

Tylerian commented 8 years ago

I've had the same problem, couldn't read CLOBs because CLOB Type was missing at Statement.php so i've ended up editing the file and adding CLOB support. I will create a PR soon if you don't mind.

PD: I wasn't using Eloquent models but a simple PL/SQL Funciton though.

yajra commented 8 years ago

@Tylerian we would gladly accept a PR.

BTW, have you tried putting the CLOB field as the last field of insert statement? Like insert into (field1, field2, field3, clob1, clob2) values (...).

yajra commented 8 years ago

PR #31 merged and released on v1.1.0. Sorry for the delays, overlooked it. Thanks!