mysql-native ResultRange + map
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 11 15:46:00 PDT 2017
On 7/5/17 12:04 PM, crimaniak wrote:
> Hi all!
>
> After some hard time with debugging, I found ResultRange returned by
> query() and Prepared::query() of mysql-native package can't be combined
> with map() because after map() it becomes empty resultset.
>
[snip]
> As you see simple each() and foreach() works, but all examples with
> map() involved always empty. Can anybody explain such strange behavior?
>
Because of the temporary copy likely inside map closes the connection.
See the bug I reported: https://github.com/mysql-d/mysql-native/issues/117
I work around this in my code by moving the temporary copy. But I'm
sorry to say you likely will not be able to fix map.
I think Nick's comment is interesting, "Seems that using struct dtors
without refcounting should in general be regarded as a code smell?"
It's a good question. I've also always added ref counting when wanting
to "auto close" a struct's resources. In fact, I can't really think of a
good use of destructors for structs that isn't for reference counting
itself.
-Steve
More information about the Digitalmars-d-learn
mailing list