MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / get_schema

Function get_schema

evaluation/test-suite-sql-eval/process_sql.py:79–100  ·  view source on GitHub ↗

Get database's schema, which is a dict with table name as key and list of column names as value :param db: database path :return: schema dict

(db)

Source from the content-addressed store, hash-verified

77
78
79def get_schema(db):
80 """
81 Get database's schema, which is a dict with table name as key
82 and list of column names as value
83 :param db: database path
84 :return: schema dict
85 """
86
87 schema = {}
88 conn = sqlite3.connect(db)
89 cursor = conn.cursor()
90
91 # fetch table names
92 cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
93 tables = [str(table[0].lower()) for table in cursor.fetchall()]
94
95 # fetch table info
96 for table in tables:
97 cursor.execute("PRAGMA table_info({})".format(table))
98 schema[table] = [str(col[1].lower()) for col in cursor.fetchall()]
99
100 return schema
101
102
103def get_schema_from_json(fpath):

Callers 2

evaluateFunction · 0.90
evaluateFunction · 0.90

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected