Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pgsqlresult.php
1<?php
2namespace Bitrix\Main\DB;
3
4class PgsqlResult extends Result
5{
7 protected $resource;
8
10 private $resultFields = null;
11
17 public function getSelectedRowsCount()
18 {
19 return pg_num_rows($this->resource);
20 }
21
27 public function getFields()
28 {
29 if ($this->resultFields == null)
30 {
31 $this->resultFields = array();
32
33 if (
34 $this->connection
35 && (is_resource($this->resource) || is_object($this->resource))
36 )
37 {
38 $fields = pg_num_fields($this->resource);
39 if ($fields)
40 {
41 $helper = $this->connection->getSqlHelper();
42 for ($i = 0; $i < $fields; $i++)
43 {
44 $fieldName = mb_strtoupper(pg_field_name($this->resource, $i));
45 $fieldType = pg_field_type($this->resource, $i);
46 $this->resultFields[$fieldName] = $helper->getFieldByColumnType($fieldName, $fieldType);
47 }
48 }
49 }
50 }
51
52 return $this->resultFields;
53 }
54
55 protected $byteaFields = false;
56
62 protected function fetchRowInternal()
63 {
64 $result = pg_fetch_assoc($this->resource);
65 if ($result)
66 {
67 if ($this->byteaFields === false)
68 {
69 $this->byteaFields = [];
70 $fieldNum = 0;
71 foreach ($result as $fieldName => $_)
72 {
73 $fieldType = pg_field_type($this->resource, $fieldNum);
74 if ($fieldType === 'bytea')
75 {
76 $this->byteaFields[$fieldName] = $fieldType;
77 }
78 $fieldNum++;
79 }
80 }
81
82 if ($this->byteaFields)
83 {
84 foreach ($this->byteaFields as $fieldName => $fieldType)
85 {
86 $result[$fieldName] = pg_unescape_bytea($result[$fieldName]);
87 }
88 }
89
90 return array_change_key_case($result, \CASE_UPPER);
91 }
92 else
93 {
94 return $result;
95 }
96 }
97}