1
@client.command()
async def tag(ctx, tag):
    sql.execute(f'select tags_name from tags_list')
    does_exist = sql.fetchone()
    print(does_exist)

    if does_exist is not None:
        sql.execute(f'SELECT tags_content FROM tags_list')
        final = sql.fetchall()
        await ctx.send(final[0])
    else:
        await ctx.send(f"Tag named `{tag}` doesnt exists!")

So the code you see up there is used to get content from the table tags_list.

enter image description here

And the image up there is the table tags_list. I am trying to get tags_content when I call the command. But for example when I call the command like .tag test, I want it to give me test because they are in the same row. But instead, it gives the tags_content from the first row. So it gives h instead of test. How can I specify the row I want to get the content from?

Edit: This is what I get when I run the command .tag test: ('h',)

5
  • you have a method named tag and it has an argument named tag (not a good idea..) What does the code do with the tag argument? Commented Nov 7, 2020 at 20:23
  • @balderman tag is equal to tags_name in the database and it should send the content of tags_content. it works as I said in the question. Commented Nov 7, 2020 at 20:38
  • As far as I understand the tag argument is not part of the sql query. Is that correct? Commented Nov 7, 2020 at 20:39
  • @balderman yes, it doesn't exist in the database. it's only for the command Commented Nov 7, 2020 at 20:42
  • I think you need to have 1 sql query: select tags_name,tags_content from tags_list where tag_name = <your tag> - isnt it? Commented Nov 7, 2020 at 20:45

1 Answer 1

1

When you're selecting a row from a SQLite table, you can use WHERE to specify the row that you want. For example:

SELECT tags_content FROM tags_list WHERE tags_name='test'

So you can use tag parameter to specify tags_name when you're selecting the row.

@client.command()
async def tag(ctx, tag):
    sql.execute(f'SELECT tags_content FROM tags_list where tags_name = "{tag}"')
    final = sql.fetchone()
    if final:
        await ctx.send(final)
    else:
        await ctx.send(f"Tag named `{tag}` doesnt exists!")
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, this worked. but it worked when I changed it into SELECT tags_content FROM tags_list where tags_name = "{tag}".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.