- h5tables[table._v_pathname] = {
- 'name': table._v_pathname,
- 'columns': colnames,
- 'primary_keys': [],
- 'count': table.nrows,
- 'label_column': None,
- 'hidden': False,
- 'fts_table': None,
- 'foreign_keys': {'incoming': [], 'outgoing': []},
- }
-
- h5file.close()
- return h5tables, views, _connector_type
-
-def _parse_sql(sql):
- parsed = sqlparse.parse(sql)
- stmt = parsed[0]
- parsed_sql = {}
- current_keyword = ""
- for token in stmt.tokens:
- if token.is_keyword:
- if current_keyword in parsed_sql and parsed_sql[current_keyword] == '':
- # Check composed keywords like 'order by'
- del parsed_sql[current_keyword]
- current_keyword += " " + str(token)
- else:
- current_keyword = str(token)
- parsed_sql[current_keyword] = ""
- elif type(token) is sqlparse.sql.Where:
- parsed_sql['where'] = token
- else:
- if not token.is_whitespace:
- parsed_sql[current_keyword] += str(token)
- return parsed_sql
-
-_operators = {
- '=': '==',
-}
-
-def _translate_condition(table, condition, params):
- field = condition.left.get_real_name()
-
- operator = list(filter(lambda t: t.ttype == sqlparse.tokens.Comparison, condition.tokens))[0]
- if operator.value in _operators:
- operator = _operators[operator.value]
- else:
- operator = operator.value
-
- value = condition.right.value
- if value.startswith(':'):
- # Value is a parameters
- value = value[1:]
- if value in params:
+ return [
+ {
+ 'idx': idx,
+ 'name': colname,
+ 'primary_key': False,
+ }
+ for idx, colname in enumerate(colnames)
+ ]
+
+ def hidden_table_names(self):
+ return []
+
+ def detect_spatialite(self):
+ return False
+
+ def view_names(self):
+ return []
+
+ def detect_fts(self, table_name):
+ return False
+
+ def foreign_keys(self, table_name):
+ return []
+
+ def table_exists(self, table_name):
+ try:
+ self.conn.h5file.get_node(table_name)
+ return True
+ except:
+ return False
+
+ def table_definition(self, table_type, table_name):
+ table = self.conn.h5file.get_node(table_name)
+ colnames = ['value']
+ if isinstance(table, tables.table.Table):
+ colnames = table.colnames
+
+ return 'CREATE TABLE {} ({})'.format(
+ table_name,
+ ', '.join(colnames),
+ )
+
+ def indices_definition(self, table_name):
+ return []
+
+ def execute(
+ self,
+ sql,
+ params=None,
+ truncate=False,
+ custom_time_limit=None,
+ page_size=None,
+ log_sql_errors=True,
+ ):
+ results = []
+ truncated = False
+ description = ()
+
+ parsed_sql = parse_sql(sql, params)
+
+ while isinstance(parsed_sql['from'], dict):
+ # Pytables does not support subqueries
+ parsed_sql['from'] = parsed_sql['from']['value']['from']
+
+ table = self.conn.h5file.get_node(parsed_sql['from'])
+ table_rows = []
+ fields = parsed_sql['select']
+ colnames = ['value']
+ if type(table) is tables.table.Table:
+ colnames = table.colnames
+
+ query = ''
+ start = 0
+ end = table.nrows
+
+ def _get_field_type(field):
+ coltype = table.dtype.name
+ if type(table) is tables.table.Table:
+ coltype = table.coltypes[field]
+ return coltype
+
+ # Use 'where' statement or get all the rows
+ def _cast_param(field, pname):