3 // vim: expandtab sw=4 ts=4 sts=4:
7 * This file checks and builds the sql-string for
8 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name
10 * [TERMINATED BY '\t']
11 * [OPTIONALLY] ENCLOSED BY "]
13 * [LINES TERMINATED BY '\n']
19 * Gets some core scripts
21 require('./libraries/grab_globals.lib.php3');
22 require('./libraries/common.lib.php3');
26 * The form used to define the query has been submitted -> do the work
28 if (isset($btnLDI) && ($textfile != 'none')) {
29 if (!isset($replace)) {
33 error_reporting(E_ALL
);
34 chmod($textfile, 0644);
36 // Kanji encoding convert appended by Y.Kawada
37 if (function_exists('PMA_kanji_file_conv')) {
38 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ?
$xkana : '');
41 // Convert the file's charset if necessary
42 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
43 && isset($charset_of_file) && $charset_of_file != $charset) {
44 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile);
47 // Formats the data posted to this script
48 $textfile = PMA_sqlAddslashes($textfile);
49 if (get_magic_quotes_gpc()) {
50 $field_terminater = stripslashes($field_terminater);
51 $enclosed = PMA_sqlAddslashes(stripslashes($enclosed));
52 $escaped = PMA_sqlAddslashes(stripslashes($escaped));
53 $line_terminator = stripslashes($line_terminator);
54 $column_name = PMA_sqlAddslashes(stripslashes($column_name));
56 $enclosed = PMA_sqlAddslashes($enclosed);
57 $escaped = PMA_sqlAddslashes($escaped);
58 $column_name = PMA_sqlAddslashes($column_name);
61 // (try to) make sure the file is readable:
62 chmod($textfile, 0777);
67 // for versions before 3.23.49, we use the LOCAL keyword, because
68 // there was a version (cannot find which one, and it does not work
69 // with 3.23.38) where the user can LOAD, even if the user does not
70 // have FILE priv, and even if the file is on the server
71 // (which is the present case)
73 // we could also code our own loader, but LOAD DATA INFILE is optimized
76 if (PMA_MYSQL_INT_VERSION
< 32349) {
80 if (PMA_MYSQL_INT_VERSION
> 40003) {
81 $tmp_query = "SHOW VARIABLES LIKE 'local\\_infile'";
82 $result = PMA_mysql_query($tmp_query);
83 if ($result != FALSE && mysql_num_rows($result) > 0) {
84 $tmp = PMA_mysql_fetch_row($result);
85 if ($tmp[1] == 'ON') {
89 mysql_free_result($result);
92 $query .= ' INFILE \'' . $textfile . '\'';
93 if (!empty($replace)) {
94 $query .= ' ' . $replace;
96 $query .= ' INTO TABLE ' . PMA_backquote($into_table);
97 if (isset($field_terminater)) {
98 $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
100 if (isset($enclose_option) && strlen($enclose_option) > 0) {
101 $query .= ' OPTIONALLY';
103 if (strlen($enclosed) > 0) {
104 $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
106 if (strlen($escaped) > 0) {
107 $query .= ' ESCAPED BY \'' . $escaped . '\'';
109 if (strlen($line_terminator) > 0){
110 $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
112 if (strlen($column_name) > 0) {
113 if (PMA_MYSQL_INT_VERSION
>= 32306) {
115 $tmp = split(',( ?)', $column_name);
116 for ($i = 0; $i < count($tmp); $i++
) {
120 $query .= PMA_backquote(trim($tmp[$i]));
124 $query .= ' (' . $column_name . ')';
128 // Executes the query
129 // sql.php3 will stripslash the query if 'magic_quotes_gpc' is set to on
130 if (get_magic_quotes_gpc()) {
131 $sql_query = addslashes($query);
136 // We could rename the ldi* scripts to tbl_properties_ldi* to improve
137 // consistency with the other sub-pages.
139 // The $goto in ldi_table.php3 is set to tbl_properties.php3 but maybe
140 // if would be better to Browse the latest inserted data.
141 include('./sql.php3');
146 * The form used to define the query hasn't been yet submitted -> loads it
149 include('./ldi_table.php3');