14 if (!defined(
'ADODB_DIR'))
die();
32 $len = $fieldobj->max_length;
34 switch (strtoupper($t)) {
40 if (isset($this) && $len <= $this->blobSize)
return 'C';
46 if (isset($this) && $len <= $this->blobSize)
return 'C2';
54 case 'LONG VARBINARY':
77 case 'C':
return 'VARCHAR';
81 case 'C2':
return 'NVARCHAR2';
82 case 'X2':
return 'NVARCHAR2(4000)';
84 case 'B':
return 'BLOB';
90 case 'T':
return 'DATE';
91 case 'L':
return 'NUMBER(1)';
92 case 'I1':
return 'NUMBER(3)';
93 case 'I2':
return 'NUMBER(5)';
95 case 'I4':
return 'NUMBER(10)';
97 case 'I8':
return 'NUMBER(20)';
98 case 'F':
return 'NUMBER';
99 case 'N':
return 'NUMBER';
100 case 'R':
return 'NUMBER(20)';
108 $options = $this->
_Options($options);
109 $password = isset($options[
'PASSWORD']) ? $options[
'PASSWORD'] :
'tiger';
110 $tablespace = isset($options[
"TABLESPACE"]) ?
" DEFAULT TABLESPACE ".$options[
"TABLESPACE"] :
'';
111 $sql[] =
"CREATE USER ".$dbname.
" IDENTIFIED BY ".$password.$tablespace;
112 $sql[] =
"GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO $dbname";
121 list($lines,$pkey) = $this->
_GenFields($flds);
122 $s =
"ALTER TABLE $tabname ADD (";
123 foreach($lines as $v) {
127 $s .= implode(
', ',$f).
')';
136 list($lines,$pkey) = $this->
_GenFields($flds);
137 $s =
"ALTER TABLE $tabname MODIFY(";
138 foreach($lines as $v) {
141 $s .= implode(
', ',$f).
')';
149 if (!is_array($flds)) $flds = explode(
',',$flds);
150 foreach ($flds as $k => $v) $flds[$k] = $this->
NameQuote($v);
153 $s =
"ALTER TABLE $tabname DROP(";
154 $s .= implode(
', ',$flds).
') CASCADE CONSTRAINTS';
161 if (strpos($t,
'.') !==
false) {
162 $tarr = explode(
'.',$t);
163 return "drop sequence ".$tarr[0].
".seq_".$tarr[1];
165 return "drop sequence seq_".$t;
169 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
173 if ($fdefault ==
"''" && $fnotnull) {
175 if ($this->
debug) ADOConnection::outp(
"NOT NULL and DEFAULT='' illegal in Oracle");
178 if (strlen($fdefault)) $suffix .=
" DEFAULT $fdefault";
179 if ($fnotnull) $suffix .=
' NOT NULL';
181 if ($fautoinc) $this->seqField = $fname;
182 if ($fconstraint) $suffix .=
' '.$fconstraint;
197 if (!$this->seqField)
return array();
200 $t = strpos($tabname,
'.');
201 if ($t !==
false) $tab = substr($tabname,$t+1);
202 else $tab = $tabname;
203 $seqname = $this->schema.
'.'.$this->seqPrefix.$tab;
204 $trigname = $this->schema.
'.'.$this->trigPrefix.$this->seqPrefix.$tab;
206 $seqname = $this->seqPrefix.$tabname;
207 $trigname = $this->trigPrefix.$seqname;
210 if (strlen($seqname) > 30) {
211 $seqname = $this->seqPrefix.uniqid(
'');
213 if (strlen($trigname) > 30) {
214 $trigname = $this->trigPrefix.uniqid(
'');
217 if (isset($tableoptions[
'REPLACE']))
$sql[] =
"DROP SEQUENCE $seqname";
219 if (isset($tableoptions[
'SEQUENCE_CACHE'])){$seqCache = $tableoptions[
'SEQUENCE_CACHE'];}
221 if (isset($tableoptions[
'SEQUENCE_INCREMENT'])){$seqIncr =
' INCREMENT BY '.$tableoptions[
'SEQUENCE_INCREMENT'];}
223 if (isset($tableoptions[
'SEQUENCE_START'])){$seqIncr =
' START WITH '.$tableoptions[
'SEQUENCE_START'];}
224 $sql[] =
"CREATE SEQUENCE $seqname $seqStart $seqIncr $seqCache";
225 $sql[] =
"CREATE OR REPLACE TRIGGER $trigname BEFORE insert ON $tabname FOR EACH ROW WHEN (NEW.$this->seqField IS NULL OR NEW.$this->seqField = 0) BEGIN select $seqname.nextval into :new.$this->seqField from dual; END;";
227 $this->seqField =
false;
249 function _IndexSQL($idxname, $tabname, $flds,$idxoptions)
253 if ( isset($idxoptions[
'REPLACE']) || isset($idxoptions[
'DROP']) ) {
254 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
255 if ( isset($idxoptions[
'DROP']) )
259 if ( empty ($flds) ) {
263 if (isset($idxoptions[
'BITMAP'])) {
265 } elseif (isset($idxoptions[
'UNIQUE'])) {
271 if ( is_array($flds) )
272 $flds = implode(
', ',$flds);
273 $s =
'CREATE' . $unique .
' INDEX ' . $idxname .
' ON ' . $tabname .
' (' . $flds .
')';
275 if ( isset($idxoptions[$this->upperName]) )
276 $s .= $idxoptions[$this->upperName];
278 if (isset($idxoptions[
'oci8']))
279 $s .= $idxoptions[
'oci8'];
289 $table = $this->connection->qstr($table);
290 $col = $this->connection->qstr($col);
291 return "select comments from USER_COL_COMMENTS where TABLE_NAME=$table and COLUMN_NAME=$col";
296 $cmt = $this->connection->qstr($cmt);
297 return "COMMENT ON COLUMN $table.$col IS $cmt";
_GenFields($flds, $widespacing=false)
AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
SetCommentSQL($table, $col, $cmt)
_IndexSQL($idxname, $tabname, $flds, $idxoptions)
_Triggers($tabname, $tableoptions)
GetCommentSQL($table, $col)
CreateDatabase($dbname, $options=false)
MetaType($t, $len=-1, $fieldobj=false)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
AddColumnSQL($tabname, $flds)
DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
_CreateSuffix($fname, &$ftype, $fnotnull, $fdefault, $fautoinc, $fconstraint, $funsigned)
NameQuote($name=NULL, $allowBrackets=false)