File tree 3 files changed +41
-2
lines changed
3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 6
6
Driver \Features \CRUDAbleInterface ,
7
7
Driver \Features \CRUDQueryableInterface ,
8
8
ModelInterface ,
9
+ Query \DeleteQuery ,
9
10
Query \Generator \SQL ,
10
11
Query \Query ,
11
- Query \QueryResult };
12
+ Query \QueryResult ,
13
+ Query \UpdateQuery
14
+ };
12
15
use Exception ;
13
16
use mysqli_result ;
14
17
@@ -240,6 +243,11 @@ public function query(Query $query): QueryResult
240
243
241
244
$ result = new QueryResult ((bool )$ rawQueryResult );
242
245
$ result ->setQueryString ($ queryString );
246
+ if ($ query instanceof UpdateQuery || $ query instanceof DeleteQuery) {
247
+ $ result ->setAffectedRows (mysqli_affected_rows ($ this ->connection ));
248
+ return $ result ;
249
+ }
250
+
243
251
if (is_bool ($ rawQueryResult )) {
244
252
return $ result ;
245
253
}
Original file line number Diff line number Diff line change @@ -95,7 +95,11 @@ public function generate(Query $query): string
95
95
}
96
96
97
97
if ($ limit = $ query ->getLimit ()) {
98
- $ queryString .= " LIMIT " . $ limit ->start . ", " . $ limit ->length ;
98
+ if ($ query instanceof UpdateQuery || $ query instanceof DeleteQuery) {
99
+ $ queryString .= " LIMIT " . $ limit ->length ;
100
+ } else {
101
+ $ queryString .= " LIMIT " . $ limit ->start . ", " . $ limit ->length ;
102
+ }
99
103
}
100
104
101
105
return $ queryString ;
Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ class QueryResult extends ModelCollectionResult
23
23
*/
24
24
protected ?string $ queryString = null ;
25
25
26
+ /**
27
+ * Number of affected rows in update or delete queries
28
+ *
29
+ * @var int|null
30
+ */
31
+ protected ?int $ affectedRows = null ;
32
+
26
33
/**
27
34
* QueryResult constructor.
28
35
*
@@ -57,4 +64,24 @@ public function setQueryString(?string $queryString): QueryResult
57
64
}
58
65
return $ this ;
59
66
}
67
+
68
+ /**
69
+ * @return int|null
70
+ */
71
+ public function getAffectedRows (): ?int
72
+ {
73
+ return $ this ->affectedRows ;
74
+ }
75
+
76
+ /**
77
+ * @param int|null $affectedRows
78
+ * @return $this
79
+ */
80
+ public function setAffectedRows (?int $ affectedRows ): static
81
+ {
82
+ if ($ this ->affectedRows === null ) {
83
+ $ this ->affectedRows = $ affectedRows ;
84
+ }
85
+ return $ this ;
86
+ }
60
87
}
You can’t perform that action at this time.
0 commit comments