Hello! I am currently working on the hotel database project in the advance python3 class.
I’m running this code and I get an error that states:
Traceback (most recent call last):
File “script.py”, line 40, in
curs.executemany(’’‘INSERT INTO bra_customers VALUES (?,?,?,?,?,?,?,?,?,?,?,?)’’’, bra)
sqlite3.ProgrammingError: Recursive use of cursors not allowed.
Import module
import sqlite3
Task 1: Create connection object
con = sqlite3.connect(‘hotel_booking.db’)
Task 2: Create cursor object
curs = con.cursor()
Task 3: View first row of booking_summary
#print(curs.execute(’’‘SELECT * FROM booking_summary’’’).fetchone())
Task 4: View first ten rows of booking_summary
#print(curs.execute(’’‘SELECT * FROM booking_summary’’’).fetchmany(10))
Task 5: Create object bra and print first 5 rows to view data
bra = (curs.execute(’’‘SELECT * FROM booking_summary WHERE country = ‘BRA’;’’’))
print(bra.fetchmany(5))
Task 6: Create new table called bra_customers
curs.execute(’’‘CREATE TABLE IF NOT EXISTS
bra_customers(
num INTEGER,
hotel TEXT,
is_cancelled INTEGER,
lead_time INTEGER,
arrival_date_year INTEGER,
arrival_date_month TEXT,
arrival_date_day_of_month INTEGER,
adults INTEGER,
children INTEGER,
country TEXT,
adr REAL,
special_requests INTEGER
)
‘’’)
Task 7: Insert the object bra into the table bra_customers
curs.executemany(’’‘INSERT INTO bra_customers VALUES (?,?,?,?,?,?,?,?,?,?,?,?)’’’, bra)
EDIT:
Nevermind! I figured it out.
bra_list = bra.fetchall()
I added this line, I guess you needed to have a fetch method to get the actual tuple of values to add into the new table.