Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

VNSGU BCA Sem 2: Desktop Publishing (205_02) Practical Solutions - April 2025 Set D

Paper Details
  • Subject: Desktop Publishing (DRA) / Python SQLite
  • Subject Code: 205_02
  • Set: D
  • Semester: 2
  • Month/Year: April 2025
  • Max Marks: 25
  • Time Recommendation: 45 Minutes
  • Paper: View Paper | Download PDF

Questions & Solutions

All questions are compulsory

Q1: Library Data Migration

Max Marks: 20

  1. Create CSV file Library.csv containing the following columns: Book_No, Book_Title, Subject, Author, Price. The file contains data of minimum 10 Books.
  2. Create a table named Books with appropriate data types.
  3. Write a Python script that Imports data from the CSV file into the Books table.

1. CSV Data Generation

Create the source file with at least 10 book records.

Hint

You can create this file manually in Excel/Notepad or using a simple Python script as shown below.

View Solution & Output

Library.csv (Content):

Book_No,Book_Title,Subject,Author,Price
101,C Programming,Programming,Dennis Ritchie,450.0
102,Python Basics,Programming,Guido van Rossum,550.0
103,Modern RDBMS,Database,C.J. Date,750.0
104,Operating Systems,Systems,Silberschatz,800.0
105,Networking,Networking,Tanenbaum,600.0
106,Data Structures,Algorithms,Sartaj Sahni,500.0
107,AI Fundamentals,AI,Stuart Russell,950.0
108,Web Design,Web,Jon Duckett,400.0
109,Java complete ref,Programming,Herbert Schildt,700.0
110,Software Engg,Management,Pressman,650.0

Step-by-Step Explanation:

  1. Initialization: Identify the required column headers for library data.
  2. Logic Flow: List at least 10 book records with their details in CSV format.
  3. Completion: Save the content as 'Library.csv' for future database import.

2. Database Table Creation

Define the Books table structure in SQLite.

View Solution & Output
import sqlite3

conn = sqlite3.connect('library.db')
cursor = conn.cursor()

cursor.execute('''
CREATE TABLE IF NOT EXISTS Books (
Book_No INTEGER PRIMARY KEY,
Book_Title TEXT NOT NULL,
Subject TEXT,
Author TEXT,
Price REAL
)
''')

print("Books table created.")
conn.close()

Step-by-Step Explanation:

  1. Initialization: Import sqlite3 and connect to 'library.db'.
  2. Logic Flow: Execute a CREATE TABLE query for the Books table with a primary key.
  3. Completion: Print a success message and close the database connection.

3. Data Import Script

Write the logic to read the CSV and insert it into the database.

Hint

Use csv.DictReader to map column headers to dictionary keys, making the insertion logic cleaner.

View Solution & Output
import sqlite3
import csv

# [1] Setup Database
conn = sqlite3.connect('library.db')
cursor = conn.cursor()

# [2] Read CSV and Import
try:
with open('Library.csv', 'r') as f:
reader = csv.reader(f)
next(reader) # Skip header row

for row in reader:
cursor.execute('INSERT INTO Books VALUES (?, ?, ?, ?, ?)', row)

conn.commit()
print("Data imported successfully from CSV to SQLite.")

except FileNotFoundError:
print("Error: Library.csv not found!")
finally:
conn.close()

Step-by-Step Explanation:

  1. Initialization: Import sqlite3 and csv and open 'Library.csv' for reading.
  2. Logic Flow: Use next(reader) to skip the header and iterate through each row to execute an INSERT statement.
  3. Completion: Commit the changes to the database and close the connection.
Concept Deep Dive: Data Migration

In real-world applications, data is often moved from legacy systems (like CSV/Excel) to relational databases (like SQLite/MySQL). This process involves reading row-by-row, validating data types, and using transactions (commit) to ensure data integrity.

Q2: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: Why use next(reader)?
    • A: It skips the header row of the CSV so you don't try to insert the column names as actual data records.
  2. Q: What happens if Book_No is a duplicate?
    • A: Since Book_No is the PRIMARY KEY, SQLite will raise an IntegrityError if you try to insert a duplicate.
  3. Q: How can you check if the import was successful?
    • A: By running a SELECT count(*) FROM Books query or SELECT * FROM Books to view the data.
  4. Q: What is the purpose of the try-except-finally block?
    • A: It provides robust error handling, ensuring the database connection is closed even if an error occurs during file reading.
  5. Q: Can you import a CSV without the csv module?
    • A: Yes, by reading the file line-by-line and using split(','), but the csv module is safer as it handles quotes and delimiters better.
  6. Q: Why is Price stored as REAL?
    • A: To allow for currency values with decimal points.
Common Pitfalls
  • Encoding Issues: If your CSV contains special characters, specify encoding='utf-8' in the open() function.
  • Header Mismatch: Ensure the number of columns in your CSV exactly matches the columns in your INSERT statement.

Quick Navigation

SetLink
Set ASolutions
Set BSolutions
Set CSolutions
Set DCurrent Page
Set ESolutions
Set FSolutions

Last Updated: April 2026

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir