#databases
1 messages · Page 155 of 1
First you had INSERT/UPDATE now you have no cursor for the result you check and want to DELETE a row which does not exists in the first place? What exactly do you want to happen and when?
I have a table called groups in postgres and every group name is not unique
I've to create unique join links for every group
using the PK the sequence would make the link abc.com/group/32
ok so i set a welcome channel and a welcome message , but when the owner doesn’t want it anymore , i want to add a cmd where it removes it
ad_messages_2 = self.bot.db.Ad_Messages.find()
for each_message in ad_messages_2:
message_dict[each_message["ad_name"]] = ["ad_message"]
print(ad_messages)
for each_message in ad_messages_2: TypeError: 'AsyncIOMotorCursor' object is not iterable
There are stuff in the database
But I don't know why the object isn't iterable
Hello, how do I retrieve a bytea field with Postgres using Django's ORM? Do i have to use a Binary field?
Use inspect db command
It will auto create ORM models for all tables in the targeted db
I am a bit good in Python, Now what should I learn for Databases
there are a lot that's why am confused:
MySQL
SQL
SQLIGHT
PostgreSQL
etc....
what should I learn??
Sqlite is very often used in the beginning
Then postgresql as main database for all types of tasks
After that people usually learn mongodb at the moment. As nosql choice
learn sql first
you can use sqlite if you want to put what you learn into action
as suggested above
Uh yeah. I missed to see sql in your choice fields
SQL language should be learned first.
Then it can be complemented with ORM language
what's an ORM language, like Python?
Basically yeah
ORM is a... thing allowing to work with database from normal programming language, having database described in your code as classes
Quite making things easier
Especially with migrating tools
ooh
so steps are:
- learn SQL
- learn SQLIGHT
- postgresqll
I am already doing general programmes in Python, just basic input output codes
SQLalchemy library allows ORM approach in python
With addition of Alembic to make auto migrations
where should I add SQLalchemy in the steps
ay,
I appreciate the help
It's more clear now on what should I do in order , makes stuff easier when planned
👍
In Django's shell?
Nvm I found how: python manage.py inspectdb > models.py
What should I use instead of MongoDB with dpy?
Postgres
hmm
SQL.execute(f'ALTER TABLE Account RENAME COLUMN diamond TO gem')
Error: sqlite3.OperationalError: near "COLUMN": syntax error
do you actually have a column called diamond
MongoDB
I am querying a collection with ref.aggregate([{"$set": {"coordinates": "test" }}]) however it does not add the coordinates field to the DB but I can see the coordinates field if I print the returned cursor as a list. What's going on here?
https://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905
pretty much anywhere
Amazon.com: The Manga Guide to Databases (0689145719055): Takahashi, Mana, Azuma, Shoko, Trend-Pro Co., Ltd.: Books
in the last year they made even about Machine Learning
Crazy, huh?
Neural nets for little kids, woohoo)
Manga isnt for kinds tho? 
Would you like me to suggest some seinen manga?
Hmm okay
Well, sure
if this particular manga has any suggestive magerial... it is not intentionally in my opinion
Japaneese people are just over open about it
So some level of it would be anywhere in any manga
But in general those manga guides are kid friendly ones
The tokyo ghoul manga was pretty good
i tried watching it, it was really bad one
the *** scenes were better in the manga 
you didnt like tokyo ghoul?
Maybe you started in the wrong order

