| 12 | |
| 13 | |
| 14 | class DataManager: |
| 15 | def __init__(self) -> None: |
| 16 | self._results = [] |
| 17 | self._export_manager = SaveManager() |
| 18 | self._cursor = None |
| 19 | |
| 20 | def _validate_arguments(self) -> bool: |
| 21 | result = True |
| 22 | if DatabaseSetting().database_name is None: |
| 23 | result = False |
| 24 | AnsiPrint.print_error(locale.get("databasenull")) |
| 25 | self.databases() |
| 26 | |
| 27 | return result |
| 28 | |
| 29 | def _get_cursor(self): |
| 30 | db = DbConnector(database=DatabaseSetting().database_name, host=DatabaseSetting().host, |
| 31 | username=DatabaseSetting().username, password=DatabaseSetting().password, |
| 32 | dbms=DatabaseSetting().dbms) |
| 33 | |
| 34 | return db._createDBEngine() |
| 35 | |
| 36 | |
| 37 | def _create_dbCursor(self): |
| 38 | if self._validate_arguments(): |
| 39 | self._cursor = self._get_cursor() |
| 40 | |
| 41 | def _get_values_to_find(self, word:str)->str: |
| 42 | criterial = [] |
| 43 | words = word.split(',') |
| 44 | for value in words: |
| 45 | criterial.append(value) |
| 46 | |
| 47 | return criterial |
| 48 | |
| 49 | def _save_results(self, value:str, criterial:QueryType, results:list[Result]) -> bool: |
| 50 | if results.length > 0: |
| 51 | values = [info for info in self._results if info.criterial == criterial and info.value == value] |
| 52 | if len(values) == 0: |
| 53 | self._results.append(QueryResult(criterial=criterial, results=results, value = value)) |
| 54 | else: |
| 55 | values[0].append(results) |
| 56 | |
| 57 | return True |
| 58 | else: |
| 59 | return False |
| 60 | |
| 61 | def _filter_tables(self, table_name) -> list[Result]: |
| 62 | return self._cursor.search_tables(table_name if table_name != '*' else None ) |
| 63 | |
| 64 | def _filter_columns(self, column_name)-> list[Result]: |
| 65 | return self._cursor.search_columns(column_name) |
| 66 | |
| 67 | def _print_query_results(self, value_to_find:str, results:Result): |
| 68 | |
| 69 | if ResultSetting().include_columns: |
| 70 | AnsiPrint.printResult(results) # Print Results |
| 71 | else: |