Documentation TYPO3 par Ameos

datadict-mssql.inc.php

00001 <?php
00002 
00013 /*
00014 In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs:
00015 
00016         Note Delimiters are for identifiers only. Delimiters cannot be used for keywords, 
00017         whether or not they are marked as reserved in SQL Server.
00018         
00019         Quoted identifiers are delimited by double quotation marks ("):
00020         SELECT * FROM "Blanks in Table Name"
00021         
00022         Bracketed identifiers are delimited by brackets ([ ]):
00023         SELECT * FROM [Blanks In Table Name]
00024         
00025         Quoted identifiers are valid only when the QUOTED_IDENTIFIER option is set to ON. By default, 
00026         the Microsoft OLE DB Provider for SQL Server and SQL Server ODBC driver set QUOTED_IDENTIFIER ON 
00027         when they connect. 
00028         
00029         In Transact-SQL, the option can be set at various levels using SET QUOTED_IDENTIFIER, 
00030         the quoted identifier option of sp_dboption, or the user options option of sp_configure.
00031         
00032         When SET ANSI_DEFAULTS is ON, SET QUOTED_IDENTIFIER is enabled.
00033         
00034         Syntax
00035         
00036                 SET QUOTED_IDENTIFIER { ON | OFF }
00037 
00038 
00039 */
00040 
00041 // security - hide paths
00042 if (!defined('ADODB_DIR')) die();
00043 
00044 class ADODB2_mssql extends ADODB_DataDict {
00045         var $databaseType = 'mssql';
00046         var $dropIndex = 'DROP INDEX %2$s.%1$s';
00047         var $renameTable = "EXEC sp_rename '%s','%s'";
00048         var $renameColumn = "EXEC sp_rename '%s.%s','%s'";
00049 
00050         var $typeX = 'TEXT';  ## Alternatively, set it to VARCHAR(4000)
00051         var $typeXL = 'TEXT';
00052         
00053         //var $alterCol = ' ALTER COLUMN ';
00054         
00055         function MetaType($t,$len=-1,$fieldobj=false)
00056         {
00057                 if (is_object($t)) {
00058                         $fieldobj = $t;
00059                         $t = $fieldobj->type;
00060                         $len = $fieldobj->max_length;
00061                 }
00062                 
00063                 $len = -1; // mysql max_length is not accurate
00064                 switch (strtoupper($t)) {
00065                 case 'R':
00066                 case 'INT': 
00067                 case 'INTEGER': return  'I';
00068                 case 'BIT':
00069                 case 'TINYINT': return  'I1';
00070                 case 'SMALLINT': return 'I2';
00071                 case 'BIGINT':  return  'I8';
00072                 
00073                 case 'REAL':
00074                 case 'FLOAT': return 'F';
00075                 default: return parent::MetaType($t,$len,$fieldobj);
00076                 }
00077         }
00078         
00079         function ActualType($meta)
00080         {
00081                 switch(strtoupper($meta)) {
00082 
00083                 case 'C': return 'VARCHAR';
00084                 case 'XL': return (isset($this)) ? $this->typeXL : 'TEXT';
00085                 case 'X': return (isset($this)) ? $this->typeX : 'TEXT'; ## could be varchar(8000), but we want compat with oracle
00086                 case 'C2': return 'NVARCHAR';
00087                 case 'X2': return 'NTEXT';
00088                 
00089                 case 'B': return 'IMAGE';
00090                         
00091                 case 'D': return 'DATETIME';
00092                 case 'T': return 'DATETIME';
00093                 case 'L': return 'BIT';
00094                 
00095                 case 'R':               
00096                 case 'I': return 'INT'; 
00097                 case 'I1': return 'TINYINT';
00098                 case 'I2': return 'SMALLINT';
00099                 case 'I4': return 'INT';
00100                 case 'I8': return 'BIGINT';
00101                 
00102                 case 'F': return 'REAL';
00103                 case 'N': return 'NUMERIC';
00104                 default:
00105                         return $meta;
00106                 }
00107         }
00108         
00109         
00110         function AddColumnSQL($tabname, $flds)
00111         {
00112                 $tabname = $this->TableName ($tabname);
00113                 $f = array();
00114                 list($lines,$pkey) = $this->_GenFields($flds);
00115                 $s = "ALTER TABLE $tabname $this->addCol";
00116                 foreach($lines as $v) {
00117                         $f[] = "\n $v";
00118                 }
00119                 $s .= implode(', ',$f);
00120                 $sql[] = $s;
00121                 return $sql;
00122         }
00123         
00124         /*
00125         function AlterColumnSQL($tabname, $flds)
00126         {
00127                 $tabname = $this->TableName ($tabname);
00128                 $sql = array();
00129                 list($lines,$pkey) = $this->_GenFields($flds);
00130                 foreach($lines as $v) {
00131                         $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
00132                 }
00133 
00134                 return $sql;
00135         }
00136         */
00137         
00138         function DropColumnSQL($tabname, $flds)
00139         {
00140                 $tabname = $this->TableName ($tabname);
00141                 if (!is_array($flds))
00142                         $flds = explode(',',$flds);
00143                 $f = array();
00144                 $s = 'ALTER TABLE ' . $tabname;
00145                 foreach($flds as $v) {
00146                         $f[] = "\n$this->dropCol ".$this->NameQuote($v);
00147                 }
00148                 $s .= implode(', ',$f);
00149                 $sql[] = $s;
00150                 return $sql;
00151         }
00152         
00153         // return string must begin with space
00154         function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
00155         {       
00156                 $suffix = '';
00157                 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00158                 if ($fautoinc) $suffix .= ' IDENTITY(1,1)';
00159                 if ($fnotnull) $suffix .= ' NOT NULL';
00160                 else if ($suffix == '') $suffix .= ' NULL';
00161                 if ($fconstraint) $suffix .= ' '.$fconstraint;
00162                 return $suffix;
00163         }
00164         
00165         /*
00166 CREATE TABLE 
00167     [ database_name.[ owner ] . | owner. ] table_name 
00168     ( { < column_definition > 
00169         | column_name AS computed_column_expression 
00170         | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
00171 
00172             | [ { PRIMARY KEY | UNIQUE } [ ,...n ] 
00173     ) 
00174 
00175 [ ON { filegroup | DEFAULT } ] 
00176 [ TEXTIMAGE_ON { filegroup | DEFAULT } ] 
00177 
00178 < column_definition > ::= { column_name data_type } 
00179     [ COLLATE < collation_name > ] 
00180     [ [ DEFAULT constant_expression ] 
00181         | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
00182     ] 
00183     [ ROWGUIDCOL] 
00184     [ < column_constraint > ] [ ...n ] 
00185 
00186 < column_constraint > ::= [ CONSTRAINT constraint_name ] 
00187     { [ NULL | NOT NULL ] 
00188         | [ { PRIMARY KEY | UNIQUE } 
00189             [ CLUSTERED | NONCLUSTERED ] 
00190             [ WITH FILLFACTOR = fillfactor ] 
00191             [ON {filegroup | DEFAULT} ] ] 
00192         ] 
00193         | [ [ FOREIGN KEY ] 
00194             REFERENCES ref_table [ ( ref_column ) ] 
00195             [ ON DELETE { CASCADE | NO ACTION } ] 
00196             [ ON UPDATE { CASCADE | NO ACTION } ] 
00197             [ NOT FOR REPLICATION ] 
00198         ] 
00199         | CHECK [ NOT FOR REPLICATION ] 
00200         ( logical_expression ) 
00201     } 
00202 
00203 < table_constraint > ::= [ CONSTRAINT constraint_name ] 
00204     { [ { PRIMARY KEY | UNIQUE } 
00205         [ CLUSTERED | NONCLUSTERED ] 
00206         { ( column [ ASC | DESC ] [ ,...n ] ) } 
00207         [ WITH FILLFACTOR = fillfactor ] 
00208         [ ON { filegroup | DEFAULT } ] 
00209     ] 
00210     | FOREIGN KEY 
00211         [ ( column [ ,...n ] ) ] 
00212         REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] 
00213         [ ON DELETE { CASCADE | NO ACTION } ] 
00214         [ ON UPDATE { CASCADE | NO ACTION } ] 
00215         [ NOT FOR REPLICATION ] 
00216     | CHECK [ NOT FOR REPLICATION ] 
00217         ( search_conditions ) 
00218     } 
00219 
00220 
00221         */
00222         
00223         /*
00224         CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name 
00225     ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) 
00226                 [ WITH < index_option > [ ,...n] ] 
00227                 [ ON filegroup ]
00228                 < index_option > :: = 
00229                     { PAD_INDEX | 
00230                         FILLFACTOR = fillfactor | 
00231                         IGNORE_DUP_KEY | 
00232                         DROP_EXISTING | 
00233                     STATISTICS_NORECOMPUTE | 
00234                     SORT_IN_TEMPDB  
00235                 }
00236 */
00237         function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
00238         {
00239                 $sql = array();
00240                 
00241                 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
00242                         $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
00243                         if ( isset($idxoptions['DROP']) )
00244                                 return $sql;
00245                 }
00246                 
00247                 if ( empty ($flds) ) {
00248                         return $sql;
00249                 }
00250                 
00251                 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
00252                 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
00253                 
00254                 if ( is_array($flds) )
00255                         $flds = implode(', ',$flds);
00256                 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
00257                 
00258                 if ( isset($idxoptions[$this->upperName]) )
00259                         $s .= $idxoptions[$this->upperName];
00260                 
00261 
00262                 $sql[] = $s;
00263                 
00264                 return $sql;
00265         }
00266         
00267         
00268         function _GetSize($ftype, $ty, $fsize, $fprec)
00269         {
00270                 switch ($ftype) {
00271                 case 'INT':
00272                 case 'SMALLINT':
00273                 case 'TINYINT':
00274                 case 'BIGINT':
00275                         return $ftype;
00276                 }
00277         if ($ty == 'T') return $ftype;
00278         return parent::_GetSize($ftype, $ty, $fsize, $fprec);    
00279 
00280         }
00281 }
00282 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6