Always decode Blob objects from Database::addQuotes
authorErik Bernhardson <ebernhardson@wikimedia.org>
Fri, 31 Oct 2014 20:16:54 +0000 (13:16 -0700)
committerEBernhardson <ebernhardson@wikimedia.org>
Mon, 2 Feb 2015 17:43:12 +0000 (17:43 +0000)
commit7fd481c77077ef3d2dc03ee40278e277f2a211e5
tree5696413fa2b27f9d991bfd400d32a0af56664146
parentb9d0f67cdff1387551faf24d9d58afc578a7283b
Always decode Blob objects from Database::addQuotes

The current API for Database::encodeBlob/Database::addQuotes requires
the code that is outputting binary data to have a database handle, so
that it may call Database::encodeBlob to get either a plain string or
a Blob object back. All database implementations other than MySQL
return a Blob object from Database::encodeBlob.

This is a rather inconvenient API, it tightly couples the creation of
binary data with the Database object unnecessarily.  If all database
objects accept a Blob via Database::addQuotes then code can simply
wrap its arguments in Blob and know that any database it ends up at
will be properly handled.

This patch changes the default implementation of Database::addQuotes
to recognize a Blob object was passed in, and use Blob::fetch to turn
it back into a string.  Database implementations other than MySQL all
handle this Blob object already.  The postgresql implementation had
to be adjusted slightly. Now when it sees a Blob object that it did
not create it will encode that appropriately.

Bug: 72367
Change-Id: I12fb4bd339be19137fffba2e47a70741382f6a8c
autoload.php
includes/db/Database.php
includes/db/DatabaseMssql.php
includes/db/DatabasePostgres.php