0

I have this array

stokmiktarı[ ]= {04.08.2019,"Stok Miktarı",40,50,60}

I want to insert this array into sqlite database like this.

-------------------------------------------------------------
Tarih      |     Isim      |   A Store   |   B Store   |   C Store  |
-------------------------------------------------------------
04.08.2019 |  Stok Miktarı |     40      |      50     |      60    |

How can ı do this in python please help me thanks.

4
  • are u using django/flask ... Commented Aug 4, 2019 at 14:58
  • No this cmd application Commented Aug 4, 2019 at 15:00
  • here is an example array to sqlite3 Commented Aug 4, 2019 at 15:02
  • sorry but ı didn't understand exampla Commented Aug 4, 2019 at 15:15

2 Answers 2

2
import sqlite3

db = sqlite3.connect(':memory:') # creates db in RAM
cursor = db.cursor()
cursor.execute('''
    CREATE TABLE stores_info(id INTEGER PRIMARY KEY, tarih DATE,
                 isim TEXT, a_store TEXT, b_store TEXT, c_store TEXT)
''')
db.commit()

stores = [
    ['04.08.2019', 'Stok Miktarı', 40,50,60],
    ['05.07.2019', 'Stok Miktarı 2', 41,51,61],
    ['06.11.2019', 'Stok Miktarı 3', 40,50,60]
]
cursor.executemany('''
    INSERT INTO stores_info(tarih, isim, a_store, b_store, c_store) VALUES(?,?,?,?,?)
''', stores)
db.commit()

# retrive result
cursor.execute(''' SELECT tarih, isim, a_store, b_store, c_store FROM stores ''')
# cursor.fetchone() # retrieves the first row
result = cursor.fetchall()
for row in result:
    print row[0], row[1], row[2], row[3], row[4]

Here is the output...

# by inserting a_store, b_store & tarih to db
05.07.2019 41 51
04.08.2019 40 50
Sign up to request clarification or add additional context in comments.

Comments

0

Have you already created database and tables to store this data?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.