@@ -156,20 +156,44 @@ void DsqlStatementCache::putStatement(thread_db* tdbb, const string& text, USHOR
156
156
#endif
157
157
}
158
158
159
+ void DsqlStatementCache::removeStatement (thread_db* tdbb, DsqlStatement* statement)
160
+ {
161
+ if (const auto cacheKey = statement->getCacheKey ())
162
+ {
163
+ if (const auto entryPtr = map.get (cacheKey))
164
+ {
165
+ const auto entry = *entryPtr;
166
+
167
+ entry->dsqlStatement ->resetCacheKey ();
168
+
169
+ if (entry->active )
170
+ {
171
+ entry->dsqlStatement ->addRef ();
172
+ activeStatementList.erase (entry);
173
+ }
174
+ else
175
+ {
176
+ inactiveStatementList.erase (entry);
177
+ cacheSize -= entry->size ;
178
+ }
179
+
180
+ map.remove (entry->key );
181
+ }
182
+ }
183
+ }
184
+
159
185
void DsqlStatementCache::statementGoingInactive (Firebird::RefStrPtr& key)
160
186
{
161
187
const auto entryPtr = map.get (key);
162
188
163
189
if (!entryPtr)
164
- {
165
- fb_assert (false );
166
190
return ;
167
- }
168
191
169
192
const auto entry = *entryPtr;
170
193
171
194
fb_assert (entry->active );
172
195
entry->active = false ;
196
+ entry->dsqlStatement ->addRef ();
173
197
entry->size = entry->dsqlStatement ->getSize (); // update size
174
198
175
199
inactiveStatementList.splice (inactiveStatementList.end (), activeStatementList, entry);
@@ -192,6 +216,9 @@ void DsqlStatementCache::purge(thread_db* tdbb, bool releaseLock)
192
216
entry.dsqlStatement ->resetCacheKey ();
193
217
}
194
218
219
+ for (auto & entry : inactiveStatementList)
220
+ entry.dsqlStatement ->resetCacheKey ();
221
+
195
222
map.clear ();
196
223
activeStatementList.clear ();
197
224
inactiveStatementList.clear ();
@@ -273,6 +300,7 @@ void DsqlStatementCache::shrink()
273
300
while (cacheSize > maxCacheSize && !inactiveStatementList.isEmpty ())
274
301
{
275
302
const auto & front = inactiveStatementList.front ();
303
+ front.dsqlStatement ->resetCacheKey ();
276
304
map.remove (front.key );
277
305
cacheSize -= front.size ;
278
306
inactiveStatementList.erase (inactiveStatementList.begin ());
0 commit comments