]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB_pgsql.php
new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB_pgsql.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PearDB_pgsql.php,v 1.12 2004-11-26 18:39:02 rurban Exp $');
3
4 require_once('lib/ErrorManager.php');
5 require_once('lib/WikiDB/backend/PearDB.php');
6
7 class WikiDB_backend_PearDB_pgsql
8 extends WikiDB_backend_PearDB
9 {
10     function WikiDB_backend_PearDB_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(new WikiMethodCb($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         foreach ($this->_table_names as $table) {
40             $this->_dbh->query("VACUUM ANALYZE $table");
41         }
42         return 1;
43     }
44
45     /**
46      * Lock all tables we might use.
47      */
48     function _lock_tables($write_lock = true) {
49         $this->_dbh->query("BEGIN WORK");
50     }
51
52     /**
53      * Unlock all tables.
54      */
55     function _unlock_tables() {
56         $this->_dbh->query("COMMIT WORK");
57     }
58
59     /**
60      * Serialize data
61      */
62     function _serialize($data) {
63         if (empty($data))
64             return '';
65         assert(is_array($data));
66         return base64_encode(serialize($data));
67     }
68
69     /**
70      * Unserialize data
71      */
72     function _unserialize($data) {
73         if (empty($data))
74             return array();
75         // Base64 encoded data does not contain colons.
76         //  (only alphanumerics and '+' and '/'.)
77         if (substr($data,0,2) == 'a:')
78             return unserialize($data);
79         return unserialize(base64_decode($data));
80     }
81
82 };
83
84 class WikiDB_backend_PearDB_pgsql_search
85 extends WikiDB_backend_PearDB_search
86 {
87     function _pagename_match_clause($node) { 
88         $method = $node->op;
89         $word = $this->$method($node->word);
90         return $this->_case_exact 
91             ? "pagename LIKE '$word'"
92             : "pagename ILIKE '$word'";
93     }
94     function _fulltext_match_clause($node) { 
95         $method = $node->op;
96         $word = $this->$method($node->word);
97         return $this->_case_exact 
98             ? "pagename LIKE '$word' OR content LIKE '$word'"
99             : "pagename ILIKE '$word' OR content ILIKE '$word'";
100     }
101 }
102
103 // (c-file-style: "gnu")
104 // Local Variables:
105 // mode: php
106 // tab-width: 8
107 // c-basic-offset: 4
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil
110 // End:   
111 ?>