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

.transform(types=) turns rowid into a concrete column #284

Closed
simonw opened this issue Jun 19, 2021 · 5 comments
Closed

.transform(types=) turns rowid into a concrete column #284

simonw opened this issue Jun 19, 2021 · 5 comments
Labels
bug Something isn't working python-library

Comments

@simonw
Copy link
Owner

simonw commented Jun 19, 2021

Noticed this in the tests for sqlite-utils memory in #282 - is it possible to fix this?

ec5174e

@simonw simonw added bug Something isn't working python-library labels Jun 19, 2021
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2021

How easy is it to detect a rowid table? Is it as simple as .pks returning None? If so the documentation should mention that.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2021

If this can be fixed it will be in the transform_sql() method.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2021

>>> db = sqlite_utils.Database(memory=True)
>>> db["rowid_table"].insert({"name": "Cleo"})
<Table rowid_table (name)>
>>> db["regular_table"].insert({"id": 1, "name": "Cleo"}, pk="id")
<Table regular_table (id, name)>
>>> db["rowid_table"].pks
['rowid']
>>> db["regular_table"].pks
['id']

I think I need an introspection property for working out if a table is a rowid table or not.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2021

@property
def pks(self):
names = [column.name for column in self.columns if column.is_pk]
if not names:
names = ["rowid"]
return names

So I can indeed detect a rowid table by looking for no is_pk columns.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2021

I think this code is at fault:

sqls = []
if pk is DEFAULT:
pks_renamed = tuple(rename.get(p) or p for p in self.pks)
if len(pks_renamed) == 1:
pk = pks_renamed[0]
else:
pk = pks_renamed

It's using .pks which adds rowid if it's missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python-library
Projects
None yet
Development

No branches or pull requests

1 participant