]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/ADODB_oci8po.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / WikiDB / backend / ADODB_oci8po.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
3
4 /**
5  * Oracle extensions for the ADODB DB backend.
6  * @author: Philippe.Vanhaesendonck@topgame.be
7  */
8
9 require_once('lib/WikiDB/backend/ADODB.php');
10
11 class WikiDB_backend_ADODB_oci8po
12 extends WikiDB_backend_ADODB
13 {
14     var $_prefix;
15
16     /**
17      * Constructor.
18      */
19     function WikiDB_backend_ADODB_oci8po($dbparams) {
20         // Lowercase Assoc arrays
21         define('ADODB_ASSOC_CASE',0);
22
23         // Backend constructor
24         $this->WikiDB_backend_ADODB($dbparams);
25
26         // Empty strings are NULLS in Oracle
27         $this->_expressions['notempty'] = "IS NOT NULL";
28         // CLOB handling
29         $this->_expressions['iscontent'] = "DECODE(DBMS_LOB.GETLENGTH(content), NULL, 0, 0, 0, 1)";
30
31         $this->_prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
32     }
33   
34     /**
35      * Pack tables.
36      */
37     function optimize() {
38         // Do nothing here -- Leave that for the DBA
39         // Cost Based Optimizer tuning vary from version to version
40         return 1;
41     }
42
43     /**
44      * Lock tables.
45      *
46      * We don't really need to lock exclusive, but I'll relax it when I fully
47      * understand phpWiki locking ;-)
48      *
49      */
50     function _lock_tables($tables, $write_lock = true) {
51             if (!$tables) return;
52
53         $dbh = &$this->_dbh;
54         if($write_lock) {
55             // Next line is default behaviour, so just skip it
56             // $dbh->Execute("SET TRANSACTION READ WRITE");
57             foreach ($tables as $table) {
58                 if ($this->_prefix && !strstr($table, $this->_prefix)) {
59                     $table = $this->_prefix . $table;
60                 }
61                 $dbh->Execute("LOCK TABLE $table IN EXCLUSIVE MODE");
62             }
63         } else {
64             // Just ensure read consistency
65             $dbh->Execute("SET TRANSACTION READ ONLY");
66         }
67     }
68
69     /**
70      * Release the locks.
71      */
72     function _unlock_tables($tables) {
73         $dbh = &$this->_dbh;
74         $dbh->Execute("COMMIT WORK");
75     }
76
77     // Search callbacks (replaced by class below)
78     // Page name
79     /*
80     function _sql_match_clause($word) {
81         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
82         $word = $this->_dbh->qstr("%$word%");
83         return "LOWER(pagename) LIKE $word";
84     }
85     */
86
87     // Fulltext -- case sensisitive :-\
88     // If we want case insensitive search, one need to create a Context
89     // Index on the CLOB. While it is very efficient, it requires the
90     // Intermedia Text option, so let's stick to the 'simple' thing
91     /*
92     function _fullsearch_sql_match_clause($word) {
93         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
94         $wordq = $this->_dbh->qstr("%$word%");
95         return "LOWER(pagename) LIKE $wordq "
96                . "OR DBMS_LOB.INSTR(content, '$word') > 0";
97     }
98     */
99   
100     /**
101      * Serialize data
102      */
103     function _serialize($data) {
104         if (empty($data))
105             return '';
106         assert(is_array($data));
107         return $this->_dbh->BlobEncode(serialize($data));
108     }
109
110     /**
111      * Unserialize data
112      */
113     function _unserialize($data) {
114         if (empty($data))
115             return array();
116         $d = $this->_dbh->BlobDecode($data);
117         if(! is_string($d)) {
118           print_r($d);
119         }
120         return unserialize($this->_dbh->BlobDecode($data));
121     }
122
123     function write_accesslog(&$entry) {
124         global $request;
125         $dbh = &$this->_dbh;
126         $log_tbl = $entry->_accesslog->logtable;
127         $dbh->query("INSERT INTO $log_tbl"
128                     . " (time_stamp,remote_host,remote_user,request_method,request_line,request_uri,"
129                     .   "request_args,request_time,status,bytes_sent,referer,agent,request_duration)"
130                     . " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
131                     array(
132                           // Problem: date formats are backend specific. Either use unixtime as %d (long),
133                           // or the native timestamp format.
134                           date('d-M-Y H:i:s', $entry->time),
135                           $entry->host,
136                           $entry->user,
137                           $entry->request_method,
138                           $entry->request,
139                           $entry->request_uri,  
140                           $entry->request_args,
141                           $entry->_ncsa_time($entry->time),
142                           $entry->status,
143                           $entry->size,
144                           $entry->referer,
145                           $entry->user_agent,
146                           $entry->duration));
147     }
148
149 };
150
151 class WikiDB_backend_ADODB_oci8_search
152 extends WikiDB_backend_ADODB_search
153 {
154     // If we want case insensitive search, one need to create a Context
155     // Index on the CLOB. While it is very efficient, it requires the
156     // Intermedia Text option, so let's stick to the 'simple' thing
157     // Note that this does only an exact fulltext search, not using MATCH or LIKE.
158     function _fulltext_match_clause($node) {
159         if ($this->isStoplisted($node))
160             return "1=1";
161         $page = $node->sql();
162         $exactword = $node->_sql_quote($node->word);
163         return ($this->_case_exact
164                 ? "pagename LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0"
165                 : "LOWER(pagename) LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0");
166     }
167 }
168
169 // Local Variables:
170 // mode: php
171 // tab-width: 8
172 // c-basic-offset: 4
173 // c-hanging-comment-ender-p: nil
174 // indent-tabs-mode: nil
175 // End: 
176 ?>