r66925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66924‎ | r66925 | r66926 >
Date:15:42, 26 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Code/doc/style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -127,7 +127,7 @@
128128 $this->m_dbs->delete( 'smw_conccache', array( 'o_id' => $cid ), 'SMW::refreshConceptCache' );
129129
130130 if ( $wgDBtype == 'postgres' ) { // PostgresQL: no INSERT IGNORE, check for duplicates explicitly
131 - $where = $qobj->where . ( $qobj->where ? ' AND ':'' ) .
 131+ $where = $qobj->where . ( $qobj->where ? ' AND ' : '' ) .
132132 'NOT EXISTS (SELECT NULL FROM ' . $this->m_dbs->tableName( 'smw_conccache' ) .
133133 ' WHERE ' . $this->m_dbs->tablename( 'smw_conccache' ) . '.s_id = ' . $qobj->alias . '.s_id ' .
134134 ' AND ' . $this->m_dbs->tablename( 'smw_conccache' ) . '.o_id = ' . $qobj->alias . '.o_id )';
@@ -135,10 +135,10 @@
136136 $where = $qobj->where;
137137 }
138138
139 - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "":"IGNORE " ) . "INTO " . $this->m_dbs->tableName( 'smw_conccache' ) .
 139+ $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( 'smw_conccache' ) .
140140 " SELECT DISTINCT $qobj->joinfield AS s_id, $cid AS o_id FROM " .
141141 $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from .
142 - ( $where ? " WHERE ":'' ) . $where . " LIMIT $smwgQMaxLimit",
 142+ ( $where ? ' WHERE ' : '' ) . $where . " LIMIT $smwgQMaxLimit",
143143 'SMW::refreshConceptCache' );
144144
145145 $this->m_dbs->update( 'smw_conc2', array( 'cache_date' => strtotime( "now" ), 'cache_count' => $this->m_dbs->affectedRows() ), array( 's_id' => $cid ), 'SMW::refreshConceptCache' );
@@ -289,7 +289,7 @@
290290 $result .= 'SQL query<br />' .
291291 "<tt>SELECT DISTINCT $qobj->alias.smw_title AS t,$qobj->alias.smw_namespace AS ns FROM " .
292292 $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from .
293 - ( ( $qobj->where == '' ) ? '':' WHERE ' ) . $qobj->where . "$tailOpts LIMIT " .
 293+ ( ( $qobj->where == '' ) ? '' : ' WHERE ' ) . $qobj->where . "$tailOpts LIMIT " .
294294 $sql_options['LIMIT'] . ' OFFSET ' . $sql_options['OFFSET'] . ';</tt>';
295295 } else {
296296 $result .= '<b>Empty result, no SQL query created.</b>';
@@ -809,14 +809,14 @@
810810 $condition = '';
811811
812812 foreach ( $subquery->joinfield as $value ) {
813 - $condition .= ( $condition ? ' OR ':'' ) . "$joinfield=" . $this->m_dbs->addQuotes( $value );
 813+ $condition .= ( $condition ? ' OR ' : '' ) . "$joinfield=" . $this->m_dbs->addQuotes( $value );
814814 }
815815
816816 if ( count( $subquery->joinfield ) > 1 ) {
817817 $condition = "($condition)";
818818 }
819819
820 - $query->where .= ( ( $query->where == '' ) ? '':' AND ' ) . $condition;
 820+ $query->where .= ( ( $query->where == '' ) ? '' : ' AND ' ) . $condition;
821821 } else { // interpret empty joinfields as impossible condition (empty result)
822822 $query->joinfield = ''; // make whole query false
823823 $query->jointable = '';
@@ -826,7 +826,7 @@
827827 }
828828
829829 if ( $subquery->where != '' ) {
830 - $query->where .= ( ( $query->where == '' ) ? '':' AND ' ) . '(' . $subquery->where . ')';
 830+ $query->where .= ( ( $query->where == '' ) ? '' : ' AND ' ) . '(' . $subquery->where . ')';
831831 }
832832
833833 $query->from .= $subquery->from;
@@ -887,10 +887,10 @@
888888 $sql = '';
889889
890890 if ( $subquery->jointable != '' ) {
891 - $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '':'IGNORE ' ) . 'INTO ' .
 891+ $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' .
892892 $this->m_dbs->tableName( $query->alias ) .
893893 " SELECT $subquery->joinfield FROM " . $this->m_dbs->tableName( $subquery->jointable ) .
894 - " AS $subquery->alias $subquery->from" . ( $subquery->where ? " WHERE $subquery->where":'' );
 894+ " AS $subquery->alias $subquery->from" . ( $subquery->where ? " WHERE $subquery->where" : '' );
