You are here

function DB_pgsql::tableInfo in Flickr API 5

Returns information about a table or a result set

NOTE: only supports 'table' and 'flags' if <var>$result</var> is a table name.

Parameters

object|string $result DB_result object from a query or a: string containing the name of a table. While this also accepts a query result resource identifier, this behavior is deprecated.

int $mode a valid tableInfo mode:

Return value

array an associative array with the information requested. A DB_Error object on failure.

Overrides DB_common::tableInfo

See also

DB_common::tableInfo()

File

phpFlickr/PEAR/DB/pgsql.php, line 889

Class

DB_pgsql
The methods PEAR DB uses to interact with PHP's pgsql extension for interacting with PostgreSQL databases

Code

function tableInfo($result, $mode = null) {
  if (is_string($result)) {

    /*
     * Probably received a table name.
     * Create a result resource identifier.
     */
    $id = @pg_exec($this->connection, "SELECT * FROM {$result} LIMIT 0");
    $got_string = true;
  }
  elseif (isset($result->result)) {

    /*
     * Probably received a result object.
     * Extract the result resource identifier.
     */
    $id = $result->result;
    $got_string = false;
  }
  else {

    /*
     * Probably received a result resource identifier.
     * Copy it.
     * Deprecated.  Here for compatibility only.
     */
    $id = $result;
    $got_string = false;
  }
  if (!is_resource($id)) {
    return $this
      ->pgsqlRaiseError(DB_ERROR_NEED_MORE_DATA);
  }
  if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
    $case_func = 'strtolower';
  }
  else {
    $case_func = 'strval';
  }
  $count = @pg_numfields($id);
  $res = array();
  if ($mode) {
    $res['num_fields'] = $count;
  }
  for ($i = 0; $i < $count; $i++) {
    $res[$i] = array(
      'table' => $got_string ? $case_func($result) : '',
      'name' => $case_func(@pg_fieldname($id, $i)),
      'type' => @pg_fieldtype($id, $i),
      'len' => @pg_fieldsize($id, $i),
      'flags' => $got_string ? $this
        ->_pgFieldFlags($id, $i, $result) : '',
    );
    if ($mode & DB_TABLEINFO_ORDER) {
      $res['order'][$res[$i]['name']] = $i;
    }
    if ($mode & DB_TABLEINFO_ORDERTABLE) {
      $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
    }
  }

  // free the result only if we were called on a table
  if ($got_string) {
    @pg_freeresult($id);
  }
  return $res;
}