]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB_oci8.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB_oci8.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
3
4 /**
5  * Oracle extensions for the Pear DB backend.
6  * @author: Philippe.Vanhaesendonck@topgame.be
7  */
8
9 require_once('lib/WikiDB/backend/PearDB_pgsql.php');
10
11 class WikiDB_backend_PearDB_oci8
12 extends WikiDB_backend_PearDB_pgsql
13 {
14     /**
15      * Constructor
16      */
17     function WikiDB_backend_PearDB_oci8($dbparams) {
18         // Backend constructor
19         $this->WikiDB_backend_PearDB($dbparams);
20         if (DB::isError($this->_dbh)) return;
21
22         // Empty strings are NULLS
23         $this->_expressions['notempty'] = "IS NOT NULL";
24         $this->_expressions['iscontent'] = "DECODE(DBMS_LOB.GETLENGTH(content), NULL, 0, 0, 0, 1)";
25
26         // Set parameters:
27         $dbh = &$this->_dbh;
28         // - No persistent conections (I don't like them)
29         $dbh->setOption('persistent', false);
30         // - Set lowercase compatibility option
31         // - Set numrows as well -- sure why this is needed, but some queries 
32         //   are triggering DB_ERROR_NOT_CAPABLE
33         $dbh->setOption('portability',
34             DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_NULL_TO_EMPTY | DB_PORTABILITY_NUMROWS);
35     }
36
37     /**
38      * Pack tables.
39      */
40     function optimize() {
41         // Do nothing here -- Leave that for the DBA
42         // Cost Based Optimizer tuning vary from version to version
43         return 1;
44     }
45
46     /**
47      * Lock all tables we might use.
48      */
49     function _lock_tables($write_lock=true) {
50         $dbh = &$this->_dbh;
51         
52         // Not sure if we really need to lock tables here, the Oracle row
53         // locking mechanism should be more than enough
54         // For the time being, lets stay on the safe side and lock...
55         if ($write_lock) {
56             // Next line is default behaviour, so just skip it
57             // $dbh->query("SET TRANSACTION READ WRITE");
58             foreach ($this->_table_names as $table) {
59                 $dbh->query("LOCK TABLE $table IN EXCLUSIVE MODE");
60             }
61         } else {
62             // Just ensure read consistency
63             $dbh->query("SET TRANSACTION READ ONLY");
64         }
65     }
66
67     function _quote($s) {
68         return base64_encode($s);
69     }
70
71     function _unquote($s) {
72         return base64_decode($s);
73     }
74
75     function write_accesslog(&$entry) {
76         global $request;
77         $dbh = &$this->_dbh;
78         $log_tbl = $entry->_accesslog->logtable;
79         // duration problem: sprintf "%f" might use comma e.g. "100,201" in european locales
80         $dbh->query("INSERT INTO $log_tbl"
81                     . " (time_stamp,remote_host,remote_user,request_method,request_line,request_uri,"
82                     .   "request_args,request_time,status,bytes_sent,referer,agent,request_duration)"
83                     . " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
84                     array(
85                           // Problem: date formats are backend specific. Either use unixtime as %d (long),
86                           // or the native timestamp format.
87                           date('d-M-Y H:i:s', $entry->time),
88                           $entry->host, 
89                           $entry->user,
90                           $entry->request_method, 
91                           $entry->request, 
92                           $entry->request_uri,    
93                           $entry->request_args,
94                           $entry->_ncsa_time($entry->time), 
95                           $entry->status, 
96                           $entry->size,
97                           $entry->referer,
98                           $entry->user_agent,
99                           $entry->duration));
100     }
101
102 };
103
104 class WikiDB_backend_PearDB_oci8_search
105 extends WikiDB_backend_PearDB_search
106 {
107     // If we want case insensitive search, one need to create a Context
108     // Index on the CLOB. While it is very efficient, it requires the
109     // Intermedia Text option, so let's stick to the 'simple' thing
110     // Note that this does only an exact fulltext search, not using MATCH or LIKE.
111     function _fulltext_match_clause($node) {
112         if ($this->isStoplisted($node))
113             return "1=1";
114         $page = $node->sql();
115         $exactword = $node->_sql_quote($node->word);
116         return ($this->_case_exact
117                 ? "pagename LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0"
118                 : "LOWER(pagename) LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0");
119     }
120 }
121
122 // (c-file-style: "gnu")
123 // Local Variables:
124 // mode: php
125 // tab-width: 8
126 // c-basic-offset: 4
127 // c-hanging-comment-ender-p: nil
128 // indent-tabs-mode: nil
129 // End:   
130 ?>