[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/creole/drivers/sqlite/metadata/ -> SQLiteTableInfo.php (source)

   1  <?php
   2  /*
   3   *  $Id: SQLiteTableInfo.php,v 1.8 2005/10/18 02:27:50 hlellelid Exp $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://creole.phpdb.org>.
  20   */
  21   
  22  require_once 'creole/metadata/TableInfo.php';
  23  
  24  /**
  25   * MySQL implementation of TableInfo.
  26   * 
  27   * @author    Hans Lellelid <hans@xmpl.org>
  28   * @version   $Revision: 1.8 $
  29   * @package   creole.drivers.sqlite.metadata
  30   */
  31  class SQLiteTableInfo extends TableInfo {
  32      
  33      /** Loads the columns for this table. */
  34      protected function initColumns() 
  35      {
  36          
  37          include_once 'creole/metadata/ColumnInfo.php';
  38          include_once 'creole/metadata/PrimaryKeyInfo.php';
  39          include_once 'creole/drivers/sqlite/SQLiteTypes.php';                
  40          
  41          // To get all of the attributes we need, we'll actually do 
  42          // two separate queries.  The first gets names and default values
  43          // the second will fill in some more details.
  44          
  45          $sql = "PRAGMA table_info('".$this->name."')";
  46                  
  47          $res = sqlite_query($this->conn->getResource(), $sql);
  48          
  49          
  50          while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
  51          
  52              $name = $row['name'];
  53              
  54              $fulltype = $row['type'];            
  55              $size = null;
  56              $precision = null;
  57              $scale = null;
  58              
  59              if (preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches)) {
  60                  $type = $matches[1];
  61                  $precision = $matches[2];
  62                  $scale = $matches[3]; // aka precision    
  63              } elseif (preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches)) {
  64                  $type = $matches[1];
  65                  $size = $matches[2];
  66              } else {
  67                  $type = $fulltype;
  68              }
  69              // If column is primary key and of type INTEGER, it is auto increment
  70              // See: http://sqlite.org/faq.html#q1
  71              $is_auto_increment = ($row['pk'] == 1 && $fulltype == 'INTEGER');
  72              $not_null = $row['notnull'];
  73              $is_nullable = !$not_null;
  74              
  75              $default_val = $row['dflt_value'];
  76              
  77              $this->columns[$name] = new ColumnInfo($this, $name, SQLiteTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default_val);
  78              
  79              if (($row['pk'] == 1) || (strtolower($type) == 'integer primary key')) {
  80                  if ($this->primaryKey === null) {
  81                      $this->primaryKey = new PrimaryKeyInfo($name);
  82                  }
  83                  $this->primaryKey->addColumn($this->columns[ $name ]);
  84              }
  85              
  86          }        
  87                  
  88          $this->colsLoaded = true;
  89      }
  90      
  91      /** Loads the primary key information for this table. */
  92      protected function initPrimaryKey()
  93      {        
  94          // columns have to be loaded first
  95          if (!$this->colsLoaded) $this->initColumns();                        
  96          // keys are loaded by initColumns() in this class.
  97          $this->pkLoaded = true;
  98      }
  99      
 100      /** Loads the indexes for this table. */
 101      protected function initIndexes() {
 102      
 103          include_once 'creole/metadata/IndexInfo.php';        
 104  
 105          // columns have to be loaded first
 106          if (!$this->colsLoaded) $this->initColumns();        
 107  
 108          $sql = "PRAGMA index_list('".$this->name."')";
 109          $res = sqlite_query($this->conn->getResource(), $sql);
 110          
 111          while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {        
 112              $name = $row['name'];
 113              $this->indexes[$name] = new IndexInfo($name);
 114              
 115              // get columns for that index
 116              $res2 = sqlite_query($this->conn->getResource(), "PRAGMA index_info('$name')");
 117              while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) {
 118                  $colname = $row2['name'];
 119                  $this->indexes[$name]->addColumn($this->columns[ $colname ]);
 120              }
 121          }        
 122                  
 123          $this->indexesLoaded = true;
 124      }
 125      
 126      /** Load foreign keys (unsupported in SQLite). */
 127      protected function initForeignKeys() {
 128          
 129          // columns have to be loaded first
 130          if (!$this->colsLoaded) $this->initColumns();        
 131          
 132          // No fkeys in SQLite
 133          
 134          $this->fksLoaded = true;
 135      }
 136      
 137  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7