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

Slightly safer way to use pseudo/hidden columns? #22

Open
debug-ito opened this issue Jun 5, 2015 · 2 comments
Open

Slightly safer way to use pseudo/hidden columns? #22

debug-ito opened this issue Jun 5, 2015 · 2 comments

Comments

@debug-ito
Copy link
Contributor

In SQLite3, we can use rowid pseudo-column and last_insert_rowid() function to query the last inserted record.

To build such a query with HRR, I tried

lastInsertRecord :: Table r -> Pi r v -> Relation () v
lastInsertRecord tab selector = relation $ do
  record <- query $ table tab
  let rowid = unsafeProjectSql "rowid"
      last_rowid = unsafeProjectSql "last_insert_rowid()"
  wheres $ rowid .=. last_rowid
  return (record ! selector)

This gives me a Relation like:

>>> lastInsertRecord tableOfSample id'
SELECT ALL T0.sample_id AS f0, T0.val AS f1 FROM MAIN.sample T0 WHERE (rowid = last_insert_rowid())

This works. However, because rowid is a pseudo-column of sample table, it should be T0.rowid in the above query.

So, is there any way to specify rowid as a pseudo-column of a table?

@khibino
Copy link
Owner

khibino commented Jan 4, 2016

Thanks for your reporting.

I added the support of Register monad for INSERT statement in
be1e318 ,
7d35bd3 and
002bbcb .

And, I updated the example of constant INSERT using Register monad.
( bd2455f )

@debug-ito
Copy link
Contributor Author

Great work! Thank you.

But I think the commits you mentioned are related to #20. Not this issue.

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

2 participants