Source for file sqlite.dbtools.php

Documentation is available at sqlite.dbtools.php

  1. <?php
  2. /**
  3. @package    jelix
  4. @subpackage db_driver
  5. @author     Loic Mathaud
  6. @contributor Laurent Jouanneau
  7. @copyright  2006 Loic Mathaud, 2007 Laurent Jouanneau
  8. @link      http://www.jelix.org
  9. @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  10. */
  11.  
  12. /**
  13.  * classe d'outils pour gérer une base de données
  14.  * @package    jelix
  15.  * @subpackage db_driver
  16.  */
  17. class sqliteDbTools extends jDbTools {
  18.  
  19.     /**
  20.     * retourne la liste des tables
  21.     * @return   array    $tab[] = $nomDeTable
  22.     */
  23.     protected function _getTableList (){
  24.         $results array ();
  25.  
  26.         $rs $this->_connector->query('SELECT name FROM sqlite_master WHERE type="table"');
  27.  
  28.         while ($line $rs->fetch ()){
  29.             $results[$line->name;
  30.         }
  31.  
  32.         return $results;
  33.     }
  34.  
  35.     /**
  36.     * récupère la liste des champs pour une base donnée.
  37.     * @return   array    $tab[NomDuChamp] = obj avec prop (tye, length, lengthVar, notnull)
  38.     */
  39.     protected function _getFieldList ($tableName{
  40.         $results array ();
  41.  
  42.         $query "PRAGMA table_info("sqlite_escape_string($tableName.")";
  43.         $rs $this->_connector->query($query);
  44.         while ($line $rs->fetch()) {
  45.             $field new jDbFieldProperties();
  46.             $field->name $line->name;
  47.             $field->primary  ($line->pk == 1);
  48.             $field->notNull   ($line->notnull == '99' || $line->pk == 1);
  49.  
  50.             if (preg_match('/^(\w+)\s*(\((\d+)\))?.*$/',$line->type,$m)) {
  51.                 $field->type strtolower($m[1]);
  52.                 if (isset($m[3])) {
  53.                     $field->length intval($m[3]);
  54.                 }
  55.             }
  56.             else {
  57.                 $field->type $line->type;
  58.             }
  59.  
  60.             if ($field->type == 'integer' && $field->primary{
  61.                 $field->autoIncrement true;
  62.             }
  63.             if (!$field->primary{
  64.                 if ($line->dflt_value !== null || ($line->dflt_value === null && !$field->notNull)) {
  65.                     $field->hasDefault true;
  66.                     $field->default =  $line->dflt_value;
  67.                 }
  68.             }
  69.             $results[$line->name$field;
  70.         }
  71.         return $results;
  72.     }
  73. }
  74. ?>

Documentation generated on Wed, 07 Sep 2011 13:48:31 +0200 by phpDocumentor 1.4.3