~automne-team/automne/trunk

« back to all changes in this revision

Viewing changes to automne/phpMyAdmin/libraries/export/sql.php

  • Committer: sebastien-pauchet
  • Date: 2012-02-15 16:47:40 UTC
  • mfrom: (363.2.105 4.2)
  • Revision ID: seb@automne-cms.org-20120215164740-xrk26iafkvztwv6s
Merge stable branch 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Set of functions used to build SQL dumps of tables
5
5
 *
6
6
 * @package phpMyAdmin-Export-SQL
7
 
 * @version $Id$
8
7
 */
9
8
if (! defined('PHPMYADMIN')) {
10
9
    exit;
22
21
    }
23
22
    if (!$hide_sql) {
24
23
        $plugin_list['sql'] = array(
25
 
            'text' => 'strSQL',
 
24
            'text' => __('SQL'),
26
25
            'extension' => 'sql',
27
26
            'mime_type' => 'text/x-sql',
28
 
            'options' => array(
29
 
                array('type' => 'text', 'name' => 'header_comment', 'text' => 'strAddHeaderComment'),
30
 
                array('type' => 'bool', 'name' => 'include_comments', 'text' => 'strComments'),
31
 
                array('type' => 'bool', 'name' => 'use_transaction', 'text' => 'strEncloseInTransaction'),
32
 
                array('type' => 'bool', 'name' => 'disable_fk', 'text' => 'strDisableForeignChecks'),
33
 
                ),
34
 
            'options_text' => 'strOptions',
35
 
            );
 
27
            'options' => array());
 
28
 
 
29
        $plugin_list['sql']['options'][] = array('type' => 'begin_group', 'name' => 'general_opts');
 
30
 
 
31
        /* comments */
 
32
        $plugin_list['sql']['options'][] =
 
33
            array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'bool', 'name' => 'include_comments', 'text' => __('Display comments <i>(includes info such as export timestamp, PHP version, and server version)</i>')));
 
34
        $plugin_list['sql']['options'][] =
 
35
            array('type' => 'text', 'name' => 'header_comment', 'text' => __('Additional custom header comment (\n splits lines):'));
 
36
        $plugin_list['sql']['options'][] =
 
37
            array('type' => 'bool', 'name' => 'dates', 'text' => __('Include a timestamp of when databases were created, last updated, and last checked'));
 
38
        if (!empty($GLOBALS['cfgRelation']['relation'])) {
 
39
            $plugin_list['sql']['options'][] =
 
40
                array('type' => 'bool', 'name' => 'relation', 'text' => __('Display foreign key relationships'));
 
41
        }
 
42
        if (!empty($GLOBALS['cfgRelation']['mimework'])) {
 
43
            $plugin_list['sql']['options'][] =
 
44
                array('type' => 'bool', 'name' => 'mime', 'text' => __('Display MIME types'));
 
45
        }
 
46
        $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
 
47
        /* end comments */
 
48
 
 
49
        /* enclose in a transaction */
 
50
        $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'use_transaction', 'text' => __('Enclose export in a transaction'), 'doc' => array('programs', 'mysqldump', 'option_mysqldump_single-transaction'));
 
51
 
 
52
        /* disable foreign key checks */
 
53
        $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'disable_fk', 'text' => __('Disable foreign key checks'), 'doc' => array('manual_MySQL_Database_Administration', 'server-system-variables', 'sysvar_foreign_key_checks'));
 
54
 
 
55
        $plugin_list['sql']['options_text'] = __('Options');
 
56
 
 
57
        /* compatibility maximization */
36
58
        $compats = PMA_DBI_getCompatibilities();
37
59
        if (count($compats) > 0) {
38
60
            $values = array();
40
62
                $values[$val] = $val;
41
63
            }
42
64
            $plugin_list['sql']['options'][] =
43
 
                array('type' => 'select', 'name' => 'compatibility', 'text' => 'strSQLCompatibility', 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode'));
 
65
                array('type' => 'select', 'name' => 'compatibility', 'text' => __('Database system or older MySQL server to maximize output compatibility with:'), 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode'));
44
66
            unset($values);
45
67
        }
46
68
 
47
 
        /* Server export options */
 
69
        /* server export options */
48
70
        if ($plugin_param['export_type'] == 'server') {
49
 
            $plugin_list['sql']['options'][] =
50
 
                array('type' => 'bgroup', 'text' => 'strDatabaseExportOptions');
51
 
            $plugin_list['sql']['options'][] =
52
 
                array('type' => 'bool', 'name' => 'drop_database', 'text' => sprintf($GLOBALS['strAddClause'], 'DROP DATABASE'));
53
 
            $plugin_list['sql']['options'][] =
54
 
                array('type' => 'egroup');
55
 
        }
56
 
 
57
 
        /* Structure options */
58
 
        if (!$hide_structure) {
59
 
            $plugin_list['sql']['options'][] =
60
 
                array('type' => 'bgroup', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data');
61
 
            if ($plugin_param['export_type'] == 'table') {
 
71
        $plugin_list['sql']['options'][] =
 
72
                array('type' => 'bool', 'name' => 'drop_database', 'text' => sprintf(__('Add %s statement'), '<code>DROP DATABASE</code>'));
 
73
         }
 
74
 
 
75
        /* what to dump (structure/data/both) */
 
76
        $plugin_list['sql']['options'][] =
 
77
            array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'message_only', 'text' => __('Dump table')));
 
78
        $plugin_list['sql']['options'][] =
 
79
            array('type' => 'radio', 'name' => 'structure_or_data', 'values' => array('structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data')));
 
80
        $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
 
81
 
 
82
        $plugin_list['sql']['options'][] = array('type' => 'end_group');
 
83
 
 
84
        /* begin Structure options */
 
85
         if (!$hide_structure) {
 
86
            $plugin_list['sql']['options'][] =
 
87
                array('type' => 'begin_group', 'name' => 'structure', 'text' => __('Object creation options'), 'force' => 'data');
 
88
 
 
89
            /* begin SQL Statements */
 
90
            $plugin_list['sql']['options'][] =
 
91
                array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'message_only', 'name' => 'add_statements', 'text' => __('Add statements:')));
 
92
             if ($plugin_param['export_type'] == 'table') {
62
93
                if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
63
 
                    $drop_clause = 'DROP VIEW';
 
94
                    $drop_clause = '<code>DROP VIEW</code>';
64
95
                } else {
65
 
                    $drop_clause = 'DROP TABLE';
 
96
                    $drop_clause = '<code>DROP TABLE</code>';
66
97
                }
67
98
            } else {
68
 
                $drop_clause = 'DROP TABLE / VIEW / PROCEDURE / FUNCTION';
69
 
                if (PMA_MYSQL_INT_VERSION > 50100) {
70
 
                    $drop_clause .= ' / EVENT';
 
99
                $drop_clause = '<code>DROP TABLE / VIEW / PROCEDURE / FUNCTION</code>';
 
100
                if (PMA_MYSQL_INT_VERSION > 50100) {
 
101
                    $drop_clause .= '<code> / EVENT</code>';
71
102
                }
72
103
            }
73
104
            $plugin_list['sql']['options'][] =
74
 
                array('type' => 'bool', 'name' => 'drop_table', 'text' => sprintf($GLOBALS['strAddClause'], $drop_clause));
75
 
            $plugin_list['sql']['options'][] =
76
 
                array('type' => 'bool', 'name' => 'if_not_exists', 'text' => sprintf($GLOBALS['strAddClause'], 'IF NOT EXISTS'));
77
 
            $plugin_list['sql']['options'][] =
78
 
                array('type' => 'bool', 'name' => 'auto_increment', 'text' => 'strAddAutoIncrement');
79
 
            $plugin_list['sql']['options'][] =
80
 
                array('type' => 'bool', 'name' => 'backquotes', 'text' => 'strUseBackquotes');
81
 
            $plugin_list['sql']['options'][] =
82
 
                array('type' => 'bool', 'name' => 'procedure_function', 'text' => sprintf($GLOBALS['strAddClause'], 'CREATE PROCEDURE / FUNCTION' . (PMA_MYSQL_INT_VERSION > 50100 ? ' / EVENT' : '')));
83
 
 
84
 
            /* MIME stuff etc. */
85
 
            $plugin_list['sql']['options'][] =
86
 
                array('type' => 'bgroup', 'text' => 'strAddIntoComments');
87
 
            $plugin_list['sql']['options'][] =
88
 
                array('type' => 'bool', 'name' => 'dates', 'text' => 'strCreationDates');
89
 
            if (!empty($GLOBALS['cfgRelation']['relation'])) {
90
 
                $plugin_list['sql']['options'][] =
91
 
                    array('type' => 'bool', 'name' => 'relation', 'text' => 'strRelations');
92
 
            }
93
 
            if (!empty($GLOBALS['cfgRelation']['mimework'])) {
94
 
                $plugin_list['sql']['options'][] =
95
 
                    array('type' => 'bool', 'name' => 'mime', 'text' => 'strMIME_MIMEtype');
96
 
            }
97
 
            $plugin_list['sql']['options'][] =
98
 
                array('type' => 'egroup');
99
 
 
100
 
            $plugin_list['sql']['options'][] =
101
 
                array('type' => 'egroup');
 
105
                array('type' => 'bool', 'name' => 'drop_table', 'text' => sprintf(__('Add %s statement'), $drop_clause));
 
106
            $plugin_list['sql']['options'][] =
 
107
                array('type' => 'bool', 'name' => 'procedure_function', 'text' => sprintf(__('Add %s statement'), '<code>CREATE PROCEDURE / FUNCTION' . (PMA_MYSQL_INT_VERSION > 50100 ? ' / EVENT</code>' : '</code>')));
 
108
 
 
109
            /* begin CREATE TABLE statements*/
 
110
            $plugin_list['sql']['options'][] =
 
111
                array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'bool', 'name' => 'create_table_statements', 'text' => __('<code>CREATE TABLE</code> options:')));
 
