1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
table.php
См. документацию.
1<?php
2
3class CPerfomanceTableList extends CDBResult
4{
5 protected $dbName = '';
6
7 public static function GetList($bFull = true, $connection = null)
8 {
10
11 return \Bitrix\Perfmon\BaseDatabase::createFromConnection($connection)->getTables($bFull);
12 }
13}
14
16{
17 public $TABLE_NAME = '';
18 protected $connection = null;
19 protected $database = null;
20
21 public function Init($TABLE_NAME, $connection = null)
22 {
24 $this->database = \Bitrix\Perfmon\BaseDatabase::createFromConnection($this->connection);
25 $this->TABLE_NAME = trim($TABLE_NAME, '`');
26 }
27
28 public function IsExists($TABLE_NAME = false)
29 {
30 if ($TABLE_NAME === false)
31 {
33 }
34
35 $TABLE_NAME = trim($TABLE_NAME, '`');
36 if ($TABLE_NAME === '')
37 {
38 return false;
39 }
40
41 return $this->connection->isTableExists($TABLE_NAME);
42 }
43
44 public function GetIndexes($TABLE_NAME = false)
45 {
46 if ($TABLE_NAME === false)
47 {
49 }
50
51 $TABLE_NAME = trim($TABLE_NAME, '`');
52 if ($TABLE_NAME === '')
53 {
54 return [];
55 }
56
57 return $this->database->getIndexes($TABLE_NAME);
58 }
59
60 public function GetUniqueIndexes($TABLE_NAME = false)
61 {
62 if ($TABLE_NAME === false)
63 {
65 }
66
67 $TABLE_NAME = trim($TABLE_NAME, '`');
68 if ($TABLE_NAME === '')
69 {
70 return [];
71 }
72
73 return $this->database->getUniqueIndexes($TABLE_NAME);
74 }
75
76 public function GetFullTextIndexes($TABLE_NAME = false)
77 {
78 if ($TABLE_NAME === false)
79 {
81 }
82
83 $TABLE_NAME = trim($TABLE_NAME, '`');
84 if ($TABLE_NAME === '')
85 {
86 return [];
87 }
88
89 return $this->database->getFullTextIndexes($TABLE_NAME);
90 }
91
92 public function GetList($arSelect, $arFilter, $arOrder = [], $arNavParams = false)
93 {
94 $context = \Bitrix\Main\Context::getCurrent();
95 $culture = $context->getCulture();
96 $sqlHelper = $this->connection->getSqlHelper();
97
98 $arFields = $this->GetTableFields();
99
100 if (!is_array($arSelect))
101 {
102 $arSelect = [];
103 }
104 if (count($arSelect) < 1)
105 {
106 $arSelect = array_keys($arFields);
107 }
108
109 if (!is_array($arOrder))
110 {
111 $arOrder = [];
112 }
113
114 $arQueryOrder = [];
115 foreach ($arOrder as $strColumn => $strDirection)
116 {
117 $strDirection = mb_strtoupper($strDirection) === 'ASC' ? 'ASC' : 'DESC';
118 if (array_key_exists($strColumn, $arFields))
119 {
120 $arSelect[] = $strColumn;
121 if ($arFields[$strColumn] === 'datetime' || $arFields[$strColumn] === 'date')
122 {
123 $arQueryOrder[$strColumn] = $sqlHelper->quote('TMP_' . $strColumn) . ' ' . $strDirection;
124 }
125 else
126 {
127 $arQueryOrder[$strColumn] = $sqlHelper->quote($strColumn) . ' ' . $strDirection;
128 }
129 }
130 }
131
132 $arQuerySelect = [];
133 foreach ($arSelect as $strColumn)
134 {
135 if (array_key_exists($strColumn, $arFields))
136 {
137 if ($arFields[$strColumn] === 'datetime' || $arFields[$strColumn] === 'date')
138 {
139 $arQuerySelect['TMP_' . $strColumn] = 't.' . $sqlHelper->quote($strColumn) . ' TMP_' . $strColumn;
140 $arQuerySelect[$strColumn] = $sqlHelper->formatDate($culture->getFormatDate(), 't.' . $sqlHelper->quote($strColumn)) . ' ' . $sqlHelper->quote($strColumn);
141 $arQuerySelect['FULL_' . $strColumn] = $sqlHelper->formatDate($culture->getFormatDatetime(), 't.' . $sqlHelper->quote($strColumn)) . ' FULL_' . $strColumn;
142 $arQuerySelect['SHORT_' . $strColumn] = $sqlHelper->formatDate($culture->getFormatDate(), 't.' . $sqlHelper->quote($strColumn)) . ' SHORT_' . $strColumn;
143 }
144 else
145 {
146 $arQuerySelect[$strColumn] = 't.' . $sqlHelper->quote($strColumn);
147 }
148 }
149 }
150
151 foreach ($arFields as $FIELD_NAME => $FIELD_TYPE)
152 {
153 $arFields[$FIELD_NAME] = [
154 'TABLE_ALIAS' => 't',
155 'FIELD_NAME' => 't.' . $sqlHelper->quote($FIELD_NAME),
156 'FIELD_TYPE' => $FIELD_TYPE,
157 'JOIN' => false,
158 //"LEFT_JOIN" => "lt",
159 ];
160 }
161 $obQueryWhere = new CSQLWhere;
162 $obQueryWhere->SetFields($arFields);
163
164 if (count($arQuerySelect) < 1)
165 {
166 $arQuerySelect = ['*' => 't.*'];
167 }
168
169 $strSelect = 'SELECT ' . implode(', ', $arQuerySelect) . "\n";
170
171 $strSql = 'FROM ' /*. $sqlHelper->quote($this->connection->getDatabase()) . '.'*/ . $sqlHelper->quote($this->TABLE_NAME) . " t\n";
172 $strQueryWhere = $obQueryWhere->GetQuery($arFilter);
173 if ($strQueryWhere)
174 {
175 $strSql .= 'WHERE ' . $strQueryWhere . "\n";
176 }
177 $strOrder = $arQueryOrder ? 'ORDER BY ' . implode(', ', $arQueryOrder) : '';
178
179 if (!is_array($arNavParams))
180 {
181 $dbr = $this->connection->query($strSelect . $strSql . $strOrder);
182 }
183 elseif (isset($arNavParams['bOnlyCount']) && $arNavParams['bOnlyCount'] === true)
184 {
185 $res_cnt = $this->connection->query("SELECT count('x') CNT " . $strSql);
186 $ar_cnt = $res_cnt->fetch();
187
188 return $ar_cnt['CNT'];
189 }
190 elseif ($arNavParams['nTopCount'] > 0)
191 {
192 $strSql = $sqlHelper->getTopSql($strSelect . $strSql . $strOrder, $arNavParams['nTopCount'], $arNavParams['nOffset']);
193 $dbr = $this->connection->query($strSql);
194 }
195 else
196 {
197 $dbr = $this->connection->query($strSelect . $strSql . $strOrder);
198 }
199
200 $dbr->is_filtered = ($strQueryWhere !== '');
201
202 return $dbr;
203 }
204
205 public function GetTableFields($TABLE_NAME = false, $bExtended = false)
206 {
207 static $cache = [];
208
209 if ($TABLE_NAME === false)
210 {
212 }
213
214 $TABLE_NAME = trim($TABLE_NAME, '`');
215 if ($TABLE_NAME === '')
216 {
217 return false;
218 }
219
220 if (!array_key_exists($TABLE_NAME, $cache))
221 {
222 $cache[$TABLE_NAME] = $this->database->getTableFields($TABLE_NAME);
223 }
224
225 if ($bExtended)
226 {
227 return $cache[$TABLE_NAME][1];
228 }
229 else
230 {
231 return $cache[$TABLE_NAME][0];
232 }
233 }
234
235 public function getCreateIndexDDL($TABLE_NAME, $INDEX_NAME, $INDEX_COLUMNS)
236 {
237 $tableFields = $this->GetTableFields($TABLE_NAME, true);
238 foreach ($INDEX_COLUMNS as $i => $field)
239 {
240 if ($tableFields[trim($field, '`[]"')]['orm_type'] === 'text')
241 {
242 $INDEX_COLUMNS[$i] = $field . '(100)';
243 }
244 }
245
246 return 'CREATE INDEX ' . $INDEX_NAME . ' ON ' . $TABLE_NAME . ' (' . implode(', ', $INDEX_COLUMNS) . ')';
247 }
248}
$connection
Определения actionsdefinitions.php:38
static getConnection($name="")
Определения application.php:638
static createFromConnection($connection)
Определения basedatabase.php:23
SetFields($arFields)
Определения sqlwhere.php:239
Определения table.php:16
$connection
Определения table.php:18
GetFullTextIndexes($TABLE_NAME=false)
Определения table.php:76
GetUniqueIndexes($TABLE_NAME=false)
Определения table.php:60
GetList($arSelect, $arFilter, $arOrder=[], $arNavParams=false)
Определения table.php:92
$database
Определения table.php:19
GetTableFields($TABLE_NAME=false, $bExtended=false)
Определения table.php:205
GetIndexes($TABLE_NAME=false)
Определения table.php:44
$TABLE_NAME
Определения table.php:17
getCreateIndexDDL($TABLE_NAME, $INDEX_NAME, $INDEX_COLUMNS)
Определения table.php:235
Init($TABLE_NAME, $connection=null)
Определения table.php:21
IsExists($TABLE_NAME=false)
Определения table.php:28
Определения table.php:4
static GetList($bFull=true, $connection=null)
Определения table.php:7
$dbName
Определения table.php:5
Определения sqlwhere.php:1359
$arFields
Определения dblapprove.php:5
$context
Определения csv_new_setup.php:223
$culture
Определения include.php:61
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$arFilter
Определения user_search.php:106