18 if (!defined(
'ADODB_DIR'))
die();
41 # define the LOB descriptor type for the given type 42 # returns false if no LOB descriptor 45 case OCI_B_BFILE:
$result = OCI_D_FILE;
break;
46 case OCI_B_CFILEE:
$result = OCI_D_FILE;
break;
47 case OCI_B_CLOB:
$result = OCI_D_LOB;
break;
48 case OCI_B_BLOB:
$result = OCI_D_LOB;
break;
49 case OCI_B_ROWID:
$result = OCI_D_ROWID;
break;
50 default:
$result =
false;
break;
62 var
$metaDatabasesSQL =
"SELECT USERNAME FROM ALL_USERS WHERE USERNAME NOT IN ('SYS','SYSTEM','DBSNMP','OUTLN') ORDER BY 1";
66 var
$metaTablesSQL =
"select table_name,table_type from cat where table_type in ('TABLE','VIEW') and table_name not like 'BIN\$%'";
67 var
$metaColumnsSQL =
"select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno";
68 var
$metaColumnsSQL2 =
"select column_name,data_type,data_length, data_scale, data_precision, 69 case when nullable = 'Y' then 'NULL' 70 else 'NOT NULL' end as nulls, 71 data_default from all_tab_cols 72 where owner='%s' and table_name='%s' order by column_id";
78 PRAGMA AUTONOMOUS_TRANSACTION; 80 execute immediate 'CREATE SEQUENCE %s START WITH %s'; 86 var
$random =
"abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
107 $this->_hasOciFetchStatement = ADODB_PHPVER >= 0x4200;
108 if (defined(
'ADODB_EXTENSION')) $this->rsPrefix .=
'ext_';
114 global $ADODB_FETCH_MODE;
117 $this->_findschema($table, $schema);
120 $save = $ADODB_FETCH_MODE;
121 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
122 if ($this->fetchMode !==
false) $savem = $this->SetFetchMode(
false);
125 $rs = $this->
Execute(sprintf($this->metaColumnsSQL2, strtoupper($schema), strtoupper($table)));
127 $rs = $this->
Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
129 if (isset($savem)) $this->SetFetchMode($savem);
130 $ADODB_FETCH_MODE = $save;
136 $fld =
new ADOFieldObject();
137 $fld->name =
$rs->fields[0];
138 $fld->type =
$rs->fields[1];
139 $fld->max_length =
$rs->fields[2];
140 $fld->scale =
$rs->fields[3];
141 if (
$rs->fields[1] ==
'NUMBER') {
142 if (
$rs->fields[3] == 0) $fld->type =
'INT';
143 $fld->max_length =
$rs->fields[4];
145 $fld->not_null = (strncmp(
$rs->fields[5],
'NOT',3) === 0);
146 $fld->binary = (strpos($fld->type,
'BLOB') !==
false);
147 $fld->default_value =
$rs->fields[6];
149 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
150 else $retarr[strtoupper($fld->name)] = $fld;
162 $rs = $this->
Execute(
"select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual");
163 if (
$rs && !
$rs->EOF)
return $this->UnixTimeStamp(reset(
$rs->fields));
194 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename=null, $mode=0)
196 if (!function_exists(
'oci_pconnect'))
return null;
199 $this->_errorMsg =
false;
200 $this->_errorCode =
false;
203 if (empty($argDatabasename)) $argDatabasename = $argHostname;
205 if(strpos($argHostname,
":")) {
206 $argHostinfo=explode(
":",$argHostname);
207 $argHostname=$argHostinfo[0];
208 $argHostport=$argHostinfo[1];
210 $argHostport = empty($this->port)?
"1521" : $this->port;
213 if (strncasecmp($argDatabasename,
'SID=',4) == 0) {
214 $argDatabasename = substr($argDatabasename,4);
215 $this->connectSID =
true;
218 if ($this->connectSID) {
219 $argDatabasename=
"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
220 .
")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
222 $argDatabasename=
"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
223 .
")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
229 $this->_connectionID = ($this->charSet)
230 ? oci_pconnect($argUsername,$argPassword, $argDatabasename,$this->charSet)
231 : oci_pconnect($argUsername,$argPassword, $argDatabasename);
232 if ($this->_connectionID && $this->autoRollback) oci_rollback($this->_connectionID);
233 }
else if ($mode==2) {
234 $this->_connectionID = ($this->charSet)
235 ? oci_new_connect($argUsername,$argPassword, $argDatabasename,$this->charSet)
236 : oci_new_connect($argUsername,$argPassword, $argDatabasename);
238 $this->_connectionID = ($this->charSet)
239 ? oci_connect($argUsername,$argPassword, $argDatabasename,$this->charSet)
240 : oci_connect($argUsername,$argPassword, $argDatabasename);
242 if (!$this->_connectionID) {
246 if ($this->_initdate) {
247 $this->
Execute(
"ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT.
"'");
259 $arr[
'compat'] = $this->GetOne(
'select value from sys.database_compatible_level');
260 $arr[
'description'] = @oci_server_version($this->_connectionID);
261 $arr[
'version'] = ADOConnection::_findvers($arr[
'description']);
265 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
267 return $this->
_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1);
271 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
273 return $this->
_connect($argHostname, $argUsername, $argPassword, $argDatabasename,2);
278 if (is_resource($this->_stmt))
return @oci_num_rows($this->_stmt);
284 return " NVL($field, $ifNull) ";
290 if (empty($d) && $d !== 0)
return 'null';
293 $d = _adodb_safedate($d);
294 return 'TO_DATE('.$d.
",'".$this->dateformat.
"')";
297 if (is_string($d)) $d = ADORecordSet::UnixDate($d);
299 if (is_object($d)) $ds = $d->format($this->fmtDate);
302 return "TO_DATE(".$ds.
",'".$this->dateformat.
"')";
307 $d = ADOConnection::DBDate($d);
308 if (strncmp($d,
"'",1))
return $d;
310 return substr($d,1,strlen($d)-2);
315 if (empty($ts) && $ts !== 0)
return 'null';
316 if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
318 if (is_object($ts)) $tss = $ts->format(
"'Y-m-d H:i:s'");
327 if (empty($ts) && $ts !== 0)
return 'null';
328 if ($isfld)
return 'TO_DATE(substr('.$ts.
",1,19),'RRRR-MM-DD, HH24:MI:SS')";
329 if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
331 if (is_object($ts)) $tss = $ts->format(
"'Y-m-d H:i:s'");
332 else $tss = date(
"'Y-m-d H:i:s'",$ts);
334 return 'TO_DATE('.$tss.
",'RRRR-MM-DD, HH24:MI:SS')";
337 function RowLock($tables,$where,$col=
'1 as adodbignore')
340 return $this->GetOne(
"select $col from $tables where $where for update");
343 function MetaTables($ttype=
false,$showSchema=
false,$mask=
false)
347 $mask = $this->
qstr(strtoupper($mask));
348 $this->metaTablesSQL .=
" AND upper(table_name) like $mask";
350 $ret = ADOConnection::MetaTables($ttype,$showSchema);
353 $this->metaTablesSQL = $save;
362 global $ADODB_FETCH_MODE;
364 $save = $ADODB_FETCH_MODE;
365 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
367 if ($this->fetchMode !== FALSE) {
368 $savem = $this->SetFetchMode(FALSE);
372 $table = strtoupper($table);
378 $rs = $this->
Execute(sprintf(
"SELECT * FROM ALL_CONSTRAINTS WHERE UPPER(TABLE_NAME)='%s' AND CONSTRAINT_TYPE='P'",$table));
379 if (!is_object(
$rs)) {
381 $this->SetFetchMode($savem);
382 $ADODB_FETCH_MODE = $save;
386 if ($row =
$rs->FetchRow())
387 $primary_key = $row[1];
389 if ($primary==TRUE && $primary_key==
'') {
391 $this->SetFetchMode($savem);
392 $ADODB_FETCH_MODE = $save;
396 $rs = $this->
Execute(sprintf(
"SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME",$table));
399 if (!is_object(
$rs)) {
401 $this->SetFetchMode($savem);
402 $ADODB_FETCH_MODE = $save;
409 while ($row =
$rs->FetchRow()) {
410 if ($primary && $row[0] != $primary_key)
continue;
411 if (!isset($indexes[$row[0]])) {
412 $indexes[$row[0]] = array(
413 'unique' => ($row[1] ==
'UNIQUE'),
417 $indexes[$row[0]][
'columns'][$row[2] - 1] = $row[3];
421 foreach ( array_keys ($indexes) as $index ) {
422 ksort ($indexes[$index][
'columns']);
426 $this->SetFetchMode($savem);
427 $ADODB_FETCH_MODE = $save;
434 if ($this->transOff)
return true;
435 $this->transCnt += 1;
436 $this->autoCommit =
false;
437 $this->_commit = OCI_DEFAULT;
439 if ($this->_transmode) $ok = $this->
Execute(
"SET TRANSACTION ".$this->_transmode);
442 return $ok ? true :
false;
447 if ($this->transOff)
return true;
450 if ($this->transCnt) $this->transCnt -= 1;
451 $ret = oci_commit($this->_connectionID);
452 $this->_commit = OCI_COMMIT_ON_SUCCESS;
453 $this->autoCommit =
true;
459 if ($this->transOff)
return true;
460 if ($this->transCnt) $this->transCnt -= 1;
461 $ret = oci_rollback($this->_connectionID);
462 $this->_commit = OCI_COMMIT_ON_SUCCESS;
463 $this->autoCommit =
true;
475 if ($this->_errorMsg !==
false)
return $this->_errorMsg;
477 if (is_resource($this->_stmt)) $arr = @oci_error($this->_stmt);
479 if (is_resource($this->_connectionID)) $arr = @oci_error($this->_connectionID);
480 else $arr = @oci_error();
481 if ($arr ===
false)
return '';
483 $this->_errorMsg = $arr[
'message'];
484 $this->_errorCode = $arr[
'code'];
485 return $this->_errorMsg;
490 if ($this->_errorCode !==
false)
return $this->_errorCode;
492 if (is_resource($this->_stmt)) $arr = @oci_error($this->_stmt);
494 $arr = @oci_error($this->_connectionID);
495 if ($arr ==
false) $arr = @oci_error();
496 if ($arr ==
false)
return '';
499 $this->_errorMsg = $arr[
'message'];
500 $this->_errorCode = $arr[
'code'];
511 $s =
'TO_CHAR('.$col.
",'";
514 for ($i=0; $i < $len; $i++) {
575 $ch = substr($fmt,$i,1);
577 if (strpos(
'-/.:;, ',$ch) !==
false) $s .= $ch;
578 else $s .=
'"'.$ch.
'"';
587 $sql =
"SELECT * FROM ($sql ORDER BY dbms_random.value) WHERE rownum = 1";
589 return $this->GetRow(
$sql,$arr);
611 if ($this->firstrows) {
612 if ($nrows > 500 && $nrows < 1000) $hint =
"FIRST_ROWS($nrows)";
613 else $hint =
'FIRST_ROWS';
615 if (strpos(
$sql,
'/*+') !==
false)
616 $sql = str_replace(
'/*+ ',
"/*+$hint ",
$sql);
618 $sql = preg_replace(
'/^[ \t\n]*select/i',
"SELECT /*+$hint*/",
$sql);
619 $hint =
"/*+ $hint */";
623 if ($offset == -1 || ($offset < $this->selectOffsetAlg1 && 0 < $nrows && $nrows < 1000)) {
625 if ($offset > 0) $nrows += $offset;
627 if ($this->databaseType ==
'oci8po') {
628 $sql =
"select * from (".$sql.
") where rownum <= ?";
630 $sql =
"select * from (".$sql.
") where rownum <= :adodb_offset";
632 $inputarr[
'adodb_offset'] = $nrows;
637 $rs = ADOConnection::SelectLimit(
$sql,$nrows,$offset,$inputarr,$secs2cache);
644 $q_fields =
"SELECT * FROM (".$sql.
") WHERE NULL = NULL";
647 if (! $stmt_arr = $this->
Prepare($q_fields)) {
650 $stmt = $stmt_arr[1];
652 if (is_array($inputarr)) {
653 foreach($inputarr as $k => $v) {
656 oci_bind_by_name($stmt,
":$k",$inputarr[$k][0],$v[1]);
658 oci_bind_by_name($stmt,
":$k",$inputarr[$k][0],$v[1],$v[2]);
661 if ($v ===
' ') $len = 1;
662 if (isset($bindarr)) {
665 oci_bind_by_name($stmt,
":$k",$inputarr[$k],$len);
671 if (!oci_execute($stmt, OCI_DEFAULT)) {
672 oci_free_statement($stmt);
676 $ncols = oci_num_fields($stmt);
677 for ( $i = 1; $i <= $ncols; $i++ ) {
678 $cols[] =
'"'.oci_field_name($stmt, $i).
'"';
682 oci_free_statement($stmt);
683 $fields = implode(
',', $cols);
684 if ($nrows <= 0) $nrows = 999999999999;
685 else $nrows += $offset;
688 if ($this->databaseType ==
'oci8po') {
689 $sql =
"SELECT $hint $fields FROM".
690 "(SELECT rownum as adodb_rownum, $fields FROM".
691 " ($sql) WHERE rownum <= ?".
692 ") WHERE adodb_rownum >= ?";
694 $sql =
"SELECT $hint $fields FROM".
695 "(SELECT rownum as adodb_rownum, $fields FROM".
696 " ($sql) WHERE rownum <= :adodb_nrows".
697 ") WHERE adodb_rownum >= :adodb_offset";
699 $inputarr[
'adodb_nrows'] = $nrows;
700 $inputarr[
'adodb_offset'] = $offset;
702 if ($secs2cache>0)
$rs = $this->CacheExecute($secs2cache,
$sql,$inputarr);
726 function UpdateBlob($table,$column,$val,$where,$blobtype=
'BLOB')
731 switch(strtoupper($blobtype)) {
732 default: ADOConnection::outp(
"<b>UpdateBlob</b>: Unknown blobtype=$blobtype");
return false;
733 case 'BLOB': $type = OCI_B_BLOB;
break;
734 case 'CLOB': $type = OCI_B_CLOB;
break;
737 if ($this->databaseType ==
'oci8po')
738 $sql =
"UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?";
740 $sql =
"UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob";
742 $desc = oci_new_descriptor($this->_connectionID, OCI_D_LOB);
743 $arr[
'blob'] = array($desc,-1,$type);
744 if ($this->session_sharing_force_blob) $this->
Execute(
'ALTER SESSION SET CURSOR_SHARING=EXACT');
745 $commit = $this->autoCommit;
747 $rs = $this->_Execute(
$sql,$arr);
748 if ($rez = !empty(
$rs)) $desc->save($val);
751 if ($this->session_sharing_force_blob) $this->
Execute(
'ALTER SESSION SET CURSOR_SHARING=FORCE');
753 if ($rez)
$rs->Close();
762 switch(strtoupper($blobtype)) {
763 default: ADOConnection::outp(
"<b>UpdateBlob</b>: Unknown blobtype=$blobtype");
return false;
764 case 'BLOB': $type = OCI_B_BLOB;
break;
765 case 'CLOB': $type = OCI_B_CLOB;
break;
768 if ($this->databaseType ==
'oci8po')
769 $sql =
"UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?";
771 $sql =
"UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob";
773 $desc = oci_new_descriptor($this->_connectionID, OCI_D_LOB);
774 $arr[
'blob'] = array($desc,-1,$type);
778 if ($rez = !empty(
$rs)) $desc->savefile($val);
782 if ($rez)
$rs->Close();
795 if ($this->fnExecute) {
796 $fn = $this->fnExecute;
797 $ret = $fn($this,
$sql,$inputarr);
798 if (isset($ret))
return $ret;
800 if ($inputarr !==
false) {
801 if (!is_array($inputarr)) $inputarr = array($inputarr);
803 $element0 = reset($inputarr);
804 $array2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0));
806 # see http://phplens.com/lens/lensforum/msgs.php?id=18786 807 if ($array2d || !$this->_bindInputArray) {
809 # is_object check because oci8 descriptors can be passed in 810 if ($array2d && $this->_bindInputArray) {
816 foreach($inputarr as $arr) {
817 $ret = $this->_Execute($stmt,$arr);
818 if (!$ret)
return $ret;
822 $sqlarr = explode(
':',
$sql);
825 #var_dump($sqlarr);echo "<hr>";var_dump($inputarr);echo"<hr>"; 826 foreach($sqlarr as $k => $str) {
827 if ($k == 0) {
$sql = $str;
continue; }
830 $ok = preg_match(
'/^([0-9]*)/', $str, $arr);
832 if (!$ok)
$sql .= $str;
835 if (isset($inputarr[$at]) || is_null($inputarr[$at])) {
836 if ((strlen($at) == strlen($str) && $k <
sizeof($arr)-1)) {
839 }
else if ($lastnomatch == $k-1) {
842 if (is_null($inputarr[$at]))
$sql .=
'null';
843 else $sql .= $this->
qstr($inputarr[$at]);
844 $sql .= substr($str, strlen($at));
855 $ret = $this->_Execute(
$sql,$inputarr);
859 $ret = $this->_Execute(
$sql,
false);
873 $stmt = oci_parse($this->_connectionID,
$sql);
876 $this->_errorMsg =
false;
877 $this->_errorCode =
false;
878 $arr = @oci_error($this->_connectionID);
879 if ($arr ===
false)
return false;
881 $this->_errorMsg = $arr[
'message'];
882 $this->_errorCode = $arr[
'code'];
888 $sttype = @oci_statement_type($stmt);
889 if ($sttype ==
'BEGIN' || $sttype ==
'DECLARE') {
890 return array(
$sql,$stmt,0,$BINDNUM, ($cursor) ? oci_new_cursor($this->_connectionID) :
false);
892 return array(
$sql,$stmt,0,$BINDNUM);
914 if (is_array($stmt) &&
sizeof($stmt) >= 5) {
917 $this->
Parameter($stmt, $ignoreCur, $cursorName,
false, -1, OCI_B_CURSOR);
919 foreach($params as $k => $v) {
928 if (
$rs->databaseType ==
'array') oci_free_cursor($stmt[4]);
929 else if ($hasref)
$rs->_refcursor = $stmt[4];
963 function Bind(&$stmt,&$var,$size=4000,$type=
false,$name=
false,$isOutput=
false)
966 if (!is_array($stmt))
return false;
968 if (($type == OCI_B_CURSOR) &&
sizeof($stmt) >= 5) {
969 return oci_bind_by_name($stmt[1],
":".$name,$stmt[4],$size,$type);
972 if ($name ==
false) {
973 if ($type !==
false) $rez = oci_bind_by_name($stmt[1],
":".$stmt[2],$var,$size,$type);
974 else $rez = oci_bind_by_name($stmt[1],
":".$stmt[2],$var,$size);
978 ADOConnection::outp(
"<b>Bind</b>: name = $name");
981 $numlob = count($this->_refLOBs);
982 $this->_refLOBs[$numlob][
'LOB'] = oci_new_descriptor($this->_connectionID,
oci_lob_desc($type));
983 $this->_refLOBs[$numlob][
'TYPE'] = $isOutput;
985 $tmp = $this->_refLOBs[$numlob][
'LOB'];
986 $rez = oci_bind_by_name($stmt[1],
":".$name, $tmp, -1, $type);
988 ADOConnection::outp(
"<b>Bind</b>: descriptor has been allocated, var (".$name.
") binded");
992 if ($isOutput ==
false) {
993 $var = $this->BlobEncode($var);
994 $tmp->WriteTemporary($var);
995 $this->_refLOBs[$numlob][
'VAR'] = &$var;
997 ADOConnection::outp(
"<b>Bind</b>: LOB has been written to temp");
1000 $this->_refLOBs[$numlob][
'VAR'] = &$var;
1005 ADOConnection::outp(
"<b>Bind</b>: name = $name");
1007 if ($type !==
false) $rez = oci_bind_by_name($stmt[1],
":".$name,$var,$size,$type);
1008 else $rez = oci_bind_by_name($stmt[1],
":".$name,$var,$size);
1035 function Parameter(&$stmt,&$var,$name,$isOutput=
false,$maxLen=4000,$type=
false)
1038 $prefix = ($isOutput) ?
'Out' :
'In';
1039 $ztype = (empty($type)) ?
'false' : $type;
1040 ADOConnection::outp(
"{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);");
1042 return $this->
Bind($stmt,$var,$maxLen,$type,$name,$isOutput);
1062 if (is_array(
$sql)) {
1067 if (is_array($inputarr)) {
1069 if (isset($this->_bind[$bindpos])) {
1071 $bindarr = $this->_bind[$bindpos];
1075 foreach($inputarr as $k => $v) {
1077 oci_bind_by_name($stmt,
":$k",$bindarr[$k],is_string($v) && strlen($v)>4000 ? -1 : 4000);
1079 $this->_bind[$bindpos] = $bindarr;
1083 $stmt=oci_parse($this->_connectionID,
$sql);
1086 $this->_stmt = $stmt;
1087 if (!$stmt)
return false;
1089 if (defined(
'ADODB_PREFETCH_ROWS')) @oci_set_prefetch($stmt,ADODB_PREFETCH_ROWS);
1091 if (is_array($inputarr)) {
1092 foreach($inputarr as $k => $v) {
1094 if (
sizeof($v) == 2)
1095 oci_bind_by_name($stmt,
":$k",$inputarr[$k][0],$v[1]);
1097 oci_bind_by_name($stmt,
":$k",$inputarr[$k][0],$v[1],$v[2]);
1099 if ($this->
debug==99) {
1100 if (is_object($v[0]))
1101 echo
"name=:$k",
' len='.$v[1],
' type='.$v[2],
'<br>';
1103 echo
"name=:$k",
' var='.$inputarr[$k][0],
' len='.$v[1],
' type='.$v[2],
'<br>';
1108 if ($v ===
' ') $len = 1;
1109 if (isset($bindarr)) {
1112 oci_bind_by_name($stmt,
":$k",$inputarr[$k],$len);
1118 $this->_errorMsg =
false;
1119 $this->_errorCode =
false;
1120 if (oci_execute($stmt,$this->_commit)) {
1122 if (count($this -> _refLOBs) > 0) {
1124 foreach ($this -> _refLOBs as $key => $value) {
1125 if ($this -> _refLOBs[$key][
'TYPE'] ==
true) {
1126 $tmp = $this -> _refLOBs[$key][
'LOB'] -> load();
1127 if ($this ->
debug) {
1128 ADOConnection::outp(
"<b>OUT LOB</b>: LOB has been loaded. <br>");
1131 $this -> _refLOBs[$key][
'VAR'] = $tmp;
1133 $this->_refLOBs[$key][
'LOB']->save($this->_refLOBs[$key][
'VAR']);
1134 $this -> _refLOBs[$key][
'LOB']->free();
1135 unset($this -> _refLOBs[$key]);
1137 ADOConnection::outp(
"<b>IN LOB</b>: LOB has been saved. <br>");
1143 switch (@oci_statement_type($stmt)) {
1149 if (is_array(
$sql) && !empty(
$sql[4])) {
1151 if (is_resource($cursor)) {
1152 $ok = oci_execute($cursor);
1157 if (is_resource($stmt)) {
1158 oci_free_statement($stmt);
1201 if (!$this->_connectionID)
return;
1203 if (!$this->autoCommit) oci_rollback($this->_connectionID);
1204 if (count($this->_refLOBs) > 0) {
1205 foreach ($this ->_refLOBs as $key => $value) {
1206 $this->_refLOBs[$key][
'LOB']->free();
1207 unset($this->_refLOBs[$key]);
1210 oci_close($this->_connectionID);
1212 $this->_stmt =
false;
1213 $this->_connectionID =
false;
1218 if ($internalKey)
return array(
'ROWID');
1221 $table = strtoupper($table);
1223 $owner_clause =
"AND ((a.OWNER = b.OWNER) AND (a.OWNER = UPPER('$owner')))";
1230 SELECT /*+ RULE */ distinct b.column_name 1231 FROM {$ptab}CONSTRAINTS a 1232 , {$ptab}CONS_COLUMNS b 1233 WHERE ( UPPER(b.table_name) = ('$table')) 1234 AND (UPPER(a.table_name) = ('$table') and a.constraint_type = 'P') 1236 AND (a.constraint_name = b.constraint_name)";
1240 $arr =
$rs->GetArray();
1242 foreach($arr as $v) {
1262 global $ADODB_FETCH_MODE;
1264 $save = $ADODB_FETCH_MODE;
1265 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1266 $table = $this->
qstr(strtoupper($table));
1268 $owner = $this->user;
1273 $owner =
' and owner='.$this->qstr(strtoupper($owner));
1276 "select constraint_name,r_owner,r_constraint_name 1277 from {$tabp}constraints 1278 where constraint_type = 'R' and table_name = $table $owner";
1280 $constraints = $this->GetArray(
$sql);
1282 foreach($constraints as $constr) {
1283 $cons = $this->
qstr($constr[0]);
1284 $rowner = $this->
qstr($constr[1]);
1285 $rcons = $this->
qstr($constr[2]);
1286 $cols = $this->GetArray(
"select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position");
1287 $tabcol = $this->GetArray(
"select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position");
1289 if ($cols && $tabcol)
1290 for ($i=0, $max=
sizeof($cols); $i < $max; $i++) {
1291 $arr[$tabcol[$i][0]] = $cols[$i][0].
'='.$tabcol[$i][1];
1294 $ADODB_FETCH_MODE = $save;
1320 function qstr($s,$magic_quotes=
false)
1324 if ($this->noNullStrings && strlen($s)==0)$s =
' ';
1325 if (!$magic_quotes) {
1326 if ($this->replaceQuote[0] ==
'\\'){
1327 $s = str_replace(
'\\',
'\\\\',$s);
1329 return "'".str_replace(
"'",$this->replaceQuote,$s).
"'";
1333 if (!ini_get(
'magic_quotes_sybase')) {
1334 $s = str_replace(
'\\"',
'"',$s);
1335 $s = str_replace(
'\\\\',
'\\',$s);
1336 return "'".str_replace(
"\\'",$this->replaceQuote,$s).
"'";
1358 if ($mode ===
false) {
1359 global $ADODB_FETCH_MODE;
1360 $mode = $ADODB_FETCH_MODE;
1364 case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1365 case ADODB_FETCH_DEFAULT:
1366 case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1367 case ADODB_FETCH_NUM:
1369 $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1372 $this->adodbFetchMode = $mode;
1373 $this->_queryID = $queryID;
1379 if ($this->_inited)
return;
1381 $this->_inited =
true;
1382 if ($this->_queryID) {
1384 $this->_currentRow = 0;
1386 if ($this->_numOfFields) $this->EOF = !$this->_fetch();
1387 else $this->EOF =
true;
1396 if (!is_array($this->fields)) {
1397 $this->_numOfRows = 0;
1398 $this->fields = array();
1401 $this->fields = array();
1402 $this->_numOfRows = 0;
1403 $this->_numOfFields = 0;
1410 $this->_numOfRows = -1;
1411 $this->_numOfFields = oci_num_fields($this->_queryID);
1412 if ($this->_numOfFields>0) {
1413 $this->_fieldobjs = array();
1414 $max = $this->_numOfFields;
1415 for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i);
1429 $fld =
new ADOFieldObject;
1431 $fld->name =oci_field_name($this->_queryID, $fieldOffset);
1432 $fld->type = oci_field_type($this->_queryID, $fieldOffset);
1433 $fld->max_length = oci_field_size($this->_queryID, $fieldOffset);
1435 switch($fld->type) {
1437 $p = oci_field_precision($this->_queryID, $fieldOffset);
1438 $sc = oci_field_scale($this->_queryID, $fieldOffset);
1439 if ($p != 0 && $sc == 0) $fld->type =
'INT';
1446 $fld->max_length = -1;
1455 return $this->_fieldobjs[$fieldOffset];
1479 if ($this->fields = @oci_fetch_array($this->_queryID,$this->fetchMode)) {
1480 $this->_currentRow += 1;
1484 $this->_currentRow += 1;
1529 $arr = $this->GetArray($nrows);
1533 for ($i=1; $i < $offset; $i++)
1534 if (!@oci_fetch($this->_queryID))
return $arr;
1536 if (!$this->fields = @oci_fetch_array($this->_queryID,$this->fetchMode))
return $arr;;
1539 while (!$this->EOF && $nrows != $cnt) {
1540 $results[$cnt++] = $this->fields;
1552 $this->bind = array();
1553 for ($i=0; $i < $this->_numOfFields; $i++) {
1554 $o = $this->FetchField($i);
1555 $this->bind[strtoupper($o->name)] = $i;
1559 return $this->fields[$this->bind[strtoupper($colname)]];
1571 return $this->fields = @oci_fetch_array($this->_queryID,$this->fetchMode);
1581 if ($this->connection->_stmt === $this->_queryID) $this->connection->_stmt =
false;
1582 if (!empty($this->_refcursor)) {
1583 oci_free_cursor($this->_refcursor);
1584 $this->_refcursor =
false;
1586 @oci_free_statement($this->_queryID);
1587 $this->_queryID =
false;
1601 if (is_object($t)) {
1603 $t = $fieldobj->type;
1604 $len = $fieldobj->max_length;
1607 switch (strtoupper($t)) {
1616 if ($len <= $this->blobSize)
return 'C';
1620 case 'LONG VARCHAR':
1625 case 'LONG VARBINARY':
1630 return ($this->connection->datetime) ?
'T' :
'D';
1633 case 'TIMESTAMP':
return 'T';
1649 if ($mode ===
false) {
1650 global $ADODB_FETCH_MODE;
1651 $mode = $ADODB_FETCH_MODE;
1655 case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1656 case ADODB_FETCH_DEFAULT:
1657 case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1658 case ADODB_FETCH_NUM:
1659 default: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS;
break;
1661 $this->adodbFetchMode = $mode;
1662 $this->_queryID = $queryID;
1667 return adodb_movenext($this);
Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false)
MetaTables($ttype=false, $showSchema=false, $mask=false)
UpdateBlob($table, $column, $val, $where, $blobtype='BLOB')
Prepare($sql, $cursor=false)
$session_sharing_force_blob
_query($sql, $inputarr=false)
ExecuteCursor($sql, $cursorName='rs', $params=false)
MetaForeignKeys($table, $owner=false, $upper=false)
Bind(&$stmt, &$var, $size=4000, $type=false, $name=false, $isOutput=false)
if(isset($_REQUEST['nrows'])) else $rs
SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0)
qstr($s, $magic_quotes=false)
GetRandRow($sql, $arr=false)
MetaType($t, $len=-1, $fieldobj=false)
adodb_date($fmt, $d=false, $is_gmt=false)
_nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
MetaPrimaryKeys($table, $owner=false, $internalKey=false)
_pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
FetchField($fieldOffset=-1)
RowLock($tables, $where, $col='1 as adodbignore')
_connect($argHostname, $argUsername, $argPassword, $argDatabasename=null, $mode=0)
Execute($sql, $inputarr=false)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
ADORecordSet_ext_oci8($queryID, $mode=false)
GetArrayLimit($nrows, $offset=-1)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
MetaColumns($table, $normalize=true)
ADORecordset_oci8($queryID, $mode=false)
MetaIndexes($table, $primary=FALSE, $owner=false)
_FetchField($fieldOffset=-1)
$useDBDateFormatForTextInput
DBTimeStamp($ts, $isfld=false)
UpdateBlobFile($table, $column, $val, $where, $blobtype='BLOB')
SQLDate($fmt, $col=false)