112
            $plugin_list['sql']['options'][] =
 
113
                array('type' => 'bool', 'name' => 'if_not_exists', 'text' => '<code>IF NOT EXISTS</code>');
 
114
            $plugin_list['sql']['options'][] =
 
115
                array('type' => 'bool', 'name' => 'auto_increment', 'text' => '<code>AUTO_INCREMENT</code>');
 
116
            $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
 
117
            /* end CREATE TABLE statements */
 
118
 
 
119
            $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
 
120
            /* end SQL statements */
 
121
 
 
122
            $plugin_list['sql']['options'][] =
 
123
                array('type' => 'bool', 'name' => 'backquotes', 'text' => __('Enclose table and field names with backquotes <i>(Protects field and table names formed with special characters or keywords)</i>'));
 
124
 
 
125
            $plugin_list['sql']['options'][] =
 
126
                array('type' => 'end_group');
102
127
        }
103
 
 
104
 
        /* Data */
105
 
        $plugin_list['sql']['options'][] =
106
 
            array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure');
107
 
        $plugin_list['sql']['options'][] =
108
 
            array('type' => 'bool', 'name' => 'columns', 'text' => 'strCompleteInserts', 'doc' => array('programs', 'mysqldump', 'option_mysqldump_complete-insert-option'));
109
 
        $plugin_list['sql']['options'][] =
110
 
            array('type' => 'bool', 'name' => 'extended', 'text' => 'strExtendedInserts', 'doc' => array('programs', 'mysqldump', 'option_mysqldump_extended-insert-option'));
111
 
        $plugin_list['sql']['options'][] =
112
 
            array('type' => 'text', 'name' => 'max_query_size', 'text' => 'strMaximalQueryLength');
113
 
        $plugin_list['sql']['options'][] =
114
 
            array('type' => 'bool', 'name' => 'delayed', 'text' => 'strDelayedInserts');
115
 
        $plugin_list['sql']['options'][] =
116
 
            array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreInserts');
117
 
        $plugin_list['sql']['options'][] =
118
 
            array('type' => 'bool', 'name' => 'hex_for_blob', 'text' => 'strHexForBLOB');
119
 
        $plugin_list['sql']['options'][] =
120
 
            array('type' => 'select', 'name' => 'type', 'text' => 'strSQLExportType', 'values' => array('INSERT' => 'INSERT', 'UPDATE' => 'UPDATE', 'REPLACE' => 'REPLACE'));
121
 
        $plugin_list['sql']['options'][] =
122
 
            array('type' => 'egroup');
 
128
        /* end Structure options */
 
129
 
 
130
        /* begin Data options */
 
131
         $plugin_list['sql']['options'][] =
 
132
            array('type' => 'begin_group', 'name' => 'data', 'text' => __('Data dump options'), 'force' => 'structure');
 
133
 
 
134
        /* begin SQL statements */
 
135
        $plugin_list['sql']['options'][] =
 
136
            array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'message_only', 'text' => __('Instead of <code>INSERT</code> statements, use:')));
 
137
        $plugin_list['sql']['options'][] =
 
138
            array('type' => 'bool', 'name' => 'delayed', 'text' => __('<code>INSERT DELAYED</code> statements'), 'doc' => array('manual_MySQL_Database_Administration', 'insert_delayed'));
 
139
        $plugin_list['sql']['options'][] =
 
140
            array('type' => 'bool', 'name' => 'ignore', 'text' => __('<code>INSERT IGNORE</code> statements'), 'doc' => array('manual_MySQL_Database_Administration', 'insert'));
 
141
        $plugin_list['sql']['options'][] =
 
142
            array('type' => 'end_subgroup');
 
143
        /* end SQL statements */
 
144
 
 
145
        /* Function to use when dumping data */
 
146
        $plugin_list['sql']['options'][] =
 
147
            array('type' => 'select', 'name' => 'type', 'text' => __('Function to use when dumping data:'), 'values' => array('INSERT' => 'INSERT', 'UPDATE' => 'UPDATE', 'REPLACE' => 'REPLACE'));
 
148
 
 
149
        /* Syntax to use when inserting data */
 
150
        $plugin_list['sql']['options'][] =
 
151
            array('type' => 'begin_subgroup', 'subgroup_header' => array('type' => 'message_only', 'text' => __('Syntax to use when inserting data:')));
 
152
        $plugin_list['sql']['options'][] =
 
153
            array('type' => 'radio', 'name' => 'insert_syntax', 'values' => array(
 
154
                'complete' => __('include column names in every <code>INSERT</code> statement <br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name (col_A,col_B,col_C) VALUES (1,2,3)</code>'),
 
155
                'extended' => __('insert multiple rows in every <code>INSERT</code> statement<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name VALUES (1,2,3), (4,5,6), (7,8,9)</code>'),
 
156
                'both' => __('both of the above<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name (col_A,col_B) VALUES (1,2,3), (4,5,6), (7,8,9)</code>'),
 
157
                'none' => __('neither of the above<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name VALUES (1,2,3)</code>')));
 
158
          $plugin_list['sql']['options'][] =
 
159
            array('type' => 'end_subgroup');
 
160
 
 
161
        /* Max length of query */
 
162
        $plugin_list['sql']['options'][] =
 
163
            array('type' => 'text', 'name' => 'max_query_size', 'text' => __('Maximal length of created query'));
 
164
 
 
165
        /* Dump binary columns in hexadecimal */
 
166
        $plugin_list['sql']['options'][] =
 
167
            array('type' => 'bool', 'name' => 'hex_for_blob', 'text' => __('Dump binary columns in hexadecimal notation <i>(for example, "abc" becomes 0x616263)</i>'));
 
168
 
 
169
        /* Dump time in UTC */
 
170
        $plugin_list['sql']['options'][] =
 
171
            array('type' => 'bool', 'name' => 'utc_time', 'text' => __('Dump TIMESTAMP columns in UTC <i>(enables TIMESTAMP columns to be dumped and reloaded between servers in different time zones)</i>'));
 
172
 
 
173
        $plugin_list['sql']['options'][] = array('type' => 'end_group');
 
174
         /* end Data options */
123
175
    }
124
176
} else {
125
177
 
131
183
}
132
184
 
133
185
/**
 
186
 * Exports routines (procedures and functions) 
 
187
 *
 
188
 * @param   string      $db 
 
189
 *
 
190
 * @return  bool        Whether it suceeded
 
191
 */
 
192
function PMA_exportRoutines($db) {
 
193
    global $crlf;
 
194
 
 
195
    $text = '';
 
196
    $delimiter = '$$';
 
197
 
 
198
    $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
 
199
    $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
 
200
 
 
201
    if ($procedure_names || $function_names) {
 
202
        $text .= $crlf
 
203
          . 'DELIMITER ' . $delimiter . $crlf;
 
204
    }
 
205
 
 
206
    if ($procedure_names) {
 
207
        $text .=
 
208
            PMA_exportComment()
 
209
          . PMA_exportComment(__('Procedures'))
 
210
          . PMA_exportComment();
 
211
 
 
212
        foreach($procedure_names as $procedure_name) {
 
213
            if (! empty($GLOBALS['sql_drop_table'])) {
 
214
                $text .= 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($procedure_name) . $delimiter . $crlf;
 
215
            }
 
216
            $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf;
 
217
        }
 
218
    }
 
219
 
 
220
    if ($function_names) {
 
221
        $text .=
 
222
            PMA_exportComment()
 
223
          . PMA_exportComment(__('Functions'))
 
224
          . PMA_exportComment();
 
225
 
 
226
        foreach($function_names as $function_name) {
 
227
            if (! empty($GLOBALS['sql_drop_table'])) {
 
228
                $text .= 'DROP FUNCTION IF EXISTS ' . PMA_backquote($function_name) . $delimiter . $crlf;
 
229
            }
 
230
            $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf;
 
231
        }
 
232
    }
 
233
 
 
234
    if ($procedure_names || $function_names) {
 
235
        $text .= 'DELIMITER ;' . $crlf;
 
236
    }
 
237
 
 
238
    if (! empty($text)) {
 
239
        return PMA_exportOutputHandler($text);
 
240
    } else {
 
241
        return false;
 
242
    }
 
243
}
 
244
 
 
245
/**
134
246
 * Possibly outputs comment
135
247
 *
136
248
 * @param   string      Text of comment
150
262
/**
151
263
 * Possibly outputs CRLF
152
264
 *
153
 
 * @return  string  $crlf or nothing 
 
265
 * @return  string  $crlf or nothing
154
266
 */
155
267
function PMA_possibleCRLF()
156
268
{
185
297
    }
186
298
 
187
299
    // restore connection settings
188
 
    // (not set if $cfg['AllowAnywhereRecoding'] is false)
189
300
    $charset_of_file = isset($GLOBALS['charset_of_file']) ? $GLOBALS['charset_of_file'] : '';
190
301
    if (!empty($GLOBALS['asfile']) && isset($mysql_charset_map[$charset_of_file])) {
191
302
        $foot .=  $crlf
194
305
               . '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' . $crlf;
195
306
    }
196
307
 
 
308
    /* Restore timezone */
 
309
    if ($GLOBALS['sql_utc_time']) {
 
310
        PMA_DBI_query('SET time_zone = "' . $GLOBALS['old_tz'] . '"');
 
311
    }
 
312
 
197
313
    return PMA_exportOutputHandler($foot);
198
314
}
199
315
 
222
338
           .  PMA_exportComment('version ' . PMA_VERSION)
223
339
           .  PMA_exportComment('http://www.phpmyadmin.net')
224
340
           .  PMA_exportComment();
225
 
    $head .= empty($cfg['Server']['port']) ? PMA_exportComment($GLOBALS['strHost'] . ': ' . $cfg['Server']['host']) : PMA_exportComment($GLOBALS['strHost'] . ': ' .  $cfg['Server']['host'] . ':' . $cfg['Server']['port']);
226
 
    $head .=  PMA_exportComment($GLOBALS['strGenTime']
 
341
    $head .= empty($cfg['Server']['port']) ? PMA_exportComment(__('Host') . ': ' . $cfg['Server']['host']) : PMA_exportComment(__('Host') . ': ' .  $cfg['Server']['host'] . ':' . $cfg['Server']['port']);
 
342
    $head .=  PMA_exportComment(__('Generation Time')
227
343
           . ': ' .  PMA_localisedDate())
228
 
           .  PMA_exportComment($GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3))
229
 
           .  PMA_exportComment($GLOBALS['strPHPVersion'] . ': ' . phpversion())
 
344
           .  PMA_exportComment(__('Server version') . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3))
 
345
           .  PMA_exportComment(__('PHP Version') . ': ' . phpversion())
230
346
           .  PMA_possibleCRLF();
231
347
 
232
348
    if (isset($GLOBALS['sql_header_comment']) && !empty($GLOBALS['sql_header_comment'])) {
254
370
                . 'START TRANSACTION;' . $crlf;
255
371
    }
256
372
 
 
373
 
 
374
    /* Change timezone if we should export timestamps in UTC */
 
375
    if ($GLOBALS['sql_utc_time']) {
 
376
        $head .= 'SET time_zone = "+00:00";' . $crlf;
 
377
        $GLOBALS['old_tz'] = PMA_DBI_fetch_value('SELECT @@session.time_zone');
 
378
        PMA_DBI_query('SET time_zone = "+00:00"');
 
379
    }
 
380
 
257
381
    $head .= PMA_possibleCRLF();
258
382
 
259
383
    if (! empty($GLOBALS['asfile'])) {
261
385
        // so that a utility like the mysql client can interpret
262
386
        // the file correctly
263
387
        if (isset($GLOBALS['charset_of_file']) && isset($mysql_charset_map[$GLOBALS['charset_of_file']])) {
264
 
            // $cfg['AllowAnywhereRecoding'] was true so we got a charset from
265
 
            // the export dialog
 
388
            // we got a charset from the export dialog
266
389
            $set_names = $mysql_charset_map[$GLOBALS['charset_of_file']];
267
390
        } else {
268
391
            // by default we use the connection charset
312
435
        $result = PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
313
436
    }
314
437
 
315
 
    if ($result && isset($GLOBALS['sql_structure']) && isset($GLOBALS['sql_procedure_function'])) {
316
 
        $text = '';
317
 
        $delimiter = '$$';
318
 
 
319
 
        $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
320
 
        $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
321
 
 
322
 
        if ($procedure_names || $function_names) {
323
 
            $text .= $crlf
324
 
              . 'DELIMITER ' . $delimiter . $crlf;
325
 
        }
326
 
 
327
 
        if ($procedure_names) {
328
 
            $text .=
329
 
                PMA_exportComment()
330
 
              . PMA_exportComment($GLOBALS['strProcedures'])
331
 
              . PMA_exportComment();
332
 
 
333
 
            foreach($procedure_names as $procedure_name) {
334
 
                if (! empty($GLOBALS['sql_drop_table'])) {
335
 
                    $text .= 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($procedure_name) . $delimiter . $crlf;
336
 
                }
337
 
                $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf;
338
 
            }
339
 
        }
340
 
 
341
 
        if ($function_names) {
342
 
            $text .=
343
 
                PMA_exportComment()
344
 
              . PMA_exportComment($GLOBALS['strFunctions'])
345
 
              . PMA_exportComment();
346
 
 
347
 
            foreach($function_names as $function_name) {
348
 
                if (! empty($GLOBALS['sql_drop_table'])) {
349
 
                    $text .= 'DROP FUNCTION IF EXISTS ' . PMA_backquote($function_name) . $delimiter . $crlf;
350
 
                }
351
 
                $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf;
352
 
            }
353
 
        }
354
 
 
355
 
        if ($procedure_names || $function_names) {
356
 
            $text .= 'DELIMITER ;' . $crlf;
357
 
        }
358
 
 
359
 
        if (! empty($text)) {
360
 
            $result = PMA_exportOutputHandler($text);
361
 
        }
362
 
    }
363
438
    return $result;
364
439
}
365
440
 
