- h5tables[table._v_pathname] = {
- 'name': table._v_pathname,
- 'columns': colnames,
- 'primary_keys': [],
- 'count': int(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:
- # Cast value to the column type
- coltype = table.coltypes[field]
- if coltype == 'string':
- params[value] = str(params[value])
- elif coltype.startswith('int'):
- params[value] = int(params[value])
- elif coltype.startswith('float'):
- params[value] = float(params[value])