Add z/OS Connector and Processor
This commit is contained in:
parent
b19daaa67c
commit
92f6800a01
40
src/Connectors/ODBCZOSConnector.php
Normal file
40
src/Connectors/ODBCZOSConnector.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Cooperl\Database\DB2\Connectors;
|
||||
|
||||
/**
|
||||
* Class ODBCZOSConnector
|
||||
*
|
||||
* @package Cooperl\Database\DB2\Connectors
|
||||
*/
|
||||
class ODBCZOSConnector extends ODBCConnector
|
||||
{
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
{
|
||||
$dsnParts = [
|
||||
'odbc:DRIVER={IBM DB2 ODBC DRIVER}',
|
||||
'Database=%s',
|
||||
'Hostname=%s',
|
||||
'Port=%s',
|
||||
'Protocol=TCPIP',
|
||||
'Uid=%s',
|
||||
'Pwd=%s',
|
||||
'', // Just to add a semicolon to the end of string
|
||||
];
|
||||
|
||||
$dsnConfig = [
|
||||
$config['database'],
|
||||
$config['host'],
|
||||
$config['port'],
|
||||
$config['username'],
|
||||
$config['password'],
|
||||
];
|
||||
|
||||
return sprintf(implode(';', $dsnParts), ...$dsnConfig);
|
||||
}
|
||||
}
|
49
src/Query/Processors/DB2ZOSProcessor.php
Normal file
49
src/Query/Processors/DB2ZOSProcessor.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Cooperl\Database\DB2\Query\Processors;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Query\Processors\Processor;
|
||||
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
|
||||
|
||||
/**
|
||||
* Class DB2ZOSProcessor
|
||||
*
|
||||
* @package Cooperl\Database\DB2\Query\Processors
|
||||
*/
|
||||
class DB2ZOSProcessor extends Processor
|
||||
{
|
||||
/**
|
||||
* Process an "insert get ID" query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param string $sql
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
*
|
||||
* @return int/array
|
||||
*/
|
||||
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
|
||||
{
|
||||
$sequenceStr = $sequence ?: 'id';
|
||||
|
||||
if (is_array($sequence)) {
|
||||
$grammar = new DB2Grammar();
|
||||
$sequenceStr = $grammar->columnize($sequence);
|
||||
}
|
||||
|
||||
$sqlStr = 'select %s from final table (%s)';
|
||||
|
||||
$finalSql = sprintf($sqlStr, $sequenceStr, $sql);
|
||||
$results = $query->getConnection()->select($finalSql, $values);
|
||||
|
||||
if (is_array($sequence)) {
|
||||
return array_values((array) $results[0]);
|
||||
} else {
|
||||
$result = (array) $results[0];
|
||||
$id = $result[strtolower($sequenceStr)];
|
||||
|
||||
return is_numeric($id) ? (int) $id : $id;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user