r80856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80855‎ | r80856 | r80857 >
Date:13:59, 24 January 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Start another attack on raw sql queries
Modified paths:
  • /trunk/phase3/includes/search/SearchMySQL.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/search/SearchMySQL.php
@@ -196,7 +196,7 @@
197197 if( $this->showRedirects ) {
198198 return '';
199199 } else {
200 - return 'AND page_is_redirect=0';
 200+ return 'page_is_redirect=0';
201201 }
202202 }
203203
@@ -212,7 +212,7 @@
213213 } else {
214214 $namespaces = $this->db->makeList( $this->namespaces );
215215 }
216 - return 'AND page_namespace IN (' . $namespaces . ')';
 216+ return 'page_namespace IN (' . $namespaces . ')';
217217 }
218218
219219 /**
@@ -240,8 +240,8 @@
241241 */
242242 function getQuery( $filteredTerm, $fulltext ) {
243243 return $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
244 - $this->queryRedirect() . ' ' .
245 - $this->queryNamespaces() . ' ' .
 244+ 'AND ' . $this->queryRedirect() . ' ' .
 245+ 'AND ' . $this->queryNamespaces() . ' ' .
246246 $this->queryRanking( $filteredTerm, $fulltext ) . ' ' .
247247 $this->queryLimit();
248248 }
@@ -276,13 +276,15 @@
277277
278278 function getCountQuery( $filteredTerm, $fulltext ) {
279279 $match = $this->parseQuery( $filteredTerm, $fulltext );
280 - $page = $this->db->tableName( 'page' );
281 - $searchindex = $this->db->tableName( 'searchindex' );
282 - return "SELECT COUNT(*) AS c " .
283 - "FROM $page,$searchindex " .
284 - 'WHERE page_id=si_page AND ' . $match .
285 - $this->queryRedirect() . ' ' .
286 - $this->queryNamespaces();
 280+
 281+ return $this->db->selectSQLText( array( 'page', 'searchindex' ),
 282+ 'COUNT(*) AS c',
 283+ array(
 284+ 'page_id=si_page',
 285+ $match,
 286+ $this->queryRedirect(),
 287+ $this->queryNamespaces()
 288+ ) );
287289 }
288290
289291 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r80861Fixup usage of raw sql in Title...reedy15:30, 24 January 2011
r80982Followup r80856, don't unconditionally add the "AND" as if '' is returned by ...reedy19:56, 25 January 2011
r86595Fixed SearchMySQL broken by r80856maxsem05:43, 21 April 2011

Comments

#Comment by Nikerabbit (talk | contribs)   16:58, 25 January 2011

[25-Jan-2011 16:36:11] /w/i.php?title=Special%3ASearch&redirs=0&search=Existing+wiki&fulltext=Search&ns8=0&title=Special%3ASearch&advanced=1&fulltext=Advanced+search: DB error: A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script Query: SELECT page_id, page_namespace, page_title FROM `bw_page`,`bw_searchindex` WHERE page_id=si_page AND MATCH(si_title) AGAINST('+existing +wiki ' IN BOOLEAN MODE) AND AND page_namespace IN ('8') LIMIT 20 Function: Error: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND page_namespace IN ('8') LIMIT 20' at line 1 (localhost)

#Comment by Catrope (talk | contribs)   18:59, 25 January 2011

Clarification: the error is due to the 'AND AND' part.

#Comment by Brion VIBBER (talk | contribs)   20:06, 25 January 2011

Was reported as bugzilla:26940; fixed by r80982

#Comment by Reedy (talk | contribs)   19:58, 25 January 2011

Resolved now, cheers

Status & tagging log