Skip to content

Commit

Permalink
Create PMA_is_system_schema() function which checks whether current d…
Browse files Browse the repository at this point in the history
…atabase server treats it as a system schema
  • Loading branch information
piotrp committed Aug 23, 2011
1 parent 4cf5fe7 commit 8cd8760
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 37 deletions.
6 changes: 1 addition & 5 deletions db_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,7 @@
}

$db_collation = PMA_getDbCollation($db);
if (strtolower($db) == 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
$is_information_schema = true;
} else {
$is_information_schema = false;
}
$is_information_schema = PMA_is_system_schema($db);

if (!$is_information_schema) {
if ($cfgRelation['commwork']) {
Expand Down
3 changes: 1 addition & 2 deletions libraries/List.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public function getHtmlOptions($selected = '', $include_information_schema = tru
$options = '';
foreach ($this as $each_item) {
if (false === $include_information_schema
&& 'information_schema' === strtolower($each_item)
&& (!PMA_DRIZZLE || 'data_dictionary' == strtolower($each_item))) {
&& PMA_is_system_schema($each_item)) {
continue;
}
$options .= '<option value="' . htmlspecialchars($each_item) . '"';
Expand Down
2 changes: 1 addition & 1 deletion libraries/Table.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ static public function countRecords($db, $table, $force_exact = false, $is_view
if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
// Make an exception for views in I_S and D_D schema in Drizzle, as these map to
// in-memory data and should execute fast enough
if (! $is_view || (PMA_DRIZZLE && (strtolower($db) == 'information_schema' || strtolower($db) == 'data_dictionary'))) {
if (! $is_view || (PMA_DRIZZLE && PMA_is_system_schema($db))) {
$row_count = PMA_DBI_fetch_value(
'SELECT COUNT(*) FROM ' . PMA_backquote($db) . '.'
. PMA_backquote($table)
Expand Down
3 changes: 1 addition & 2 deletions libraries/blobstreaming.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function initPBMSDatabase()
return true;
}
if ($target == "") {
if ($current_db != 'pbxt' && $current_db != 'mysql' && strtolower($current_db) != 'information_schema'
&& (!PMA_DRIZZLE || strtolower($current_db) != 'data_dictionary')) {
if ($current_db != 'pbxt' && !PMA_is_system_schema($current_db, true)) {
$target = $current_db;
}
}
Expand Down
4 changes: 1 addition & 3 deletions libraries/build_html_for_db.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ function PMA_buildHtmlForDb($current, $is_superuser, $checkall, $url_query, $col
$out .= '<td class="tool">';
$out .= '<input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ';

if (strtolower($current['SCHEMA_NAME']) != 'information_schema'
&& (PMA_DRIZZLE || $current['SCHEMA_NAME'] != 'mysql')
&& (!PMA_DRIZZLE || strtolower($current['SCHEMA_NAME']) != 'data_dictionary')) {
if (!PMA_is_system_schema($current['SCHEMA_NAME'], true)) {
$out .= (empty($checkall) ? '' : 'checked="checked" ') . '/>';
} else {
$out .= ' disabled="disabled" />';
Expand Down
3 changes: 1 addition & 2 deletions libraries/common.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,7 @@ function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count =
// set this because PMA_Table::countRecords() can use it
$tbl_is_view = $table['TABLE_TYPE'] == 'VIEW';

if ($tbl_is_view || strtolower($db) == 'information_schema'
|| (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
if ($tbl_is_view || PMA_is_system_schema($db)) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], false, true);
}
}
Expand Down
15 changes: 15 additions & 0 deletions libraries/database_interface.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,21 @@ function PMA_DBI_get_triggers($db, $table = '', $delimiter = '//')
return($result);
}

/**
* Checks whether given schema is a system schema: information_schema (MySQL and Drizzle)
* or data_dictionary (Drizzle)
*
* @param string $schema_name
* @param bool $test_for_mysql_schema Whether 'mysql' schema should be treated the same as IS and DD
* @return bool
*/
function PMA_is_system_schema($schema_name, $test_for_mysql_schema = false)
{
return strtolower($schema_name) == 'information_schema'
|| (PMA_DRIZZLE && strtolower($schema_name) == 'data_dictionary')
|| ($test_for_mysql_schema && !PMA_DRIZZLE && $schema_name == 'mysql');
}

/**
* Returns true if $db.$view_name is a view, false if not
*
Expand Down
6 changes: 2 additions & 4 deletions libraries/db_common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

$is_show_stats = $cfg['ShowStats'];

if (strtolower($db) == 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
$db_is_information_schema = PMA_is_system_schema($db);
if ($db_is_information_schema) {
$is_show_stats = false;
$db_is_information_schema = true;
} else {
$db_is_information_schema = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/db_info.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
*/
$db_is_information_schema = false;

if (strtolower($db) == 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
if (PMA_is_system_schema($db)) {
$is_show_stats = false;
$db_is_information_schema = true;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/mysql_charsets.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function PMA_generateCharsetQueryPart($collation)
*/
function PMA_getDbCollation($db)
{
if (strtolower($db) == 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
if (PMA_is_system_schema($db)) {
// We don't have to check the collation of the virtual
// information_schema database: We know it!
return 'utf8_general_ci';
Expand Down
2 changes: 1 addition & 1 deletion libraries/replication.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function PMA_replication_master_replicated_dbs($link = null)

$tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $link);
while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
if ($tmp_row[0] == 'information_schema')
if (PMA_is_system_schema($tmp_row[0]))
continue;
if (count($do_db) == 0) {
if (array_search($tmp_row[0], $ignore_db) !== false) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/replication_gui.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function PMA_replication_db_multibox()
$multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';

foreach ($GLOBALS['pma']->databases as $current_db) {
if ('information_schema' == $current_db) {
if (PMA_is_system_schema($current_db)) {
continue;
}
if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
Expand Down
6 changes: 1 addition & 5 deletions libraries/tbl_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
// Check parameters
PMA_checkParameters(array('db', 'table'));

if (strtolower($db) === 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
$db_is_information_schema = true;
} else {
$db_is_information_schema = false;
}
$db_is_information_schema = PMA_is_system_schema($db);

/**
* Set parameters for links
Expand Down
2 changes: 1 addition & 1 deletion navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function PMA_exitNavigationFrame()
echo __('No tables found in database.');
}
unset($table_list);
if (strtolower($db) != 'information_schema' && (!PMA_DRIZZLE || strtolower($db) != 'data_dictionary')) {
if (!PMA_is_system_schema($db)) {
$class = '';
$GLOBALS['cfg']['AjaxEnable'] ? $class="ajax" : '';
echo '<ul id="newtable"><li><a target="frame_content" href="tbl_create.php' . PMA_generate_common_url(array('db' => $GLOBALS['db'])) . '" class="'.$class .'" >'
Expand Down
4 changes: 1 addition & 3 deletions server_databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@
$odd_row = true;
foreach ($databases as $current) {
$tr_class = $odd_row ? 'odd' : 'even';
if (strtolower($current['SCHEMA_NAME']) == 'information_schema'
|| (!PMA_DRIZZLE && $current['SCHEMA_NAME'] == 'mysql')
|| (PMA_DRIZZLE && strtolower($current['SCHEMA_NAME']) == 'data_dictionary')) {
if (PMA_is_system_schema($current['SCHEMA_NAME'], true)) {
$tr_class .= ' noclick';
}
echo '<tr class="' . $tr_class . '">' . "\n";
Expand Down
2 changes: 1 addition & 1 deletion server_replication.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

$tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $src_link);
while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
if ($tmp_row[0] == 'information_schema') {
if (PMA_is_system_schema($tmp_row[0])) {
continue;
}
if (count($do_db) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@
}

// hide edit and delete links for information_schema
if ($db == 'information_schema') {
if (PMA_is_system_schema($db)) {
$disp_mode = 'nnnn110111';
}

Expand Down Expand Up @@ -907,7 +907,7 @@
}

// hide edit and delete links for information_schema
if (strtolower($db) == 'information_schema' || (PMA_DRIZZLE && strtolower($db) == 'data_dictionary')) {
if (PMA_is_system_schema($db)) {
$disp_mode = 'nnnn110111';
}

Expand Down
3 changes: 1 addition & 2 deletions tbl_printview.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@
</tbody>
</table>
<?php
if (! $tbl_is_view && strtolower($db) != 'information_schema'
&& (!PMA_DRIZZLE || strtolower($db) != 'data_dictionary')) {
if (! $tbl_is_view && !PMA_is_system_schema($db)) {
/**
* Displays indexes
*/
Expand Down

0 comments on commit 8cd8760

Please sign in to comment.