Last modified: 2014-06-23 16:07:17 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T54294, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 52294 - Database tableExists() produces errors.
Database tableExists() produces errors.
Status: UNCONFIRMED
Product: MediaWiki
Classification: Unclassified
Database (Other open bugs)
1.21.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-07-30 20:10 UTC by Alexia E. Smith
Modified: 2014-06-23 16:07 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Alexia E. Smith 2013-07-30 20:10:31 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 );
Comment 1 Sam Reed (reedy) 2013-07-30 20:16:34 UTC
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;
	}
Comment 2 Alexia E. Smith 2013-07-30 20:20:32 UTC
Any error monitoring PHP extensions, such as NewRelic, will still catch fatal exceptions and report them regardless if the code catches it.
Comment 3 Alexia E. Smith 2013-07-30 21:21:15 UTC
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;
        }
Comment 4 Max Semenik 2013-07-30 21:31:47 UTC
The removal of tableName() would break installations with DB prefix.
Comment 5 Alexia E. Smith 2013-07-30 21:49:28 UTC
(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;
        }
Comment 6 Andre Klapper 2013-08-14 11:45:18 UTC
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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links