3 * @defgroup Database Database
5 * This file deals with database interface functions
6 * and query specifics/optimisations.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
28 * Database abstraction object
31 abstract class DatabaseBase
extends Database
{
33 * Boolean, controls output of large amounts of debug information.
34 * @param bool|null $debug
35 * - true to enable debugging
36 * - false to disable debugging
37 * - omitted or null to do nothing
39 * @return bool Previous value of the flag
40 * @deprecated since 1.28; use setFlag()
42 public function debug( $debug = null ) {
43 $res = $this->getFlag( DBO_DEBUG
);
44 if ( $debug !== null ) {
45 $debug ?
$this->setFlag( DBO_DEBUG
) : $this->clearFlag( DBO_DEBUG
);
52 * @return string Command delimiter used by this database engine
54 public function getDelimiter() {
55 return $this->delimiter
;
59 * Returns true if this database supports (and uses) cascading deletes
63 public function cascadingDeletes() {
67 * Returns true if this database supports (and uses) triggers (e.g. on the page table)
71 public function cleanupTriggers() {
75 * Returns true if this database is strict about what can be put into an IP field.
76 * Specifically, it uses a NULL value instead of an empty string.
80 public function strictIPs() {
85 * Returns true if this database can do a native search on IP columns
86 * e.g. this works as expected: .. WHERE rc_ip = '127.42.12.102/32';
90 public function searchableIPs() {
95 * Returns true if this database uses timestamps rather than integers
99 public function realTimestamps() {
104 * Returns true if this database can use functional indexes
108 public function functionalIndexes() {
113 * Intended to be compatible with the PEAR::DB wrapper functions.
114 * http://pear.php.net/manual/en/package.database.db.intro-execute.php
116 * ? = scalar value, quoted as necessary
117 * ! = raw SQL bit (a function for instance)
118 * & = filename; reads the file and inserts as a blob
119 * (we don't use this though...)
122 * @param string $func
126 protected function prepare( $sql, $func = __METHOD__
) {
127 /* MySQL doesn't support prepared statements (yet), so just
128 * pack up the query for reference. We'll manually replace
131 return [ 'query' => $sql, 'func' => $func ];
135 * Free a prepared query, generated by prepare().
136 * @param string $prepared
138 protected function freePrepared( $prepared ) {
139 /* No-op by default */
143 * Execute a prepared query with the various arguments
144 * @param string $prepared The prepared sql
145 * @param mixed $args Either an array here, or put scalars as varargs
147 * @return ResultWrapper
149 public function execute( $prepared, $args = null ) {
150 if ( !is_array( $args ) ) {
152 $args = func_get_args();
153 array_shift( $args );
156 $sql = $this->fillPrepared( $prepared['query'], $args );
158 return $this->query( $sql, $prepared['func'] );
162 * For faking prepared SQL statements on DBs that don't support it directly.
164 * @param string $preparedQuery A 'preparable' SQL statement
165 * @param array $args Array of Arguments to fill it with
166 * @return string Executable SQL
168 public function fillPrepared( $preparedQuery, $args ) {
170 $this->preparedArgs
=& $args;
172 return preg_replace_callback( '/(\\\\[?!&]|[?!&])/',
173 [ &$this, 'fillPreparedArg' ], $preparedQuery );
177 * preg_callback func for fillPrepared()
178 * The arguments should be in $this->preparedArgs and must not be touched
179 * while we're doing this.
181 * @param array $matches
182 * @throws DBUnexpectedError
185 protected function fillPreparedArg( $matches ) {
186 switch ( $matches[1] ) {
195 list( /* $n */, $arg ) = each( $this->preparedArgs
);
197 switch ( $matches[1] ) {
199 return $this->addQuotes( $arg );
203 # return $this->addQuotes( file_get_contents( $arg ) );
204 throw new DBUnexpectedError(
206 '& mode is not implemented. If it\'s really needed, uncomment the line above.'
209 throw new DBUnexpectedError(
211 'Received invalid match. This should never happen!'
217 * Get search engine class. All subclasses of this need to implement this
218 * if they wish to use searching.
222 public function getSearchEngine() {
223 return 'SearchEngineDummy';