perl5-dbi/dbi

prepare_cached() does not cache correctly with Slice => {} passed in as attr

Closed this issue · 1 comments

pepl commented

It looks like DBI::_concat_hash_sorted is not handling nested data structures passed in as attributes correctly. Given for example Slice => {} is passed, the reference to {} will be part of the cache key and thus the statement handle will never be hit again.

I assume _concat_hash_sorted / _join_hash_sorted would need to recurse.

Here a simple test to reproduce the issue: prepare_cached_test.pl.txt

In our local scenario this behaviour causes significant memory leakage.

A documentation patch is needed with a similar wording to that for connect_cached:

Also, to ensure that the attributes passed are always the same, avoid passing references inline. For example, the Callbacks attribute is specified as a hash reference. Be sure to declare it external to the call to connect_cached(), such that the hash reference is not re-created on every call. A package-level lexical works well: