Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / SystemDatabase.php
blob7e39e46293b4b7577dd9657120e467673fa67eef
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA\libraries\SystemDatabase class
6 * @package PMA
7 */
8 namespace PMA\libraries;
10 require_once 'libraries/database_interface.inc.php';
12 /**
13 * Class SystemDatabase
15 * @package PMA
17 class SystemDatabase
19 /**
20 * @var DatabaseInterface
22 protected $dbi;
24 /**
25 * Get instance of SystemDatabase
27 * @param DatabaseInterface $dbi Database interface for the system database
30 function __construct(DatabaseInterface $dbi)
32 $this->dbi = $dbi;
35 /**
36 * Get existing data on transformations applied for
37 * columns in a particular table
39 * @param string $db Database name looking for
41 * @return \mysqli_result Result of executed SQL query
43 public function getExistingTransformationData($db)
45 $cfgRelation = \PMA_getRelationsParam();
47 // Get the existing transformation details of the same database
48 // from pma__column_info table
49 $pma_transformation_sql = sprintf(
50 "SELECT * FROM %s.%s WHERE `db_name` = '%s'",
51 Util::backquote($cfgRelation['db']),
52 Util::backquote($cfgRelation['column_info']),
53 $GLOBALS['dbi']->escapeString($db)
56 return $this->dbi->tryQuery($pma_transformation_sql);
59 /**
60 * Get SQL query for store new transformation details of a VIEW
62 * @param object $pma_transformation_data Result set of SQL execution
63 * @param array $column_map Details of VIEW columns
64 * @param string $view_name Name of the VIEW
65 * @param string $db Database name of the VIEW
67 * @return string $new_transformations_sql SQL query for new transformations
69 function getNewTransformationDataSql(
70 $pma_transformation_data, $column_map, $view_name, $db
71 ) {
72 $cfgRelation = \PMA_getRelationsParam();
74 // Need to store new transformation details for VIEW
75 $new_transformations_sql = sprintf(
76 "INSERT INTO %s.%s ("
77 . "`db_name`, `table_name`, `column_name`, "
78 . "`comment`, `mimetype`, `transformation`, "
79 . "`transformation_options`) VALUES",
80 Util::backquote($cfgRelation['db']),
81 Util::backquote($cfgRelation['column_info'])
84 $column_count = 0;
85 $add_comma = false;
87 while ($data_row = $this->dbi->fetchAssoc($pma_transformation_data)) {
89 foreach ($column_map as $column) {
91 if ($data_row['table_name'] != $column['table_name']
92 || $data_row['column_name'] != $column['refering_column']
93 ) {
94 continue;
97 $new_transformations_sql .= sprintf(
98 "%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
99 $add_comma ? ', ' : '',
100 $db,
101 $view_name,
102 isset($column['real_column'])
103 ? $column['real_column']
104 : $column['refering_column'],
105 $data_row['comment'],
106 $data_row['mimetype'],
107 $data_row['transformation'],
108 $GLOBALS['dbi']->escapeString(
109 $data_row['transformation_options']
113 $add_comma = true;
114 $column_count++;
115 break;
118 if ($column_count == count($column_map)) {
119 break;
123 return ($column_count > 0) ? $new_transformations_sql : '';