Fix compatibility problems with sqlite standard queries
authorJavier Sancho <jsf@jsancho.org>
Mon, 10 Sep 2018 15:04:49 +0000 (17:04 +0200)
committerJavier Sancho <jsf@jsancho.org>
Mon, 10 Sep 2018 15:04:49 +0000 (17:04 +0200)
datasette_pytables/__init__.py

index 2e6920e..45d3a32 100644 (file)
@@ -245,23 +245,22 @@ class Connection:
 
     def _execute_datasette_query(self, sql, params):
         "Datasette special queries for getting tables info"
-        if sql == "SELECT count(*) from sqlite_master WHERE type = 'view' and name=:n":
-            row = Row()
-            row['count(*)'] = 0
-            return [row]
-        elif sql == 'select sql from sqlite_master where name = :n and type="table"':
-            try:
-                table = self.h5file.get_node(params['n'])
-                colnames = ['value']
-                if type(table) is tables.table.Table:
-                    colnames = table.colnames
-                row = Row()
-                row['sql'] = 'CREATE TABLE {} ({})'.format(params['n'], ", ".join(colnames))
-                return [row]
-            except:
+        if sql == 'select sql from sqlite_master where name = :n and type=:t':
+            if params['t'] == 'view':
                 return []
+            else:
+                try:
+                    table = self.h5file.get_node(params['n'])
+                    colnames = ['value']
+                    if type(table) is tables.table.Table:
+                        colnames = table.colnames
+                    row = Row()
+                    row['sql'] = 'CREATE TABLE {} ({})'.format(params['n'], ", ".join(colnames))
+                    return [row]
+                except:
+                    return []
         else:
-            raise Exception("SQLite queries cannot be executed with this connector")
+            raise Exception("SQLite queries cannot be executed with this connector: %s, %s" % (sql, params))
 
 
 class Row(list):