80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Db2;
|
|
|
|
use Illuminate\Database\Connection;
|
|
use Illuminate\Database\Query\Grammars\Grammar as QueryGrammar;
|
|
use App\Database\Db2\Db2Processor;
|
|
class Db2Connection extends Connection
|
|
{
|
|
|
|
/**
|
|
* Restore SQL NULL values from Db2 workaround expressions
|
|
* before Eloquent processes the results.
|
|
*/
|
|
public function select(
|
|
$query,
|
|
$bindings = [],
|
|
$useReadPdo = true,
|
|
array $fetchUsing = []
|
|
) {
|
|
$rows = parent::select(
|
|
$query,
|
|
$bindings,
|
|
$useReadPdo,
|
|
$fetchUsing
|
|
);
|
|
|
|
foreach ($rows as $row) {
|
|
if (! is_object($row)) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($row as $key => $value) {
|
|
if ($value === Db2QueryGrammar::NULL_TIMESTAMP_SENTINEL) {
|
|
$row->{$key} = null;
|
|
continue;
|
|
}
|
|
|
|
if (
|
|
in_array($key, [
|
|
'two_factor_secret',
|
|
'two_factor_recovery_codes',
|
|
], true)
|
|
&& $value === Db2QueryGrammar::NULL_STRING_SENTINEL
|
|
) {
|
|
$row->{$key} = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
protected function getDefaultQueryGrammar()
|
|
{
|
|
return new Db2QueryGrammar($this);
|
|
}
|
|
|
|
protected function getDefaultSchemaGrammar()
|
|
{
|
|
return new Db2SchemaGrammar($this);
|
|
}
|
|
|
|
public function getSchemaBuilder()
|
|
{
|
|
if (is_null($this->schemaGrammar)) {
|
|
$this->useDefaultSchemaGrammar();
|
|
}
|
|
|
|
return new Db2SchemaBuilder($this);
|
|
}
|
|
|
|
protected function getDefaultPostProcessor()
|
|
{
|
|
return new Db2Processor;
|
|
}
|
|
|
|
|
|
}
|