10 defined(
'JPATH_PLATFORM') or die;
28 public $name =
'oracle';
39 protected $nameQuote =
'"';
64 public function __construct($options)
66 $options[
'driver'] =
'oci';
67 $options[
'charset'] = (isset($options[
'charset'])) ? $options[
'charset'] :
'AL32UTF8';
68 $options[
'dateformat'] = (isset($options[
'dateformat'])) ? $options[
'dateformat'] :
'RRRR-MM-DD HH24:MI:SS';
70 $this->charset = $options[
'charset'];
71 $this->dateformat = $options[
'dateformat'];
74 parent::__construct($options);
82 public function __destruct()
85 unset($this->connection);
96 public function connect()
98 if ($this->connection)
105 if (isset($this->options[
'schema']))
107 $this->setQuery(
'ALTER SESSION SET CURRENT_SCHEMA = ' . $this->quoteName($this->options[
'schema']))->execute();
110 $this->setDateFormat($this->dateformat);
120 public function disconnect()
124 unset($this->connection);
139 public function dropTable($tableName, $ifExists =
true)
143 $query = $this->getQuery(
true)
144 ->setQuery(
'DROP TABLE :tableName');
145 $query->bind(
':tableName', $tableName);
147 $this->setQuery($query);
161 public function getCollation()
163 return $this->charset;
173 public function getConnectedQuery()
175 return 'SELECT 1 FROM dual';
189 public function getDateFormat()
191 return $this->dateformat;
207 public function getTableCreate($tables)
212 $query = $this->getQuery(
true)
213 ->select(
'dbms_metadata.get_ddl(:type, :tableName)')
215 ->bind(
':type',
'TABLE');
218 settype($tables,
'array');
219 foreach ($tables as $table)
221 $query->bind(
':tableName', $table);
222 $this->setQuery($query);
223 $statement = (string) $this->loadResult();
224 $result[$table] = $statement;
241 public function getTableColumns($table, $typeOnly =
true)
246 $query = $this->getQuery(
true);
248 $fieldCasing = $this->getOption(PDO::ATTR_CASE);
250 $this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
252 $table = strtoupper($table);
255 $query->from(
'ALL_TAB_COLUMNS');
256 $query->where(
'table_name = :tableName');
258 $prefixedTable = str_replace(
'#__', strtoupper($this->tablePrefix), $table);
259 $query->bind(
':tableName', $prefixedTable);
260 $this->setQuery($query);
261 $fields = $this->loadObjectList();
265 foreach ($fields as $field)
267 $columns[$field->COLUMN_NAME] = $field->DATA_TYPE;
272 foreach ($fields as $field)
274 $columns[$field->COLUMN_NAME] = $field;
275 $columns[$field->COLUMN_NAME]->Default = null;
279 $this->setOption(PDO::ATTR_CASE, $fieldCasing);
294 public function getTableKeys($table)
298 $query = $this->getQuery(
true);
300 $fieldCasing = $this->getOption(PDO::ATTR_CASE);
302 $this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
304 $table = strtoupper($table);
306 ->from(
'ALL_CONSTRAINTS')
307 ->where(
'table_name = :tableName')
308 ->bind(
':tableName', $table);
310 $this->setQuery($query);
311 $keys = $this->loadObjectList();
313 $this->setOption(PDO::ATTR_CASE, $fieldCasing);
329 public function getTableList($databaseName = null, $includeDatabaseName =
false)
333 $query = $this->getQuery(
true);
335 if ($includeDatabaseName)
337 $query->select(
'owner, table_name');
341 $query->select(
'table_name');
344 $query->from(
'all_tables');
347 $query->where(
'owner = :database')
348 ->bind(
':database', $databaseName);
351 $query->order(
'table_name');
353 $this->setQuery($query);
355 if ($includeDatabaseName)
357 $tables = $this->loadAssocList();
361 $tables = $this->loadColumn();
374 public function getVersion()
378 $this->setQuery(
"select value from nls_database_parameters where parameter = 'NLS_RDBMS_VERSION'");
380 return $this->loadResult();
393 public function select($database)
414 public function setDateFormat($dateFormat =
'DD-MON-RR')
418 $this->setQuery(
"ALTER SESSION SET NLS_DATE_FORMAT = '$dateFormat'");
420 if (!$this->execute())
425 $this->setQuery(
"ALTER SESSION SET NLS_TIMESTAMP_FORMAT = '$dateFormat'");
426 if (!$this->execute())
431 $this->dateformat = $dateFormat;
447 public function setUTF()
462 public function lockTable($table)
464 $this->setQuery(
'LOCK TABLE ' . $this->quoteName($table) .
' IN EXCLUSIVE MODE')->execute();
482 public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
484 $this->setQuery(
'RENAME ' . $oldTable .
' TO ' . $newTable)->execute();
497 public function unlockTables()
499 $this->setQuery(
'COMMIT')->execute();
511 public static function isSupported()
513 return class_exists(
'PDO') && in_array(
'oci', PDO::getAvailableDrivers());
527 public function replacePrefix($query, $prefix =
'#__')
533 $query = trim($query);
536 while ($startPos < $n)
538 $ip = strpos($query, $prefix, $startPos);
544 $j = strpos($query,
"'", $startPos);
551 $literal .= str_replace($prefix, $this->tablePrefix, substr($query, $startPos, $j - $startPos));
564 $k = strpos($query, $quoteChar, $j);
571 while ($l >= 0 && $query{$l} ==
'\\')
574 $escaped = !$escaped;
588 $literal .= substr($query, $startPos, $k - $startPos + 1);
593 $literal .= substr($query, $startPos, $n - $startPos);
609 public function transactionCommit($toSavepoint =
false)
613 if (!$toSavepoint || $this->transactionDepth <= 1)
615 parent::transactionCommit($toSavepoint);
619 $this->transactionDepth--;
633 public function transactionRollback($toSavepoint =
false)
637 if (!$toSavepoint || $this->transactionDepth <= 1)
639 parent::transactionRollback($toSavepoint);
643 $savepoint =
'SP_' . ($this->transactionDepth - 1);
644 $this->setQuery(
'ROLLBACK TO SAVEPOINT ' . $this->quoteName($savepoint));
646 if ($this->execute())
648 $this->transactionDepth--;
663 public function transactionStart($asSavepoint =
false)
667 if (!$asSavepoint || !$this->transactionDepth)
669 return parent::transactionStart($asSavepoint);
672 $savepoint =
'SP_' . $this->transactionDepth;
673 $this->setQuery(
'SAVEPOINT ' . $this->quoteName($savepoint));
675 if ($this->execute())
677 $this->transactionDepth++;