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

Function get_schema

hardness_eval.py:108–129  ·  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

106
107
108def get_schema(db):
109 """
110 Get database's schema, which is a dict with table name as key
111 and list of column names as value
112 :param db: database path
113 :return: schema dict
114 """
115
116 schema = {}
117 conn = sqlite3.connect(db)
118 cursor = conn.cursor()
119
120 # fetch table names
121 cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
122 tables = [str(table[0].lower()) for table in cursor.fetchall()]
123
124 # fetch table info
125 for table in tables:
126 cursor.execute("PRAGMA table_info({})".format(table))
127 schema[table] = [str(col[1].lower()) for col in cursor.fetchall()]
128
129 return schema
130
131
132def get_schema_from_json(fpath):

Callers 1

get_hardnessFunction · 0.70

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected