#SQL query trouble
1 messages · Page 1 of 1 (latest)
I have a command to check what the database contains
#verify data
@plugin.slash_command(name="verify-data", description="Verifies all data is stored correctly")
async def verify_integ(self, inter:CommandInteraction):
cursor.execute("SELECT * FROM Roles")
roles = cursor.fetchall()
cursor.execute("SELECT * FROM Users")
users = cursor.fetchall()
await inter.response.send_message(f"ROLES\n{roles}\n\nUSERS\n{users}")
Which spits out
But when trying to
@plugin.listener("on_member_update")
async def member_update(before:Member, after:Member):
beforef = [role.id for role in before.roles]
afterf = [role.id for role in after.roles]
removed_roles = set(beforef) - set(afterf)
cursor.execute("SELECT * FROM Users WHERE ? IN (roleids)", (str(list(removed_roles)[0]),))
users = cursor.fetchall()
print(users)
My output is []
# Database setup
connection = sqlite3.connect("data/database.db")
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS Roles (roleid INTEGER PRIMARY KEY UNIQUE)")
cursor.execute("CREATE TABLE IF NOT EXISTS Users (userid INTEGER PRIMARY KEY UNIQUE, roleids TEXT)")
connection.commit()
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
try printing
(str(list(removed_roles)[0])
1238702884774871161
I read somewhere you can specify in a column, I re-wrote this anyways and it works now
But also you are probably right
in doesn't check for substrings afaik
Oh, that's likely why it didn't find it then
mhm
it'd probably make more sense to use an array type there instead of a string anyways
Well, this bot could have just used json, I chose SQL simply to learn it
I chose SQL simply to learn it
very valid
I thought you couldn't do that
I'm storing the roleids like id;id;id;id etc
mm I'm not exactly sure about mysql because I never use it
could be mysql can't make arrays ig
I'm using sqlite3
I'm now just adding eye candy (embeds)
welp postgres for the win ig
It also can't use REPLACE which would have been super useful
Because instead of selecting, then editing I could have just edited
Oh on another note, how do I actually write code for a user installed app, if that's even possible yet
not supported by disnake yet outside of some PR
PR?
pull request
So it's probably going to be added soon
Alright, thanks again
I don't actually know how to close this forum
but yeah in the meantime something like this can be manually done
#general message
/solved or something along those lines