895895 } elseif ( $subquery->joinfield !== '' ) {
896896 // NOTE: this works only for single "unconditional" values without further
897897 // WHERE or FROM. The execution must take care of not creating any others.
@@ -900,7 +900,7 @@
901901 $values .= ( $values ? ',' : '' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')';
902902 }
903903
904 - $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '':'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( $query->alias ) . " (id) VALUES $values";
 904+ $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( $query->alias ) . " (id) VALUES $values";
905905 } // else: // interpret empty joinfields as impossible condition (empty result), ignore
906906 if ( $sql ) {
907907 $this->m_querylog[$query->alias][] = $sql;
@@ -948,11 +948,11 @@
949949 $valuecond = '';
950950
951951 foreach ( $query->joinfield as $value ) {
952 - $values .= ( $values ? ',':'' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')';
953 - $valuecond .= ( $valuecond ? ' OR ':'' ) . 'o_id=' . $this->m_dbs->addQuotes( $value );
 952+ $values .= ( $values ? ',' : '' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')';
 953+ $valuecond .= ( $valuecond ? ' OR ' : '' ) . 'o_id=' . $this->m_dbs->addQuotes( $value );
954954 }
955955
956 - $smwtable = $this->m_dbs->tableName( ( $query->type == SMW_SQL2_PROP_HIERARCHY ) ? 'smw_subp2':'smw_subs2' );
 956+ $smwtable = $this->m_dbs->tableName( ( $query->type == SMW_SQL2_PROP_HIERARCHY ) ? 'smw_subp2' : 'smw_subs2' );
957957
958958 // Try to safe time (SELECT is cheaper than creating/dropping 3 temp tables):
959959 $res = $this->m_dbs->select( $smwtable, 's_id', $valuecond, array( 'LIMIT' => 1 ) );
@@ -991,19 +991,21 @@
992992 // obtained in the previous step are relevant. So this is a performance measure.
993993 $tmpnew = 'smw_new';
994994 $tmpres = 'smw_res';
 995+
995996 $this->m_dbs->query( $this->getCreateTempIDTableSQL( $tmpnew ), 'SMW::executeQueries' );
996997 $this->m_dbs->query( $this->getCreateTempIDTableSQL( $tmpres ), 'SMW::executeQueries' );
997 - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "" : "IGNORE" ) . " INTO $tablename (id) VALUES $values", 'SMW::executeHierarchyQuery' );
998 - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "" : "IGNORE" ) . " INTO $tmpnew (id) VALUES $values", 'SMW::executeHierarchyQuery' );
 998+
 999+ $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : "IGNORE" ) . " INTO $tablename (id) VALUES $values", 'SMW::executeHierarchyQuery' );
 1000+ $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : "IGNORE" ) . " INTO $tmpnew (id) VALUES $values", 'SMW::executeHierarchyQuery' );
9991001
10001002 for ( $i = 0; $i < $depth; $i++ ) {
1001 - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tmpres (id) SELECT s_id" . ( $wgDBtype == 'postgres' ? '::integer':'' ) . " FROM $smwtable, $tmpnew WHERE o_id=id",
 1003+ $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tmpres (id) SELECT s_id" . ( $wgDBtype == 'postgres' ? '::integer' : '' ) . " FROM $smwtable, $tmpnew WHERE o_id=id",
10021004 'SMW::executeHierarchyQuery' );
10031005 if ( $this->m_dbs->affectedRows() == 0 ) { // no change, exit loop
10041006 break;
10051007 }
10061008
1007 - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tablename (id) SELECT $tmpres.id FROM $tmpres",
 1009+ $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tablename (id) SELECT $tmpres.id FROM $tmpres",
10081010 'SMW::executeHierarchyQuery' );
10091011
10101012 if ( $this->m_dbs->affectedRows() == 0 ) { // no change, exit loop
@@ -1032,6 +1034,7 @@
10331035 */
10341036 protected function applyOrderConditions( $qid ) {
10351037 $qobj = $this->m_queries[$qid];
 1038+
10361039 // (1) collect required extra property descriptions:
10371040 $extraproperties = array();
10381041
@@ -1098,9 +1101,10 @@
10991102 */
11001103 protected function cleanUp() {
11011104 global $wgDBtype;
 1105+
11021106 if ( $this->m_qmode !== SMWQuery::MODE_DEBUG ) {
11031107 foreach ( $this->m_querylog as $table => $log ) {
1104 - $this->m_dbs->query( ( ( $wgDBtype == 'postgres' ) ? "DROP TABLE IF EXISTS ":"DROP TEMPORARY TABLE " ) . $this->m_dbs->tableName( $table ), 'SMW::getQueryResult' );
 1108+ $this->m_dbs->query( ( ( $wgDBtype == 'postgres' ) ? 'DROP TABLE IF EXISTS ' : 'DROP TEMPORARY TABLE ' ) . $this->m_dbs->tableName( $table ), 'SMW::getQueryResult' );
11051109 }
11061110 }
11071111 }

Status & tagging log