Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please pick the best possible answer for the following SQL Quiz---- Thank you Qu

ID: 3751438 • Letter: P

Question

Please pick the best possible answer for the following SQL Quiz---- Thank you

Question 1 (1 point)

Placeholders are used to defend against what kind of hacking attack?

a

SQL Injection

b

Key stroke logging

c

Phishing

d

Denial of Service

Question 2 (1 point)

The parameters needed for a MySQL database connect string are

a

host name

b

user name

c

password

d

All of the above

Question 3 (1 point)

Which step is missing in the procedure for running database commands from a Python script?
Import the connector library,
Open a connection to the database using your database connection credentials,
Construct and send a query,
Commit the query if it’s an insert, update, or delete operation,
Close the cursor,
Close the connection.

a

obtain a cursor

b

validate the connection

c

validate the query

d

buffer the connection

Question 4 (1 point)

___________ are used when an SQL statement has to be executed multiple times in a Python script.

a

Prepared statements

b

Cursors

c

Connections

d

Queries

Question 5 (1 point)

To control for an InternalError exception you should use a(n) __________ connection.

a

Unbuffered

b

Buffered

c

Secure

d

Open

Question 6 (1 point)

The default behavior for Connector/Python is to use __________ results.

a

buffered

b

unbuffered

c

uninitialized

d

list-based

Question 7 (1 point)

You get an error when trying to insert a record into a table from a Python script. A possible reason for this could be:

a

Malformed insert statement

b

Failure to connect to the database

c

No permission to insert into the table

d

All of these

Question 8 (1 point)

You have a Python script where you don’t buffer your query results. The query result returns ten rows and you read only the first row and then close the cursor. What kind of error will you get?

a

Should not get an error.

b

Syntax error

c

Buffer underflow exception

d

Internal error

Question 9 (1 point)

You were trying to insert a record into a table from a Python script when you got the following error message:
>>> ================================ RESTART ================================
>>>
cannot connect to MySQL : exception : 1044 (42000): Access denied for user 'jump'@'localhost' to database 'classicmodels'
Terminating MySQL connection.
What should you do?

a

Check for missing libraries

b

Reinstall Python

c

Reboot your computer

d

Grant user permissions on the database

Question 10 (1 point)

Which MySQLCursor object returns all the rows in a result set?

a

fetchone()

b

fecthsome()

c

fetchmany()

d

fetchall()

a

SQL Injection

b

Key stroke logging

c

Phishing

d

Denial of Service

Explanation / Answer

Answer 1
********
a). SQL injection

Answer 2
********
d). All of the above

syntax
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Answer 3
********

a) obtain a curson

# importing the module
import MySQLdb

# opening a database connection
db = MySQLdb.connect ("localhost","testprog","stud","PYDB")

# obtain a cursor
cursor = conn.cursor

# drop table if exists
Cursor.execute("IF STUDENT TABLE EXISTS DROP IT")

# query
sql = "CREATE TABLE STUDENT (NAME CHAR(30) NOT NULL, CLASS CHAR(5), AGE INT, GENDER CHAR(8), MARKS INT"

# execute query
cursor.execute(sql)

# close object
cursor.close()

# close connection
conn.close()

Answer 4
*********

1) cursor.execute('USE db_name')
cursor.execute('INSERT INTO table_name VALUES (1)')
cursor.execute('INSERT INTO table_name VALUES ("non-integer value")')
cursor.execute('DROP DATABASE IF EXISTS db_name')
cursor.execute('CREATE DATABASE db_name')
2) cursor.execute('USE db_name')
cursor.execute('CREATE TABLE table_name(first_field INTEGER)')

in above all the answer just check that cursor.execute remains same , but if we consider that same statement than answer will be A

from 1) and 2) are Prepared Statement

Answer 5
*********
b) buffered

try:
    code here
except pymysql.err.InternalError:
    print('already exists')
except:
    print('catch-all exception!')

Answer 6
********
a) uninitialized

By default, MySQL Connector/Python does not buffer or prefetch results. This means that after a query is executed, your program is responsible for fetching the data. This avoids excessive memory use when queries return large result sets. If you know that the result set is small enough to handle all at once, you can fetch the results immediately by setting buffered to True

Answer 7
*********
d) All of these

any of them could cause an error

Answer 8
*********
i am not sure about it but it may be
b) syntax error
as we are not storing the result in tht buffer so buffer underflow is not going to occur

Answer 9
*********
d) Grant user permissions on the database

its permission access denied error

Answer 10
*********
d) fetchall()

rows = cursor.fetchall()
print('Total Row(s):', cursor.rowcount)

if you like my answer please appreciate with thumbs up , thanks :)