@@ -102,6 +102,7 @@ protected function executeQuery(): void
102
102
$ this ->fetchStarted = true ;
103
103
}
104
104
105
+ private $ count = null ;
105
106
/**
106
107
* Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings).
107
108
*
@@ -113,30 +114,14 @@ public function count()
113
114
return $ this ->count ;
114
115
}
115
116
116
- if ($ this ->tdbmService ->getConnection ()->getDatabasePlatform () instanceof MySqlPlatform) {
117
+ if ($ this ->fetchStarted && $ this -> tdbmService ->getConnection ()->getDatabasePlatform () instanceof MySqlPlatform) {
117
118
// Optimisation: we don't need a separate "count" SQL request in MySQL.
118
- return $ this ->getRowCountViaRowCountFunction ();
119
- } else {
120
- return $ this ->getRowCountViaSqlQuery ();
121
- }
122
- }
123
-
124
- private $ count = null ;
125
-
126
- /**
127
- * Get the row count from the rowCount function (only works with MySQL)
128
- */
129
- private function getRowCountViaRowCountFunction (): int
130
- {
131
- if (!$ this ->fetchStarted ) {
132
- $ this ->executeQuery ();
119
+ $ this ->count = $ this ->statement ->rowCount ();
120
+ return $ this ->count ;
133
121
}
134
-
135
- $ this ->count = $ this ->statement ->rowCount ();
136
- return $ this ->count ;
122
+ return $ this ->getRowCountViaSqlQuery ();
137
123
}
138
124
139
-
140
125
/**
141
126
* Makes a separate SQL query to compute the row count.
142
127
* (not needed in MySQL)
@@ -147,7 +132,7 @@ private function getRowCountViaSqlQuery(): int
147
132
148
133
$ this ->logger ->debug ('Running count SQL request: ' .$ countSql );
149
134
150
- $ this ->count = $ this ->tdbmService ->getConnection ()->fetchColumn ($ countSql , $ this ->parameters );
135
+ $ this ->count = ( int ) $ this ->tdbmService ->getConnection ()->fetchColumn ($ countSql , $ this ->parameters );
151
136
return $ this ->count ;
152
137
}
153
138
0 commit comments