summaryrefslogtreecommitdiff
path: root/includes/Database.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/Database.php')
-rw-r--r--includes/Database.php52
1 files changed, 44 insertions, 8 deletions
diff --git a/includes/Database.php b/includes/Database.php
index 4f8c7d5e..f8738288 100644
--- a/includes/Database.php
+++ b/includes/Database.php
@@ -36,6 +36,22 @@ class DBObject {
};
/**
+ * Utility class
+ * @addtogroup Database
+ *
+ * This allows us to distinguish a blob from a normal string and an array of strings
+ */
+class Blob {
+ private $mData;
+ function __construct($data) {
+ $this->mData = $data;
+ }
+ function fetch() {
+ return $this->mData;
+ }
+};
+
+/**
* Utility class.
* @addtogroup Database
*/
@@ -729,8 +745,8 @@ class Database {
global $wgUser;
if ( is_object( $wgUser ) && !($wgUser instanceof StubObject) ) {
$userName = $wgUser->getName();
- if ( strlen( $userName ) > 15 ) {
- $userName = substr( $userName, 0, 15 ) . '...';
+ if ( mb_strlen( $userName ) > 15 ) {
+ $userName = mb_substr( $userName, 0, 15 ) . '...';
}
$userName = str_replace( '/', '', $userName );
} else {
@@ -743,9 +759,13 @@ class Database {
# If DBO_TRX is set, start a transaction
if ( ( $this->mFlags & DBO_TRX ) && !$this->trxLevel() &&
- $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK'
- ) {
- $this->begin();
+ $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK') {
+ // avoid establishing transactions for SHOW and SET statements too -
+ // that would delay transaction initializations to once connection
+ // is really used by application
+ $sqlstart = substr($sql,0,10); // very much worth it, benchmark certified(tm)
+ if (strpos($sqlstart,"SHOW ")!==0 and strpos($sqlstart,"SET ")!==0)
+ $this->begin();
}
if ( $this->debug() ) {
@@ -1548,7 +1568,15 @@ class Database {
} elseif ( ($mode == LIST_SET) && is_numeric( $field ) ) {
$list .= "$value";
} elseif ( ($mode == LIST_AND || $mode == LIST_OR) && is_array($value) ) {
- $list .= $field." IN (".$this->makeList($value).") ";
+ if( count( $value ) == 0 ) {
+ // Empty input... or should this throw an error?
+ $list .= '0';
+ } elseif( count( $value ) == 1 ) {
+ // Special-case single values, as IN isn't terribly efficient
+ $list .= $field." = ".$this->addQuotes( $value[0] );
+ } else {
+ $list .= $field." IN (".$this->makeList($value).") ";
+ }
} elseif( is_null($value) ) {
if ( $mode == LIST_AND || $mode == LIST_OR ) {
$list .= "$field IS ";
@@ -2011,10 +2039,11 @@ class Database {
}
/**
- * Rollback a transaction
+ * Rollback a transaction.
+ * No-op on non-transactional databases.
*/
function rollback( $fname = 'Database::rollback' ) {
- $this->query( 'ROLLBACK', $fname );
+ $this->query( 'ROLLBACK', $fname, true );
$this->mTrxLevel = 0;
}
@@ -2286,6 +2315,13 @@ class Database {
return $this->tableName( $matches[1] );
}
+ /*
+ * Build a concatenation list to feed into a SQL query
+ */
+ function buildConcat( $stringList ) {
+ return 'CONCAT(' . implode( ',', $stringList ) . ')';
+ }
+
}
/**