May-04-2022, 07:19 AM
Here is a rough example of one way to do it. (There are better ways)
Just call the function for each insert.
Just call the function for each insert.
import sqlite3 as sq conn = sq.connect('inventory.db') table = ''' create table items ( id integer primary key autoincrement not null, name varchar(255) not null, image blob, quantity integer not null default 0, price double not null, sell_price double, location text, description text, category varchar(255), length integer default 0, brightness varchar(255), rating varchar(255), torque varchar(255), updated datetime default current_timestamp ); ''' conn.execute(table) def inserts(): name = input('item name: ') price = input('item price: ') quantity = input('item quantity: ') description = input('item description: ') category = input('item category: ') mylist = [name, price, quantity, description, category] return mylist cursor = conn.cursor() cursor.execute(''' insert into items (name, price, quantity, description, category) values (?,?,?,?,?) ''', inserts()) conn.commit() cursor.execute('select * from items') result = cursor.fetchall() conn.close() print(result)
Output:[(1, 'goofy', None, 8, 10.0, None, None, 'some kind of something', 'doggy', 0, None, None, None, '2022-05-04 07:13:50')]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts