Page MenuHomePhabricator

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


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:

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 added a subscriber: Krinkle.

Looks like this is still an issue indeed.

	 * @return bool|IResultWrapper
	 * @throws DBError
	public function delete( $table, $conds, $fname = __METHOD__ );
	 * @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 );
	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

	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 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

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

Already fixed in /470071/.