2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * DocSQL import plugin for phpMyAdmin
7 * @package phpMyAdmin-Import
9 if (! defined('PHPMYADMIN')) {
16 require_once './libraries/relation.lib.php';
17 $cfgRelation = PMA_getRelationsParam();
20 * We need relations enabled and we work only on database
22 if ($plugin_param !== 'database' ||
$GLOBALS['num_tables'] < 1
23 ||
! $cfgRelation['relwork'] ||
! $cfgRelation['commwork']) {
27 if (isset($plugin_list)) {
28 $plugin_list['docsql'] = array( // set name of your plugin
29 'text' => 'strDocSQL', // text to be displayed as choice
30 'extension' => '', // extension this plugin can handle
31 'options' => array( // array of options for your plugin (optional)
32 array('type' => 'text', 'name' => 'table', 'text' => 'strTableName'),
34 'options_text' => 'strOptions', // text to describe plugin options (must be set if options are used)
36 /* We do not define function when plugin is just queried for information above */
40 $tab = $_POST['docsql_table'];
42 /* Read whole buffer, we except it is small enough */
43 while (!$finished && !$error && !$timeout_passed) {
44 $data = PMA_importGetNextChunk();
45 if ($data === FALSE) {
46 // subtract data we didn't handle yet and stop processing
48 } elseif ($data === TRUE) {
52 // Append new data to buffer
55 } // End of import loop
56 /* Process the data */
57 if ($data === TRUE && !$error && !$timeout_passed) {
58 $buffer = str_replace("\r\n", "\n", $buffer);
59 $buffer = str_replace("\r", "\n", $buffer);
60 $lines = explode("\n", $buffer);
61 foreach ($lines AS $lkey => $line) {
62 //echo '<p>' . $line . '</p>';
63 $inf = explode('|', $line);
64 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
67 ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
68 (db_name, table_name, column_name, ' . PMA_backquote('comment') . ')
70 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
71 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
72 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
73 \'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
74 PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]), true);
75 } // end inf[1] exists
76 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
77 $for = explode('->', $inf[2]);
80 ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
81 (master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
83 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
84 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
85 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
86 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
87 \'' . PMA_sqlAddslashes(trim($for[0])) . '\',
88 \'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
89 PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
90 } // end inf[2] exists
93 // Commit any possible data in buffers