3 require_once 'lib/WikiDB/backend/ADODB.php';
5 if (!defined("USE_BYTEA")) // see schemas/psql-initialize.sql
6 define("USE_BYTEA", true); // only BYTEA is binary safe
7 //define("USE_BYTEA", false);
10 * WikiDB layer for ADODB-postgres (7 or 8), called by lib/WikiDB/ADODB.php.
12 * - use Foreign Keys and ON DELETE CASCADE.
15 * @author: Reini Urban
17 class WikiDB_backend_ADODB_postgres7
18 extends WikiDB_backend_ADODB
23 function WikiDB_backend_ADODB_postgres7($dbparams)
25 $this->WikiDB_backend_ADODB($dbparams);
26 if (!$this->_dbh->_connectionID) return;
28 $this->_serverinfo = $this->_dbh->ServerInfo();
29 if (!empty($this->_serverinfo['version'])) {
30 $arr = explode('.', $this->_serverinfo['version']);
31 $this->_serverinfo['version'] = (string)(($arr[0] * 100) + $arr[1]);
33 $this->_serverinfo['version'] .= ("." . (integer)$arr[2]);
39 * NOTE: Only the table owner can do this. Either fix the schema or setup autovacuum.
43 return 0; // if the wikiuser is not the table owner
45 foreach ($this->_table_names as $table) {
46 $this->_dbh->Execute("VACUUM ANALYZE $table");
51 // just for blobs. the rest is escaped with qstr()
55 return $this->_dbh->BlobEncode($s);
56 return base64_encode($s);
59 // just for blobs, which might be base64_encoded
63 //if function_exists('pg_unescape_bytea')
64 //return pg_unescape_bytea($s);
65 // TODO: already unescaped by ADORecordSet_postgres64::_decode?
68 return base64_decode($s);
71 function get_cached_html($pagename)
74 $page_tbl = $this->_table_names['page_tbl'];
75 $data = $dbh->GetOne(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s",
76 $dbh->qstr($pagename)));
77 if ($data) return $this->_unquote($data);
81 function set_cached_html($pagename, $data)
84 $page_tbl = $this->_table_names['page_tbl'];
86 $dbh->UpdateBlob($page_tbl, 'cached_html', $data, "pagename=" . $dbh->qstr($pagename));
88 $dbh->Execute(sprintf("UPDATE $page_tbl"
89 . " SET cached_html='%s'"
90 . " WHERE pagename=%s",
92 $dbh->qstr($pagename)));
95 $dbh->Execute("UPDATE $page_tbl"
96 . " SET cached_html=?"
97 . " WHERE pagename=?",
98 array($this->_quote($data), $pagename));
103 * Lock all tables we might use.
104 * postgresql has proper transactions so we dont need table locks.
106 function _lock_tables($tables, $write_lock = true)
113 * postgresql has proper transactions so we dont need table locks.
115 function _unlock_tables($tables, $write_lock = false)
123 function _serialize($data)
127 assert(is_array($data));
128 return $this->_quote(serialize($data));
134 function _unserialize($data)
138 // Base64 encoded data does not contain colons.
139 // (only alphanumerics and '+' and '/'.)
140 if (substr($data, 0, 2) == 'a:')
141 return unserialize($data);
142 return unserialize($this->_unquote($data));
149 class WikiDB_backend_ADODB_postgres7_search
150 extends WikiDB_backend_ADODB_search
152 function _pagename_match_clause($node)
154 $word = $node->sql();
155 if ($node->op == 'REGEX') { // posix regex extensions
156 return ($this->_case_exact
157 ? "pagename ~* '$word'"
158 : "pagename ~ '$word'");
160 return ($this->_case_exact
161 ? "pagename LIKE '$word'"
162 : "pagename ILIKE '$word'");
166 // TODO: use tsearch2
167 //function _fulltext_match_clause($node)
174 // c-hanging-comment-ender-p: nil
175 // indent-tabs-mode: nil