2 rcs_id('$Id: PearDB_pgsql.php,v 1.12 2004-11-26 18:39:02 rurban Exp $');
4 require_once('lib/ErrorManager.php');
5 require_once('lib/WikiDB/backend/PearDB.php');
7 class WikiDB_backend_PearDB_pgsql
8 extends WikiDB_backend_PearDB
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:
14 // Undefined index: options
15 // Undefined index: tty
16 // Undefined index: port
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.)
23 $ErrorManager->pushErrorHandler(new WikiMethodCb($this,'_pgsql_open_error'));
24 $this->WikiDB_backend_PearDB($dbparams);
25 $ErrorManager->popErrorHandler();
28 function _pgsql_open_error($error) {
29 if (preg_match('/^Undefined\s+index:\s+(options|tty|port)/',
31 return true; // Ignore error
39 foreach ($this->_table_names as $table) {
40 $this->_dbh->query("VACUUM ANALYZE $table");
46 * Lock all tables we might use.
48 function _lock_tables($write_lock = true) {
49 $this->_dbh->query("BEGIN WORK");
55 function _unlock_tables() {
56 $this->_dbh->query("COMMIT WORK");
62 function _serialize($data) {
65 assert(is_array($data));
66 return base64_encode(serialize($data));
72 function _unserialize($data) {
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));
84 class WikiDB_backend_PearDB_pgsql_search
85 extends WikiDB_backend_PearDB_search
87 function _pagename_match_clause($node) {
89 $word = $this->$method($node->word);
90 return $this->_case_exact
91 ? "pagename LIKE '$word'"
92 : "pagename ILIKE '$word'";
94 function _fulltext_match_clause($node) {
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'";
103 // (c-file-style: "gnu")
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil