added japanese language
[openemr.git] / phpmyadmin / libraries / tbl_views.lib.php
blob9454454016ac5f4b8c5a09138824a936e08f3fb1
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 $nbColumns = count($view_columns);
35 $nbFields = count($real_source_fields_meta);
36 if ($nbFields > 0) {
38 for ($i=0; $i < $nbFields; $i++) {
40 $map = array();
41 $map['table_name'] = $real_source_fields_meta[$i]->table;
42 $map['refering_column'] = $real_source_fields_meta[$i]->name;
44 if ($nbColumns > 1) {
45 $map['real_column'] = $view_columns[$i];
48 $column_map[] = $map;
55 unset($real_source_result);
57 return $column_map;
62 /**
63 * Get existing data on tranformations applyed for
64 * columns in a particular table
66 * @param string $db Database name looking for
68 * @return mysqli_result Result of executed SQL query
70 function PMA_getExistingTranformationData($db)
72 $cfgRelation = PMA_getRelationsParam();
74 // Get the existing transformation details of the same database
75 // from pma__column_info table
76 $pma_transformation_sql = 'SELECT * FROM '
77 . PMA_Util::backquote($cfgRelation['db']) . '.'
78 . PMA_Util::backquote($cfgRelation['column_info'])
79 . ' WHERE `db_name` = \''
80 . PMA_Util::sqlAddSlashes($db) . '\'';
82 return $GLOBALS['dbi']->tryQuery($pma_transformation_sql);
87 /**
88 * Get SQL query for store new transformation details of a VIEW
90 * @param mysqli_result $pma_tranformation_data Result set of SQL execution
91 * @param array $column_map Details of VIEW columns
92 * @param string $view_name Name of the VIEW
93 * @param string $db Database name of the VIEW
95 * @return string $new_transformations_sql SQL query for new tranformations
97 function PMA_getNewTransformationDataSql(
98 $pma_tranformation_data, $column_map, $view_name, $db
99 ) {
100 $cfgRelation = PMA_getRelationsParam();
102 // Need to store new transformation details for VIEW
103 $new_transformations_sql = 'INSERT INTO '
104 . PMA_Util::backquote($cfgRelation['db']) . '.'
105 . PMA_Util::backquote($cfgRelation['column_info'])
106 . ' (`db_name`, `table_name`, `column_name`, `comment`, '
107 . '`mimetype`, `transformation`, `transformation_options`)'
108 . ' VALUES ';
110 $column_count = 0;
111 $add_comma = false;
113 while ($data_row = $GLOBALS['dbi']->fetchAssoc($pma_tranformation_data)) {
115 foreach ($column_map as $column) {
117 if ($data_row['table_name'] == $column['table_name']
118 && $data_row['column_name'] == $column['refering_column']
121 $new_transformations_sql .= $add_comma ? ', ' : '';
123 $new_transformations_sql .= '('
124 . '\'' . $db . '\', '
125 . '\'' . $view_name . '\', '
126 . '\'';
128 $new_transformations_sql .= (isset($column['real_column']))
129 ? $column['real_column']
130 : $column['refering_column'];
132 $new_transformations_sql .= '\', '
133 . '\'' . $data_row['comment'] . '\', '
134 . '\'' . $data_row['mimetype'] . '\', '
135 . '\'' . $data_row['transformation'] . '\', '
136 . '\''
137 . PMA_Util::sqlAddSlashes(
138 $data_row['transformation_options']
140 . '\')';
142 $add_comma = true;
143 $column_count++;
144 break;
150 if ($column_count == count($column_map)) {
151 break;
156 return ($column_count > 0) ? $new_transformations_sql : '';