Returns list of tables or functions for a (optional) schema
(self, schema: str | None, obj_type: str, columns: list[str] | None = None)
| 1847 | return "'" + value.replace("'", "''") + "'" |
| 1848 | |
| 1849 | def populate_schema_objects(self, schema: str | None, obj_type: str, columns: list[str] | None = None) -> list[str]: |
| 1850 | """Returns list of tables or functions for a (optional) schema""" |
| 1851 | metadata = self.dbmetadata[obj_type] |
| 1852 | schema = schema or self.dbname |
| 1853 | try: |
| 1854 | objects = list(metadata[schema].keys()) |
| 1855 | except KeyError: |
| 1856 | # schema doesn't exist |
| 1857 | objects = [] |
| 1858 | |
| 1859 | filtered_objects: list[str] = [] |
| 1860 | remaining_objects: list[str] = [] |
| 1861 | |
| 1862 | # If the requested object type is tables and the user already entered |
| 1863 | # columns, return a filtered list of tables (or views) that contain |
| 1864 | # one or more of the given columns. If a table does not contain the |
| 1865 | # given columns, add it to a separate list to add to the end of the |
| 1866 | # filtered suggestions. |
| 1867 | if obj_type == "tables" and columns and objects: |
| 1868 | for obj in objects: |
| 1869 | matched = False |
| 1870 | for column in metadata[schema][obj]: |
| 1871 | if column in columns: |
| 1872 | filtered_objects.append(obj) |
| 1873 | matched = True |
| 1874 | break |
| 1875 | if not matched: |
| 1876 | remaining_objects.append(obj) |
| 1877 | else: |
| 1878 | filtered_objects = objects |
| 1879 | return filtered_objects + remaining_objects |