1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @filesource QueryTest.php |
5
|
|
|
* @created 12.05.2017 |
6
|
|
|
* @package chillerlan\DatabaseTest\Query |
7
|
|
|
* @author Smiley <[email protected]> |
8
|
|
|
* @copyright 2017 Smiley |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace chillerlan\DatabaseTest\Query; |
13
|
|
|
|
14
|
|
|
use chillerlan\Database\Drivers\PDO\PDOMySQLDriver; |
15
|
|
|
use chillerlan\Database\DBQuery; |
16
|
|
|
use chillerlan\Database\Query\CreateInterface; |
17
|
|
|
use chillerlan\Database\Query\CreateTableInterface; |
18
|
|
|
use chillerlan\Database\Query\SelectInterface; |
19
|
|
|
use chillerlan\Database\Query\StatementInterface; |
20
|
|
|
use chillerlan\DatabaseTest\TestAbstract; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class QueryTest |
24
|
|
|
*/ |
25
|
|
|
class QueryTest extends TestAbstract{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \chillerlan\Database\DBQuery |
29
|
|
|
*/ |
30
|
|
|
protected $statement; |
31
|
|
|
|
32
|
|
|
protected $driver = PDOMySQLDriver::class; |
33
|
|
|
protected $envVar = 'DB_MYSQLI_'; |
34
|
|
|
|
35
|
|
|
public function setUp(){ |
36
|
|
|
parent::setUp(); |
37
|
|
|
|
38
|
|
|
$this->statement = new DBQuery($this->DBDriver); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testSelect(){ |
42
|
|
|
$select = $this->statement->select; |
43
|
|
|
$this->assertInstanceOf(SelectInterface::class, $select); |
44
|
|
|
$this->assertInstanceOf(StatementInterface::class, $select); |
45
|
|
|
|
46
|
|
|
$select |
47
|
|
|
->distinct() |
48
|
|
|
->cols(['t2.what', 't1.foo' => 'foo']) |
49
|
|
|
->cols(['t1.bar' => ['bar', 'lower'], 'nope', ['what', 'upper']]) |
50
|
|
|
->from(['foo' => 't1', 'bar' => 't2']) |
51
|
|
|
->from(['whatever']) |
52
|
|
|
->groupby(['foo', 'bar']) |
53
|
|
|
->orderby(['foo', 'bar' => 'desc']) |
54
|
|
|
->offset(3) |
55
|
|
|
->limit(5); |
56
|
|
|
|
57
|
|
|
# print_r($select->sql()); |
|
|
|
|
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testCreate(){ |
62
|
|
|
$create = $this->statement->create; |
63
|
|
|
$this->assertInstanceOf(CreateInterface::class, $create); |
64
|
|
|
$this->assertInstanceOf(StatementInterface::class, $create); |
65
|
|
|
|
66
|
|
|
$database = $create->database('foo'); |
67
|
|
|
|
68
|
|
|
var_dump($database->name('bar')->collate('utf8mb4_bin')->ifNotExists()->sql()); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$table = $create->table(); |
71
|
|
|
$this->assertInstanceOf(CreateTableInterface::class, $table); |
72
|
|
|
$this->assertInstanceOf(StatementInterface::class, $table); |
73
|
|
|
|
74
|
|
|
$table |
75
|
|
|
->name('foo') |
76
|
|
|
->ifNotExists() |
77
|
|
|
->primaryKey('id') |
78
|
|
|
->field('id', 'int', 10, 'unsigned', null, false, null, null, 'AUTO_INCREMENT') |
79
|
|
|
->field('bar', 'varchar', 32, null, 'utf8mb4_bin', true, 'NULL', 'foo') |
80
|
|
|
->field('nope', 'decimal', '9,6'); |
81
|
|
|
|
82
|
|
|
var_dump($table->sql()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/* |
|
|
|
|
89
|
|
|
|
90
|
|
|
// get skills |
91
|
|
|
$sql = 'SELECT skilldata.`id`, |
92
|
|
|
skilldesc.`pve_name`, |
93
|
|
|
skilldesc.`pve_desc`, |
94
|
|
|
skilldesc.`pve_desc_short`, |
95
|
|
|
skilldesc.`pvp_name`, |
96
|
|
|
skilldesc.`pvp_desc`, |
97
|
|
|
skilldesc.`pvp_desc_short`, |
98
|
|
|
skilldata.`campaign` AS `campaign_id`, |
99
|
|
|
skilldata.`elite`, |
100
|
|
|
skilldata.`pve`, |
101
|
|
|
skilldata.`pvp_split`, |
102
|
|
|
skilldata.`attribute` AS `attribute_id`, |
103
|
|
|
skilldata.`'.$mode.'_activation` AS `activation`, |
104
|
|
|
skilldata.`'.$mode.'_recharge` AS `recharge`, |
105
|
|
|
skilldata.`'.$mode.'_energy` AS `energy`, |
106
|
|
|
skilldata.`'.$mode.'_upkeep` AS `upkeep`, |
107
|
|
|
skilldata.`'.$mode.'_adrenaline` AS `adrenaline`, |
108
|
|
|
skilldata.`'.$mode.'_sacrifice` AS `sacrifice`, |
109
|
|
|
skilldata.`'.$mode.'_overcast` AS `overcast`, |
110
|
|
|
skilldata.`'.$mode.'_type` AS `type_id`, |
111
|
|
|
profs.`name_'.$lang.'` AS `prof`, |
112
|
|
|
profs.`id` AS `prof_id`, |
113
|
|
|
profs.`abbr_'.$lang.'` AS `prof_abbr`, |
114
|
|
|
attribs.`name_'.$lang.'` AS `attribute`, |
115
|
|
|
attribs.`primary`, |
116
|
|
|
attribs.`max` AS `attribute_max`, |
117
|
|
|
types.`name_'.$lang.'` AS `type`, |
118
|
|
|
campaigns.`name_'.$lang.'` AS `campaign` |
119
|
|
|
FROM '.constant('SKILLDESC_'.strtoupper($lang)).' AS skilldesc, |
120
|
|
|
'.SKILLDATA.' AS skilldata, |
121
|
|
|
'.PROFESSIONS.' AS profs, |
122
|
|
|
'.ATTRIBUTES.' AS attribs, |
123
|
|
|
'.SKILLTYPES.' AS types, |
124
|
|
|
'.CAMPAIGNS.' AS campaigns |
125
|
|
|
WHERE skilldata.`profession` = profs.`id` |
126
|
|
|
AND skilldata.`attribute` = attribs.`id` |
127
|
|
|
AND skilldata.`'.$mode.'_type` = types.`id` |
128
|
|
|
AND skilldesc.`id` = skilldata.`id` |
129
|
|
|
AND campaigns.`id` = skilldata.`campaign` |
130
|
|
|
AND skilldata.`id` IN(?,?,?,?,?,?,?,?)'; |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
|
134
|
|
|
*/ |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.