Nov-08-2022, 07:05 PM
(This post was last modified: Nov-08-2022, 07:07 PM by marlonbown.
Edit Reason: Include block for code
)
Hello, can someone assist here please:
When I run the program below, I expect table to be created and record inserted into the database.
However when I query database, it displays no records.
Please let me know if you can point out what is missing here from either query or insert operation.
Thank you,
Marlon
=====
Table is Ready. Now I will insert...
[]
(venv) user@3c0630078aad venv %
When I run the program below, I expect table to be created and record inserted into the database.
However when I query database, it displays no records.
Please let me know if you can point out what is missing here from either query or insert operation.
Thank you,
Marlon
=====
import sqlite3 def insert(): connection_obj = sqlite3.connect('apix.db') cursor_obj = connection_obj.cursor() cursor_obj.execute("DROP TABLE IF EXISTS APIX") table = """ CREATE TABLE APIX ( IP VARCHAR(255) NOT NULL, DATE CHAR(8) NOT NULL ); """ cursor_obj.execute(table) print("Table is Ready. Now I will insert...") connection_obj.execute ("""INSERT INTO APIX (IP,Date) VALUES ("1.1.1.1","03/03/01")""") connection_obj.close() def query(): connection_obj = sqlite3.connect('apix.db') cursor_obj = connection_obj.cursor() statement = '''SELECT * FROM APIX''' cursor_obj.execute(statement) output = cursor_obj.fetchall() for row in output: print(row) connection_obj.commit() connection_obj.close() return output insert() print(query())(venv) user@3c0630078aad venv % python delmain.py
Table is Ready. Now I will insert...
[]
(venv) user@3c0630078aad venv %