3
* $RCSfile: OracleStorage.class,v $
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or (at
11
* your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
23
* @version $Revision: 1.10.2.1 $ $Date: 2006/04/10 15:36:16 $
24
* @package GalleryCore
25
* @author Alan Harder <alan.harder@sun.com>
28
GalleryCoreApi::requireOnce('modules/core/classes/GalleryStorage.class', true);
31
* Oracle extension of the GalleryStorage class.
33
* This object implements the hooks for saving and restoring objects in an
36
* @package GalleryCore
39
class OracleStorage extends GalleryStorage {
42
* The type of Oracle database (oci8, oci8po, oci805 or oracle)
44
* @var string $_oracleDbType
53
function OracleStorage($config) {
54
$this->GalleryStorage($config);
55
$this->_oracleDbType = $config['type'];
56
$this->_isTransactional = true;
57
$this->_isEmptyAllowedForNotNullColumn = false;
61
* Return the type of this database
65
function getAdoDbType() {
66
return $this->_oracleDbType;
70
* Return the type of this database
79
* @see GalleryStorage::_setConnectionSettings
81
function _setConnectionSettings(&$db) {
82
/* May cause "ORA-12705: Cannot access NLS data files or invalid environment specified" */
83
/* @putenv("NLS_LANG=UTF8"); */
89
* @see GalleryStorage::getFunctionsSql
91
function getFunctionSql($functionName, $args) {
92
switch($functionName) {
94
$sql = implode(' || ', $args);
98
$sql = 'BITAND(' . $args[0] . ',' . $args[1] . ')';
102
$sql = 'BIT_OR(' . $args[0] . ')';
110
$sql = sprintf('SUBSTR(%s)', implode(', ', $args));
115
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
116
$functionName . ' ' . implode(' ', $args)), null);
118
$sql = 'DBMS_RANDOM.RANDOM';
122
$sql = 'SELECT * FROM (' . $args[1] . ') WHERE ROWNUM <= ' . $args[0];
127
while (count($args) > 1) {
128
$sql[] = 'WHEN ' . array_shift($args) . ' THEN ' . array_shift($args);
130
$sql = 'CASE ' . implode(' ', $sql) . ' ELSE ' . $args[0] . ' END';
134
$sql = $args[0] . ' LIKE ' . $args[1];
140
* 1 - array of column names
143
$markers = GalleryUtilities::makeMarkers(sizeof($args[1]));
144
$rowList = array(); //php4.2: array-fill(1, $args[2], 'SELECT '.$markers.' FROM DUAL');
145
for ($i = 0; $i < $args[2]; $i++) {
146
$rowList[] = 'SELECT ' . $markers . ' FROM DUAL';
148
$sql = 'INSERT INTO ' . $args[0] . ' (';
149
$sql .= implode(', ', $args[1]);
150
$sql .= ') ' . implode(' UNION ALL ', $rowList);
154
$sql = sprintf('AVG(%s)', $args[0]);
158
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
159
$functionName . ' ' . implode(' ', $args)), null);
162
return array(null, $sql);
166
* @see GalleryStorage::cleanStore
168
function cleanStore() {
169
$ret = parent::cleanStore();
171
return $ret->wrap(__FILE__, __LINE__);
175
* Create a temporary database connection and remove our custom
176
* aggregate function.
178
list ($ret, $tmpDb) = $this->_getConnection(true);
180
return $ret->wrap(__FILE__, __LINE__);
183
$this->_traceStart();
184
$recordSet1 = $tmpDb->Execute('DROP FUNCTION BIT_OR');
185
$recordSet2 = $tmpDb->Execute('DROP TYPE BIT_OR_IMPL');
189
if (empty($recordSet1) || empty($recordSet2)) {
190
return GalleryCoreApi::error(ERROR_STORAGE_FAILURE, __FILE__, __LINE__);
197
* @see GalleryStorage::configureStore
199
function configureStore($moduleId, $upgradeInfo=array()) {
200
if ($moduleId == 'core') {
201
/* Install our custom aggregate function */
202
$ret = $this->_executeSqlFile(dirname(__FILE__) . '/OracleCreateBitOr.sql');
205
* Ignore errors here, since we'll get them every time we try to
206
* install the aggregate, which will happen every time we upgrade core
207
* or install in a database with another Gallery already present.
209
* XXX: At some point figure out a way to detect if the aggregate is
210
* already there before trying to install it again.
214
$ret = parent::configureStore($moduleId, $upgradeInfo);
216
return $ret->wrap(__FILE__, __LINE__);
223
* Get database version.
224
* @return string version
226
function getVersion() {
227
if (function_exists('oci_server_version')) {
228
return oci_server_version();
230
return ociserverversion();
234
* @see GalleryStorage::_getOptimizeStatement
236
function _getOptimizeStatement() {
237
/* Is this the right command to use? */
238
return 'ANALYZE TABLE %s COMPUTE STATISTICS';
242
* @see GalleryStorage::_normalizeValue
244
function _normalizeValue($value, $memberData, $fromDb=false) {
245
if ($fromDb && is_null($value) && ($memberData['type'] == STORAGE_TYPE_STRING
246
|| $memberData['type'] == STORAGE_TYPE_TEXT)) {
249
return parent::_normalizeValue($value, $memberData, $fromDb);