改进Builder类的insertall方法

This commit is contained in:
thinkphp
2016-06-21 13:54:55 +08:00
parent 92b3fb7006
commit b4a1905200

View File

@@ -340,13 +340,13 @@ abstract class Builder
} else { } else {
$whereStr .= $exp . ' (' . $value . ')'; $whereStr .= $exp . ' (' . $value . ')';
} }
} elseif (in_array($exp, ['< TIME', '> TIME'])){ } elseif (in_array($exp, ['< TIME', '> TIME'])) {
$whereStr .= $key . ' ' . substr($exp,0,1) . ' ' . $this->parseDateTime($value, $field); $whereStr .= $key . ' ' . substr($exp, 0, 1) . ' ' . $this->parseDateTime($value, $field);
} elseif (in_array($exp, ['BETWEEN TIME', 'NOT BETWEEN TIME'])){ } elseif (in_array($exp, ['BETWEEN TIME', 'NOT BETWEEN TIME'])) {
if(is_string($value)){ if (is_string($value)) {
$value = explode(',',$value); $value = explode(',', $value);
} }
$whereStr .= $key . ' ' . substr($exp,0,-4) . $this->parseDateTime($value[0], $field) . ' AND ' . $this->parseDateTime($value[1], $field); $whereStr .= $key . ' ' . substr($exp, 0, -4) . $this->parseDateTime($value[0], $field) . ' AND ' . $this->parseDateTime($value[1], $field);
} }
return $whereStr; return $whereStr;
} }
@@ -370,17 +370,17 @@ abstract class Builder
{ {
// 获取时间字段类型 // 获取时间字段类型
$type = $this->query->getTableInfo('', 'type'); $type = $this->query->getTableInfo('', 'type');
if(isset($type[$key])){ if (isset($type[$key])) {
$value = strtotime($value) ?: $value; $value = strtotime($value) ?: $value;
if(preg_match('/(datetime|timestamp)/is', $type[$key])){ if (preg_match('/(datetime|timestamp)/is', $type[$key])) {
// 日期及时间戳类型 // 日期及时间戳类型
$value = date('Y-m-d H:i:s', $value); $value = date('Y-m-d H:i:s', $value);
}elseif(preg_match('/(date)/is', $type[$key])){ } elseif (preg_match('/(date)/is', $type[$key])) {
// 日期及时间戳类型 // 日期及时间戳类型
$value = date('Y-m-d', $value); $value = date('Y-m-d', $value);
} }
} }
return is_int($value)? $value : $this->connection->quote($value); return is_int($value) ? $value : $this->connection->quote($value);
} }
/** /**
@@ -625,7 +625,7 @@ abstract class Builder
$value = array_values($data); $value = array_values($data);
$values[] = 'SELECT ' . implode(',', $value); $values[] = 'SELECT ' . implode(',', $value);
} }
$fields = array_map([$this, 'parseKey'], array_keys($dataSet[0])); $fields = array_map([$this, 'parseKey'], array_keys(reset($dataSet)));
$sql = str_replace( $sql = str_replace(
['%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], ['%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'],
[ [