Page MenuHomePhabricator

sqlite: DatabaseBase::delete and DatabaseBase::update return ResultWrapper object
Closed, ResolvedPublic

Description

DatabaseBase::delete and DatabaseBase::update should always return a boolean, this is what the docs state and what appears to be happening when using MySQL. However, when using sqlite to run some of my tests (that run fine with MySQL), I'm getting some failures because I'm getting back a ResultWrapper object.

See failing test here: https://integration.mediawiki.org/ci/job/MediaWiki-Tests-Misc/1446/console


Version: 1.20.x
Severity: normal

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:25 AM
bzimport set Reference to bz37159.
bzimport added a subscriber: Unknown Object (MLST).

Installed sqlite and could reproduce locally.

Did some debugging, and found that the DB abstraction layer is riddled with inconsistencies in return types. Just have a look at DatabaseBase::doQuery and it's implementations in DatabaseMysql and DatabaseSqlite.

Krinkle subscribed.

Looks like this is still an issue indeed.

IDatabase::delete
	/*
	 * @return bool|IResultWrapper
	 * @throws DBError
	 */
	public function delete( $table, $conds, $fname = __METHOD__ );
IDatabase::query
	/*
	 * @return bool|IResultWrapper True for a successful write query, IResultWrapper object
	 *     for a successful read query, or false on failure if $tempIgnore set
	 * @throws DBError
	 */
	public function query( $sql, $fname = __METHOD__, $tempIgnore = false );
DatabaseMysqli::doQuery
	protected function doQuery( $sql ) {
		/* .. */ $ret = $conn->query( $sql );
		/* .. */ 

		return $ret;
	}

Where mysqli::query does the work for us, and returns true for successful non-read queries per https://secure.php.net/manual/en/mysqli.query.php.

DatabaseSqlite::doQuery
	protected function doQuery( $sql ) {
		$res = $this->getBindingHandle()->query( $sql );
		/* .. */
		$res = new ResultWrapper( $this, $r->fetchAll() );

		return $res;
	}

Here is the cause of the problem. PDO::query does have the return true feature that mysqli does, per https://secure.php.net/manual/en/pdo.query.php. Which means we need to write code to do that for write queries. Currently, the code currently returns ResultWrapper unconditionally for all successful queries.

Change 463640 had a related patch set uploaded (by 星耀晨曦; owner: 星耀晨曦):
[mediawiki/core@master] Coding to handle write queries

https://gerrit.wikimedia.org/r/463640

Change 463640 abandoned by 星耀晨曦:
Coding to handle write queries in sqlite implement

Reason:
Already fixed in https://gerrit.wikimedia.org/r/#/c/mediawiki/core/ /470071/.

https://gerrit.wikimedia.org/r/463640