Exception handling for SQLite cell caching
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@83587 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
bde593557d
commit
91f74c5893
|
@ -42,7 +42,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
if ($this->_currentCellIsDirty) {
|
if ($this->_currentCellIsDirty) {
|
||||||
$this->_currentObject->detach();
|
$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->_currentCellIsDirty = false;
|
||||||
}
|
}
|
||||||
$this->_currentObjectID = $this->_currentObject = null;
|
$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."'";
|
$query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
|
||||||
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
|
$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 if requested entry doesn't exist in cache
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +120,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
// Check if the requested entry exists in the cache
|
// Check if the requested entry exists in the cache
|
||||||
$query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
|
$query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
|
||||||
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
|
$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 if requested entry doesn't exist in cache
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +144,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
|
|
||||||
// Check if the requested entry exists in the cache
|
// Check if the requested entry exists in the cache
|
||||||
$query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
|
$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;
|
$this->_currentCellIsDirty = false;
|
||||||
} // function deleteCacheData()
|
} // function deleteCacheData()
|
||||||
|
@ -153,6 +159,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
public function getCellList() {
|
public function getCellList() {
|
||||||
$query = "SELECT id FROM kvp_".$this->_TableName;
|
$query = "SELECT id FROM kvp_".$this->_TableName;
|
||||||
$cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
|
$cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
|
||||||
|
if ($cellIdsResult === false)
|
||||||
|
throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
|
||||||
|
|
||||||
$cellKeys = array();
|
$cellKeys = array();
|
||||||
foreach($cellIdsResult as $row) {
|
foreach($cellIdsResult as $row) {
|
||||||
|
@ -171,8 +179,9 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
public function copyCellCollection(PHPExcel_Worksheet $parent) {
|
public function copyCellCollection(PHPExcel_Worksheet $parent) {
|
||||||
// Get a new id for the new table name
|
// Get a new id for the new table name
|
||||||
$tableName = str_replace('.','_',$this->_getUniqueID());
|
$tableName = str_replace('.','_',$this->_getUniqueID());
|
||||||
$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||||
AS SELECT * FROM kvp_'.$this->_TableName);
|
AS SELECT * FROM kvp_'.$this->_TableName))
|
||||||
|
throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
|
||||||
|
|
||||||
// Copy the existing cell cache file
|
// Copy the existing cell cache file
|
||||||
$this->_TableName = $tableName;
|
$this->_TableName = $tableName;
|
||||||
|
@ -199,7 +208,10 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
|
||||||
$_DBName = ':memory:';
|
$_DBName = ':memory:';
|
||||||
|
|
||||||
$this->_DBHandle = new SQLiteDatabase($_DBName);
|
$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()
|
} // function __construct()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue