X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseSqlite.php;h=83c88149b01ddc242eca07f22fa8f10c21681ab4;hb=1621c57c3724a66c487a65f46940a6e0e4dc4dea;hp=01772cf809b273706264a21b690586b0ecd81723;hpb=689c847a32e7fe8a0b3a559a88a627a252c5018e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 01772cf809..83c88149b0 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -46,12 +46,12 @@ class DatabaseSqlite extends Database { protected $trxMode; /** @var int The number of rows affected as an integer */ - protected $mAffectedRows; + protected $lastAffectedRowCount; /** @var resource */ - protected $mLastResult; + protected $lastResultHandle; /** @var PDO */ - protected $mConn; + protected $conn; /** @var FSLockManager (hopefully on the same server as the DB) */ protected $lockMgr; @@ -79,8 +79,8 @@ class DatabaseSqlite extends Database { throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." ); } else { $this->dbDir = $p['dbDirectory']; - $this->mDBname = $p['dbname']; - $lockDomain = $this->mDBname; + $this->dbName = $p['dbname']; + $lockDomain = $this->dbName; // Stock wiki mode using standard file names per DB. parent::__construct( $p ); // Super doesn't open when $user is false, but we can work with $dbName @@ -103,6 +103,10 @@ class DatabaseSqlite extends Database { ] ); } + protected static function getAttributes() { + return [ self::ATTR_DB_LEVEL_LOCKING => true ]; + } + /** * @param string $filename * @param array $p Options map; supports: @@ -153,12 +157,12 @@ class DatabaseSqlite extends Database { $this->close(); $fileName = self::generateFileName( $this->dbDir, $dbName ); if ( !is_readable( $fileName ) ) { - $this->mConn = false; + $this->conn = false; throw new DBConnectionError( $this, "SQLite database not accessible" ); } $this->openFile( $fileName ); - return (bool)$this->mConn; + return (bool)$this->conn; } /** @@ -173,29 +177,29 @@ class DatabaseSqlite extends Database { $this->dbPath = $fileName; try { - if ( $this->mFlags & self::DBO_PERSISTENT ) { - $this->mConn = new PDO( "sqlite:$fileName", '', '', + if ( $this->flags & self::DBO_PERSISTENT ) { + $this->conn = new PDO( "sqlite:$fileName", '', '', [ PDO::ATTR_PERSISTENT => true ] ); } else { - $this->mConn = new PDO( "sqlite:$fileName", '', '' ); + $this->conn = new PDO( "sqlite:$fileName", '', '' ); } } catch ( PDOException $e ) { $err = $e->getMessage(); } - if ( !$this->mConn ) { + if ( !$this->conn ) { $this->queryLogger->debug( "DB connection error: $err\n" ); throw new DBConnectionError( $this, $err ); } - $this->mOpened = !!$this->mConn; - if ( $this->mOpened ) { + $this->opened = !!$this->conn; + if ( $this->opened ) { # Set error codes only, don't raise exceptions - $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); + $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); # Enforce LIKE to be case sensitive, just like MySQL $this->query( 'PRAGMA case_sensitive_like = 1' ); - return $this->mConn; + return $this->conn; } return false; @@ -218,7 +222,7 @@ class DatabaseSqlite extends Database { * @return bool */ protected function closeConnection() { - $this->mConn = null; + $this->conn = null; return true; } @@ -311,13 +315,13 @@ class DatabaseSqlite extends Database { * @return bool|ResultWrapper */ protected function doQuery( $sql ) { - $res = $this->mConn->query( $sql ); + $res = $this->conn->query( $sql ); if ( $res === false ) { return false; } $r = $res instanceof ResultWrapper ? $res->result : $res; - $this->mAffectedRows = $r->rowCount(); + $this->lastAffectedRowCount = $r->rowCount(); $res = new ResultWrapper( $this, $r->fetchAll() ); return $res; @@ -447,7 +451,7 @@ class DatabaseSqlite extends Database { */ function insertId() { // PDO::lastInsertId yields a string :( - return intval( $this->mConn->lastInsertId() ); + return intval( $this->conn->lastInsertId() ); } /** @@ -472,10 +476,10 @@ class DatabaseSqlite extends Database { * @return string */ function lastError() { - if ( !is_object( $this->mConn ) ) { + if ( !is_object( $this->conn ) ) { return "Cannot return last error, no db connection"; } - $e = $this->mConn->errorInfo(); + $e = $this->conn->errorInfo(); return isset( $e[2] ) ? $e[2] : ''; } @@ -484,10 +488,10 @@ class DatabaseSqlite extends Database { * @return string */ function lastErrno() { - if ( !is_object( $this->mConn ) ) { + if ( !is_object( $this->conn ) ) { return "Cannot return last error, no db connection"; } else { - $info = $this->mConn->errorInfo(); + $info = $this->conn->errorInfo(); return $info[1]; } @@ -497,7 +501,7 @@ class DatabaseSqlite extends Database { * @return int */ protected function fetchAffectedRowCount() { - return $this->mAffectedRows; + return $this->lastAffectedRowCount; } /** @@ -720,7 +724,7 @@ class DatabaseSqlite extends Database { * @return string Version information from the database */ function getServerVersion() { - $ver = $this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + $ver = $this->conn->getAttribute( PDO::ATTR_SERVER_VERSION ); return $ver; } @@ -752,7 +756,7 @@ class DatabaseSqlite extends Database { } else { $this->query( 'BEGIN', $fname ); } - $this->mTrxLevel = 1; + $this->trxLevel = 1; } /** @@ -810,8 +814,17 @@ class DatabaseSqlite extends Database { ); return "x'" . bin2hex( (string)$s ) . "'"; } else { - return $this->mConn->quote( (string)$s ); + return $this->conn->quote( (string)$s ); + } + } + + public function buildSubstring( $input, $startPosition, $length = null ) { + $this->assertBuildSubstringParams( $startPosition, $length ); + $params = [ $input, $startPosition ]; + if ( $length !== null ) { + $params[] = $length; } + return 'SUBSTR(' . implode( ',', $params ) . ')'; } /** @@ -1054,7 +1067,7 @@ class DatabaseSqlite extends Database { * @return string */ public function __toString() { - return 'SQLite ' . (string)$this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + return 'SQLite ' . (string)$this->conn->getAttribute( PDO::ATTR_SERVER_VERSION ); } }