Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Customizable export

  • Loading branch information...
commit 095d472366593c5133b844b7796e464fe934826a 1 parent a244367
Jakub Vrána authored October 29, 2010
8  adminer/dump.inc.php
@@ -7,7 +7,7 @@
7 7
 		$cookie .= "&$key=" . urlencode($_POST[$key]);
8 8
 	}
9 9
 	cookie("adminer_export", substr($cookie, 1));
10  
-	$ext = dump_headers(($TABLE != "" ? $TABLE : DB), (DB == "" || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
  10
+	$ext = $adminer->dumpHeaders(($TABLE != "" ? $TABLE : DB), (DB == "" || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
11 11
 	$is_sql = ($_POST["format"] == "sql");
12 12
 	if ($is_sql) {
13 13
 		echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump
@@ -73,9 +73,9 @@
73 73
 							if ($ext == "tar") {
74 74
 								ob_start();
75 75
 							}
76  
-							dump_table($row["Name"], ($table ? $_POST["table_style"] : ""));
  76
+							$adminer->dumpTable($row["Name"], ($table ? $_POST["table_style"] : ""));
77 77
 							if ($data) {
78  
-								dump_data($row["Name"], $_POST["data_style"]);
  78
+								$adminer->dumpData($row["Name"], $_POST["data_style"]);
79 79
 							}
80 80
 							if ($is_sql && $_POST["triggers"]) {
81 81
 								$triggers = trigger_sql($row["Name"], $_POST["table_style"]);
@@ -94,7 +94,7 @@
94 94
 					}
95 95
 				}
96 96
 				foreach ($views as $view) {
97  
-					dump_table($view, $_POST["table_style"], true);
  97
+					$adminer->dumpTable($view, $_POST["table_style"], true);
98 98
 				}
99 99
 				if ($ext == "tar") {
100 100
 					echo pack("x512");
183  adminer/include/adminer.inc.php
@@ -501,6 +501,189 @@ function dumpFormat($select, $value = "") {
501 501
 		return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
502 502
 	}
503 503
 	
  504
+	/** Export table structure
  505
+	* @param string
  506
+	* @param string
  507
+	* @param bool
  508
+	* @return null prints data
  509
+	*/
  510
+	function dumpTable($table, $style, $is_view = false) {
  511
+		if ($_POST["format"] != "sql") {
  512
+			echo "\xef\xbb\xbf"; // UTF-8 byte order mark
  513
+			if ($style) {
  514
+				dump_csv(array_keys(fields($table)));
  515
+			}
  516
+		} elseif ($style) {
  517
+			$create = create_sql($table, $_POST["auto_increment"]);
  518
+			if ($create) {
  519
+				if ($style == "DROP+CREATE") {
  520
+					echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
  521
+				}
  522
+				if ($is_view) {
  523
+					// remove DEFINER with current user
  524
+					$create = preg_replace('~^([A-Z =]+) DEFINER=`' . str_replace("@", "`@`", logged_user()) . '`~', '\\1', $create); //! proper escaping of user
  525
+				}
  526
+				echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
  527
+			}
  528
+			if ($style == "CREATE+ALTER" && !$is_view) {
  529
+				// create procedure which iterates over original columns and adds new and removes old
  530
+				$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION";
  531
+				echo "DELIMITER ;;
  532
+CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
  533
+	DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
  534
+	DECLARE _column_type, _column_default text;
  535
+	DECLARE _is_nullable char(3);
  536
+	DECLARE _extra varchar(30);
  537
+	DECLARE _column_comment varchar(255);
  538
+	DECLARE done, set_after bool DEFAULT 0;
  539
+	DECLARE add_columns text DEFAULT '";
  540
+				$fields = array();
  541
+				$after = "";
  542
+				foreach (get_rows($query) as $row) {
  543
+					$default = $row["COLUMN_DEFAULT"];
  544
+					$row["default"] = (isset($default) ? q($default) : "NULL");
  545
+					$row["after"] = q($after); //! rgt AFTER lft, lft AFTER id doesn't work
  546
+					$row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
  547
+						. " $row[COLUMN_TYPE]"
  548
+						. ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
  549
+						. (isset($default) ? " DEFAULT " . ($default == "CURRENT_TIMESTAMP" ? $default : $row["default"]) : "")
  550
+						. ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
  551
+						. ($row["EXTRA"] ? " $row[EXTRA]" : "")
  552
+						. ($row["COLUMN_COMMENT"] ? " COMMENT " . q($row["COLUMN_COMMENT"]) : "")
  553
+						. ($after ? " AFTER " . idf_escape($after) : " FIRST")
  554
+					);
  555
+					echo ", ADD $row[alter]";
  556
+					$fields[] = $row;
  557
+					$after = $row["COLUMN_NAME"];
  558
+				}
  559
+				echo "';
  560
+	DECLARE columns CURSOR FOR $query;
  561
+	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  562
+	SET @alter_table = '';
  563
+	OPEN columns;
  564
+	REPEAT
  565
+		FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
  566
+		IF NOT done THEN
  567
+			SET set_after = 1;
  568
+			CASE _column_name";
  569
+			foreach ($fields as $row) {
  570
+				echo "
  571
+				WHEN " . q($row["COLUMN_NAME"]) . " THEN
  572
+					SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', '');
  573
+					IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != " . q($row["COLUMN_TYPE"]) . " OR _extra != '$row[EXTRA]' OR _column_comment != " . q($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN
  574
+						SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]');
  575
+					END IF;"; //! don't replace in comment
  576
+			}
  577
+			echo "
  578
+				ELSE
  579
+					SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
  580
+					SET set_after = 0;
  581
+			END CASE;
  582
+			IF set_after THEN
  583
+				SET after = _column_name;
  584
+			END IF;
  585
+		END IF;
  586
+	UNTIL done END REPEAT;
  587
+	CLOSE columns;
  588
+	IF @alter_table != '' OR add_columns != '' THEN
  589
+		SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . table($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n');
  590
+	END IF;
  591
+END;;
  592
+DELIMITER ;
  593
+CALL adminer_alter(@adminer_alter);
  594
+DROP PROCEDURE adminer_alter;
  595
+
  596
+";
  597
+				//! indexes
  598
+			}
  599
+		}
  600
+	}
  601
+	
  602
+	/** Export table data
  603
+	* @param string
  604
+	* @param string
  605
+	* @param string query to execute, defaults to SELECT * FROM $table
  606
+	* @return null prints data
  607
+	*/
  608
+	function dumpData($table, $style, $select = "") {
  609
+		global $connection, $jush;
  610
+		$max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
  611
+		if ($style) {
  612
+			if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
  613
+				echo truncate_sql($table) . ";\n";
  614
+			}
  615
+			$fields = fields($table);
  616
+			$result = $connection->query(($select ? $select : "SELECT * FROM " . table($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
  617
+			if ($result) {
  618
+				$insert = "";
  619
+				$buffer = "";
  620
+				while ($row = $result->fetch_assoc()) {
  621
+					if ($_POST["format"] != "sql") {
  622
+						dump_csv($row);
  623
+					} else {
  624
+						if (!$insert) {
  625
+							$insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
  626
+						}
  627
+						foreach ($row as $key => $val) {
  628
+							$row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
  629
+						}
  630
+						$s = implode(",\t", $row);
  631
+						if ($style == "INSERT+UPDATE") {
  632
+							$set = array();
  633
+							foreach ($row as $key => $val) {
  634
+								$set[] = idf_escape($key) . " = $val";
  635
+							}
  636
+							echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
  637
+						} else {
  638
+							$s = ($max_packet ? "\n" : " ") . "($s)";
  639
+							if (!$buffer) {
  640
+								$buffer = $insert . $s;
  641
+							} elseif (strlen($buffer) + 2 + strlen($s) < $max_packet) { // 2 - separator and terminator length
  642
+								$buffer .= ",$s";
  643
+							} else {
  644
+								$buffer .= ";\n";
  645
+								echo $buffer;
  646
+								$buffer = $insert . $s;
  647
+							}
  648
+						}
  649
+					}
  650
+				}
  651
+				if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) {
  652
+					$buffer .= ";\n";
  653
+					echo $buffer;
  654
+				}
  655
+			}
  656
+		}
  657
+	}
  658
+	
  659
+	/** Send headers for export
  660
+	* @param string
  661
+	* @param bool
  662
+	* @return string extension
  663
+	*/
  664
+	function dumpHeaders($identifier, $multi_table = false) {
  665
+		$filename = ($identifier != "" ? friendly_url($identifier) : "adminer");
  666
+		$output = $_POST["output"];
  667
+		$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
  668
+		header("Content-Type: " .
  669
+			($output == "bz2" ? "application/x-bzip" :
  670
+			($output == "gz" ? "application/x-gzip" :
  671
+			($ext == "tar" ? "application/x-tar" :
  672
+			($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
  673
+		))));
  674
+		if ($output != "text") {
  675
+			header("Content-Disposition: attachment; filename=$filename.$ext" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
  676
+		}
  677
+		session_write_close();
  678
+		if ($_POST["output"] == "bz2") {
  679
+			ob_start('bzcompress', 1e6);
  680
+		}
  681
+		if ($_POST["output"] == "gz") {
  682
+			ob_start('gzencode', 1e6);
  683
+		}
  684
+		return $ext;
  685
+	}
  686
+	
504 687
 	/** Prints navigation after Adminer title
505 688
 	* @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
506 689
 	* @return null
1  adminer/include/bootstrap.inc.php
@@ -71,7 +71,6 @@
71 71
 include "../adminer/include/auth.inc.php";
72 72
 include "./include/connect.inc.php";
73 73
 include "./include/editing.inc.php";
74  
-include "./include/export.inc.php";
75 74
 
76 75
 session_cache_limiter(""); // to allow restarting session
77 76
 if (!ini_bool("session.use_cookies") || @ini_set("session.use_cookies", false) !== false) { // @ - may be disabled
15  adminer/include/editing.inc.php
@@ -333,3 +333,18 @@ function drop_create($drop, $create, $location, $message_drop, $message_alter, $
333 333
 	}
334 334
 	return $dropped;
335 335
 }
  336
+
  337
+/** Get string to add a file in TAR
  338
+* @param string
  339
+* @param string
  340
+* @return string
  341
+*/
  342
+function tar_file($filename, $contents) {
  343
+	$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
  344
+	$checksum = 8*32; // space for checksum itself
  345
+	for ($i=0; $i < strlen($return); $i++) {
  346
+		$checksum += ord($return{$i});
  347
+	}
  348
+	$return .= sprintf("%06o", $checksum) . "\0 ";
  349
+	return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
  350
+}
176  adminer/include/export.inc.php
... ...
@@ -1,176 +0,0 @@
1  
-<?php
2  
-function tar_file($filename, $contents) {
3  
-	$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
4  
-	$checksum = 8*32; // space for checksum itself
5  
-	for ($i=0; $i < strlen($return); $i++) {
6  
-		$checksum += ord($return{$i});
7  
-	}
8  
-	$return .= sprintf("%06o", $checksum) . "\0 ";
9  
-	return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
10  
-}
11  
-
12  
-function dump_table($table, $style, $is_view = false) {
13  
-	if ($_POST["format"] != "sql") {
14  
-		echo "\xef\xbb\xbf"; // UTF-8 byte order mark
15  
-		if ($style) {
16  
-			dump_csv(array_keys(fields($table)));
17  
-		}
18  
-	} elseif ($style) {
19  
-		$create = create_sql($table, $_POST["auto_increment"]);
20  
-		if ($create) {
21  
-			if ($style == "DROP+CREATE") {
22  
-				echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
23  
-			}
24  
-			if ($is_view) {
25  
-				// remove DEFINER with current user
26  
-				$create = preg_replace('~^([A-Z =]+) DEFINER=`' . str_replace("@", "`@`", logged_user()) . '`~', '\\1', $create); //! proper escaping of user
27  
-			}
28  
-			echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
29  
-		}
30  
-		if ($style == "CREATE+ALTER" && !$is_view) {
31  
-			// create procedure which iterates over original columns and adds new and removes old
32  
-			$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION";
33  
-			echo "DELIMITER ;;
34  
-CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
35  
-	DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
36  
-	DECLARE _column_type, _column_default text;
37  
-	DECLARE _is_nullable char(3);
38  
-	DECLARE _extra varchar(30);
39  
-	DECLARE _column_comment varchar(255);
40  
-	DECLARE done, set_after bool DEFAULT 0;
41  
-	DECLARE add_columns text DEFAULT '";
42  
-			$fields = array();
43  
-			$after = "";
44  
-			foreach (get_rows($query) as $row) {
45  
-				$default = $row["COLUMN_DEFAULT"];
46  
-				$row["default"] = (isset($default) ? q($default) : "NULL");
47  
-				$row["after"] = q($after); //! rgt AFTER lft, lft AFTER id doesn't work
48  
-				$row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
49  
-					. " $row[COLUMN_TYPE]"
50  
-					. ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
51  
-					. (isset($default) ? " DEFAULT " . ($default == "CURRENT_TIMESTAMP" ? $default : $row["default"]) : "")
52  
-					. ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
53  
-					. ($row["EXTRA"] ? " $row[EXTRA]" : "")
54  
-					. ($row["COLUMN_COMMENT"] ? " COMMENT " . q($row["COLUMN_COMMENT"]) : "")
55  
-					. ($after ? " AFTER " . idf_escape($after) : " FIRST")
56  
-				);
57  
-				echo ", ADD $row[alter]";
58  
-				$fields[] = $row;
59  
-				$after = $row["COLUMN_NAME"];
60  
-			}
61  
-			echo "';
62  
-	DECLARE columns CURSOR FOR $query;
63  
-	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
64  
-	SET @alter_table = '';
65  
-	OPEN columns;
66  
-	REPEAT
67  
-		FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
68  
-		IF NOT done THEN
69  
-			SET set_after = 1;
70  
-			CASE _column_name";
71  
-			foreach ($fields as $row) {
72  
-				echo "
73  
-				WHEN " . q($row["COLUMN_NAME"]) . " THEN
74  
-					SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', '');
75  
-					IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != " . q($row["COLUMN_TYPE"]) . " OR _extra != '$row[EXTRA]' OR _column_comment != " . q($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN
76  
-						SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]');
77  
-					END IF;"; //! don't replace in comment
78  
-			}
79  
-			echo "
80  
-				ELSE
81  
-					SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
82  
-					SET set_after = 0;
83  
-			END CASE;
84  
-			IF set_after THEN
85  
-				SET after = _column_name;
86  
-			END IF;
87  
-		END IF;
88  
-	UNTIL done END REPEAT;
89  
-	CLOSE columns;
90  
-	IF @alter_table != '' OR add_columns != '' THEN
91  
-		SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . table($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n');
92  
-	END IF;
93  
-END;;
94  
-DELIMITER ;
95  
-CALL adminer_alter(@adminer_alter);
96  
-DROP PROCEDURE adminer_alter;
97  
-
98  
-";
99  
-			//! indexes
100  
-		}
101  
-	}
102  
-}
103  
-
104  
-function dump_data($table, $style, $select = "") {
105  
-	global $connection, $jush;
106  
-	$max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
107  
-	if ($style) {
108  
-		if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
109  
-			echo truncate_sql($table) . ";\n";
110  
-		}
111  
-		$fields = fields($table);
112  
-		$result = $connection->query(($select ? $select : "SELECT * FROM " . table($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
113  
-		if ($result) {
114  
-			$insert = "";
115  
-			$buffer = "";
116  
-			while ($row = $result->fetch_assoc()) {
117  
-				if ($_POST["format"] != "sql") {
118  
-					dump_csv($row);
119  
-				} else {
120  
-					if (!$insert) {
121  
-						$insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
122  
-					}
123  
-					foreach ($row as $key => $val) {
124  
-						$row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
125  
-					}
126  
-					$s = implode(",\t", $row);
127  
-					if ($style == "INSERT+UPDATE") {
128  
-						$set = array();
129  
-						foreach ($row as $key => $val) {
130  
-							$set[] = idf_escape($key) . " = $val";
131  
-						}
132  
-						echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
133  
-					} else {
134  
-						$s = ($max_packet ? "\n" : " ") . "($s)";
135  
-						if (!$buffer) {
136  
-							$buffer = $insert . $s;
137  
-						} elseif (strlen($buffer) + 2 + strlen($s) < $max_packet) { // 2 - separator and terminator length
138  
-							$buffer .= ",$s";
139  
-						} else {
140  
-							$buffer .= ";\n";
141  
-							echo $buffer;
142  
-							$buffer = $insert . $s;
143  
-						}
144  
-					}
145  
-				}
146  
-			}
147  
-			if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) {
148  
-				$buffer .= ";\n";
149  
-				echo $buffer;
150  
-			}
151  
-		}
152  
-	}
153  
-}
154  
-
155  
-function dump_headers($identifier, $multi_table = false) {
156  
-	$filename = ($identifier != "" ? friendly_url($identifier) : "adminer");
157  
-	$output = $_POST["output"];
158  
-	$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
159  
-	header("Content-Type: " .
160  
-		($output == "bz2" ? "application/x-bzip" :
161  
-		($output == "gz" ? "application/x-gzip" :
162  
-		($ext == "tar" ? "application/x-tar" :
163  
-		($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
164  
-	))));
165  
-	if ($output != "text") {
166  
-		header("Content-Disposition: attachment; filename=$filename.$ext" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
167  
-	}
168  
-	session_write_close();
169  
-	if ($_POST["output"] == "bz2") {
170  
-		ob_start('bzcompress', 1e6);
171  
-	}
172  
-	if ($_POST["output"] == "gz") {
173  
-		ob_start('gzencode', 1e6);
174  
-	}
175  
-	return $ext;
176  
-}
8  adminer/select.inc.php
@@ -43,8 +43,8 @@
43 43
 		}
44 44
 	}
45 45
 	if ($_POST["export"]) {
46  
-		dump_headers($TABLE);
47  
-		dump_table($TABLE, "");
  46
+		$adminer->dumpHeaders($TABLE);
  47
+		$adminer->dumpTable($TABLE, "");
48 48
 		if ($_POST["format"] != "sql") { // Editor doesn't send format
49 49
 			$row = array_keys($fields);
50 50
 			if ($select) {
@@ -60,14 +60,14 @@
60 60
 			if (is_array($_POST["check"])) {
61 61
 				$where2[] = "($where_check)";
62 62
 			}
63  
-			dump_data($TABLE, "INSERT", "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by);
  63
+			$adminer->dumpData($TABLE, "INSERT", "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by);
64 64
 		} else {
65 65
 			$union = array();
66 66
 			foreach ($_POST["check"] as $val) {
67 67
 				// where is not unique so OR can't be used
68 68
 				$union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
69 69
 			}
70  
-			dump_data($TABLE, "INSERT", implode(" UNION ALL ", $union));
  70
+			$adminer->dumpData($TABLE, "INSERT", implode(" UNION ALL ", $union));
71 71
 		}
72 72
 		exit;
73 73
 	}
23  editor/include/adminer.inc.php
@@ -442,6 +442,29 @@ function dumpFormat($select, $value = "") {
442 442
 		return html_select("format", array('csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
443 443
 	}
444 444
 	
  445
+	function dumpTable() {
  446
+		echo "\xef\xbb\xbf"; // UTF-8 byte order mark
  447
+	}
  448
+	
  449
+	function dumpData($table, $style, $select = "") {
  450
+		global $connection;
  451
+		$result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT
  452
+		if ($result) {
  453
+			while ($row = $result->fetch_assoc()) {
  454
+				dump_csv($row);
  455
+			}
  456
+		}
  457
+	}
  458
+	
  459
+	function dumpHeaders($identifier) {
  460
+		$filename = ($identifier != "" ? friendly_url($identifier) : "dump");
  461
+		$ext = "csv";
  462
+		header("Content-Type: text/csv; charset=utf-8");
  463
+		header("Content-Disposition: attachment; filename=$filename.$ext");
  464
+		session_write_close();
  465
+		return $ext;
  466
+	}
  467
+	
445 468
 	function navigation($missing) {
446 469
 		global $VERSION, $token;
447 470
 		?>
23  editor/include/export.inc.php
... ...
@@ -1,23 +0,0 @@
1  
-<?php
2  
-function dump_table($table) {
3  
-	echo "\xef\xbb\xbf"; // UTF-8 byte order mark
4  
-}
5  
-
6  
-function dump_data($table, $style, $select = "") {
7  
-	global $connection;
8  
-	$result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT
9  
-	if ($result) {
10  
-		while ($row = $result->fetch_assoc()) {
11  
-			dump_csv($row);
12  
-		}
13  
-	}
14  
-}
15  
-
16  
-function dump_headers($identifier) {
17  
-	$filename = ($identifier != "" ? friendly_url($identifier) : "dump");
18  
-	$ext = "csv";
19  
-	header("Content-Type: text/csv; charset=utf-8");
20  
-	header("Content-Disposition: attachment; filename=$filename.$ext");
21  
-	session_write_close();
22  
-	return $ext;
23  
-}

0 notes on commit 095d472

Please sign in to comment.
Something went wrong with that request. Please try again.