This commit is contained in:
2020-09-11 16:27:08 +08:00
parent 3bbd3e7c4e
commit b9a017571f
3 changed files with 48 additions and 59 deletions
-40
View File
@@ -309,16 +309,6 @@ class Command extends Component
return $this->execute(static::EXECUTE);
}
/**
* @param PDOStatement $prepare
* @param $name
* @param $value
*/
public function bindParam($prepare, $name, $value)
{
$prepare->bindParam($name, $value);
}
/**
* @param array|null $data
* @return $this
@@ -353,34 +343,4 @@ class Command extends Component
return $this->prepare->errorInfo()[2] ?? 'Db 驱动错误.';
}
/**
* @return bool
* @throws Exception
*/
public function addErrorLog()
{
if ($this->prepare->errorCode() === '00000') {
return true;
}
return $this->addError($this->getError(), 'mysql');
}
/**
* @param PDOStatement $prepare
* @return PDOStatement
* @throws Exception
*/
private function bind($prepare)
{
if (empty($this->params)) {
return $prepare;
}
foreach ($this->params as $key => $val) {
if (is_array($val)) {
throw new Exception("Save data cannot have array");
}
$this->bindParam($prepare, ':' . ltrim($key, ':'), $val);
}
return $prepare;
}
}
+44 -14
View File
@@ -229,23 +229,54 @@ class Columns extends Component
if (empty($column)) {
throw new Exception("The table " . $table . " not exists.");
}
foreach ($column as $key => $item) {
$column[$key]['Type'] = $this->clean($item['Type']);
if ($item['Key'] === 'PRI') {
if (!isset($this->_primary[$table])) {
$this->_primary[$table] = [];
}
$this->_primary[$table][] = $item['Field'];
}
if ($item['Extra'] === 'auto_increment') {
$this->_auto_increment[$table] = $item['Field'];
}
}
$this->columns[$table] = $column;
$this->columns[$table] = $this->resolve($column, $table);
return $this;
}
/**
* @param $column
* @param $table
* @return mixed
*/
private function resolve(array $column, $table)
{
foreach ($column as $key => $item) {
$this->addPrimary($item, $table);
$column[$key]['Type'] = $this->clean($item['Type']);
}
return $column;
}
/**
* @param $item
* @param $table
*/
private function addPrimary($item, $table)
{
if (!isset($this->_primary[$table])) {
$this->_primary[$table] = [];
}
if ($item['Key'] === 'PRI') {
$this->_primary[$table][] = $item['Field'];
}
$this->addIncrement($item, $table);
}
/**
* @param $item
* @param $table
*/
private function addIncrement($item, $table)
{
if ($item['Extra'] !== 'auto_increment') {
return;
}
$this->_auto_increment[$table] = $item['Field'];
}
/**
* @param $type
* @return string
@@ -255,7 +286,6 @@ class Columns extends Component
if (strpos($type, ')') === false) {
return $type;
}
$replace = preg_replace('/\(\d+(,\d+)?\)(\s+\w+)*/', '', $type);
if (strpos(' ', $replace) !== FALSE) {
$replace = explode(' ', $replace)[1];
+4 -5
View File
@@ -26,7 +26,7 @@ class Change extends BaseObject
* @return string
* @throws Exception
*/
public function update($model, $attributes, $condition, &$params)
public function update(string $model, $attributes, $condition, &$params)
{
if (empty($params)) {
throw new Exception("Not has update values.");
@@ -109,7 +109,7 @@ class Change extends BaseObject
* @return array
* @throws Exception
*/
private function assemble($params, $op, $_tmp)
private function assemble($params, $op, array $_tmp)
{
$message = 'Incr And Decr action. The value must a numeric.';
foreach ($params as $key => $val) {
@@ -247,7 +247,7 @@ class Change extends BaseObject
* @return string
* @throws Exception
*/
public function delete($query)
public function delete(ActiveQuery $query)
{
if (empty($query->from)) {
$query->from = $query->getTable();
@@ -265,9 +265,8 @@ class Change extends BaseObject
/**
* @param string $tableName
* @return string
* @throws
*/
public function truncate($tableName)
public function truncate(string $tableName)
{
return 'TRUNCATE ' . $tableName;
}