it had too many snots in it. with a lot of crying / denial and e.t.c.
well heres a list of
some 'kids' manga that you were talking about
https://myanimelist.net/anime/934/Higurashi_no_Naku_Koro_ni
https://myanimelist.net/anime/22535/Kiseijuu__Sei_no_Kakuritsu
https://myanimelist.net/anime/339/Serial_Experiments_Lain
https://myanimelist.net/anime/10620/Mirai_Nikki_TV
Keiichi Maebara has just moved to the quiet little village of Hinamizawa in the summer of 1983, and quickly becomes inseparable friends with schoolmates Rena Ryuuguu, Mion Sonozaki, Satoko Houjou, and Rika Furude. However, darkness lurks underneath the seemingly idyllic life they lead. As the village prepares for its annual festival, Keiichi lea...
All of a sudden, they arrived: parasitic aliens that descended upon Earth and quickly infiltrated humanity by burrowing into the brains of vulnerable targets. These insatiable beings acquire full control of their host and are able to morph into a variety of forms in order to feed on unsuspecting prey. Sixteen-year-old high school student Shinich...
Lain Iwakura, an awkward and introverted fourteen-year-old, is one of the many girls from her school to receive a disturbing email from her classmate Chisa Yomoda—the very same Chisa who recently committed suicide. Lain has neither the desire nor the experience to handle even basic technology; yet, when the technophobe opens the email, it leads ...
Lonely high school student, Yukiteru Amano, spends his days writing a diary on his cellphone, while conversing with his two seemingly imaginary friends Deus Ex Machina, who is the god of time and space, and Murmur, the god's servant. Revealing himself to be an actual entity, Deus grants Yukiteru a "Random Diary," which shows highly descriptive e...
But we should probably take this to OT
hello
I personally, woudnt want my child reading these 😔
And then theres doujinshi 
i do
it is absolutely awesome one)
I liked that
Guilty Crown is not bad too
Code Geass
!ot 👏 This probably wants to go to ot
Off-topic channels
There are three off-topic channels:
• #ot0-fear-of-python
• #ot1-this-regex-is-impossible
• #ot2-the-original-pubsta
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
can you show your full code?
oh
this might be because of the sqlite version python uses
1 sec
it is from my bot's db, i just wanna rename a field
can you do print(sqlite3.sqlite_version) and tell me what it says
3.22.0
you basically have to create a temporary table
copy the table data to the temp table
drop the old table
re-make the old table with the renamed column
transfer data back
delete temp table
or well
just rename the temp table to the old table name
if db browser does it automatically for you then stonks indeed
otherwise it might just expect rename to exist
you are on a reasonably old version of sqlite though
what os r u on?
windows rn
yikes
Works!
nice
i run the same command on db browser lol
it'll likely do the temp table stuff for you for older versions
noted!
@brazen charm i had another question
sup?
sup
any replacements for import mysql.connector
because this one is filled with problems
i am looking for database migration from mysql to oracle
somebody out there who knows?
where statement isn't returning anything
SELECT * FROM passwd WHERE `host` = 'paypal';
when i execute that from shell it returns values
but from python no luck
well what's your python code
Hey guys!
I need in the cloud DB hosting. For 1 short script which was written using MySQL.connector.
I need to get a host. And after I would like to create a user and make some requests.
Probably somebody can recommend me.
I need in the host.
i think nobody has done mysql to oracle migration before
cursor.execute("SELECT * FROM table_name WHERE Id=1;")
qs = cursor.fetchone()
print(qs)
> (1, 'test')```How can I convert the query set into a `dict` like `{column_name: value}` in my case ```py
{'id': 1, name: 'test'}```
what database library? the db-api specifies a cursor.description attribute that has column names in it https://www.python.org/dev/peps/pep-0249/#description. some libraries also let you customize how the "row" object is created, e.g. https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.row_factory
The data base library is psycopg2
the general solution that should work with all db-api/pep-249 compliant libraries is:
cursor.execute("SELECT * FROM table_name WHERE Id=1;")
column_names = [desc[0] for desc in cursor.description]
qs = dict(zip(column_names, cursor.fetchone()))
in psycopg2 you can write desc.name instead of desc[0] as per https://www.psycopg.org/docs/extensions.html?highlight=description#psycopg2.extensions.Column
you could also make your own cursor subclass to always implement this behavior https://www.psycopg.org/docs/advanced.html#subclassing-cursor
Thanks
note that this doesn't handle the case where 0 rows are returned... you'll need to check for None first
Thanks, I'll keep that in mind 
Can someone here please teach me how to use MongoDB database with my discord bot code
data = await conn.fetch('''SELECT * FROM some_table WHERE id = ($1) AND name = ($2)''', 1, "Bartick Maiti")
These are the placeholders(at least for asyncpg)
Hello
(Sqlalchemy Question)
I want to know if there is a Sqlalchemy command which allowed me to insert a new entry (Table => two columns) but at the same time, return value indicating if that pair already existed in DB? (And even if it's existed, I went in to be inserted too)
Note: using constraint is not sufficient since it will raise an error without inserting that value again, but I want that pair to be duplicated in the DB.
Btw: I can type one comment to insert and another one for query(.filter), but I'm looking for a better method if available.
Thank you
How do I insert a list like this: ['hi 1', 'hi 2', 'hi 3'] in python with sqlite?
Hi pls help me with C#
use json.dumps before saving to the database, then use json.loads to read the data back into python
sqlite has a native json type, json1, and you can use various json functions to process the data in sql queries https://www.sqlite.org/json1.html
I need some help with connecting remotely to a postgresql server. I changed the ph_hba.conf file to allow all connections and the postgresql.conf to listen to all addresses but it still wont work. Can someone help?
Hi, How to make the connection in mysql have timeout
Hey @dense barn!
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:
Am i doing anything wrong? It says the interaction failed. Also the result prints None.
https://paste.pythondiscord.com/subazibigi.py
I can say that it exists in django ORM at least
Class.objects.get_or_create, update_or_create and e.t.c.
Is anyone able to help with a mongodb query?
i believe elemmatch should be returning only the object with the symbol matching
but why is it returning the whole thing
Thank you ,
This is really helpful😁
guys can you suggest a yt tutorial or website wherin i can get complete info on decomposition of relations(Normalisation) in database management system?
I have my connection pool setup as:
bot.db = bot.loop.run_until_complete(asyncpg.create_pool(url)), it works perfectly fine. But when I moved my url to .env it suddenly displays ValueError: invalid DSN: scheme is expected to be either "postgresql" or "postgres", got ''
Any clue?
The error gives the clue @ripe matrix
Your getting empty string back from env
So make sure your loading it properly.
I see, I'm not sure if I'm loading it right or not
bot.db = bot.loop.run_until_complete(asyncpg.create_pool(DB_URL))```
In my .env I have DATABASE_URL = user="postgres", password="a", host="127.0.0.1", database="dbname"
How to connect to my 🖥 DB Table using my mother's 🖥
do ping me here if u get em
You can use this library to read from env file https://pypi.org/project/python-dotenv/
Also its better to store your variables separately as opposed to a single value. Then build the connection url in your py file
The book by CJ date should cover it if you want the theory side. #databases message
For videos you might just have to browse and find one that you can understand.
hello
its present in another book
could you please provide link for that?
Forms and All That Jazz, which is a companion to the present book─see Appendix G)```
this is what is mentioned in that book
maybe this is not the place, but should DAO classes be table dependant?
i mean, if i got say a relation X to Y, id suppose i need a DAO for X, a DAO for Y, but also a DAO for X related to Y?
What about holidays?
Dm me
Depends how the relation is. For example let’s say you have a Roles table and Users table. The roles are assigned when the user is created. So I would just add it to the user dao.
but say i got a user and tags tables, when i tag an user, i have to relate the tag to it, so in that case the relationship gets formed by the tag dao, but if say i delete that user and the tag ends up with no relations, i want to delete that tag
where does that piece of logic go in the whole structure?
clearly it should not be in the user dao logic, but how far up?
it seems to me that if i don't have a user-tags dao i would be handling database logic in the api level
but now again, having a user-tags dao seems like im exposing db implementation
in the same sense, imagine if i delete a tag i also want to delete all users associated with it
so in that case, i would need all daos to know about all the db implementation, right?
Not all the db, just the tables it needs to manipulate.
What’s the relationship type anyways?
sorry, let me rephrase
theres 8 tables: categories, tags, users, lists, and (fk -> fk) users-to-categories, tags-to-categories, tags-to-users, lists-to-users
some deletions are on the db level, if you delete an user it deletes that relation, that kind of thing
but i also want to, say i delete tag X, i want to delete all users associated to it if they are not associated to other tags
i also want to delete tag X if its not associated to anything, say i delete all users associated to it, it should go too
i want to have the possibility to use different dbs, so im implementing an abstraction layer between the controller logic and the actual db logic
but im having issues understanding what goes where
mutes.update_one({"_id": ctx.guild.id}, {
"$unset": {str(member.id): ""}})
This is how I delete a field from a documentation right?
@torn sphinx sorry had to go in a meeting so couldn’t respond. But the goal of what your doing is for easier maintainability. Pick whatever you find easier to read and maintain.
I would make a separate layer that deletes the tags, and just call the method in when you delete the user.
Problem MySQL Databse in Python
Code in Python:
cursor.execute("SELECT * FROM tblUsers WHERE userID=%s", (1)) # userID is an interger so userID='%s' does not work
cursor.fetchall() #returns None, although there is an entry where userID == 1
# I think you have to put something different than %s but after some google searching I didn't find anything
@errant arch can you try this? I added a conma after the 1 so it’s a tuple.
cursor.execute("SELECT * FROM tblUsers WHERE userID=%s", (1,))
cursor.fetchall()
also cursor.fetchone() should be fine.
Works thx 😄 Thought it would be a little bit more complicated 😂
Yeah the parameters should be passed as an iterable. So a tuple or list or dict works.
no problem
My question is the following:
# Controller level
def delete_user(user_id: str):
self.user_dao.delete_user(user_id)
class UserDaoSQL(UserDAO):
def delete_user(user_id: str):
# sqlite logic to delete user
If a tag ends up orphan, i should delete the tag, so somebody here needs to query the Tags table, and delete any orphan tags
so
# Controller level
def delete_user(user_id: str):
self.user_dao.delete_user(user_id)
self.tag_dao.handle_orphans()
or
class UserDaoSQL(UserDAO):
def delete_user(user_id: str):
# sqlite logic to delete user
self.handle_orphan_tags()
or
# Controller level
def delete_user(user_id: str):
self.user_dao.delete_user(user_id)
self.user_to_tag_dao.handle_orphans()
class UserToTagDAOSQL(UserToTagDAO):
def handle_orphan_tags():
# handle orphan tags
def handle_orphan_users():
# handle orphan users
I assume the second option is wrong, cause its having to do Tag things, and the class is explicitly handling User stuff. So looking at 1 and 3, number 1 makes more sense, right?
in the WHERE Clause in PostgreSQL it tells me to do this (https://www.postgresqltutorial.com/postgresql-json/)
WHERE guild_info -> 'guild_id' = 837241873277386763;
But then it says
ERROR: operator does not exist: json = bigint
LINE 3: WHERE guild_info -> 'guild_id' = 837241873277386763;
^
And of course I can't compare json to bigint but then how do i get the integer of the key "guild_id"
We show you how to work with PostgreSQL JSON data and introduce you to some important PostgreSQL JSON operators and functions for handling JSON data.
nvm
Hi, why the call does not close when it has finished a work?
Knowing that I put the close code
cursor.close()
hello i have this problem with lists its not related to databases but thought i ask here
i webscraped some stuff and i made a loop for it now i want to add the things i scraped to a list. but it doesnt work
i put list.append(variable)
in the loop
it works outside the loop but it only adds the last thing that was scraped
ain't there a difference between cursor.close and exit or logout or something? idk i don't got these problems with my database.
are you perhaps closing the cursor but not the database connection (assuming you create one every time)?
How the code going to be if I am using cursor.fetchall?
And is there a Connection.row_factory in psycopg2 as well?
Guys how is PostgreSQL better than MySQL
if this:
https://developer.okta.com/blog/2019/07/19/mysql-vs-postgres
is to be believed, it's slightly nicer in many ways
I think alot of it comes down to support
mysql is owned by Oracle who already have their own db paid service
and they are not updating like they used to
while post gre is entirely open and have more updates
Does psycopg2 have a built in Cursor subclass which implements the behaviour which I need.
I am too lazy to make my own Cursor subclass 
['product', 'size']
[
('product1', '8'),
('product1', '8'),
('product1', '9'),
('product1', '10'),
('product2', '5Y'),
('product2', '6Y')
]
If I have a SQLite3 database like this, is there a select query that can get all unique sizes per unique product
like return [('product1', '8', '9', '10'), ('product2', '5Y', '6Y')]
@glacial spindle ```sql
SELECT DISTINCT product, size
FROM products
GROUP BY product, size
That will give as individual rows, but if you want it like [('product1', '8', '9', '10'), ('product2', '5Y', '6Y')] then you can use:
SELECT product, GROUP_CONCAT(size, ', ')
FROM (SELECT DISTINCT product, size
FROM products
GROUP BY product, size) t1
GROUP BY product;
If you need to use it then sure.
Can majority of problems be solved without a nosql database? Yes.
Relational databases are the most applicable to most situations when it comes to discord bots right? Which provider would be the best to go for when starting out with a DB for a bot? I was thinking of running my bot on a raspberry pi initially as I have a few lying around, does that affect my DB choices?
So if i am storing the user message count for each day should i insert a new row for each message for each user for each server? or is there any better way?
sqlite3 already comes with Python, you can try it out: https://aiosqlite.omnilib.dev/en/stable/ (for async applications)
Postgres/MySQL probably could run on a raspberry pi, but that would probably take up lots of resources. You could consider using a database-as-a-service service like ElephantSQL, but that comes with a big latency cost, and they don't have 100% uptime, of course.
How do I create a list in mongo db? I need to remove the "" and replace with [] for dpy
I need it to be in the form prefix : ["??" , "m/"]
@brave bridge Not sure if I should ping or if its against the rules, If it is please forgive me this time
@torn sphinx Unless you're in conversation with someone or you want to address someone personally, don't ping anyone
I don't know anything about mongo
as i said
Ok
use unset and set operator
I have no idea how to do that 😔
So I need a shell?
r u in compass
I am in the cluster collection
if you have an interface for your mongo db you can easily do that without typing the query
I have no idea on how to use that but ill try learning
I want to state in the beginning that this is a mix python and postgresql question.
I am currently using tortoise-orm that handles all the sql related stuff for me but today I got stuck while inserting into a JSONB field.
Here's my table:
class PointsInfo(models.Model):
class Meta:
table = "pt_info"
id = fields.BigIntField(pk=True, index=True)
guild_id = fields.BigIntField(index=True)
kill_points = fields.IntField(default=1)
posi_points = fields.JSONField(default=dict)
default_format = fields.IntField(default=1)
data: fields.ManyToManyRelation["PointsTable"] = fields.ManyToManyField("models.PointsTable", index=True)
class PointsTable(models.Model):
class Meta:
table = "pt_data"
id = fields.BigIntField(pk=True, index=True)
points_table = fields.JSONField()
created_by = fields.DatetimeField()
created_at = fields.DatetimeField(auto_now=True, index=True)
edited_at = fields.DatetimeField(null=True)
channel_id = fields.BigIntField(null=True)
message_id = fields.BigIntField(null=True)
I want to insert a row in pt_data table and then add that row to data column in pt_info table
_dict = {'quotient': [1, 20, 20, 40], 'butterfly': [2, 14, 14, 28], '4pandas': [3, 10, 8, 18], 'kite': [4, 10, 5, 15]}
table = await PointsTable.create(points_table=_dict, created_by= 123456789)
points= await PointsInfo.get(id=3)
await points.data.add(table)
but I get an error while doing this:
File "/home/deadshot/softs/softs/total-quotient/Quotient-Bot/.venv/lib/python3.8/site-packages/tortoise/models.py", line 655, in __init__
for key in meta.fields.difference(self._set_kwargs(kwargs)):
File "/home/deadshot/softs/softs/total-quotient/Quotient-Bot/.venv/lib/python3.8/site-packages/tortoise/models.py", line 682, in _set_kwargs
setattr(self, key, field_object.to_python_value(value))
OSError: [Errno 75] Value too large for defined data type
idk why python couldn't parse that dict
so I want to do this with raw SQL, since I have doing this with tortoise-orm , I don't have much experience with raw SQL , I know the basics but this is advanced for me.
What should I do here? can you help me with writing the raw SQL query for what I want to achieve here?
Thanks.
Will compass work?
Anyone work with hiveql or pyspark? I am wondering any alternative to running recursive query since its currently not supported?
hello
import sqlite3
conn = sqlite3.connect("wordbase.db")
conn.execute("CREATE TABLE IF NOT EXISTS words(word)")
def inserting(data):
conn = sqlite3.connect("wordbase.db")
cursor = conn.cursor()
print(data)
cursor.execute("INSERT INTO words VALUES (?)", (data,))
conn.commit()
conn.close()
def deleting(counter3):
conn = sqlite3.connect("wordbase.db")
cursor = conn.cursor()
counter3 += 1
print("count: ", counter3)
counter = str(counter3)
cursor.execute(f"DELETE FROM words WHERE rowid = {counter}")
conn.commit()
conn.close()
print(getting_data())
def getting_data():
conn = sqlite3.connect("wordbase.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM words")
conn.commit()
return cursor.fetchall()
I'm trying to delete data from database but nothing is deleted at all
please help me out
Ok I don't know ask to get helped at help general i mean sey: can someone help me at #databases
@torn sphinx The way you are deleting is not the best way to delete data as you can't guarantee your deleting what you want.
But your issue is probably because you increment counter by 1 so it wont find the row
what is the solution?
Try without counter3 += 1
You can delete by the word, cursor.execute("DELETE FROM words WHERE word = ?", ('the-word',))
still same
Works for me, #bot-commands message
def deleting_var():
data_number = len(getting_data())
counter3 = 0
list_data = listbox.get(ANCHOR)
listbox.delete(ANCHOR)
list_data = ''.join(list_data)
counter3 = 0
converted_data = list()
word_list = getting_data()
while counter3 != data_number:
converting = ''.join(word_list[counter3])
converted_data.insert(counter3, converting)
if(converted_data[counter3] == list_data):
print(converted_data[counter3] + '<---->' + list_data)
deleting(counter3)
print("breaking...x")
counter3 = 0
break
else:
counter3 += 1```
I use the function here
that's why I need rowid 🙂
But the rowid you are giving to the query doesn't exist. So make sure you pass the correct value then.
mmm
When I create a table and insert a value in pycharm using sqlite3, why does the database file look like this ?
at the end of the file the values are inserted, but i don't understand where all the null is from
or why
SQLite doesn't store its database in a human-readable format, you're not supposed to read it in plain text. There are various programs for viewing the contents, though.
Aah
thx, going to download now and see if i can make it work 😄
Is that with the database tool it has built in or just by opening the file.
ye i read it's with the pro version actually somewhere, but thought it waas outdated
is unittesting for creation of database, tables etc necessary using sqlite?
No kind of testing is necessary for anything. But you can write a test for it if you need or want full coverage.
class TestCreateTable(TestCase):
def test_create_table(self):
database_test = "store_hidden_string.db"
conn = hidden_string.create_database_connection(database_test)
test1 = hidden_string.create_table(conn)
test1.execute("""CREATE TABLE IF NOT EXISTS
testing(id INTEGER PRIMARY KEY AUTOINCREMENT, num INTEGER, string TEXT)""")
self.Equal(test1, """CREATE TABLE IF NOT EXISTS
testing(id INTEGER PRIMARY KEY AUTOINCREMENT, num INTEGER, string TEXT)""")
i'm not sure say if i wanted to tst the creation of a table in a db
but i thought this would work
doesn't
What do you mean your not sure if you want to test? Either you do or you don’t?
For testing you can use the :memory: database
And you can use a statement like this to check if it exists,
select exists(select name from sqlite_master where type='table' AND name=?), (‘table_name’,)
It will return 1 or 0.
Print the information of client_master, product_master, sales_order table in the
following format for all the records :-
{cust_name} nas placed order {order no} on {s_order_date}.
write sql query for this?
Help
Help people help you, by providing more details to your question with some code/data set.
Actually I have created two tables ( client_master and sales order tables)
And I want to write above mentioned text into sql query
?
Column cust_name belong to client_master table and columns order no and s_order_date belongs to productmaster table
Show your table structure
Print the information of client_master, product_master, sales_order table in the
following format for all the records :-
{cust_name} nas placed order {order no} on {s_order_date}.
The above query belongs to these tables
select
client_master.name, sales_order.s_order_no, sales_order.s_order_date
from
client_master
inner join
sales_order on client_master.client_no = sales_order.client_no;
@cold basin That gives you the data you need. You can use the data to format it.
And next time make sure to send a proper screenshot rather than an image which is very hard to read. 😉 👍
How to prevent sqlite3 input sql injection
mongodb doesn't create the database/ collection
@client.event
async def on_ready():
client.mongo = motor.motor_asyncio.AsyncIOMotorClient(str(My database url))
client.db = client.mongo["Discord"]
client.warns = Document(client.db, "warns")
Ok will this work for now
File "c:\Users\mazze\OneDrive\Documenti\GitHub\Crypto\src\variabili.py", line 20, in <module>
data = sqlite3.connect("../FILES/database.db")
sqlite3.OperationalError: unable to open database file
``` but why? 😢
@cedar cargo File doesn't exist at that location you gave for the file
but the file exist
Then it would be silly for sqlite to give that error.
./FILES/database.db
sql = ("INSERT INTO CLAN_USER_INFO(guild_name, guild_id, user_name, user_id, clan_name, clan_role_id, clan_id, roles_in_clan, join_clan_date, clan_invites, clan_user_exp) VALUES(?,?,?,?,?,?,?,?,?,?,?)")
val = (ctx.guild.name, ctx.guild.id, user_name, ctx.author.id, clan_name_dp, clan_role_id, clan_id, 'owner', date_now, 0, 0)
print(val)
cursor.execute(sql, val)
db.commit()
Do you think this code is prevent from sql injection ?
i upgrade it
no the python file is in a src faulder
yes its fine
Oh jesusthanks
maybe the database is locked?
Thanks
yo @proven arrow You seem bigbrain, #help-cheese
You do postgresql right? hehe
is there a library or package channel?
the docs will explain what fetchall returns, and you can use that information accordingly
i don't know if it has row_factory, i didn't see it in the docs, so i assume it doesn't
yo
for sqlalchemy when defining a model, is it possible to use a class method to query and do something with the model itself?
@classmethod
def test(cls):
test = session.query(cls).first()
print(f'{test.attribute} {test.attribute2}')
test.some_method()
above doesn't work but I could imagine its something close to that
any nudge in the right direction would be appreciated
guys anyone know how can I reduce the attack in kdd nsl to 2% ?
more explnation : I don't want to drop all the rows that are labeled as attacks I only want to reduce their number, I can do it manually but it will take a lot of time, if anyone knows a better way to do it please , and thank u
I am a beginner in Python and I am planning to build a desktop application with python and it basically should read RFID tag and run a query with the RFID code. The problem is I don't know how to get the RFID card code in my python code. Any idea how to do that? tnx!
cursor.execute("INSERT INTO table_name (col1, col2, col3) VALUES(%s, %s, %s)", (val1, val2, val3))```So say the value of `val3` is "default" then the query is going to be `INSERT INTO table_name (col1, col2, col3) VALUES(10, 20, 'default')` but I don't want the string "default" I want it to be the default type in postgresql
I tried doing this:py cursor.execute("INSERT INTO table_name (col1, col2) VALUES(%s, %s)", (val1, val2)) But I get an psycopg2.errors.NotNullViolation error
@austere portal Does the column have a default value?
yes
846710584824561674 856143191220682753 9c328aaffeca49c1baed20077b5f65e8
Error
_ClientEventTask exception was never retrieved
future: <ClientEventTask state=finished event=on_raw_reaction_add coro=<bound method Modmail.on_raw_reaction_add of <lib.cogs.modmail.Modmail object at 0x000001E0A503F0A0>> exception=TypeError('cannot unpack non-iterable NoneType object')>
Traceback (most recent call last):
File "C:\Users\Lasse\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 348, in _run_event
await self.on_error(event_name, *args, **kwargs)
File "C:\Users\Lasse\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Lasse\Documents\Discord Bots\Multi Server Bot\lib\cogs\modmail.py", line 214, in on_raw_reaction_add
Submit_Channel_ID, Questions = db.execute("SELECT submit_channel, Questions FROM modmail WHERE GuildID = ? AND MessageID = ? AND Emoji = ?", payload.guild_id, payload.message_id, payload.emoji.name)
TypeError: cannot unpack non-iterable NoneType object
@Cog.listener()
async def on_raw_reaction_add(self, payload):
try:
print(payload.guild_id, payload.message_id, payload.emoji.name)
Submit_Channel_ID, Questions = db.execute("SELECT submit_channel, Questions FROM modmail WHERE GuildID = ? AND MessageID = ? AND Emoji = ?", payload.guild_id, payload.message_id, payload.emoji.name)
except:
print("Error")
raise
return
if Emoji == None:
return
else:
message = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id)
user = await bot.fetch_user(payload.user_id)
await message.remove_reaction(payload.emoji, user)
Why do I get this error? The values in the database and the from the code (payload.guild_id, payload.message_id, payload.emoji.name) are the same
CREATE TABLE IF NOT EXISTS Post (
id SERIAL,
title VARCHAR(50) NOT NULL,
body TEXT NOT NULL,
date TIMESTAMP NOT NULL
)```
which database library is this?
sqlite
.execute never returns anything
you need to call .fetchone afterwards
which will return None for no match, and the row (as tuples) for a match
ohhhh yessss thank you xDD didnt reconized that I used execute xD
When someone type Good morning it sends Good morning ctx.author.mention at the channel that save in the db
How to do it?
is there a way to get a list of pending queries on a connection in aiosqlite? I'm trying to grab that info if say my bot disconnects/turns off unexpectedly.
hey, im getting this error, does someone know how i can fix this?
scheduler | sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30.00 (Background on this erro
r at: http://sqlalche.me/e/14/3o7r)
i already added this:
app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://root:root@db/main'
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {
"pool_pre_ping": True,
"pool_recycle": 300,
"connect_args": {
"connect_timeout": 30
}
}
CORS(app)
db = SQLAlchemy(app)
but it still didnt fix it
Hey Guys,
i am running into an issue with an delete function if my project... it simply does nothing.
output = {}
mydb = mysql.connector.connect(
host=,
user=,
password=,
database=
)
cursor = mydb.cursor()
sql = f'DELETE FROM {table} WHERE `{select_collumn}` = {select_data};'
print(sql)
try:
cursor.execute(sql)
return True
except:
return False
Even after i tried to execute the sql statement written by hand
cursor.execute("DELETE FROM km_import WHERE `killmail_id` = 93274148;")
return True```
It returns only true but don't delete the row in my table.
I tried to run the statement by hand via console with the same user and it works fine.
No exception btw.
@magic gulch Can you add mydb.commit() after the execute and try again
i hate myself sometimes
could anyone help me with this?
class Macro(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False)
fps = db.Column(db.Integer, nullable=False)
path_to_file = db.Column(db.String(50), nullable=False)
type = db.Column(db.String(10), nullable=False)
created = db.Column(db.DateTime, default=datetime.utcnow())
def __repr__(self):
return 'name: %r' % self.id
it doesnt see the column or the integer
please ping me if you are willing to help
Hello can someone help me build a modlogs command for discord.py?
I have sqlite as database but I don't know how to add all moderation data in it
Can no one help me?
use sqlalchemy for that
look up a tutorial for it
Can you not help me with it? I can give you nitro for it if you'd like
you just need to insert data in a sqlite db?
As well as make a modlogs command and make moderation commands like warn, ban, kick and mute to dump data in it
i can help you later with sqlalchemy im not home rn
Ok thanks alot please dm me whenever you're back home
@upper delta If your new to sql or databases in general you should avoid jumping straight to an ORM, as Lvcas suggests. Instead try to go through the basics first.
The world wont end no, but by jumping straight to an ORM like sqlalchemy, you will just end up crippling yourself from understanding the language and best practices that go along with it.
I am reading psycopg2 documentation and trying to understand the % placeholder.
Is the placeholders only purpose for the VALUES and to prevent SQL injections?
Yes
Thank you 🙂
If I have a nested structure, like
CREATE TABLE IF NOT EXISTS problems (
id INTEGER NOT NULL PRIMARY KEY ASC,
title TEXT NOT NULL,
desc TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS problem_tests (
problem_id INTEGER REFERENCES problems(id) ON DELETE CASCADE,
input TEXT NOT NULL,
output TEXT NOT NULL,
UNIQUE (problem_id, input, output)
);
```, on a server-based database (Postgres/MySQL), what would be a proper way to select all problems together with their test cases?
And how would I do it with a single query in SQLite (which doesn't have arrays)?
@brave bridge an inner join
So I'll get a result like this
id title desc input output
1 FizzBuzz ... 1 1
1 FizzBuzz ... 1 2
1 FizzBuzz ... 3 Fizz
1 FizzBuzz ... 5 Buzz
2 Factorial ... 3 6
3 NoTestsYet ... NULL NULL
``` and then I'll need to loop over the results in some clever way?
But if there are no problems, an inner join will put NULLs, no?
No, that would be an outer join.
ah
So if I need to include problems with no tests as well, I'll need an outer join?
Left outer join yeah
I’m trying to find an article I linked once here that explains it well
Can’t seem to find the link
won't this approach waste lots of bandwidth if I have a large amount of data in desc?
e.g., if the metadata (title, description etc.) takes 5KB of space, and I have 100 tests for each problem, fetching 100 problems will transfer at least 50 MB of data
Oh I misread
Depending on the context, I would use two selects. First the proplems and then another select for the test.
The bandwidth and data you pull also depends on what your storing
What is this logs?
I'm storing programming problems. The description can contain fancy markup like tables, equations etc., so it might take on the order of kilobytes
Well depends what you want to optimize it for. There’s many questions to ask for when performance tuning
Sometimes it may not be worth it and you just let it be
But you can paginate the results if you like
I was thinking of only including the metadata in the first row, and then padding things with NULLs.
id title desc input output
1 FizzBuzz ... NULL NULL
1 NULL NULL 1 2
1 NULL NULL 3 Fizz
1 NULL NULL 5 Buzz
2 Factorial ... NULL NULL
2 NULL NULL 3 6
3 NoTestsYet ... NULL NULL
``` but this sounds like a hack
Or, as Berndulas suggested, first fetch all metadata rows, then fetch all test rows.
I think I'll go with this, because I have more one-to-many relations that I'll need to query
thank you for the help @grim vault @proven arrow
or maybe I'll give up and store each problem as a JSON field
How to count positive or negative differences between two tables which is exactly the same?
@brave bridge do you know ^
I don't understand your question
Ok sorry
Wait
Basically I gave 2 tables exactly same like column name etc.
Only difference is the content in the tables is different.
So I want to get a query to get the difference between two tables for each cell
If you know then ping me please 😬
But how do you determine which rows to subtract?
Table B - Table A
Oh, you want to find the difference, as in, which rows were added and which are missing?
No so say the first row first column value of table B is 10. And the same cell in Table A value is 3. The difference is 7.
I want the 7
Like this for each cell
How do you determine the order of columns?
is there some primary key?
It’s the same, structure for both tables
Consider it data sets for two different points in time
AFAIK, SQL doesn't guarantee any particular order. You have to sort by some criteria (primary key, date, etc.) if you want to get a consistent order.
Yeah there is primary key. For each row
Hmm not sure I’ll try that later
But maybe not because pk might be different
As it’s not a foreign key
what do you mean by that?
That query assumes each row has the same PK value
But it might not so it won’t join all rows
right, because otherwise you don't know which row in t1 corresponds to which row in t2.
Yeah exactly which is why I was looking for cell by cell approach
I’ll think of it later now, thanks for the reply but still
That might depend on the database you're using. For example, SQLite has a special rowid column in each table (unless you tell it not to use it).
But why are you changing the value of the primary key? That sounds like something you shouldn't do.
What kind of data do you store?
Just events
It’s a fucking pain if you ask me
If it was up to me it would not be like this but here we are, and I have to deal with it ahah 😂
Well I’ll work on it later now
Anyone familiar with the Datstax Cassandra python ORM?
Basically, I want to create a multi table queryset. The table schemas are the same except for the table name. How can this best be achieved?
!code
I am using pymongo
I want to list all collections inside a db
Currently I am using list_collection_names to list them
But they are coming in random order
I want them to sort according to the last modified
If it helps I have one document called meta inside each collection which has timestamp in it
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, ObjectId):
return str(o)
return json.JSONEncoder.default(self, o)
collections = database.list_collection_names()
all_bots = []
for i in collections:
i_one = database[i].find_one({"meta": True})
all_bots.append(i_one)
all_bots_json = json.loads(JSONEncoder().encode(all_bots))
no idea how your documents are defined
but you can just find and orderby
db.collection.find( { $query: {}, $orderby: { age : -1 } } )
Document is simple as
{
"_id": {
"$oid": "60cc2663c9be7504ed3a1e79"
},
"meta": true,
"modified_timestamp": 1623991907.88602,
"published": false,
}
@sick salmon
Works
What if I want to have two sort conditions?
First
If it's published it should be sorted
And then the rest
Everything according to modified_timestamp?
$sort
Currently
I just sorted according to timestamp but is there any easy way to include according to published True also?
collections = database.list_collection_names()
all_bots = []
for i in collections:
i_one = database[i].find_one({"meta": True})
all_bots.append(i_one)
all_bots_json = json.loads(JSONEncoder().encode(all_bots))
all_bots_json.sort(key=itemgetter('modified_timestamp'), reverse=True)
pprint(all_bots_json)
is find faster?
Ah, thought so
I only have one document with meta: True
rest are of different structure
Hence, I used find_one
if you want to sort by multiple
you need to use $sort with pymongo aggregate
idk the syntax
i think you can just use sort
i dont use pymongo
.sort([("field1",pymongo.ASCENDING), ("field2",pymongo.DESCENDING)])
Hmmm
Cannot figure out the query
According to my understanding this would sort documents inside collection right?
I have one document inside every collection
That needs to be sorted
Correct me if I'm wrong
huh
but you said
your document is
{
"_id": {
"$oid": "60cc2663c9be7504ed3a1e79"
},
"meta": true,
"modified_timestamp": 1623991907.88602,
"published": false,
}
what is there to sort
Yes
o.o
This document I have inside each collection
So now I want to sort that
If I do list_collection_names it shows random order
seems convoluted way of ordering db
you want to extract documents from each collection and then sort by two different keys
yes?
so collection could be
collection_name = mango
onedocument_inmango = {
"_id": {
"$oid": "60cc2663c9be7504ed3a1e79"
},
"meta": true,
"modified_timestamp": 1623991907.88602,
"published": false,
}
#Collection2
collection_name = apple
one_document_inapple = {
"_id": {
"$oid": "60cc2663c9be7504ed3a1e79"
},
"meta": true,
"modified_timestamp": 1624261776.6484642,
"published": false,
}
#Collection3
collection_name = banana
one_document_inbanana = {
"_id": {
"$oid": "60cc2663c9be7504ed3a1e79"
},
"meta": true,
"modified_timestamp": 1621991907.88602,
"published": true,
}
So here it should show as
banana, apple, mango (banana because published rest based on timestamp)
i have no idea about this one
anyone knows sqlite
@bot.command()
async def change(ctx, new : str=None):
if new is None:
db = await aiosqlite.connect("prefix.db")
async with db.execute("SELECT prefix FROM prefixes WHERE guild_id = ?", (ctx.guild.id)) as cursor:
data = await cursor.fetchone()
await ctx.send(data)
else:
db = await aiosqlite.connect("prefix.db")
await db.execute("UPDATE prefixes SET prefix = ? WHERE guild_id = ?", (new, ctx.guild.id))
await db.commit()```
```s\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```
okay, did you understand the concern though?
yes
that error seems to come from dpy iteself,post the full traceback. Also I think the data is going to be a tuple of one tuple thus you'd need to get string representation of that for your ctx.send
well what i want is for it to show the prefix from database in that part if new is None
please re-read my message
oh sorry, its a long error though
ret = await coro(*args, **kwargs)
File "c:\Users\tenuk\OneDrive\Documents\Bot folder\test\botcode.py", line 101, in change
async with db.execute("SELECT prefix FROM prefixes WHERE guild_id = ?", (ctx.guild.id)) as cursor:
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\context.py", line 41, in __aenter__
self._obj = await self._coro
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\core.py", line 184, in execute
cursor = await self._execute(self._conn.execute, sql, parameters)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\core.py", line 129, in _execute
return await future
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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 "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\tenuk\OneDrive\Documents\Bot folder\test\botcode.py", line 123, in on_command_error
raise error
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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```
ah I see
you forgot the ,
this needs to be a tuple (ctx.guild.id) just add , so it looks like (ctx.guild.id,)
ohhhh tysm 
okay so now i had made all the stuff for my custom prefix but i do not have it as the prefix for the bot is what's in the database. Could anyone help me with that?
i have the change prefix and get_prefix
out of topic but you can pass a callable to Bot as command_prefix kwarg https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=command_prefix#discord.ext.commands.Bot.command_prefix and that callable will return the prefix based on passed guild. For additional questions you can use #discord-bots
cursor.execute(f"SELECT name FROM applications WHERE guild_id = '{ctx.message.guild.id}' and name = '{name.content}'")
sqlite3.OperationalError: no such table: applications```
how do i fix this?
create the table
and use bindings parameter
cursor.execute("SELECT name FROM applications WHERE guild_id = ? and name = ?", (ctx.message.guild.id, name.content))```
Need some help; #tools-and-devops message
I wonder how you can store an image with values outside of 0 and 255 as a byte array. i've seen methods with cv2 and pillow, but I just want the values in case I want to display them on a heatmap later.
Turning them into a PNG compresses the data and I don't want any loss.
So I was wondering if there was another way to extract data from a np array in a bytestring and store it in a db for later
This is what happens when you do it like in this picture
different messages
I want to put them all in the same message
but how?
Concatenate a string and take the sending out of the for loop
can you give example ?
messages = []
for i in data:
ID = "blah"
# ...
messages.append(f"{ID}")
await ctx.send('\n'.join(messages))
Basically this. I would have actually concatenate because you need to watch out for the 2k character limit
(basically send the message in the for loop if the concatenated string would be over 2k adding the next row)
i will do page system

you can use datetime
yeah i want something like that
done
how do you put that field in the database ?
1minute
im manually making the table here, not sure which data type to use if i were to do date
no
wait
db = sqlite3.connect("infs.db")
cursor = db.cursor()
type = ("Warning")
cursor.execute(f"INSERT INTO inf (User,UserID,Moderator,ModeratorID,Timestamp,Type,Reason) VALUES(?,?,?,?,?,?,?)", (user.name, user.id, ctx.author.name,ctx.author.id,timestamp,type,reason))
await ctx.send(f"{ctx.author.mention} tarafından {user.name}#{user.discriminator} kullanıcısı **{reason} ** sebebinden dolayı `Uyarıldı`")
db.commit()
cursor.close()
db.close()```
if you dont create table
you must create table
this is insert
sorry my english is bad
Yeah but over here in the screenshot i sent above, for date which data type should i use?
INTEGER or NUMERIC etc.
Uh sorry but one more question, how do you select multiple items from the columms?
1m
@median wave like this ?
cursor.execute(f"""SELECT ID,User,Moderator,Timestamp,Type,Reason from inf WHERE UserID = {member.id} OR ModeratorID = {member.id} ORDER BY ID DESC""")
i made it
Is it not possible to split my reason, moderatorid and timestamp here?
@commands.command()
async def warnings(self, ctx, member : discord.Member):
db = await aiosqlite.connect("modlogs.db")
async with db.execute("SELECT reason,moderatorid, timestamp FROM warnings WHERE guildid = ? AND userid = ?", (ctx.guild.id, member.id)) as cursor:
data = await cursor.fetchone()
@median wave what do you mean split?
like i want to be able to put them on seperate lines
With Sql or for using the data in python?
Right now this is what I have
Yeah so just index it to get the value you want
It’s a tuple, https://www.w3schools.com/python/python_tuples.asp
I want it to write Reason:{reason}
ID: {ID}
Date: {date}
Hmm but not really a database question. You should know how to manipulate and use basic structures.
If not, know is a good time to brush up on the knowledge, so you can use it later on as well 😉
well are there any docs?
The execute function returns a tuple here's some examples https://www.w3schools.com/python/python_tuples.asp
use indexing.
Sorry I can't seem to find the execute function
oh i got it
Thanks 
SO I asked this earlier and got one answer... asked something similar elsewhere and got another... gonna ask one more time because the conclusion I've reached is insane.
I have a project that entails wanting to allow multiple users the same fine-grained access control over a filesystem that the operating system provides. Problem is, I don't want to use operating-system user accounts. In Linux terms, I basically want to have a userspace program managing a folder wherein all the files within are owned/accessed by 'fake uids/gids' not found in /etc/passwd.
It seems that, so far, as I'm operating in Python, the only practical way to do this would be to use a SQLite3 file as a 'virtual filesystem' that is accessed by a custom FS implemented in PyFilesystem2.
is there something out there I'm not aware of which is appropriate for this situation
it seems kinda ridiculous that a situation like this is so unusual
@winter harbor do you need to store the files themselves in sqlite? or can you keep a "registry" of files in sqlite while keeping the files themselves on the filesystem, perhaps in some kind of obfuscated form?
maybe the files can be kept in a big flat directory with random strings for names
that's not at all a bad idea.
and the actual file names with their paths and permissions are stored in the sqlite database
a dedicated user could certainly use strings, grep, etc. to figure out which files are which, but if you don't have to worry about such users then you don't have a problem
plus if you store them in sqlite they could just read the sqlite database anyway
what I'm more argh about is the fact that there doesn't seem to be any obvious existing way to deal with this issue
i think it's an issue that mostly only shows up if you're developing a cloud storage service with shared access to files
so you're basically saying use sqlite3 for the filetable but dump the actual file binary content to the filesystem.
which is sensible.
that's my off-the-cuff suggestion having never worked on such a system before 😛
I actually found an 'sqlfs' based on sqlite3 which uses FUSE, but... the problem is that FUSE doesn't do what I want it to do at all so it's not much use to me
Hey All, I thought I would share an easy solution for the common issue of "shared state among workers". This is normally solved by DB access or Redis service . Introducing, easycaching, https://github.com/codemation/easycaching - persistent & shared caching, without the complexity. Hope it helps, glad to hear what you think.
does someone know a fix to close idle txn connections with sqlalchemy?
How would I save a dictionary to a postgres db with asyncpg?
Hello, I have a discord bot that stores everything in a SQLite Database, and have multiple tables for things from different cogs like automoderation, levels, currency, etc.
Should I make multiple databases? or can I continue using different tables
?
save as jsonb
I have some doubts about MySQL like whenever I will try to connect with it using mysql_connector will it automatically switch on its server or I am supposed to switch on the server manually using xampp
You will have to switch it on each time through xampp.
Unless you installed it different and it starts as a service
Hi, i have this code
import urllib.request as urlrequest
import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
today = datetime.today()
yesterday_till_high_noon = today + timedelta(hours=12)
datum_vertretungsplan = yesterday_till_high_noon.strftime("%Y%m%d")
def hol_vertretungsplan():
url_vertretungsplan = f'https://www.reclamgymnasium.de/mobil/mobdaten/PlanKl' + \
datum_vertretungsplan + '.xml'
print(url_vertretungsplan)
try:
xml_vertretungsplan = ET.ElementTree(
file=urlrequest.urlopen(url_vertretungsplan))
except ET.ParseError:
print('Es ist noch kein Vertretungsplan für dieses Datum verfügbar.')
exit()
return xml_vertretungsplan
vp = hol_vertretungsplan().getroot()
meine_klasse = '9.2'
plan_datum = vp.find('Kopf/DatumPlan').text
klassenplan = vp.find(f'Klassen/Kl[Kurz="{meine_klasse}"]/Pl')
#faecher = klassenplan.findall('Fa')
print(f'Vertretungsplan für {plan_datum}')
for stunde in klassenplan.iter('Std'):
fach = stunde.find('Fa').text
lehrer = stunde.find('Le').text
raum = stunde.find('Ra').text
print(fach, lehrer, raum)```
if i print
fach, lehrer, raum
it it works but if i want to use it any where else it dosent work
Download mysql or configure xampp to start it automatically @grim zephyr
Will it start it automatically when I will switch on my pc until I switch it off
Yes as a system service
But I want it to be online 24/7 cause I need a db for my discord bot
Any other db that is online for 24/7
Either you run your pc 24/7 or find an online hosting provider or free service.
I will host my bot on heroku but where to host a db?
@proven arrow
I will host my bot on heroku but where to host a db?
Suggest me some site to host a db cause i don't know much about db
Any other site that is not paid
I dont know you'll have to look around. Just search the web you'll find some.
Maybe mongodb is a 24*7 db
I am wanting to store a value from 0.1 to 2.0 (inclusive) in a postgres column, looking at the real it seems like a bit much, what should I store this kind of thing as
if anyone is interested, it is a speed multiplier for audio
yep, any db you host yourself on a VPS :)
have you seen how cheap hetzner is, like seriously, run your bot and DB on it and you are fine
I don't want to host my db myself I want someone to host it cause I cannot switch on my pc for 24*7
pay someone then, if you don't want to do something yourself, you pay someone else to do it
that is how everything works
I want a MySQL db which will be online for 24*7 but how about a mongodb maybe it's a 24 / 7 db
all major databases are designed to be running 24/7
async def _execute(self, failure_retry: int, cursor: mysql.Cursor, sql, val=None):
for x in range(failure_retry):
try:
if val:
await cursor.execute(sql, val)
else:
await cursor.execute(sql)
return cursor
except OperationalError:
if x < failure_retry - 1:
continue
else:
raise OperationalError
Is this a way to execute something or isn't this working?
@cold quail don't re-use cursors between queries
mongodb has a free tier. only 512 mb of storage though
hi, I have a dict inside a class that I would like to store in mongodb. But the dict sometimes changes, is there a way I can make it so every time the dict updates, it gets put into mongodb
ok thanks
hello guys does any have some experiences with connection pooling?
my pool is getting exhausted
I am closing the connections but the problem still occurs
can we add images in sql3 db ?
@slender narwhal Please don't try to ping @everyone or @here. Your message has been removed. If you believe this was a mistake, please let staff know!
Did you read the error message? It suggests a specific solution
You can save them as binary blobs
i already figured it out
lemme try
still returns it as a link, is that what its supposed to do? @harsh pulsar
A link? Huh?
which is the best python module to connect with a mysql db for read and write operation
Hey @loud crane!
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:
i get this error when I try to connect to mongodb in windows
but works fine in linux
ping me to reply
Anyone here who can tell me how can I make my bot read my SQL database
Hello,
Could anyone please guide me where I can find some basic knowledge of regression testing in ETL and reporting environment.
I guess what I am trying to say is, how I make sure that some user is not messing someone else’s work while creating reports in the database.
I was thinking that maybe we should follow some rules such as object naming convention so that no one deletes an already existing object .
But that still does not stop someone from doing DML actions in someone else’s table.
I am trying to implement a reporting environment with the help of Apache Airflow and trying to figure out how to keep things in order.
@wraith shell do you know how to make my bot read a mysql db and write in it
Do you know sql firstly?
It's just a create table statement
Wouldn't wanna spoon-feed since you declined the example though heh : )
i just want it in a big db for multiple server prefixes
conn.execute('''CREATE TABLE prefix
(guild_id INT PRIMAR KEY NOT NULL,
prefix varchar(255))'''
);
(2003, "Can't connect to MySQL server on '185.27.134.10'")
How do I get the laetst row content from a SQLITE table discord.py
In SQLITE, how do I get the last row content?
Like I want to make a case number command where each time a moderation command is used the case number increases by one
So I guess one way of doing that is checking what is the most recent case number and adding one to that
i want to do is insert some data to an table and return that that how can i do it?
in postgres you can using the returning clause.
insert into my_table(a,b,c) values (1,2,3) returning *
Especially useful when you have automatically incremented ids, timestamps etc.
yh ty
Just use auto increment
It increases by value each time automatically
ret = await coro(*args, **kwargs)
File "c:\Users\tenuk\OneDrive\Documents\Bot folder\test\botcode.py", line 167, in case
async with db.execute("SELECT user_id, type, mod, reason, time FROM modlogs WHERE case = ?", (case,)) as cursor:
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\context.py", line 41, in __aenter__
self._obj = await self._coro
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\core.py", line 184, in execute
cursor = await self._execute(self._conn.execute, sql, parameters)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\core.py", line 129, in _execute
return await future
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiosqlite\core.py", line 102, in run
result = function()
sqlite3.OperationalError: near "=": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\tenuk\OneDrive\Documents\Bot folder\test\botcode.py", line 232, in on_command_error
raise error
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\tenuk\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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```
@bot.command()
async def case(ctx, case : int):
db = aiosqlite.connect("final.db")
await db
async with db.execute("SELECT user_id, type, mod, reason, time FROM modlogs WHERE case = ?", (case,)) as cursor:
data = await cursor.fetchone()
embed2 = discord.Embed(title=f"Case {case}", value=data, color=discord.Color.green())
await ctx.send(embed=embed2)
case is an SQL keyword, use ":
async with db.execute('SELECT user_id, type, mod, reason, time FROM modlogs WHERE "case" = ?', (case,)) as cursor:```
@keen rock hey you told me to ping you
oh, okay thanks
And why does my embed just make the title as Case 2 when I do (commmand prefix)case 2?
Did you connect to the cloud db?
No
Finish the prompt then @verbal island
it should give you something like this: myclient = motor.motor_asyncio.AsyncIOMotorClient("localhost", 27017)
But for cloud and not localhost
Wait btw does it mean that I’m hosting my bot cloud or locally or cloud/locally hosting my monodb database if that makes sense?
Well, case(ctx, case : int) and you do (commmand prefix)case 2 which means that case = 2 and f"Case {case}" will be "Case 2" which is exactly what you get.
query = """INSERT INTO timer (event, extra, created, expires) VALUES ($1, $2::jsonb, $3, $4) RETURNING id"""
row = await self.bot.db.fetchrow(query, event, {'args': args, 'kwargs': kwargs}, event_time, when)
CREATE TABLE IF NOT EXISTS timer (
id SERIAL NOT NULL,
event VARCHAR,
extra JSONB,
created TIMESTAMP WITHOUT TIME ZONE,
expires TIMESTAMP WITHOUT TIME ZONE
)
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DataError: invalid input for query argument $2: {'args': [711043296025378856, 8493129529... (expected str, got dict)```
I don't understand
(expected str, got dict)
huh then show should i insert if i make it str
How do you connect to your db
from the mongo db compass
json.dumps({'args': args, 'kwargs': kwargs})
VALUES ($1, $2::jsonb, $3, $4)
wouldnt this do anything/make any diff?
Yeah no point doing json.dumps because that just stores it as string.
so what should i do?
any other way?
depending on the database, dumping to "json string" might be the correct way to pass the data
this often is the case with postgres for example
and is definitely the case with sqlite
sqlite doesn't have a JSONB datatype.
sqlite has json1
that dict contains datetime object also so, i get error
json itself doesn't have a "datetime" type. maybe postgres has some kind of support for timestamp data inside jsonb, but i doubt it. you might have to "dump" your data from a "dict of python stuff" to "a dict of basic types that are 1:1 with json"
e.g. by converting the datetime to rfc3339 format string
hmm sure but i have also seen a bot do the same thing and directly passing dict and it working for him
What are some high level steps to convert mongo db to postgres db?
if the dict values are just strings, ints, etc. then they don't need to do anything
Or they have registered an adapter.
they have datetime object in it
You can extend the json encoder.
how can i do it?
eg, I'm using:
class SetJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
if isinstance(obj, (Enum, Flag)):
return obj.value
return json.JSONEncoder.default(self, obj)
...
ins_column["value"] = json.dumps(value, cls=SetJSONEncoder)```
good point
what is Flag?
It's just an example, you'll need datetime.datetime. Enum and Flag are from the enum module.
hey i need a little help with MySQL, can i ask here?
hello
i'm getting an error
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InterfaceError: Error binding parameter 0 - probably unsupported type.
!code
this is my code of error :
@client.command()
async def addtoken(ctx, userid: int, maxuses: int):
if ctx.author.id != 746302070201647115:
await ctx.send("You don't have the permissions to use this command!")
else:
token = uuid4()
conn = sqlite3.connect("db.db")
c = conn.cursor()
c.execute("INSERT INTO tokens VALUES(?,?,?,?,?)", (token,userid,0,maxuses,"True"))
conn.commit()
c.execute("SELECT FROM tokens WHERE token = ?", (token,))
for row in c:
tkn = row[0]
uid = row[1]
ues = row[2]
mes = row[3]
sts = row[4]
await ctx.author.send(f"The '{tkn}', was successfully created with the following parameters:\n User ID : {uid},\n Uses : {ues}\n, Max Uses : {mes}, Status : {sts}")
this is my table code :
c.execute("CREATE TABLE IF NOT EXISTS tokens(token TEXT PRIMARY KEY, userid INT, uses INT, maxuses INT, status TEXT)")
@little pumice uuid4 returns a UUID object, not a string. use the .hex attribute to get a text representation. see https://docs.python.org/3/library/uuid.html
i did it
my problem was in token = uuid4(), i maked it str(uuid4)
don't do that, do token = uuid4().hex
token = str(uuid4) is very definitely not what you want
You didn't get a syntax error for the missing * in c.execute("SELECT FROM tokens WHERE token = ?", (token,))?
ok lemme test
nope, but i fixed it
token = str(uuid4()) is the same as uuid4().hex but less obvious and therefore worse
@harsh pulsar another question, how can i delete a row after a specific date ( automatically ) and this specific date it's from the same table, i missed it
in the WHERE clause, how can i filter without the exact word
like there are ABC company, BCD school and CDE university
then i use ABC only to filter the choices
@harsh pulsar but how can i make it an automatically process, everyday
like a background task
use the LIKE operator?
I might have to add database to the project I have been working on. We have an aws account. What databases would be a good choice?
What's the best way to cache mongodb data?
I need to make the same call multiple times and it's slowing my application
Hey, anyone experience with Alembic running in async loop? I'm aware of async template introuced recently, but my problem is that I have already an async loop created in my up, so I'm not able to create another one in env.py
@client.command(aliases=["c"])
@commands.cooldown(1,1,commands.cooldowns.BucketType.user)
async def card(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute("SELECT user_id FROM pokesets WHERE user_id = ?",(ctx.author.id,))
result = cursor.fetchone()
if result is None:
await ctx.send(f"{ctx.author.mention}, please use the {prefix}lss (lets start sleevin) command before using any of the other commands, thanks!")
return
elif result is not None:
def check(m):
return m.author == ctx.author and m.channel == ctx.channel and m.content.lower() == "pb" or m.content.lower() == "gb" or m.content.lower() == "ub" or m.content.lower() == "mb"
msg = await ctx.send(content="Type `pb`,`gb`,`ub` or`mb` to catch it!",embed=random.choice(pokes))
reply = await client.wait_for("message",check=check)
if reply.content.lower() == "pb":
int = random.randint(1,2)
if int == 1:
embed = msg.embeds
embed2 = msg.embeds[0].fields
pc = embed2[0].value
image = embed[0].image.url
cursor.execute("INSERT INTO pokesets(pc,user_id) VALUES(?,?)",(pc,ctx.author.id,))
cursor.execute("SELECT pb FROM pokesets WHERE user_id = ?",(ctx.author.id,))
result2 = cursor.fetchone()
print(result2)
cursor.execute("UPDATE pokesets SET pb = ? WHERE user_id = ?",(-1*result2,ctx.author.id,))
embed2=discord.Embed(description="The Pokemon was successfully caught with a `PokeBall!`")
embed2.set_author(name=f"Congratulations, {ctx.author.name}!",icon_url="https://cdn.discordapp.com/attachments/856373686809788430/856619128726224916/671848138935500836.png")
embed2.set_image(url=image)
await msg.edit(content="You caught the pokemon with a `Pokeball`!",embed=embed2)
await ctx.send(pc)
``` Im trying to multiply the result2 with -1 but it says this:
```py
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\25dch\github\pythonbot\PokeSets.py", line 107, in card
cursor.execute("UPDATE pokesets SET pb = ? WHERE user_id = ?",(-1*result2,ctx.author.id,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
```i dont know if im doing anything wrong
What's aiosqlite's equivalent to sync sqlite's cursor.affected_rows()?
Can I get help saving this data to a sqlite db?
def home(request):
url = f'https://newsapi.org/v2/everything?q=gaming&from= {DATE}&sortBy=popularity&language=en&apiKey={API_KEY}'
response = requests.get(url)
data = response.json()
articles = data['articles']
context ={
'articles' : articles
}
return render(request, 'news/home.html', context)
it depends on the specific database library, check their docs
hi i am quite lost
What with?
result2 = cursor.fetchone() -> result2 will be a tuple, if you want to use the selected value you must use result2[0].
yep, i got it thanks anyway
NameError: name 'article' is not defined
Need some help with this
con = sqlite3.connect('news_api/artilces.db')
cur = con.cursor()
url = f'https://newsapi.org/v2/everything?q=gaming&from={DATE}&sortBy=popularity&language=en&apiKey={API_KEY}'
response = requests.get(url)
data = response.json()
o = json.dumps(data)
obj = json.loads(o)
for artilce in obj['articles']:
print(artilce)
cur.execute("Insert into Article values (?, ?, ?)",
(artilce['title'], artilce['publishedAt'], artilce['url']))
con.commit()
artilce != article check your naming.
got it thank you
@client.command()
async def stats(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute("SELECT date FROM pokesets WHERE user_id = ?",(ctx.author.id,))
result = cursor.fetchone()
await ctx.send(result[0].strftime("%y-%d-%m"))
``` im trying to format the time it gets from the db as year-day-month but i get an error saying:
```py
gnoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "s" is not found
Ignoring exception in command stats:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\25dch\github\pythonbot\PokeSets.py", line 65, in stats
await ctx.send(result[0].strftime("%y-%d-%m"))
AttributeError: 'str' object has no attribute 'strftime'
sqlite does not have a date datatype, so your select will return a string which can't be formated with .strftime(). You'll need to convert it into a datetime object first with .strptime(...).
ah
well
i tried that but it says this: i think the seconds is whats causing the error
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "stast" is not found
Ignoring exception in command stats:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\25dch\github\pythonbot\PokeSets.py", line 65, in stats
dt = datetime.strptime(result[0], "%d/%m/%y %H:%M")
File "C:\Python39\lib\_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "C:\Python39\lib\_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2021-06-22 18:13:46.681220' does not match format '%y/%m/%d %H:%M:%S'
'2021-06-22 18:13:46.681220' is format "%Y-%m-%d %H:%M:%S.%f"
oh
dam
im new to formatting time, i should look at the datetime python docs
ah
i see how it works
ty
Good night guys, i've recently entered this discord.
I really need some help i am having a lot of problems trying to do the command "pip install impyla" on my cmd is there anyone that can help me fix this?
i am doing this on my company computer and today i went to the company office for them to switch the computer and now im having a different kind of error.
That's blurry as. Can you make a textual paste
c:\users\andrefcastro\appdata\local\programs\python\python39\include\pyconfig.h(59): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
that's the error resume message
try to update your python version or your pip version
Like a text paste of the whole thing
c:\users\andrefcastro\appdata\local\programs\python\python39\include\pyconfig.h(59): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
The whole thing
https://www.lfd.uci.edu/~gohlke/pythonlibs/#bitarray I managed to squint at the text and found you need the binary version of bitarray
@weak yoke so i should try the pip install bitarray right?
First time using Python my bad guys
Recently changed from UiPath to this new project
@weak yoke got the same trying to do "pip install bitarray" c:\users\andrefcastro\appdata\local\programs\python\python39\include\pyconfig.h(59): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
You need the binary wheel
Remember to always paste the whole output
The bit you pasted doesn't help debug the problem
Instructions are on the top of this page I linked you
Hey @sleek aspen!
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:
You can use https://paste.pythondiscord.com as the bot said
oh ok
Did you click this URL?
read again
this
Right so you see right at the top of the page,
Use pip version 19.2 or newer to install the downloaded .whl files. This page is not a pip package index.
it's literally in the first 10 lines...
Which is a link to https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
oh ok thanks for the command !
ill give a try , thanks for trying to help !!
i will try this one :
bitarray-2.1.3-pp37-pypy37_pp73-win_amd64
Are you using pypy3.7?
It looks like you're using cPython 3.9
Which will need bitarray-2.1.3-cp39-cp39-win_amd64.whl
ERROR: bitarray-2.1.3-pp37-pypy37_pp73-win_amd64.whl is not a supported wheel on this platform.
oh okok
So this should be the command right:
py -m pip wheel --wheel-dir=\C:\Users\andrefcastro\Desktop -r bitarray-2.1.3-cp39-cp39-win32.whl
after wheel installation
Don't you want the 64 bit one?
Sure, can i go to the voice chat please?
if possible of course
oh all voice chats on this discord are voice disabled 😦
C:\Users\andrefcastro\Documents>py -m pip install bitarray-2.1.3-cp39-cp39-win_amd64.whl
Processing c:\users\andrefcastro\documents\bitarray-2.1.3-cp39-cp39-win_amd64.whl
Installing collected packages: bitarray
Successfully installed bitarray-2.1.3
dudes
I love this discord
U guys might even saved me from being fired xD
They should just put the wheels on pypi ffs
You should subscribe to that GitHub issue so you know if they ever do
Or raise an issue in pyimpala to let them know about the fork with wheels
are those unnoficial modules?
Yes i will try to make this resolution public and let the credits to the guys who did that topic
thank you very much
how do i add commas in numbers that fetchone gets?
@client.command(aliases=["bal"])
async def balance(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute("SELECT balance FROM pokesets WHERE user_id = ?",(ctx.author.id,))
result = cursor.fetchone()
await ctx.reply(f"**{ctx.author.name}**, you currently have **{result[0]}** CardCoins!")
``` i wanna do that in this command
nvm i got it, used {:,} and .format
is there a database that you would suggest I should use if I just started learning? I dont really understand how they work, or if there is a "good one" yet, so your opinions would help :D
sqlite
ok :D
as mentioned above, SQLite is great.
ok thaaanks!
Check out #databases message for some help
can I use async for for execute() from aiosqlite module?
how do u check if a row already exists?
var = "INSERT INTO stats(user_name, user_id, total_msg) VALUES(?,?,?)"
self.cursor.execute(var, [("Total"), ("000000000000000000"),(0)])
self.database.commit() #saves the information
I am trying to add a if statement to this to check whether if this row named total already exists, if yess, then ignore, else create a row named total
do you have a primary key on the table?
yes i do
import _sqlite3
with _sqlite3.connect("ServerStats.db") as database:
cursor = database.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS stats(
BasicID INTEGER PRIMARY KEY,
user_name VARCHAR(20) NOT NULL,
user_id VARCHAR(20) NOT NULL,
total_msg VARCHAR(20) NOT NULL);
''')
This is how i created the database
and total always has an id of 1 but i am not sure onto how i can get a True or False result to check if that is created or not
that being the row named total
do you need to specifically check if the row exists? maybe you can use ON CONFLICT in your INSERT instead https://sqlite.org/lang_conflict.html
also, the (20) in your VARCHAR type is ignored by sqlite https://www.sqlite.org/datatype3.html
VARCHAR is an alias for TEXT
im trying to download mysql workbench.. is this the right download? i've windows
searches for database projects without ui get's rejected
Can you guys recommend some if any?
yea this should work
What?
I am too lazy to build a full ui but want to do some sql project
Ok so do it.
And not sure what you meant by gets rejected?
Error Code 1044. Access denied for user '.....'@'%' to database '......'
mysql db*
what could be the reason
That the combination of host,user,port,password is incorrect
does sql3 store data in array format?
No
any way i can do it?
Store it in a text column as json.dumps() and restore it after select with json.loads().
Ideally you want atomic values, and you can break the list down and normalise it
certain names that i want to array it in an embed
alr, ill try
It would be better if you model your data properly rather than just smash everything into a column that’s not even json.
ok
how do I check if something is deleted in aiosqlite cursor?
cursor.rowcount
Returns the number of rows affected by the statement
o
Or you can do a select exist if you want to write a query to check if it’s gone
didnt quit work, also that i used fetchall maybe that could be the problem
Without code and data it's hard to tell, but as 38654 has said, normalising the data schema would be preferable.
@client.command(aliases=["bag","col"])
async def collection(ctx):
db = sqlite3.connect(db_path2)
db.text_factory = str
cursor = db.cursor()
cursor.execute("SELECT rowid,pc FROM pokesetspc WHERE user_id = ?",(ctx.author.id,))
result = cursor.fetchall()
embed=discord.Embed()
embed.add_field(name="\u200b",value=f"\n{result}")
await ctx.send(embed=embed)
``` heres the code
What do you expect? result will be a list of tuples or an empty list if no rows are found.
no, i signed in mysql workbench and i can access anything, the only thing i could not use is making a database
oo ig it should work now 
Then you don’t have permissions to perform that action with that user.
You can grant the privileges
i fixed!
hi im trying to use ravendb with python where would you say is a good place to start?
warnings.warn(str(exc))
Traceback (most recent call last):
File "h:\PYTHON\TEST UNBAN\COG TEST\bot.py", line 42, in <module>
prx.prefixes = discordmongo.mongo(connection_url = prx.db, dbname = "prefixes")
TypeError: 'module' object is not callable```
@grim zephyr try using pymongo
i am using pymongo
well any way i can fix this error?
making a connection
well is it possible to read and write a sqlite db using heroku
Is there a bot command for a wiki or FAQ for databases and online hosting? I'm a student and I have some beginner questions. I don't care about scaling, or api count, or any of that extra stuff.
whats the differance bettween executing sql using db and cursor
The latter is required behavior by the db api specification, the former is a convenience provided by the library where it just creates and returns a new cursor for you
If the former is available, use it
can anyone explain
def update_encourage(encourage_message):
if "encouragement" in db.keys():
encouragement = db["encouragement"]
encouragement.append(encourage_message)
db["encouragement"] = encouragement
else :
db["encouragement"] = [encourage_message]
meaning
especially that database part
It'd be better if you can keep the code this way:
YOUR CODE
By doing py paste your code here
def update_encourage(encourage_message):
if "encouragement" in db.keys():
encouragement = db["encouragement"]
encouragement.append(encourage_message)
db["encouragement"] = encouragement
else :
db["encouragement"] = [encourage_message]```
This way!
an ISO 8601 falls into which category of datatype i sqlalchemy? eg. 2021-06-25T10:00
this is what i am guessing
i've been trying to add 2 values to a 2 column table
but it ends up like this
it doesn't end up in any errors but i dont see the values anywhere
am i using the db browser wrong or its the code??
also in the terminal it prints out no value
Hi All... I have started learning data science from today. I am going in a clear learning path way. Will be completing the Data science in 6 months. If anyone else is interested in preparing with me, you can join me.
My guess would be that you're missing the conn.commit() before the conn.close() to confirm the transaction.
Guys how do I make the primary key in SQLAlchemy a custom one or at least hide it?
is sqlite3 LIKE operator case-sensitive?
I think case-insensitive (for ascii characters only), unless you use the case_sensitive_like pragma: https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_and_match_operators
Hello. You might want to check out the #data-science-and-ml channel and the pinned messages there.
thx
Hi, I have a MongoDB in the backend and would like to store images. Perhaps it is different for Mongo, but usually you dont want to store raw files in a DB because it is slow and unoptimized. My idea would be to save the images to AWS S3 and save the link in MongoDB and it seems like there is MongoDB Data Lake that can help me with that - but that is a paid service so I would prefer to do it without.
I unfortunately did not found a tutorial on that.
Sql languages add very simple. Think of it like this.
All keywords (commands) should be uppercase, such as SELECT, FROM, ORDER etc.
Everything else must match their corresponding value. For example, if you have a table called "Test", you have to query the table as "Test".
Booleans are the only exception to this rule. They can be either, True, TRUE, true, False, FALSE, or false
I use lowercase keywords 👀
Uppercase just makes it look like Cobol or something. Too shouty 😄
While I agree, 1) it's generally better coding practice, and 2) it's easier to read IMO
that used to be
nowadays most engines can deal with both uppercase and lowercase sql
Sorry, you can't do that here!
```py
-code here




