Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit bf16a7b

Browse files
author
Daniel Opitz
committed
Added whereRaw and orWhereRaw
Fixed first closure conditions
1 parent d9d5170 commit bf16a7b

File tree

10 files changed

+139
-441
lines changed

10 files changed

+139
-441
lines changed

src/Database/Condition.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public function getConditionSql(array $sql, array $where, string $conditionType)
8080
}
8181
foreach ($where as $index => $item) {
8282
if ($item instanceof RawExp) {
83+
if ($index == 0) {
84+
$sql[] = $conditionType . ' ' . $item->getValue();
85+
continue;
86+
}
8387
$sql[] = $item->getValue();
8488
continue;
8589
}

src/Database/SelectQuery.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ public function where(...$conditions): self
272272
return $this;
273273
}
274274

275+
/**
276+
* Add a raw AND WHERE condition.
277+
*
278+
* @param string $condition The raw where conditions e.g. 'user.id = article.user_id'
279+
*
280+
* @return self
281+
*/
282+
public function whereRaw(string $condition): self
283+
{
284+
$this->condition->where([new RawExp($condition)]);
285+
286+
return $this;
287+
}
288+
275289
/**
276290
* Where OR condition.
277291
*
@@ -288,6 +302,20 @@ public function orWhere(...$conditions): self
288302
return $this;
289303
}
290304

305+
/**
306+
* Add a raw OR WHERE condition.
307+
*
308+
* @param string $condition The raw where conditions e.g. 'user.id = article.user_id'
309+
*
310+
* @return self
311+
*/
312+
public function orWhereRaw(string $condition): self
313+
{
314+
$this->condition->orWhere([new RawExp($condition)]);
315+
316+
return $this;
317+
}
318+
291319
/**
292320
* The whereColumn method may be used to verify that two columns are equal.
293321
*

tests/CompressionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public function getCompression()
4343
* Test compress method.
4444
*
4545
* @return void
46-
* @covers ::compress
47-
* @covers ::uncompress
4846
*/
4947
public function testCompress()
5048
{

tests/DeleteQueryTest.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class DeleteQueryTest extends BaseTest
1414
* Test create object.
1515
*
1616
* @return void
17-
* @covers ::__construct
1817
*/
1918
public function testInstance()
2019
{
@@ -31,13 +30,6 @@ protected function delete()
3130

3231
/**
3332
* Test.
34-
*
35-
* @covers ::from
36-
* @covers ::from
37-
* @covers ::getDeleteSql
38-
* @covers ::prepare
39-
* @covers ::build
40-
* @covers ::execute
4133
*/
4234
public function testFrom()
4335
{
@@ -48,12 +40,6 @@ public function testFrom()
4840

4941
/**
5042
* Test.
51-
*
52-
* @covers ::from
53-
* @covers ::lowPriority
54-
* @covers ::getDeleteSql
55-
* @covers ::prepare
56-
* @covers ::build
5743
*/
5844
public function testLowPriority()
5945
{
@@ -64,14 +50,6 @@ public function testLowPriority()
6450

6551
/**
6652
* Test.
67-
*
68-
* @covers ::from
69-
* @covers ::where
70-
* @covers ::lowPriority
71-
* @covers ::getDeleteSql
72-
* @covers ::ignore
73-
* @covers ::prepare
74-
* @covers ::build
7553
*/
7654
public function testIgnore()
7755
{
@@ -84,14 +62,6 @@ public function testIgnore()
8462

8563
/**
8664
* Test.
87-
*
88-
* @covers ::from
89-
* @covers ::where
90-
* @covers ::quick
91-
* @covers ::getDeleteSql
92-
* @covers ::ignore
93-
* @covers ::prepare
94-
* @covers ::build
9565
*/
9666
public function testQuick()
9767
{
@@ -101,13 +71,6 @@ public function testQuick()
10171

10272
/**
10373
* Test.
104-
*
105-
* @covers ::from
106-
* @covers ::where
107-
* @covers ::orderBy
108-
* @covers ::getOrderBySql
109-
* @covers ::prepare
110-
* @covers ::build
11174
*/
11275
public function testOrderBy()
11376
{
@@ -126,13 +89,6 @@ public function testOrderBy()
12689

12790
/**
12891
* Test.
129-
*
130-
* @covers ::from
131-
* @covers ::where
132-
* @covers ::limit
133-
* @covers ::getLimitSql
134-
* @covers ::prepare
135-
* @covers ::build
13692
*/
13793
public function testLimit()
13894
{
@@ -142,16 +98,6 @@ public function testLimit()
14298

14399
/**
144100
* Test.
145-
*
146-
* @covers ::from
147-
* @covers ::where
148-
* @covers ::orWhere
149-
* @covers ::prepare
150-
* @covers ::build
151-
* @covers ::getDeleteSql
152-
* @covers ::getOrderBySql
153-
* @covers ::getLimitSql
154-
* @covers ::getDeleteSql
155101
*/
156102
public function testWhere()
157103
{
@@ -163,12 +109,6 @@ public function testWhere()
163109

164110
/**
165111
* Test.
166-
*
167-
* @covers ::from
168-
* @covers ::truncate
169-
* @covers ::getTruncateSql
170-
* @covers ::prepare
171-
* @covers ::build
172112
*/
173113
public function testTruncate()
174114
{

tests/InsertQueryTest.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class InsertQueryTest extends BaseTest
1414
* Test create object.
1515
*
1616
* @return void
17-
* @covers ::__construct
1817
*/
1918
public function testInstance()
2019
{
@@ -31,12 +30,6 @@ protected function insert()
3130

3231
/**
3332
* Test.
34-
*
35-
* @covers ::into
36-
* @covers ::set
37-
* @covers ::prepare
38-
* @covers ::build
39-
* @covers ::execute
4033
*/
4134
public function testInto()
4235
{
@@ -51,13 +44,6 @@ public function testInto()
5144

5245
/**
5346
* Test.
54-
*
55-
* @covers ::into
56-
* @covers ::set
57-
* @covers ::lastInsertId
58-
* @covers ::prepare
59-
* @covers ::build
60-
* @covers ::execute
6147
*/
6248
public function testLastInsertId()
6349
{
@@ -68,13 +54,6 @@ public function testLastInsertId()
6854

6955
/**
7056
* Test.
71-
*
72-
* @covers ::into
73-
* @covers ::set
74-
* @covers ::insertGetId
75-
* @covers ::prepare
76-
* @covers ::build
77-
* @covers ::execute
7857
*/
7958
public function testInsertGetId()
8059
{
@@ -84,13 +63,6 @@ public function testInsertGetId()
8463

8564
/**
8665
* Test.
87-
*
88-
* @covers ::into
89-
* @covers ::set
90-
* @covers ::lowPriority
91-
* @covers ::highPriority
92-
* @covers ::prepare
93-
* @covers ::build
9466
*/
9567
public function testPriority()
9668
{
@@ -103,13 +75,6 @@ public function testPriority()
10375

10476
/**
10577
* Test.
106-
*
107-
* @covers ::into
108-
* @covers ::set
109-
* @covers ::lowPriority
110-
* @covers ::ignore
111-
* @covers ::prepare
112-
* @covers ::build
11378
*/
11479
public function testIgnore()
11580
{
@@ -122,13 +87,6 @@ public function testIgnore()
12287

12388
/**
12489
* Test.
125-
*
126-
* @covers ::into
127-
* @covers ::set
128-
* @covers ::delayed
129-
* @covers ::ignore
130-
* @covers ::prepare
131-
* @covers ::build
13290
*/
13391
public function testDelayed()
13492
{
@@ -138,12 +96,6 @@ public function testDelayed()
13896

13997
/**
14098
* Test.
141-
*
142-
* @covers ::into
143-
* @covers ::set
144-
* @covers ::onDuplicateKeyUpdate
145-
* @covers ::prepare
146-
* @covers ::build
14799
*/
148100
public function testOnDuplicateKeyUpdate()
149101
{

tests/QuoterTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function testInstance()
2828
* Test.
2929
*
3030
* @return void
31-
* @covers ::quoteValue
3231
*/
3332
public function testEsc()
3433
{
@@ -67,9 +66,6 @@ public function testEsc()
6766
* Test.
6867
*
6968
* @return void
70-
* @covers ::quoteName
71-
* @covers ::quoteNameWithSeparator
72-
* @covers ::quoteIdentifier
7369
*/
7470
public function testIdent()
7571
{
@@ -109,7 +105,6 @@ public function testIdent()
109105
* Test.
110106
*
111107
* @return void
112-
* @covers ::quoteArray
113108
*/
114109
public function testQuoteArray()
115110
{
@@ -124,7 +119,6 @@ public function testQuoteArray()
124119
* Test.
125120
*
126121
* @return void
127-
* @covers ::quoteNames
128122
*/
129123
public function testQuoteNames()
130124
{

tests/RawExpTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class RawExpTest extends BaseTest
1111
{
1212
/**
1313
* Test.
14-
*
15-
* @covers ::getValue
1614
*/
1715
public function testGetValue()
1816
{
@@ -22,8 +20,6 @@ public function testGetValue()
2220

2321
/**
2422
* Test.
25-
*
26-
* @covers ::__toString
2723
*/
2824
public function testToString()
2925
{
@@ -33,8 +29,6 @@ public function testToString()
3329

3430
/**
3531
* Test.
36-
*
37-
* @covers ::getValue
3832
*/
3933
public function testColumnsRaw()
4034
{
@@ -52,8 +46,6 @@ public function testColumnsRaw()
5246

5347
/**
5448
* Test.
55-
*
56-
* @covers ::getValue
5749
*/
5850
public function testColumnsRaw2()
5951
{

0 commit comments

Comments
 (0)