Skip to content

Commit 0b0a2a5

Browse files
cooperl22Maxime Rault
authored andcommitted
Refactoring
1 parent dd6771f commit 0b0a2a5

File tree

12 files changed

+351
-423
lines changed

12 files changed

+351
-423
lines changed

README.md

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ Add the laravel-db2 Service Provider to your config in ``app/config/app.php``:
4343

4444
### Configuration
4545

46-
There are two ways to configure laravel-db2. You can choose the most convenient way for you. You can put your DB2 credentials into ``app/config/database.php`` (option 1) file or use package config file which you can be generated through command line by artisan (option 2).
46+
There are two ways to configure laravel-db2. You can choose the most convenient way for you. You can put your DB2 credentials into ``app/config/database.php`` (option 1) file or use package config file which you can generate through command line by artisan (option 2).
47+
48+
Please check appropriate specific DSN parameters for your connection.
49+
For instance here are the ODBC keywords for IBMi
50+
https://www.ibm.com/support/knowledgecenter/fr/ssw_ibm_i_73/rzaik/connectkeywords.htm
4751

4852
#### Option 1: Configure DB2 using ``app/config/database.php`` file
4953

@@ -57,97 +61,103 @@ Simply add this code at the end of your ``app/config/database.php`` file:
5761
*/
5862

