[limb-svn] r5975 - in 3.x/trunk/limb/dbal: src/drivers/sqlite tests/cases/driver

svn at limb-project.com svn at limb-project.com
Fri Jun 8 20:37:34 MSD 2007


Author: pachanga
Date: 2007-06-08 20:37:33 +0400 (Fri, 08 Jun 2007)
New Revision: 5975
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5975

Modified:
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteColumnInfo.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php
   3.x/trunk/limb/dbal/tests/cases/driver/DriverColumnInfoTestBase.class.php
Log:
-- all sqlite tests pass

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteColumnInfo.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteColumnInfo.class.php	2007-06-08 14:02:24 UTC (rev 5974)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteColumnInfo.class.php	2007-06-08 16:37:33 UTC (rev 5975)
@@ -1,20 +1,20 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 lmb_require('limb/dbal/src/drivers/lmbDbColumnInfo.class.php');
-lmb_require(dirname(__FILE__) . '/lmbSqliteTypeInfo.class.php');
-
+lmb_require(dirname(__FILE__) . '/lmbSqliteTypeInfo.class.php');
+
 /**
  * class lmbSqliteColumnInfo.
  *
  * @package dbal
  * @version $Id$
- */
+ */
 class lmbSqliteColumnInfo extends lmbDbColumnInfo
 {
   protected $nativeType;
@@ -32,13 +32,12 @@
                 $isAutoIncrement = null,
                 $isExisting = false)
   {
-
     $this->nativeType = $this->canonicalizeNativeType($nativeType);
     $this->isAutoIncrement = $this->canonicalizeIsAutoincrement($isAutoIncrement);
 
     $typeinfo = new lmbSqliteTypeInfo();
     $typemap = $typeinfo->getNativeToColumnTypeMapping();
-    $type = $typemap[$nativeType];
+    $type = $typemap[$this->nativeType];
 
     $this->isExisting = $isExisting;
 
@@ -52,7 +51,7 @@
 
   function canonicalizeNativeType($nativeType)
   {
-    return $nativeType;
+    return strtolower($nativeType);
   }
 
   function isAutoIncrement()

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php	2007-06-08 14:02:24 UTC (rev 5974)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php	2007-06-08 16:37:33 UTC (rev 5975)
@@ -2,9 +2,9 @@
 /*
  * Limb PHP Framework
  *
- * @link http://limb-project.com 
+ * @link http://limb-project.com
  * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 lmb_require('limb/dbal/src/drivers/lmbDbInfo.class.php');
 lmb_require('limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php');
@@ -37,11 +37,13 @@
   {
     if($this->isExisting && !$this->isTablesLoaded)
     {
-      $queryId = $this->connection->execute("SHOW TABLES FROM '" . $this->name . "'");
-      while(is_array($value = sqlite_fetch_single($queryId)))
-      {
-        $this->tables[$value] = null;
-      }
+      $sql = "SELECT name FROM sqlite_master WHERE type='table' UNION ALL " .
+             "SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;";
+
+      $queryId = $this->connection->execute($sql);
+      while(sqlite_has_more($queryId))
+        $this->tables[sqlite_fetch_single($queryId)] = null;
+
       $this->isTablesLoaded = true;
     }
   }
@@ -49,13 +51,11 @@
   function getTable($name)
   {
     if(!$this->hasTable($name))
-    {
       throw new lmbDbException("Table does not exist '$name'");
-    }
+
     if(is_null($this->tables[$name]))
-    {
       $this->tables[$name] = new lmbSqliteTableInfo($this, $name, true);
-    }
+
     return $this->tables[$name];
   }
 }

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php	2007-06-08 14:02:24 UTC (rev 5974)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php	2007-06-08 16:37:33 UTC (rev 5975)
@@ -2,9 +2,9 @@
 /*
  * Limb PHP Framework
  *
- * @link http://limb-project.com 
+ * @link http://limb-project.com
  * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 lmb_require('limb/dbal/src/drivers/lmbDbTableInfo.class.php');
 lmb_require('limb/dbal/src/drivers/sqlite/lmbSqliteColumnInfo.class.php');
@@ -39,47 +39,45 @@
     if($this->isExisting && !$this->isColumnsLoaded)
     {
       $connection = $this->database->getConnection();
-      $queryId = $connection->execute("SHOW COLUMNS FROM '" . $this->name . "'");
+      $sql = "PRAGMA table_info('" . $this->name . "')";
+      $queryId = $connection->execute($sql);
 
       while($row = sqlite_fetch_array($queryId, SQLITE_ASSOC))
       {
-        $name = $row['Field'];
-        $isNullable =($row['Null'] == 'YES');
-        $isAutoIncrement =(strpos($row['Extra'], 'auto_increment') !== false);
-        $size = null;
-        $precision = null;
+        $name = $row['name'];
 
-        if(preg_match('/^(\w+)[\(]?([\d,]*)[\)]?( |$)/', $row['Type'], $matches))
+        $fulltype = $row['type'];
+        $size = null;
+        $scale = null;
+        if(preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches))
         {
-          //            colname[1]   size/precision[2]
-          $nativeType = $matches[1];
-          if($matches[2])
-          {
-            if(($cpos = strpos($matches[2], ',')) !== false)
-            {
-              $size = (int) substr($matches[2], 0, $cpos);
-              $precision = (int) substr($matches[2], $cpos + 1);
-            }
-            else
-            {
-              $size = (int) $matches[2];
-            }
-          }
+          $type = $matches[1];
+          $size = $matches[2];
+          $scale = $matches[3]; // aka precision
         }
-        elseif(preg_match('/^(\w+)\(/', $row['Type'], $matches))
+        elseif(preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches))
         {
-          $nativeType = $matches[1];
+          $type = $matches[1];
+          $size = $matches[2];
         }
         else
-        {
-          $nativeType = $row['Type'];
-        }
+          $type = $fulltype;
 
-        // BLOBs can't have any default values in MySQL
-        $default = preg_match('~blob|text~', $nativeType) ?  null : $row['Default'];
+        // If column is primary key and of type INTEGER, it is auto increment
+        // See: http://sqlite.org/faq.html#q1
+        $is_auto_increment = ($row['pk'] == 1 && $fulltype == 'INTEGER');
+        $not_null = $row['notnull'];
+        $is_nullable = !$not_null;
 
-        $this->columns[$name] = new lmbSqliteColumnInfo($this,
-                    $name, $nativeType, $size, $precision, $isNullable, $default, $isAutoIncrement);
+        $default_val = $row['dflt_value'];
+
+        $this->columns[$name] = new lmbSqliteColumnInfo($this, $name, $type, $size, $scale,
+                                                        $is_nullable, $default_val, $is_auto_increment);
+
+        if(($row['pk'] == 1) || (strtolower($type) == 'integer primary key'))
+        {
+          //primary key handling...
+        }
       }
       $this->isColumnsLoaded = true;
     }

Modified: 3.x/trunk/limb/dbal/tests/cases/driver/DriverColumnInfoTestBase.class.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/driver/DriverColumnInfoTestBase.class.php	2007-06-08 14:02:24 UTC (rev 5974)
+++ 3.x/trunk/limb/dbal/tests/cases/driver/DriverColumnInfoTestBase.class.php	2007-06-08 16:37:33 UTC (rev 5975)
@@ -2,15 +2,14 @@
 /*
  * Limb PHP Framework
  *
- * @link http://limb-project.com 
+ * @link http://limb-project.com
  * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 require_once(dirname(__FILE__) . '/DriverMetaTestBase.class.php');
 
 abstract class DriverColumnInfoTestBase extends DriverMetaTestBase
 {
-
   var $table;
 
   function setUp()



More information about the limb-svn mailing list