Associate cached statements with correct logical connection

Fixes bug https://bugs.launchpad.net/bonecp/+bug/1247826