2 rcs_id('$Id: ADODB_postgres7.php,v 1.7 2006-12-23 11:56:17 rurban Exp $');
4 require_once('lib/WikiDB/backend/ADODB.php');
6 if (!defined("USE_BYTEA")) // see schemas/psql-initialize.sql
7 define("USE_BYTEA", true); // only BYTEA is binary safe
8 //define("USE_BYTEA", false);
11 * WikiDB layer for ADODB-postgres (7 or 8), called by lib/WikiDB/ADODB.php.
13 * - use Foreign Keys and ON DELETE CASCADE.
16 * @author: Reini Urban
18 class WikiDB_backend_ADODB_postgres7
19 extends WikiDB_backend_ADODB
24 function WikiDB_backend_ADODB_postgres7($dbparams) {
25 $this->WikiDB_backend_ADODB($dbparams);
27 $this->_serverinfo = $this->_dbh->ServerInfo();
28 if (!empty($this->_serverinfo['version'])) {
29 $arr = explode('.',$this->_serverinfo['version']);
30 $this->_serverinfo['version'] = (string)(($arr[0] * 100) + $arr[1]);
32 $this->_serverinfo['version'] .= ("." . (integer)$arr[2]);
38 * NOTE: Only the table owner can do this. Either fix the schema or setup autovacuum.
41 return 0; // if the wikiuser is not the table owner
43 foreach ($this->_table_names as $table) {
44 $this->_dbh->Execute("VACUUM ANALYZE $table");
49 // just for blobs. the rest is escaped with qstr()
52 return $this->_dbh->BlobEncode($s);
53 return base64_encode($s);
56 // just for blobs, which might be base64_encoded
57 function _unquote($s) {
59 //if function_exists('pg_unescape_bytea')
60 //return pg_unescape_bytea($s);
61 // TODO: already unescaped by ADORecordSet_postgres64::_decode?
64 return base64_decode($s);
67 function get_cached_html($pagename) {
69 $page_tbl = $this->_table_names['page_tbl'];
70 $data = $dbh->GetOne(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s",
71 $dbh->qstr($pagename)));
72 if ($data) return $this->_unquote($data);
76 function set_cached_html($pagename, $data) {
78 $page_tbl = $this->_table_names['page_tbl'];
80 $dbh->UpdateBlob($page_tbl,'cached_html',$data,"pagename=".$dbh->qstr($pagename));
82 $dbh->Execute(sprintf("UPDATE $page_tbl"
83 . " SET cached_html='%s'"
84 . " WHERE pagename=%s",
86 $dbh->qstr($pagename)));
89 $dbh->Execute("UPDATE $page_tbl"
90 . " SET cached_html=?"
91 . " WHERE pagename=?",
92 array($this->_quote($data), $pagename));
97 * Lock all tables we might use.
98 * postgresql has proper transactions so we dont need table locks.
100 function _lock_tables($tables, $write_lock = true) {
106 * postgresql has proper transactions so we dont need table locks.
108 function _unlock_tables($tables, $write_lock=false) {
115 function _serialize($data) {
118 assert(is_array($data));
119 return $this->_quote(serialize($data));
125 function _unserialize($data) {
128 // Base64 encoded data does not contain colons.
129 // (only alphanumerics and '+' and '/'.)
130 if (substr($data,0,2) == 'a:')
131 return unserialize($data);
132 return unserialize($this->_unquote($data));
137 class WikiDB_backend_ADODB_postgres7_search
138 extends WikiDB_backend_ADODB_search
140 function _pagename_match_clause($node) {
141 $word = $node->sql();
142 if ($node->op == 'REGEX') { // posix regex extensions
143 return ($this->_case_exact
144 ? "pagename ~* '$word'"
145 : "pagename ~ '$word'");
147 return ($this->_case_exact
148 ? "pagename LIKE '$word'"
149 : "pagename ILIKE '$word'");
153 // TODO: use tsearch2
154 //function _fulltext_match_clause($node)
157 // (c-file-style: "gnu")
162 // c-hanging-comment-ender-p: nil
163 // indent-tabs-mode: nil