yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8

Home Page:https://yajrabox.com/docs/laravel-oci8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$model->update() BLOB do not work, $model->fill()->save() yes

jirapetr opened this issue · comments

Summary of problem or feature request

On update
$identity->update($arrayInput);
make error:

if I use
$identityUpdated = $identity->fill($arrayInput)->save();
it is OK

maybe problem is in:
// vendor/yajra/laravel-oci8/src/Oci8/Eloquent/OracleEloquent.php

// If dirty attributes contains binary field
// extract binary fields to new array
if ($this->extractBinaries($attributes)) {
return $this->newQuery()->updateLob($attributes, $this->binaryFields, $this->getKeyName());
}

Code snippet of problem

"message": "Error Code : 24369\nError Message : ORA-24369: required callbacks not registered for one or more bind handles\nPosition : 0\nStatement : update "IDENTITIES" set "PHOTO_VERIFIED_TYPE" = :p0, "PHOTO_UNVERIFIED_TYPE" = :p1, "UPDATED_BY" = :p2, "PHOTO_VERIFIED" = EMPTY_BLOB(), "PHOTO_UNVERIFIED" = EMPTY_BLOB() returning "PHOTO_VERIFIED", "PHOTO_UNVERIFIED", "ID" into :p3, :p4, :p5\nBindings : [jpeg,jpeg,21,OCILob,OCILob,0]\n",
"exception": "Yajra\Pdo\Oci8\Exceptions\Oci8Exception",
"file": "/var/www//vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8/Statement.php",
"line": 797,
"trace": [
{
"file": "/var/www/
/vendor/yajra/laravel-oci8/src/Oci8/Query/Processors/OracleProcessor.php",
"line": 166,
"function": "execute",
"class": "Yajra\Pdo\Oci8\Statement",
"type": "->"
},
{
"file": "/var/www/*******/vendor/yajra/laravel-oci8/src/Oci8/Query/OracleBuilder.php",
"line": 108,
"function": "saveLob",
"class": "Yajra\Oci8\Query\Processors\OracleProcessor",
"type": "->"

System details

  • Linux
  • PHP Version 8
  • Laravel Version 9
  • Laravel-OCI8 Version 2.2

@yajra @jirapetr
I have a similar problem, I have a procedure that receives a blob, but it is giving me the error:

$binds = [
                'ptitle' => ['value' => $title, 'type' => \PDO::PARAM_STR, 'length' => 200],
                'pbody' => ['value' => $body, 'type' => \PDO::PARAM_LOB, 'length' => -1], //here
                'pstatus' => ['value' => '0', 'type' => \PDO::PARAM_STR, 'length' => 1],
                'preason' => ['value' => $reason, 'type' => \PDO::PARAM_STR, 'length' => 255],
                'pdate_finished' => ['value' => $date_finished, 'type' => \PDO::PARAM_STR, 'length' => 30],
                'pissuer_user_fk' => ['value' => $user_id, 'type' => \PDO::PARAM_INT, 'length' => 19],
                'president_user_fk' => ['value' => $resident, 'type' => \PDO::PARAM_INT, 'length' => 19],
                'previewer_user_fk' => ['value' => $reviewer, 'type' => \PDO::PARAM_INT, 'length' => 19],
                'pstudy_fk' => ['value' => $study, 'type' => \PDO::PARAM_INT, 'length' => 19],
                'puser_fk' => ['value' => $user_id, 'type' => \PDO::PARAM_INT, 'length' => 19],
                'porigin' => ['value' => $origin, 'type' => \PDO::PARAM_STR, 'length' => 10],
                'preturn' => ['value' => $return, 'type' => \PDO::PARAM_STR, 'length' => 10]
            ];

$return = DB::executeProcedure('procedure', $binds);

Error Code : 6550\nError Message : ORA-06550: line 1, column 7:\nPLS-00306: wrong number or types of arguments in call to 'PROCEDURE'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored\nPosition : 6\nStatement : begin procedure(:ptitle,:pbody,:pstatus,:preason,:pdate_finished,:pissuer_user_fk,:president_user_fk,:previewer_user_fk,:pstudy_fk,:puser_fk,:porigin,:preturn); end;\nBindings : [Test 2,OCI-Lob,0,,,21,0,0,15491,21,TEST,]

if I change the parameter from PARAM_LOB to PARAM_STR it inserts up to the maximum number of characters.

but if it exceeds the maximum number of characters, it displays the error:

ORA-01460 unimplemented or unreasonable conversion requested.

I already tried with statement and bindParams, empt_blob() and without, I couldn't in any way.

any idea how to resolve this?

System details

  • Linux
  • PHP Version 7.4
  • Laravel Version 7
  • Laravel-OCI8 Version 7

I think this should be done on the PDO level atm. See https://yajrabox.com/docs/laravel-oci8/9.0/blob for ref.

like this?

$pdo = DB::getPdo();
$stmt = $pdo->prepare('begin insert_report(:ptitle, empty_blob(), :pstatus, :preason, :pdate_finished, :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :preturn); RETURNING :pbody INTO :pbody');
//$stmt = $pdo->prepare("begin insert_report(:ptitle, :pbody, :pstatus, :preason, :pdate_finished, :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :preturn); end;");

$stmt->bindParam(':ptitle', $title, \PDO::PARAM_STR, 200);
$stmt->bindParam(':pbody', $body, \PDO::PARAM_LOB, -1);
$stmt->bindParam(':pstatus', $status, \PDO::PARAM_STR, 1);
$stmt->bindParam(':preason', $reason, \PDO::PARAM_STR, 255);
$stmt->bindParam(':pdate_finished', $date_finished, \PDO::PARAM_STR, 30);
$stmt->bindParam(':pissuer_user_fk', $user_id, \PDO::PARAM_INT, 19);
$stmt->bindParam(':president_user_fk', $resident, \PDO::PARAM_INT, 19);
$stmt->bindParam(':previewer_user_fk', $reviewer, \PDO::PARAM_INT, 19);
$stmt->bindParam(':pstudy_fk', $study, \PDO::PARAM_INT, 19);
$stmt->bindParam(':puser_fk', $user_id, \PDO::PARAM_INT, 19);
$stmt->bindParam(':porigin', $origin, \PDO::PARAM_STR, 10);
$stmt->bindParam(':preturn', $return, \PDO::PARAM_STR, 10);

$stmt->execute();

this returns me:

Error Code : 6550\nError Message : ORA-06550: line 1, column 205:\nPLS-00049: bad bind variable ''\nORA-06550: line 1, column 193:\nPLS-00103: Encountered the symbol "" when expecting one of the following:\n\n := . ( @ % ;\nPosition : 204\nStatement : begin procedure(:ptitle, empty_blob(), :pstatus, :preason, :pdate_finished, :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :preturn); RETURNING :pbody INTO :pbody \nBindings : [Test 2,OCI-Lob,0,,,21,0,0,15491,21,TEST,]\n

or this with pbody only

Error Message : ORA-06550: line 1, column 204:\nPLS-00049: bad bind variable ''\nORA-06550: line 1, column 193:\nPLS-00103: Encountered the symbol "PBODY" when expecting one of the following

with:

$stmt = $pdo->prepare("begin insert_report(:ptitle, :pbody, :pstatus, :preason, :pdate_finished, :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :preturn); end;");

return:

wrong number or types of arguments in call to 'INSERT_REPORT'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored

I had it working like this:

$sql = "begin insert_report(:ptitle, :pbody, :pstatus, :preason, to_date(:pdate_finished,'yyyy-MM-dd HH24:MI:SS'), :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :preturn); end;";
$stmt = oci_parse($connection, $sql);
$clob = oci_new_descriptor($connection, OCI_D_LOB);
oci_bind_by_name($stmt, ':ptitle', $title);
oci_bind_by_name($stmt, ':pbody', $clob, -1, OCI_B_CLOB);
$clob->writeTemporary($body, OCI_TEMP_BLOB);
...

@yajra I started using connection pooling, and I have to switch to PDO.

I think it should be pbody(actual column name) that should be returned. Not the bound param:

$stmt = $pdo->prepare('
begin 
insert_report(:ptitle, empty_blob(), :pstatus, :preason, :pdate_finished, :pissuer_user_fk, :president_user_fk, :previewer_user_fk, :pstudy_fk, :puser_fk, :porigin, :return) 
RETURNING pbody INTO :pbody
');

Also, I haven't tried using stored proc to return a blob. Direct insert into SQL was tested afaik.

with the direct insert I have a tested code too, it's just in the procedure as you said, thanks for the answer

This issue is stale because it has been open for 30 days with no activity.

This issue was closed because it has been inactive for 7 days since being marked as stale.