コード例 #1
0
ファイル: DB2Info.php プロジェクト: ryanblanchard/Dashboard
 /**
  * @param String strSQL
  * @return Array
  */
 public function db_getfieldslist($table)
 {
     $res = array();
     $arr = implode(".", $table);
     $stmt = db2_columns($this->connectionObj->conn, null, $arr[0], $arr[1], '%');
     if ($stmt) {
         while ($rowC = db2_fetch_assoc($stmt)) {
             $ntype = $this->getFieldTypeNumber($rowC["TYPE_NAME"]);
             $res[$i] = array("fieldname" => $rowC["COLUMN_NAME"], "type" => $ntype, "is_nullable" => 0);
         }
     }
     return $res;
 }
コード例 #2
0
 function &MetaColumns($table)
 {
     global $ADODB_FETCH_MODE;
     $false = false;
     if ($this->uCaseTables) {
         $table = strtoupper($table);
     }
     $schema = '';
     $this->_findschema($table, $schema);
     $savem = $ADODB_FETCH_MODE;
     $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     $colname = "%";
     $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname);
     if (empty($qid)) {
         return $false;
     }
     $rs =& new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $false;
     }
     $rs->_fetch();
     $retarr = array();
     /*
     $rs->fields indices
     0 TABLE_QUALIFIER
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 DATA_TYPE
     5 TYPE_NAME
     6 PRECISION
     7 LENGTH
     8 SCALE
     9 RADIX
     10 NULLABLE
     11 REMARKS
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $fld = new ADOFieldObject();
             $fld->name = $rs->fields[3];
             $fld->type = $this->DB2Types($rs->fields[4]);
             // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
             // access uses precision to store length for char/varchar
             if ($fld->type == 'C' or $fld->type == 'X') {
                 if ($rs->fields[4] <= -95) {
                     // UNICODE
                     $fld->max_length = $rs->fields[7] / 2;
                 } else {
                     $fld->max_length = $rs->fields[7];
                 }
             } else {
                 $fld->max_length = $rs->fields[7];
             }
             $fld->not_null = !empty($rs->fields[10]);
             $fld->scale = $rs->fields[8];
             $fld->primary_key = false;
             $retarr[strtoupper($fld->name)] = $fld;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
     if (empty($retarr)) {
         $retarr = false;
     }
     $qid = db2_primary_keys($this->_connectionID, "", $schema, $table);
     if (empty($qid)) {
         return $false;
     }
     $rs =& new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $retarr;
     }
     $rs->_fetch();
     /*
     $rs->fields indices
     0 TABLE_CAT
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 KEY_SEQ
     5 PK_NAME
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $retarr[strtoupper($rs->fields[3])]->primary_key = true;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
     if (empty($retarr)) {
         $retarr = false;
     }
     return $retarr;
 }
コード例 #3
0
 /**
  * Returns an array of the fields in given table name.
  *
  * @param Model $model Model object to describe
  * @return array Fields in table. Keys are name and type
  */
 function &describe(&$model)
 {
     $cache = parent::describe($model);
     if ($cache != null) {
         return $cache;
     }
     $fields = array();
     $result = db2_columns($this->connection, '', '', strtoupper($this->fullTableName($model)));
     while (db2_fetch_row($result)) {
         $fields[strtolower(db2_result($result, 'COLUMN_NAME'))] = array('type' => $this->column(strtolower(db2_result($result, 'TYPE_NAME'))), 'null' => db2_result($result, 'NULLABLE'), 'default' => db2_result($result, 'COLUMN_DEF'), 'length' => db2_result($result, 'COLUMN_SIZE'));
     }
     $this->__cacheDescription($model->tablePrefix . $model->table, $fields);
     return $fields;
 }