]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB_pgsql.php
Jeff's hacks II.
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB_pgsql.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PearDB_pgsql.php,v 1.1 2001-09-18 19:16:23 dairiki Exp $');
3
4 require_once('lib/ErrorManager.php');
5 require_once('lib/WikiDB/backend/PearDB.php');
6
7 class WikiDB_backend_pgsql
8 extends WikiDB_backend_PearDB
9 {
10     function WikiDB_backend_pgsql($dbparams) {
11         // The pgsql handler of (at least my version of) the PEAR::DB
12         // library generates three warnings when a database is opened:
13         //
14         //     Undefined index: options
15         //     Undefined index: tty
16         //     Undefined index: port
17         //
18         // This stuff is all just to catch and ignore these warnings,
19         // so that they don't get reported to the user.  (They are
20         // not consequential.)  
21
22         global $ErrorManager;
23         $ErrorManager->pushErrorHandler(array($this,'_pgsql_open_error'));
24         $this->WikiDB_backend_PearDB($dbparams);
25         $ErrorManager->popErrorHandler();
26     }
27
28     function _pgsql_open_error($error) {
29         if (preg_match('/^Undefined\s+index:\s+(options|tty|port)/',
30                        $error->errstr))
31             return true;        // Ignore error
32         return false;
33     }
34             
35     /**
36      * Pack tables.
37      */
38     function optimize() {
39         $dbh = &$this->_dbh;
40         foreach ($this->_table_names as $table) {
41             $dbh->query("VACUUM ANALYZE $table");
42         }
43     }
44
45     /**
46      * Lock all tables we might use.
47      */
48     function _lock_tables($write_lock = true) {
49         $dbh = &$this->_dbh;
50         
51         $dbh->query("BEGIN WORK");
52         foreach ($this->_table_names as $table) {
53             // FIXME: can we use less restrictive locking.
54             //        (postgres supports transactions, after all.)
55             $dbh->query("LOCK TABLE $table");
56         }
57     }
58
59     /**
60      * Unlock all tables.
61      */
62     function _unlock_tables() {
63         $dbh = &$this->_dbh;
64         $dbh->query("COMMIT WORK");
65     }
66 };
67
68 // (c-file-style: "gnu")
69 // Local Variables:
70 // mode: php
71 // tab-width: 8
72 // c-basic-offset: 4
73 // c-hanging-comment-ender-p: nil
74 // indent-tabs-mode: nil
75 // End:   
76 ?>