Skip to content

Commit a12d9aa

Browse files
committed
修复:部分BUG
1 parent c04aad3 commit a12d9aa

File tree

8 files changed

+338
-250
lines changed

8 files changed

+338
-250
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
/tests
1515
.suda
1616
*.phar
17-
script/docme/template/*.tpl.php
17+
script/docme/template/*.tpl.php
18+
.idea/workspace.xml

system/src/suda/archive/Table.php

+18-16
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,21 @@ public function listWhere($where, array $binds = [], ?int $page = null, int $row
358358
{
359359
$statment = $this->statement;
360360
$where_str = $statment->prepareWhere($where, $binds);
361-
$where = $where_str.' '.$this->genOrderBy();
362361
if ($this->group !== null) {
363-
$where .= ' '. $this->genGroupBy();
362+
$where_str .= ' '. $this->genGroupBy();
364363
}
364+
$where = $where_str.' '.$this->genOrderBy();
365365
return $statment->where($this->getTableName(), $this->getWants(), $where, $binds, [$page, $rows,$offset])->fetchAll();
366366
}
367367

368368
/**
369369
* 根据条件更新列
370370
*
371+
* @param string|array $values 更新的列
372+
* @param string|array $where 条件区域
373+
* @param array $bind 扩展条件值
374+
* @return integer
375+
* @throws \suda\exception\TableException
371376
* @example
372377
*
373378
* 条件可以为键值对也可以为特殊条件
@@ -388,10 +393,6 @@ public function listWhere($where, array $binds = [], ?int $page = null, int $row
388393
* $table->update(['name'=>$name],'id > :id ',['id'=>3]);
389394
* ```
390395
*
391-
* @param string|array $values 更新的列
392-
* @param string|array $where 条件区域
393-
* @param array $bind 扩展条件值
394-
* @return integer
395396
*/
396397
public function update($values, $where, array $bind = []) :int
397398
{
@@ -407,6 +408,14 @@ public function update($values, $where, array $bind = []) :int
407408
/**
408409
* 选择列
409410
*
411+
* @param string|array $wants 想要查询的列
412+
* @param string|array $where 查询条件
413+
* @param array $whereBinder 查询条件的值
414+
* @param integer|null $page 分页页码
415+
* @param integer $row 分页行
416+
* @param boolean $offset 直接偏移
417+
* @return RawQuery
418+
* @throws \suda\exception\TableException
410419
* @example
411420
*
412421
* 相当于 select 语句,返回一个 SQLQuery类
@@ -429,13 +438,6 @@ public function update($values, $where, array $bind = []) :int
429438
* $table->select(['name'],'id > :id',['id'=>2])->fetchAll();
430439
* ```
431440
*
432-
* @param string|array $wants 想要查询的列
433-
* @param string|array $where 查询条件
434-
* @param array $whereBinder 查询条件的值
435-
* @param integer|null $page 分页页码
436-
* @param integer $row 分页行
437-
* @param boolean $offset 直接偏移
438-
* @return RawQuery
439441
*/
440442
public function select($wants, $where, $whereBinder = [], ?int $page = null, int $row = 10, bool $offset = false): RawQuery
441443
{
@@ -450,12 +452,12 @@ public function select($wants, $where, $whereBinder = [], ?int $page = null, int
450452
} else {
451453
$where = $this->statement->prepareWhere($where, $whereBinder);
452454
}
453-
if ($this->orderField !== null) {
454-
$where .= ' '.$this->genOrderBy();
455-
}
456455
if ($this->group !== null) {
457456
$where .= ' '. $this->genGroupBy();
458457
}
458+
if ($this->orderField !== null) {
459+
$where .= ' '.$this->genOrderBy();
460+
}
459461
return $this->statement->where($this->getTableName(), $wants, $where, $whereBinder, [$page, $row, $offset], $offset);
460462
}
461463

system/src/suda/archive/TableAccess.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public function getCreator()
8181
return $this->creator;
8282
}
8383

84-
84+
/**
85+
* @param \suda\archive\creator\Table $table
86+
* @return mixed
87+
*/
8588
abstract protected function onBuildCreator($table);
8689

8790

