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