]> git.jsancho.org Git - datasette-connectors.git/commitdiff
Check if table exists before getting table definition
authorJavier Sancho <jsf@jsancho.org>
Fri, 30 Oct 2020 18:53:25 +0000 (19:53 +0100)
committerJavier Sancho <jsf@jsancho.org>
Fri, 30 Oct 2020 18:53:25 +0000 (19:53 +0100)
datasette_connectors/cursor.py
tests/test_api.py

index f3898cc23f4d97eca9eba0e12a9e7b1ea95fe240..bf3a1b1dbf177ec48f33ff216365ccca17db6ed1 100644 (file)
@@ -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:
index 25bd29757da230af08fece32442bbcd7398dc487..e7303a83e697d7ecfa509cc3410e803110b55ffa 100644 (file)
@@ -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):