13 require_once dirname(__FILE__).
'/DALConverter.inc';
34 protected $name =
'Oracle';
42 protected $dataTypes = array(
44 'varchar' =>
'VARCHAR2',
48 'smallint' =>
'SMALLINT',
49 'numeric' =>
'NUMERIC',
52 'double_precision' =>
'DOUBLE PRECISION',
53 'boolean' =>
'CHAR(1)',
55 'time' =>
'TIMESTAMP',
56 'timestamp' =>
'TIMESTAMP',
58 'time with time zone' =>
'TIMESTAMP',
88 $sql .=
"\n".$this->convertCreateColumns($table).
',';
89 $sql .=
"\n".$this->convertConstraints($table[
'CONSTRAINTS']);
93 if ($indexes !==
'') {
94 $sql .=
"\n".$indexes;
97 if (isset($table[
'SEQUENCES']) === TRUE) {
98 $sql .=
"\n".$this->convertCreateSequences($table[
'SEQUENCES']);
121 if (strtolower($col[
'type']) ===
'boolean') {
122 if ($col[
'default'] !==
'') {
123 if (strtolower($col[
'default']) ===
'false') {
124 $col[
'default'] =
"'0'";
125 }
else if (strtolower($col[
'default']) ===
'true') {
126 $col[
'default'] =
"'1'";
131 return parent::convertSingleCreateColumn($col);
149 $sql = $seqName[0].
'.nextval';
167 $sql = $seqName[0].
'.currval';
184 if (is_array($tableName) === TRUE) {
185 $tableName = $tableName[0];
188 $sql =
'SELECT count(table_name) FROM user_tables WHERE table_name = UPPER('.$tableName.
')';
204 if (is_array($sequenceName) === TRUE) {
205 $sequenceName = $sequenceName[0];
208 $sql =
'SELECT count(sequence_name) FROM user_sequences WHERE sequence_name = UPPER('.$sequenceName.
')';
228 $sql =
'TO_DATE('.$iso8601_date.
', \'YYYY-MM-DD HH24:MI:SS\')';
244 $firstSelectQuery = $withQuery[
'AFTER'];
249 $secondSelectQuery = $withQuery[
'UNION-ALL'][
'SELECTS'][1];
251 $sql .=
'CONNECT BY PRIOR ';
254 $sql .=
'START WITH ';
255 if (isset($firstSelectQuery[
'WHERE']) === TRUE) {
276 $sql =
'DROP TABLE '.$tableName;
277 if ($cascade === TRUE) {
278 $sql .=
' CASCADE CONSTRAINTS';
301 if (empty($sqlArray[
'FROM'])) {
302 $sqlArray[
'FROM'] = Array(
'dual');
305 $sql = parent::convertSelectQuery($sqlArray, $level, $ignore);
308 if (isset($sqlArray[
'START-WITH']) === TRUE) {
309 $sql .=
"\n".$this->getConstructName(
'start-with');
311 $startWith = trim($startWith);
312 $startWith = trim($startWith,
'()');
313 $sql .=
"\n".$startWith;
317 if (isset($sqlArray[
'CONNECT-BY']) === TRUE) {
318 $sql .=
"\n".$this->getConstructName(
'connect-by');
320 $connectBy = trim($connectBy);
321 $connectBy = trim($connectBy,
'()');
322 $sql .=
"\n".$connectBy;
357 $sql =
"(\n".$this->addSpaces($level);
359 $sql .=
') '.$union[$type][
'alias'];
376 $sql .=
' WHERE row_num >= '.($limit[
'offset'] + 1);
396 if (isset($this->query[
'LIMIT']) === TRUE) {
400 foreach ($names as $name) {
401 $namesStr[] =
'col_'.($counter++).
' as '.$name;
404 $nameStr = implode(
', ', $namesStr);
405 $sql = $nameStr.
' FROM (SELECT ';
408 foreach ($fields as $field) {
413 $sql .= $this->
addSpaces($level).$this->separateFields($list);
414 $sql .=
', rownum as row_num';
418 foreach ($fields as $field) {
422 $sql = $this->
addSpaces($level).$this->separateFields($list);
443 if (isset($this->query[
'LIMIT']) === TRUE) {
444 $limit = $this->query[
'LIMIT'];
445 if (isset($this->query[
'WHERE']) === TRUE) {
451 $sql .=
' rownum <= '.($limit[
'rows'] + $limit[
'offset']);
455 if (isset($sqlArray[
'GROUP-BY']) === TRUE) {
460 if (isset($sqlArray[
'HAVING']) === TRUE) {
461 $sql .=
"\n".$this->getConstructName(
'having');
462 $sql .=
"\n".$this->convertWhereClause($sqlArray[
'HAVING']);
466 if (isset($sqlArray[
'ORDER-BY']) === TRUE) {
467 $sql .=
"\n".$this->convertOrderBy($sqlArray[
'ORDER-BY']);
471 if (isset($sqlArray[
'LIMIT']) === TRUE) {
472 $sql .=
"\n".$this->convertLimit($sqlArray[
'LIMIT']);
494 if (count($args) != 2 && count($args) != 3) {
495 $msg =
'The SUBSTR() function only accepts two or three parameters.';
501 $length = isset($args[2]) ?
",$args[2]" :
'';
502 $sql =
"SUBSTR($input, $start $length)";