A
A
Arem Developer2020-10-23 22:03:18
Python
Arem Developer, 2020-10-23 22:03:18

How to compare data from a table with null?

Tell me how you can compare the data from the table with zero
. There is such a code:

@bot.command(aliases = ['warn'])
async def __warn(ctx, member: discord.Member = None, arg: int = None):
  print('1')
  if member is None:
    await ctx.send('Пользователь')
    print('2')
  elif arg is None:
    await ctx.send('Причина')
    print('3')
  else: 
    for i in cursor.execute("SELECT Wreason FROM users WHERE id = {}".format(member.id)).fetchone():
      if i == 0:
        print('4')
        cursor.execute("UPDATE users SET warns = warns + {1} WHERE id = {}".format(member.id))
        cursor.execute("UPDATE users SET Wreason = Wreason + {} WHERE id = {}".format(arg, member.id))

Condition: if the number from the table is 0, then we change the value in the warns and Wreason tables

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2020-10-24
@delam0re

Instead of

for i in cursor.execute("SELECT Wreason FROM users WHERE id = {}".format(member.id)).fetchone():
      if i == 0:
        print('4')
        cursor.execute("UPDATE users SET warns = warns + {1} WHERE id = {}".format(member.id))
        cursor.execute("UPDATE users SET Wreason = Wreason + {} WHERE id = {}".format(arg, member.id))

Use SQL Syntax Directly
cursor.execute("UPDATE users SET warns = warns + 1, Wreason = {} WHERE id = {} AND Wreason = 0".format(arg, member.id))

Updates the users table for the given user (increases the warning counter by 1, puts in a new reason for the warning), if Wreason = 0 before.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question