Add z/OS Connector and Processor

This commit is contained in:
Lucas Mezêncio 2016-08-19 14:09:04 -03:00
parent b19daaa67c
commit 92f6800a01
2 changed files with 89 additions and 0 deletions

View 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);
}
}

View 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;
}
}
}