| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-12-31 18:36:33 +00:00
										 |  |  |  * Copyright (c) 2006 - 2014 PHPExcel | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package    PHPExcel_CachedObjectStorage | 
					
						
							| 
									
										
										
										
											2013-12-31 18:36:33 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL | 
					
						
							|  |  |  |  * @version    ##VERSION##, ##DATE##
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel_CachedObjectStorage_SQLite3 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package    PHPExcel_CachedObjectStorage | 
					
						
							| 
									
										
										
										
											2013-12-31 18:36:33 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Database table name | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	private $_TableName = null; | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Database handle | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var resource | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	private $_DBHandle = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-27 13:49:08 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Prepared statement for a SQLite3 select query | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var SQLite3Stmt | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 	private $_selectQuery; | 
					
						
							| 
									
										
										
										
											2013-04-27 13:49:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Prepared statement for a SQLite3 insert query | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var SQLite3Stmt | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 	private $_insertQuery; | 
					
						
							| 
									
										
										
										
											2013-04-27 13:49:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Prepared statement for a SQLite3 update query | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var SQLite3Stmt | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 	private $_updateQuery; | 
					
						
							| 
									
										
										
										
											2013-04-27 13:49:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Prepared statement for a SQLite3 delete query | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var SQLite3Stmt | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 	private $_deleteQuery; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Store cell data in cache for the current cell object if it's "dirty", | 
					
						
							|  |  |  |      *     and the 'nullify' the current cell object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  |      * @throws	PHPExcel_Exception | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-11-29 23:57:12 +00:00
										 |  |  | 	protected function _storeData() { | 
					
						
							| 
									
										
										
										
											2013-12-29 23:48:42 +00:00
										 |  |  | 		if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 			$this->_currentObject->detach(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 			$this->_insertQuery->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT); | 
					
						
							|  |  |  | 			$this->_insertQuery->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB); | 
					
						
							|  |  |  | 			$result = $this->_insertQuery->execute(); | 
					
						
							| 
									
										
										
										
											2011-12-03 20:16:57 +00:00
										 |  |  | 			if ($result === false) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 				throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 			$this->_currentCellIsDirty = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$this->_currentObjectID = $this->_currentObject = null; | 
					
						
							|  |  |  | 	}	//	function _storeData()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  |      * Add or Update a cell in cache identified by coordinate address | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  |      * @param	string			$pCoord		Coordinate address of the cell to update | 
					
						
							|  |  |  |      * @param	PHPExcel_Cell	$cell		Cell to update | 
					
						
							| 
									
										
										
										
											2014-04-03 16:59:47 +00:00
										 |  |  | 	 * @return	PHPExcel_Cell | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  |      * @throws	PHPExcel_Exception | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  | 	public function addCacheData($pCoord, PHPExcel_Cell $cell) { | 
					
						
							|  |  |  | 		if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { | 
					
						
							|  |  |  | 			$this->_storeData(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->_currentObjectID = $pCoord; | 
					
						
							|  |  |  | 		$this->_currentObject = $cell; | 
					
						
							|  |  |  | 		$this->_currentCellIsDirty = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $cell; | 
					
						
							|  |  |  | 	}	//	function addCacheData()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get cell at a specific coordinate | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param 	string 			$pCoord		Coordinate of the cell | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  |      * @throws 	PHPExcel_Exception | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |      * @return 	PHPExcel_Cell 	Cell that was found, or null if not found | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 	public function getCacheData($pCoord) { | 
					
						
							|  |  |  | 		if ($pCoord === $this->_currentObjectID) { | 
					
						
							|  |  |  | 			return $this->_currentObject; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$this->_storeData(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 		$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$cellResult = $this->_selectQuery->execute(); | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		if ($cellResult === FALSE) { | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); | 
					
						
							|  |  |  | 		if ($cellData === FALSE) { | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 			//	Return null if requested entry doesn't exist in cache
 | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Set current entry to the requested entry
 | 
					
						
							|  |  |  | 		$this->_currentObjectID = $pCoord; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		$this->_currentObject = unserialize($cellData['value']); | 
					
						
							| 
									
										
										
										
											2013-02-21 11:44:33 +00:00
										 |  |  |         //    Re-attach this as the cell's parent
 | 
					
						
							|  |  |  |         $this->_currentObject->attach($this); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//	Return requested entry
 | 
					
						
							|  |  |  | 		return $this->_currentObject; | 
					
						
							|  |  |  | 	}	//	function getCacheData()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 *	Is a value set for an indexed cell? | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * @param	string		$pCoord		Coordinate address of the cell to check | 
					
						
							|  |  |  | 	 * @return	boolean | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function isDataSet($pCoord) { | 
					
						
							|  |  |  | 		if ($pCoord === $this->_currentObjectID) { | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 			return TRUE; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Check if the requested entry exists in the cache
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 		$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$cellResult = $this->_selectQuery->execute(); | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		if ($cellResult === FALSE) { | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return ($cellData === FALSE) ? FALSE : TRUE; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	}	//	function isDataSet()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      *	Delete a cell in cache identified by coordinate address | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  |      * @param	string			$pCoord		Coordinate address of the cell to delete | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  |      * @throws	PHPExcel_Exception | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  | 	public function deleteCacheData($pCoord) { | 
					
						
							|  |  |  | 		if ($pCoord === $this->_currentObjectID) { | 
					
						
							|  |  |  | 			$this->_currentObject->detach(); | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 			$this->_currentObjectID = $this->_currentObject = NULL; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Check if the requested entry exists in the cache
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 		$this->_deleteQuery->bindValue('id',$pCoord,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$result = $this->_deleteQuery->execute(); | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		if ($result === FALSE) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-01 13:50:06 +00:00
										 |  |  | 		$this->_currentCellIsDirty = FALSE; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	}	//	function deleteCacheData()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-27 23:13:49 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Move a cell object from one address to another | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string		$fromAddress	Current address of the cell to move | 
					
						
							|  |  |  | 	 * @param	string		$toAddress		Destination address of the cell to move | 
					
						
							|  |  |  | 	 * @return	boolean | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function moveCell($fromAddress, $toAddress) { | 
					
						
							|  |  |  | 		if ($fromAddress === $this->_currentObjectID) { | 
					
						
							|  |  |  | 			$this->_currentObjectID = $toAddress; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 		$this->_deleteQuery->bindValue('id',$toAddress,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$result = $this->_deleteQuery->execute(); | 
					
						
							| 
									
										
										
										
											2013-02-27 23:13:49 +00:00
										 |  |  | 		if ($result === false) | 
					
						
							|  |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 		$this->_updateQuery->bindValue('toid',$toAddress,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$this->_updateQuery->bindValue('fromid',$fromAddress,SQLITE3_TEXT); | 
					
						
							|  |  |  | 		$result = $this->_updateQuery->execute(); | 
					
						
							| 
									
										
										
										
											2013-02-27 23:13:49 +00:00
										 |  |  | 		if ($result === false) | 
					
						
							|  |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return TRUE; | 
					
						
							|  |  |  | 	}	//	function moveCell()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * Get a list of all cell addresses currently held in cache | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2014-04-03 16:59:47 +00:00
										 |  |  | 	 * @return	string[] | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getCellList() { | 
					
						
							| 
									
										
										
										
											2012-11-29 23:57:12 +00:00
										 |  |  | 		if ($this->_currentObjectID !== null) { | 
					
						
							|  |  |  | 			$this->_storeData(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		$query = "SELECT id FROM kvp_".$this->_TableName; | 
					
						
							|  |  |  | 		$cellIdsResult = $this->_DBHandle->query($query); | 
					
						
							| 
									
										
										
										
											2011-12-03 20:16:57 +00:00
										 |  |  | 		if ($cellIdsResult === false) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$cellKeys = array(); | 
					
						
							|  |  |  | 		while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) { | 
					
						
							|  |  |  | 			$cellKeys[] = $row['id']; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $cellKeys; | 
					
						
							|  |  |  | 	}	//	function getCellList()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * Clone the cell collection | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 	 * @param	PHPExcel_Worksheet	$parent		The new worksheet | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * @return	void | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function copyCellCollection(PHPExcel_Worksheet $parent) { | 
					
						
							| 
									
										
										
										
											2012-11-29 23:57:12 +00:00
										 |  |  | 		$this->_currentCellIsDirty; | 
					
						
							|  |  |  |         $this->_storeData(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		//	Get a new id for the new table name
 | 
					
						
							|  |  |  | 		$tableName = str_replace('.','_',$this->_getUniqueID()); | 
					
						
							| 
									
										
										
										
											2011-12-03 20:16:57 +00:00
										 |  |  | 		if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) | 
					
						
							|  |  |  | 		                                       AS SELECT * FROM kvp_'.$this->_TableName)) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 			throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//	Copy the existing cell cache file
 | 
					
						
							|  |  |  | 		$this->_TableName = $tableName; | 
					
						
							|  |  |  | 	}	//	function copyCellCollection()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Clear the cell collection and disconnect from our parent | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return	void | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	public function unsetWorksheetCells() { | 
					
						
							|  |  |  | 		if(!is_null($this->_currentObject)) { | 
					
						
							|  |  |  | 			$this->_currentObject->detach(); | 
					
						
							|  |  |  | 			$this->_currentObject = $this->_currentObjectID = null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		//	detach ourself from the worksheet, so that it can then delete this object successfully
 | 
					
						
							|  |  |  | 		$this->_parent = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Close down the temporary cache file
 | 
					
						
							|  |  |  | 		$this->__destruct(); | 
					
						
							|  |  |  | 	}	//	function unsetWorksheetCells()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Initialise this new cell collection | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	PHPExcel_Worksheet	$parent		The worksheet for this cell collection | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	public function __construct(PHPExcel_Worksheet $parent) { | 
					
						
							|  |  |  | 		parent::__construct($parent); | 
					
						
							|  |  |  | 		if (is_null($this->_DBHandle)) { | 
					
						
							|  |  |  | 			$this->_TableName = str_replace('.','_',$this->_getUniqueID()); | 
					
						
							|  |  |  | 			$_DBName = ':memory:'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->_DBHandle = new SQLite3($_DBName); | 
					
						
							| 
									
										
										
										
											2011-12-03 20:16:57 +00:00
										 |  |  | 			if ($this->_DBHandle === false) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 				throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 20:16:57 +00:00
										 |  |  | 			if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) | 
					
						
							| 
									
										
										
										
											2013-01-15 21:42:28 +00:00
										 |  |  | 				throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-06 17:43:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$this->_selectQuery = $this->_DBHandle->prepare("SELECT value FROM kvp_".$this->_TableName." WHERE id = :id"); | 
					
						
							|  |  |  | 		$this->_insertQuery = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)"); | 
					
						
							|  |  |  | 		$this->_updateQuery = $this->_DBHandle->prepare("UPDATE kvp_".$this->_TableName." SET id=:toId WHERE id=:fromId"); | 
					
						
							|  |  |  | 		$this->_deleteQuery = $this->_DBHandle->prepare("DELETE FROM kvp_".$this->_TableName." WHERE id = :id"); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	}	//	function __construct()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 23:55:54 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Destroy this cell collection | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 	public function __destruct() { | 
					
						
							|  |  |  | 		if (!is_null($this->_DBHandle)) { | 
					
						
							| 
									
										
										
										
											2013-03-06 17:19:22 +00:00
										 |  |  | 			$this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | 			$this->_DBHandle->close(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$this->_DBHandle = null; | 
					
						
							|  |  |  | 	}	//	function __destruct()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 12:10:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * Identify whether the caching method is currently available | 
					
						
							|  |  |  | 	 * Some methods are dependent on the availability of certain extensions being enabled in the PHP build | 
					
						
							| 
									
										
										
										
											2011-12-09 12:10:46 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-03-11 17:58:38 +00:00
										 |  |  | 	 * @return	boolean | 
					
						
							| 
									
										
										
										
											2011-12-09 12:10:46 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function cacheMethodIsAvailable() { | 
					
						
							| 
									
										
										
										
											2012-09-06 21:56:56 +00:00
										 |  |  | 		if (!class_exists('SQLite3',FALSE)) { | 
					
						
							| 
									
										
										
										
											2011-12-09 12:10:46 +00:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:24:44 +00:00
										 |  |  | } |