mirror of
https://github.com/typecho/typecho.git
synced 2025-03-18 08:59:40 +01:00
增加HAVING语句方法
This commit is contained in:
parent
4ddd293f3d
commit
7c1ff3029b
@ -146,7 +146,7 @@ class Typecho_Db_Adapter_Mysql implements Typecho_Db_Adapter
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,6 +87,6 @@ class Typecho_Db_Adapter_Pdo_Mysql extends Typecho_Db_Adapter_Pdo
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class Typecho_Db_Adapter_Pdo_Pgsql extends Typecho_Db_Adapter_Pdo
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,6 +73,6 @@ class Typecho_Db_Adapter_Pdo_SQLite extends Typecho_Db_Adapter_Pdo
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class Typecho_Db_Adapter_Pgsql implements Typecho_Db_Adapter
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,7 +174,7 @@ class Typecho_Db_Adapter_SQLite implements Typecho_Db_Adapter
|
||||
$sql['offset'] = (0 == strlen($sql['offset'])) ? NULL : ' OFFSET ' . $sql['offset'];
|
||||
|
||||
return 'SELECT ' . $sql['fields'] . ' FROM ' . $sql['table'] .
|
||||
$sql['where'] . $sql['group'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
$sql['where'] . $sql['group'] . $sql['having'] . $sql['order'] . $sql['limit'] . $sql['offset'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,6 +73,7 @@ class Typecho_Db_Query
|
||||
'offset' => NULL,
|
||||
'order' => NULL,
|
||||
'group' => NULL,
|
||||
'having' => NULL,
|
||||
'rows' => array(),
|
||||
);
|
||||
}
|
||||
@ -339,6 +340,28 @@ class Typecho_Db_Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* HAVING (HAVING)
|
||||
*
|
||||
* @return Typecho_Db_Query
|
||||
*/
|
||||
public function having()
|
||||
{
|
||||
$condition = func_get_arg(0);
|
||||
$condition = str_replace('?', "%s", $this->filterColumn($condition));
|
||||
$operator = empty($this->_sqlPreBuild['having']) ? ' HAVING ' : ' AND';
|
||||
|
||||
if (func_num_args() <= 1) {
|
||||
$this->_sqlPreBuild['having'] .= $operator . ' (' . $condition . ')';
|
||||
} else {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
$this->_sqlPreBuild['having'] .= $operator . ' (' . vsprintf($condition, array_map(array($this->_adapter, 'quoteValue'), $args)) . ')';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择查询字段
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user