Refactoring SqlCriteria, SqlModel. Add SqlResultProvider.fetchField().
This commit is contained in:
@ -127,9 +127,9 @@ abstract class SqlDbDriver extends DbDriver
|
||||
/**
|
||||
* @param mixed $where
|
||||
* @return string
|
||||
* TODO: Если cond Это int и term Это тоже int - кидать Exception (иначе эта ошибка повлечет обновление всех записей в таблице
|
||||
* @throws ErrorException
|
||||
*/
|
||||
protected function whereExpr($where)
|
||||
public function whereExpr($where)
|
||||
{
|
||||
if (empty($where)) {
|
||||
return $where;
|
||||
@ -140,16 +140,61 @@ abstract class SqlDbDriver extends DbDriver
|
||||
}
|
||||
foreach ($where as $cond => &$term) {
|
||||
if (is_int($cond)) {
|
||||
if (is_int($term)) {
|
||||
throw new ErrorException('Condition in where expression as integer. Dangerous. ' . $term);
|
||||
}
|
||||
if ($term instanceof DbExpr) {
|
||||
$term = (string) $term;
|
||||
}
|
||||
} else {
|
||||
if (is_array($term)) {
|
||||
$term = new DbExpr('(' . implode(',', array_map(function($item){return intval($item);}, $term)) . ')');
|
||||
}
|
||||
$term = $this->quoteInto($cond, $term);
|
||||
}
|
||||
}
|
||||
return implode(' AND ', $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $select array
|
||||
* @param $distinct string|bool
|
||||
* @return string
|
||||
*/
|
||||
public function selectExpr($select, $distinct = false)
|
||||
{
|
||||
if (empty($distinct) && empty($select)) {
|
||||
return '*';
|
||||
}
|
||||
if (!is_array($select)) {
|
||||
$select = array($select);
|
||||
}
|
||||
if ($distinct) {
|
||||
$distinct = ((is_bool($distinct)) ? '*' : $this->quoteIdentifier($distinct));
|
||||
array_unshift($select, new DbExpr('DISTINCT ' . $distinct));
|
||||
}
|
||||
foreach ($select as $field => &$term) {
|
||||
if (is_int($field)) {
|
||||
if ($term instanceof DbExpr) {
|
||||
$term = (string) $term;
|
||||
} else {
|
||||
$term = $this->quoteIdentifier($term);
|
||||
}
|
||||
} else {
|
||||
$term = $this->quoteIdentifier($field) . ' as ' . $this->quoteIdentifier($term);
|
||||
}
|
||||
}
|
||||
return implode(',', $select);
|
||||
}
|
||||
|
||||
public function limitExpr($limit)
|
||||
{
|
||||
if (empty($limit)) {
|
||||
return $limit;
|
||||
}
|
||||
return implode(',',array_map(function($item){return intval($item);},explode(',',$limit)));
|
||||
}
|
||||
|
||||
abstract protected function driverQuote($value);
|
||||
|
||||
abstract protected function driverBeginTransaction();
|
||||
|
Reference in New Issue
Block a user