Activity 20: Python Orm Sqlalchemy
GitHub Reposiory
github.com/MonetForProgrammingPurposes/PYTH..
ORMQuizDb
Table Creation:
The
CREATE TABLE
statement was successfully executed to create the quiz table, as shown in the following logs:CREATE TABLE quiz ( id INTEGER NOT NULL, question VARCHAR, answer VARCHAR, PRIMARY KEY (id) )
Inserting Data:
Five records inserted into the quiz
table, as confirmed by the following repeated INSERT INTO quiz
logs:
INSERT INTO quiz (question, answer) VALUES (?, ?)
Committing Changes:
After both the table creation and data insertion, SQLAlchemy committed the transactions with the logs:
COMMIT
Querying Data:
The data was queried from the table. The following lines show the
SELECT
statement being executed and the result being printed:SELECT quiz.id AS quiz_id, quiz.question AS quiz_question, quiz.answer AS quiz_answer FROM quiz
The printed output is:
Question: What is the capital of France?, Answer: Paris Question: What is 2 + 2?, Answer: 4 Question: Who wrote Hamlet?, Answer: Shakespeare Question: What is the boiling point of water?, Answer: 100°C Question: What is the speed of light?, Answer: 299,792,458 m/s
Updating Data:
Updated the answer to the first quiz item. This is indicated by:
UPDATE quiz SET answer=? WHERE quiz.id = ?
Deleting Data:
The second quiz entry was deleted, as indicated by:
DELETE FROM quiz WHERE quiz.id = ?
ORMEcommerceDb