home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 612708274

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/sqlite-utils/issues/98#issuecomment-612708274 https://api.github.com/repos/simonw/sqlite-utils/issues/98 612708274 MDEyOklzc3VlQ29tbWVudDYxMjcwODI3NA== 9599 2020-04-13T01:25:59Z 2020-04-13T01:26:11Z OWNER

In mucking around with sqlite3 it looks like result.lastrowid is indeed populated for UPDATE - in this case with the last inserted rowid in the table. This differs from the documented behaviour I linked to above.

``` In [1]: import sqlite3

In [2]: c = sqlite3.connect(":memory:")

In [3]: c
Out[3]: <sqlite3.Connection at 0x103c4d490>

In [4]: c.execute('create table foo (bar integer);')
Out[4]: <sqlite3.Cursor at 0x103f760a0>

In [5]: c.execute('insert into foo (bar) values (1)')
Out[5]: <sqlite3.Cursor at 0x103f76650>

In [6]: c.execute('select * from foo').fetchall()
Out[6]: [(1,)]

In [7]: c.execute('insert into foo (bar) values (1)')
Out[7]: <sqlite3.Cursor at 0x103f766c0>

In [8]: c.execute('select * from foo').fetchall()
Out[8]: [(1,), (1,)]

In [9]: c.execute('insert into foo (bar) values (1)').lastrowid
Out[9]: 3

In [10]: c.execute('select * from foo').fetchall()
Out[10]: [(1,), (1,), (1,)]

In [11]: c.execute('select rowid, bar from foo').fetchall()
Out[11]: [(1, 1), (2, 1), (3, 1)]

In [12]: c.execute('insert into foo (bar) values (1)').lastrowid
Out[12]: 4

In [13]: c.execute('select rowid, bar from foo').fetchall()
Out[13]: [(1, 1), (2, 1), (3, 1), (4, 1)]

In [14]: r = c.execute('update foo set bar =2 where rowid = 1')

In [15]: r.lastrowid
Out[15]: 4

In [16]: c.execute('select rowid, bar from foo').fetchall()
Out[16]: [(1, 2), (2, 1), (3, 1), (4, 1)]

In [17]: r = c.execute('select rowid, bar from foo')

In [18]: r.fetchall()
Out[18]: [(1, 2), (2, 1), (3, 1), (4, 1)]

In [19]: r.lastrowid
Out[19]: 4 ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
597671518  
Powered by Datasette · Queries took 1.011ms · About: github-to-sqlite