Is there any way to create different tables in SQLITE3 through the same python function?

Asked

Viewed 92 times

0

I’m creating a python bot through the python-Telegram-bot library, and it works through commands. I know that through 'cursor.execute()' I can create a table via python, but the real question is: is there a way to create different tables every time I call a function?

def criarnovarodada():   
     cursor.execute("""
CREATE TABLE rodada1 (id, rodada, texto, autor);
""")

ready, I created the cursor.execute, now I would like to create a table called "rotate2", but using the same function "createsall". How to proceed?

1 answer

0

Just go back to the basics of programming and use function parameters:

def criar_nova_rodada(numero):
    cursor.execute("CREATE TABLE rodada{} (id, rodada, texto, autor);".format(numero))

Thus:

criar_nova_rodada(1)  # Cria rodada1
criar_nova_rodada(2)  # Cria rodada2

But you probably don’t need to do that. Hardly an application needs this dynamic table creation. I recommend that you review the structure of your bank, as it is almost certain that you are not making the best solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.