diff --git a/src/db/pool_prepared_statement.cr b/src/db/pool_prepared_statement.cr index e3241e5..5a65910 100644 --- a/src/db/pool_prepared_statement.cr +++ b/src/db/pool_prepared_statement.cr @@ -33,13 +33,14 @@ module DB private def build_statement clean_connections conn, existing = @db.checkout_some(@connections) - @connections << WeakRef.new(conn) unless existing begin - conn.prepared.build(@query) + stmt = conn.prepared.build(@query) rescue ex conn.release raise ex end + @connections << WeakRef.new(conn) unless existing + stmt end private def clean_connections