36 lines
857 B
PHP
36 lines
857 B
PHP
<?php
|
|
|
|
namespace App\Database\Db2;
|
|
|
|
use Illuminate\Database\Query\Processors\Processor;
|
|
|
|
class Db2Processor extends Processor
|
|
{
|
|
public function processInsertGetId($query, $sql, $values, $sequence = null)
|
|
{
|
|
$query->getConnection()->insert($sql, $values);
|
|
|
|
$result = $query->getConnection()->selectOne(
|
|
'SELECT IDENTITY_VAL_LOCAL() AS ID FROM SYSIBM.SYSDUMMY1',
|
|
[],
|
|
false
|
|
);
|
|
|
|
if ($result === null) {
|
|
throw new \RuntimeException(
|
|
'Db2 did not return a generated identity value.'
|
|
);
|
|
}
|
|
|
|
$id = $result->ID ?? $result->id ?? null;
|
|
|
|
if ($id === null) {
|
|
throw new \RuntimeException(
|
|
'Db2 identity value was NULL.'
|
|
);
|
|
}
|
|
|
|
return is_numeric($id) ? (int) $id : $id;
|
|
}
|
|
}
|