// --------------- // Add table index // --------------- $Output->Append("<table>\n"); $Output->Append("<tr><th><strong>Table</strong></th><th><strong>Description</strong></th><th><strong>Doc Status</strong></th></tr>\n"); $tables = $db->Query("SHOW TABLE STATUS")->fetchAll(); $tables_simplified = array(); foreach ($tables as $table) { $tables_simplified[] = $table["Name"]; $Output->Append("<tr>"); if (isset($table_doc[$schema][$table["Name"]])) { $Output->Append("<td>@subpage {$MakeRef($schema, $table["Name"])} \"{$table["Name"]}\" </td><td>{$table_doc[$schema][$table["Name"]]["brief"]}</td>"); } else { $Output->Append("<td>@subpage {$MakeRef($schema, $table["Name"])} \"{$table["Name"]}\" </td><td></td>"); } $cols_in_table = $db->Query("SELECT COLUMN_NAME FROM `information_schema`.`columns` WHERE `TABLE_SCHEMA` = '{$schema}' AND `TABLE_NAME` = {$db->Quote($table["Name"])}")->fetchAll(PDO::FETCH_NUM); $documented_cols = $db->Query("SELECT `column` FROM `documentation`.`column` WHERE `schema` = '{$schema}' AND `table` = {$db->Quote($table["Name"])}")->fetchAll(PDO::FETCH_NUM); $real_documented_cols = 0; $cols_in_table_simplified = array(); foreach ($cols_in_table as $col) { $cols_in_table_simplified[] = $col[0]; } foreach ($documented_cols as $col) { if (!in_array($col[0], $cols_in_table_simplified)) { print "WARNING: Column {$col[0]} is documented for table {$table["Name"]} but doesn't exist!\n"; } else { ++$real_documented_cols; } } $pct = $real_documented_cols / count($cols_in_table) * 100; //if (ceil($pct) >= 100 && $real_documented_cols < count($cols_in_table))
unlink($filename); die("{$prog}: internal error: no tables for bin: {$bin} (check case is correct)\n"); } if ($export == "all") { $cmd = "{$bin_mysqldump} --skip-add-drop-table --default-character-set=utf8mb4 -u{$dbuser} -h {$hostname} {$database} {$string} >> {$filename}"; } else { $cmd = "{$bin_mysqldump} --skip-add-drop-table --no-data --default-character-set=utf8mb4 -u{$dbuser} -h {$hostname} {$database} {$string} >> {$filename}"; } system($cmd); /* Now append the dump with TCAT table information */ $fh = fopen($filename, "a"); fputs($fh, "\n"); fputs($fh, "--\n"); fputs($fh, "-- DMI-TCAT - Update TCAT tables\n"); fputs($fh, "--\n"); $sql = "INSERT INTO tcat_query_bins ( querybin, `type`, active, access ) values ( " . $dbh->Quote($bin) . ", " . $dbh->Quote($bintype) . ", 0, 0 );"; fputs($fh, $sql . "\n"); if ($bintype == 'track') { // Notice: We do not export information from the tcat_captured_phrases table here. Because we allow adding of phrasing and querybins to an existing tcat installation, // the phrase IDs will change and it would not be safe to simply copy the data (phrase id <-> phrase text would no longer match) foreach ($phrases as $phrase) { $sql = "INSERT INTO tcat_query_phrases ( phrase ) values ( " . $dbh->Quote($phrase) . " );"; fputs($fh, $sql . "\n"); } foreach ($phrases as $phrase) { $starttime = $phrase_starttime[$phrase]; $endtime = $phrase_endtime[$phrase]; $sql = "INSERT INTO tcat_query_bins_phrases SET " . " starttime = '{$starttime}', " . " endtime = '{$endtime}', " . " phrase_id = ( select MIN(id) from tcat_query_phrases where phrase = " . $dbh->Quote($phrase) . " ), " . " querybin_id = ( select MAX(id) from tcat_query_bins );"; fputs($fh, $sql . "\n"); } // we could have just now inserted duplicate phrases in the database, the next two queries resolve that problem
die("Empty bin name would dump the complete database. Exiting!\n"); } $cmd = "{$bin_mysqldump} --default-character-set=utf8mb4 -u{$dbuser} -h {$hostname} {$database} {$string} > {$filename}"; system($cmd); } else { touch($filename); } /* Now append the dump with TCAT table information */ $fh = fopen($filename, "a"); fputs($fh, "\n"); fputs($fh, "--\n"); fputs($fh, "-- DMI-TCAT - Update TCAT tables\n"); fputs($fh, "--\n"); /* Lock TCAT tables */ fputs($fh, "LOCK TABLES `tcat_query_bins` WRITE, `tcat_query_phrases` WRITE, `tcat_query_bins_periods` WRITE, `tcat_query_users` WRITE, `tcat_query_bins_phrases` WRITE, `tcat_query_bins_users` WRITE;\n"); $sql = "INSERT INTO tcat_query_bins ( querybin, `type`, active, visible ) values ( " . $dbh->Quote($bin) . ", " . $dbh->Quote($bintype) . ", 0, 1 );"; fputs($fh, $sql . "\n"); if ($bintype == 'track') { $sql = "CREATE TEMPORARY TABLE temp_phrase_ids ( phrase_id bigint primary key, phrase varchar(512) );"; fputs($fh, $sql . "\n"); foreach ($phrases as $phrase) { $sql = "INSERT INTO tcat_query_phrases ( phrase ) values ( " . $dbh->Quote($phrase) . " );"; fputs($fh, $sql . "\n"); $sql = "INSERT INTO temp_phrase_ids ( phrase_id, phrase ) values ( LAST_INSERT_ID(), " . $dbh->Quote($phrase) . " );"; fputs($fh, $sql . "\n"); } foreach ($phrases as $phrase) { $starttime = $phrase_starttime[$phrase]; $endtime = $phrase_endtime[$phrase]; $sql = "INSERT INTO tcat_query_bins_phrases SET " . " starttime = '{$starttime}', " . " endtime = '{$endtime}', " . " phrase_id = ( select phrase_id from temp_phrase_ids where phrase = " . $dbh->Quote($phrase) . " ), " . " querybin_id = ( select MAX(id) from tcat_query_bins );"; fputs($fh, $sql . "\n");
/** * @param string $input * @return string */ public function escape($input) { if (is_null($this->db)) { $this->connect_db(); } return $this->db->Quote($input); }