Give A Try - Database Connectivity
Give A Try - Database Connectivity
Give A Try - Database Connectivity
/bin/python3
import sys
import os
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
cursor = conn.cursor()
---------------------1----------------------------------
#!/bin/python3
import sys
import os
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
#create connection cursor
cur = conn.cursor()
#create table ITEMS using the cursor
cur.execute('''CREATE TABLE ITEMS(
item_id text, item_name text, item_description text, item_category text,
quantity_in_stock real)''')
#commit connection
conn.commit()
#close connection
conn.close()
------------------------2--------------------------------
cursor.execute("drop table if exists ITEMS")
cursor.execute(sql_statement)
if __name__ == "__main__":
----------------------3----------------------
#!/bin/python3
import sys
import os
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
cursor = conn.cursor()
cursor.execute(sql_statement)
if __name__ == "__main__":
---------------------------4-----------------------------
#!/bin/python3
import sys
import os
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
cursor = conn.cursor()
cursor.execute("drop table if exists ITEMS")
cursor.execute(sql_statement)
if __name__ == "__main__":
-------------------------5---------------------------
#!/bin/python3
import sys
import os
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
cursor = conn.cursor()
cursor.execute(sql_statement)
try:
cursor.executemany("Insert into ITEMS values (?,?,?,?,?)", items)
cursor.executemany("update ITEMS set quantity_in_stock = ? where item_id
= ?",
[(4, 103),
(2, 101),
(0, 105)])
#Add code below to delete items
conn.execute("DELETE from ITEMS where item_id = 105;")
cursor.execute("select item_id from ITEMS")
except:
return 'Unable to perform the transaction.'
rowout=[]
for row in cursor.fetchall():
rowout.append(row)
return rowout
conn.close()
if __name__ == "__main__":