Better connection management:

- No mandatory ODBC connection under Operating System admnistration
- add all ODBC settings according official IBM documentation
This commit is contained in:
Maxime Rault 2015-07-22 17:23:32 +02:00
parent b902a5e030
commit 85a8cacce5
4 changed files with 209 additions and 64 deletions

View File

@ -11,7 +11,55 @@ class IBMConnector extends Connector implements ConnectorInterface
{ {
$dsn = $this->getDsn($config); $dsn = $this->getDsn($config);
$options = $this->getOptions($config); $options = [
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;
break;
case 0:
default:
$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;
break;
case 2:
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_READ_UNCOMMITTED;
break;
case 3:
$options[PDO::I5_ATTR_COMMIT] = PDO::I5_TXN_REPEATABLE_READ;
break;
case 4:
$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;
break;
case 0:
default:
$options[PDO::I5_ATTR_DBC_SYS_NAMING] = false;
break;
}
$options = array_merge($this->getOptions($config), $options) ;
$connection = $this->createConnection($dsn, $config, $options); $connection = $this->createConnection($dsn, $config, $options);

View File

@ -28,17 +28,70 @@ class ODBCConnector extends Connector implements ConnectorInterface
protected function getDsn(array $config) { protected function getDsn(array $config) {
extract($config); extract($config);
$dsn = "odbc:DRIVER={iSeries Access ODBC Driver};" $dsn = "odbc:"
. "SYSTEM=$database;" // General settings
. "NAM=$i5_naming;" . "DRIVER={iSeries Access ODBC Driver};"
. "DATABASE=$i5_lib;" . "SYSTEM=$host;"
. "DBQ=$i5_libl;" . "UserID=$username;"
. "DFT=$i5_date_fmt;" . "Password=$password;"
. "DSP=$i5_date_sep;" //Server settings
. "DEC=$i5_decimal_sep;" . "DATABASE=$database;"
. "TFT=$i5_time_fmt;" . "SIGNON=$signon;"
. "TSP=$i5_time_sep;" . "SSL=$ssl;"
. "CCSID=$ccsid"; . "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;"
;
return $dsn; return $dsn;
} }

View File

@ -7,6 +7,29 @@ use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
class DB2Processor extends Processor { class DB2Processor extends Processor {
/**
* Process the results of a "select" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $results
* @return array
*/
/*public function processSelect(Builder $query, $results)
{
$results = array_map(function($result) {
foreach (get_object_vars($result) as $field => $value) {
if (is_string($value))
{
$result->$field = trim(preg_split('/[^\r\n\t\x20-\x7E\xA0-\xFF]/', $value)[0]);
}
}
return $result;
}, $results);
return $results;
}*/
/** /**
* Process an "insert get ID" query. * Process an "insert get ID" query.
* *

View File

@ -11,11 +11,11 @@ Valeurs définies pour le niveau d'isolation, pour PDO (mot clé "CMT" ou "Commi
3 = Repeatable read (*ALL) 3 = Repeatable read (*ALL)
4 = Serializable (*RR) 4 = Serializable (*RR)
* i5_naming: * naming:
0 = "sql" (as in schema.table) 0 = "sql" (as in schema.table)
1 = "system" (as in schema/table) 1 = "system" (as in schema/table)
* i5_date_fmt: * dateFormat:
0 = yy/dd (*JUL) 0 = yy/dd (*JUL)
1 = mm/dd/yy (*MDY) 1 = mm/dd/yy (*MDY)
2 = dd/mm/yy (*DMY) 2 = dd/mm/yy (*DMY)
@ -25,25 +25,25 @@ Valeurs définies pour le niveau d'isolation, pour PDO (mot clé "CMT" ou "Commi
6 = dd.mm.yyyy (*EUR) 6 = dd.mm.yyyy (*EUR)
7 = yyyy-mm-dd (*JIS) 7 = yyyy-mm-dd (*JIS)
* i5_date_sep: * dateSeperator:
0 = "/" (forward slash) 0 = "/" (forward slash)
1 = "-" (dash) 1 = "-" (dash)
2 = "." (period) 2 = "." (period)
3 = "," (comma) 3 = "," (comma)
4 = " " (blank) 4 = " " (blank)
* i5_decimal_sep: * decimal:
0 = "." (period) 0 = "." (period)
1 = "," (comma) 1 = "," (comma)
* i5_time_fmt: * timeFormat:
0 = hh:mm:ss (*HMS) 0 = hh:mm:ss (*HMS)
1 = hh:mm AM/PM (*USA) 1 = hh:mm AM/PM (*USA)
2 = hh.mm.ss (*ISO) 2 = hh.mm.ss (*ISO)
3 = hh.mm.ss (*EUR) 3 = hh.mm.ss (*EUR)
4 = hh:mm:ss (*JIS) 4 = hh:mm:ss (*JIS)
* i5_time_sep: * timeSeparator:
0 = ":" (colon) 0 = ":" (colon)
1 = "." (period) 1 = "." (period)
2 = "," (comma) 2 = "," (comma)
@ -61,51 +61,72 @@ return [
'connections' => [ 'connections' => [
'odbc' => [ 'ibmi' => [
'driver' => 'odbc', 'driver' => 'odbc' / 'ibm',
'host' => '', // General settings
'database' => '', 'host' => 'gigc',
'username' => '', 'username' => '',
'password' => '', 'password' => '',
'charset' => 'utf8', //Server settings
'ccsid' => 1208, 'database' => 'WRKRDBDIRE entry',
'prefix' => '', 'prefix' => '',
'schema' => '', 'schema' => 'default schema',
'i5_libl' => '', 'signon' => 3,
'i5_lib' => '', 'ssl' => 0,
'i5_commit' => 0, 'commitMode' => 2,
'i5_naming' => 0, 'connectionType' => 0,
'i5_date_fmt' => 5, 'defaultLibraries' => '',
'i5_date_sep' => 0, 'naming' => 0,
'i5_decimal_sep' => 0, 'unicodeSql' => 0,
'i5_time_fmt' => 0, // Format settings
'i5_time_sep' => 0, 'dateFormat' => 5,
'options' => [ 'dateSeperator' => 0,
PDO::ATTR_CASE => PDO::CASE_LOWER, 'decimal' => 0,
PDO::ATTR_EMULATE_PREPARES => false, 'timeFormat' => 0,
PDO::ATTR_PERSISTENT => false 'timeSeparator' => 0,
] // Performances settings
], 'blockFetch' => 1,
'blockSizeKB' => 32,
'ibm' => [ 'allowDataCompression' => 1,
'driver' => 'ibm', 'concurrency' => 0,
'host' => '', 'lazyClose' => 0,
'database' => '', 'maxFieldLength' => 15360,
'username' => '', 'prefetch' => 0,
'password' => '', 'queryTimeout' => 1,
'charset' => 'utf8', // Modules settings
'defaultPkgLibrary' => 'QGPL',
'defaultPackage' => 'A/DEFAULT(IBM),2,0,1,0',
'extendedDynamic' => 1,
// Diagnostic settings
'QAQQINILibrary' => '',
'sqDiagCode' => '',
// Sort settings
'languageId' => 'ENU',
'sortTable' => '',
'sortSequence' => 0,
'sortWeight' => 0,
'jobSort' => 0,
// Conversion settings
'allowUnsupportedChar' => 0,
'ccsid' => 1208, 'ccsid' => 1208,
'prefix' => '', 'graphic' => 0,
'schema' => '', 'forceTranslation' => 0,
'i5_libl' => '', // Other settings
'i5_lib' => '', 'allowProcCalls' => 0,
'i5_commit' => 0, 'DB2SqlStates' => 0,
'i5_naming' => 0, 'debug' => 0,
'i5_date_fmt' => 5, 'trueAutoCommit' => 0,
'i5_date_sep' => 0, 'catalogOptions' => 3,
'i5_decimal_sep' => 0, 'libraryView' => 0,
'i5_time_fmt' => 0, 'ODBCRemarks' => 0,
'i5_time_sep' => 0, 'searchPattern' => 1,
'translationDLL' => '',
'translationOption' => 0,
'maxTraceSize' => 0,
'multipleTraceFiles' => 1,
'trace' => 0,
'traceFilename' => '',
'extendedColInfo' => 0,
'options' => [ 'options' => [
PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_EMULATE_PREPARES => false,