Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -22,12 +22,8 @@ |
23 | 23 | * Parameters $server, $user and $password are not used. |
24 | 24 | */ |
25 | 25 | function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) { |
26 | | - global $wgSQLiteDataDir; |
27 | 26 | $this->mFailFunction = $failFunction; |
28 | 27 | $this->mFlags = $flags; |
29 | | - $this->mDatabaseFile = self::generateFileName( $wgSQLiteDataDir, $dbName ); |
30 | | - if ( !is_readable( $this->mDatabaseFile ) ) |
31 | | - throw new DBConnectionError( $this, "SQLite database not accessible" ); |
32 | 28 | $this->mName = $dbName; |
33 | 29 | $this->open( $server, $user, $password, $dbName ); |
34 | 30 | } |
— | — | @@ -49,36 +45,47 @@ |
50 | 46 | * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases |
51 | 47 | */ |
52 | 48 | function open( $server, $user, $pass, $dbName ) { |
53 | | - $this->mConn = false; |
54 | | - if ( $dbName ) { |
55 | | - $file = $this->mDatabaseFile; |
56 | | - try { |
57 | | - if ( $this->mFlags & DBO_PERSISTENT ) { |
58 | | - $this->mConn = new PDO( "sqlite:$file", $user, $pass, |
59 | | - array( PDO::ATTR_PERSISTENT => true ) ); |
60 | | - } else { |
61 | | - $this->mConn = new PDO( "sqlite:$file", $user, $pass ); |
62 | | - } |
63 | | - } catch ( PDOException $e ) { |
64 | | - $err = $e->getMessage(); |
65 | | - } |
66 | | - if ( $this->mConn === false ) { |
67 | | - wfDebug( "DB connection error: $err\n" ); |
68 | | - if ( !$this->mFailFunction ) { |
69 | | - throw new DBConnectionError( $this, $err ); |
70 | | - } else { |
71 | | - return false; |
72 | | - } |
| 49 | + global $wgSQLiteDataDir; |
73 | 50 | |
74 | | - } |
75 | | - $this->mOpened = $this->mConn; |
76 | | - # set error codes only, don't raise exceptions |
77 | | - $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); |
| 51 | + $fileName = self::generateFileName( $wgSQLiteDataDir, $dbName ); |
| 52 | + if ( !is_readable( $fileName ) ) { |
| 53 | + throw new DBConnectionError( $this, "SQLite database not accessible" ); $this->mConn = false; |
78 | 54 | } |
| 55 | + $this->openFile( $fileName ); |
79 | 56 | return $this->mConn; |
80 | 57 | } |
81 | 58 | |
82 | 59 | /** |
| 60 | + * Opens a database file |
| 61 | + * @return SQL connection or false if failed |
| 62 | + */ |
| 63 | + function openFile( $fileName ) { |
| 64 | + $this->mDatabaseFile = $fileName; |
| 65 | + try { |
| 66 | + if ( $this->mFlags & DBO_PERSISTENT ) { |
| 67 | + $this->mConn = new PDO( "sqlite:$fileName", '', '', |
| 68 | + array( PDO::ATTR_PERSISTENT => true ) ); |
| 69 | + } else { |
| 70 | + $this->mConn = new PDO( "sqlite:$fileName", '', '' ); |
| 71 | + } |
| 72 | + } catch ( PDOException $e ) { |
| 73 | + $err = $e->getMessage(); |
| 74 | + } |
| 75 | + if ( $this->mConn === false ) { |
| 76 | + wfDebug( "DB connection error: $err\n" ); |
| 77 | + if ( !$this->mFailFunction ) { |
| 78 | + throw new DBConnectionError( $this, $err ); |
| 79 | + } else { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + $this->mOpened = $this->mConn; |
| 85 | + # set error codes only, don't raise exceptions |
| 86 | + $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
83 | 90 | * Close an SQLite database |
84 | 91 | */ |
85 | 92 | function close() { |
— | — | @@ -551,8 +558,19 @@ |
552 | 559 | } // end DatabaseSqlite class |
553 | 560 | |
554 | 561 | /** |
| 562 | + * This class allows simple acccess to a SQLite database independently from main database settings |
555 | 563 | * @ingroup Database |
556 | 564 | */ |
| 565 | +class DatabaseSqliteStandalone extends DatabaseSqlite { |
| 566 | + public function __construct( $fileName, $flags = 0 ) { |
| 567 | + $this->mFlags = $flags; |
| 568 | + $this->openFile( $fileName ); |
| 569 | + } |
| 570 | +} |
| 571 | + |
| 572 | +/** |
| 573 | + * @ingroup Database |
| 574 | + */ |
557 | 575 | class SQLiteField { |
558 | 576 | private $info, $tableName; |
559 | 577 | function __construct( $info, $tableName ) { |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -351,6 +351,7 @@ |
352 | 352 | 'DatabaseOracle' => 'includes/db/DatabaseOracle.php', |
353 | 353 | 'DatabasePostgres' => 'includes/db/DatabasePostgres.php', |
354 | 354 | 'DatabaseSqlite' => 'includes/db/DatabaseSqlite.php', |
| 355 | + 'DatabaseSqliteStandalone' => 'includes/db/DatabaseSqlite.php', |
355 | 356 | 'DBConnectionError' => 'includes/db/Database.php', |
356 | 357 | 'DBError' => 'includes/db/Database.php', |
357 | 358 | 'DBObject' => 'includes/db/Database.php', |