Coder Social home page Coder Social logo

Comments (11)

simonw avatar simonw commented on July 24, 2024

Code at fault:

@documented
async def derive_named_parameters(db: "Database", sql: str) -> List[str]:
"""
Given a SQL statement, return a list of named parameters that are used in the statement
e.g. for ``select * from foo where id=:id`` this would return ``["id"]``
"""
explain = "explain {}".format(sql.strip().rstrip(";"))
possible_params = _re_named_parameter.findall(sql)
try:
results = await db.execute(explain, {p: None for p in possible_params})
return [row["p4"].lstrip(":") for row in results if row["opcode"] == "Variable"]
except sqlite3.DatabaseError:
return possible_params

from datasette.

simonw avatar simonw commented on July 24, 2024

The key problem here is that opcodes are not a stable feature of SQLite, so it was always risk to attempt to use them in this way.

from datasette.

simonw avatar simonw commented on July 24, 2024

We need to ensure SQLite 3.46.0 is covered in the new tests here:

from datasette.

simonw avatar simonw commented on July 24, 2024

Posted about this on the SQLite forum - https://sqlite.org/forum/forumpost/0adbc56447 - but since opcodes are an undocumented and unsupported interface I don't expect them to fix it.

from datasette.

simonw avatar simonw commented on July 24, 2024

This mechanism here was already supposed to catch things if SQLite broke the mechanism I was using:

except sqlite3.DatabaseError:
return possible_params

But it didn't think to catch AttributeError.

from datasette.

simonw avatar simonw commented on July 24, 2024

Here's the macOS SQLite 3.46.0 libsqlite3.0.dylib I was using: https://static.simonwillison.net/static/2024/libsqlite3.0.dylib

from datasette.

simonw avatar simonw commented on July 24, 2024

Here's the commit that removed this feature: https://sqlite.org/src/info/dd5977c9a8a418be

Via https://sqlite.org/forum/forumpost/1cafc721009cef7f

from datasette.

simonw avatar simonw commented on July 24, 2024

I manually tested the patch to 0.64.x like this:

DYLD_LIBRARY_PATH=sqlite-3.46.0 datasette fixtures.db -m issue-2353.yaml -p 8034

Then visited http://127.0.0.1:8034/fixtures/demo?table=facetable and it worked.

I confirmed that the page had an error before applying that cherry-pick.

from datasette.

simonw avatar simonw commented on July 24, 2024

Here's the full set of changes going out in 0.64.7: 0.64.6...0.64.7

from datasette.

simonw avatar simonw commented on July 24, 2024

Released: https://pypi.org/project/datasette/0.64.7/ / https://docs.datasette.io/en/stable/changelog.html#v0-64-7

from datasette.

simonw avatar simonw commented on July 24, 2024

Blogged about the release here: https://simonwillison.net/2024/Jun/12/datasette-0647/

from datasette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.