375
450
function PMA_exportDBHeader($db)
376
451
{
377
452
    $head = PMA_exportComment()
378
 
          . PMA_exportComment($GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''))
 
453
          . PMA_exportComment(__('Database') . ': ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''))
379
454
          . PMA_exportComment();
380
455
    return PMA_exportOutputHandler($head);
381
456
}
399
474
        unset($GLOBALS['sql_constraints']);
400
475
    }
401
476
 
402
 
    if (isset($GLOBALS['sql_structure']) && isset($GLOBALS['sql_procedure_function'])) {
 
477
    if (($GLOBALS['sql_structure_or_data'] == 'structure' || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') && isset($GLOBALS['sql_procedure_function'])) {
403
478
        $text = '';
404
479
        $delimiter = '$$';
405
480
 
415
490
 
416
491
            $text .=
417
492
                PMA_exportComment()
418
 
              . PMA_exportComment($GLOBALS['strEvents'])
 
493
              . PMA_exportComment(__('Events'))
419
494
              . PMA_exportComment();
420
495
 
421
496
            foreach($event_names as $event_name) {
422
497
                if (! empty($GLOBALS['sql_drop_table'])) {
423
 
                    $text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf;
 
498
            $text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf;
424
499
                }
425
500
                $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf;
426
501
            }
513
588
            }
514
589
 
515
590
            if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
516
 
                $schema_create .= PMA_exportComment($GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])));
 
591
                $schema_create .= PMA_exportComment(__('Creation') . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])));
517
592
                $new_crlf = PMA_exportComment() . $crlf;
518
593
            }
519
594
 
520
595
            if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
521
 
                $schema_create .= PMA_exportComment($GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])));
 
596
                $schema_create .= PMA_exportComment(__('Last update') . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])));
522
597
                $new_crlf = PMA_exportComment() . $crlf;
523
598
            }
524
599
 
525
600
            if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
526
 
                $schema_create .= PMA_exportComment($GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])));
 
601
                $schema_create .= PMA_exportComment(__('Last check') . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])));
527
602
                $new_crlf = PMA_exportComment() . $crlf;
528
603
            }
529
604
        }
537
612
        $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $sql_backquotes) . ';' . $crlf;
538
613
    }
539
614
 
540
 
    // Steve Alberty's patch for complete table dump,
 
615
    // Complete table dump,
541
616
    // Whether to quote table and fields names or not
542
617
    if ($sql_backquotes) {
543
618
        PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1');
558
633
    // an error can happen, for example the table is crashed
559
634
    $tmp_error = PMA_DBI_getError();
560
635
    if ($tmp_error) {
561
 
        return PMA_exportComment($GLOBALS['strInUse'] . '(' . $tmp_error . ')');
 
636
        return PMA_exportComment(__('in use') . '(' . $tmp_error . ')');
562
637
    }
563
638
 
564
639
    if ($result != FALSE && ($row = PMA_DBI_fetch_row($result))) {
617
692
                    } else {
618
693
                        $sql_constraints = $crlf
619
694
                                         . PMA_exportComment()
620
 
                                         . PMA_exportComment($GLOBALS['strConstraintsForDumped'])
 
695
                                         . PMA_exportComment(__('Constraints for dumped tables'))
621
696
                                         . PMA_exportComment();
622
697
                    }
623
698
                }
626
701
                if (!isset($GLOBALS['no_constraints_comments'])) {
627
702
                    $sql_constraints .= $crlf
628
703
                                     . PMA_exportComment()
629
 
                                     . PMA_exportComment($GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table))
 
704
                                     . PMA_exportComment(__('Constraints for table') . ' ' . PMA_backquote($table))
630
705
                                     . PMA_exportComment();
631
706
                }
632
707
 
