1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mysqlidatabase.php
См. документацию.
1<?php
2
3namespace Bitrix\Perfmon;
4
6{
10 public function getTables($full = true)
11 {
12 $sqlHelper = $this->connection->getSqlHelper();
13 $dbName = $this->connection->getDatabase();
14 $tables = [];
15
16 if ($full)
17 {
18 $tableList = $this->connection->query('show table status');
19 while ($table = $tableList->fetch())
20 {
21 $tables[] = [
22 'TABLE_NAME' => $table['Name'],
23 'ENGINE_TYPE' => $table['Comment'] === 'VIEW' ? 'VIEW' : $table['Engine'],
24 'NUM_ROWS' => $table['Rows'],
25 'BYTES' => $table['Data_length'],
26 'BYTES_INDEX' => $table['Index_length'],
27 ];
28 }
29 }
30 else
31 {
32 $tableList = $this->connection->query('show tables from ' . $sqlHelper->quote($dbName));
33 while ($table = $tableList->fetch())
34 {
35 $tables[] = [
36 'TABLE_NAME' => $table['Tables_in_' . $dbName],
37 'ENGINE_TYPE' => '',
38 'NUM_ROWS' => '',
39 'BYTES' => '',
40 'BYTES_INDEX' => '',
41 ];
42 }
43 }
44
45 $result = new \CDBResult();
46 $result->InitFromArray($tables);
47
48 return $result;
49 }
50
54 protected function fillTableIndexes($tableName)
55 {
56 $table = $this->schema->tables->search($tableName);
57 if (!$table)
58 {
59 $table = new \Bitrix\Perfmon\Sql\Table($tableName);
60
61 $sqlHelper = $this->connection->getSqlHelper();
62 $strSql = 'SHOW INDEXES FROM ' . $sqlHelper->quote($tableName);
63 $indexColumns = [];
64 $unique = [];
65 $fulltext = [];
66 try
67 {
68 $indexList = $this->connection->query($strSql);
69 while ($indexColumn = $indexList->fetch())
70 {
71 $indexColumns[$indexColumn['Key_name']][$indexColumn['Seq_in_index']] = $indexColumn['Column_name'];
72 $unique[$indexColumn['Key_name']] = !$indexColumn['Non_unique'];
73 $fulltext[$indexColumn['Key_name']] = $indexColumn['Index_type'] === 'FULLTEXT';
74 }
75 }
76 catch (\Bitrix\Main\DB\SqlQueryException $_)
77 {
78 }
79
80 foreach ($indexColumns as $indexName => $columns)
81 {
82 $index = new \Bitrix\Perfmon\Sql\Index($indexName, $unique[$indexName], $fulltext[$indexName]);
83 $index->columns = array_values($columns);
84 $table->indexes->add($index);
85 }
86 $this->schema->tables->add($table);
87 }
88
89 return $table;
90 }
91
95 public function getTableFields($tableName = false)
96 {
97 $sqlHelper = $this->connection->getSqlHelper();
98 $strSql = 'SHOW COLUMNS FROM ' . $sqlHelper->quote($tableName);
99 $columnList = $this->connection->query($strSql);
100 $result = [];
101 $resultExt = [];
102 while ($column = $columnList->fetch())
103 {
104 $canSort = true;
105 $match = [];
106 if (preg_match('/^(varchar|char|varbinary)\\((\\d+)\\)/', $column['Type'], $match))
107 {
108 $column['DATA_TYPE'] = 'string';
109 $column['DATA_LENGTH'] = $match[2];
110 if ($match[2] == 1 && ($column['Default'] === 'N' || $column['Default'] === 'Y'))
111 {
112 $column['ORM_DATA_TYPE'] = 'boolean';
113 }
114 else
115 {
116 $column['ORM_DATA_TYPE'] = 'string';
117 }
118 }
119 elseif (preg_match('/^(varchar|char)/', $column['Type']))
120 {
121 $column['DATA_TYPE'] = 'string';
122 $column['ORM_DATA_TYPE'] = 'string';
123 }
124 elseif (preg_match('/^(text|longtext|mediumtext|longblob|mediumblob|blob)/', $column['Type']))
125 {
126 $canSort = false;
127 $column['DATA_TYPE'] = 'string';
128 $column['ORM_DATA_TYPE'] = 'text';
129 }
130 elseif (preg_match('/^(datetime|timestamp)/', $column['Type']))
131 {
132 $column['DATA_TYPE'] = 'datetime';
133 $column['ORM_DATA_TYPE'] = 'datetime';
134 }
135 elseif (preg_match('/^(date)/', $column['Type']))
136 {
137 $column['DATA_TYPE'] = 'date';
138 $column['ORM_DATA_TYPE'] = 'date';
139 }
140 elseif (preg_match('/^(int|smallint|bigint|tinyint|mediumint)/', $column['Type']))
141 {
142 $column['DATA_TYPE'] = 'int';
143 $column['ORM_DATA_TYPE'] = 'integer';
144 }
145 elseif (preg_match('/^(float|double|decimal)/', $column['Type']))
146 {
147 $column['DATA_TYPE'] = 'double';
148 $column['ORM_DATA_TYPE'] = 'float';
149 }
150 else
151 {
152 $canSort = false;
153 $column['DATA_TYPE'] = 'unknown';
154 $column['ORM_DATA_TYPE'] = 'UNKNOWN';
155 }
156 $result[$column['Field']] = $column['DATA_TYPE'];
157 $resultExt[$column['Field']] = [
158 'type' => $column['DATA_TYPE'],
159 'length' => $column['DATA_LENGTH'] ?? null,
160 'nullable' => $column['Null'] !== 'NO',
161 'default' => $column['Default'],
162 'sortable' => $canSort,
163 'orm_type' => $column['ORM_DATA_TYPE'],
164 'increment' => ($column['Extra'] === 'auto_increment'),
165 'type~' => $column['Type'],
166 ];
167 }
168
169 return [$result, $resultExt];
170 }
171}
fillTableIndexes($tableName)
Определения mysqlidatabase.php:54
getTableFields($tableName=false)
Определения mysqlidatabase.php:95
getTables($full=true)
Определения mysqlidatabase.php:10
$result
Определения get_property_values.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$columnList
Определения template.php:276