Translated using Weblate (Polish)
[phpmyadmin.git] / libraries / tbl_views.lib.php
blob955e2d5064796a18d6a7ca169cdf8f3b2c0fa2e5
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions related to applying transformations for VIEWs
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
13 /**
14 * Get the column details of VIEW with its original references
16 * @param string $sql_query SQL for original resource
17 * @param array $view_columns Columns of VIEW if defined new column names
19 * @return array $column_map Details of VIEW columns
21 function PMA_getColumnMap($sql_query, $view_columns)
24 $column_map = array();
25 // Select query which give results for VIEW
26 $real_source_result = $GLOBALS['dbi']->tryQuery($sql_query);
28 if ($real_source_result !== false) {
30 $real_source_fields_meta = $GLOBALS['dbi']->getFieldsMeta(
31 $real_source_result
34 if (count($real_source_fields_meta) > 0) {
36 for ($i=0; $i<count($real_source_fields_meta); $i++) {
38 $map = array();
39 $map['table_name'] = $real_source_fields_meta[$i]->table;
40 $map['refering_column'] = $real_source_fields_meta[$i]->name;
42 if (count($view_columns) > 1) {
43 $map['real_column'] = $view_columns[$i];
46 $column_map[] = $map;
53 unset($real_source_result);
55 return $column_map;
60 /**
61 * Get existing data on tranformations applyed for
62 * columns in a particular table
64 * @param string $db Database name looking for
66 * @return mysqli_result Result of executed SQL query
68 function PMA_getExistingTranformationData($db)
70 $cfgRelation = PMA_getRelationsParam();
72 // Get the existing transformation details of the same database
73 // from pma__column_info table
74 $pma_transformation_sql = 'SELECT * FROM '
75 . PMA_Util::backquote($cfgRelation['db']) . '.'
76 . PMA_Util::backquote($cfgRelation['column_info'])
77 . ' WHERE `db_name` = \''
78 . PMA_Util::sqlAddSlashes($db) . '\'';
80 return $GLOBALS['dbi']->tryQuery($pma_transformation_sql);
85 /**
86 * Get SQL query for store new transformation details of a VIEW
88 * @param mysqli_result $pma_tranformation_data Result set of SQL execution
89 * @param array $column_map Details of VIEW columns
90 * @param string $view_name Name of the VIEW
91 * @param string $db Database name of the VIEW
93 * @return string $new_transformations_sql SQL query for new tranformations
95 function PMA_getNewTransformationDataSql(
96 $pma_tranformation_data, $column_map, $view_name, $db
97 ) {
98 $cfgRelation = PMA_getRelationsParam();
100 // Need to store new transformation details for VIEW
101 $new_transformations_sql = 'INSERT INTO '
102 . PMA_Util::backquote($cfgRelation['db']) . '.'
103 . PMA_Util::backquote($cfgRelation['column_info'])
104 . ' (`db_name`, `table_name`, `column_name`, `comment`, '
105 . '`mimetype`, `transformation`, `transformation_options`)'
106 . ' VALUES ';
108 $column_count = 0;
109 $add_comma = false;
111 while ($data_row = $GLOBALS['dbi']->fetchAssoc($pma_tranformation_data)) {
113 foreach ($column_map as $column) {
115 if ($data_row['table_name'] == $column['table_name']
116 && $data_row['column_name'] == $column['refering_column']
119 $new_transformations_sql .= $add_comma ? ', ' : '';
121 $new_transformations_sql .= '('
122 . '\'' . $db . '\', '
123 . '\'' . $view_name . '\', '
124 . '\'';
126 $new_transformations_sql .= (isset($column['real_column']))
127 ? $column['real_column']
128 : $column['refering_column'];
130 $new_transformations_sql .= '\', '
131 . '\'' . $data_row['comment'] . '\', '
132 . '\'' . $data_row['mimetype'] . '\', '
133 . '\'' . $data_row['transformation'] . '\', '
134 . '\''
135 . PMA_Util::sqlAddSlashes(
136 $data_row['transformation_options']
138 . '\')';
140 $add_comma = true;
141 $column_count++;
142 break;
148 if ($column_count == count($column_map)) {
149 break;
154 return ($column_count > 0) ? $new_transformations_sql : '';