/** * Clone the cell collection * * @param PHPExcel_Worksheet $parent The new worksheet * * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { $this->_currentCellIsDirty; $this->_storeData(); // Get a new id for the new table name $tableName = str_replace('.', '_', $this->_getUniqueID()); if (!$this->_DBHandle->exec('CREATE TABLE kvp_' . $tableName . ' (id VARCHAR(12) PRIMARY KEY, value BLOB) AS SELECT * FROM kvp_' . $this->_TableName)) { throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); } // Copy the existing cell cache file $this->_TableName = $tableName; }
/** * Initialise this new cell collection * * @param PHPExcel_Worksheet $parent The worksheet for this cell collection */ 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); if ($this->_DBHandle === false) { throw new Exception($this->_DBHandle->lastErrorMsg()); } if (!$this->_DBHandle->exec('CREATE TABLE kvp_' . $this->_TableName . ' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) { throw new Exception($this->_DBHandle->lastErrorMsg()); } } }
/** * 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; } $query = "DELETE FROM kvp_" . $this->_TableName . " WHERE id = '" . $toAddress . "'"; $result = $this->_DBHandle->exec($query); if ($result === false) { throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); } $query = "UPDATE kvp_" . $this->_TableName . " SET id = '" . $toAddress . "' WHERE id = '" . $fromAddress . "'"; $result = $this->_DBHandle->exec($query); if ($result === false) { throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); } return true; }
/** * Initialise this new cell collection * * @param PHPExcel_Worksheet $parent The worksheet for this cell collection */ 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); if ($this->_DBHandle === false) { throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); } if (!$this->_DBHandle->exec('CREATE TABLE kvp_' . $this->_TableName . ' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) { throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); } } $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"); }
/** * 直接查询Sql * * @param String $SQL * @return Mix */ function query($sql) { if (!$this->conn) { $this->connect(); } if (strtolower(substr(ltrim($sql), 0, 5)) == 'alter') { $queryparts = preg_split("/[\\s]+/", $sql, 4, PREG_SPLIT_NO_EMPTY); $tablename = $queryparts[2]; $alterdefs = $queryparts[3]; $result = $this->alterTable($tablename, $alterdefs); } else { if ($this->type == "SQLite2") { $result = sqlite_query($sql, $this->conn); } else { $result = $this->conn->query($sql); } } if (!$result) { if ($this->type == "SQLite2") { $this->lasterr = sqlite_last_error($this->conn); $this->lasterrcode = sqlite_error_string($this->lasterr); } elseif ($this->type == "SQLite3") { $this->lasterr = $this->conn->lastErrorCode(); $this->lasterrcode = $this->conn->lastErrorMsg(); } elseif ($this->type == 'PDO') { $this->lasterr = $this->conn->errorCode(); $this->lasterrcode = implode(',', $this->conn->errorInfo()); } if ($this->_transflag) { $this->_transErrors[]['sql'] = $sql; $this->_transErrors[]['errcode'] = $this->lasterrcode; $this->_transErrors[]['err'] = $this->lasterr; } else { exit('SQL:' . $sql . ' ERROR_INFO:' . $this->lasterrcode . ',' . $this->lasterr); return false; } } else { $this->query_num++; $this->lastResult = $result; return $result; } }
public function errorInfo() { return $this->dbh->lastErrorMsg(); }