]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB_oci8.php
Reformat code
[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     /**
14      * Constructor
15      */
16     function WikiDB_backend_PearDB_oci8($dbparams)
17     {
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     {
42         // Do nothing here -- Leave that for the DBA
43         // Cost Based Optimizer tuning vary from version to version
44         return 1;
45     }
46
47     /**
48      * Lock all tables we might use.
49      */
50     function _lock_tables($write_lock = true)
51     {
52         $dbh = &$this->_dbh;
53
54         // Not sure if we really need to lock tables here, the Oracle row
55         // locking mechanism should be more than enough
56         // For the time being, lets stay on the safe side and lock...
57         if ($write_lock) {
58             // Next line is default behaviour, so just skip it
59             // $dbh->query("SET TRANSACTION READ WRITE");
60             foreach ($this->_table_names as $table) {
61                 $dbh->query("LOCK TABLE $table IN EXCLUSIVE MODE");
62             }
63         } else {
64             // Just ensure read consistency
65             $dbh->query("SET TRANSACTION READ ONLY");
66         }
67     }
68
69     function _quote($s)
70     {
71         return base64_encode($s);
72     }
73
74     function _unquote($s)
75     {
76         return base64_decode($s);
77     }
78
79     function write_accesslog(&$entry)
80     {
81         global $request;
82         $dbh = &$this->_dbh;
83         $log_tbl = $entry->_accesslog->logtable;
84         // duration problem: sprintf "%f" might use comma e.g. "100,201" in european locales
85         $dbh->query("INSERT INTO $log_tbl"
86                 . " (time_stamp,remote_host,remote_user,request_method,request_line,request_uri,"
87                 . "request_args,request_time,status,bytes_sent,referer,agent,request_duration)"
88                 . " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
89             array(
90                 // Problem: date formats are backend specific. Either use unixtime as %d (long),
91                 // or the native timestamp format.
92                 date('d-M-Y H:i:s', $entry->time),
93                 $entry->host,
94                 $entry->user,
95                 $entry->request_method,
96                 $entry->request,
97                 $entry->request_uri,
98                 $entry->request_args,
99                 $entry->_ncsa_time($entry->time),
100                 $entry->status,
101                 $entry->size,
102                 $entry->referer,
103                 $entry->user_agent,
104                 $entry->duration));
105     }
106
107 }
108
109 ;
110
111 class WikiDB_backend_PearDB_oci8_search
112     extends WikiDB_backend_PearDB_search
113 {
114     // If we want case insensitive search, one need to create a Context
115     // Index on the CLOB. While it is very efficient, it requires the
116     // Intermedia Text option, so let's stick to the 'simple' thing
117     // Note that this does only an exact fulltext search, not using MATCH or LIKE.
118     function _fulltext_match_clause($node)
119     {
120         if ($this->isStoplisted($node))
121             return "1=1";
122         $page = $node->sql();
123         $exactword = $node->_sql_quote($node->word);
124         return ($this->_case_exact
125             ? "pagename LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0"
126             : "LOWER(pagename) LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0");
127     }
128 }
129
130 // Local Variables:
131 // mode: php
132 // tab-width: 8
133 // c-basic-offset: 4
134 // c-hanging-comment-ender-p: nil
135 // indent-tabs-mode: nil
136 // End: