Authored by ziy

修复严重BUG

查询和更新都是用了写
... ... @@ -143,11 +143,11 @@ class PDOConnection extends Root
$_serverConfig = $server->getServerConfig('database', $this->_database);
$_dbConfig = $server->getServerConfig('mysql');
if (!isset($_serverConfig[$modality]) || !in_array($modality, array('write', 'read'))) {
throw new DebugException('MySQL db:'.$this->_database.' Not Modality ' . $modality);
throw new DebugException('MySQL db:' . $this->_database . ' Not Modality ' . $modality);
}
$_server = $server->getServerMap($_serverConfig[$modality], Server::SERVER_SELECT_MODEL_RAND);
if (empty($_server)) {
throw new DebugException('Db:'.$this->_database.' Server is null.');
throw new DebugException('Db:' . $this->_database . ' Server is null.');
}
$charset = isset($_dbConfig['charset']) ? $_dbConfig['charset'] : 'UTF8';
#如果设置了 dbname 使用 配置的
... ... @@ -163,7 +163,7 @@ class PDOConnection extends Root
} catch (\Exception $e) {
throw new DebugException($dsn . ' error ' . $e->getMessage());
}
foreach ($this->_attribute as $key => $val) {
$_connection->setAttribute($key, $val);
}
... ... @@ -291,10 +291,10 @@ class PDOConnection extends Root
* @return \PDOStatement
* @throws DebugException
*/
protected function _statement($sql, $parameterMap, $replaceMap)
protected function _statement($sql, array $parameterMap, array $replaceMap = array(), $modality = 'write')
{
$sql = $this->makeReplaceMapToSql($sql, $replaceMap);
$this->_PDOConn = $conn = $this->connect();
$this->_PDOConn = $conn = $this->connect($modality);
$this->_PDOStatement = $stmt = $conn->prepare($sql);
$this->bindValues($parameterMap, $stmt);
$stmt->execute();
... ... @@ -307,8 +307,9 @@ class PDOConnection extends Root
* @param $parameterMap
* @throws DebugException
*/
public function execute($sql, array $parameterMap = array())
public function execute($sql, array $parameterMap = array(), array $replaceMap = array())
{
$sql = $this->makeReplaceMapToSql($sql, $replaceMap);
$this->_PDOConn = $conn = $this->connect();
$this->_PDOStatement = $stmt = $conn->prepare($sql);
$this->bindValues($parameterMap, $stmt);
... ... @@ -391,7 +392,7 @@ class PDOConnection extends Root
*/
public function fetchAssoc($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tmp = array_values(array_slice($row, 0, 1));
... ... @@ -420,7 +421,7 @@ class PDOConnection extends Root
*/
public function fetchClass($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_CLASS, $this->_className);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_CLASS, $this->_className);
}
... ... @@ -433,7 +434,7 @@ class PDOConnection extends Root
*/
public function fetchClassRow($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->_className);
return $stmt->fetch();
}
... ... @@ -457,7 +458,7 @@ class PDOConnection extends Root
*/
public function columnCount($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->columnCount();
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->columnCount();
}
/**
... ... @@ -469,7 +470,7 @@ class PDOConnection extends Root
*/
public function debugDumpParams($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->debugDumpParams();
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->debugDumpParams();
}
... ... @@ -482,7 +483,7 @@ class PDOConnection extends Root
*/
public function fetchAll($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_ASSOC);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_ASSOC);
}
/**
... ... @@ -494,7 +495,7 @@ class PDOConnection extends Root
*/
public function fetchRow($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetch(\PDO::FETCH_ASSOC);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetch(\PDO::FETCH_ASSOC);
}
/**
... ... @@ -507,7 +508,7 @@ class PDOConnection extends Root
*/
public function fetchPairs($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);;
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$data[$row[0]] = $row[1];
... ... @@ -524,7 +525,7 @@ class PDOConnection extends Root
*/
public function fetchOne($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchColumn(0);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchColumn(0);
}
/**
... ... @@ -563,7 +564,7 @@ class PDOConnection extends Root
*/
public function fetchColumn($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchColumn($this->_columnNumber);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchColumn($this->_columnNumber);
}
/**
... ... @@ -575,7 +576,7 @@ class PDOConnection extends Root
*/
public function fetchCol($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_COLUMN, 0);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_COLUMN, 0);
}
/**
... ... @@ -598,7 +599,7 @@ class PDOConnection extends Root
*/
public function fetchObject($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchObject($this->_className);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchObject($this->_className);
}
/**
... ...
... ... @@ -375,13 +375,13 @@ class PDOConnection extends Root
* @return \PDOStatement
* @throws DebugException
*/
protected function _statement($sql, array $parameterMap, array $replaceMap)
protected function _statement($sql, array $parameterMap, array $replaceMap, $modality = 'write')
{
if (is_object($this->_form)) {
$this->formatParameter($parameterMap);
}
$sql = $this->makeReplaceMapToSql($sql, $replaceMap);
$this->_PDOConn = $conn = $this->connect();
$this->_PDOConn = $conn = $this->connect($modality);
$this->_PDOStatement = $stmt = $conn->prepare($sql);
$this->bindValues($parameterMap, $stmt);
$stmt->execute();
... ... @@ -478,7 +478,7 @@ class PDOConnection extends Root
*/
public function fetchAssoc($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tmp = array_values(array_slice($row, 0, 1));
... ... @@ -507,7 +507,7 @@ class PDOConnection extends Root
*/
public function fetchClass($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_CLASS, $this->_className);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_CLASS, $this->_className);
}
... ... @@ -520,7 +520,7 @@ class PDOConnection extends Root
*/
public function fetchClassRow($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->_className);
return $stmt->fetch();
}
... ... @@ -544,7 +544,7 @@ class PDOConnection extends Root
*/
public function columnCount($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->columnCount();
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->columnCount();
}
/**
... ... @@ -556,7 +556,7 @@ class PDOConnection extends Root
*/
public function debugDumpParams($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->debugDumpParams();
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->debugDumpParams();
}
... ... @@ -569,7 +569,7 @@ class PDOConnection extends Root
*/
public function fetchAll($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_ASSOC);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_ASSOC);
}
/**
... ... @@ -581,7 +581,7 @@ class PDOConnection extends Root
*/
public function fetchRow($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetch(\PDO::FETCH_ASSOC);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetch(\PDO::FETCH_ASSOC);
}
/**
... ... @@ -594,7 +594,7 @@ class PDOConnection extends Root
*/
public function fetchPairs($sql, $parameterMap = array(), $replaceMap = array())
{
$stmt = $this->_statement($sql, $parameterMap, $replaceMap);;
$stmt = $this->_statement($sql, $parameterMap, $replaceMap, 'read');
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$data[$row[0]] = $row[1];
... ... @@ -611,7 +611,7 @@ class PDOConnection extends Root
*/
public function fetchOne($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchColumn(0);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchColumn(0);
}
/**
... ... @@ -650,7 +650,7 @@ class PDOConnection extends Root
*/
public function fetchColumn($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchColumn($this->_columnNumber);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchColumn($this->_columnNumber);
}
/**
... ... @@ -662,7 +662,7 @@ class PDOConnection extends Root
*/
public function fetchCol($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchAll(\PDO::FETCH_COLUMN, 0);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchAll(\PDO::FETCH_COLUMN, 0);
}
/**
... ... @@ -685,7 +685,7 @@ class PDOConnection extends Root
*/
public function fetchObject($sql, $parameterMap = array(), $replaceMap = array())
{
return $this->_statement($sql, $parameterMap, $replaceMap)->fetchObject($this->_className);
return $this->_statement($sql, $parameterMap, $replaceMap, 'read')->fetchObject($this->_className);
}
/**
... ...
... ... @@ -84,8 +84,12 @@ class Table
*/
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
$this->whereList[$boolean][] = $column . $operator . ':' . $column;
$this->parameterMap[$column] = $value;
if ($operator == 'in') {
$this->whereList[$boolean][] = $column . ' in (' . implode(',', $value) . ')';
} else {
$this->whereList[$boolean][] = $column . $operator . ':' . $column;
$this->parameterMap[$column] = $value;
}
return $this;
}
... ...