Answer the question
In order to leave comments, you need to log in
How to separately display each value from the database?
There is a table with columns:
Id ║ UserId ║ DateAdded
If I display all the values using SELECT *, I will get tuples:
(1, 524914064653025280, 2021-07-07)
But I need to make the bot display the data in this format:
Please, tell me how this can be implemented. Available code:
async def sqlselectall(ctx, arg):
try:
result = ' ║ '.join(name[1] for name in cur.execute(f"PRAGMA table_info({arg})"))
result2 = ' ║ '.join(f'{val}' for val in cur.execute(f"SELECT * FROM {arg}"))
emb = discord.Embed(
title = f'{result}',
description = f'{result2}',
color = 0xdb7dbc
)
await ctx.send(embed = emb)
except Exception as e:
emb = discord.Embed(description = f'**{e}**', color = 0xff0000)
await ctx.send(embed = emb)
Answer the question
In order to leave comments, you need to log in
The result of executing select in the cursor, like fetchall(), returns not just a tuple, but a nested tuple, i.e.
((ряд1значение1, ряд1значение2, ряд1значение3... ), (ряд2значение1, ряд2значение2, ряд2значение3... ), ...)
result2 = '\n'.join(' ║ '.join(f'{val}' for val in row) for row in cur.execute(f"SELECT * FROM {arg}"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question