5963
'ibmi' => [
60-
'driver' => 'odbc' / 'ibm' / 'odbczos',
61-
'driverName' => '{IBM i Access ODBC Driver}' / '{iSeries Access ODBC Driver}',
62-
// General settings
63-
'host' => 'server',
64-
'username' => '',
65-
'password' => '',
66-
//Server settings
67-
'database' => 'WRKRDBDIRE entry',
68-
'prefix' => '',
69-
'schema' => 'default schema',
70-
'port' => 50000,
71-
'signon' => 3,
72-
'ssl' => 0,
73-
'commitMode' => 2,
74-
'connectionType' => 0,
75-
'defaultLibraries' => '',
76-
'naming' => 0,
77-
'unicodeSql' => 0,
78-
// Format settings
79-
'dateFormat' => 5,
80-
'dateSeperator' => 0,
81-
'decimal' => 0,
82-
'timeFormat' => 0,
83-
'timeSeparator' => 0,
84-
// Performances settings
85-
'blockFetch' => 1,
86-
'blockSizeKB' => 32,
87-
'allowDataCompression' => 1,
88-
'concurrency' => 0,
89-
'lazyClose' => 0,
90-
'maxFieldLength' => 15360,
91-
'prefetch' => 0,
92-
'queryTimeout' => 1,
93-
// Modules settings
94-
'defaultPkgLibrary' => 'QGPL',
95-
'defaultPackage' => 'A/DEFAULT(IBM),2,0,1,0',
96-
'extendedDynamic' => 1,
97-
// Diagnostic settings
98-
'QAQQINILibrary' => '',
99-
'sqDiagCode' => '',
100-
// Sort settings
101-
'languageId' => 'ENU',
102-
'sortTable' => '',
103-
'sortSequence' => 0,
104-
'sortWeight' => 0,
105-
'jobSort' => 0,
106-
// Conversion settings
107-
'allowUnsupportedChar' => 0,
108-
'ccsid' => 1208,
109-
'graphic' => 0,
110-
'forceTranslation' => 0,
111-
// Other settings
112-
'allowProcCalls' => 0,
113-
'DB2SqlStates' => 0,
114-
'debug' => 0,
115-
'trueAutoCommit' => 0,
116-
'catalogOptions' => 3,
117-
'libraryView' => 0,
118-
'ODBCRemarks' => 0,
119-
'searchPattern' => 1,
120-
'translationDLL' => '',
121-
'translationOption' => 0,
122-
'maxTraceSize' => 0,
123-
'multipleTraceFiles' => 1,
124-
'trace' => 0,
125-
'traceFilename' => '',
126-
'extendedColInfo' => 0,
127-
'options' => [
64+
'driver' => 'db2_ibmi_odbc',
65+
// or 'db2_ibmi_ibm' / 'db2_zos_odbc' / 'db2_expressc_odbc
66+
'driverName' => '{IBM i Access ODBC Driver}',
67+
// or '{iSeries Access ODBC Driver}' / '{IBM i Access ODBC Driver 64-bit}'
68+
'host' => 'server',
69+
'username' => '',
70+
'password' => '',
71+
'database' => 'WRKRDBDIRE entry',
72+
'prefix' => '',
73+
'schema' => 'default schema',
74+
'port' => 50000,
75+
'date_format' => 'Y-m-d H:i:s',
76+
// or 'Y-m-d H:i:s.u' / 'Y-m-d-H.i.s.u'...
77+
'odbc_keywords' => [
78+
'SIGNON' => 3,
79+
'SSL' => 0,
80+
'CommitMode' => 2,
81+
'ConnectionType' => 0,
82+
'DefaultLibraries' => '',
83+
'Naming' => 0,
84+
'UNICODESQL' => 0,
85+
'DateFormat' => 5,
86+
'DateSeperator' => 0,
87+
'Decimal' => 0,
88+
'TimeFormat' => 0,
89+
'TimeSeparator' => 0,
90+
'TimestampFormat' => 0,
91+
'ConvertDateTimeToChar' => 0,
92+
'BLOCKFETCH' => 1,
93+
'BlockSizeKB' => 32,
94+
'AllowDataCompression' => 1,
95+
'CONCURRENCY' => 0,
96+
'LAZYCLOSE' => 0,
97+
'MaxFieldLength' => 15360,
98+
'PREFETCH' => 0,
99+
'QUERYTIMEOUT' => 1,
100+
'DefaultPkgLibrary' => 'QGPL',
101+
'DefaultPackage' => 'A /DEFAULT(IBM),2,0,1,0',
102+
'ExtendedDynamic' => 0,
103+
'QAQQINILibrary' => '',
104+
'SQDIAGCODE' => '',
105+
'LANGUAGEID' => 'ENU',
106+
'SORTTABLE' => '',
107+
'SortSequence' => 0,
108+
'SORTWEIGHT' => 0,
109+
'AllowUnsupportedChar' => 0,
110+
'CCSID' => 819,
111+
'GRAPHIC' => 0,
112+
'ForceTranslation' => 0,
113+
'ALLOWPROCCALLS' => 0,
114+
'DB2SQLSTATES' => 0,
115+
'DEBUG' => 0,
116+
'TRUEAUTOCOMMIT' => 0,
117+
'CATALOGOPTIONS' => 3,
118+
'LibraryView' => 0,
119+
'ODBCRemarks' => 0,
120+
'SEARCHPATTERN' => 1,
121+
'TranslationDLL' => '',
122+
'TranslationOption' => 0,
123+
'MAXTRACESIZE' => 0,
124+
'MultipleTraceFiles' => 1,
125+
'TRACE' => 0,
126+
'TRACEFILENAME' => '',
127+
'ExtendedColInfo' => 0,
128+
],
129+
'options' => [
128130
PDO::ATTR_CASE => PDO::CASE_LOWER,
129-
PDO::ATTR_EMULATE_PREPARES => false,
130-
PDO::ATTR_PERSISTENT => false
131+
PDO::ATTR_PERSISTENT => false,
132+
PDO::I5_ATTR_DBC_SYS_NAMING => false,
133+
PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT,
134+
PDO::I5_ATTR_JOB_SORT => false,
135+
PDO::I5_ATTR_DBC_LIBL => '',
136+
PDO::I5_ATTR_DBC_CURLIB => '',
131137
]
132138
],
133139

134-
```
135-
driver setting is either 'odbc' for ODBC connection or 'ibm' for pdo_ibm connection
136-
Then if driver is 'odbc', database must be set to ODBC connection name.
137-
if driver is 'ibm', database must be set to IBMi database name (WRKRDBDIRE).
140+
```
141+
driver setting can be:
142+
- 'db2_ibmi_odbc' for IBMi ODBC connection
143+
- 'db2_ibmi_ibm' for IBMi PDO_IBM connection
144+
- 'db2_zos_odbc' for zOS ODBC connection
145+
- 'db2_expressc_odbc for Express-C ODBC connection
146+
147+
Then if driver is 'db2_*_odbc', database must be set to ODBC connection name.
148+
if driver is 'db2_ibmi_ibm', database must be set to IBMi database name (WRKRDBDIRE).
138149

139150
#### Option 2: Configure DB2 using package config file
140151

141152
Run on the command line from the root of your project:
142153

143154
```
144-
$ php artisan config:publish cooperl/laravel-db2
155+
$ php artisan vendor:publish
145156
```
146157

147-
Set your laravel-db2 credentials in ``app/config/packages/cooperl/laravel-db2/config.php``
158+
Set your laravel-db2 credentials in ``app/config/db2.php``
148159
the same way as above
149160

150-
151161
## Usage
152162

153163
Consult the [Laravel framework documentation](http://laravel.com/docs).

src/Connectors/DB2Connector.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Cooperl\Database\DB2\Connectors;
4+
5+
use Illuminate\Database\Connectors\Connector;
6+
use Illuminate\Database\Connectors\ConnectorInterface;
7+
8+
/**
9+
* Class IBMConnector
10+
*
11+
* @package Cooperl\Database\DB2\Connectors
12+
*/
13+
class DB2Connector extends Connector implements ConnectorInterface
14+
{
15+
/**
16+
* @param array $config
17+
*
18+
* @return \PDO
19+
*/
20+
public function connect(array $config)
21+
{
22+
$dsn = $this->getDsn($config);
23+
$options = $this->getOptions($config);
24+
$connection = $this->createConnection($dsn, $config, $options);
25+
26+
if (isset($config['schema'])) {
27+
$schema = $config['schema'];
28+
29+
$connection->prepare('set schema ' . $schema)
30+
->execute();
31+
}
32+
33+
return $connection;
34+
}
35+
}

src/Connectors/IBMConnector.php

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,13 @@
22

33
namespace Cooperl\Database\DB2\Connectors;
44

5-
use Illuminate\Database\Connectors\Connector;
6-
use Illuminate\Database\Connectors\ConnectorInterface;
7-
85
/**
96
* Class IBMConnector
107
*
118
* @package Cooperl\Database\DB2\Connectors
129
*/
13-
class IBMConnector extends Connector implements ConnectorInterface
10+
class IBMConnector extends DB2Connector
1411
{
15-
/**
16-
* @param array $config
17-
*
18-
* @return \PDO
19-
*/
20-
public function connect(array $config)
21-
{
22-
$dsn = $this->getDsn($config);
23-
$options = [
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,
27-
];
28-
29-
// Naming mode
30-
switch ($config['naming']) {
31-
case 1:
32-
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true;
33-
34-
break;
35-
case 0:
36-
default:
37-
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false;
38-
39-
break;
40-
}
41-
42-
// Isolation mode
43-
switch ($config['commitMode']) {
44-
case 1:
45-
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_COMMITTED;
46-
47-
break;
48-
case 2:
49-
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_READ_UNCOMMITTED;
50-
51-
break;
52-
case 3:
53-
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_REPEATABLE_READ;
54-
55-
break;
56-
case 4:
57-
$options[\PDO::I5_ATTR_COMMIT] = \PDO::I5_TXN_SERIALIZABLE;
58-
59-
break;
60-
case 0:
61-
default:
62-
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_NO_COMMIT;
63-
64-
break;
65-
}
66-
67-
// Job sort mode
68-
switch ($config['jobSort']) {
69-
case 1:
70-
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = true;
71-
72-
break;
73-
case 0:
74-
default:
75-
$options[\PDO::I5_ATTR_DBC_SYS_NAMING] = false;
76-
77-
break;
78-
}
79-
80-
$options = $this->getOptions($config) + $options;
81-
$connection = $this->createConnection($dsn, $config, $options);
82-
83-
if (isset($config['schema'])) {
84-
$schema = $config['schema'];
85-
86-
$connection->prepare("set schema $schema")->execute();
87-
}
88-
89-
return $connection;
90-
}
91-
9212
/**
9313
* @param array $config
9414
*

0 commit comments

Comments
 (0)