$cond2 = $dbw->conditional( 'page_namespace=' . NS_FILE, 1, 'NULL' );
$result = $dbw->selectRow(
array( 'categorylinks', 'page' ),
- array( 'COUNT(*) AS pages',
- "COUNT($cond1) AS subcats",
- "COUNT($cond2) AS files"
+ array( 'pages' => 'COUNT(*)',
+ 'subcats' => "COUNT($cond1)",
+ 'files' => "COUNT($cond2)"
),
array( 'cl_to' => $this->mName, 'page_id = cl_from' ),
__METHOD__,
$options['ORDER BY'] = 'qc_value ASC';
}
$res = $dbr->select( 'querycache', array( 'qc_type',
- 'qc_namespace AS namespace',
- 'qc_title AS title',
- 'qc_value AS value' ),
+ 'namespace' => 'qc_namespace',
+ 'title' => 'qc_title',
+ 'value' => 'qc_value' ),
array( 'qc_type' => $this->getName() ),
__METHOD__, $options
);
* @return Integer
*/
static function countByPageId( $db, $id ) {
- $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
+ $row = $db->selectRow( 'revision', array( 'revCount' => 'COUNT(*)' ),
array( 'rev_page' => $id ), __METHOD__ );
if( $row ) {
return $row->revCount;
$tables = array( 'revision', 'user' );
$fields = array(
- 'rev_user as user_id',
- 'rev_user_text AS user_name',
+ 'user_id' => 'rev_user',
+ 'user_name' => 'rev_user_text',
$realNameField,
- 'MAX(rev_timestamp) AS timestamp',
+ 'timestamp' => 'MAX(rev_timestamp)',
);
$conds = array( 'rev_page' => $this->getId() );
'pp_page=page_id',
'pp_propname' => 'hiddencat' ) ),
) );
- $this->addFields( 'pp_propname AS cat_hidden' );
+ $this->addFields( array( 'cat_hidden' => 'pp_propname' ) );
}
$res = $this->select( __METHOD__ );
'INNER JOIN', 'rc_user_text=user_name'
) ) );
- $this->addFields( 'COUNT(*) AS recentedits' );
+ $this->addFields( array( 'recentedits' => 'COUNT(*)' ) );
$this->addWhere( 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes( 'newusers' ) );
$timestamp = $db->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 );
'pp_propname' => 'hiddencat' ) ),
) );
- $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'pp_propname AS cat_hidden' ) );
+ $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'cat_hidden' => 'pp_propname' ) );
$this->addWhere( array( 'cat_title' => $cattitles ) );
if ( !is_null( $params['continue'] ) ) {
$params = $this->extractRequestParams();
$this->addFields( array(
- $this->prefix . '_from AS pl_from',
- $this->prefix . '_namespace AS pl_namespace',
- $this->prefix . '_title AS pl_title'
+ 'pl_from' => $this->prefix . '_from',
+ 'pl_namespace' => $this->prefix . '_namespace',
+ 'pl_title' => $this->prefix . '_title'
) );
$this->addTables( $this->table );
$this->addTables( 'change_tag' );
$this->addFields( 'ct_tag' );
- $this->addFieldsIf( 'count(*) AS hitcount', $this->fld_hitcount );
+ $this->addFieldsIf( array( 'hitcount' => 'COUNT(*)' ), $this->fld_hitcount );
$this->addOption( 'LIMIT', $this->limit + 1 );
$this->addOption( 'GROUP BY', 'ct_tag' );
* @param $vars string|array
*
* May be either a field name or an array of field names. The field names
- * here are complete fragments of SQL, for direct inclusion into the SELECT
- * query. Expressions and aliases may be specified as in SQL, for example:
+ * can be complete fragments of SQL, for direct inclusion into the SELECT
+ * query. If an array is given, field aliases can be specified, for example:
*
- * array( 'MAX(rev_id) AS maxrev' )
+ * array( 'maxrev' => 'MAX(rev_id)' )
+ *
+ * This includes an expression with the alias "maxrev" in the query.
*
* If an expression is given, care must be taken to ensure that it is
* DBMS-independent.
$options = array(), $join_conds = array() )
{
if ( is_array( $vars ) ) {
- $vars = implode( ',', $vars );
+ $vars = implode( ',', $this->fieldNamesWithAlias( $vars ) );
}
$options = (array)$options;
$fname = 'DatabaseBase::estimateRowCount', $options = array() )
{
$rows = 0;
- $res = $this->select( $table, 'COUNT(*) AS rowcount', $conds, $fname, $options );
+ $res = $this->select( $table, array( 'rowcount' => 'COUNT(*)' ), $conds, $fname, $options );
if ( $res ) {
$row = $this->fetchRow( $res );
return $retval;
}
+ /**
+ * Get an aliased field name
+ * e.g. fieldName AS newFieldName
+ *
+ * @param $name string Field name
+ * @param $alias string|bool Alias (optional)
+ * @return string SQL name for aliased field. Will not alias a field to its own name
+ */
+ public function fieldNameWithAlias( $name, $alias = false ) {
+ if ( !$alias || (string)$alias === (string)$name ) {
+ return $name;
+ } else {
+ return $name . ' AS ' . $alias; //PostgreSQL needs AS
+ }
+ }
+
+ /**
+ * Gets an array of aliased field names
+ *
+ * @param $fields array( [alias] => field )
+ * @return array of strings, see fieldNameWithAlias()
+ */
+ public function fieldNamesWithAlias( $fields ) {
+ $retval = array();
+ foreach ( $fields as $alias => $field ) {
+ if ( is_numeric( $alias ) ) {
+ $alias = $field;
+ }
+ $retval[] = $this->fieldNameWithAlias( $field, $alias );
+ }
+ return $retval;
+ }
+
/**
* Get the aliased table name clause for a FROM clause
* which might have a JOIN and/or USE INDEX clause
*/
public function count( array $conditions = array(), array $options = array() ) {
$res = $this->rawSelectRow(
- array( 'COUNT(*) AS rowcount' ),
+ array( 'rowcount' => 'COUNT(*)' ),
$this->getPrefixedValues( $conditions ),
$options
);
if ( !$affected ) {
// Failed, someone else beat us to it
// Try getting a random row
- $row = $dbw->selectRow( 'job', array( 'MIN(job_id) as minjob',
- 'MAX(job_id) as maxjob' ), '1=1', __METHOD__ );
+ $row = $dbw->selectRow( 'job', array( 'minjob' => 'MIN(job_id)',
+ 'maxjob' => 'MAX(job_id)' ), '1=1', __METHOD__ );
if ( $row === false || is_null( $row->minjob ) || is_null( $row->maxjob ) ) {
// No jobs to get
wfProfileOut( __METHOD__ );
$query = array(
'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
- 'fields' => array( 'rc_user_text AS user_name', // inheritance
+ 'fields' => array( 'user_name' => 'rc_user_text', // inheritance
'rc_user_text', // for Pager
'user_id',
- 'COUNT(*) AS recentedits',
- 'MAX(ipb_user) AS blocked'
+ 'recentedits' => 'COUNT(*)',
+ 'blocked' => 'MAX(ipb_user)'
),
'options' => array(
'GROUP BY' => array( 'rc_user_text', 'user_id' ),
function getQueryInfo() {
return array(
'tables' => array( 'page', 'revision' ),
- 'fields' => array( 'page_namespace AS namespace',
- 'page_title AS title',
- 'rev_timestamp AS value' ),
+ 'fields' => array( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'rev_timestamp' ),
'conds' => array( 'page_namespace' => MWNamespace::getContentNamespaces(),
'page_is_redirect' => 0,
'page_latest=rev_id' )
'ipb_user',
'ipb_by',
'ipb_by_text',
- 'user_name AS by_user_name',
+ 'by_user_name' => 'user_name',
'ipb_reason',
'ipb_timestamp',
'ipb_auto',
return array(
'tables' => array( 'redirect', 'p1' => 'page',
'p2' => 'page' ),
- 'fields' => array( 'p1.page_namespace AS namespace',
- 'p1.page_title AS title',
- 'p1.page_title AS value',
+ 'fields' => array( 'namespace' => 'p1.page_namespace',
+ 'title' => 'p1.page_title',
+ 'value' => 'p1.page_title',
'rd_namespace',
'rd_title'
),
function getQueryInfo() {
return array(
'tables' => array( 'page', 'pagelinks' ),
- 'fields' => array( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value'
+ 'fields' => array( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title'
),
'conds' => array( 'pl_from IS NULL',
'page_namespace' => MWNamespace::getContentNamespaces(),
'p2' => 'page'
),
'fields' => array(
- 'p1.page_namespace AS namespace',
- 'p1.page_title AS title',
- 'pl_from AS value'
+ 'namespace' => 'p1.page_namespace',
+ 'title' => 'p1.page_title',
+ 'value' => 'pl_from'
),
'conds' => array(
$this->getQueryFromLinkBatch(),
'tables' => array ( 'ra' => 'redirect',
'rb' => 'redirect', 'pa' => 'page',
'pb' => 'page', 'pc' => 'page' ),
- 'fields' => array ( 'pa.page_namespace AS namespace',
- 'pa.page_title AS title',
- 'pa.page_title AS value',
- 'pb.page_namespace AS nsb',
- 'pb.page_title AS tb',
- 'pc.page_namespace AS nsc',
- 'pc.page_title AS tc' ),
+ 'fields' => array ( 'namespace' => 'pa.page_namespace',
+ 'title' => 'pa.page_title',
+ 'value' => 'pa.page_title',
+ 'nsb' => 'pb.page_namespace',
+ 'tb' => 'pb.page_title',
+ 'nsc' => 'pc.page_namespace',
+ 'tc' => 'pc.page_title' ),
'conds' => array ( 'ra.rd_from = pa.page_id',
'pb.page_namespace = ra.rd_namespace',
'pb.page_title = ra.rd_title',
private function getTemplates( $inputPages, $pageSet ) {
return $this->getLinks( $inputPages, $pageSet,
'templatelinks',
- array( 'tl_namespace AS namespace', 'tl_title AS title' ),
+ array( 'namespace' => 'tl_namespace', 'title' => 'tl_title' ),
array( 'page_id=tl_from' )
);
}
for( ; $depth > 0; --$depth ) {
$pageSet = $this->getLinks(
$inputPages, $pageSet, 'pagelinks',
- array( 'pl_namespace AS namespace', 'pl_title AS title' ),
+ array( 'namespace' => 'pl_namespace', 'title' => 'pl_title' ),
array( 'page_id=pl_from' )
);
$inputPages = array_keys( $pageSet );
$inputPages,
$pageSet,
'imagelinks',
- array( NS_FILE . ' AS namespace', 'il_to AS title' ),
+ array( 'namespace' => NS_FILE, 'title' => 'il_to' ),
array( 'page_id=il_from' )
);
}
function getQueryInfo() {
return array (
'tables' => array ( 'revision', 'page' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'COUNT(*) AS value',
- 'page_is_redirect AS redirect' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'COUNT(*)',
+ 'redirect' => 'page_is_redirect' ),
'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces(),
'page_id = rev_page' ),
'options' => array ( 'HAVING' => 'COUNT(*) > 1',
return array(
'tables' => array( 'image' ),
'fields' => array(
- 'img_name AS title',
- 'img_sha1 AS value',
+ 'title' => 'img_name',
+ 'value' => 'img_sha1',
'img_user_text',
'img_timestamp'
),
$like = $dbr->buildLike( $stripped );
$retval = array (
'tables' => array ( 'page', 'externallinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'el_index AS value', 'el_to AS url' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'el_index', 'url' => 'el_to' ),
'conds' => array ( 'page_id = el_from',
"$clause $like" ),
'options' => array( 'USE INDEX' => $clause )
function getQueryInfo() {
return array(
'tables' => array( 'p1' => 'page', 'redirect', 'p2' => 'page' ),
- 'fields' => array( 'p1.page_namespace AS namespace',
- 'p1.page_title AS title',
- 'p1.page_title AS value',
+ 'fields' => array( 'namespace' => 'p1.page_namespace',
+ 'title' => 'p1.page_title',
+ 'value' => 'p1.page_title',
'rd_namespace',
'rd_title',
'rd_fragment',
'rd_interwiki',
- 'p2.page_id AS redirid' ),
+ 'redirid' => 'p2.page_id' ),
'conds' => array( 'p1.page_is_redirect' => 1 ),
'join_conds' => array( 'redirect' => array(
'LEFT JOIN', 'rd_from=p1.page_id' ),
return array (
'tables' => array ( 'page', 'pagelinks',
'templatelinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
'conds' => array ( 'pl_namespace IS NULL',
'page_namespace' => MWNamespace::getContentNamespaces(),
'page_is_redirect' => 0,
public function getQueryInfo() {
return array(
'tables' => array( 'image' ),
- 'fields' => array( "'" . NS_FILE . "' AS namespace",
- 'img_name AS title',
- 'img_major_mime AS value',
+ 'fields' => array( 'namespace' => NS_FILE,
+ 'title' => 'img_name',
+ 'value' => 'img_major_mime',
'img_size',
'img_width',
'img_height',
function getQueryInfo() {
return array (
'tables' => array ( 'categorylinks', 'page' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'COUNT(*)' ),
'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces() ),
'options' => array ( 'HAVING' => 'COUNT(*) > 1',
'GROUP BY' => array( 'page_namespace', 'page_title' ) ),
function getQueryInfo() {
return array (
'tables' => array ( 'imagelinks' ),
- 'fields' => array ( "'" . NS_FILE . "' AS namespace",
- 'il_to AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => NS_FILE,
+ 'title' => 'il_to',
+ 'value' => 'COUNT(*)' ),
'options' => array ( 'GROUP BY' => 'il_to',
'HAVING' => 'COUNT(*) > 1' )
);
function getQueryInfo() {
return array (
'tables' => array ( 'pagelinks', 'page' ),
- 'fields' => array ( 'pl_namespace AS namespace',
- 'pl_title AS title',
- 'COUNT(*) AS value',
+ 'fields' => array ( 'namespace' => 'pl_namespace',
+ 'title' => 'pl_title',
+ 'value' => 'COUNT(*)',
'page_namespace' ),
'options' => array ( 'HAVING' => 'COUNT(*) > 1',
'GROUP BY' => array( 'pl_namespace', 'pl_title',
function getQueryInfo() {
return array (
'tables' => array ( 'category' ),
- 'fields' => array ( 'cat_title AS title',
- NS_CATEGORY . ' AS namespace',
- 'cat_pages AS value' ),
+ 'fields' => array ( 'title' => 'cat_title',
+ 'namespace' => NS_CATEGORY,
+ 'value' => 'cat_pages' ),
);
}
public function getQueryInfo() {
return array (
'tables' => array ( 'templatelinks' ),
- 'fields' => array ( 'tl_namespace AS namespace',
- 'tl_title AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => 'tl_namespace',
+ 'title' => 'tl_title',
+ 'value' => 'COUNT(*)' ),
'conds' => array ( 'tl_namespace' => NS_TEMPLATE ),
'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) )
);
$fields = array(
'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text',
'rc_comment', 'rc_timestamp', 'rc_patrolled','rc_id', 'rc_deleted',
- 'page_len AS length', 'page_latest AS rev_id', 'ts_tags', 'rc_this_oldid',
+ 'length' => 'page_len', 'rev_id' => 'page_latest', 'ts_tags', 'rc_this_oldid',
'page_namespace', 'page_title'
);
$join_conds = array( 'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ) );
function getQueryInfo() {
return array (
'tables' => array( 'page' ),
- 'fields' => array( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_counter AS value'),
+ 'fields' => array( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_counter'),
'conds' => array( 'page_is_redirect' => 0,
'page_namespace' => MWNamespace::getContentNamespaces() ) );
}
function getQueryInfo() {
return array (
'tables' => array ( 'page' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_len AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_len' ),
'conds' => array ( 'page_namespace' =>
MWNamespace::getContentNamespaces(),
'page_is_redirect' => 0 ),
Xml::tags( 'th', null, $this->msg( 'tags-hitcount-header' )->parse() )
);
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) AS hitcount' ),
+ $res = $dbr->select( 'change_tag', array( 'ct_tag', 'hitcount' => 'count(*)' ),
array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) );
foreach ( $res as $row ) {
function getQueryInfo() {
return array (
'tables' => array( 'page', 'categorylinks' ),
- 'fields' => array( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
'conds' => array( 'cl_from IS NULL',
'page_namespace' => NS_FILE,
'page_is_redirect' => 0 ),
function getQueryInfo() {
return array (
'tables' => array ( 'page', 'categorylinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
// default for page_namespace is all content namespaces (if requestedNamespace is false)
// otherwise, page_namespace is requestedNamespace
'conds' => array ( 'cl_from IS NULL',
array(
'ar_namespace',
'ar_title',
- 'COUNT(*) AS count'
+ 'count' => 'COUNT(*)'
),
$condition,
__METHOD__,
function getQueryInfo() {
return array (
'tables' => array ( 'page', 'categorylinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
'conds' => array ( 'cl_from IS NULL',
'page_namespace' => NS_CATEGORY,
'page_is_redirect' => 0 ),
global $wgCountCategorizedImagesAsUsed;
$retval = array (
'tables' => array ( 'image', 'imagelinks' ),
- 'fields' => array ( "'" . NS_FILE . "' AS namespace",
- 'img_name AS title',
- 'img_timestamp AS value',
+ 'fields' => array ( 'namespace' => NS_FILE,
+ 'title' => 'img_name',
+ 'value' => 'img_timestamp',
'img_user', 'img_user_text',
'img_description' ),
'conds' => array ( 'il_to IS NULL' ),
function getQueryInfo() {
return array (
'tables' => array ( 'page', 'templatelinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
'conds' => array ( 'page_namespace' => NS_TEMPLATE,
'tl_from IS NULL',
'page_is_redirect' => 0 ),
function getQueryInfo() {
return array (
'tables' => array ( 'page', 'watchlist' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_namespace AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_namespace' ),
'conds' => array ( 'wl_title IS NULL',
'page_is_redirect' => 0,
"page_namespace != '" . NS_MEDIAWIKI .
function getQueryInfo() {
return array (
'tables' => array ( 'categorylinks', 'page' ),
- 'fields' => array ( "'" . NS_CATEGORY . "' AS namespace",
- 'cl_to AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => NS_CATEGORY,
+ 'title' => 'cl_to',
+ 'value' => 'COUNT(*)' ),
'conds' => array ( 'page_title IS NULL' ),
'options' => array ( 'GROUP BY' => 'cl_to' ),
'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
function getQueryInfo() {
return array (
'tables' => array ( 'imagelinks', 'image' ),
- 'fields' => array ( "'" . NS_FILE . "' AS namespace",
- 'il_to AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => NS_FILE,
+ 'title' => 'il_to',
+ 'value' => 'COUNT(*)' ),
'conds' => array ( 'img_name IS NULL' ),
'options' => array ( 'GROUP BY' => 'il_to' ),
'join_conds' => array ( 'image' =>
'pg2' => 'page'
),
'fields' => array(
- 'pl_namespace AS namespace',
- 'pl_title AS title',
- 'COUNT(*) AS value'
+ 'namespace' => 'pl_namespace',
+ 'title' => 'pl_title',
+ 'value' => 'COUNT(*)'
),
'conds' => array(
'pg1.page_namespace IS NULL',
function getQueryInfo() {
return array (
'tables' => array ( 'templatelinks', 'page' ),
- 'fields' => array ( 'tl_namespace AS namespace',
- 'tl_title AS title',
- 'COUNT(*) AS value' ),
+ 'fields' => array ( 'namespace' => 'tl_namespace',
+ 'title' => 'tl_title',
+ 'value' => 'COUNT(*)' ),
'conds' => array ( 'page_title IS NULL',
'tl_namespace' => NS_TEMPLATE ),
'options' => array (
$dbr = wfGetDB( DB_SLAVE, 'watchlist' );
# Fetch the raw count
- $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
+ $res = $dbr->select( 'watchlist', array( 'count' => 'COUNT(*)' ),
array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );
$row = $dbr->fetchObject( $res );
$count = $row->count;
function getQueryInfo() {
$query = array (
'tables' => array ( 'page', 'langlinks' ),
- 'fields' => array ( 'page_namespace AS namespace',
- 'page_title AS title',
- 'page_title AS value' ),
+ 'fields' => array ( 'namespace' => 'page_namespace',
+ 'title' => 'page_title',
+ 'value' => 'page_title' ),
'conds' => array ( 'll_title IS NULL',
'page_namespace' => MWNamespace::getContentNamespaces(),
'page_is_redirect' => 0 ),
--- /dev/null
+<?php
+
+/**
+ * Test the abstract database layer
+ * Using Mysql for the sql at the moment TODO
+ *
+ * @group Database
+ */
+class DatabaseSQLTest extends MediaWikiTestCase {
+
+ public function setUp() {
+ // TODO support other DBMS or find another way to do it
+ if( $this->db->getType() !== 'mysql' ) {
+ $this->markTestSkipped( 'No mysql database' );
+ }
+ }
+
+ /**
+ * @dataProvider dataSQL
+ */
+ function testSQL( $sql, $sqlText ) {
+ $this->assertEquals( trim( $this->db->selectSQLText(
+ isset( $sql['tables'] ) ? $sql['tables'] : array(),
+ isset( $sql['fields'] ) ? $sql['fields'] : array(),
+ isset( $sql['conds'] ) ? $sql['conds'] : array(),
+ __METHOD__,
+ isset( $sql['options'] ) ? $sql['options'] : array(),
+ isset( $sql['join_conds'] ) ? $sql['join_conds'] : array()
+ ) ), $sqlText );
+ }
+
+ function dataSQL() {
+ return array(
+ array(
+ array(
+ 'tables' => 'table',
+ 'fields' => array( 'field', 'alias' => 'field2' ),
+ 'conds' => array( 'alias' => 'text' ),
+ ),
+ "SELECT field,field2 AS alias " .
+ "FROM `unittest_table` " .
+ "WHERE alias = 'text'"
+ ),
+ array(
+ array(
+ 'tables' => 'table',
+ 'fields' => array( 'field', 'alias' => 'field2' ),
+ 'conds' => array( 'alias' => 'text' ),
+ 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ),
+ ),
+ "SELECT field,field2 AS alias " .
+ "FROM `unittest_table` " .
+ "WHERE alias = 'text' " .
+ "ORDER BY field " .
+ "LIMIT 1"
+ ),
+ array(
+ array(
+ 'tables' => array( 'table', 't2' => 'table2' ),
+ 'fields' => array( 'tid', 'field', 'alias' => 'field2', 't2.id' ),
+ 'conds' => array( 'alias' => 'text' ),
+ 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ),
+ 'join_conds' => array( 't2' => array(
+ 'LEFT JOIN', 'tid = t2.id'
+ )),
+ ),
+ "SELECT tid,field,field2 AS alias,t2.id " .
+ "FROM `unittest_table` LEFT JOIN `unittest_table2` `t2` ON ((tid = t2.id)) " .
+ "WHERE alias = 'text' " .
+ "ORDER BY field " .
+ "LIMIT 1"
+ ),
+ );
+ }
+}
\ No newline at end of file