(self, connection, table_name, schema=None, **kw)
| 2882 | |
| 2883 | @reflection.cache |
| 2884 | def get_indexes(self, connection, table_name, schema=None, **kw): |
| 2885 | pragma_indexes = self._get_table_pragma( |
| 2886 | connection, "index_list", table_name, schema=schema |
| 2887 | ) |
| 2888 | indexes = [] |
| 2889 | |
| 2890 | # regular expression to extract the filter predicate of a partial |
| 2891 | # index. this could fail to extract the predicate correctly on |
| 2892 | # indexes created like |
| 2893 | # CREATE INDEX i ON t (col || ') where') WHERE col <> '' |
| 2894 | # but as this function does not support expression-based indexes |
| 2895 | # this case does not occur. |
| 2896 | partial_pred_re = re.compile(r"\)\s+where\s+(.+)", re.IGNORECASE) |
| 2897 | |
| 2898 | if schema: |
| 2899 | schema_expr = "%s." % self.identifier_preparer.quote_identifier( |
| 2900 | schema |
| 2901 | ) |
| 2902 | else: |
| 2903 | schema_expr = "" |
| 2904 | |
| 2905 | include_auto_indexes = kw.pop("include_auto_indexes", False) |
| 2906 | for row in pragma_indexes: |
| 2907 | # ignore implicit primary key index. |
| 2908 | # https://www.mail-archive.com/sqlite-users@sqlite.org/msg30517.html |
| 2909 | if not include_auto_indexes and row[1].startswith( |
| 2910 | "sqlite_autoindex" |
| 2911 | ): |
| 2912 | continue |
| 2913 | indexes.append( |
| 2914 | dict( |
| 2915 | name=row[1], |
| 2916 | column_names=[], |
| 2917 | unique=row[2], |
| 2918 | dialect_options={}, |
| 2919 | ) |
| 2920 | ) |
| 2921 | |
| 2922 | # check partial indexes |
| 2923 | if len(row) >= 5 and row[4]: |
| 2924 | s = ( |
| 2925 | "SELECT sql FROM %(schema)ssqlite_master " |
| 2926 | "WHERE name = ? " |
| 2927 | "AND type = 'index'" % {"schema": schema_expr} |
| 2928 | ) |
| 2929 | rs = connection.exec_driver_sql(s, (row[1],)) |
| 2930 | index_sql = rs.scalar() |
| 2931 | predicate_match = partial_pred_re.search(index_sql) |
| 2932 | if predicate_match is None: |
| 2933 | # unless the regex is broken this case shouldn't happen |
| 2934 | # because we know this is a partial index, so the |
| 2935 | # definition sql should match the regex |
| 2936 | util.warn( |
| 2937 | "Failed to look up filter predicate of " |
| 2938 | "partial index %s" % row[1] |
| 2939 | ) |
| 2940 | else: |
| 2941 | predicate = predicate_match.group(1) |
no test coverage detected