Documentation TYPO3 par Ameos |
00001 <?php 00002 00013 // security - hide paths 00014 if (!defined('ADODB_DIR')) die(); 00015 00016 class ADODB2_oci8 extends ADODB_DataDict { 00017 00018 var $databaseType = 'oci8'; 00019 var $seqField = false; 00020 var $seqPrefix = 'SEQ_'; 00021 var $dropTable = "DROP TABLE %s CASCADE CONSTRAINTS"; 00022 var $trigPrefix = 'TRIG_'; 00023 var $alterCol = ' MODIFY '; 00024 var $typeX = 'VARCHAR(4000)'; 00025 var $typeXL = 'CLOB'; 00026 00027 function MetaType($t,$len=-1) 00028 { 00029 if (is_object($t)) { 00030 $fieldobj = $t; 00031 $t = $fieldobj->type; 00032 $len = $fieldobj->max_length; 00033 } 00034 switch (strtoupper($t)) { 00035 case 'VARCHAR': 00036 case 'VARCHAR2': 00037 case 'CHAR': 00038 case 'VARBINARY': 00039 case 'BINARY': 00040 if (isset($this) && $len <= $this->blobSize) return 'C'; 00041 return 'X'; 00042 00043 case 'NCHAR': 00044 case 'NVARCHAR2': 00045 case 'NVARCHAR': 00046 if (isset($this) && $len <= $this->blobSize) return 'C2'; 00047 return 'X2'; 00048 00049 case 'NCLOB': 00050 case 'CLOB': 00051 return 'XL'; 00052 00053 case 'LONG RAW': 00054 case 'LONG VARBINARY': 00055 case 'BLOB': 00056 return 'B'; 00057 00058 case 'DATE': 00059 return 'T'; 00060 00061 case 'INT': 00062 case 'SMALLINT': 00063 case 'INTEGER': 00064 return 'I'; 00065 00066 default: 00067 return 'N'; 00068 } 00069 } 00070 00071 function ActualType($meta) 00072 { 00073 switch($meta) { 00074 case 'C': return 'VARCHAR'; 00075 case 'X': return $this->typeX; 00076 case 'XL': return $this->typeXL; 00077 00078 case 'C2': return 'NVARCHAR'; 00079 case 'X2': return 'NVARCHAR(2000)'; 00080 00081 case 'B': return 'BLOB'; 00082 00083 case 'D': 00084 case 'T': return 'DATE'; 00085 case 'L': return 'DECIMAL(1)'; 00086 case 'I1': return 'DECIMAL(3)'; 00087 case 'I2': return 'DECIMAL(5)'; 00088 case 'I': 00089 case 'I4': return 'DECIMAL(10)'; 00090 00091 case 'I8': return 'DECIMAL(20)'; 00092 case 'F': return 'DECIMAL'; 00093 case 'N': return 'DECIMAL'; 00094 default: 00095 return $meta; 00096 } 00097 } 00098 00099 function CreateDatabase($dbname, $options=false) 00100 { 00101 $options = $this->_Options($options); 00102 $password = isset($options['PASSWORD']) ? $options['PASSWORD'] : 'tiger'; 00103 $tablespace = isset($options["TABLESPACE"]) ? " DEFAULT TABLESPACE ".$options["TABLESPACE"] : ''; 00104 $sql[] = "CREATE USER ".$dbname." IDENTIFIED BY ".$password.$tablespace; 00105 $sql[] = "GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO $dbname"; 00106 00107 return $sql; 00108 } 00109 00110 function AddColumnSQL($tabname, $flds) 00111 { 00112 $f = array(); 00113 list($lines,$pkey) = $this->_GenFields($flds); 00114 $s = "ALTER TABLE $tabname ADD ("; 00115 foreach($lines as $v) { 00116 $f[] = "\n $v"; 00117 } 00118 00119 $s .= implode(', ',$f).')'; 00120 $sql[] = $s; 00121 return $sql; 00122 } 00123 00124 function AlterColumnSQL($tabname, $flds) 00125 { 00126 $f = array(); 00127 list($lines,$pkey) = $this->_GenFields($flds); 00128 $s = "ALTER TABLE $tabname MODIFY("; 00129 foreach($lines as $v) { 00130 $f[] = "\n $v"; 00131 } 00132 $s .= implode(', ',$f).')'; 00133 $sql[] = $s; 00134 return $sql; 00135 } 00136 00137 function DropColumnSQL($tabname, $flds) 00138 { 00139 if (!is_array($flds)) $flds = explode(',',$flds); 00140 foreach ($flds as $k => $v) $flds[$k] = $this->NameQuote($v); 00141 00142 $sql = array(); 00143 $s = "ALTER TABLE $tabname DROP("; 00144 $s .= implode(', ',$flds).') CASCADE CONSTRAINTS'; 00145 $sql[] = $s; 00146 return $sql; 00147 } 00148 00149 function _DropAutoIncrement($t) 00150 { 00151 if (strpos($t,'.') !== false) { 00152 $tarr = explode('.',$t); 00153 return "drop sequence ".$tarr[0].".seq_".$tarr[1]; 00154 } 00155 return "drop sequence seq_".$t; 00156 } 00157 00158 // return string must begin with space 00159 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) 00160 { 00161 $suffix = ''; 00162 00163 if ($fdefault == "''" && $fnotnull) {// this is null in oracle 00164 $fnotnull = false; 00165 if ($this->debug) ADOConnection::outp("NOT NULL and DEFAULT='' illegal in Oracle"); 00166 } 00167 00168 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; 00169 if ($fnotnull) $suffix .= ' NOT NULL'; 00170 00171 if ($fautoinc) $this->seqField = $fname; 00172 if ($fconstraint) $suffix .= ' '.$fconstraint; 00173 00174 return $suffix; 00175 } 00176 00177 /* 00178 CREATE or replace TRIGGER jaddress_insert 00179 before insert on jaddress 00180 for each row 00181 begin 00182 select seqaddress.nextval into :new.A_ID from dual; 00183 end; 00184 */ 00185 function _Triggers($tabname,$tableoptions) 00186 { 00187 if (!$this->seqField) return array(); 00188 00189 if ($this->schema) { 00190 $t = strpos($tabname,'.'); 00191 if ($t !== false) $tab = substr($tabname,$t+1); 00192 else $tab = $tabname; 00193 $seqname = $this->schema.'.'.$this->seqPrefix.$tab; 00194 $trigname = $this->schema.'.'.$this->trigPrefix.$this->seqPrefix.$tab; 00195 } else { 00196 $seqname = $this->seqPrefix.$tabname; 00197 $trigname = $this->trigPrefix.$seqname; 00198 } 00199 if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname"; 00200 $seqCache = ''; 00201 if (isset($tableoptions['SEQUENCE_CACHE'])){$seqCache = $tableoptions['SEQUENCE_CACHE'];} 00202 $seqIncr = ''; 00203 if (isset($tableoptions['SEQUENCE_INCREMENT'])){$seqIncr = ' INCREMENT BY '.$tableoptions['SEQUENCE_INCREMENT'];} 00204 $seqStart = ''; 00205 if (isset($tableoptions['SEQUENCE_START'])){$seqIncr = ' START WITH '.$tableoptions['SEQUENCE_START'];} 00206 $sql[] = "CREATE SEQUENCE $seqname $seqStart $seqIncr $seqCache"; 00207 $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;"; 00208 00209 $this->seqField = false; 00210 return $sql; 00211 } 00212 00213 /* 00214 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] 00215 [table_options] [select_statement] 00216 create_definition: 00217 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] 00218 [PRIMARY KEY] [reference_definition] 00219 or PRIMARY KEY (index_col_name,...) 00220 or KEY [index_name] (index_col_name,...) 00221 or INDEX [index_name] (index_col_name,...) 00222 or UNIQUE [INDEX] [index_name] (index_col_name,...) 00223 or FULLTEXT [INDEX] [index_name] (index_col_name,...) 00224 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...) 00225 [reference_definition] 00226 or CHECK (expr) 00227 */ 00228 00229 00230 00231 function _IndexSQL($idxname, $tabname, $flds,$idxoptions) 00232 { 00233 $sql = array(); 00234 00235 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { 00236 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname); 00237 if ( isset($idxoptions['DROP']) ) 00238 return $sql; 00239 } 00240 00241 if ( empty ($flds) ) { 00242 return $sql; 00243 } 00244 00245 if (isset($idxoptions['BITMAP'])) { 00246 $unique = ' BITMAP'; 00247 } elseif (isset($idxoptions['UNIQUE'])) { 00248 $unique = ' UNIQUE'; 00249 } else { 00250 $unique = ''; 00251 } 00252 00253 if ( is_array($flds) ) 00254 $flds = implode($this->quote.', '.$this->quote,$flds); 00255 $s = 'CREATE' . $unique . ' INDEX ' .$this->quote. $idxname .$this->quote. ' ON ' . $this->quote.$tabname . $this->quote.' (' .$this->quote. $flds .$this->quote. ')'; 00256 00257 if ( isset($idxoptions[$this->upperName]) ) 00258 $s .= $idxoptions[$this->upperName]; 00259 00260 if (isset($idxoptions['oci8'])) 00261 $s .= $idxoptions['oci8']; 00262 00263 00264 $sql[] = $s; 00265 00266 return $sql; 00267 } 00268 00269 function GetCommentSQL($table,$col) 00270 { 00271 $table = $this->connection->qstr($table); 00272 $col = $this->connection->qstr($col); 00273 return "select comments from USER_COL_COMMENTS where TABLE_NAME=$table and COLUMN_NAME=$col"; 00274 } 00275 00276 function SetCommentSQL($table,$col,$cmt) 00277 { 00278 $cmt = $this->connection->qstr($cmt); 00279 return "COMMENT ON COLUMN $table.$col IS $cmt"; 00280 } 00281 } 00282 ?>