Important: This is a development wiki, so things might be a little unstable. If something doesn't work properly, try refreshing the page. If that fails, come back later!

Debugging tools/describe table

From TestWiki

Jump to: navigation, search

The WikiDebug extension adds a new tag that allows you to display a live description of a DB table within a wiki page.

Contents

Syntax

<describe_table table="{TableName}" display="{DisplayType}" showindexes="{bool}"></describe_table>
  • {TableName} is the name of a table in the wiki's database. Do not include the prefix specified by $wgPrefix.
  • {DisplayType} is the output format for the table data and currently has two possible values. "table" outputs the table definition in tabular form and "sql" outputs it as an SQL "CREATE TABLE" statement. The display attribute is optional, and if omitted (or present but the value is invalid) then "sql" will be used.
  • showindexes is an optional argument, which defaults to true if omitted. Set to false to disable index display when outputting in tabular form (ignored for SQL output).

As a security measure this extension will only allow display of tables added to the $wgWikiDebug_ViewableTables array. Any other tables are blocked.

For example, to view the table 'page', you would need to add the following to LocalSettings.php:

$wgWikiDebug_ViewableTables[] = "page";

Example 1: SQL output

Providing the table 'page' is in the viewable tables array, then you can show its description by using the following syntax:

<describe_table table="page"></describe_table>

Live Table Definition: page

CREATE TABLE IF NOT EXISTS `page` (
  `page_id` int(8) unsigned NOT NULL auto_increment,
  `page_namespace` int(11) NOT NULL default '0',
  `page_title` varchar(255) NOT NULL default '',
  `page_restrictions` tinyblob NOT NULL,
  `page_counter` bigint(20) unsigned NOT NULL default '0',
  `page_is_redirect` tinyint(1) unsigned NOT NULL default '0',
  `page_is_new` tinyint(1) unsigned NOT NULL default '0',
  `page_random` double unsigned NOT NULL default '0',
  `page_touched` varchar(14) NOT NULL default '',
  `page_latest` int(8) unsigned NOT NULL default '0',
  `page_len` int(8) unsigned NOT NULL default '0',
  PRIMARY KEY  (`page_id`),
  UNIQUE KEY `name_title` (`page_namespace`,`page_title`),
  KEY `page_random` (`page_random`),
  KEY `page_len` (`page_len`)
) TYPE=MyISAM;

Example 2: Tabular description with indexes

<describe_table table="page" display="table"></describe_table>

Live Table Definition: page

FieldTypeNullKeyDefaultExtra
page_idint(8) unsigned PRI auto_increment
page_namespaceint(11) MUL0 
page_titlevarchar(255)    
page_restrictionstinyblob    
page_counterbigint(20) unsigned  0 
page_is_redirecttinyint(1) unsigned  0 
page_is_newtinyint(1) unsigned  0 
page_randomdouble unsigned MUL0 
page_touchedvarchar(14)    
page_latestint(8) unsigned  0 
page_lenint(8) unsigned MUL0 

Indexes

Non_uniqueKey_nameSeq_in_indexColumn_nameCollationCardinalitySub_partPackedNullIndex_typeComment
0PRIMARY1page_idA1518   BTREE 
0name_title1page_namespaceA11   BTREE 
0name_title2page_titleA1518   BTREE 
1page_random1page_randomA1518   BTREE 
1page_len1page_lenA253   BTREE 


Example 2: Tabular Description without indexes

<describe_table table="page" display="table" showindexes="false"></describe_table>

Live Table Definition: page

FieldTypeNullKeyDefaultExtra
page_idint(8) unsigned PRI auto_increment
page_namespaceint(11) MUL0 
page_titlevarchar(255)    
page_restrictionstinyblob    
page_counterbigint(20) unsigned  0 
page_is_redirecttinyint(1) unsigned  0 
page_is_newtinyint(1) unsigned  0 
page_randomdouble unsigned MUL0 
page_touchedvarchar(14)    
page_latestint(8) unsigned  0 
page_lenint(8) unsigned MUL0 


Example 3: Non-viewable table

If we try and look at a table that is not listed in the $wgWikiDebug_ViewableTables array we get the following:

Live Table Definition: user

Table cannot be viewed. It either does not exist, or is protected against viewing.
Personal tools