Search Header Logo

🌟 Python + MySQL Connectivity

Authored by Harmeet Kaur

Computers

12th Grade

Used 3+ times

🌟 Python + MySQL Connectivity
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

22 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is the correct method to prevent SQL injection when inserting user input into a MySQL database using PyMySQL?

Use string concatenation for query formation

Use %s placeholders in the query and pass values as a tuple

Use f-string formatting in SQL queries

Use raw input directly in the SQL query

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a Python program using PyMySQL, what happens if you attempt to insert a record into a table where a NOT NULL column is left empty and no default value is set?

The record is inserted with NULL in that column

A ProgrammingError is raised by PyMySQL

A DataError is raised by the MySQL server

An IntegrityError is raised by PyMySQL

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider a table orders(order_id INT PRIMARY KEY, customer_id INT, order_date DATE) and customers(customer_id INT PRIMARY KEY, name VARCHAR(50)). Which query retrieves all orders along with customer names, ensuring that orders without a matching customer are also shown?

SELECT * FROM orders JOIN customers USING(customer_id)

SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id

SELECT * FROM orders LEFT JOIN customers ON orders.customer_id = customers.customer_id

SELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.customer_id

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Given a PyMySQL connection object conn, how do you ensure that changes made via cursor operations are permanently saved in the database?

Use conn.save()

Call conn.commit()

Call conn.flush()

Call cursor.commit()

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is NOT a valid reason for a MySQLdb._exceptions.OperationalError: (2006, "MySQL server has gone away") error?

Query execution timeout

Server closed the connection due to inactivity

Data size in a single packet exceeds max_allowed_packet

Primary key constraint violation in INSERT query

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a PyMySQL program, you attempt to execute the following query: cursor.execute("SELECT * FROM flights WHERE destination = %s", "London"). What is the issue in this statement?

The placeholder %s must be replaced with the actual value before execution

The value “London” must be passed as a tuple

The query will work without any issue

The query requires a dictionary instead of a tuple for parameter passing

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following tasks would typically require the use of the tabulate module in a PyMySQL application?

Validating data types in a MySQL table

Displaying query results in a formatted table view in the console

Handling SQL exceptions in Python

Automating database backups

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?