• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Db/Adapter/Pdo/Mysql.php

00001 <?php
00027 require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
00028 
00029 
00039 class Zend_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Abstract
00040 {
00041 
00047     protected $_pdoType = 'mysql';
00048 
00060     protected $_numericDataTypes = array(
00061         Zend_Db::INT_TYPE    => Zend_Db::INT_TYPE,
00062         Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
00063         Zend_Db::FLOAT_TYPE  => Zend_Db::FLOAT_TYPE,
00064         'INT'                => Zend_Db::INT_TYPE,
00065         'INTEGER'            => Zend_Db::INT_TYPE,
00066         'MEDIUMINT'          => Zend_Db::INT_TYPE,
00067         'SMALLINT'           => Zend_Db::INT_TYPE,
00068         'TINYINT'            => Zend_Db::INT_TYPE,
00069         'BIGINT'             => Zend_Db::BIGINT_TYPE,
00070         'SERIAL'             => Zend_Db::BIGINT_TYPE,
00071         'DEC'                => Zend_Db::FLOAT_TYPE,
00072         'DECIMAL'            => Zend_Db::FLOAT_TYPE,
00073         'DOUBLE'             => Zend_Db::FLOAT_TYPE,
00074         'DOUBLE PRECISION'   => Zend_Db::FLOAT_TYPE,
00075         'FIXED'              => Zend_Db::FLOAT_TYPE,
00076         'FLOAT'              => Zend_Db::FLOAT_TYPE
00077     );
00078 
00085     protected function _connect()
00086     {         
00087         if ($this->_connection) {
00088             return;
00089         }
00090 
00091         if (!empty($this->_config['charset'])) {
00092             $initCommand = "SET NAMES '" . $this->_config['charset'] . "'";
00093             $this->_config['driver_options'][1002] = $initCommand; // 1002 = PDO::MYSQL_ATTR_INIT_COMMAND
00094         }
00095         parent::_connect();
00096     }
00097 
00101     public function getQuoteIdentifierSymbol()
00102     {
00103         return "`";
00104     }
00105 
00111     public function listTables()
00112     {
00113         return $this->fetchCol('SHOW TABLES');
00114     }
00115 
00144     public function describeTable($tableName, $schemaName = null)
00145     {
00146         // @todo  use INFORMATION_SCHEMA someday when MySQL's
00147         // implementation has reasonably good performance and
00148         // the version with this improvement is in wide use.
00149 
00150         if ($schemaName) {
00151             $sql = 'DESCRIBE ' . $this->quoteIdentifier("$schemaName.$tableName", true);
00152         } else {
00153             $sql = 'DESCRIBE ' . $this->quoteIdentifier($tableName, true);
00154         }
00155         $stmt = $this->query($sql);
00156 
00157         // Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
00158         $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
00159 
00160         $field   = 0;
00161         $type    = 1;
00162         $null    = 2;
00163         $key     = 3;
00164         $default = 4;
00165         $extra   = 5;
00166 
00167         $desc = array();
00168         $i = 1;
00169         $p = 1;
00170         foreach ($result as $row) {
00171             list($length, $scale, $precision, $unsigned, $primary, $primaryPosition, $identity)
00172                 = array(null, null, null, null, false, null, false);
00173             if (preg_match('/unsigned/', $row[$type])) {
00174                 $unsigned = true;
00175             }
00176             if (preg_match('/^((?:var)?char)\((\d+)\)/', $row[$type], $matches)) {
00177                 $row[$type] = $matches[1];
00178                 $length = $matches[2];
00179             } else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row[$type], $matches)) {
00180                 $row[$type] = 'decimal';
00181                 $precision = $matches[1];
00182                 $scale = $matches[2];
00183             } else if (preg_match('/^float\((\d+),(\d+)\)/', $row[$type], $matches)) {
00184                 $row[$type] = 'float';
00185                 $precision = $matches[1];
00186                 $scale = $matches[2];
00187             } else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row[$type], $matches)) {
00188                 $row[$type] = $matches[1];
00189                 // The optional argument of a MySQL int type is not precision
00190                 // or length; it is only a hint for display width.
00191             }
00192             if (strtoupper($row[$key]) == 'PRI') {
00193                 $primary = true;
00194                 $primaryPosition = $p;
00195                 if ($row[$extra] == 'auto_increment') {
00196                     $identity = true;
00197                 } else {
00198                     $identity = false;
00199                 }
00200                 ++$p;
00201             }
00202             $desc[$this->foldCase($row[$field])] = array(
00203                 'SCHEMA_NAME'      => null, // @todo
00204                 'TABLE_NAME'       => $this->foldCase($tableName),
00205                 'COLUMN_NAME'      => $this->foldCase($row[$field]),
00206                 'COLUMN_POSITION'  => $i,
00207                 'DATA_TYPE'        => $row[$type],
00208                 'DEFAULT'          => $row[$default],
00209                 'NULLABLE'         => (bool) ($row[$null] == 'YES'),
00210                 'LENGTH'           => $length,
00211                 'SCALE'            => $scale,
00212                 'PRECISION'        => $precision,
00213                 'UNSIGNED'         => $unsigned,
00214                 'PRIMARY'          => $primary,
00215                 'PRIMARY_POSITION' => $primaryPosition,
00216                 'IDENTITY'         => $identity
00217             );
00218             ++$i;
00219         }
00220         return $desc;
00221     }
00222 
00232      public function limit($sql, $count, $offset = 0)
00233      {
00234         $count = intval($count);
00235         if ($count <= 0) {
00237             require_once 'Zend/Db/Adapter/Exception.php';
00238             throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
00239         }
00240 
00241         $offset = intval($offset);
00242         if ($offset < 0) {
00244             require_once 'Zend/Db/Adapter/Exception.php';
00245             throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
00246         }
00247 
00248         $sql .= " LIMIT $count";
00249         if ($offset > 0) {
00250             $sql .= " OFFSET $offset";
00251         }
00252 
00253         return $sql;
00254     }
00255 
00256 }

Generated on Thu Apr 19 2012 17:01:17 for openbiz by  doxygen 1.7.2