642
717
                            $sql_constraints .= $crlf;
643
718
                        }
644
719
                        if (strpos($sql_lines[$j], 'CONSTRAINT') === FALSE) {
645
 
                            $str_tmp = preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]);
646
 
                            $sql_constraints_query .= $str_tmp;
647
 
                            $sql_constraints .= $str_tmp;
 
720
                            $tmp_str = preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]);
 
721
                            $sql_constraints_query .= $tmp_str;
 
722
                            $sql_constraints .= $tmp_str;
648
723
                        } else {
649
 
                            $str_tmp = preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]);
650
 
                            $sql_constraints_query .= $str_tmp;
651
 
                            $sql_constraints .= $str_tmp;
 
724
                            $tmp_str = preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]);
 
725
                            $sql_constraints_query .= $tmp_str;
 
726
                            $sql_constraints .= $tmp_str;
652
727
                            preg_match('/(CONSTRAINT)([\s])([\S]*)([\s])/', $sql_lines[$j], $matches);
653
728
                            if (! $first) {
654
729
                                $sql_drop_foreign_keys .= ', ';
724
799
    }
725
800
 
726
801
    if (isset($mime_map) && count($mime_map) > 0) {
727
 
        $schema_create .= PMA_possibleCRLF() 
 
802
        $schema_create .= PMA_possibleCRLF()
728
803
                       . PMA_exportComment()
729
 
                       . PMA_exportComment($GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $sql_backquotes) . ':');
 
804
                       . PMA_exportComment(__('MIME TYPES FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
730
805
        @reset($mime_map);
731
806
        foreach ($mime_map AS $mime_field => $mime) {
732
807
            $schema_create .= PMA_exportComment('  ' . PMA_backquote($mime_field, $sql_backquotes))
736
811
    }
737
812
 
738
813
    if ($have_rel) {
739
 
        $schema_create .= PMA_possibleCRLF() 
 
814
        $schema_create .= PMA_possibleCRLF()
740
815
                       . PMA_exportComment()
741
 
                       . PMA_exportComment($GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $sql_backquotes) . ':');
 
816
                       . PMA_exportComment(__('RELATIONS FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
742
817
        foreach ($res_rel AS $rel_field => $rel) {
743
818
            $schema_create .= PMA_exportComment('  ' . PMA_backquote($rel_field, $sql_backquotes))
744
819
                            . PMA_exportComment('      ' . PMA_backquote($rel['foreign_table'], $sql_backquotes)
777
852
    $formatted_table_name = (isset($GLOBALS['sql_backquotes']))
778
853
                          ? PMA_backquote($table)
779
854
                          : '\'' . $table . '\'';
780
 
    $dump = PMA_possibleCRLF() 
 
855
    $dump = PMA_possibleCRLF()
781
856
          . PMA_exportComment(str_repeat('-', 56))
782
 
          . PMA_possibleCRLF() 
 
857
          . PMA_possibleCRLF()
783
858
          . PMA_exportComment();
784
859
 
785
860
    switch($export_mode) {
786
861
        case 'create_table':
787
 
            $dump .=  PMA_exportComment($GLOBALS['strTableStructure'] . ' ' . $formatted_table_name)
 
862
            $dump .=  PMA_exportComment(__('Table structure for table') . ' ' . $formatted_table_name)
788
863
                  . PMA_exportComment();
789
864
            $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);
790
865
            $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $mime);
791
866
            break;
792
867
        case 'triggers':
793
 
            $dump = ''; 
 
868
            $dump = '';
794
869
            $triggers = PMA_DBI_get_triggers($db, $table);
795
870
            if ($triggers) {
796
 
                $dump .=  PMA_possibleCRLF() 
 
871
                $dump .=  PMA_possibleCRLF()
797
872
                      . PMA_exportComment()
798
 
                      . PMA_exportComment($GLOBALS['strTriggers'] . ' ' . $formatted_table_name)
 
873
                      . PMA_exportComment(__('Triggers') . ' ' . $formatted_table_name)
799
874
                      . PMA_exportComment();
800
875
                $delimiter = '//';
801
876
                foreach ($triggers as $trigger) {
807
882
            }
808
883
            break;
809
884
        case 'create_view':
810
 
            $dump .= PMA_exportComment($GLOBALS['strStructureForView'] . ' ' . $formatted_table_name)
 
885
            $dump .= PMA_exportComment(__('Structure for view') . ' ' . $formatted_table_name)
811
886
                  .  PMA_exportComment();
812
887
            // delete the stand-in table previously created (if any)
813
888
            if ($export_type != 'table') {
816
891
            $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates, true, true);
817
892
            break;
818
893
        case 'stand_in':
819
 
            $dump .=  PMA_exportComment($GLOBALS['strStandInStructureForView'] . ' ' . $formatted_table_name)
 
894
            $dump .=  PMA_exportComment(__('Stand-in structure for view') . ' ' . $formatted_table_name)
820
895
                  .  PMA_exportComment();
821
896
            // export a stand-in definition to resolve view dependencies
822
897
            $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
850
925
 *
851
926
 * @see     PMA_getTableContentFast(), PMA_getTableContentOld()
852
927
 *
853
 
 * @author  staybyte
854
928
 */
855
929
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
856
930
{
865
939
    // Do not export data for a VIEW
866
940
    // (For a VIEW, this is called only when exporting a single VIEW)
867
941
    if (PMA_Table::isView($db, $table)) {
868
 
        $head = PMA_possibleCRLF() 
 
942
        $head = PMA_possibleCRLF()
869
943
          . PMA_exportComment()
870
944
          . PMA_exportComment('VIEW ' . ' ' . $formatted_table_name)
871
 
          . PMA_exportComment($GLOBALS['strData'] . ': ' . $GLOBALS['strNone'])
 
945
          . PMA_exportComment(__('Data') . ': ' . __('None'))
872
946
          . PMA_exportComment()
873
947
          . PMA_possibleCRLF();
874
948
 
879
953
    }
880
954
 
881
955
    // it's not a VIEW
882
 
    $head = PMA_possibleCRLF() 
883
 
          . PMA_exportComment()
884
 
          . PMA_exportComment($GLOBALS['strDumpingData'] . ' ' . $formatted_table_name)
885
 
          . PMA_exportComment();
886
 
 
887
 
    if (! PMA_exportOutputHandler($head)) {
888
 
        return FALSE;
889
 
    }
890
 
 
891
956
    $buffer = '';
892
957
 
893
958
    // analyze the query to get the true column names, not the aliases
899
964
    // a possible error: the table has crashed
900
965
    $tmp_error = PMA_DBI_getError();
901
966
    if ($tmp_error) {
902
 
        return PMA_exportOutputHandler(PMA_exportComment($GLOBALS['strInUse'] . ' (' . $tmp_error . ')'));
 
967
        return PMA_exportOutputHandler(PMA_exportComment(__('in use') . ' (' . $tmp_error . ')'));
903
968
    }
904
969
 
905
970
    if ($result != FALSE) {
906
 
        // emit a single CRLF before the first data statement (produces
907
 
        // an unintended CRLF when there is no data, but I don't see how it
908
 
        // can be avoided, as we are in UNBUFFERED mode)
909
 
        if (! PMA_exportOutputHandler($crlf)) {
910
 
            return FALSE;
911
 
        }
912
 
 
913
971
        $fields_cnt     = PMA_DBI_num_fields($result);
914
972
 
915
973
        // Get field information
956
1014
            }
957
1015
 
958
1016
            // scheme for inserting fields
959
 
            if (isset($GLOBALS['sql_columns'])) {
 
1017
            if ($GLOBALS['sql_insert_syntax'] == 'complete' || $GLOBALS['sql_insert_syntax'] == 'both') {
960
1018
                $fields        = implode(', ', $field_set);
961
1019
                $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)
962
1020
            // avoid EOL blank
971
1029
        $replace      = array('\0', '\n', '\r', '\Z');
972
1030
        $current_row  = 0;
973
1031
        $query_size   = 0;
974
 
        if (isset($GLOBALS['sql_extended']) && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
 
1032
        if (($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
975
1033
            $separator    = ',';
976
1034
            $schema_insert .= $crlf;
977
1035
        } else {
979
1037
        }
980
1038
 
981
1039
        while ($row = PMA_DBI_fetch_row($result)) {
 
1040
            if ($current_row == 0) {
 
1041
                $head = PMA_possibleCRLF()
 
1042
                      . PMA_exportComment()
 
1043
                      . PMA_exportComment(__('Dumping data for table') . ' ' . $formatted_table_name)
 
1044
                      . PMA_exportComment()
 
1045
                      . $crlf;
 
1046
                if (! PMA_exportOutputHandler($head)) {
 
1047
                    return FALSE;
 
1048
                }
 
1049
            }
982
1050
            $current_row++;
983
1051
            for ($j = 0; $j < $fields_cnt; $j++) {
984
1052
                // NULL
1035
1103
            } else {
1036
1104
 
1037
1105
                // Extended inserts case
1038
 
                if (isset($GLOBALS['sql_extended'])) {
 
1106
                if ($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') {
1039
1107
                    if ($current_row == 1) {
1040
1108
                        $insert_line  = $schema_insert . '(' . implode(', ', $values) . ')';
1041
1109
                    } else {