(self, connection, table_name, schema=None, **kw)
| 2396 | |
| 2397 | @reflection.cache |
| 2398 | def get_columns(self, connection, table_name, schema=None, **kw): |
| 2399 | pragma = "table_info" |
| 2400 | # computed columns are threaded as hidden, they require table_xinfo |
| 2401 | if self.server_version_info >= (3, 31): |
| 2402 | pragma = "table_xinfo" |
| 2403 | info = self._get_table_pragma( |
| 2404 | connection, pragma, table_name, schema=schema |
| 2405 | ) |
| 2406 | columns = [] |
| 2407 | tablesql = None |
| 2408 | for row in info: |
| 2409 | name = row[1] |
| 2410 | type_ = row[2].upper() |
| 2411 | nullable = not row[3] |
| 2412 | default = row[4] |
| 2413 | primary_key = row[5] |
| 2414 | hidden = row[6] if pragma == "table_xinfo" else 0 |
| 2415 | |
| 2416 | # hidden has value 0 for normal columns, 1 for hidden columns, |
| 2417 | # 2 for computed virtual columns and 3 for computed stored columns |
| 2418 | # https://www.sqlite.org/src/info/069351b85f9a706f60d3e98fbc8aaf40c374356b967c0464aede30ead3d9d18b |
| 2419 | if hidden == 1: |
| 2420 | continue |
| 2421 | |
| 2422 | generated = bool(hidden) |
| 2423 | persisted = hidden == 3 |
| 2424 | |
| 2425 | if tablesql is None and generated: |
| 2426 | tablesql = self._get_table_sql( |
| 2427 | connection, table_name, schema, **kw |
| 2428 | ) |
| 2429 | # remove create table |
| 2430 | match = re.match( |
| 2431 | ( |
| 2432 | r"create table .*?\((.*)\)" |
| 2433 | r"(?:\s*,?\s*(?:WITHOUT\s+ROWID|STRICT))*$" |
| 2434 | ), |
| 2435 | tablesql.strip(), |
| 2436 | re.DOTALL | re.IGNORECASE, |
| 2437 | ) |
| 2438 | assert match, f"create table not found in {tablesql}" |
| 2439 | tablesql = match.group(1).strip() |
| 2440 | |
| 2441 | columns.append( |
| 2442 | self._get_column_info( |
| 2443 | name, |
| 2444 | type_, |
| 2445 | nullable, |
| 2446 | default, |
| 2447 | primary_key, |
| 2448 | generated, |
| 2449 | persisted, |
| 2450 | tablesql, |
| 2451 | ) |
| 2452 | ) |
| 2453 | if columns: |
| 2454 | return columns |
| 2455 | elif not self.has_table(connection, table_name, schema): |
no test coverage detected