90 if (!defined(
'ADODB_DIR'))
die();
92 if (!defined(
'_ADODB_ODBC_LAYER')) {
93 include(ADODB_DIR.
"/drivers/adodb-odbc.inc.php");
95 if (!defined(
'ADODB_ODBC_DB2')){
96 define(
'ADODB_ODBC_DB2',1);
99 var $databaseType =
"db2";
100 var $concat_operator =
'||';
101 var $sysTime =
'CURRENT TIME';
102 var $sysDate =
'CURRENT DATE';
103 var $sysTimeStamp =
'CURRENT TIMESTAMP';
106 var $fmtTimeStamp =
"'Y-m-d-H.i.s'";
107 var $ansiOuter =
true;
108 var $identitySQL =
'values IDENTITY_VAL_LOCAL()';
109 var $_bindInputArray =
true;
110 var $hasInsertID =
true;
111 var $rsPrefix =
'ADORecordset_odbc_';
115 if (strncmp(PHP_OS,
'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC;
119 function IfNull( $field, $ifNull )
121 return " COALESCE($field, $ifNull) ";
127 $vers = $this->GetOne(
'select versionnumber from sysibm.sysversions');
129 return array(
'description'=>
'DB2 ODBC driver',
'version'=>$vers);
134 return $this->GetOne($this->identitySQL);
137 function RowLock($tables,$where,$col=
'1 as adodbignore')
140 return $this->GetOne(
"select $col from $tables where $where for update");
143 function MetaTables($ttype=
false,$showSchema=
false, $qtable=
"%", $qschema=
"%")
145 global $ADODB_FETCH_MODE;
147 $savem = $ADODB_FETCH_MODE;
148 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
149 $qid = odbc_tables($this->_connectionID,
"", $qschema, $qtable,
"");
153 $ADODB_FETCH_MODE = $savem;
158 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
160 $arr =
$rs->GetArray();
167 $isview = strncmp($ttype,
'V',1) === 0;
169 for ($i=0; $i <
sizeof($arr); $i++) {
171 if (!$arr[$i][2])
continue;
172 if (strncmp($arr[$i][1],
'SYS',3) === 0)
continue;
176 if ($showSchema) $arr[$i][2] = $arr[$i][1].
'.'.$arr[$i][2];
180 if (strncmp($type,
'V',1) === 0) $arr2[] = $arr[$i][2];
181 }
else if (strncmp($type,
'T',1) === 0) $arr2[] = $arr[$i][2];
182 }
else if (strncmp($type,
'S',1) !== 0) $arr2[] = $arr[$i][2];
187 function MetaIndexes ($table, $primary = FALSE, $owner=
false)
190 global $ADODB_FETCH_MODE;
191 $save = $ADODB_FETCH_MODE;
192 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
193 if ($this->fetchMode !== FALSE) {
194 $savem = $this->SetFetchMode(FALSE);
198 $table = strtoupper($table);
199 $SQL=
"SELECT NAME, UNIQUERULE, COLNAMES FROM SYSIBM.SYSINDEXES WHERE TBNAME='$table'";
201 $SQL.=
" AND UNIQUERULE='P'";
202 $rs = $this->Execute($SQL);
203 if (!is_object(
$rs)) {
205 $this->SetFetchMode($savem);
206 $ADODB_FETCH_MODE = $save;
211 while ($row =
$rs->FetchRow()) {
212 $indexes[$row[0]] = array(
213 'unique' => ($row[1] ==
'U' || $row[1] ==
'P'),
216 $cols = ltrim($row[2],
'+');
217 $indexes[$row[0]][
'columns'] = explode(
'+', $cols);
220 $this->SetFetchMode($savem);
221 $ADODB_FETCH_MODE = $save;
227 function SQLDate($fmt, $col=
false)
230 if (!$col) $col = $this->sysDate;
234 for ($i=0; $i < $len; $i++) {
240 $s .=
"char(year($col))";
243 $s .=
"substr(monthname($col),1,3)";
246 $s .=
"right(digits(month($col)),2)";
250 $s .=
"right(digits(day($col)),2)";
254 if ($col != $this->sysDate) $s .=
"right(digits(hour($col)),2)";
259 if ($col != $this->sysDate)
260 $s .=
"right(digits(minute($col)),2)";
265 if ($col != $this->sysDate)
266 $s .=
"right(digits(second($col)),2)";
272 $ch = substr($fmt,$i,1);
274 $s .= $this->qstr($ch);
281 function SelectLimit(
$sql,$nrows=-1,$offset=-1,$inputArr=
false)
283 $nrows = (integer) $nrows;
286 if ($nrows >= 0)
$sql .=
" FETCH FIRST $nrows ROWS ONLY ";
287 $rs = $this->Execute(
$sql,$inputArr);
289 if ($offset > 0 && $nrows < 0);
292 $sql .=
" FETCH FIRST $nrows ROWS ONLY ";
294 $rs = ADOConnection::SelectLimit(
$sql,-1,$offset,$inputArr);
305 var $databaseType =
"db2";
312 function MetaType($t,$len=-1,$fieldobj=
false)
316 $t = $fieldobj->type;
317 $len = $fieldobj->max_length;
320 switch (strtoupper($t)) {
325 if ($len <= $this->blobSize)
return 'C';
if(isset($_REQUEST['nrows'])) else $rs
MetaTables($ttype=false, $showSchema=false, $mask=false)