#databases
1 messages · Page 162 of 1
oh wait. I have an idea
it seems that it can be connected to logger
lemme run it without logging ON
40 seconds seems like a very long time for a query like this
if you just run each query in a postgres client, how long does it take?
the problem with this is you don't know which part is taking 40 seconds
adding some of your own logging could help, not using the discord logger but create a new one for your app
i'm very new to logging...can you point me at any guide, or just the documentation will suffice?
and no, seems like not a logger issue, I was wrong. With logger section commented I still have to wait for a long time
the official docs are are OK, but not the best if you are totally new to it:
https://docs.python.org/3/howto/logging.html#logging-basic-tutorial
https://docs.python.org/3/howto/logging.html#logging-advanced-tutorial
https://docs.python.org/3/howto/logging-cookbook.html
it might be easier in your case to just print(time.perf_counter()) between each line and see which line takes the longest to execute
doing it
okay, now I have a bunch of numbers like
3 117.2003458
4 117.9515448
5 118.7009403
6 118.7010365
where 3,4,5 are queries to database and 6 is a function for counting hours
and queries from items 3,4,5 takes 0,5-0,7 seconds each
@bot.command()
async def top(ctx, count: int = 10):
result_list = []
#await ctx.message.delete()
db = await pool.acquire()
users_count, users_ids = await initial_db_read()
print(1, time.perf_counter())
checkrole = discord.utils.find(lambda r: ('СОКЛАНЫ' in r.name.upper()), ctx.guild.roles)
print(2, time.perf_counter())
for member in ctx.guild.members:
if member.id in users_ids and checkrole in member.roles and not (member.id == member.guild.owner_id):
gold = await db.fetchval(f"SELECT gold from discord_users WHERE id={member.id};")
print(3, time.perf_counter())
if int(gold) > 0:
warns = await db.fetchval(f"SELECT warns from discord_users WHERE id={member.id};")
print(4, time.perf_counter())
thirty_days_activity_records = await db.fetch(
f"SELECT login, logoff from LogTable WHERE user_id={member.id} AND login BETWEEN '{datetime.datetime.now() - datetime.timedelta(days=30)}'::timestamptz AND '{datetime.datetime.now()}'::timestamptz ORDER BY login DESC;")
print(5, time.perf_counter())
activity = await count_result_activity(thirty_days_activity_records, warns)
print(6, time.perf_counter())
result_list.append((member.mention, activity))
res = sorted(result_list, key=itemgetter(1), reverse=True)
print(7, time.perf_counter())
count = len(res) if count > len(res) else count
output = "".join(f"{i + 1}: {res[i][0]}, актив: {res[i][1]} часа(ов);\n" for i in range(count))
print(8, time.perf_counter())
embed = discord.Embed(color=discord.Colour(int('efff00', 16)))
embed.add_field(name='Топ активности', value=output)
await ctx.send(embed=embed)
await pool.release(db)```
ok, so we know it's not your queries. those are clearly fast
what about the difference between 2 and 3?
well, there are just quite many of them. The timer goes from 23 to 113+ while the function is being executed
1 44.2718655
2 44.2727759
3 44.7847913
4 45.2790097
5 45.7720971
this is the first sequence
after it ends I'll post the last
3 84.2718272
4 84.5214431
5 84.7721952
3 85.0218643
3 85.271848
this time it was faster
41 seconds
what do you mean "while the function is being executed"
oh, you do this in a loop
i want to know:
- is acquiring the connection slower?
- are the queries slower?
- is releasing the connection slower?
nvm, it seems I know the real reason...Someone else connected to the machine where my VM is situated and now overutilizing it
hah, there you go

so i just got a vps whats the easiest way to copy my db from my local machine to vps?
How can the cpu usage exceed 100% 
upload it...
dunno, someone decided to squeeze out everything it has I suppose...and maybe some CPU overclocking occurred.
oh
now, when the grip loosened my function executes in like less than a second
shared core VMs are like this, but they're too cheap to say no xD

right now I pay like $0,06 a month. the next cheapest VM instance will be $9,15 a month
feel the difference
1000% value
hello i have aws vps and i installed postgresql on it and i am trying to enable remote access to it but im getting error while connecting from my pc
https://linuxconfig.org/ubuntu-20-04-postgresql-installation/
i did these things as of now ^
is the db on the vps running?
you can lookup some guide, akaik you have to edit some files, as maybe the postgres server is only listening for localhost
by default it listens only localhost
https://www.linuxcloudvps.com/blog/how-to-install-postgresql-on-ubuntu-18-04/
personally I used this guide to setup mine
I just use json files lmfao
Free hosting
you need to run a server 24/7 to run a program 24/7. the easiest option is to use sqlite, because the database is just a single file, and you can store that file on the server where your python code runs
I have this code wit Mongo DB Atlas but getting this error ```py
@client.command()
async def setcountchannel(ctx, channel1):
try:
channel = client.get_channel(channel1)
to_store={
"_id": ctx.guild.id,
"game-channel" :111111111111111111,
"hc": 0,
"lost-name" : "None",
"highest-gon" : 0,
"type":"server-storage"
}
Collection.insert_one(to_store)
await ctx.send(f"{channel.mention} is been set as the counting channel.\nuse command =sc 1 to start the game")
except:
if channel == client.get_channel(channel1):
channel = client.get_channel(channel1)
result = Collection.find_one({"_id" : ctx.guild.id})
a = result["game-channel"]
prv = {"game-channel" : a}
a_up = {"$set":{"game-channel" : channel.id}}
Collection.update_one(prv , a_up)
else:
await ctx.send("an error ouccered") ```
error Ignoring exception in command setcountchannel: Traceback (most recent call last): File "c:\Users\Soham\Desktop\alphagamer bot\test.py", line 1297, in setcountchannel Collection.insert_one(to_store) File "C:\Program Files\Python39\lib\site-packages\pymongo\collection.py", line 705, in insert_one self._insert(document, File "C:\Program Files\Python39\lib\site-packages\pymongo\collection.py", line 620, in _insert return self._insert_one( File "C:\Program Files\Python39\lib\site-packages\pymongo\collection.py", line 609, in _insert_one self.__database.client._retryable_write( File "C:\Program Files\Python39\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write return self._retry_with_session(retryable, func, s, None) has no attribute 'id'
Yes....
^^
k
it’s been around for a while and has a lot of uses
@wheat swan what is Collection? where is it defined?
thank you for the help but the problem is solved
Hey @small wadi!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
why isn't this working
@client.command()
async def work(ctx):
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT money FROM main WHERE user_id = {ctx.author.id}")
result = cursor.fetchall()
if result == "Null":
cursor.execute(f"INSERT INTO main (money, user_id) VALUES ({random.randint(50, 100)}, {ctx.author.id})")
else:
cursor.execute(f"UPDATE main SET money = money + {random.randint(50, 100)} WHERE user_id = {ctx.author.id}")
db.commit()```
At first
it wouldn't add
then it would keep making new rows
even if it was me
so I would have like 5 of the things with my ID
now it doesn't do anything
Try doing if not result:
+1, "Null" doesn't mean anything in this case
if there are no results, result will be an empty list
also don't use f-strings for sql
https://docs.python.org/3/library/sqlite3.html ctrl-f for "Instead, use the DB-API's parameter substitution"
@torn sphinx ☝️
I did if result == "Null" or not result:
now it works sorta
my friend is helping me
btw thanks salt rock
- also don't reuse cursors for multiple queries
- don't use f-strings for putting data into sql queries
"Null"is just a string and it isn't what you meant; the result will never be"Null"
a better version might look like this:
@client.command()
async def work(ctx):
db = sqlite3.connect('main.sqlite')
cursor = db.execute(
f"SELECT money FROM main WHERE user_id = ?",
(ctx.author.id,),
)
result = cursor.fetchone()
if result is not None:
db.execute(
"INSERT INTO main (money, user_id) VALUES (?, ?)",
(random.randint(50, 100), ctx.author.id),
)
else:
db.execute(
"UPDATE main SET money = money + ? WHERE user_id = ?",
(random.randint(50, 100), ctx.author.id),
)
db.commit()
better still, if user_id is the primary key of your table (and it should be), you can make use of the database more effectively:
@client.command()
async def work(ctx):
db = sqlite3.connect('main.sqlite')
query = """
INSERT INTO main (money, user_id)
VALUES (:money, :user_id)
ON CONFLICT(word) DO UPDATE SET
money = money + excluded.money
"""
params = {'money': random.randint(50, 100), 'user_id': ctx.author.id}
db.execute(query, params)
db.commit()
this is called an "upsert" operation - update and insert in the same query. see here: https://sqlite.org/lang_upsert.html. note also the use of named parameters (:foo) as opposed to unnamed parameters (?)
edit: this will only work if you have the user_id column set to PRIMARY KEY
okay
thanks
I'll look into that
@client.command()
async def hunt(ctx):
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT boar FROM main WHERE user_id = {ctx.author.id}")
result = cursor.fetchall()
if result == "Null" or not result:
cursor.execute(f"INSERT INTO main (boar, user_id) VALUES ({random.randint(1, 3)}, {ctx.author.id})")
else:
cursor.execute(f"UPDATE main SET boar = boar + {random.randint(1, 3)} WHERE user_id = {ctx.author.id}")
embed = discord.Embed(
colour = discord.Color.random()
)
embed.add_field(name="You went hunting", value=f"You caught {random.randint(1, 3)} boar", inline=False)
await ctx.send(embed=embed)
db.commit()```
This is another thing I have
for some reason it's not doing anything
when I run it
i find that hard to believe, do you see an error message in the console?
do you understand what's wrong with result == "Null" at least?
uhhhh no?
"Null" is a string
it is text
it is not "special" in any way
fetchall never returns text
it returns a list of tuples containing data from the database
result == "Null" will always be False because it's a meaningless comparison
it's like asking if the color of your house is "shoe"
"shoe" is not a color
it is a piece of clothing
not result is the same as len(result) == 0 -- this is the actual comparison that you want to perform
!e py print(type("Null")) print(type(None))
@austere portal :white_check_mark: Your eval job has completed with return code 0.
001 | <class 'str'>
002 | <class 'NoneType'>
@harsh pulsar so it would be Null just with no quotes?
No, it should be not result
ok
Null is a type in js, sql but not in python
still didn't fix it
@client.command()
async def fish(ctx):
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT fish FROM main WHERE user_id = {ctx.author.id}")
result = cursor.fetchall()
if not result:
cursor.execute(f"INSERT INTO main (fish, user_id) VALUES ({random.randint(1, 3)}, {ctx.author.id})")
else:
cursor.execute(f"UPDATE main SET fish = fish + {random.randint(1, 3)} WHERE user_id = {ctx.author.id}")
embed = discord.Embed(
colour = discord.Color.random()
)
embed.add_field(name="You went fishing", value=f"You Caught {random.randint(1, 3)} fish", inline=False)
await ctx.send(embed=embed)
db.commit()```
i still find that hard to believe
how are you running this?
i would imagine that this produced an error in the console if it didn't return anything in discord
no error
Do you have an error handler?
I would also use a variable for random.randint(1, 3) otherwise the db insert/update can be different than the embed-output.
And which command/function are you changing/testing: hunt() or fish()?
Hello, I'm trying to get the delta between two timestamps, but unfortunately they are formatted differently:
2021-08-03 13:35:00+00:00
2021-08-03 13:37:00
Help me get these two minutes timedelta object! please :)
you have a timezone-aware timestamp and a timestamp that's naive. that's not really something you should calculate with each other. do you know which timezone the second timestamp is in?
also, from where are you retrieving the data? seeing as this is #databases
how to print each line of a .json file?
what have you tried already?
I'm getting my data from Alpaca's API, both of them are in the same timezone i guess
me?
Yes
nothing, i dont know where to begin lol
then you're looking for datetime.datetime.strptime to parse it for one:
>>> import datetime
>>> dt = datetime.datetime.strptime('2021-08-03 13:37:00', '%Y-%m-%d %H:%M:%S')
>>> dt
datetime.datetime(2021, 8, 3, 13, 37)
for the one with the timestamp, you can either split it off entirely, or parse and discard it
then you just need to subract the datetime instances from each other
the thing is, if you really want to print each line, that would basically just output the json file. do you not want to do any parsing of it?
so, ill explain what im trynna do
im lazy but i need to add "**" to EACH line. What im thinking is having it print each line + what i need to add, so it does it for me\
Which one of the timestamps should be inserted to strptime?
You mention adding it to the line, but that's not going to produce valid JSON, that is intentional, right? Or do you want to modify the JSON structure?
yes, i just want it to print out the line, + my added thing
like...
print(line + "this here")
So strptime takes two arguments:
- the string to parse
- a formatting string that determines how it should be parsed
The formatting string above works for parsing the stamp without timezone.
Actually now that I look at it a bit more closely, you can parse this with fromisoformat (since it's in a standardized form):
>>> datetime.datetime.fromisoformat('2021-08-03 13:35:00+00:00')
datetime.datetime(2021, 8, 3, 13, 35, tzinfo=datetime.timezone.utc)
>>> datetime.datetime.fromisoformat('2021-08-03 13:37:00')
datetime.datetime(2021, 8, 3, 13, 37)
To kill off the tzinfo on the first datetime object, you can use datetime.datetime.replace:
>>> datetime.fromisoformat('2021-08-03 13:35:00+00:00')
datetime.datetime(2021, 8, 3, 13, 35, tzinfo=datetime.timezone.utc)
>>> _.replace(tzinfo=None)
datetime.datetime(2021, 8, 3, 13, 35)
I found a nice article that explains working with files and has an example for reading each line in a file: https://realpython.com/read-write-files-python/#iterating-over-each-line-in-the-file that you can check out
Thank you! i'll try that
@torn sphinx where did you get the 0 from?
check the link I sent you. There's no 0 being passed there. Now that I think about it, I've never seen that being passed anywhere...
Ah yes, wonderful Windows, don't we love it.
I'll assume that the file is UTF-8 encoded, change the line saying
open("test.txt", 'r')
to
open("test.txt", 'r', encoding='utf-8')
Is there a way to use pd.apply just on the index of a dataframe?
in order to kill that tz with .replace
sorry, I have no idea of pandas :(
That's the problem i face, these timestamps are in a Dataframe as the index column, i wish to get rid of the tz in one of them... any idea?
hi, so i have an issue
ok so
i need to add a LONG list to a .json file
not numbers or anything
but words
100+
idk how ;-;
I am not sure if there's a better place to ask your question, but it's a bit off asked here.
Honestly, what I would do is load the json, add the list wherever you need to, then dump it again. 100+ words is like nothing
@faint bladeok so
im not trying to do it with a command
i need to add 100+ lines to a list in a .json file
but idk how
e.e
think i got it
lemme try sum
SyntaxError: EOL while scanning string literal
k
got it
Sorry, I really don'r know pandas :(
I got it i think! thanks anyway!
@ionic pecanhey
# Open file
fileHandler = open("data.txt", 'r', encoding='utf-8')
# Get list of all lines in file
listOfLines = fileHandler.readlines()
# Iterate over the lines
for line in listOfLines:
print( "**" + line.strip() + "**")
how do i add quotations to the printing?
without it messing up
i want it to be like... adding quotes, astrisks and the words
i have to ask... why would you want to remove the time zones?
!code @cosmic pollen you can ask for help, but you should use your own help channel. see #❓|how-to-get-help . also, please post your full code and the full error output as text if possible. see below 👇
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
thank you will keep that in mind
@cosmic pollen this channel is more for specific discussion about databases. for your kinds of questions, the helpe channels will be more useful.
how can i get just the boolean value from that
That record object acts like a dictionary-tuple hybrid
so record["exists"] or record[0] either works
i figured it out its return blacklisted_channel[0].get("exists")
if you want quotes inside of something use single quotes so ' "" ' line.strip() + ' "" '
i figured it out haha, thx
Because some have timezone and some don't, which makes it impossible to compare between them, i was able to do it using index.tolist(), then list comprehension on the index column
old_timestamps = df.index.tolist()
new_timestamps = [timestamp.replace(tzinfo=None) for timestamp in old_timestamps]
df.index = new_timestamps
@mint tundra in the future you can use df.index.tz_convert and df.index.tz_localize
also - wouldn't removing all timezone info just make the problem worse?
suppose I have a list of IDs and I want to fetch a record from a table that should not have those IDs. Is there any way to do this in mysql?
You can do something like this ```sql
SELECT * FROM table_name
WHERE id_column NOT IN (list_of_ids)
@lost echo
query = """
SELECT * FROM table_name
WHERE id_column NOT IN %s
"""
value = (101,102,103,104)
db_cursor.execute(query, value)
result = db_cursor.fetchall()
Like so? @austere portal
Yeah, that should work
alright, i'll test it out
oh yeah, that's obvious
def get_test_records():
query = """
SELECT * FROM requestitem
WHERE RequestItemId NOT IN %s;
"""
value = (101,)
db_cursor.execute(query, value)
result = db_cursor.fetchall()
return result
Traceback (most recent call last): File "D:\Coding Stuff\UpWorkStuff\li_bot_server\test_sql.py", line 81, in <module> print(get_test_records()) File "D:\Coding Stuff\UpWorkStuff\li_bot_server\test_sql.py", line 72, in get_test_records db_cursor.execute(query, value) File "C:\Users\maila\.virtualenvs\li_bot_server-uHVWTe_a\lib\site-packages\mysql\connector\cursor.py", line 568, in execute self._handle_result(self._connection.cmd_query(stmt)) File "C:\Users\maila\.virtualenvs\li_bot_server-uHVWTe_a\lib\site-packages\mysql\connector\connection.py", line 686, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "C:\Users\maila\.virtualenvs\li_bot_server-uHVWTe_a\lib\site-packages\mysql\connector\connection.py", line 573, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '101' at line 2
you have to manually add the ()
didn't work @austere portal
def get_test_records():
query = """
SELECT * FROM requestitem
WHERE RequestItemId NOT IN (%s)
"""
params = (101,)
db_cursor.execute(query, params)
result = db_cursor.fetchall()
return result
where? in query?
alright
works, thanks guys!
👍
Does anyone know how I can delete all null values and any whitespace
from my mongodb
The thing is all timezoned timestamps are in UTC so the timezone doesn't matter at all
that does make sense then
the +00:00 killed me, so i eliminated it first
semi-offtopic question, in case there are people who work with mongodb on arch linux - did you install it from site or from aur?
anyone know what postgres program this is? psql outputs this as a bunch of columns in a different format (is there a way to make it rows?)
@deft badge is responsible for the above, I assume 👀
this might be pgcli https://www.pgcli.com/
this looks sick, made my day
oh, you were asking where the screenshot came from, I didn't get your question
Is it bad practice to establish a new connection to my sqlite database every time I want to use it? (I'm making a discord bot) I've seen some examples of people instead creating a connection at runtime and using that for further queries. Should I use a single connection across all queries or is the way I'm doing it now fine?
Are you familiar with transactions in SQL?
Does the sqlite3 module have something like Cursor.transaction?
As far as I know, SQLite supports one transaction per connection.
So if you reuse the same connection, you basically can't use transctions -- it will be all over the place.
no
Well that sucks
Does postgres support more than 1 concurrent transaction on a connection?
this is psql
jump into psql, use \x to throw on extended mode, profit
have never seen this lol
but yeah it's just a psql shell on our prod Postgres with \x mode on
Not sure if it supports more than one concurrent transaction
Expanded display is on.

thank you!
All writes in SQL happens (or, well, should happen) inside a transaction. A transaction is a safeguard to only change data atomically (i.e. all at once, not in parts). In SQLite, when you perform your first write, a transaction is opened. Then you can either commit it (to actually make the changes) or rollback it (to undo the changes).
This prevents data from being partially written, which will create inconsistencies. For example, if you want to execute 6 cursor.execute(...) calls, and the third one fails with an exception, you'll be able to undo the first two.
So if you reuse the same connection, you won't be able to create separate transactions. So just create new connections as you need them: it doesn't take a long time, about 25 microseconds on my machine. The maintainer of aiosqlite (which is what you should be using if you use async/await) also advocates for this approach from what I understand
.so Does postgres support more than 1 concurrent transaction on a connection?
can i connect to a mysql database hosted on a website with python?
Awesome! That's really great to know. Thank you so much for such a thorough response too!
Just make sure to use transactions correctly. You'd want to do this:
Command transfer_money(user1, user2, amount ):
Inside the transaction:
execute(
"UPDATE balance SET money = money - :amount SET WHERE user_id = :user_id",
{"user_id": user1.id, "amount": amount}
)
execute(
"UPDATE balance SET money = money + :amount SET WHERE user_id = :user_id",
{"user_id": user2.id, "amount": amount}
)
send_message(f"Transferred {amount} from {user1} to {user2}")
```, not
Command transfer_money(user1, user2, amount ):
Inside the transaction:
execute(
"UPDATE balance SET money = money - :amount SET WHERE user_id = :user_id",
{"user_id": user1.id, "amount": amount}
)
Inside the transaction:
execute(
"UPDATE balance SET money = money + :amount SET WHERE user_id = :user_id",
{"user_id": user2.id, "amount": amount}
)
send_message(f"Transferred {amount} from {user1} to {user2}")
(let's ignore checking that there's enough money)
Thanks again. This really clears everything up!
sorry i misunderstood that
Has anyone had any experience with https://keydb.dev/ before? It seems to be a drop in replacement for redis, but much higher ops/sec
No, because PostgreSQL is meant to have a lot of connections at the same time.
Each connection refers to a process PostgreSQL has spawned, you should not share connections asynchronously back- and forth in your application. You should manage a connection pool and acquire, release connections from there.
right
So there is no other way for transactions other than creating a new connection?
You can start and end a transaction as many times as you want, but you can't have two different transactions on a connection at the same time
Got it, thanks
Oi lindas
Is there a way I can display the data from my database with the column names in SQL
can you be more specific
in general, you can usually get column names from the description attribute of a cursor, if the library is db-api compliant
!pep 249
so like in my select query how can I get the column names along with all the other data
try using the description attribute on the cursor like i said above
Ah thanks
Where can I get free ElasticSearch, mongodb, redis, mysql, mqtt server ?
how can I do input validation with sqlalchemy?
I am using sqlalchemy with graphene (a graphql framework)
but I need to validate input.
this does not come out of the box with graphene sadly
i have a code that is supposed to save a channel id associated with a server id and then when u use a diff command fetches that channel id based on the servers id using sqlite3, heres the code:
await client.wait_until_ready()
client.db = await aiosqlite.connect("suggest.db")
await client.db.execute("CREATE TABLE IF NOT EXISTS suggest (guild_id int, channel_id int, PRIMARY KEY (guild_id, channel_id))")
await client.db.commit()
@client.command()
async def stest(ctx):
cur = await client.db.execute("SELECT channel_id FROM suggest WHERE guild_id = ?",(ctx.guild.id))
res = await cur.fetchone()
if res is None:
suggest = 0
else:
suggest = res
if suggest != 0:
await client.get_channel(suggest).send(f"{ctx.author.mention}")
@client.command()
async def channelset(ctx, channel : discord.TextChannel):
await client.db.execute("INSERT INTO suggest (guild_id, channel_id) VALUES (?,?)", (ctx.guild.id, ctx.channel.id))
await ctx.send("done")```
the setup works and so does the channelset
but the stest command doesnt and it errors with this:
`Ignoring exception in command stest:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 93, in stest
cur = await client.db.execute("SELECT channel_id FROM suggest WHERE guild_id = ?",(ctx.guild.id))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 184, in execute
cursor = await self._execute(self._conn.execute, sql, parameters)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
result = function()
ValueError: parameters are of unsupported type
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: parameters are of unsupported type`
and idk how to fix it.
cur = await client.db.execute("SELECT channel_id FROM suggest WHERE guild_id = ?",(ctx.guild.id,))
try that
also are your value types correct?
ok so when i do that, suggest becomes the (channelid,) so then it cant rly fetch the channel to send stuff in it
`Ignoring exception in command stest:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 101, in stest
await client.get_channel(int(suggest)).send(f"{ctx.author.mention}")
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'`
okay
check your value types
also this
@client.command()
async def channelset(ctx, channel : discord.TextChannel):
await client.db.execute("INSERT INTO suggest (guild_id, channel_id) VALUES (?,?)", (ctx.guild.id, ctx.channel.id))
await ctx.send("done")
you put above to input the ctx.channel.id there, which i assume you did by mistake
and meant to do channel.id
wdym
wait
can you try this
await client.db.execute("INSERT INTO suggest (guild_id, channel_id) VALUES (?,?)", (ctx.guild.id, ctx.channel.id,))
for your channelset command (remove the comma for the stest one)
afaik this should fix it
ok
`Ignoring exception in command stest:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 93, in stest
cur = await client.db.execute("SELECT channel_id FROM suggest WHERE guild_id = ?",(ctx.guild.id))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 184, in execute
cursor = await self._execute(self._conn.execute, sql, parameters)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
result = function()
ValueError: parameters are of unsupported type
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: parameters are of unsupported type`
like this?
cur = await client.db.execute("SELECT, channel_id FROM suggest WHERE guild_id = ?",(ctx.guild.id))
ah ya that makes more sense
`Ignoring exception in command stest:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 101, in stest
await client.get_channel(int(suggest)).send(f"{ctx.author.mention}")
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'`
bruh
and it went back to having it be (channelid,)
i give up
wait
oh
i see now
you are doing int() on a tuple
so need to index the value
so it would be
await client.get_channel(int(suggest[0])).send(f"{ctx.author.mention}")
should work^
it did work but, whenever i reran the bot for some reason i would need to reuse the channelset command
wdym
ok so if i used channelset command
then used stest command it works now,
but
if i rerun the bot and try using stest command again
yeah, after the insert you did in that command, do await client.db.commit()
ah right ig i forgot that
like how you did for the CREATE TABLE IF NOT EXISTS
ya i see now
thanks man u have no idea how much this helped me @median wave.
i rly needed to switch databases for lots of systems in a bot of mine, now i can ditch json, i wish i knew better when i first started tbh
np 
there is 1 command left @median wave and thats a delete channel id command like to remove it from the database
@client.command()
async def sremove(ctx):
await client.db.execute("DELETE channel_id FROM suggest WHERE guild_id =?", (ctx.guild.id,))
await client.db.commit()
await ctx.send("done")```
I thought that would work ^
but it errors with this:
`Ignoring exception in command sremove:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 105, in sremove
await client.db.execute("DELETE channel_id FROM suggest WHERE guild_id =?", (ctx.guild.id,))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 184, in execute
cursor = await self._execute(self._conn.execute, sql, parameters)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
result = function()
sqlite3.OperationalError: near "channel_id": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "channel_id": syntax error`
hmm
yeah that is wrong
"DELETE FROM (table) WHERE (row) = ?", ((the row to delete from ))```
like this?
await client.db.execute("DELETE FROM suggest WHERE guild_id = ?", (ctx.guild.id,))
or at least i think its like that bc that seemed to work
thanks man
No? Didn't they revert that?
I'm having trouble getting profiling to work in MongoDB. What I'm doing is use test and then db.setProfilingLevel(2), after that I check the setting with db.getProfilingLevel() which returns:
{
was: 2,
slowms: 500,
sampleRate: 1,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp(1, 1628180999),
signature: {
hash: Binary(Buffer.from("b42dbb3f30979f696ece17acb4aef1be5a3b5188", "hex"), 0),
keyId: Long("6992299061030158341")
}
},
operationTime: Timestamp(1, 1628180999)
}
Then I do some random queries and inserts on a collection in the test db, then check the profiling logs with db.system.profile.find_one() and it returns None. The system.profile collection doesn't exist
What am I doing wrong?
https://www.python.org/dev/peps/pep-0249/ python thought of everything...
Is that for me?
no sorry
is there someone willing to help me with a python fueled sql based question in burrito? ❤️
Actually this is normal for other languages as well not just python
Hey so I'm completely new to python databases, what exactly do you guys use to make good databases?
What do you want a database for?
There’s many so what kind you need depends on what you want to do
I mean really just storing and accessing data that my code creates from user input
@gleaming cipher generally you don't want to build your own database, as it's a project in itself. if you want to store and access data in your code, your best bet is going with an SQL database, such as the built-in sqlite of Python, or PostgreSQL if you want to start out a little bit bigger
You can use the built in sqlite3 module to interact with sqlite databases
Hi, I'm using the built-in Sqlite3 module, and I'm running into an issue.
Line 109 is prompting this error, but I don't know why:
File "main.py", line 109, in <module>
sql_command("""SELECT * FROM discord_Web;""")
TypeError: 'str' object is not callable```
Okay thank you I'll look into that
how do i setup a search system where it checks if the message reacted to is the same as one of the ids in th DB and then check if the emoji that was reacted matches one of the emojis tied to that message id for my reaction roles module?
sql_command is a string, you can't call it. I think you meant crsr.execute("SELECT * FROM discord_web;")
hey, can someone help me do a query with 3 tables with sqlalchemy?
That was the issue. Now when I run:
db.commit()
rows = crsr.fetchall()
for row in rows:
print(f"row{[0]} row{[1]} row{[2]} row{[3]} row{[4]} row{[5]} row{[6]}")
db.close()
the print statement never runs because rowsis empty for some reason. Why is rows empty even though there are several data entries in the table its fetching from?
Yeah it shouldnt run
You need to call db.commit, eg db.commit()
Show your SQL query also
You don’t even have the correct syntax with the brackets so not sure why you would expect it to run
And that
I do have db.commit(), must've been a typo when translating it over here.
Could you elaborate? Aren't you able to print the index of a row by the element number and print that as an f-string?
Like:
print(f"row{[0]}")
that would print row[0]
I see my mistake... I was doing print(f"row{[0]}") and not print(f"{row[0]}"). Suttle, but simple mistake.
anyone had error pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it using pymongo with dpy
@commands.Cog.listener()
async def on_ready(self):
await self.client.change_presence(activity=discord.Activity(type=2, name='$help'))
channel = self.client.get_channel(872935199812513862)
try:
await channel.edit(name="Online-🟢")
print(Fore.CYAN + "[Status] Updated Status Channel." + Fore.RESET)
except:
print(Fore.RED + "[Status] Failed to Update Status Channel." + Fore.RESET)
pass
print(Fore.CYAN + '\n=======================\n{0.user} has connected to Discord\'s API\n'.format(self.client) + Fore.RESET)
guilds = self.client.guilds
dbguilds = []
for item in db.find():
try:
dbguilds.append(item['guild_id'])
except:
pass
for guild in guilds:
if len(dbguilds) == 0 or guild.id not in dbguilds:
try:
db.insert_one({
"guild_id": guild.id,
"prefix": [
os.environ.get('default_prefix'),
],
"premium": "False",
})
print(f"[{Fore.GREEN}+{Fore.RESET}] {Fore.GREEN}Added Server To Database. {Fore.RESET}({Fore.GREEN}{guild.id}{Fore.RESET})")
except:
print(f"[{Fore.RED}+{Fore.RESET}] {Fore.RED}Failed To Add Server To Database. {Fore.RESET}({Fore.RED}{guild.id}{Fore.RESET})")```
firing on `for item in db.find():`
How can I edit a row(that I got buy using fetchone()) as an tuple in a SQLite database?
Code:
# Buy stock command
@bot.command()
async def buystock(ctx, arg1, arg2):
user_id = str(ctx.message.author.id)
guild_id = str(ctx.message.guild.id)
cursor.execute(
"SELECT * FROM main WHERE user=? and guild=?",
[user_id, guild_id]
)
do_query = """SELECT * from main"""
cursor.execute(do_query)
valueCheck = cursor.fetchone()
if (valueCheck is None):
await ctx.send("You need to be registered in this server to use this command.")
elif (valueCheck is not None):
if (int(arg2) < 0):
await ctx.send("You can't buy negative shares!")
elif (int(arg2) == 0):
await ctx.send("You can't buy 0 shares!")
To edit the row within the database you'd use an UPDATE statement
UPDATE table SET col=val, col=val, col=val WHERE xxxx
With the WHERE xxxx being optional
ohh cool, can u send me a link or a tutorial? i have to use variables in the update statement btw
https://www.w3schools.com/sql/sql_update.asp seems good
ok, ty 🙂
idk if this is possible but need some help with mongo, I have the following document, and I want to make it so I can use $addToSet to add a value to one of the items in votes, but remove that item from all the other items in votes but have no idea how
{
_id: '872952643117518909',
questions: [
{ question: 'a', number: 1, dropDownInfo: [Object] },
{ question: 'b', number: 2, dropDownInfo: [Object] },
{ question: 'c', number: 3, dropDownInfo: [Object] }
],
votes: {
'1': [ '619284841187246090', '662697094104219678' ],
'2': [ '619284841187246090', '662697094104219678' ],
'3': [ '662697094104219678', '619284841187246090' ]
},
question: 'abc',
timestamp: 1628198528903,
finished: false,
channel: '812038854302892064'
}
in mongodb can I get all document's values of a key that is of type array
can any one tell me how to create store procedure from python?
Hey guys! I have a question about Django and setting up models...
This is probably pretty simple but I am having a mental block so help is appreciated. I have a discussion app which contains a Message model. I want to relate the Message to several other models (e.g. Video, Note, etc.).
I don't feel that it is right to add a field for each model onto the Message model but I want the messages to "cascade delete" when the parent object is deleted (e.g. if Video is deleted all related Messages should be deleted as well).
How can I accomplish this?
class Message(models.Model):
"""
Stores information pertaining to a message.
"""
sender = models.ForeignKey(
Employee,
on_delete=models.CASCADE,
null=True,
related_name='messages'
)
message = models.TextField()
parent = models.ForeignKey(
'self',
related_name='children',
null=True,
blank=True,
on_delete=models.SET_NULL
)
created_on = models.DateTimeField(auto_now_add=True)
# this seems wrong
# video = models.FK
# note = models.FK
# etc...
I am using django-tenant-schemas so I am concerned that generic fks would mess up my db on implementation.. Is there a scalable way to do this without generic fks?
#bot-commands
I am working with Django and am trying to migrate my User data from Postgres into another Django project running Postgres. Am I correct in thinking that datadump on auth would be the way to go for this? I want to transfer everything, included the passwords and permissions.
Hi, I've apt installed a postgres and pgadmin4. Now how do I connect the one to the other?
guys
I am struggling a big time to create an ssh tunnel to access a remote postgresql database through the command line
has anyone ever done that here?
How can I find the most common number in a column without using LIMIT?
What do you mean? It depends what do you want to limit 
How do I find the correct names of people who share the same PANUM with a specific ACNUM For example.
I have two tables, one table consists of PANUM Paper Numbers that isn't unique to individuals and multiple People can share the same PANUM but every individual has a unique ACNUM that is specific to them. I want to find the names of the People who share the same PANUM of the ACNUM 202 How can I write this out? The names of the ACNUM can be found in another table and both ACNUM is found in both tables. I hope that doesn't sound complicated
SELECT
ACADEMIC.ACNUM,
GIVENAME,
FAMNAME,
PANUM
FROM
ACADEMIC,
AUTHOR
WHERE
AUTHOR.ACNUM = 202``` This is what I got so far but it displays everything
@torn sphinx you aren't specifying any kind of condition for joining the academic and author tables. maybe you want this?
SELECT
ACADEMIC.ACNUM,
GIVENAME,
FAMNAME,
PANUM
FROM
ACADEMIC,
AUTHOR
WHERE
ACADEMIC.ACNUM = AUTHOR.ACNUM AND
AUTHOR.ACNUM = 202
or its equivalent
SELECT
ACADEMIC.ACNUM,
GIVENAME,
FAMNAME,
PANUM
FROM
ACADEMIC
JOIN AUTHOR ON AUTHOR.ACNUM = ACADEMIC.ACNUM
WHERE
AUTHOR.ACNUM = 202
usually JOIN and INNER JOIN are synonyms
or maybe you want something more complicated..
Hmm let me see rq
it helps if you clarify which table you want what data from
one moment plss and thank you
if you can upload example data to https://www.db-fiddle.com/ and provide example output, it'd help a lot
An online SQL database playground for testing, debugging and sharing SQL snippets.
site doesnt work
fixed
nvm
how do i upload my .db to the site
just example data would be fine. it's easier to see what's happening in that case anyway
you have to write CREATE TABLE and INSERT statements on the left panel
then you can write queries on the right panel
oh because I got the data from my Uni, but I will try my best
So this got the Name and etc. of the ACNUM 202 What I want is the names of those who share the same PANUM with ACNUM = 202 PANUM only exists within the table AUTHOR and ACNUM exists within both ACADAMIC and AUTHOR Names all exist within ACADEMIC
ok, it helps to know which columns are in which tables
Hey @torn sphinx!
It looks like you tried to attach file type(s) that we do not allow (.db). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a.
Feel free to ask in #community-meta if you think this is a mistake.
that's ok
i think i can help
first you need to get the AUTHOR row with your desired ACNUM, right?
SELECT
AUTHOR.ACNUM,
AUTHOR.PANUM
FROM
AUTHOR
WHERE
AUTHOR.ACNUM = 202
So
Table AUTHOR:
PANUM ACNUM
Table ACADEMIC:
ACNUM DEPTNUM FAMNAME GIVENAME INITALS TITLE
does this work? the condition is literally "where AUTHOR.ACNUM = 202 and where AUTHOR.PANUM is the same as ACADEMIC.PANUM"
SELECT
AUTHOR.ACNUM,
AUTHOR.PANUM,
ACADEMIC.GIVENNAME,
FROM
AUTHOR,
ACADEMIC
WHERE
AUTHOR.ACNUM = 202 AND
AUTHOR.PANUM = ACADEMIC.PANUM
I am trying to get the FAMNAME GIVENAME and ACNUM From ACADEMIC but only those who have the same PANUM as the individual with the ACNUM 202 since ACNUM are unique and PANUM are not
that gives an error
hold on
it says no such column
Spelling looks right
Yeah strange
it doesn't seem to work
Download research.db for free from ufile.io instantly, no signup required and no popup ads
thats the database file I am using
@torn sphinx you posted GIVENAME, did you actually mean GIVENAME or GIVENNAME?
I figured wat was wrong, you put ACADEMIC.PANUM but PANUM Doesn't exist within ACAMEDIC
I think it worked but just a slight problem
oh, i thought it was in both
oh... this is totally different then
ok, well we agree that this is the right way to get the desired author, right?
SELECT
AUTHOR.ACNUM,
AUTHOR.PANUM
FROM
AUTHOR
WHERE
AUTHOR.ACNUM = 202
Find the academic number and full name of academics who have written one or more papers with
Adam Kilg. Do not include Adam Kilg in the results. Do not include duplicates. Sort the results by surname and then first name in alphabetical order.
Yes
...is this homework?
practical exercises
well then i certainly can't do your homework for you
but i can suggest that you might need to join the table to itself
its not homework
we dont get graded on this
just to practice
how would I join the tables?
with JOIN?
well again, start with the table that you know has the desired PANUM in it
you can do a nested query
hmm
so like
JOIN ACADEMIC ON AUTHOR.ACNUM = ACADEMIC.ACNUM
This is more complicated then I thought
SELECT
ACADEMIC.ACNUM,
AUTHOR.PANUM,
ACADEMIC.GIVENAME,
ACADEMIC.FAMNAME
FROM
ACADEMIC
INNER JOIN AUTHOR ON AUTHOR.ACNUM = ACADEMIC.ACNUM
WHERE
AUTHOR.ACNUM = 202```
this produces all name of the ACNUM 202 Though I need it to produce those who share the same PANUM with ACNUM = 202
so close yet so far
today we mess with psycopg2... i wonder why they called their libpq wrapper psycho lol
haha
lmao
db = await aiosqlite.connect(...)
cursor = await db.execute('SELECT * FROM some_table')
row = await cursor.fetchone()
rows = await cursor.fetchall()
await cursor.close()
await db.close()
``` how do i create a table tho
and to execute how do i execute x
await db.execute(
"""CREATE TABLE some_table (
column_1 datatype
)""")
and commit() after it
some table being optional name?
alright tysm
https://sqlitebrowser.org/dl/ @ripe rapids
i have to download that for sqlite?
im so confused can i dm you after i eat dinner @remote plinth
no, but it can help you creating table/managing stuff easily
uh sorry i don't allow dms
oh ok ill ping you here after im done
@remote plinth how would i start a database connect bc db = await would raise cant be used outside a async function
!d asyncio.loop.run_until_complete
loop.run_until_complete(future)```
Run until the *future* (an instance of [`Future`](https://docs.python.org/3/library/asyncio-future.html#asyncio.Future "asyncio.Future")) has completed.
If the argument is a [coroutine object](https://docs.python.org/3/library/asyncio-task.html#coroutine) it is implicitly scheduled to run as a [`asyncio.Task`](https://docs.python.org/3/library/asyncio-task.html#asyncio.Task "asyncio.Task").
Return the Future’s result or raise its exception.
do you want a global db connection?
i mean add it as attribute to Bot
?? @ripe rapids
yes that would be alright
Bot already have a loop attribute then db = bot.loop.run_until_complete(aiosqlite.connect())
so db = that
yeh
ok ok
Hello, just a little dumb question (which may be seems dumb for you, I'm sorry), I'm a new french developer who wants to develop a game in an "Advance Wars" or "Fire Emblem" style with nothing but IDLE, DBBrowser and Aseprite
To create units, I decided to make a class "unit" with every stats (attack, defense, HP, etc...), and to put different type of units, and their stats on a database
To put the stats from the database to the object, I want to create a method that will take the id given at the object's creation and use it to give to the object the stats of the unit I (or the player) want
you subclass it right?
then self.loop
ok
ima try
@remote plinth and 1 more thing where would i create the table
when a command is ran or
await db.execute("create table...")
await db.commit()
``` just ^^
anywhere
i prefer making tables in gui apps
like ^^
alright alright
no, just make one table
for example a table for tempbans and another for prefixes etc ...
How can I get a mongodb latency with pymongo?
just execute a query like every other query you do
do you have exp with sql?
just started learning
@remote plinth can i ask something?
im so sorry for disturbing
How can I get a mongodb latency with pymongo?
...
cur.execute("SELECT vendor_id, vendor_name FROM vendors ORDER BY vendor_name")
print("The number of parts: ", cur.rowcount)
print(cur.description)
for row in cur:
print(row)
...```
awesome thank you
The print(cur.description) may need some work.
so how would i insert something
await db.execute("INSERT INTO my_table (column_1, column_2) VALUES (?, ?)", [column_1_value, column_2_value])
.execute(query, args_here)
colnames = [desc[0] for desc in cur.description] did it
each arg will replace the ? with it
the column 1 and 2 are the text you put in right the data
i don't understand 
where do i put the data i store
^^
you need sql exp before it ig
i learnt here https://sololearn.com
thats a list so can i do lists too
ill learn thk u!
there's a (?, ?) in the query it will get replaced with the values in the list in the args argument
oke
it workedd thk u sm
and
does rows = await cursor.fetchall() return a list @remote plinth
has any1 had this error? pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it, Timeout: 30s
internet has no answers for me, using dpy pymongo
list of tuples
each tuple is a row
yep just what i needed thk u
@remote plinth anything wrong
@commands.command()
@commands.is_owner()
async def blacklist(self, ctx, m: discord.Member):
cursor = await self.bot.db.execute("INSERT INTO blacklist (column_1) VALUES (?)", [m.id])
await self.bot.db.commit()
await ctx.send(embed = discord.Embed(description = str(m) + "has been blacklisted.", color = self.bot.theme))
anyways ima sleep
ping me with answer ima start learning sql with ur link that u gave me
How can I use the update statement on the userdbCheck variable?
Code:
# Buy stock command
@bot.command()
async def buystock(ctx, arg1, arg2):
user_id = str(ctx.message.author.id)
guild_id = str(ctx.message.guild.id)
cursor.execute(
"SELECT * FROM main WHERE user=? and guild=?",
[user_id, guild_id]
)
do_query = """SELECT * from main"""
cursor.execute(do_query)
userdbCheck = cursor.fetchone()
if (userdbCheck is None):
await ctx.send("You need to be registered in this server to use this command.")
elif (userdbCheck is not None):
if (int(arg2) < 0):
await ctx.send("You can't buy negative shares!")
elif (int(arg2) == 0):
await ctx.send("You can't buy 0 shares!")
Would userdbcheck = userdbcheck + 5 or f’{userdbcheck} blah blah’ work? You can do something similar if it’s a dictionary. userdbcheck[‘item to update’] = blah
Not familiar with that db but I hope you can figure it out from there
Yea, that’s what I want, but idk how to do that
Everyone says use the update system
Oh I see, what database are you using?
SQLite
Yeah, never touched it. Docs and find the update function and it’s formatting. Pass a variable that is the data you want. That var can contain the original value if need be.
Might be useful.
Is there any way by which I can emit an event in python socket.io server when a new row is added to a mysql table?
i wanted to know how i can use MongoDB
like for my master plan i have
So it can save Channel ID
for chatbot
how to install postgress on ubuntu?
do column_1 exists?
and the blacklist table
yes
c.execute("SELECT ID,guildID,name FROM players WHERE name REGEXP '(^|\D{1})536(\D{1}|$)' AND GUILDID = 760366380901728257")
sqlite3.OperationalError: no such function: REGEXP```
how do i setup a function in python for REGEXP
im currently using sqlite3 to pull data
it works in sqlite3 just not when i use it in python
nvm got it
nope it just doesnt even insert the data
when i made it print the list it just printed
[]
TY, i will definitely look at it
ok, what database do u have?
ok, are u using an app to browse the database? like this one:
No
ohhh
It's for my discord bot
ik
But not working
ok....
Showing error
are using a app to browse the database?
This
No
damn
I am not using any
code?
wait, how do u see the contents of the database?
But I don't use any app to see
did u face this error before?
so just rn?
Yep
ok for me, i use a app to browse the database. when i run the app and open the database it locks the db. so i have to keep the app closed and then run the code
mostly smth is using the db
idk
Yep
are using a hosting service?
@thorny field
yea
A vps
the bot is running right?
Waiting
Yep
and u are trying to run the code from ur computer?
No
ohh
so mostly hosting service probs?
like u get the error from the hosting service?
No vps
vps?
SQL error
hmm, send me a screen shot
@grim zephyr here a stackoverflow problem regarding ur problem: https://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database
@thorny field
yee
Well shall I open the db once and close it once
wdym?
ohh, yea
like stop the code and run it again
I have connected it in all the codes but didn't close
I got it
error: asyncpg.exceptions.InvalidCatalogNameError: database "test" does not exist
but i already made a db with that name
connection:
async def connect_database(self):
self.main_db = await asyncpg.create_pool(
database="test",
user="postgres",
password=self.secrets["POSTGRES"],
host="1234",
)
Alternately it connected when i supplied the db name to postgres the default one
but when im running queries ie:
SELECT * FROM guild
it throws this error: no table "guild" exists
These are all the tables inside postgres (the db)
u could clearly see theres a table called guild
is anyone able to give me a hand with a django rest serializer please? im trying to use simple_history to get historical data of models into my frontend but having some issues not being able to pass in the correct methods
what does sample_history actually doing? i'm looking into the documentation, but can you give a short explanation about when this package can be used?
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it, Timeout: 30s, Topology Description: <TopologyDescription id: 610ed726fc175b71b0a23e2a, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it')>]>
anyone encounter this error b4? using dpy and pymongo; nothing on the interent relating to dpy,
I'm having an issue with discord.py and asynpc:
async def db_conn():
bot.connection = await asyncpg.create_pool(
host="localhost",
user="postgres",
password="xxxx",
max_inactive_connection_lifetime=10)
async def getuserprofile(user):
conn = await bot.connection.acquire()
result = await conn.fetch("SELECT * FROM main WHERE discordid = $1", str(user))
return result
result is returning [] and empty list for some reason instead of the proper result. print(user) shows the right userid, everything works fine if I use individual connections although thats 5x slower than pools with asyncpg
Can you show the code that works?
I'm probably still going to make this for fun.. but just so I know is there a package that formats sql queries from psycopg2 to look like they do in psql? like i know i can do rowcount and fetchmany and description but it's really ugly and not in a pretty table like psql
Not that im aware of but should be possible with a couple lines of string formatting and loops
also different data types have different indentation 😫
db.execute("SELECT UserId FROM users WHERE UserId = \"%s\"", (userid)) is giving me error ValueError: Could not process parameters
can someone help me with that pls
but db.execute("SELECT UserId FROM users WHERE UserId = \"%s\""%(userid)) is working
you must use (userid,) to make it a tuple, otherwise it's just the same as userid alone
also, use '' instead of "" in SQL - though I don't think that you should need of it at all there?
hi there
How can i view the data tables in my sqlite3 database?
https://www.sqlite.org/schematab.html
SELECT * FROM sqlite_schema
Is it possible to make a bigint[] into a non list bigint in postgres? I'm currently storing a list of channels but the list seems to be having a problem so I'm going to separate the list items into separate entries in my table rather than making them a bigint[]
You can run an alter statement and change the data type
ALTER TABLE table_name
ALTER COLUMN column_name1 SET DATA TYPE new_data_type```
thanks
And don't forget the docs 
https://www.postgresql.org/docs/current/sql-altertable.html
So I tried sql ALTER TABLE data ALTER COLUMN countchannel SET DATA TYPE bigintand gotsql ERROR: column "countchannel" cannot be cast automatically to type bigint HINT: You might need to specify "USING countchannel::bigint". SQL state: 42804
try doing ```sql
ALTER TABLE table_name
ALTER COLUMN col_name TYPE current_data_type
USING col_name::new_data_type;
Hey, im trying to select manageable amounts of data from my database so it can be displayed on pages, in groups of 10. However, im getting duplicates, and the offset isnt doing what it should. Anyone seen this before, is there a known reason for this to happen?
SELECT USER, Level FROM Game.Players ORDER BY Level DESC LIMIT 20, 10;
After looking at the whole player list, instead of starting the the bottom of Level 14 and leaving off where it started, its starting at the top of the offset. The userid is in position 26, even though the offset is set to 30??
https://cdn.no1irishstig.co.uk/82mt1.png [20 Offset]
https://cdn.no1irishstig.co.uk/v0gtz.png [30 Offset]
As you can see the data isnt even what it should be
what is going on here?
why wont my data update?
after the update statement, it says it matched one but didnt update one
despite those two IDs being clearly different
i want to install greenplum on my job, but im dumb (currently using mariadb and suck at speed). is it worth the pain? inb4: decided to hire devops for this kind of jobs
@dark oxide what r u conding?
with pymongo's .find method can you provide multiple queries??
Hihi is there someone that can help me with some things related to microsoft access pleasee?
Hii! So I am using a SQLite database for my discord bot. In one of the commands I have used the update system with some variables. I am getting an error which idk how to solve
Code:
# Buy stock command
@bot.command()
async def buystock(ctx, arg1, arg2):
user_id = str(ctx.message.author.id)
guild_id = str(ctx.message.guild.id)
cursor.execute(
"SELECT * FROM main WHERE user=? and guild=?",
[user_id, guild_id]
)
do_query = """SELECT * from main"""
cursor.execute(do_query)
userdbCheck = cursor.fetchone()
if (userdbCheck is None):
await ctx.send("You need to be registered in this server to use this command.")
elif (userdbCheck is not None):
if (int(arg2) < 0):
await ctx.send("You can't buy negative shares!")
elif (int(arg2) == 0):
await ctx.send("You can't buy 0 shares!")
for name, column in zip(["mango", "megasoft", "elecar", "soulairlines", "givida", "planetmoney", "wallmall", "chickdonald's", "gamestart", "fuber"], ["mango", "megas", "ele", "soul", "givida", "pm", "wm", "cd", "gs", "f"]):
if (str(arg1.lower()) == name):
cursor.execute("""
UPDATE main
SET ? = ?
WHERE
user = ?;
guild = ?;
""", [column, str(arg2), user_id, guild_id]
)
db.commit()
Error:
Ignoring exception in on_command_error
Traceback (most recent call last):
File "C:\Users\becin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\becin\Documents\computer science\Python\Discord stocks game\bot.py", line 313, in buystock
cursor.execute("""
sqlite3.OperationalError: near "?": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\becin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\becin\Documents\computer science\Python\Discord stocks game\bot.py", line 87, in on_command_error
raise error
File "C:\Users\becin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\becin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\becin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "?": syntax error
Can any help me solve it?
SET ? = ? You cannot parameterize the column name, just the value being assigned.
but i need to set the column name based on the i variable of the for loop
@whole widget can u help me?
The library will not do that for column name or table name. Just the values. There's too much risk for injection at those points, if I understand the reason why.
ig, but i have to set it based on the for loop, so what do i do?
Guys I have made a command which is using a db but it always work for the first time and the second time I use it, it gives an error telling "database is locked"
You are pulling the entire row on the first query. I'd work with that to add the arg2 value to the correct column and then run an UPDATE which updates then entire table row with the columns explicitly named.
ohh, how do i do that? sorry i am a noob
Help!
delete the db, and try again?
I tried many times
Nothing from stackoverflow
i meant post ur question
Unfortunately I need to head out this second. userdbCheck is all of the columns of your table's row in the order they were created. You want to loop through that and the names (like you have already). Instead of updating the database though, you want to create a new list of values and when the name matches arg2 make sure to change that value.
That gets you a list of the updated table row which you can then use UPDATE to send back to the database and, since you're updating eveything, you won't have to use a variable for a column name.
Can I have some help
ok, the main confusion is how to update the row using a new list
i asked a question got answered in a day
Nice
Maybe I will try it
stackoverflow is pretty much google for devs
u should, there is nothing loose, right?
Well yeah I will try
Still this is making me mad
Why working for the first and not working for the second
yes. you didn't commit the database
can you send your code?
Ok wait a sec
yea i had similar problem. it was bcz i used an app to see my db and i ran the code while the app was open. but it fixed it 😅
Cool
To fix the data base is locked error you need to close all connections to the db
commit and close perhaps
Is there a journal file?
But won't just keeping a single connection to the DB and commiting it every time data is edited work? @austere portal
Yep
The data base doesn't get locked when a connection is made
When you insert data sqlite locks the database so when that is happening you can't do anything else until the database is unlocked
Hey @grim zephyr!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
Ah, yeah
If you don't have already, btw, make sure you have a single connection with your database within your code @grim zephyr
Instead of connecting to it everytime you need to use it
I am using it multiple times but have a single connection
So you connect to it everytime you need?
No
It's not a error in your code, it's just the limitations of sqlite
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
Okay, and what's the error?
Database is locked
Your code looks good
Well can I know which line?
It's not showing the line
SQLite is meant to be a lightweight database, and thus can't support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.
Python's SQLite wrapper has a default timeout value that determines how long the second thread is allowed to wait on the lock before it times out and raises the OperationalError: database is locked error.
If you're getting this error, you can solve it by:
Switching to another database backend. At a certain point SQLite becomes too "lite" for real-world applications, and these sorts of concurrency errors indicate you've reached that point.
Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.
Increase the default timeout value by setting the timeout database option
Yeah..
Look at the last paragraph @grim zephyr
Yeah
By the way, open SQLite and check if the Write changes button hasn't been pressed. If it hasn't, that could be the reason this is happening.
Looks like I need it switch
To another db
@torn sphinx
Hey bud
What db should I use
Postgres 🐘
I used SQLite and it worked fine.
If it isn't working, consider Postgres. It can handle more than SQLite and is good for storing a lot of data/good for big bots
By good I mean better than SQLite
Yes,


Well I need to host it right
Wym?
???
You can host it locally
It can be hosted locally like SQL
If you know how to use SQL, using PG shouldn't be too hard.
I need to host it using my computer switched on for 24 hrs right??
Oh that yes, you mean hosting the bot
No
Well, if you turn your computer off your bot will turn off
Huh?
I mean hosting the db
Hosting a DB? 
I am new to portgre
You don't need to keep it open
Noob
Wdym
Maybe go through the documentation 
How will it be online
It doesn't need to be running 24/7
Is it like mongo
Wdym?
I think it works, just like SQL works, it'll work even if the SQL application is closed on your PC
Since you are making a connection to it
no, but if you are locally hosting your bot and turn of your PC, it won't work then
because well of course it won't
are you hosting your bot?
Aight
virtual private server
ohhh
I know
So if I switch off my pc still the portgre will be running right
No
ok
@torn sphinx
Yes, do you mind not pinging so much and waiting for a response? 
Sry foor the ping 😅😅
It means it somehow works like mongo
Well a last question
Can u help
??
@torn sphinx sry for the ping but for the last time
is it possible for PortgreSQL to manage and update and store data of 8000 members
@grim zephyr maybe
You can also increase the timeout on the SQLite side
PRAGMA busy_timeout = 100; (is in ms)
Hi, I need some help. I have a products table with a parent_product column, this columns stores the parent product id, which is in the same table, but has Null in this column. How can I get this parent product with the data of its childs?. To get the parent product I do this query SELECT * FROM products WHERE parent_product IS NULL but I don't know how to do a JOIN to the same table
Also to clarify products can have a maximum of 4 childs. Child products can't have more sub childs products. I'm using mysql server, and for testing in local phpmyadmin. I want all products with all their children. All childs of a product have the parent product id in a column named parent_proudct.
In the image, column names are in spanish, but this is how a product would look. 2290 is the parent product, and 2291, and 2992 are subchilds. In practice they would not say Parent, Subchild 1, and Subchild 2.
[] makes it an array of bigint i think
CREATE TABLE contacts (
id serial PRIMARY KEY,
name VARCHAR (100),
phones TEXT []
);
INSERT INTO contacts (name, phones)
VALUES('John Doe',ARRAY [ '(408)-589-5846','(408)-589-5555' ]);
INSERT INTO contacts (name, phones)
VALUES('Lily Bush','{"(408)-589-5841"}'),
('William Gate','{"(408)-589-5842","(408)-589-58423"}');
SELECT
name
FROM
contacts
WHERE
phones [ 2 ] = '(408)-589-58423';
UPDATE contacts
SET phones = '{"(408)-589-5843"}'
WHERE id = 3;
whats the difference between bigint and bigint[]
with postgresql
why did you delete and repost that?
ppl make massive clunky code and dont use a mb
it's for you dude
whats best database for discord.py bots?
generally postgres is regarded as the best
generally a very solid choice in combination with the asyncpg driver
In relational databases you lay out data as tables and their connections. For example, you might have a table members with fields (id, name) and another table rooms with fields (id, name, capacity). If you want to store the members in a room, you'll have another table room_members with fields (room_id, member_id). This is the structure you would have (not actual syntax of anything, just a diagram):
# members
id | name
---+-------
1 | alice
2 | bob
3 | charlie
# rooms
id | name | capacity
---+------+----------
1 | foo | 3
2 | bar | 2
# room_members
room_id | member_id
--------+-----------
1 | 1
2 | 1
2 | 3
1 | 2
Then you can set up different constraints, such as:
"all id values in members are unique"
"all id values in rooms are unique"
"all room_id values in room_members refer to an id in rooms"
"all member_id values in room_members refer to an id in members"
"all rows in room_members are unique"
Yes, you could have another table like that, or just store those info in the members table
yeah
I recommend https://sqlbolt.com/ if you need a tutorial on SQL
what exactly are you referring to?
join
"foreign key" is probably what you need
Yes
I need help
It's best to state your question so when someone sees it they can help you out faster
await bot.db.execute("INSERT INTO Prefix(guild_id, prefix) VALUES ($1, $2)", (message.guild.id, DEFAULT_PREFIX))
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\asyncpg\pool.py", line 530, in execute
return await con.execute(query, *args, timeout=timeout)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\asyncpg\connection.py", line 299, in execute
_, status, _ = await self._execute(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\asyncpg\connection.py", line 1625, in _execute
result, _ = await self.__execute(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\asyncpg\connection.py", line 1650, in __execute
return await self._do_execute(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\asyncpg\connection.py", line 1697, in _do_execute
result = await executor(stmt, None)
File "asyncpg\protocol\protocol.pyx", line 183, in bind_execute
File "asyncpg\protocol\prepared_stmt.pyx", line 129, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions._base.InterfaceError: the server expects 2 arguments for this query, 1 ```
@median wave
Did you change the database module? Because asyncpg doesn't expect an iterable as second argument, but just for each substitution one argument, so in your case:
await bot.db.execute("INSERT INTO Prefix(guild_id, prefix) VALUES ($1, $2)", message.guild.id, DEFAULT_PREFIX)```
I think asyncpg is not PEP-249 conform.
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 979, in on_message
await self.process_commands(message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 975, in process_commands
ctx = await self.get_context(message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 886, in get_context
prefix = await self.get_prefix(message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 831, in get_prefix
ret = await discord.utils.maybe_coroutine(prefix, self, message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\utils.py", line 343, in maybe_coroutine
return await value
File "C:\Users\USER\Desktop\ZENESIS\PREFIX\bot.py", line 21, in get_prefix
prefix = [0].get("prefix")
AttributeError: 'list' object has no attribute 'get'```
Did you read the error?
I mean the line
am i supposed to use the recordobject
!e
print([0].get('prefix'))```
@jaunty galleon :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | AttributeError: 'list' object has no attribute 'get'
Depends on what you are doing
well can you tell me what should i do next as i am noob in db
You are trying to get the prefix from the db right?
async def get_prefix(bot, message):
if not message.guild:
return when_mentioned_or(DEFAULT_PREFIX)(bot, message)
prefix = await bot.db.fetch("SELECT prefix FROM Prefix WHERE guild_id = $1", message.guild.id)
if len(prefix) == 0:
await bot.db.execute("INSERT INTO Prefix(guild_id, prefix) VALUES ($1, $2)", (message.guild.id, DEFAULT_PREFIX))
prefix = DEFAULT_PREFIX
else:
prefix = [0].get("prefix")
return commands.when_mentioned_or(prefix)(bot, message)```
prefix = await bot.db.fetch("SELECT prefix FROM Prefix WHERE guild_id = $1", message.guild.id)```
`prefix` is a list with ig one value of Record object
So to get the record object, you need to do prefix[0],
And than .get('prefix')
ok
lemme try
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 896, in get_context
if message.content.startswith(tuple(prefix)):
TypeError: tuple for startswith must only contain str, not list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 979, in on_message
await self.process_commands(message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 975, in process_commands
ctx = await self.get_context(message)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 909, in get_context
raise TypeError("Iterable command_prefix or list returned from get_prefix must "
TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not list
@jaunty galleon
Show code
ok
import discord
from discord.ext import commands
import asyncpg
from discord.ext.commands.bot import when_mentioned, when_mentioned_or
DEFAULT_PREFIX = "!"
async def get_prefix(bot, message):
if not message.guild:
return when_mentioned_or(DEFAULT_PREFIX)(bot, message)
prefix = await bot.db.fetch("SELECT prefix FROM Prefix WHERE guild_id = $1", message.guild.id)
if len(prefix) == 0:
await bot.db.execute("INSERT INTO Prefix(guild_id, prefix) VALUES ($1, $2)", (message.guild.id, DEFAULT_PREFIX))
prefix = DEFAULT_PREFIX
else:
prefix[0].get("prefix")
return commands.when_mentioned_or(prefix)(bot, message)
bot = commands.Bot(command_prefix= get_prefix)
async def create_db_pool():
bot.db = await asyncpg.create_pool(dsn = "removed the link")
print("connected to database")
@bot.event
async def on_ready():
print("i am in")
@bot.command()
@commands.has_permissions(administrator = True)
async def setpre(ctx, new_prefix):
await bot.db.execute("UPDATE Prefix SET prefix = $1 WHERE guild_id = $2", new_prefix, ctx.guild.id)
await ctx.send("prefix updated")
token = 'token'
bot.loop.run_until_complete(create_db_pool())
bot.run(token)
ok one sec
ok
You need to do prefix = prefix[0].get('prefix') and than prefix would be the string
lol i though of doing this but just thought didn't do lol
hey nir my bot isin't responding
No error?
no
Try to add print statements in the get_prefix function
ok
<function get_prefix at 0x000002166D167F70>
async def get_prefix(bot, message):
print(get_prefix)
if not message.guild:
return when_mentioned_or(DEFAULT_PREFIX)(bot, message)
prefix = await bot.db.fetch("SELECT prefix FROM Prefix WHERE guild_id = $1", message.guild.id)
if len(prefix) == 0:
await bot.db.execute("INSERT INTO Prefix(guild_id, prefix) VALUES ($1, $2)", (message.guild.id, DEFAULT_PREFIX))
prefix = DEFAULT_PREFIX
else:
prefix = prefix[0].get("prefix")
return commands.when_mentioned_or(prefix)(bot, message)```
but what should i print
ok
@grim zephyr This is the code?
I think im gonna make my own cloud service business :)
well a part of the code
Send the line where you defined bot
He passed it correctly
i got it thanks @jaunty galleon
thanks @torn sphinx for trying to help me out
@torn sphinx
i have a question/
Wat?
Uh
approx
I don't know
more than 2000?

true
So you may have 100000+
https://www.postgresql.org/docs/12/limits.html maybe this would help?
and what about the guild ids
Guild ID in otherwr hand
Its around 8char
more than 10000?
Yeah, ik MB is not as big these day but they are still big in the world of only char
more than 15000?
last time plz
Probably
ok it means not sure right
@grim zephyr are you using cloud storage?
If no then maybw buy some SD or MICROsd card for 15GB+ storage
Definitely not a small portion of prefix and guildID
Is this channel also for SQL?
portgres
So you are using cloud?
yep
Did you just say JSON?
@grim zephyr i used to saved userdata in .txt file
How good is dynamic typing
(I don't know the terminologies)
I have a table with a foreign key (TableF) and null. I delete the item in TableF and I want to delete the item that it referenced. I tried to use delete cascade bu then the null constraint just stops it.
JSON sux
readLines()
writeLines()
Better
Someone will come to help you hopefully
I just don't know how to put it into google friendly words
Is asyncpg missing half the type hints, or is there an issue with my type checker? I'm using pyright
For example, when I do py async with pool.acquire() as conn: , conn's type is inferred as Unknown
is there any good way to task queue sqlite update/changes? I tried using aiosqlite but when there are multiple changes at the same time the 'databases is locked' still occur
Well which is faster mongoDB or PortgreSQL
mycursor.execute("SELECT * FROM Users")
for x in mycursor:
print(x)
the above code returns nothing
NoSQL databases are faster than SQL ones afaik
Are you sure that you have results in your table?
AioSQLite does queue changes, but it can't if you use multiple connections. You should be using one connections and sharing it
I see thanks
There are some race conditions when using transactions, but for many use-cases you will not be using transactions
Mysql is taking too long to execute my query
its like 1minute and its still executing my query
is there any problem with it
Well you're dropping a complete database, if this is big I would expect it to take a while. Especially if you have a slower disk.
There are stubs, gimme a second to find them
sql = "INSERT INTO Users ( id, wallet, bank ) VALUES (%s %s %s)"
what is wrong in this syntax
Add , between values
sql = "INSERT INTO Users(id, wallet, bank) VALUES (%s, %s, %s)"
Does anyone know how to use SQLite database for discord bot?
You create the database and connect to it
K
You can use the aiosqlite module, the built in sqlite module is blocking
How do I avoid asyncpg.exceptions.ForeignKeyViolationError: insert or update on table "nicknames" violates foreign key constraint "nicknames_guild_id_fkey" DETAIL: Key (guild_id)=(698223755582898207) is not present in table "guilds".by like, automatically inserting into the foreign table if not present