Untitled

 avatar
unknown
plain_text
a year ago
854 B
3
Indexable
import sqlite3

with sqlite3.connect('new_klasa2.db') as new_conn:
    new_cursor = new_conn.cursor()

    try:
        with sqlite3.connect('klasa.db') as source_conn:
            source_cursor = source_conn.cursor()
            source_cursor.execute('PRAGMA table_info(studentet)')
            columns = [column[1] for column in source_cursor.fetchall()]

            create_table = f'CREATE TABLE IF NOT EXISTS studentet ({", ".join(columns)})'
            new_cursor.execute(create_table)

            source_cursor.execute("SELECT * FROM studentet")
            rows = source_cursor.fetchall()

            new_cursor.executemany(f'INSERT INTO studentet VALUES ({",".join(["?"]*len(columns))})', rows)

            print("Tabela u kopjua me sukses në bazën e re")

    except sqlite3.Error as e:
        print(f"Gabim në kopjimin e bazës: {e}")
Editor is loading...
Leave a Comment