'sql', 'copy' => 'sql', 'csv' => 'csv', 'tab' => 'txt', 'html' => 'html', 'xml' => 'xml' ); // Prevent timeouts on large exports (non-safe mode only) if (!ini_get('safe_mode')) set_time_limit(0); // if (!isset($_REQUEST['table']) && !isset($_REQUEST['query'])) // What must we do in this case? Maybe redirect to the homepage? // If format is set, then perform the export if (isset($_REQUEST['what'])) { // Include application functions $_no_output = true; include_once('./libraries/lib.inc.php'); switch ($_REQUEST['what']) { case 'dataonly': // Check to see if they have pg_dump set up and if they do, use that // instead of custom dump code if ($misc->isDumpEnabled() && ($_REQUEST['d_format'] == 'copy' || $_REQUEST['d_format'] == 'sql')) { include('./dbexport.php'); exit; } else { $format = $_REQUEST['d_format']; $oids = isset($_REQUEST['d_oids']); } break; case 'structureonly': // Check to see if they have pg_dump set up and if they do, use that // instead of custom dump code if ($misc->isDumpEnabled()) { include('./dbexport.php'); exit; } else $clean = isset($_REQUEST['s_clean']); break; case 'structureanddata': // Check to see if they have pg_dump set up and if they do, use that // instead of custom dump code if ($misc->isDumpEnabled()) { include('./dbexport.php'); exit; } else { $format = $_REQUEST['sd_format']; $clean = isset($_REQUEST['sd_clean']); $oids = isset($_REQUEST['sd_oids']); } break; } // Make it do a download, if necessary if ($_REQUEST['output'] == 'download') { // Set headers. MSIE is totally broken for SSL downloading, so // we need to have it download in-place as plain text if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS'])) { header('Content-Type: text/plain'); } else { header('Content-Type: application/download'); if (isset($extensions[$format])) $ext = $extensions[$format]; else $ext = 'txt'; header('Content-Disposition: attachment; filename=dump.' . $ext); } } else { header('Content-Type: text/plain'); } if (isset($_REQUEST['query'])) $_REQUEST['query'] = trim(urldecode($_REQUEST['query'])); // Set the schema search path if (isset($_REQUEST['search_path'])) { $data->setSearchPath(array_map('trim',explode(',',$_REQUEST['search_path']))); } // Set up the dump transaction $status = $data->beginDump(); // If the dump is not dataonly then dump the structure prefix if ($_REQUEST['what'] != 'dataonly') echo $data->getTableDefPrefix($_REQUEST['table'], $clean); // If the dump is not structureonly then dump the actual data if ($_REQUEST['what'] != 'structureonly') { // Get database encoding $dbEncoding = $data->getDatabaseEncoding(); // Set fetch mode to NUM so that duplicate field names are properly returned $data->conn->setFetchMode(ADODB_FETCH_NUM); // Execute the query, if set, otherwise grab all rows from the table if (isset($_REQUEST['table'])) $rs = $data->dumpRelation($_REQUEST['table'], $oids); else $rs = $data->conn->Execute($_REQUEST['query']); if ($format == 'copy') { $data->fieldClean($_REQUEST['table']); echo "COPY \"{$_REQUEST['table']}\""; if ($oids) echo " WITH OIDS"; echo " FROM stdin;\n"; while (!$rs->EOF) { $first = true; while(list($k, $v) = each($rs->fields)) { // Escape value $v = $data->escapeBytea($v); // We add an extra escaping slash onto octal encoded characters $v = preg_replace('/\\\\([0-7]{3})/', '\\\\\1', $v); if ($first) { echo (is_null($v)) ? '\\N' : $v; $first = false; } else echo "\t", (is_null($v)) ? '\\N' : $v; } echo "\n"; $rs->moveNext(); } echo "\\.\n"; } elseif ($format == 'html') { echo "\r\n"; echo "\r\n"; echo "
\r\n"; echo "\t", $misc->printVal($finfo->name, true), " | \r\n"; } } echo "\t
---|
", $misc->printVal($v, true, $finfo->type), " | \r\n"; } echo "\t