Commit all modified tracked files

This commit is contained in:
2026-01-29 08:06:31 +01:00
parent 34b685bef1
commit cf36b715fe
38 changed files with 1522 additions and 10231 deletions
+34 -31
View File
@@ -7,38 +7,41 @@ Loading...
│  2 | # Connect to an in-memory database
│  3 | conn = sqlite3.connect(':memory:')
│  4 | cur = conn.cursor()
│  5 | # Create schema for library system
│  6 | schema = '''
│  7 | CREATE TABLE authors (
│  8 | id INTEGER PRIMARY KEY AUTOINCREMENT,
│  9 | name TEXT NOT NULL
│  10 | );
│  11 | CREATE TABLE books (
│  5 | # Create tables
│  6 | cur.execute('''CREATE TABLE authors (
│  7 | id INTEGER PRIMARY KEY AUTOINCREMENT,
│  8 | name TEXT NOT NULL,
│  9 | birth_year INTEGER
│  10 | );''')
│  11 | cur.execute('''CREATE TABLE books (
│  12 | id INTEGER PRIMARY KEY AUTOINCREMENT,
│  13 | title TEXT NOT NULL,
│  14 | author_id INTEGER,
│  15 | FOREIGN KEY(author_id) REFERENCES authors(id)
│  16 | );
│  17 | '''
│  18 | cur.executescript(schema)
│  19 | # Insert sample records
│  20 | authors = [('Jane Austen',), ('Mark Twain',), ('J.K. Rowling',), ('George Orwell',), ('Leo Tolstoy',)]
│  21 | cur.executemany('INSERT INTO authors (name) VALUES (?)', authors)
│  22 | books = [
│  23 | ('Pride and Prejudice', 1),
│  24 | ('Adventures of Huckleberry Finn', 2),
│  25 | ('Harry Potter and the Sorcerer\'s Stone', 3),
│  26 | ('1984', 4),
│  27 | ('War and Peace', 5),
│  28 | ]
│  29 | cur.executemany('INSERT INTO books (title, author_id) VALUES (?, ?)', books)
│  30 | # Generate SQL dump
│  31 | dump = ""
│  32 | for line in conn.iterdump():
│  33 | dump += line + "\n"
│  34 | # Save dump to file
│  35 | with open('db_migration.sql', 'w') as f:
│  36 | f.write(dump)
│  37 | conn.close()
│  15 | published_year INTEGER,
│  16 | FOREIGN KEY(author_id) REFERENCES authors(id)
│  17 | );''')
│  18 | # Insert sample authors
│  19 | authors = [
│  20 | ('Jane Austen', 1775),
│  21 | ('Charles Dickens', 1812),
│  22 | ('Leo Tolstoy', 1828),
│  23 | ('Mark Twain', 1835),
│  24 | ('Virginia Woolf', 1882)
│  25 | ]
│  26 | cur.executemany('INSERT INTO authors (name, birth_year) VALUES (?, ?);', authors)
│  27 | # Insert sample books
│  28 | books = [
│  29 | ('Pride and Prejudice', 1, 1813),
│  30 | ('Great Expectations', 2, 1861),
│  31 | ('War and Peace', 3, 1869),
│  32 | ('Adventures of Huckleberry Finn', 4, 1884),
│  33 | ('Mrs. Dalloway', 5, 1925)
│  34 | ]
│  35 | cur.executemany('INSERT INTO books (title, author_id, published_year) VALUES (?, ?, ?);', books)
│  36 | # Generate dump
│  37 | with open('db_migration.sql', 'w') as f:
│  38 | for line in conn.iterdump():
│  39 | f.write('%s\n' % line)
│  40 | conn.close()
└────────────────────────────────────────────────────────────
The SQLite schema for the library system has been created, five sample records have been inserted, and a SQL dump has been generated and saved to 'db_migration.sql'. If you need to review the dump or perform further operations, please let me know!
The SQLite schema for a library system has been created, sample records inserted, and a SQL dump has been generated in the file 'db_migration.sql'.