@@ -265,7 +268,7 @@ public function getTableName():string
265268
* 设置表列
266269
*
267270
* @param array|null $fields
268-
* @return TableAccess
271+
* @return $this
269272
*/
270273
public function setFields(?array $fields=null)
271274
{

system/src/suda/archive/creator/Field.php

+32-32
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ class Field
2929
protected $key; //primary unique index
3030
// foreign key
3131
protected $foreign;
32-
32+
3333
protected $name;
3434
protected $type;
3535
protected $length;
3636
protected $default;
3737
protected $isDefault;
38-
38+
3939
protected $null; // nullable
40-
protected $attribute; // binary unsigned
41-
protected $collation;
40+
protected $attribute; // binary unsigned
41+
protected $collation;
4242
protected $tableName;
4343
protected $charset;
44-
44+
4545
const BINARY = 'BINARY';
4646
const UNSIGNED = 'UNSIGNED';
47-
47+
4848
const UNIQUE = 'UNIQUE';
4949
const PRIMARY = 'PRIMARY';
5050
const INDEX = 'INDEX';
5151
const KEY = 'KEY';
52-
52+
5353
public function __construct(string $tableName, string $name, string $type, int $length = null)
5454
{
5555
$this->tableName = $tableName;
@@ -58,31 +58,31 @@ public function __construct(string $tableName, string $name, string $type, int $
5858
$this->length = $length;
5959
$this->isDefault = false;
6060
}
61-
61+
6262
public function charset(string $charset)
6363
{
6464
$this->charset = 'CHARACTER SET ' . $charset;
6565
return $this;
6666
}
67-
67+
6868
public function comment(string $comment)
6969
{
7070
$this->comment = $comment;
7171
return $this;
7272
}
73-
73+
7474
public function length(int $length)
7575
{
7676
$this->length = $length;
7777
return $this;
7878
}
79-
79+
8080
public function key()
8181
{
8282
$this->key = self::KEY;
8383
return $this;
8484
}
85-
85+
8686
public function primary()
8787
{
8888
$this->key = self::PRIMARY;
@@ -93,25 +93,25 @@ public function index()
9393
$this->key = self::INDEX;
9494
return $this;
9595
}
96-
96+
9797
public function unique()
9898
{
9999
$this->key = self::UNIQUE;
100100
return $this;
101101
}
102-
102+
103103
public function collate(string $collate)
104104
{
105105
$this->collation = $collate;
106106
return $this;
107107
}
108-
108+
109109
public function auto()
110110
{
111111
$this->auto = true;
112112
return $this;
113113
}
114-
114+
115115
public function foreign(Field $field)
116116
{
117117
$this->foreign = $field;
@@ -123,13 +123,13 @@ public function foreign(Field $field)
123123
}
124124
return $this;
125125
}
126-
126+
127127
public function null(bool $set = true)
128128
{
129129
$this->null = $set;
130130
return $this;
131131
}
132-
132+
133133
public function default($value)
134134
{
135135
$this->isDefault = true;
@@ -139,19 +139,19 @@ public function default($value)
139139
}
140140
return $this;
141141
}
142-
142+
143143
public function binary()
144144
{
145145
$this->attribute = self::BINARY;
146146
return $this;
147147
}
148-
148+
149149
public function unsigned()
150150
{
151151
$this->attribute = self::UNSIGNED;
152152
return $this;
153153
}
154-
154+
155155
public function getFieldSQL()
156156
{
157157
$type = $this->length?strtoupper($this->type).'('.$this->length.')':strtoupper($this->type);
@@ -169,45 +169,45 @@ public function getFieldSQL()
169169
} else {
170170
$default = '';
171171
}
172-
172+
173173
$list = [$type, $attr, $this->charset, $null, $default, $auto, $comment];
174-
175-
174+
175+
176176
$data = implode(' ', array_filter(array_map('trim', $list), 'strlen'));
177-
177+
178178
return trim("`{$this->name}` {$data}");
179179
}
180-
180+
181181
public function getKeyType()
182182
{
183183
return $this->key;
184184
}
185-
185+
186186
public function getName()
187187
{
188188
return $this->name;
189189
}
190-
190+
191191
public function getType()
192192
{
193193
return $this->type;
194194
}
195-
195+
196196
public function getTableName()
197197
{
198198
return $this->tableName;
199199
}
200-
200+
201201
public function getForeignKey()
202202
{
203203
return $this->foreign;
204204
}
205-
205+
206206
public function getAutoIncrement()
207207
{
208208
return $this->auto;
209209
}
210-
210+
211211
public function getComment()
212212
{
213213
return $this->comment;

0 commit comments

Comments
 (0)