46 if (($this->options & self::PERSISTENT) != 0)
47 $connection = oci_pconnect($this->login, $this->password, $this->database);
49 $connection = oci_new_connect($this->login, $this->password, $this->database);
55 $this->resource = $connection;
57 $this->afterConnected();
108 oci_bind_by_name($result,
":".$key, $clob[$key], -1, OCI_B_CLOB);
166 list($sql, $binds, $offset, $limit) = self::parseQueryFunctionArgs(func_get_args());
170 $binds1 = $binds2 =
"";
171 foreach ($binds as $key => $value)
187 $sql .=
" RETURNING ".$binds1.
" INTO ".$binds2;
190 return parent::query($sql, $binds, $offset, $limit);
196 public function add($tableName, array $data, $identity =
"ID")
198 if($identity !==
null && !isset($data[$identity]))
199 $data[$identity] = $this->
getNextId(
"sq_".$tableName);
201 $insert = $this->getSqlHelper()->prepareInsert($tableName, $data);
206 "INSERT INTO ".$tableName.
"(".$insert[0].
") ".
207 "VALUES (".$insert[1].
")";
209 $this->queryExecute($sql, $binds);
211 $this->lastInsertedId = $data[$identity];
213 return $data[$identity];
288 public function getIndexName($tableName, array $columns, $strict =
false)
298 $result = $this->
query(
"SELECT * FROM USER_IND_COLUMNS WHERE TABLE_NAME = upper('".$this->getSqlHelper()->forSql($tableName).
"')");
299 while ($ar = $result->fetch())
301 $indexes[$ar[
"INDEX_NAME"]][$ar[
"COLUMN_POSITION"] - 1] = $ar[
"COLUMN_NAME"];
302 if (strncmp($ar[
"COLUMN_NAME"],
"SYS_NC", 6) === 0)
310 $result = $this->
query(
"SELECT * FROM USER_IND_EXPRESSIONS WHERE TABLE_NAME = upper('".$this->getSqlHelper()->forSql($tableName).
"')");
311 while ($ar = $result->fetch())
313 $indexes[$ar[
"INDEX_NAME"]][$ar[
"COLUMN_POSITION"] - 1] = $ar[
"COLUMN_EXPRESSION"];
317 return static::findIndex($indexes, $columns, $strict);
341 public function createTable($tableName, $fields, $primary = array(), $autoincrement = array())
343 $sql =
'CREATE TABLE '.$this->getSqlHelper()->quote($tableName).
' (';
344 $sqlFields = array();
346 foreach ($fields as $columnName => $field)
351 'Field `%s` should be an Entity\ScalarField instance', $columnName
355 $realColumnName = $field->getColumnName();
357 $sqlFields[] = $this->getSqlHelper()->quote($realColumnName)
358 .
' ' . $this->getSqlHelper()->getColumnTypeByField($field)
359 .
' ' . (in_array($columnName, $primary,
true) ?
'NOT NULL' :
'NULL')
363 $sql .= join(
', ', $sqlFields);
365 if (!empty($primary))
367 foreach ($primary as &$primaryColumn)
369 $realColumnName = $fields[$primaryColumn]->getColumnName();
370 $primaryColumn = $this->getSqlHelper()->quote($realColumnName);
373 $sql .=
', PRIMARY KEY('.join(
', ', $primary).
')';
381 if (!empty($autoincrement))
383 foreach ($autoincrement as $autoincrementColumn)
385 $autoincrementColumn = $fields[$autoincrementColumn]->getColumnName();
387 if ($autoincrementColumn ==
'ID')
390 $aiName = $tableName;
394 $aiName = $tableName.
'_'.$autoincrementColumn;
397 $this->
query(
'CREATE SEQUENCE '.$this->getSqlHelper()->quote(
'sq_'.$aiName));
399 $this->
query(
'CREATE OR REPLACE TRIGGER '.$this->getSqlHelper()->quote($aiName.
'_insert').
'
401 ON '.$this->getSqlHelper()->quote($tableName).
'
404 IF :NEW.'.$this->getSqlHelper()->quote($autoincrementColumn).
' IS NULL THEN
405 SELECT '.$this->getSqlHelper()->quote(
'sq_'.$aiName).
'.NEXTVAL
406 INTO :NEW.'.$this->getSqlHelper()->quote($autoincrementColumn).
' FROM dual;
419 $this->
query(
'RENAME '.$this->getSqlHelper()->quote($currentName).
' TO '.$this->getSqlHelper()->quote($newName));
423 $aiName = $currentName;
425 if ($this->queryScalar(
"SELECT 1 FROM user_sequences WHERE sequence_name=upper('".$this->getSqlHelper()->forSql(
'sq_'.$aiName).
"')"))
428 $newAiName = $newName;
431 $this->
query(
'RENAME '.$this->getSqlHelper()->quote(
'sq_'.$aiName).
' TO '.$this->getSqlHelper()->quote(
'sq_'.$newAiName));
434 $this->
query(
'DROP TRIGGER '.$this->getSqlHelper()->quote($aiName.
'_insert'));
436 $this->
query(
'CREATE OR REPLACE TRIGGER '.$this->getSqlHelper()->quote($newAiName.
'_insert').
'
438 ON '.$this->getSqlHelper()->quote($newName).
'
441 IF :NEW.'.$this->getSqlHelper()->quote(
'ID').
' IS NULL THEN
442 SELECT '.$this->getSqlHelper()->quote(
'sq_'.$newAiName).
'.NEXTVAL
443 INTO :NEW.'.$this->getSqlHelper()->quote(
'ID').
' FROM dual;
522 if ($this->version ==
null)
524 $version = $this->queryScalar(
'SELECT BANNER FROM v$version');
525 if ($version !=
null)
527 $version = trim($version);
528 $this->versionExpress = (mb_strpos($version,
"Express Edition") > 0);
529 preg_match(
"#[0-9]+\\.[0-9]+\\.[0-9]+#", $version, $arr);
530 $this->version = $arr[0];
534 return array($this->version, $this->versionExpress);