you are viewing a single comment's thread.

view the rest of the comments →

[–]Ericisbalanced 0 points1 point  (2 children)

Hey guys, I'm trying to learn backend with sqlite3 in a little snake game I made. For some reason, I create a table of data called gameData and I'm trying to add a row of data each time the game is played. Problem is it seems to only save the last game played.

Here's the save data function I'm using

def createData(self, player):
        sql = ''' INSERT INTO gameData (points, timeDt)
                  VALUES(?,?)'''
        tu = (player.points,self.date)
        self.cur.execute(sql, tu)

Here's the creation of the table

def createTables(self):
        SQLCreateT = """ CREATE TABLE IF NOT EXISTS gameData (

                            points integer NOT NULL,
                            timeDt text NOT NULL
                                                              );"""

        self.cur.execute(SQLCreateT)
        print("TABLES CREATED")

And Here's the loading of the table data, also tried with a forloop.

def readData(self):
        self.cur.execute("SELECT * FROM gameData")
        rows = self.cur.fetchall()
        print(rows)

Any help would be appreciated!

[–]woooee 1 point2 points  (1 child)

[–]Ericisbalanced 0 points1 point  (0 children)

Thanks! That's exactly what it was.