From 91f74c5893a43a021b5335d2d263e0a6dd0e8b8b Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Sat, 3 Dec 2011 18:49:27 +0000 Subject: [PATCH] Exception handling for SQLite cell caching git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@83587 2327b42d-5241-43d6-9e2a-de5ac946f064 --- .../PHPExcel/CachedObjectStorage/SQLite.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite.php b/Classes/PHPExcel/CachedObjectStorage/SQLite.php index 6a74f580..ddbdb8e5 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite.php @@ -42,7 +42,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C if ($this->_currentCellIsDirty) { $this->_currentObject->detach(); - $this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')"); + if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')")) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); $this->_currentCellIsDirty = false; } $this->_currentObjectID = $this->_currentObject = null; @@ -85,7 +86,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); - if ($cellResultSet->numRows() == 0) { + if ($cellResultSet === false) { + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); + } elseif ($cellResultSet->numRows() == 0) { // Return null if requested entry doesn't exist in cache return null; } @@ -117,7 +120,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C // Check if the requested entry exists in the cache $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); - if ($cellResultSet->numRows() == 0) { + if ($cellResultSet === false) { + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); + } elseif ($cellResultSet->numRows() == 0) { // Return null if requested entry doesn't exist in cache return false; } @@ -139,7 +144,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C // Check if the requested entry exists in the cache $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; - $this->_DBHandle->queryExec($query); + if (!$this->_DBHandle->queryExec($query)) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); $this->_currentCellIsDirty = false; } // function deleteCacheData() @@ -153,6 +159,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C public function getCellList() { $query = "SELECT id FROM kvp_".$this->_TableName; $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); + if ($cellIdsResult === false) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); $cellKeys = array(); foreach($cellIdsResult as $row) { @@ -171,8 +179,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C public function copyCellCollection(PHPExcel_Worksheet $parent) { // Get a new id for the new table name $tableName = str_replace('.','_',$this->_getUniqueID()); - $this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) - AS SELECT * FROM kvp_'.$this->_TableName); + if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) + AS SELECT * FROM kvp_'.$this->_TableName)) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); // Copy the existing cell cache file $this->_TableName = $tableName; @@ -199,7 +208,10 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C $_DBName = ':memory:'; $this->_DBHandle = new SQLiteDatabase($_DBName); - $this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'); + if ($this->_DBHandle === false) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); + if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); } } // function __construct()