Python Forum
Help With Python SQLite Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help With Python SQLite Error
#9
Here is a rough example of one way to do it. (There are better ways)
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


Reply


Messages In This Thread
Help With Python SQLite Error - by Extra - Apr-30-2022, 12:16 AM
RE: Help With Python SQLite Error - by Extra - Apr-30-2022, 01:01 AM
RE: Help With Python SQLite Error - by deanhystad - Apr-30-2022, 03:01 AM
RE: Help With Python SQLite Error - by ibreeden - May-01-2022, 09:09 AM
RE: Help With Python SQLite Error - by Extra - May-02-2022, 11:08 PM
RE: Help With Python SQLite Error - by menator01 - May-03-2022, 12:42 AM
RE: Help With Python SQLite Error - by Extra - May-03-2022, 10:47 PM
RE: Help With Python SQLite Error - by ibreeden - May-04-2022, 07:18 AM
RE: Help With Python SQLite Error - by Extra - May-04-2022, 11:42 PM
RE: Help With Python SQLite Error - by menator01 - May-04-2022, 07:19 AM
RE: Help With Python SQLite Error - by Extra - May-04-2022, 11:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with data analysing with python and sqlite Hardcool 2 1,057 Jan-30-2024, 06:49 AM
Last Post: Athi
  python sqlite autoincrement in primary column janeik 6 3,113 Aug-13-2023, 11:22 AM
Last Post: janeik
  Help with subtracting values using SQLite & Python Extra 10 5,360 May-10-2022, 08:36 AM
Last Post: ibreeden
  [Solved]Help with search statement-SQLite & Python Extra 1 1,923 May-06-2022, 07:38 PM
Last Post: Extra
  Python Sqlite georgebijum 0 1,622 May-04-2022, 10:12 AM
Last Post: georgebijum
  Error while transferring data from sqlite to elasticsearch - please help! ps96068 1 3,709 Jun-12-2021, 09:24 AM
Last Post: ibreeden
  SQLite Unique constraint failed error djwilson0495 3 16,799 Aug-14-2020, 05:23 PM
Last Post: ndc85430
  Importing data from a text file into an SQLite database with Python macieju1974 7 6,220 Jun-29-2020, 08:51 PM
Last Post: buran
  how to use items combobox in table name sqlite in python hampython 1 3,481 May-24-2020, 02:17 AM
Last Post: Larz60+
  Error SQLite objects created in a thread can only be used in that same thread. binhduonggttn 3 19,277 Jan-31-2020, 11:08 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020