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

svn at limb-project.com svn at limb-project.com
Tue Jun 5 01:48:05 MSD 2007


Author: pachanga
Date: 2007-06-05 01:48:05 +0400 (Tue, 05 Jun 2007)
New Revision: 5934
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5934

Modified:
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteQueryStatement.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php
   3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php
   3.x/trunk/limb/dbal/tests/cases/driver/sqlite/fixture.inc.php
Log:
-- some initial working sqlite tests added

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -1,13 +1,13 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    $package$
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    $package$
  */
 
 lmb_require('limb/dbal/src/drivers/lmbDbConnection.interface.php');
@@ -154,9 +154,9 @@
       return '';
 
     $pieces = explode('.', $id);
-    $quoted = '`' . $pieces[0] . '`';
+    $quoted = "'" . $pieces[0] . "'";
     if(isset($pieces[1]))
-       $quoted .= '.`' . $pieces[1] . '`';
+       $quoted .= ".'" . $pieces[1] . "'";
     return $quoted;
   }
 

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-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDbInfo.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -34,12 +34,11 @@
   {
     if($this->isExisting && !$this->isTablesLoaded)
     {
-      $queryId = $this->connection->execute("SHOW TABLES FROM `" . $this->name . "`");
-      while(is_array($row = mysql_fetch_row($queryId)))
+      $queryId = $this->connection->execute("SHOW TABLES FROM '" . $this->name . "'");
+      while(is_array($value = sqlite_fetch_single($queryId)))
       {
-        $this->tables[$row[0]] = null;
+        $this->tables[$value] = null;
       }
-      mysql_free_result($queryId);
       $this->isTablesLoaded = true;
     }
   }

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -1,13 +1,13 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    $package$
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    $package$
  */
 
 lmb_require('limb/dbal/src/drivers/lmbDbManipulationStatement.interface.php');
@@ -17,7 +17,7 @@
 {
   function getAffectedRowCount()
   {
-    return mysql_affected_rows($this->connection->getConnectionId());
+    return sqlite_changes($this->connection->getConnectionId());
   }
 }
 

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteQueryStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteQueryStatement.class.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteQueryStatement.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -21,18 +21,18 @@
   {
     $record = new lmbSqliteRecord();
     $queryId = $this->connection->execute($this->getSQL());
-    $values = mysql_fetch_assoc($queryId);
-    $record->import($values);
-    mysql_free_result($queryId);
+    $values = sqlite_fetch_array($queryId, SQLITE_ASSOC);       
     if(is_array($values))
+    {
+      $record->import($values);
       return $record;
+    }
   }
 
   function getOneValue()
   {
     $queryId = $this->connection->execute($this->getSQL());
-    $row = mysql_fetch_row($queryId);
-    mysql_free_result($queryId);
+    $row = sqlite_fetch_single($queryId);    
     if(is_array($row))
       return $row[0];
   }
@@ -41,9 +41,8 @@
   {
     $column = array();
     $queryId = $this->connection->execute($this->getSQL());
-    while(is_array($row = mysql_fetch_row($queryId)))
-      $column[] = $row[0];
-    mysql_free_result($queryId);
+    while($value = sqlite_fetch_single($queryId))
+      $column[] = $value;
     return $column;
   }
 

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -31,17 +31,14 @@
   function freeQuery()
   {
     if(isset($this->queryId) && is_resource($this->queryId))
-    {
-      mysql_free_result($this->queryId);
       $this->queryId = null;
-    }
   }
 
   function rewind()
   {
-    if(isset($this->queryId) && is_resource($this->queryId) && mysql_num_rows($this->queryId))
+    if(isset($this->queryId) && is_resource($this->queryId) && sqlite_num_rows($this->queryId))
     {
-      if(mysql_data_seek($this->queryId, 0) === false)
+      if(sqlite_seek($this->queryId, 0) === false)
       {
         $this->connection->_raiseError();
       }
@@ -65,8 +62,8 @@
       if($this->limit)
       {
         $query .= ' LIMIT ' .
-        $this->offset . ',' .
-        $this->limit;
+        $this->limit . ' OFFSET ' . 
+        $this->offset;        
       }
 
       $this->queryId = $this->connection->execute($query);
@@ -78,7 +75,7 @@
   function next()
   {
     $this->current = new lmbSqliteRecord();
-    $values = mysql_fetch_assoc($this->queryId);
+    $values = sqlite_fetch_array($this->queryId, SQLITE_ASSOC);
     $this->current->import($values);
     $this->valid = is_array($values);
     $this->key++;
@@ -111,10 +108,9 @@
       $query = rtrim($query, ',');
     }
 
-    $queryId = $this->connection->execute($query . " LIMIT $pos, 1");
+    $queryId = $this->connection->execute($query . " LIMIT 1 OFFSET $pos");
 
-    $res = mysql_fetch_assoc($queryId);
-    mysql_free_result($queryId);
+    $res = sqlite_fetch_array($queryId, SQLITE_ASSOC);    
     if($res)
     {
       $record = new lmbSqliteRecord();
@@ -127,7 +123,7 @@
   {
     if(is_null($this->queryId))
       $this->rewind();
-    return mysql_num_rows($this->queryId);
+    return sqlite_num_rows($this->queryId);
   }
 
   function count()
@@ -138,16 +134,12 @@
       $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','', $rewritesql);
 
       $queryId = $this->connection->execute($rewritesql);
-      $row = mysql_fetch_row($queryId);
-      mysql_free_result($queryId);
-      if(is_array($row))
-        return $row[0];
+      return sqlite_fetch_single($queryId);
     }
 
     // could not re-write the query, try a different method.
     $queryId = $this->connection->execute($this->query);
-    $count = mysql_num_rows($queryId);
-    mysql_free_result($queryId);
+    $count = sqlite_num_rows($queryId);
     return $count;
   }
 }

Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -87,21 +87,21 @@
   {
     $this->parameters[$name] = is_null($value) ?
     'null' :
-    "'" . mysql_escape_string((string) $value) . "'";
+    "'" . sqlite_escape_string((string) $value) . "'";
   }
 
   function setVarChar($name, $value)
   {
     $this->parameters[$name] = is_null($value) ?
     'null' :
-    "'" . mysql_escape_string((string) $value) . "'";
+    "'" . sqlite_escape_string((string) $value) . "'";
   }
 
   function setClob($name, $value)
   {
     $this->parameters[$name] = is_null($value) ?
     'null' :
-    "'" . mysql_escape_string((string) $value) . "'";
+    "'" . sqlite_escape_string((string) $value) . "'";
   }
 
   protected function _setDate($name, $value, $format)
