Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiPoco queries may fail after a database schema change #617

Open
TomTondeur opened this issue Aug 11, 2021 · 0 comments
Open

MultiPoco queries may fail after a database schema change #617

TomTondeur opened this issue Aug 11, 2021 · 0 comments

Comments

@TomTondeur
Copy link
Contributor

I bumped into an unfortunate interaction between the "multi poco" functionality and the use of wildcards in select statements.

As I understand it, when a query is run using PetaPoco, it generate some IL to efficiently store the query results. This generated IL is then cached, so that it can be re-used when the same query is run again later. The generated IL makes assumptions about the columns returned by the query, so the "offset" and "count" of columns are used in the key of these cached IL poco factories.

When using multi-poco queries, a wrapper "multi poco factory" is created and cached, which calls into the individual poco factories described above. However, as it stands, the "multi poco factory" cache key does not include column count.

Because of this, an inappropriate poco factory may be used when a multi-poco query is run if the new resulting set of columns is different from the first run. Here's an example:

SELECT *
FROM Orders o
JOIN People p ON p.Id = o.PersonId

ALTER TABLE Orders ADD SomeRandomColumn INT NULL

SELECT *
FROM Orders o
JOIN People p ON p.Id = o.PersonId

When the second query is run with the poco factories generated by the first, their split points will be incorrect, so fields can get parsed into the wrong poco, or fields may be dropped entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant