0

So, I want to create a database for my program where one of the variables I want to store are 2 lists with data:

[2, 6, 14, 17, 24, 31, 40, 48, 56, 63, 69]
[0, 15, 30, 60, 90, 90, 90, 120, 120, 120, 120]

Creating a graph:

enter image description here

It will change every time user adds new data.

My problem is, how can I store those lists in this database?

etch_45
  • 792
  • 1
  • 6
  • 21
ubant
  • 39
  • 9

1 Answers1

0

This is a very broad question and there are plenty of good tutorials to help yout. But I would recommend to download sqlite3 and make the db file in the command line, f.x.

sqlite3 test.db
CREATE TABLE T(X INT,Y INT,Z INT);
.dump
.quit

Then I would open up an IDE and move the database to the same folder and create a .py file.

import sqlite3
conn = sqlite3.connect("test.db")
c = conn.cursor()
c.execute('''INSERT INTO T(X, Y, Z) VALUES(1, 2, 3);''')
conn.commit()
c.close()

This is very simple and might show you how to get started. But I highly recommend going on youtube and follow a tutorial there, just search python sqlite. Its going help you a lot more than any information that you are going to get from this thread.


Aslo recommend downloading Dbeaver(Database tool) to have more power over the .db file.


Best of luck.


EDIT
For the graphs I would recommend matplotlib.

IceJonas
  • 720
  • 6
  • 13
  • Thanks, that tool will definitely be helpful. I already use matplotlib and know a little bit how to create a database, but my only problem is how to store graphs in one. For now it looks like this `c.execute("""CREATE TABLE IF NOT EXISTS productivity ( todo_name text, habit_name text, timer_name text, timer_time time, xp_text text, xp_list ?, mood_list ? )""")` and I jusy don't know what to enter in places with question marks – ubant Nov 16 '20 at 19:37
  • I think you should then use prepared statements, but Python's SQLite libraries unfortunately don't have prepared statement so I think this thread here could help you out. https://stackoverflow.com/questions/5616895/how-do-i-use-prepared-statements-for-inserting-multiple-records-in-sqlite-using – IceJonas Nov 16 '20 at 20:17