@@ -112,7 +112,7 @@
     }
     else if(is_string($value))
     {
-      $this->parameters[$name] = "'" . mysql_escape_string((string) $value) . "'";
+      $this->parameters[$name] = "'" . sqlite_escape_string((string) $value) . "'";
     }
     else
     {

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-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteTableInfo.class.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -36,9 +36,9 @@
     if($this->isExisting && !$this->isColumnsLoaded)
     {
       $connection = $this->database->getConnection();
-      $queryId = $connection->execute("SHOW COLUMNS FROM `" . $this->name . "`");
+      $queryId = $connection->execute("SHOW COLUMNS FROM '" . $this->name . "'");
 
-      while($row = mysql_fetch_assoc($queryId))
+      while($row = sqlite_fetch_array($queryId, SQLITE_ASSOC))
       {
         $name = $row['Field'];
         $isNullable =($row['Null'] == 'YES');

Modified: 3.x/trunk/limb/dbal/tests/cases/driver/sqlite/fixture.inc.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/driver/sqlite/fixture.inc.php	2007-06-04 13:06:23 UTC (rev 5933)
+++ 3.x/trunk/limb/dbal/tests/cases/driver/sqlite/fixture.inc.php	2007-06-04 21:48:05 UTC (rev 5934)
@@ -1,28 +1,35 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    $package$
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    $package$
  */
 
 function DriverSqliteSetup($conn)
-{
-  if(DriverSqliteTableExists($conn, 'founding_fathers'))
-    DriverSqliteExec($conn, 'DROP TABLE founding_fathers');
+{  
+  DriverSqliteExec($conn, 'DROP TABLE founding_fathers', false);
 
   $sql = "CREATE TABLE founding_fathers (
             id INTEGER,
             first VARCHAR,
             last VARCHAR)";
   DriverSqliteExec($conn, $sql);
+  
+  $inserts = array(
+        "INSERT INTO founding_fathers VALUES (1, 'George', 'Washington');",
+        "INSERT INTO founding_fathers VALUES (2, 'Alexander', 'Hamilton');",
+        "INSERT INTO founding_fathers VALUES (3, 'Benjamin', 'Franklin');"
+    );
 
-  if(DriverSqliteTableExists($conn, 'standard_types'))
-    DriverSqliteExec($conn, 'DROP TABLE standard_types');
+  foreach($inserts as $sql)
+    DriverSqliteExec($conn, $sql);  
+  
+  DriverSqliteExec($conn, 'DROP TABLE standard_types', false);
 
   $sql = "CREATE TABLE standard_types (
             id INTEGER,
@@ -40,35 +47,18 @@
             type_time time,
             type_blob blob)";
   DriverSqliteExec($conn, $sql);
-
-  DriverSqliteExec($conn, 'DELETE founding_fathers');
-  DriverSqliteExec($conn, 'DELETE standard_types');
-
-  $inserts = array(
-        "INSERT INTO founding_fathers VALUES (1, 'George', 'Washington');",
-        "INSERT INTO founding_fathers VALUES (2, 'Alexander', 'Hamilton');",
-        "INSERT INTO founding_fathers VALUES (3, 'Benjamin', 'Franklin');"
-    );
-
-  foreach($inserts as $sql)
-    DriverSqliteExec($conn, $sql);
 }
 
-function DriverSqliteExec($conn, $sql)
+function DriverSqliteExec($conn, $sql, $check_result = true)
 {
-  $result = sqlite_query($conn, $sql);
-  if(!$result)
-    throw new lmbDbException('SQLite error happened: ' . sqlite_error_string(sqlite_last_error($conn)));
-  return $result;
-}
-
-function DriverSqliteTableExists($conn, $table)
-{
-  $query = DriverSqliteExec($conn, "SELECT name FROM sqlite_master WHERE type='table'");
-  if($tables = sqlite_fetch_array($query))
-    return in_array($table, $tables);
+  if($check_result)
+  {    
+    if(!$result = sqlite_query($conn, $sql))
+      throw new lmbDbException('SQLite error happened: ' . sqlite_error_string(sqlite_last_error($conn)));    
+  }
   else
-    return false;
+    $result = @sqlite_query($conn, $sql);
+  return $result;   
 }
 
 ?>
\ No newline at end of file



More information about the limb-svn mailing list