File size: 1,496 Bytes
a71dd13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sqlite3

def extract_name_and_colums(db):
    try:
        # Connect to the database (replace 'student.db' with your database name)
        connection = sqlite3.connect(db)
        cur = connection.cursor()
        
        all_tables_and_columns = {}
        
        for_table = cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = for_table.fetchall()
        
        for table in tables:
            table_name = table[0]
            cur.execute(f"PRAGMA table_info({table_name});")
            columns = cur.fetchall()
            column_names = [col[1] for col in columns]
            all_tables_and_columns[table_name] = column_names
        

        # Extract table names from the query result
        table_name = [table[0] for table in tables]
        
   
        return  {"table_name": table_name , "colum_names" : all_tables_and_columns}
    
    
    except sqlite3.Error as e:
        print(f"An error occurred: {e}")
    
    finally:
        # Close the connection
        if connection:
            connection.close()
            
            
            
def read_excel_query():
    pass



# Function to retrive query from the
def read_sql_query(sql,db):
    
    connection = sqlite3.connect(db)
    cur = connection.cursor()
    cur.execute(sql)
    rows = cur.fetchall()
    connection.commit()
    connection.close()
    # for row in rows:
    #     # print(row)
    return rows