Handle different SQLite version error messages

Refs https://github.com/simonw/sqlite-utils/pull/653#issuecomment-2864967364
This commit is contained in:
Simon Willison 2025-05-08 20:20:27 -07:00
commit 79913af28a
2 changed files with 5 additions and 5 deletions

View file

@ -1098,7 +1098,9 @@ def insert_upsert_implementation(
if ( if (
isinstance(e, OperationalError) isinstance(e, OperationalError)
and e.args and e.args
and "has no column named" in e.args[0] and (
"has no column named" in e.args[0] or "no such column" in e.args[0]
)
): ):
raise click.ClickException( raise click.ClickException(
"{}\n\nTry using --alter to add additional columns".format( "{}\n\nTry using --alter to add additional columns".format(

View file

@ -1116,10 +1116,8 @@ def test_upsert_alter(db_path, tmpdir):
cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id"] cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id"]
) )
assert result.exit_code == 1 assert result.exit_code == 1
assert ( # Could be one of two errors depending on SQLite version
"Error: table dogs has no column named age\n\n" assert ("Try using --alter to add additional columns") in result.output.strip()
"Try using --alter to add additional columns"
) == result.output.strip()
# Should succeed with --alter # Should succeed with --alter
result = CliRunner().invoke( result = CliRunner().invoke(
cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id", "--alter"] cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id", "--alter"]