{"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895622908", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895622908, "node_id": "IC_kwDOCGYnMM41Yh78", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T23:40:29Z", "updated_at": "2021-08-09T23:40:29Z", "author_association": "OWNER", "body": "TIL about how the stack inspection works: https://til.simonwillison.net/python/find-local-variables-in-exception-traceback", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895581038", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895581038, "node_id": "IC_kwDOCGYnMM41YXtu", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T22:03:54Z", "updated_at": "2021-08-09T23:39:53Z", "author_association": "OWNER", "body": "Steps to reproduce:\r\n\r\n echo '{\"v\": 34223049823094832094802398430298048240}' | sqlite-utils insert /tmp/blah.db row -", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895592507", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895592507, "node_id": "IC_kwDOCGYnMM41Yag7", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T22:26:28Z", "updated_at": "2021-08-09T22:33:48Z", "author_association": "OWNER", "body": "Demo:\r\n```\r\n$ echo '{\"v\": 34223049823094832094802398430298048240}' | sqlite-utils insert /tmp/blah.db row - \r\nError: Python int too large to convert to SQLite INTEGER\r\n\r\nsql = INSERT INTO [row] ([v]) VALUES (?);\r\nparameters = [34223049823094832094802398430298048240]\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895587441", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895587441, "node_id": "IC_kwDOCGYnMM41YZRx", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T22:15:45Z", "updated_at": "2021-08-09T22:15:45Z", "author_association": "OWNER", "body": "```\r\nOverflowError: Python int too large to convert to SQLite INTEGER\r\n>>> import sys\r\n>>> def find_variables(tb, vars):\r\n to_find = list(vars)\r\n found = {}\r\n for var in to_find:\r\n if var in tb.tb_frame.f_locals:\r\n vars.remove(var)\r\n found[var] = tb.tb_frame.f_locals[var]\r\n if vars and tb.tb_next:\r\n found.update(find_variables(tb.tb_next, vars))\r\n return found\r\n... \r\n>>> find_variables(sys.last_traceback, [\"sql\", \"params\"])\r\n{'params': [34223049823094832094802398430298048240], 'sql': 'INSERT INTO [row] ([v]) VALUES (?);'}\r\n```", "reactions": "{\"total_count\": 1, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 1, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895587282", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895587282, "node_id": "IC_kwDOCGYnMM41YZPS", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T22:15:25Z", "updated_at": "2021-08-09T22:15:25Z", "author_association": "OWNER", "body": "I'm going to use a bit of a dirty trick for this one: I'm going to recursively inspect the stack on an error and try to find the `sql` and `params` variables.\r\n\r\nThat way I can handle this all at the CLI layer without changing the exceptions that are being raised by the Python library.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/309#issuecomment-895577012", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/309", "id": 895577012, "node_id": "IC_kwDOCGYnMM41YWu0", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-09T21:55:52Z", "updated_at": "2021-08-09T21:59:03Z", "author_association": "OWNER", "body": "Yeah this error message could certainly be more helpful.\r\n\r\nI thought `OverflowError` might be one of the SQLite exceptions: https://docs.python.org/3/library/sqlite3.html#exceptions - but it turns out it's actually reusing the Python built-in `OverflowError` class:\r\n```python\r\nimport sqlite3\r\ndb = sqlite3.connect(\":memory:\")\r\ncaught = []\r\ntry:\r\n db.execute(\"create table foo (number integer)\")\r\n db.execute(\"insert into foo (number) values (?)\", [34223049823094832094802398430298048240])\r\nexcept Exception as e:\r\n print(e)\r\n caught.append(e)\r\nisinstance(caught[0], OverflowError)\r\n```\r\nHere's where that happens in the Python `sqlite3` module code: https://github.com/python/cpython/blob/058fb35b57ca8c5063d16ec818e668b3babfea65/Modules/_sqlite/util.c#L123-L124", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 963897111, "label": "sqlite-utils insert errors should show SQL and parameters, if possible"}, "performed_via_github_app": null}