列的當前值countProductSelect和countProductInput - INTEGER NOT NULL;無法從SQLite中新創建的列中獲取數據
需要使INTEGER DEFAULT NULL;
下面的PHP代碼。
的問題是,當試圖更新數據和countProductSelect countProductInput,從時間列和countProductSelectTmp countProductInputTmp,得到錯誤 - 「沒有這樣的列:countProductSelectTmp」。
如何處理這個錯誤?或者也許有更多受過教育的算法來解決原始問題?
/**
* Updating the database
*
* @return bool
*/
protected function _updateDB()
{
$version = '3.8.4.0';
$this->_pdo->exec('
ALTER TABLE data ADD optionalCountProduct INTEGER DEFAULT NULL;
ALTER TABLE data ADD countProductSelectTmp INTEGER DEFAULT NULL;
ALTER TABLE data ADD countProductInputTmp INTEGER DEFAULT NULL;
UPDATE data SET countProductSelectTmp = countProductSelect, countProductInputTmp = countProductInput;
');
$this->_deleteSQLiteColumn(array('countProductSelect', 'countProductInput'));
// BUG
// countProductSelect and countProductInput can not get the value countProductSelectTmp and countProductInputTmp
$this->_pdo->exec('
ALTER TABLE data ADD countProductSelect INTEGER DEFAULT NULL;
ALTER TABLE data ADD countProductInput INTEGER DEFAULT NULL;
UPDATE data SET countProductSelect = countProductSelectTmp, countProductInput = countProductInputTmp;
UPDATE version SET id = "' . $version . '";
');
$this->_deleteSQLiteColumn(array('countProductSelectTmp', 'countProductInputTmp'));
return true;
}
/**
* Remove column from a SQLite Table
*
* @param array $column name of the column to remove
* @return bool
*/
protected function _deleteSQLiteColumn(array $column)
{
return (bool)$this->_pdo->exec('
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE backup(' . $this->_getFullColumnsString() . ');
INSERT INTO backup SELECT ' . $this->_getShortColumnsString() . ' FROM data;
DROP TABLE data;
CREATE TABLE data(' . $this->_getFullColumnsString($column) . ');
INSERT INTO data SELECT ' . $this->_getShortColumnsString($column) . ' FROM backup;
DROP TABLE backup;
COMMIT;
');
}
問題依然存在。仍然需要幫助。 – Gemorroj
@Gemorroj:你的新版本是什麼樣的?當我早上回來時,我會看看。 –