type; $len = $fieldobj->max_length; } $_typeConversion = array( -155 => 'D', 93 => 'D', -154 => 'D', -2 => 'D', 91 => 'D', 12 => 'C', 1 => 'C', -9 => 'C', -8 => 'C', -7 => 'L', -6 => 'I2', -5 => 'I8', -11 => 'I', 4 => 'I', 5 => 'I4', -1 => 'X', -10 => 'X', 2 => 'N', 3 => 'N', 6 => 'N', 7 => 'N', -152 => 'X', -151 => 'X', -4 => 'X', -3 => 'X' ); return $_typeConversion($t); } function ActualType($meta) { $DATE_TYPE = 'DATETIME'; switch(strtoupper($meta)) { case 'C': return 'VARCHAR'; case 'XL': return (isset($this)) ? $this->typeXL : 'TEXT'; case 'X': return (isset($this)) ? $this->typeX : 'TEXT'; ## could be varchar(8000), but we want compat with oracle case 'C2': return 'NVARCHAR'; case 'X2': return 'NTEXT'; case 'B': return 'IMAGE'; case 'D': return $DATE_TYPE; case 'T': return 'TIME'; case 'L': return 'BIT'; case 'R': case 'I': return 'INT'; case 'I1': return 'TINYINT'; case 'I2': return 'SMALLINT'; case 'I4': return 'INT'; case 'I8': return 'BIGINT'; case 'F': return 'REAL'; case 'N': return 'NUMERIC'; default: print "RETURN $meta"; return $meta; } } function AddColumnSQL($tabname, $flds) { $tabname = $this->TableName ($tabname); $f = array(); list($lines,$pkey) = $this->_GenFields($flds); $s = "ALTER TABLE $tabname $this->addCol"; foreach($lines as $v) { $f[] = "\n $v"; } $s .= implode(', ',$f); $sql[] = $s; return $sql; } /* function AlterColumnSQL($tabname, $flds) { $tabname = $this->TableName ($tabname); $sql = array(); list($lines,$pkey) = $this->_GenFields($flds); foreach($lines as $v) { $sql[] = "ALTER TABLE $tabname $this->alterCol $v"; } return $sql; } */ /** * Drop a column, syntax is ALTER TABLE table DROP COLUMN column,column * * @param string $tabname Table Name * @param string[] $flds One, or an array of Fields To Drop * @param string $tableflds Throwaway value to make the function match the parent * @param string $tableoptions Throway value to make the function match the parent * * @return string The SQL necessary to drop the column */ function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); if (!is_array($flds)) $flds = explode(',',$flds); $f = array(); $s = 'ALTER TABLE ' . $tabname . ' DROP COLUMN '; foreach($flds as $v) { //$f[] = "\n$this->dropCol ".$this->NameQuote($v); $f[] = $this->NameQuote($v); } $s .= implode(', ',$f); $sql[] = $s; return $sql; } // return string must begin with space function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; if ($fautoinc) $suffix .= ' IDENTITY(1,1)'; if ($fnotnull) $suffix .= ' NOT NULL'; else if ($suffix == '') $suffix .= ' NULL'; if ($fconstraint) $suffix .= ' '.$fconstraint; return $suffix; } /* CREATE TABLE [ database_name.[ owner ] . | owner. ] table_name ( { < column_definition > | column_name AS computed_column_expression | < table_constraint > ::= [ CONSTRAINT constraint_name ] } | [ { PRIMARY KEY | UNIQUE } [ ,...n ] ) [ ON { filegroup | DEFAULT } ] [ TEXTIMAGE_ON { filegroup | DEFAULT } ] < column_definition > ::= { column_name data_type } [ COLLATE < collation_name > ] [ [ DEFAULT constant_expression ] | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ] ] [ ROWGUIDCOL] [ < column_constraint > ] [ ...n ] < column_constraint > ::= [ CONSTRAINT constraint_name ] { [ NULL | NOT NULL ] | [ { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] [ WITH FILLFACTOR = fillfactor ] [ON {filegroup | DEFAULT} ] ] ] | [ [ FOREIGN KEY ] REFERENCES ref_table [ ( ref_column ) ] [ ON DELETE { CASCADE | NO ACTION } ] [ ON UPDATE { CASCADE | NO ACTION } ] [ NOT FOR REPLICATION ] ] | CHECK [ NOT FOR REPLICATION ] ( logical_expression ) } < table_constraint > ::= [ CONSTRAINT constraint_name ] { [ { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] { ( column [ ASC | DESC ] [ ,...n ] ) } [ WITH FILLFACTOR = fillfactor ] [ ON { filegroup | DEFAULT } ] ] | FOREIGN KEY [ ( column [ ,...n ] ) ] REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] [ ON DELETE { CASCADE | NO ACTION } ] [ ON UPDATE { CASCADE | NO ACTION } ] [ NOT FOR REPLICATION ] | CHECK [ NOT FOR REPLICATION ] ( search_conditions ) } */ /* CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) [ WITH < index_option > [ ,...n] ] [ ON filegroup ] < index_option > :: = { PAD_INDEX | FILLFACTOR = fillfactor | IGNORE_DUP_KEY | DROP_EXISTING | STATISTICS_NORECOMPUTE | SORT_IN_TEMPDB } */ function _IndexSQL($idxname, $tabname, $flds, $idxoptions) { $sql = array(); if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { $sql[] = sprintf ($this->dropIndex, $idxname, $tabname); if ( isset($idxoptions['DROP']) ) return $sql; } if ( empty ($flds) ) { return $sql; } $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : ''; $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : ''; if ( is_array($flds) ) $flds = implode(', ',$flds); $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')'; if ( isset($idxoptions[$this->upperName]) ) $s .= $idxoptions[$this->upperName]; $sql[] = $s; return $sql; } function _GetSize($ftype, $ty, $fsize, $fprec) { switch ($ftype) { case 'INT': case 'SMALLINT': case 'TINYINT': case 'BIGINT': return $ftype; } if ($ty == 'T') return $ftype; return parent::_GetSize($ftype, $ty, $fsize, $fprec); } }