Last modified: 2014-06-23 16:07:17 UTC
This call produces errors when it attempts to run SELECT statements against missing tables. Ideally this call should be running SHOW TABLES to find the table. This will prevent errors and still return no results if the table is missing. Example change at Line 1651: $res = $this->query( "SHOW TABLES LIKE '$table'", $fname );
Why? Noting the current code explicitly ignores errors public function tableExists( $table, $fname = __METHOD__ ) { $table = $this->tableName( $table ); $old = $this->ignoreErrors( true ); $res = $this->query( "SELECT 1 FROM $table LIMIT 1", $fname ); $this->ignoreErrors( $old ); return (bool)$res; }
Any error monitoring PHP extensions, such as NewRelic, will still catch fatal exceptions and report them regardless if the code catches it.
I just finished testing this code against our development environment and made a few changes. The table tableName() call was removed since this is text search now and a fetchRow() is called since $res is always an object. function tableExists( $table, $fname = __METHOD__ ) { $old = $this->ignoreErrors( true ); $res = $this->query( "SHOW TABLES LIKE '$table'", $fname ); $row = $this->fetchRow($res); $this->ignoreErrors( $old ); return (bool)$row; }
The removal of tableName() would break installations with DB prefix.
(In reply to comment #4) > The removal of tableName() would break installations with DB prefix. You're absolutely right. I took it out since the identifier quotes broke the query. Adding the raw parameter with tableName() fixes that. Adding: $table = $this->tableName( $table, 'raw' ); function tableExists( $table, $fname = __METHOD__ ) { $table = $this->tableName( $table, 'raw' ); $old = $this->ignoreErrors( true ); $res = $this->query( "SHOW TABLES LIKE '$table'", $fname ); $row = $this->fetchRow($res); $this->ignoreErrors( $old ); return (bool)$row; }
Alexia: Any chance to turn this into a Gerrit patch? You are welcome to use Developer access https://www.mediawiki.org/wiki/Developer_access to submit this as a Git branch directly into Gerrit: https://www.mediawiki.org/wiki/Git/Tutorial Putting your branch in Git makes it easier to review it quickly.