27 #require_once 'Zend/Db.php'; 32 #require_once 'Zend/Db/Adapter/Abstract.php'; 37 #require_once 'Zend/Db/Statement/Db2.php'; 69 'host' =>
'localhost',
71 'protocol' =>
'TCPIP',
72 'persistent' =>
false,
126 if (!extension_loaded(
'ibm_db2')) {
130 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 135 if ($this->_config[
'persistent']) {
137 $conn_func_name =
'db2_pconnect';
140 $conn_func_name =
'db2_connect';
143 if (!isset($this->_config[
'driver_options'][
'autocommit'])) {
149 $caseAttrMap = array(
154 $this->_config[
'driver_options'][
'DB2_ATTR_CASE'] = $caseAttrMap[$this->_config[
'options'][
Zend_Db::CASE_FOLDING]];
157 if ($this->_isI5 && isset($this->_config[
'driver_options'][
'i5_naming'])) {
158 if ($this->_config[
'driver_options'][
'i5_naming']) {
159 $this->_config[
'driver_options'][
'i5_naming'] = DB2_I5_NAMING_ON;
161 $this->_config[
'driver_options'][
'i5_naming'] = DB2_I5_NAMING_OFF;
165 if ($this->_config[
'host'] !==
'localhost' && !$this->_isI5) {
167 $dbname =
'DRIVER={IBM DB2 ODBC DRIVER}' .
168 ';DATABASE=' . $this->_config[
'dbname'] .
169 ';HOSTNAME=' . $this->_config[
'host'] .
170 ';PORT=' . $this->_config[
'port'] .
171 ';PROTOCOL=' . $this->_config[
'protocol'] .
172 ';UID=' . $this->_config[
'username'] .
173 ';PWD=' . $this->_config[
'password'] .
';';
174 $this->_connection = $conn_func_name(
178 $this->_config[
'driver_options']
182 $this->_connection = $conn_func_name(
183 $this->_config[
'dbname'],
184 $this->_config[
'username'],
185 $this->_config[
'password'],
186 $this->_config[
'driver_options']
191 if (!$this->_connection) {
195 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 219 db2_close($this->_connection);
221 $this->_connection =
null;
235 #require_once 'Zend/Loader.php'; 238 $stmt =
new $stmtClass($this, $sql);
239 $stmt->setFetchMode($this->_fetchMode);
260 case DB2_AUTOCOMMIT_OFF:
261 case DB2_AUTOCOMMIT_ON:
262 $this->_execute_mode =
$mode;
263 db2_autocommit($this->_connection,
$mode);
269 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 292 return "'" . db2_escape_string(
$value) .
"'";
294 return parent::_quote(
$value);
303 $info = db2_server_info($this->_connection);
305 $identQuote =
$info->IDENTIFIER_QUOTE_CHAR;
324 if (
$schema ===
null && $this->_config[
'schema'] !=
null) {
325 $schema = $this->_config[
'schema'];
332 $stmt = db2_tables($this->_connection,
null,
$schema);
334 $stmt = db2_tables($this->_connection);
336 while (
$row = db2_fetch_assoc($stmt)) {
337 $tables[] =
$row[
'TABLE_NAME'];
381 if ($schemaName ===
null && $this->_config[
'schema'] !=
null) {
382 $schemaName = $this->_config[
'schema'];
387 $sql =
"SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno, 388 c.typename, c.default, c.nulls, c.length, c.scale, 389 c.identity, tc.type AS tabconsttype, k.colseq 390 FROM syscat.columns c 391 LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc 392 ON (k.tabschema = tc.tabschema 393 AND k.tabname = tc.tabname 395 ON (c.tabschema = k.tabschema 396 AND c.tabname = k.tabname 397 AND c.colname = k.colname) 402 $sql .= $this->
quoteInto(
' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
405 $sql .=
" ORDER BY c.colno";
410 $sql =
"SELECT DISTINCT C.TABLE_SCHEMA, C.TABLE_NAME, C.COLUMN_NAME, C.ORDINAL_POSITION, 411 C.DATA_TYPE, C.COLUMN_DEFAULT, C.NULLS ,C.LENGTH, C.SCALE, LEFT(C.IDENTITY,1), 412 LEFT(tc.TYPE, 1) AS tabconsttype, k.COLSEQ 413 FROM QSYS2.SYSCOLUMNS C 414 LEFT JOIN (QSYS2.syskeycst k JOIN QSYS2.SYSCST tc 415 ON (k.TABLE_SCHEMA = tc.TABLE_SCHEMA 416 AND k.TABLE_NAME = tc.TABLE_NAME 417 AND LEFT(tc.type,1) = 'P')) 418 ON (C.TABLE_SCHEMA = k.TABLE_SCHEMA 419 AND C.TABLE_NAME = k.TABLE_NAME 420 AND C.COLUMN_NAME = k.COLUMN_NAME) 425 $sql .= $this->
quoteInto(
' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
428 $sql .=
" ORDER BY C.ORDINAL_POSITION FOR FETCH ONLY";
432 $stmt = $this->
query($sql);
457 list ($primary, $primaryPosition, $identity) = array(
false,
null,
false);
458 if (
$row[$tabconstType] ==
'P') {
460 $primaryPosition =
$row[$colseq];
466 if (
$row[$identityCol] ==
'Y') {
475 'COLUMN_POSITION' => (!$this->_isI5) ?
$row[$colno]+1 :
$row[$colno],
476 'DATA_TYPE' =>
$row[$typename],
477 'DEFAULT' =>
$row[$default],
478 'NULLABLE' => (
bool) (
$row[$nulls] ==
'Y'),
479 'LENGTH' =>
$row[$length],
480 'SCALE' =>
$row[$scale],
481 'PRECISION' => (
$row[$typename] ==
'DECIMAL' ?
$row[$length] : 0),
483 'PRIMARY' => $primary,
484 'PRIMARY_POSITION' => $primaryPosition,
485 'IDENTITY' => $identity
506 $sql =
'SELECT PREVVAL FOR ' . $quotedSequenceName .
' AS VAL FROM SYSIBM.SYSDUMMY1';
508 $quotedSequenceName = $sequenceName;
509 $sql =
'SELECT PREVVAL FOR ' . $this->
quoteIdentifier($sequenceName,
true) .
' AS VAL FROM QSYS2.QSQPTABL';
527 $sql =
'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName,
true).
' AS VAL FROM SYSIBM.SYSDUMMY1';
562 $sequenceName .=
"_$primaryKey";
564 $sequenceName .=
'_seq';
568 $sql =
'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1';
590 if (!db2_commit($this->_connection)) {
594 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 596 db2_conn_errormsg($this->_connection),
597 db2_conn_error($this->_connection));
610 if (!db2_rollback($this->_connection)) {
614 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 616 db2_conn_errormsg($this->_connection),
617 db2_conn_error($this->_connection));
636 $this->_fetchMode =
$mode;
642 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 649 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 670 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 674 $offset = intval($offset);
679 #require_once 'Zend/Db/Adapter/Db2/Exception.php'; 684 $limit_sql = $sql .
" FETCH FIRST $count ROWS ONLY";
694 $limit_sql =
"SELECT z2.* 696 SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.* 701 WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) .
" AND " . ($offset+
$count);
713 if (
$type ==
'positional') {
729 $server_info = db2_server_info($this->_connection);
730 if ($server_info !==
false) {
748 if ($this->_isI5 ===
null) {
764 $this->_isI5 = (php_uname(
's') ==
'OS400') ?
true :
false;
767 if (isset($this->_config[
'os'])){
768 if (strtolower($this->_config[
'os']) ===
'i5') {
772 $this->_isI5 =
false;
791 $tablesStatement = db2_tables($this->_connection,
null,
$schema);
792 while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
793 if ($rowTables[
'TABLE_NAME'] !==
null) {
794 $tables[] = $rowTables[
'TABLE_NAME'];
798 $schemaStatement = db2_tables($this->_connection);
799 while (
$schema = db2_fetch_assoc($schemaStatement)) {
800 if (
$schema[
'TABLE_SCHEM'] !==
null) {
802 $tablesStatement = db2_tables($this->_connection, NULL,
$schema[
'TABLE_SCHEM']);
804 while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
805 if ($rowTables[
'TABLE_NAME'] !==
null) {
806 $tables[] = $rowTables[
'TABLE_NAME'];
820 if ($objectName ===
null) {
821 $sql =
'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM QSYS2.QSQPTABL';
826 if (strtoupper($idType) ===
'S'){
828 $sequenceName = $objectName;
describeTable($tableName, $schemaName=null)
fetchOne($sql, $bind=array())
static loadClass($class, $dirs=null)
lastInsertId($tableName=null, $primaryKey=null, $idType=null)
quoteInto($text, $value, $type=null, $count=null)
supportsParameters($type)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
_i5listTables($schema=null)
lastSequenceId($sequenceName)
_i5LastInsertId($objectName=null, $idType=null)
query($sql, $bind=array())
foreach( $_productCollection as $_product)() ?>" class $info
quoteIdentifier($ident, $auto=false)
limit($sql, $count, $offset=0)
nextSequenceId($sequenceName)
getQuoteIdentifierSymbol()