Skip to content

Commit 4374796

Browse files
authored
Merge pull request #15 from lucasmezencio/master
Add IBM Mainframe z/OS support
2 parents ed43908 + 1d08883 commit 4374796

File tree

13 files changed

+594
-377
lines changed

13 files changed

+594
-377
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Simply add this code at the end of your ``app/config/database.php`` file:
5757
*/
5858

5959
'ibmi' => [
60-
'driver' => 'odbc' / 'ibm',
60+
'driver' => 'odbc' / 'ibm' / 'odbczos',
6161
'driverName' => '{IBM i Access ODBC Driver}' / '{iSeries Access ODBC Driver}',
6262
// General settings
6363
'host' => 'server',
@@ -67,6 +67,7 @@ Simply add this code at the end of your ``app/config/database.php`` file:
6767
'database' => 'WRKRDBDIRE entry',
6868
'prefix' => '',
6969
'schema' => 'default schema',
70+
'port' => 50000,
7071
'signon' => 3,
7172
'ssl' => 0,
7273
'commitMode' => 2,

src/Connectors/IBMConnector.php

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,103 @@
11
<?php
2+
23
namespace Cooperl\Database\DB2\Connectors;
34

45
use Illuminate\Database\Connectors\Connector;
56
use Illuminate\Database\Connectors\ConnectorInterface;
67

7-
use PDO;
8-
8+
/**
9+
* Class IBMConnector
10+
*
11+
* @package Cooperl\Database\DB2\Connectors
12+
*/
913
class IBMConnector extends Connector implements ConnectorInterface
1014
{
11-
15+
/**
16+
* @param array $config
17+
*
18+
* @return \PDO
19+
*/
1220
public function connect(array $config)
1321
{
1422
$dsn = $this->getDsn($config);
15-
1623
$options = [
17-
PDO::I5_ATTR_DBC_SYS_NAMING => false,
18-
PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT,
19-
PDO::I5_ATTR_JOB_SORT => false
24+
\PDO::I5_ATTR_DBC_SYS_NAMING => false,
25+
\PDO::I5_ATTR_COMMIT => \PDO::I5_TXN_NO_COMMIT,
26+
\PDO::I5_ATTR_JOB_SORT => false,
2027
];
2128

2229
// Naming mode
2330
switch ($config['naming']) {
2431
case 1:
25-
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = true;
32+
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true;
33+
2634
break;
2735
case 0:
2836
default:
29-
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = false;
37+
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false;
38+
3039
break;
3140
}
3241

3342
// Isolation mode
3443
switch ($config['commitMode']) {
3544
case 1:
36-
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_READ_COMMITTED;
45+
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_COMMITTED;
46+
3747
break;
3848
case 2:
39-
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_READ_UNCOMMITTED;
49+
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_UNCOMMITTED;
50+
4051
break;
4152
case 3:
42-
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_REPEATABLE_READ;
53+
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_REPEATABLE_READ;
54+
4355
break;
4456
case 4:
45-
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_SERIALIZABLE;
57+
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_SERIALIZABLE;
58+
4659
break;
4760
case 0:
4861
default:
4962
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_NO_COMMIT;
63+
5064
break;
5165
}
5266

5367
// Job sort mode
5468
switch ($config['jobSort']) {
5569
case 1:
56-
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = true;
70+
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true;
71+
5772
break;
5873
case 0:
5974
default:
60-
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = false;
75+
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false;
76+
6177
break;
6278
}
6379

6480
$options = $this->getOptions($config) + $options;
65-
6681
$connection = $this->createConnection($dsn, $config, $options);
6782

68-
if (isset($config['schema']))
69-
{
83+
if (isset($config['schema'])) {
7084
$schema = $config['schema'];
7185

72-
$connection->prepare("set schema $schema")->execute();
86+
$connection->prepare("set schema $schema")->execute();
7387
}
7488

7589
return $connection;
7690
}
7791

78-
protected function getDsn(array $config) {
79-
extract($config);
80-
$dsn = "ibm:$database";
92+
/**
93+
* @param array $config
94+
*
95+
* @return string
96+
*/
97+
protected function getDsn(array $config)
98+
{
99+
$dsn = "ibm:{$config['database']}";
100+
81101
return $dsn;
82102
}
83-
84103
}

src/Connectors/ODBCConnector.php

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,86 @@
11
<?php
2+
23
namespace Cooperl\Database\DB2\Connectors;
34

45
use Illuminate\Database\Connectors\Connector;
56
use Illuminate\Database\Connectors\ConnectorInterface;
67

8+
/**
9+
* Class ODBCConnector
10+
*
11+
* @package Cooperl\Database\DB2\Connectors
12+
*/
713
class ODBCConnector extends Connector implements ConnectorInterface
814
{
915

16+
/**
17+
* @param array $config
18+
*
19+
* @return \PDO
20+
*/
1021
public function connect(array $config)
1122
{
1223
$dsn = $this->getDsn($config);
13-
1424
$options = $this->getOptions($config);
15-
1625
$connection = $this->createConnection($dsn, $config, $options);
1726

18-
if (isset($config['schema']))
19-
{
27+
if (isset($config['schema'])) {
2028
$schema = $config['schema'];
2129

22-
$connection->prepare("set schema $schema")->execute();
30+
$connection->prepare('set schema '.$schema)->execute();
2331
}
2432

2533
return $connection;
2634
}
2735

28-
protected function getDsn(array $config) {
29-
extract($config);
36+
/**
37+
* @param array $config
38+
*
39+
* @return string
40+
*/
41+
protected function getDsn(array $config)
42+
{
43+
$dsnParts = [
44+
'odbc:DRIVER=%s', 'SYSTEM=%s', 'UserID=%s', 'Password=%s', 'DATABASE=%s', 'SIGNON=%s', 'SSL=%s',
45+
'CommitMode=%s', 'ConnectionType=%s', 'DefaultLibraries=%s', 'Naming=%s', 'UNICODESQL=%s', 'DateFormat=%s',
46+
'DateSeperator=%s', 'Decimal=%s', 'TimeFormat=%s', 'TimeSeparator=%s', 'BLOCKFETCH=%s', 'BlockSizeKB=%s',
47+
'AllowDataCompression=%s', 'CONCURRENCY=%s', 'LAZYCLOSE=%s', 'MaxFieldLength=%s', 'PREFETCH=%s',
48+
'QUERYTIMEOUT=%s', 'DefaultPkgLibrary=%s', 'DefaultPackage=%s', 'ExtendedDynamic=%s', 'QAQQINILibrary=%s',
49+
'SQDIAGCODE=%s', 'LANGUAGEID=%s', 'SORTTABLE=%s', 'SortSequence=%s', 'SORTWEIGHT=%s',
50+
'AllowUnsupportedChar=%s', 'CCSID=%s', 'GRAPHIC=%s', 'ForceTranslation=%s', 'ALLOWPROCCALLS=%s',
51+
'DB2SQLSTATES=%s', 'DEBUG=%s', 'TRUEAUTOCOMMIT=%s', 'CATALOGOPTIONS=%s', 'LibraryView=%s', 'ODBCRemarks=%s',
52+
'SEARCHPATTERN=%s', 'TranslationDLL=%s', 'TranslationOption=%s', 'MAXTRACESIZE=%s', 'MultipleTraceFiles=%s',
53+
'TRACE=%s', 'TRACEFILENAME=%s', 'ExtendedColInfo=%s',
54+
'', // Just to add a semicolon to the end of string
55+
];
3056

31-
$dsn = "odbc:"
32-
// General settings
33-
. "DRIVER=$driverName;"
34-
. "SYSTEM=$host;"
35-
. "UserID=$username;"
36-
. "Password=$password;"
37-
//Server settings
38-
. "DATABASE=$database;"
39-
. "SIGNON=$signon;"
40-
. "SSL=$ssl;"
41-
. "CommitMode=$commitMode;"
42-
. "ConnectionType=$connectionType;"
43-
. "DefaultLibraries=$defaultLibraries;"
44-
. "Naming=$naming;"
45-
. "UNICODESQL=$unicodeSql;"
46-
// Format settings
47-
. "DateFormat=$dateFormat;"
48-
. "DateSeperator=$dateSeperator;"
49-
. "Decimal=$decimal;"
50-
. "TimeFormat=$timeFormat;"
51-
. "TimeSeparator=$timeSeparator;"
52-
// Performances settings
53-
. "BLOCKFETCH=$blockFetch;"
54-
. "BlockSizeKB=$blockSizeKB;"
55-
. "AllowDataCompression=$allowDataCompression;"
56-
. "CONCURRENCY=$concurrency;"
57-
. "LAZYCLOSE=$lazyClose;"
58-
. "MaxFieldLength=$maxFieldLength;"
59-
. "PREFETCH=$prefetch;"
60-
. "QUERYTIMEOUT=$queryTimeout;"
61-
// Modules settings
62-
. "DefaultPkgLibrary=$defaultPkgLibrary;"
63-
. "DefaultPackage=$defaultPackage;"
64-
. "ExtendedDynamic=$extendedDynamic;"
65-
// Diagnostic settings
66-
. "QAQQINILibrary=$QAQQINILibrary;"
67-
. "SQDIAGCODE=$sqDiagCode;"
68-
// Sort settings
69-
. "LANGUAGEID=$languageId;"
70-
. "SORTTABLE=$sortTable;"
71-
. "SortSequence=$sortSequence;"
72-
. "SORTWEIGHT=$sortWeight;"
73-
// Conversion settings
74-
. "AllowUnsupportedChar=$allowUnsupportedChar;"
75-
. "CCSID=$ccsid;"
76-
. "GRAPHIC=$graphic;"
77-
. "ForceTranslation=$forceTranslation;"
78-
// Other settings
79-
. "ALLOWPROCCALLS=$allowProcCalls;"
80-
. "DB2SQLSTATES=$DB2SqlStates;"
81-
. "DEBUG=$debug;"
82-
. "TRUEAUTOCOMMIT=$trueAutoCommit;"
83-
. "CATALOGOPTIONS=$catalogOptions;"
84-
. "LibraryView=$libraryView;"
85-
. "ODBCRemarks=$ODBCRemarks;"
86-
. "SEARCHPATTERN=$searchPattern;"
87-
. "TranslationDLL=$translationDLL;"
88-
. "TranslationOption=$translationOption;"
89-
. "MAXTRACESIZE=$maxTraceSize;"
90-
. "MultipleTraceFiles=$multipleTraceFiles;"
91-
. "TRACE=$trace;"
92-
. "TRACEFILENAME=$traceFilename;"
93-
. "ExtendedColInfo=$extendedColInfo;"
94-
;
57+
$dsnConfig = [
58+
// General settings
59+
$config['driverName'], $config['host'], $config['username'], $config['password'],
60+
//Server settings
61+
$config['database'], $config['signon'], $config['ssl'], $config['commitMode'], $config['connectionType'],
62+
$config['defaultLibraries'], $config['naming'], $config['unicodeSql'],
63+
// Format settings
64+
$config['dateFormat'], $config['dateSeperator'], $config['decimal'], $config['timeFormat'],
65+
$config['timeSeparator'],
66+
// Performances settings
67+
$config['blockFetch'], $config['blockSizeKB'], $config['allowDataCompression'], $config['concurrency'],
68+
$config['lazyClose'], $config['maxFieldLength'], $config['prefetch'], $config['queryTimeout'],
69+
// Modules settings
70+
$config['defaultPkgLibrary'], $config['defaultPackage'], $config['extendedDynamic'],
71+
// Diagnostic settings
72+
$config['QAQQINILibrary'], $config['sqDiagCode'],
73+
// Sort settings
74+
$config['languageId'], $config['sortTable'], $config['sortSequence'], $config['sortWeight'],
75+
// Conversion settings
76+
$config['allowUnsupportedChar'], $config['ccsid'], $config['graphic'], $config['forceTranslation'],
77+
// Other settings
78+
$config['allowProcCalls'], $config['DB2SqlStates'], $config['debug'], $config['trueAutoCommit'],
79+
$config['catalogOptions'], $config['libraryView'], $config['ODBCRemarks'], $config['searchPattern'],
80+
$config['translationDLL'], $config['translationOption'], $config['maxTraceSize'],
81+
$config['multipleTraceFiles'], $config['trace'], $config['traceFilename'], $config['extendedColInfo'],
82+
];
9583

96-
return $dsn;
84+
return sprintf(implode(';', $dsnParts), ...$dsnConfig);
9785
}
98-
9986
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Cooperl\Database\DB2\Connectors;
4+
5+
/**
6+
* Class ODBCZOSConnector
7+
*
8+
* @package Cooperl\Database\DB2\Connectors
9+
*/
10+
class ODBCZOSConnector extends ODBCConnector
11+
{
12+
/**
13+
* @param array $config
14+
*
15+
* @return string
16+
*/
17+
protected function getDsn(array $config)
18+
{
19+
$dsnParts = [
20+
'odbc:DRIVER={IBM DB2 ODBC DRIVER}',
21+
'Database=%s',
22+
'Hostname=%s',
23+
'Port=%s',
24+
'Protocol=TCPIP',
25+
'Uid=%s',
26+
'Pwd=%s',
27+
'', // Just to add a semicolon to the end of string
28+
];
29+
30+
$dsnConfig = [
31+
$config['database'],
32+
$config['host'],
33+
$config['port'],
34+
$config['username'],
35+
$config['password'],
36+
];
37+
38+
return sprintf(implode(';', $dsnParts), ...$dsnConfig);
39+
}
40+
}

0 commit comments

Comments
 (0)