From: Javier Sancho Date: Fri, 30 Oct 2020 18:53:25 +0000 (+0100) Subject: Check if table exists before getting table definition X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=58720a43974da688021531ed107dc8693b62ca39;p=datasette-connectors.git Check if table exists before getting table definition --- diff --git a/datasette_connectors/cursor.py b/datasette_connectors/cursor.py index f3898cc..bf3a1b1 100644 --- a/datasette_connectors/cursor.py +++ b/datasette_connectors/cursor.py @@ -67,7 +67,8 @@ class Cursor: if self.connector.table_exists(params[0]): results = [{'1': '1'}] elif sql == "select sql from sqlite_master where name = :n and type=:t": - results = [{'sql': self.connector.table_definition(params['t'], params['n'])}] + if self.connector.table_exists(params['n']): + results = [{'sql': self.connector.table_definition(params['t'], params['n'])}] elif sql == "select sql from sqlite_master where tbl_name = :n and type='index' and sql is not null": results = [{'sql': sql} for sql in self.connector.indices_definition(params['n'])] else: diff --git a/tests/test_api.py b/tests/test_api.py index 25bd297..e7303a8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -64,9 +64,9 @@ def test_table_json(app_client): def test_table_not_exists_json(app_client): assert { 'ok': False, - 'title': 'Invalid SQL', - 'error': 'no such table: blah', - 'status': 400, + 'error': 'Table not found: blah', + 'status': 404, + 'title': None, } == app_client.get('/dummy_tables/blah.json').json def test_table_shape_arrays(app_client):