Skip to content

Commit

Permalink
version => 2.7.16
Browse files Browse the repository at this point in the history
  • Loading branch information
billge committed Jan 17, 2018
1 parent cbcff3b commit a3d5fbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Biny

[![license](http://img.shields.io/badge/license-BSD3-blue.svg?style=flat)](https://github.com/tencent/biny/blob/master/LICENSE.TXT)
[![Release Version](https://img.shields.io/badge/release-2.7.15-red.svg)](https://github.com/tencent/biny/releases)
[![Release Version](https://img.shields.io/badge/release-2.7.16-red.svg)](https://github.com/tencent/biny/releases)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tencent/biny/pulls)

Biny是一款高性能的轻量级PHP框架
Expand Down
13 changes: 13 additions & 0 deletions app/template/demo/demo.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@
-><func>filter</func>(<sys>array</sys>(<sys>array</sys>(),<sys>array</sys>(<str>'type'</str>=><str>'admin'</str>)))
-><func>query</func>();</pre>

<p>另外,如果想实现<code>where start=end</code>或者<code>where start=end+86400</code>这类的条件也是支持的,方法如下:</p>
<pre class="code"><note>// ... WHERE `user`.`lastLoginTime` = `user`.`registerTime` and `user`.`lastLoginTime` <= refreshTime+86400</note>
<prm>$filter</prm> = <prm>$this</prm>-><prm>userDAO</prm>-><func>filter</func>(<sys>array</sys>(
<str>'lastLoginTime'</str>=>TXDatabase::<func>field</func>(<str>'`user`.`registerTime`'</str>),
<str>'<='</str>=><sys>array</sys>(<str>'lastLoginTime'</str>=>TXDatabase::<func>field</func>(<str>'refreshTime+86400'</str>)),
));</pre>

<p>无论是<code>filter</code>还是<code>merge</code>,在执行SQL语句前都<code>不会被执行</code>,不会增加sql负担,可以放心使用。</p>

<h2 id="dao-extracts">复杂选择</h2>
Expand Down Expand Up @@ -1001,6 +1008,12 @@
<note>// 100 (user表总行数)</note>
<prm>$count</prm> = <prm>$this</prm>-><prm>userDAO</prm>-><func>count</func>()</pre>

<p>Biny同时也可以使用<code>TXDatabase::field()</code>来支持复杂的<code>Group By</code>语句,例如:</p>
<pre class="code"><note>// SELECT FROM_UNIXTIME(time,'%Y-%m-%d') AS time, count(*) AS 'count'
FROM `user` Group By FROM_UNIXTIME(time,'%Y-%m-%d')</note>
<prm>$result</prm> = <prm>$this</prm>-><prm>userDAO</prm>-><func>group</func>(TXDatabase::<func>field</func>(<str>"FROM_UNIXTIME(time,'%Y-%m-%d')"</str>))
-><func>addition</func>(<sys>array</sys>(<str>'count'</str>=><str>'*'</str>))
-><func>query</func>(<str>"FROM_UNIXTIME(time,'%Y-%m-%d') AS time");</pre>

<h2 id="dao-command">SQL模版</h2>
<p>框架中提供了上述<code>选择器</code>,<code>条件语句</code>,<code>联表</code>等,基本覆盖了所有sql语法,但可能还有部分生僻的用法无法被实现,
Expand Down
21 changes: 11 additions & 10 deletions lib/models/TXSingleDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,22 @@ protected function buildFields($fields, $group=[]){
if (!in_array(strtolower($key), $this->calcs)){
throw new TXException(3011, [$key]);
}
$calc = $key == 'distinct' ? "COUNT(DISTINCT " : "{$key}(";
if (is_string($values)){
$values = $values === '*' ? $values : '`'.$this->real_escape_string($values).'`';
$groups[] = $calc."{$values}) as '{$key}'";
continue;
} else if ($values instanceof \stdClass){
$groups[] = $calc."{$values->scalar}) as '{$key}'";
continue;
}
foreach ($values as $k => $value){
$value = $this->real_escape_string($value);
if (is_string($k)){
$k = $this->real_escape_string($k);
if ($key == 'distinct'){
$groups[] = "COUNT(DISTINCT `{$k}`) as '{$value}'";
} else {
$groups[] = "{$key}(`{$k}`) as '{$value}'";
}
$groups[] = $calc."`{$k}`) as '{$value}'";
} else {
if ($key == 'distinct'){
$groups[] = "COUNT(DISTINCT `{$value}`) as '{$value}'";
} else {
$groups[] = "{$key}(`{$value}`) as '{$value}'";
}
$groups[] = $calc."`{$value}`) as '{$value}'";
}
}
}
Expand Down

0 comments on commit a3d5fbb

Please sign in to comment.