Ejemplo n.º 1
0
    def select_query(self, query):
        query_tables = get_all_tables(query)

        if len(query_tables) != 1:
            raise Exception(f'Only one table can be used in query to information_schema: {query}')

        data = self.datastore.get_data(query_tables[0], where=None, limit=None, offset=None)
        return data['data']
Ejemplo n.º 2
0
    def select(self, query):
        query_tables = get_all_tables(query)

        if len(query_tables) != 1:
            raise Exception(
                f'Only one table can be used in query to information_schema: {query}'
            )

        table = query_tables[0].upper()
        if table == 'TABLES':
            dataframe = self._get_tables()
        elif table == 'COLUMNS':
            dataframe = self._get_columns()
        elif table == 'SCHEMATA':
            dataframe = self._get_schemata()
        elif table == 'EVENTS':
            dataframe = self._get_events()
        elif table == 'ROUTINES':
            dataframe = self._get_routines()
        elif table == 'TRIGGERS':
            dataframe = self._get_triggers()
        elif table == 'PLUGINS':
            dataframe = self._get_plugins()
        else:
            raise Exception('Information schema: Not implemented.')

        table_name = query.from_table.parts[-1]
        # region FIXME https://github.com/mindsdb/dfsql/issues/37 https://github.com/mindsdb/mindsdb_sql/issues/53
        if ' 1 = 0' in str(query):
            q = str(query)
            q = q[:q.lower().find('where')] + ' limit 0'
            data = dfsql.sql_query(q,
                                   ds_kwargs={'case_sensitive': False},
                                   reduce_output=False,
                                   **{table_name: dataframe})
        # endregion
        else:
            # ---
            try:
                if table == 'TABLES':
                    query = 'select * from TABLES'
                    table_name = 'TABLES'
                data = dfsql.sql_query(str(query),
                                       ds_kwargs={'case_sensitive': False},
                                       reduce_output=False,
                                       **{table_name: dataframe})
            except Exception as e:
                print(f'Exception! {e}')
                return [], []

        return data.to_dict(orient='records'), data.columns.to_list()
Ejemplo n.º 3
0
    def select(self, query):
        query_tables = get_all_tables(query)

        if len(query_tables) != 1:
            raise Exception(
                f'Only one table can be used in query to information_schema: {query}'
            )

        data = self.datastore.get_data(query_tables[0],
                                       where=None,
                                       limit=None,
                                       offset=None)
        data_df = DF(data['data'])
        result = query_df(data_df, query)
        return result.to_dict(orient='records'), result.columns.to_list()
Ejemplo n.º 4
0
    def select(self, query):
        query_tables = get_all_tables(query)

        if len(query_tables) != 1:
            raise Exception(
                f'Only one table can be used in query to information_schema: {query}'
            )

        table_name = query_tables[0].upper()

        if table_name not in self.get_dataframe_funcs:
            raise Exception('Information schema: Not implemented.')

        dataframe = self.get_dataframe_funcs[table_name]()

        try:
            data = query_df(dataframe, query)
        except Exception as e:
            print(f'Exception! {e}')
            return [], []

        return data.to_dict(orient='records'), data.columns.to_list()