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);
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.
42 return 0; // if the wikiuser is not the table owner
44 foreach ($this->_table_names as $table) {
45 $this->_dbh->Execute("VACUUM ANALYZE $table");
50 // just for blobs. the rest is escaped with qstr()
53 return $this->_dbh->BlobEncode($s);
54 return base64_encode($s);
57 // just for blobs, which might be base64_encoded
58 function _unquote($s) {
60 //if function_exists('pg_unescape_bytea')
61 //return pg_unescape_bytea($s);
62 // TODO: already unescaped by ADORecordSet_postgres64::_decode?
65 return base64_decode($s);
68 function get_cached_html($pagename) {
70 $page_tbl = $this->_table_names['page_tbl'];
71 $data = $dbh->GetOne(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s",
72 $dbh->qstr($pagename)));
73 if ($data) return $this->_unquote($data);
77 function set_cached_html($pagename, $data) {
79 $page_tbl = $this->_table_names['page_tbl'];
81 $dbh->UpdateBlob($page_tbl,'cached_html',$data,"pagename=".$dbh->qstr($pagename));
83 $dbh->Execute(sprintf("UPDATE $page_tbl"
84 . " SET cached_html='%s'"
85 . " WHERE pagename=%s",
87 $dbh->qstr($pagename)));
90 $dbh->Execute("UPDATE $page_tbl"
91 . " SET cached_html=?"
92 . " WHERE pagename=?",
93 array($this->_quote($data), $pagename));
98 * Lock all tables we might use.
99 * postgresql has proper transactions so we dont need table locks.
101 function _lock_tables($tables, $write_lock = true) {
107 * postgresql has proper transactions so we dont need table locks.
109 function _unlock_tables($tables, $write_lock=false) {
116 function _serialize($data) {
119 assert(is_array($data));
120 return $this->_quote(serialize($data));
126 function _unserialize($data) {
129 // Base64 encoded data does not contain colons.
130 // (only alphanumerics and '+' and '/'.)
131 if (substr($data,0,2) == 'a:')
132 return unserialize($data);
133 return unserialize($this->_unquote($data));
138 class WikiDB_backend_ADODB_postgres7_search
139 extends WikiDB_backend_ADODB_search
141 function _pagename_match_clause($node) {
142 $word = $node->sql();
143 if ($node->op == 'REGEX') { // posix regex extensions
144 return ($this->_case_exact
145 ? "pagename ~* '$word'"
146 : "pagename ~ '$word'");
148 return ($this->_case_exact
149 ? "pagename LIKE '$word'"
150 : "pagename ILIKE '$word'");
154 // TODO: use tsearch2
155 //function _fulltext_match_clause($node)
162 // c-hanging-comment-ender-p: nil
163 // indent-tabs-mode: nil