[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/adodb/datadict/ -> datadict-mysql.inc.php (source)

   1  <?php
   2  
   3  /**
   4    V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   5    Released under both BSD license and Lesser GPL library license. 
   6    Whenever there is any discrepancy between the two licenses, 
   7    the BSD license will take precedence.
   8      
   9    Set tabs to 4 for best viewing.
  10   
  11  */
  12  
  13  // security - hide paths
  14  if (!defined('ADODB_DIR')) die();
  15  
  16  class ADODB2_mysql extends ADODB_DataDict {
  17      var $databaseType = 'mysql';
  18      var $alterCol = ' MODIFY COLUMN';
  19      var $alterTableAddIndex = true;
  20      var $dropTable = 'DROP TABLE IF EXISTS %s'; // requires mysql 3.22 or later
  21      
  22      var $dropIndex = 'DROP INDEX %s ON %s';
  23      var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s';    // needs column-definition!
  24      
  25  	function MetaType($t,$len=-1,$fieldobj=false)
  26      {
  27          if (is_object($t)) {
  28              $fieldobj = $t;
  29              $t = $fieldobj->type;
  30              $len = $fieldobj->max_length;
  31          }
  32          $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
  33          
  34          $len = -1; // mysql max_length is not accurate
  35          switch (strtoupper($t)) {
  36          case 'STRING': 
  37          case 'CHAR':
  38          case 'VARCHAR': 
  39          case 'TINYBLOB': 
  40          case 'TINYTEXT': 
  41          case 'ENUM': 
  42          case 'SET':
  43              if ($len <= $this->blobSize) return 'C';
  44              
  45          case 'TEXT':
  46          case 'LONGTEXT': 
  47          case 'MEDIUMTEXT':
  48              return 'X';
  49              
  50          // php_mysql extension always returns 'blob' even if 'text'
  51          // so we have to check whether binary...
  52          case 'IMAGE':
  53          case 'LONGBLOB': 
  54          case 'BLOB':
  55          case 'MEDIUMBLOB':
  56              return !empty($fieldobj->binary) ? 'B' : 'X';
  57              
  58          case 'YEAR':
  59          case 'DATE': return 'D';
  60          
  61          case 'TIME':
  62          case 'DATETIME':
  63          case 'TIMESTAMP': return 'T';
  64          
  65          case 'FLOAT':
  66          case 'DOUBLE':
  67              return 'F';
  68              
  69          case 'INT': 
  70          case 'INTEGER': return $is_serial ? 'R' : 'I';
  71          case 'TINYINT': return $is_serial ? 'R' : 'I1';
  72          case 'SMALLINT': return $is_serial ? 'R' : 'I2';
  73          case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
  74          case 'BIGINT':  return $is_serial ? 'R' : 'I8';
  75          default: return 'N';
  76          }
  77      }
  78  
  79  	function ActualType($meta)
  80      {
  81          switch(strtoupper($meta)) {
  82          case 'C': return 'VARCHAR';
  83          case 'XL':return 'LONGTEXT';
  84          case 'X': return 'TEXT';
  85          
  86          case 'C2': return 'VARCHAR';
  87          case 'X2': return 'LONGTEXT';
  88          
  89          case 'B': return 'LONGBLOB';
  90              
  91          case 'D': return 'DATE';
  92          case 'T': return 'DATETIME';
  93          case 'L': return 'TINYINT';
  94          
  95          case 'R':
  96          case 'I4':
  97          case 'I': return 'INTEGER';
  98          case 'I1': return 'TINYINT';
  99          case 'I2': return 'SMALLINT';
 100          case 'I8': return 'BIGINT';
 101          
 102          case 'F': return 'DOUBLE';
 103          case 'N': return 'NUMERIC';
 104          default:
 105              return $meta;
 106          }
 107      }
 108      
 109      // return string must begin with space
 110  	function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
 111      {    
 112          $suffix = '';
 113          if ($funsigned) $suffix .= ' UNSIGNED';
 114          if ($fnotnull) $suffix .= ' NOT NULL';
 115          if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
 116          if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
 117          if ($fconstraint) $suffix .= ' '.$fconstraint;
 118          return $suffix;
 119      }
 120      
 121      /*
 122      CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
 123          [table_options] [select_statement]
 124          create_definition:
 125          col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
 126          [PRIMARY KEY] [reference_definition]
 127          or PRIMARY KEY (index_col_name,...)
 128          or KEY [index_name] (index_col_name,...)
 129          or INDEX [index_name] (index_col_name,...)
 130          or UNIQUE [INDEX] [index_name] (index_col_name,...)
 131          or FULLTEXT [INDEX] [index_name] (index_col_name,...)
 132          or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
 133          [reference_definition]
 134          or CHECK (expr)
 135      */
 136      
 137      /*
 138      CREATE [UNIQUE|FULLTEXT] INDEX index_name
 139          ON tbl_name (col_name[(length)],... )
 140      */
 141      
 142  	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
 143      {
 144          $sql = array();
 145          
 146          if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
 147              if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
 148              else $sql[] = sprintf($this->dropIndex, $idxname, $tabname);
 149  
 150              if ( isset($idxoptions['DROP']) )
 151                  return $sql;
 152          }
 153          
 154          if ( empty ($flds) ) {
 155              return $sql;
 156          }
 157          
 158          if (isset($idxoptions['FULLTEXT'])) {
 159              $unique = ' FULLTEXT';
 160          } elseif (isset($idxoptions['UNIQUE'])) {
 161              $unique = ' UNIQUE';
 162          } else {
 163              $unique = '';
 164          }
 165          
 166          if ( is_array($flds) ) $flds = implode(', ',$flds);
 167          
 168          if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
 169          else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
 170          
 171          $s .= ' (' . $flds . ')';
 172          
 173          if ( isset($idxoptions[$this->upperName]) )
 174              $s .= $idxoptions[$this->upperName];
 175          
 176          $sql[] = $s;
 177          
 178          return $sql;
 179      }
 180  }
 181  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics