Extension:SQL2Wiki

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
SQL2Wiki

Release status: beta

Implementation Tag
Description Run a custom query on an external database.
Author(s) freakolowsky (old code by Patrick Müller)
Latest version 1.0 (30.05.11)
MediaWiki Works with 1.17
License No license specified
Download

Translate the SQL2Wiki extension if possible

Check usage and version matrix; code metrics

Warning Warning: This extension IS EXTREMELY DANGEROUS as it enables as it gives a user direct access to the database. USE EXTREME CAUTION when enabling this extension. User permissions must be handled on the database level. In most cases the connections to external databases should be read-only on table level.

What can this extension do?[edit | edit source]

This is a remake of an old extension that has been untouched for a while now, the old extension page has been copied to Extension:SQL2Wiki/old

This extension can run a custom query on an external database (not the database MW is running on). For databases supporting PLSQL (currently only supported for Oracle) this extension can also provide execution of an PLSQL anonymous block. Extension uses direct SQL calls so the queries have to be in the correct format for desired database.

Installation[edit | edit source]

  1. Download the files from SVN and place them in $IP/extensions/SQL2Wiki/
  2. Add
    require_once("$IP/extensions/SQL2Wiki/SQL2Wiki.php");
    into your wiki's LocalSettings.php
  3. Specify databases you want to access into
    $wgExSql2WikiDatabases["db1"] = array( "type"=> "oracle", "host" => "tnsname", "dbname" => "scott", "user" => "scott", "password" => "tiger");
    in your wiki's LocalSettings.php

Usage examples[edit | edit source]

  • Show data in a table

<sql2wiki database="db1"> select * from dual </sql2wiki>

  • Show data inline

<sql2wiki database="db1" inline="span"> select * from dual </sql2wiki>

    • if there is more than one column or row in the target table the data will be separated with line/field separator characters that can be defined as tag parameters
  • Execute PLSQL anonymous block (output can be returned trough DBMS_OUTPUT system)

<plsql2wiki database="db1"> BEGIN dbms_output.put_line('result!!'); END; </plsql2wiki>

Parameters[edit | edit source]

  • General parameters:
    • database = Database id (array key in $wgExSql2WikiDatabases array) (required)
    • inline = inline tag to wrap the results into. If this parameter is omitted the result will be displayed as table in case of sql2wiki or span tag in case of plsql2wiki
    • quiet = in case of error display nothing (true|false)
    • preexpand = recursive parse of input text before executing query (true|false)
    • expand = recursive parse of query result (true|false)
    • cache = handle page caching. In case of plsql or table display setting this parameter to "manual" will cause a refresh link to be placed under the displayed data (on|off|manual)
  • Inline parameters:
    • fieldseparator = character that separates fields in inline display (not displayed after last field)
    • lineseparator = character that separates rows in inline display (by default newlines are appended on rows)
  • Table parameters:
    • noheader = omit table header row (by default filled with column names) (true|false)
    • (table|hrow|hcell|row|cell)style = style attribute applied to table, header row, header cell, data row or data cell.

All other parameters passed to the tag will be appended to attributes of inline or table tag on output.

Changelog[edit | edit source]

1.0 - Remake release - 30.05.11 (the old extension page has been copied to Extension:SQL2Wiki/old)