Improve storing columns on designer and add a translation
[phpmyadmin.git] / libraries / tbl_partition_definition.inc.php
blob4663b2f0697529e084f99fa0a42d22931b9d85f2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table partition definition
6 * @package PhpMyAdmin
7 */
9 use PhpMyAdmin\Core;
11 if (!isset($partitionDetails)) {
13 $partitionDetails = array();
15 // Extract some partitioning and subpartitioning parameters from the request
16 $partitionParams = array(
17 'partition_by', 'partition_expr',
18 'subpartition_by', 'subpartition_expr',
20 foreach ($partitionParams as $partitionParam) {
21 $partitionDetails[$partitionParam] = isset($_POST[$partitionParam])
22 ? $_POST[$partitionParam] : '';
25 if (Core::isValid($_POST['partition_count'], 'numeric')) {
26 // MySQL's limit is 8192, so do not allow more
27 $partition_count = min(intval($_POST['partition_count']), 8192);
28 } else {
29 $partition_count = 0;
31 $partitionDetails['partition_count']
32 = ($partition_count === 0) ? '' : $partition_count;
33 if (Core::isValid($_POST['subpartition_count'], 'numeric')) {
34 // MySQL's limit is 8192, so do not allow more
35 $subpartition_count = min(intval($_POST['subpartition_count']), 8192);
36 } else {
37 $subpartition_count = 0;
39 $partitionDetails['subpartition_count']
40 = ($subpartition_count === 0) ? '' : $subpartition_count;
42 // Only LIST and RANGE type parameters allow subpartitioning
43 $partitionDetails['can_have_subpartitions'] = $partition_count > 1
44 && isset($_POST['partition_by'])
45 && ($_POST['partition_by'] == 'RANGE'
46 || $_POST['partition_by'] == 'RANGE COLUMNS'
47 || $_POST['partition_by'] == 'LIST'
48 || $_POST['partition_by'] == 'LIST COLUMNS');
50 // Values are specified only for LIST and RANGE type partitions
51 $partitionDetails['value_enabled'] = isset($_POST['partition_by'])
52 && ($_POST['partition_by'] == 'RANGE'
53 || $_POST['partition_by'] == 'RANGE COLUMNS'
54 || $_POST['partition_by'] == 'LIST'
55 || $_POST['partition_by'] == 'LIST COLUMNS');
57 // Has partitions
58 if ($partition_count > 1) {
59 $partitions = isset($_POST['partitions'])
60 ? $_POST['partitions']
61 : array();
63 // Remove details of the additional partitions
64 // when number of partitions have been reduced
65 array_splice($partitions, $partition_count);
67 for ($i = 0; $i < $partition_count; $i++) {
68 if (! isset($partitions[$i])) { // Newly added partition
69 $partitions[$i] = array(
70 'name' => 'p' . $i,
71 'value_type' => '',
72 'value' => '',
73 'engine' => '',
74 'comment' => '',
75 'data_directory' => '',
76 'index_directory' => '',
77 'max_rows' => '',
78 'min_rows' => '',
79 'tablespace' => '',
80 'node_group' => '',
84 $partition =& $partitions[$i];
85 $partition['prefix'] = 'partitions[' . $i . ']';
87 // Changing from HASH/KEY to RANGE/LIST
88 if (! isset($partition['value_type'])) {
89 $partition['value_type'] = '';
90 $partition['value'] = '';
92 if (! isset($partition['engine'])) { // When removing subpartitioning
93 $partition['engine'] = '';
94 $partition['comment'] = '';
95 $partition['data_directory'] = '';
96 $partition['index_directory'] = '';
97 $partition['max_rows'] = '';
98 $partition['min_rows'] = '';
99 $partition['tablespace'] = '';
100 $partition['node_group'] = '';
103 if ($subpartition_count > 1
104 && $partitionDetails['can_have_subpartitions'] == true
105 ) { // Has subpartitions
106 $partition['subpartition_count'] = $subpartition_count;
108 if (! isset($partition['subpartitions'])) {
109 $partition['subpartitions'] = array();
111 $subpartitions =& $partition['subpartitions'];
113 // Remove details of the additional subpartitions
114 // when number of subpartitions have been reduced
115 array_splice($subpartitions, $subpartition_count);
117 for ($j = 0; $j < $subpartition_count; $j++) {
118 if (! isset($subpartitions[$j])) { // Newly added subpartition
119 $subpartitions[$j] = array(
120 'name' => $partition['name'] . '_s' . $j,
121 'engine' => '',
122 'comment' => '',
123 'data_directory' => '',
124 'index_directory' => '',
125 'max_rows' => '',
126 'min_rows' => '',
127 'tablespace' => '',
128 'node_group' => '',
132 $subpartition =& $subpartitions[$j];
133 $subpartition['prefix'] = 'partitions[' . $i . ']'
134 . '[subpartitions][' . $j . ']';
136 } else { // No subpartitions
137 unset($partition['subpartitions']);
138 unset($partition['subpartition_count']);
141 $partitionDetails['partitions'] = $partitions;