-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lucasmezencio/master
Add IBM Mainframe z/OS support
- Loading branch information
Showing
13 changed files
with
594 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,103 @@ | ||
<?php | ||
|
||
namespace Cooperl\Database\DB2\Connectors; | ||
|
||
use Illuminate\Database\Connectors\Connector; | ||
use Illuminate\Database\Connectors\ConnectorInterface; | ||
|
||
use PDO; | ||
|
||
/** | ||
* Class IBMConnector | ||
* | ||
* @package Cooperl\Database\DB2\Connectors | ||
*/ | ||
class IBMConnector extends Connector implements ConnectorInterface | ||
{ | ||
|
||
/** | ||
* @param array $config | ||
* | ||
* @return \PDO | ||
*/ | ||
public function connect(array $config) | ||
{ | ||
$dsn = $this->getDsn($config); | ||
|
||
$options = [ | ||
PDO::I5_ATTR_DBC_SYS_NAMING => false, | ||
PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT, | ||
PDO::I5_ATTR_JOB_SORT => false | ||
\PDO::I5_ATTR_DBC_SYS_NAMING => false, | ||
\PDO::I5_ATTR_COMMIT => \PDO::I5_TXN_NO_COMMIT, | ||
\PDO::I5_ATTR_JOB_SORT => false, | ||
]; | ||
|
||
// Naming mode | ||
switch ($config['naming']) { | ||
case 1: | ||
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = true; | ||
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true; | ||
|
||
break; | ||
case 0: | ||
default: | ||
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = false; | ||
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false; | ||
|
||
break; | ||
} | ||
|
||
// Isolation mode | ||
switch ($config['commitMode']) { | ||
case 1: | ||
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_READ_COMMITTED; | ||
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_COMMITTED; | ||
|
||
break; | ||
case 2: | ||
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_READ_UNCOMMITTED; | ||
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_UNCOMMITTED; | ||
|
||
break; | ||
case 3: | ||
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_REPEATABLE_READ; | ||
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_REPEATABLE_READ; | ||
|
||
break; | ||
case 4: | ||
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_SERIALIZABLE; | ||
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_SERIALIZABLE; | ||
|
||
break; | ||
case 0: | ||
default: | ||
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_NO_COMMIT; | ||
|
||
break; | ||
} | ||
|
||
// Job sort mode | ||
switch ($config['jobSort']) { | ||
case 1: | ||
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = true; | ||
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true; | ||
|
||
break; | ||
case 0: | ||
default: | ||
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = false; | ||
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false; | ||
|
||
break; | ||
} | ||
|
||
$options = $this->getOptions($config) + $options; | ||
|
||
$connection = $this->createConnection($dsn, $config, $options); | ||
|
||
if (isset($config['schema'])) | ||
{ | ||
if (isset($config['schema'])) { | ||
$schema = $config['schema']; | ||
|
||
$connection->prepare("set schema $schema")->execute(); | ||
$connection->prepare("set schema $schema")->execute(); | ||
} | ||
|
||
return $connection; | ||
} | ||
|
||
protected function getDsn(array $config) { | ||
extract($config); | ||
$dsn = "ibm:$database"; | ||
/** | ||
* @param array $config | ||
* | ||
* @return string | ||
*/ | ||
protected function getDsn(array $config) | ||
{ | ||
$dsn = "ibm:{$config['database']}"; | ||
|
||
return $dsn; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,86 @@ | ||
<?php | ||
|
||
namespace Cooperl\Database\DB2\Connectors; | ||
|
||
use Illuminate\Database\Connectors\Connector; | ||
use Illuminate\Database\Connectors\ConnectorInterface; | ||
|
||
/** | ||
* Class ODBCConnector | ||
* | ||
* @package Cooperl\Database\DB2\Connectors | ||
*/ | ||
class ODBCConnector extends Connector implements ConnectorInterface | ||
{ | ||
|
||
/** | ||
* @param array $config | ||
* | ||
* @return \PDO | ||
*/ | ||
public function connect(array $config) | ||
{ | ||
$dsn = $this->getDsn($config); | ||
|
||
$options = $this->getOptions($config); | ||
|
||
$connection = $this->createConnection($dsn, $config, $options); | ||
|
||
if (isset($config['schema'])) | ||
{ | ||
if (isset($config['schema'])) { | ||
$schema = $config['schema']; | ||
|
||
$connection->prepare("set schema $schema")->execute(); | ||
$connection->prepare('set schema '.$schema)->execute(); | ||
} | ||
|
||
return $connection; | ||
} | ||
|
||
protected function getDsn(array $config) { | ||
extract($config); | ||
/** | ||
* @param array $config | ||
* | ||
* @return string | ||
*/ | ||
protected function getDsn(array $config) | ||
{ | ||
$dsnParts = [ | ||
'odbc:DRIVER=%s', 'SYSTEM=%s', 'UserID=%s', 'Password=%s', 'DATABASE=%s', 'SIGNON=%s', 'SSL=%s', | ||
'CommitMode=%s', 'ConnectionType=%s', 'DefaultLibraries=%s', 'Naming=%s', 'UNICODESQL=%s', 'DateFormat=%s', | ||
'DateSeperator=%s', 'Decimal=%s', 'TimeFormat=%s', 'TimeSeparator=%s', 'BLOCKFETCH=%s', 'BlockSizeKB=%s', | ||
'AllowDataCompression=%s', 'CONCURRENCY=%s', 'LAZYCLOSE=%s', 'MaxFieldLength=%s', 'PREFETCH=%s', | ||
'QUERYTIMEOUT=%s', 'DefaultPkgLibrary=%s', 'DefaultPackage=%s', 'ExtendedDynamic=%s', 'QAQQINILibrary=%s', | ||
'SQDIAGCODE=%s', 'LANGUAGEID=%s', 'SORTTABLE=%s', 'SortSequence=%s', 'SORTWEIGHT=%s', | ||
'AllowUnsupportedChar=%s', 'CCSID=%s', 'GRAPHIC=%s', 'ForceTranslation=%s', 'ALLOWPROCCALLS=%s', | ||
'DB2SQLSTATES=%s', 'DEBUG=%s', 'TRUEAUTOCOMMIT=%s', 'CATALOGOPTIONS=%s', 'LibraryView=%s', 'ODBCRemarks=%s', | ||
'SEARCHPATTERN=%s', 'TranslationDLL=%s', 'TranslationOption=%s', 'MAXTRACESIZE=%s', 'MultipleTraceFiles=%s', | ||
'TRACE=%s', 'TRACEFILENAME=%s', 'ExtendedColInfo=%s', | ||
'', // Just to add a semicolon to the end of string | ||
]; | ||
|
||
$dsn = "odbc:" | ||
// General settings | ||
. "DRIVER=$driverName;" | ||
. "SYSTEM=$host;" | ||
. "UserID=$username;" | ||
. "Password=$password;" | ||
//Server settings | ||
. "DATABASE=$database;" | ||
. "SIGNON=$signon;" | ||
. "SSL=$ssl;" | ||
. "CommitMode=$commitMode;" | ||
. "ConnectionType=$connectionType;" | ||
. "DefaultLibraries=$defaultLibraries;" | ||
. "Naming=$naming;" | ||
. "UNICODESQL=$unicodeSql;" | ||
// Format settings | ||
. "DateFormat=$dateFormat;" | ||
. "DateSeperator=$dateSeperator;" | ||
. "Decimal=$decimal;" | ||
. "TimeFormat=$timeFormat;" | ||
. "TimeSeparator=$timeSeparator;" | ||
// Performances settings | ||
. "BLOCKFETCH=$blockFetch;" | ||
. "BlockSizeKB=$blockSizeKB;" | ||
. "AllowDataCompression=$allowDataCompression;" | ||
. "CONCURRENCY=$concurrency;" | ||
. "LAZYCLOSE=$lazyClose;" | ||
. "MaxFieldLength=$maxFieldLength;" | ||
. "PREFETCH=$prefetch;" | ||
. "QUERYTIMEOUT=$queryTimeout;" | ||
// Modules settings | ||
. "DefaultPkgLibrary=$defaultPkgLibrary;" | ||
. "DefaultPackage=$defaultPackage;" | ||
. "ExtendedDynamic=$extendedDynamic;" | ||
// Diagnostic settings | ||
. "QAQQINILibrary=$QAQQINILibrary;" | ||
. "SQDIAGCODE=$sqDiagCode;" | ||
// Sort settings | ||
. "LANGUAGEID=$languageId;" | ||
. "SORTTABLE=$sortTable;" | ||
. "SortSequence=$sortSequence;" | ||
. "SORTWEIGHT=$sortWeight;" | ||
// Conversion settings | ||
. "AllowUnsupportedChar=$allowUnsupportedChar;" | ||
. "CCSID=$ccsid;" | ||
. "GRAPHIC=$graphic;" | ||
. "ForceTranslation=$forceTranslation;" | ||
// Other settings | ||
. "ALLOWPROCCALLS=$allowProcCalls;" | ||
. "DB2SQLSTATES=$DB2SqlStates;" | ||
. "DEBUG=$debug;" | ||
. "TRUEAUTOCOMMIT=$trueAutoCommit;" | ||
. "CATALOGOPTIONS=$catalogOptions;" | ||
. "LibraryView=$libraryView;" | ||
. "ODBCRemarks=$ODBCRemarks;" | ||
. "SEARCHPATTERN=$searchPattern;" | ||
. "TranslationDLL=$translationDLL;" | ||
. "TranslationOption=$translationOption;" | ||
. "MAXTRACESIZE=$maxTraceSize;" | ||
. "MultipleTraceFiles=$multipleTraceFiles;" | ||
. "TRACE=$trace;" | ||
. "TRACEFILENAME=$traceFilename;" | ||
. "ExtendedColInfo=$extendedColInfo;" | ||
; | ||
$dsnConfig = [ | ||
// General settings | ||
$config['driverName'], $config['host'], $config['username'], $config['password'], | ||
//Server settings | ||
$config['database'], $config['signon'], $config['ssl'], $config['commitMode'], $config['connectionType'], | ||
$config['defaultLibraries'], $config['naming'], $config['unicodeSql'], | ||
// Format settings | ||
$config['dateFormat'], $config['dateSeperator'], $config['decimal'], $config['timeFormat'], | ||
$config['timeSeparator'], | ||
// Performances settings | ||
$config['blockFetch'], $config['blockSizeKB'], $config['allowDataCompression'], $config['concurrency'], | ||
$config['lazyClose'], $config['maxFieldLength'], $config['prefetch'], $config['queryTimeout'], | ||
// Modules settings | ||
$config['defaultPkgLibrary'], $config['defaultPackage'], $config['extendedDynamic'], | ||
// Diagnostic settings | ||
$config['QAQQINILibrary'], $config['sqDiagCode'], | ||
// Sort settings | ||
$config['languageId'], $config['sortTable'], $config['sortSequence'], $config['sortWeight'], | ||
// Conversion settings | ||
$config['allowUnsupportedChar'], $config['ccsid'], $config['graphic'], $config['forceTranslation'], | ||
// Other settings | ||
$config['allowProcCalls'], $config['DB2SqlStates'], $config['debug'], $config['trueAutoCommit'], | ||
$config['catalogOptions'], $config['libraryView'], $config['ODBCRemarks'], $config['searchPattern'], | ||
$config['translationDLL'], $config['translationOption'], $config['maxTraceSize'], | ||
$config['multipleTraceFiles'], $config['trace'], $config['traceFilename'], $config['extendedColInfo'], | ||
]; | ||
|
||
return $dsn; | ||
return sprintf(implode(';', $dsnParts), ...$dsnConfig); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.