Esempio n. 1
0
 /**
  * @param string $fieldName
  *
  * @return int Index of field with given name.
  *
  * @throws \Icicle\Exception\InvalidArgumentError If the field name does not exist in the result.
  */
 public function fieldNum(string $fieldName) : int
 {
     $result = \pg_field_num($this->handle, $fieldName);
     if (-1 === $result) {
         throw new InvalidArgumentError(\sprintf('No field with name "%s" in result', $fieldName));
     }
     return $result;
 }
Esempio n. 2
0
 public function as_array($key = NULL, $value = NULL)
 {
     if ($this->_total_rows === 0) {
         return array();
     }
     if (!$this->_as_object and $key === NULL) {
         // Rewind
         $this->_current_row = 0;
         if ($value === NULL) {
             // Indexed rows
             return pg_fetch_all($this->_result);
         }
         // Indexed columns
         return pg_fetch_all_columns($this->_result, pg_field_num($this->_result, $value));
     }
     return parent::as_array($key, $value);
 }
Esempio n. 3
0
 public function FieldNum($fieldName)
 {
     return pg_field_num($this->ds, $fieldName);
 }
Esempio n. 4
0
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_array($result, $i, PGSQL_NUM);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_object($result);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_row($result, $i);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_result($result, $i, 0);
    }
    pg_result_error($result);
    pg_num_rows(pg_execute($db, "php_test", array(100)));
    pg_num_fields(pg_execute($db, "php_test", array(100)));
    pg_field_name($result, 0);
    pg_field_num($result, $field_name);
    pg_field_size($result, 0);
    pg_field_type($result, 0);
    pg_field_prtlen($result, 0);
    pg_field_is_null($result, 0);
    $result = pg_prepare($db, "php_test2", "INSERT INTO " . $table_name . " VALUES (\$1, \$2);");
    pg_result_error($result);
    pg_free_result($result);
    $result = pg_execute($db, "php_test2", array(9999, "A'BC"));
    pg_last_oid($result);
    pg_free_result($result);
}
pg_close($db);
echo "OK";
Esempio n. 5
0
 /**
  * fieldExist
  *
  * Check if a field exist or not.
  *
  * @access public
  * @param  mixed $name
  * @return bool
  */
 public function fieldExist($name)
 {
     return (bool) (pg_field_num($this->handler, $name) > -1);
 }
Esempio n. 6
0
 /**
  * Чтение 1 записи, возврат объекта
  * @param null $i
  * @return object
  */
 public function row($i = null)
 {
     //Если значение больше, чем строк в запросе, выходим
     if ($i >= pg_num_rows($this->result)) {
         return false;
     }
     //Результат возврата
     $return = pg_fetch_object($this->result, $i);
     if ($return == false) {
         return $return;
     }
     //Прооходим по колонкам, собираем массив
     foreach ($return as $column => $value) {
         //Получаем номер столбца
         $num = pg_field_num($this->result, $column);
         //Если значение нулевое, идём дальше
         if (pg_field_is_null($this->result, $i, $num)) {
             $return->{$column} = null;
             continue;
         }
         //В зависимости от типа присваиваем значение
         switch (pg_field_type($this->result, $num)) {
             case "bool":
                 $return->{$column} = $value == "t" ? true : false;
                 break;
             case "int4":
             case "int8":
                 $return->{$column} = (int) $value;
                 break;
         }
     }
     return $return;
 }
Esempio n. 7
0
 private function getPgFieldTypesByName($rs, $r0)
 {
     //$ncols = pg_num_fields($rs);
     $field_types = [];
     foreach ($r0 as $fn => $v0) {
         $fi = pg_field_num($rs, $fn);
         $ft = pg_field_type($rs, $fi);
         $field_types[$fn] = $ft;
     }
     //var_dump($field_types);exit;
     return $field_types;
 }
Esempio n. 8
0
File: pgsql.php Progetto: roojs/pear
 /**
  * mungle booleans into true and false.
  * For a reason that no-one can understand, booleans in postgress return as
  * 't' or 'f' - if you enable option DB_PORTABILITY_BOOLEAN then this 
  * 
  * @param resource postgres result
  * @param array   the row
  * @access protected
  */
 function _convertBoolean($res, &$ar)
 {
     foreach ($ar as $k => $v) {
         if ('bool' != pg_field_type($res, is_int($k) ? $k : pg_field_num($res, $k))) {
             continue;
         }
         $ar[$k] = $v == 't' ? true : ($v == 'f' ? false : null);
     }
 }