Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 388 lines (372 sloc) 15.657 kB
a7096dd Separate editing functions
jakubvrana authored
1 <?php
471ae2b Move select function
jakubvrana authored
2 /** Print select result
3 * @param Min_Result
4 * @param Min_DB connection to examine indexes
0449351 @vrana Report errors only in primary connection
authored
5 * @param string base link for <th> fields
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
6 * @param array
471ae2b Move select function
jakubvrana authored
7 * @return null
8 */
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
9 function select($result, $connection2 = null, $href = "", $orgtables = array()) {
782921b @vrana Finish SQLite
authored
10 $links = array(); // colno => orgtable - create links from these columns
11 $indexes = array(); // orgtable => array(column => colno) - primary keys
12 $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
13 $blobs = array(); // colno => bool - display bytes for blobs
14 $types = array(); // colno => type - display char in <code>
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
15 $return = array(); // table => orgtable - mapping to use in EXPLAIN
782921b @vrana Finish SQLite
authored
16 odd(''); // reset odd for each result
17 for ($i=0; $row = $result->fetch_row(); $i++) {
18 if (!$i) {
19 echo "<table cellspacing='0' class='nowrap'>\n";
20 echo "<thead><tr>";
21 for ($j=0; $j < count($row); $j++) {
22 $field = $result->fetch_field();
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
23 $name = $field->name;
782921b @vrana Finish SQLite
authored
24 $orgtable = $field->orgtable;
25 $orgname = $field->orgname;
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
26 $return[$field->table] = $orgtable;
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
27 if ($href) { // MySQL EXPLAIN
28 $links[$j] = ($name == "table" ? "table=" : ($name == "possible_keys" ? "indexes=" : null));
29 } elseif ($orgtable != "") {
782921b @vrana Finish SQLite
authored
30 if (!isset($indexes[$orgtable])) {
31 // find primary key in each table
32 $indexes[$orgtable] = array();
33 foreach (indexes($orgtable, $connection2) as $index) {
34 if ($index["type"] == "PRIMARY") {
35 $indexes[$orgtable] = array_flip($index["columns"]);
36 break;
471ae2b Move select function
jakubvrana authored
37 }
38 }
782921b @vrana Finish SQLite
authored
39 $columns[$orgtable] = $indexes[$orgtable];
471ae2b Move select function
jakubvrana authored
40 }
782921b @vrana Finish SQLite
authored
41 if (isset($columns[$orgtable][$orgname])) {
42 unset($columns[$orgtable][$orgname]);
43 $indexes[$orgtable][$orgname] = $j;
44 $links[$j] = $orgtable;
471ae2b Move select function
jakubvrana authored
45 }
46 }
782921b @vrana Finish SQLite
authored
47 if ($field->charsetnr == 63) { // 63 - binary
48 $blobs[$j] = true;
49 }
50 $types[$j] = $field->type;
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
51 $name = h($name);
f195903 @vrana Use rel="noreferrer" for documentation links
authored
52 echo "<th" . ($orgtable != "" || $field->name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . ($href ? "<a href='$href" . strtolower($name) . "' target='_blank' rel='noreferrer'>$name</a>" : $name);
471ae2b Move select function
jakubvrana authored
53 }
782921b @vrana Finish SQLite
authored
54 echo "</thead>\n";
55 }
56 echo "<tr" . odd() . ">";
57 foreach ($row as $key => $val) {
6591d48 @vrana Replace isset($var) by $var !== null
authored
58 if ($val === null) {
782921b @vrana Finish SQLite
authored
59 $val = "<i>NULL</i>";
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
60 } elseif ($blobs[$key] && !is_utf8($val)) {
61 $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
62 } elseif (!strlen($val)) { // strlen - SQLite can return int
63 $val = "&nbsp;"; // some content to print a border
782921b @vrana Finish SQLite
authored
64 } else {
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
65 $val = h($val);
66 if ($types[$key] == 254) { // 254 - char
67 $val = "<code>$val</code>";
782921b @vrana Finish SQLite
authored
68 }
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
69 }
70 if (isset($links[$key]) && !$columns[$links[$key]]) {
71 if ($href) { // MySQL EXPLAIN
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
72 $table = $row[array_search("table=", $links)];
73 $link = $links[$key] . urlencode($orgtables[$table] != "" ? $orgtables[$table] : $table);
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
74 } else {
782921b @vrana Finish SQLite
authored
75 $link = "edit=" . urlencode($links[$key]);
76 foreach ($indexes[$links[$key]] as $col => $j) {
77 $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
471ae2b Move select function
jakubvrana authored
78 }
79 }
8a9642b @vrana Link tables and indexes from SQL command EXPLAIN
authored
80 $val = "<a href='" . h(ME . $link) . "'>$val</a>";
471ae2b Move select function
jakubvrana authored
81 }
782921b @vrana Finish SQLite
authored
82 echo "<td>$val";
471ae2b Move select function
jakubvrana authored
83 }
84 }
782921b @vrana Finish SQLite
authored
85 echo ($i ? "</table>" : "<p class='message'>" . lang('No rows.')) . "\n";
48df7aa @vrana Link to original table in EXPLAIN of SELECT * FROM table t
authored
86 return $return;
471ae2b Move select function
jakubvrana authored
87 }
88
1118566 Documentation
jakubvrana authored
89 /** Get referencable tables with single column primary key except self
90 * @param string
91 * @return array ($table_name => $field)
92 */
ced9de9 Create single column foreign key in table structure
jakubvrana authored
93 function referencable_primary($self) {
94 $return = array(); // table_name => field
3f5b683 Reintegrate sqlite branch
jakubvrana authored
95 foreach (table_status() as $table_name => $table) {
96 if ($table_name != $self && fk_support($table)) {
ced9de9 Create single column foreign key in table structure
jakubvrana authored
97 foreach (fields($table_name) as $field) {
98 if ($field["primary"]) {
99 if ($return[$table_name]) { // multi column primary key
100 unset($return[$table_name]);
101 break;
102 }
103 $return[$table_name] = $field;
104 }
105 }
106 }
107 }
108 return $return;
109 }
110
d6ac5f1 @vrana Move textarea function to editing.*
authored
111 /** Print SQL <textarea> tag
112 * @param string
113 * @param int
114 * @param int
115 * @param string
116 * @return null
117 */
a71b990 @vrana Remove CodeMirror
authored
118 function textarea($name, $value, $rows = 10, $cols = 80) {
119 echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>"; // spellcheck, wrap - not valid before HTML5
ef9d6d4 @vrana Save memory
authored
120 if (is_array($value)) {
121 foreach ($value as $val) { // not implode() to save memory
24c51fe @vrana Print current time next to executed SQL queries
authored
122 echo h($val[0]) . "\n\n\n"; // $val == array($query, $time)
ef9d6d4 @vrana Save memory
authored
123 }
124 } else {
125 echo h($value);
126 }
127 echo "</textarea>";
d6ac5f1 @vrana Move textarea function to editing.*
authored
128 }
129
9eced78 @vrana Display total time in show only errors mode in SQL command
authored
130 /** Format time difference
0060c60 @vrana Save bytes
authored
131 * @param string output of microtime()
132 * @param string output of microtime()
9eced78 @vrana Display total time in show only errors mode in SQL command
authored
133 * @return string HTML code
134 */
135 function format_time($start, $end) {
0060c60 @vrana Save bytes
authored
136 return " <span class='time'>(" . lang('%.3f s', max(0, array_sum(explode(" ", $end)) - array_sum(explode(" ", $start)))) . ")</span>";
9eced78 @vrana Display total time in show only errors mode in SQL command
authored
137 }
138
1118566 Documentation
jakubvrana authored
139 /** Print table columns for type edit
140 * @param string
141 * @param array
142 * @param array
143 * @param array returned by referencable_primary()
144 * @return null
145 */
ced9de9 Create single column foreign key in table structure
jakubvrana authored
146 function edit_type($key, $field, $collations, $foreign_keys = array()) {
b0d637b @vrana Avoid fatal errors
authored
147 global $structured_types, $types, $unsigned, $on_actions;
f2813b5 Don't hide/show added/dropped columns (bug 1920167)
jakubvrana authored
148 ?>
6e2a887 @vrana Typos
authored
149 <td><select name="<?php echo $key; ?>[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"><?php echo optionlist((!$field["type"] || isset($types[$field["type"]]) ? array() : array($field["type"])) + $structured_types + ($foreign_keys ? array(lang('Foreign keys') => $foreign_keys) : array()), $field["type"]); ?></select>
d0cf5a8 @vrana Create table options width
authored
150 <td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td class="options"><?php
5cac902 Work with default values
jakubvrana authored
151 echo "<select name='$key" . "[collation]'" . (ereg('(char|text|enum|set)$', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
dc4fc82 @vrana ON DELETE action for foreign keys in Create table
authored
152 echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
8e75d54 @vrana Save bytes
authored
153 echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
a7096dd Separate editing functions
jakubvrana authored
154 }
155
1118566 Documentation
jakubvrana authored
156 /** Filter length value including enums
157 * @param string
158 * @return string
159 */
f93c84e Function process_length used only in Adminer
jakubvrana authored
160 function process_length($length) {
161 global $enum_length;
162 return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
163 }
164
1118566 Documentation
jakubvrana authored
165 /** Create SQL string from field type
166 * @param array
167 * @param string
168 * @return string
169 */
a3c969c Routines uses CHARACTER SET
jakubvrana authored
170 function process_type($field, $collate = "COLLATE") {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
171 global $unsigned;
9e1d1c3 @vrana Respect unsupported types
authored
172 return " $field[type]"
4780703 @vrana Respect PostgreSQL custom types
authored
173 . ($field["length"] != "" ? "(" . process_length($field["length"]) . ")" : "")
5abd943 Change simple preg_match to ereg
jakubvrana authored
174 . (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
175 . (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
a7096dd Separate editing functions
jakubvrana authored
176 ;
177 }
178
1118566 Documentation
jakubvrana authored
179 /** Create SQL string from field
180 * @param array basic field information
181 * @param array information about field type
9e1d1c3 @vrana Respect unsupported types
authored
182 * @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT")
1118566 Documentation
jakubvrana authored
183 */
2e680bc Speedup of simple alter table
jakubvrana authored
184 function process_field($field, $type_field) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
185 return array(
ef867e6 @vrana Trim identifiers (bug #3405309)
authored
186 idf_escape(trim($field["field"])),
3f5b683 Reintegrate sqlite branch
jakubvrana authored
187 process_type($type_field),
188 ($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
4ff2f03 @vrana Alter bit type default value
authored
189 (isset($field["default"]) ? " DEFAULT " . (($field["type"] == "timestamp" && eregi('^CURRENT_TIMESTAMP$', $field["default"])) || ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $field["default"])) ? $field["default"] : q($field["default"])) : ""),
3f5b683 Reintegrate sqlite branch
jakubvrana authored
190 ($field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
191 (support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
736d6e4 @vrana Fix alter table
authored
192 ($field["auto_increment"] ? auto_increment() : null),
3f5b683 Reintegrate sqlite branch
jakubvrana authored
193 );
2e680bc Speedup of simple alter table
jakubvrana authored
194 }
195
1118566 Documentation
jakubvrana authored
196 /** Get type class to use in CSS
197 * @param string
198 * @return string class=''
199 */
3015aed Separate type_class
jakubvrana authored
200 function type_class($type) {
d144e9c Save bytes
jakubvrana authored
201 foreach (array(
202 'char' => 'text',
203 'date' => 'time|year',
204 'binary' => 'blob',
205 'enum' => 'set',
206 ) as $key => $val) {
c0c7ab3 Typo
jakubvrana authored
207 if (ereg("$key|$val", $type)) {
d144e9c Save bytes
jakubvrana authored
208 return " class='$key'";
209 }
3015aed Separate type_class
jakubvrana authored
210 }
211 }
212
1118566 Documentation
jakubvrana authored
213 /** Print table interior for fields editing
214 * @param array
215 * @param array
216 * @param string TABLE or PROCEDURE
217 * @param int number of fields allowed by Suhosin
218 * @param array returned by referencable_primary()
3a14845 @vrana Respect defaults and comments checkbox after post (bug #3311791)
authored
219 * @param bool display comments column
220 * @return null
1118566 Documentation
jakubvrana authored
221 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
222 function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $foreign_keys = array(), $comments = false) {
d31d4e9 Emulate REQUEST_URI
jakubvrana authored
223 global $inout;
f2813b5 Don't hide/show added/dropped columns (bug 1920167)
jakubvrana authored
224 ?>
dfe2540 Centralize nowrap
jakubvrana authored
225 <thead><tr class="wrap">
b349612 Remove useless translations
jakubvrana authored
226 <?php if ($type == "PROCEDURE") { ?><td>&nbsp;<?php } ?>
ace55ed HTML instead of XHTML
jakubvrana authored
227 <th><?php echo ($type == "TABLE" ? lang('Column name') : lang('Parameter name')); ?>
3a76704 Spaces
jakubvrana authored
228 <td><?php echo lang('Type'); ?><textarea id="enum-edit" rows="4" cols="12" wrap="off" style="display: none;" onblur="editingLengthBlur(this);"></textarea>
ace55ed HTML instead of XHTML
jakubvrana authored
229 <td><?php echo lang('Length'); ?>
230 <td><?php echo lang('Options'); ?>
a7096dd Separate editing functions
jakubvrana authored
231 <?php if ($type == "TABLE") { ?>
b349612 Remove useless translations
jakubvrana authored
232 <td>NULL
3f5b683 Reintegrate sqlite branch
jakubvrana authored
233 <td><input type="radio" name="auto_increment_col" value=""><acronym title="<?php echo lang('Auto Increment'); ?>">AI</acronym>
3a14845 @vrana Respect defaults and comments checkbox after post (bug #3311791)
authored
234 <td<?php echo ($_POST["defaults"] ? "" : " class='hidden'"); ?>><?php echo lang('Default values'); ?>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
235 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . ">" . lang('Comment') : ""); ?>
a7096dd Separate editing functions
jakubvrana authored
236 <?php } ?>
dafd2de @vrana Avoid flicker before the image is loaded
authored
237 <td><?php echo "<input type='image' class='icon' name='add[" . (support("move_col") ? 0 : count($fields)) . "]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script>
ace55ed HTML instead of XHTML
jakubvrana authored
238 </thead>
dfc03ca @vrana Comment
authored
239 <tbody onkeydown="return editingKeydown(event);">
240 <?php
93c27c9 Separate type_change()
jakubvrana authored
241 foreach ($fields as $i => $field) {
242 $i++;
da8a1b6 Respect move and drop column support
jakubvrana authored
243 $orig = $field[($_POST ? "orig" : "field")];
244 $display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && !$_POST["drop_col"][$i])) && (support("drop_col") || $orig == "");
93c27c9 Separate type_change()
jakubvrana authored
245 ?>
a76c555 Remove odd() from create
jakubvrana authored
246 <tr<?php echo ($display ? "" : " style='display: none;'"); ?>>
55e2b75 @vrana Save bytes
authored
247 <?php echo ($type == "PROCEDURE" ? "<td>" . html_select("fields[$i][inout]", explode("|", $inout), $field["inout"]) : ""); ?>
da8a1b6 Respect move and drop column support
jakubvrana authored
248 <th><?php if ($display) { ?><input name="fields[<?php echo $i; ?>][field]" value="<?php echo h($field["field"]); ?>" onchange="<?php echo ($field["field"] != "" || count($fields) > 1 ? "" : "editingAddRow(this, $allowed); "); ?>editingNameChange(this);" maxlength="64"><?php } ?><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo h($orig); ?>">
ced9de9 Create single column foreign key in table structure
jakubvrana authored
249 <?php edit_type("fields[$i]", $field, $collations, $foreign_keys); ?>
a7096dd Separate editing functions
jakubvrana authored
250 <?php if ($type == "TABLE") { ?>
6b30cfa Separate checkbox
jakubvrana authored
251 <td><?php echo checkbox("fields[$i][null]", 1, $field["null"]); ?>
b79a28f @vrana Link table names in SQL queries
authored
252 <td><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked<?php } ?> onclick="var field = this.form['fields[' + this.value + '][field]']; if (!field.value) { field.value = 'id'; field.onchange(); }">
3a14845 @vrana Respect defaults and comments checkbox after post (bug #3311791)
authored
253 <td<?php echo ($_POST["defaults"] ? "" : " class='hidden'"); ?>><?php echo checkbox("fields[$i][has_default]", 1, $field["has_default"]); ?><input name="fields[<?php echo $i; ?>][default]" value="<?php echo h($field["default"]); ?>" onchange="this.previousSibling.checked = true;">
3f5b683 Reintegrate sqlite branch
jakubvrana authored
254 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . "><input name='fields[$i][comment]' value='" . h($field["comment"]) . "' maxlength='255'>" : ""); ?>
a7096dd Separate editing functions
jakubvrana authored
255 <?php } ?>
256 <?php
da8a1b6 Respect move and drop column support
jakubvrana authored
257 echo "<td>";
258 echo (support("move_col") ?
dafd2de @vrana Avoid flicker before the image is loaded
authored
259 "<input type='image' class='icon' name='add[$i]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "' onclick='return !editingAddRow(this, $allowed, 1);'>&nbsp;"
260 . "<input type='image' class='icon' name='up[$i]' src='../adminer/static/up.gif' alt='^' title='" . lang('Move up') . "'>&nbsp;"
261 . "<input type='image' class='icon' name='down[$i]' src='../adminer/static/down.gif' alt='v' title='" . lang('Move down') . "'>&nbsp;"
da8a1b6 Respect move and drop column support
jakubvrana authored
262 : "");
dafd2de @vrana Avoid flicker before the image is loaded
authored
263 echo ($orig == "" || support("drop_col") ? "<input type='image' class='icon' name='drop_col[$i]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick='return !editingRemoveRow(this);'>" : "");
50881f8 Move whitespace to CSS
jakubvrana authored
264 echo "\n";
a7096dd Separate editing functions
jakubvrana authored
265 }
266 }
93c27c9 Separate type_change()
jakubvrana authored
267
1118566 Documentation
jakubvrana authored
268 /** Move fields up and down or add field
269 * @param array
270 * @return null
271 */
fd8948f Order of columns in table
jakubvrana authored
272 function process_fields(&$fields) {
273 ksort($fields);
274 $offset = 0;
275 if ($_POST["up"]) {
276 $last = 0;
277 foreach ($fields as $key => $field) {
278 if (key($_POST["up"]) == $key) {
279 unset($fields[$key]);
280 array_splice($fields, $last, 0, array($field));
281 break;
282 }
283 if (isset($field["field"])) {
284 $last = $offset;
285 }
286 $offset++;
287 }
288 }
289 if ($_POST["down"]) {
290 $found = false;
291 foreach ($fields as $key => $field) {
292 if (isset($field["field"]) && $found) {
293 unset($fields[key($_POST["down"])]);
294 array_splice($fields, $offset, 0, array($found));
295 break;
296 }
297 if (key($_POST["down"]) == $key) {
298 $found = $field;
299 }
300 $offset++;
301 }
302 }
303 $fields = array_values($fields);
304 if ($_POST["add"]) {
305 array_splice($fields, key($_POST["add"]), 0, array(array()));
306 }
307 }
308
1118566 Documentation
jakubvrana authored
309 /** Callback used in routine()
310 * @param array
311 * @return string
312 */
8060c5b Routines
jakubvrana authored
313 function normalize_enum($match) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
314 return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0][0] . $match[0][0], $match[0][0], substr($match[0], 1, -1))), '\\')) . "'";
8060c5b Routines
jakubvrana authored
315 }
316
1118566 Documentation
jakubvrana authored
317 /** Issue grant or revoke commands
318 * @param string GRANT or REVOKE
319 * @param array
320 * @param string
321 * @param string
83d659c @vrana Comments
authored
322 * @return bool
1118566 Documentation
jakubvrana authored
323 */
464d84a Define functions unconditionally
jakubvrana authored
324 function grant($grant, $privileges, $columns, $on) {
325 if (!$privileges) {
326 return true;
327 }
328 if ($privileges == array("ALL PRIVILEGES", "GRANT OPTION")) {
329 // can't be granted or revoked together
330 return ($grant == "GRANT"
331 ? queries("$grant ALL PRIVILEGES$on WITH GRANT OPTION")
332 : queries("$grant ALL PRIVILEGES$on") && queries("$grant GRANT OPTION$on")
333 );
334 }
335 return queries("$grant " . preg_replace('~(GRANT OPTION)\\([^)]*\\)~', '\\1', implode("$columns, ", $privileges) . $columns) . $on);
336 }
32d5b9c Inform about dropped routine, trigger and view
jakubvrana authored
337
1118566 Documentation
jakubvrana authored
338 /** Drop old object and create a new one
339 * @param string drop query
340 * @param string create query
341 * @param string
342 * @param string
343 * @param string
344 * @param string
345 * @param string
346 * @return bool dropped
347 */
32d5b9c Inform about dropped routine, trigger and view
jakubvrana authored
348 function drop_create($drop, $create, $location, $message_drop, $message_alter, $message_create, $name) {
349 if ($_POST["drop"]) {
350 return query_redirect($drop, $location, $message_drop, true, !$_POST["dropped"]);
351 }
7352c28 Replace strlen() by != ""
jakubvrana authored
352 $dropped = $name != "" && ($_POST["dropped"] || queries($drop));
32d5b9c Inform about dropped routine, trigger and view
jakubvrana authored
353 $created = queries($create);
7352c28 Replace strlen() by != ""
jakubvrana authored
354 if (!queries_redirect($location, ($name != "" ? $message_alter : $message_create), $created) && $dropped) {
a379bde @vrana Save bytes
authored
355 redirect(null, $message_drop);
32d5b9c Inform about dropped routine, trigger and view
jakubvrana authored
356 }
357 return $dropped;
358 }
095d472 @vrana Customizable export
authored
359
360 /** Get string to add a file in TAR
361 * @param string
362 * @param string
363 * @return string
364 */
365 function tar_file($filename, $contents) {
366 $return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
367 $checksum = 8*32; // space for checksum itself
368 for ($i=0; $i < strlen($return); $i++) {
b0666e5 @vrana Remove unnecessary { } in compile
authored
369 $checksum += ord($return[$i]);
095d472 @vrana Customizable export
authored
370 }
371 $return .= sprintf("%06o", $checksum) . "\0 ";
372 return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
373 }
9d944c8 @vrana Respect original memory_limit
authored
374
375 /** Get INI bytes value
376 * @param string
377 * @return int
378 */
379 function ini_bytes($ini) {
380 $val = ini_get($ini);
381 switch (strtolower(substr($val, -1))) {
382 case 'g': $val *= 1024; // no break
383 case 'm': $val *= 1024; // no break
384 case 'k': $val *= 1024;
385 }
386 return $val;
387 }
Something went wrong with that request. Please try again.