A
A
Andrew2021-02-25 17:59:14
Python
Andrew, 2021-02-25 17:59:14

How to create a new record in a table?

So the thing is: I just recently started with databases and it is necessary that when a player enters
the server, a separate entry in the table is created for him

@commands.Cog.listener()
    async def on_member_join(self, member):
        conn = sqlite3.connect(f"Servers.db")
        cursor = conn.cursor()
        cursor.execute(f"""INSERT INTO '{member.guild.name}'
                          ('{member.name}')
                       """)
        conn.commit()

That is, a completely new record must be created that was not specified when the table was created. Is this possible to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2021-02-25
@Mikyc

How to create a new record in a table?

Here are the docks on the SQLIte library for Python
cursor.execute(f"""INSERT INTO '{member.guild.name}'
                          ('{member.name}')
                       """)

You lost VALUES and column names:
INSERT INTO table (column1,column2 ,..)
VALUES( value1,	value2 ,...);

and if you make a public bot, how to save, for example, warnings for each ds server? I just wanted to make levels.

Use relationships, google FOREIGN KEY, MANY TO MANY, etc.
There is a lot of information here, get used to the English language)

S
Sergey Gornostaev, 2021-02-25
@sergey-gornostaev

it is necessary that when a player enters the server, a separate table is created for him

Not necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question