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