/** * 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; }
/** * Move internal result pointer * * Moves the pointer within the query result to a specified location, or * to the beginning if nothing is specified. * * @param resource $result Resultset * @param integer $rowNumber Row number * * @return boolean */ public function resultSeek($result, $rowNumber) { return db2_result($result, $rowNumber); }
/** * Gets a property value in the fetched row given a SQL statement. * * @param unknown $sql * the sql statement. * @throws Exception * @return the property value. */ public function fetchObjectProperty($sql, $property) { $propertyValue = null; $connection = $this->connect(); $stmt = db2_prepare($connection, $sql); $result = db2_execute($stmt, array(0)); if ($result) { while (db2_fetch_row($stmt)) { $propertyValue = db2_result($stmt, $property); } } else { $message = "\nCould not fetch the object from database table. " . db2_stmt_errormsg($stmt); throw new Exception($message); } $this->__destruct(); return $propertyValue; }
/** * returns a first column from sql stmt result set * * used in one place: iToolkitService's ReadSPLFData(). * * @todo eliminate this method if possible. * * @param $conn * @param $sql * @throws \Exception * @return array */ public function executeQuery($conn, $sql) { $txt = array(); $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); if (is_resource($stmt)) { if (db2_fetch_row($stmt)) { $column = db2_result($stmt, 0); $txt[] = $column; } } else { $this->setStmtError(); throw new \Exception("Failure executing SQL: ({$sql}) " . db2_stmt_errormsg(), db2_stmt_error()); } return $txt; }