Python SQL Flashcards
1
Q
Creating Connection
A
conn = Main_Menu.create_connection(“Candles Database”)
cur = conn.cursor()
def create_connection(connstr):
conn = None
try:
conn = sqlite3.connect(connstr)
except Exception as e:
print(e)
return conn
2
Q
SELECT (with LIKE)
A
sql = (“SELECT OldCustomerOrders.CustomerOrderID FROM OldCustomerOrders WHERE OldCustomerOrders.CustomerOrderID LIKE ‘%” + word + “%’”)
cur.execute(sql)
self.x = cur.fetchall()
OR
cur.execute(“SELECT Forename, Surname, Orders, OldCustomerOrders.CustomerOrderID FROM Customers, OldCustomerOrders WHERE Customers.CustomerID = OldCustomerOrders.CustomerID”)
_fetched = cur.fetchall()