#databases
1 messages · Page 118 of 1
The main difference is SQL databases are relational, whereas NoSQL aren't.
Yes so where you can have tables and the data can be related
eek not really
Pretty much all the data your bot will use will be relational
and is very very suited to being relational
which SQL excels at
no
there are other NoSQL dbs
though only 1 viable Driver for python atm for async
If you guys wanted to make a table that looks like this, what would you use?
the NoSQL db drivers for python are really rather lacking for async stuff
im using a mongodb, flask, and datatables
@queen saffron looks like a data table
@finite chasm just use a json, its super easy to use.
the python code that takes the queries that come from datatables isn't working properly. theres got to be a better way to do this 😦
Data tables is front end, generally your server would populate the table
just use a json, its super easy to use.
@torn sphinx Just because it's easy to use does not mean it's the appropriate solution here.
what would you use to populate datatables with data from mongodb
Your server should return that data to the front end
Then data tables will take care of the rest.
This question would be better suited in #web-development maybe?
hi, I would like to save this as json to use it later as a mongodb document. How can I translate this grammar files to json? <symbol> = a mix of constants and <other_symbol>s
this is the file https://github.com/googleprojectzero/domato/blob/master/common.txt
uhhhh not too sure what you mean by that... how do you expect mongo to interpret the queries coming from datatables
i have python code that takes the server side requests coming from datatables and performs the filtering, searching, sorting against the mongodb
I can't just dump 10,000 entries against the clients browser and expect everything to be nice and fast
Sorry to interrupt, but I'm trying to combine two big data files, and I was using pandas data frames originally but they're really slow, plus take a ton of ram. Would SQLite be a good alternative?
please some help.. I'm asking and no one even reply
I can't just dump 10,000 entries against the clients browser and expect everything to be nice and fast
Well yeah don't be doing that. Datatables has documentation on how server side processing should be done. You should have a read of this https://datatables.net/manual/server-side
Use the parameters it provides you to get your data from the database and pass it back accordingly. You may also want to check if python has a library for datatables that may assist you in this.
please some help.. I'm asking and no one even reply
@torn sphinx Your question in your current task is not database related. You may want to claim one of the help channels to get help with this issue of yours. See #❓|how-to-get-help
I asked in general and I got no help, one told me because json maybe database channel help
yes it's a task but I'm asking for guide not work done
I meant task as in the current problem you are trying to solve.
i may have figured out the problem, I formated the date that i insert each document, and i think its having a problem sorting by the date
the problem im having is the pagnating was returning the same data as the first page but if I sorted by a different column it didnt seem to happen
I meant task as in the current problem you are trying to solve.
@proven arrow the problem is I've no experience with python and maybe I will invest a week to make something it can be done in 5minutes with some help
@torn sphinx Ok. In that case can you be more clear in your question as to exactly what your trying to achieve so someone can give you a better answer.
the question is, how can I translate a grammar txt from that project grammar.py parses the files, to translate it to json. Problem is there is symbol = value or another symbol = value, and some symbols have multiple values, then I need something like "<symbol>": [['<another>'], ['x']], etc
I want to generate a big json file with all that grammar
later I will able to parse it or use it as document in mongodb
So as an example, you want it like this?
"<newline>" : [ "<cr><lf>"],
"<interestingint>" : [ "32768", "3737",...],
....
Guys, I have the database connected once and then it doesn't work, why? "use mysql"
raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.
As the error says it can't find a connection to the database
Could happen if there was a network issue or the connection to the database was closed
So as an example, you want it like this?
"<newline>" : [ "<cr><lf>"], "<interestingint>" : [ "32768", "3737",...], ....
@proven arrow right
Ok well I'm not on a computer but let me try typing something up from my phone.
thank you
from collections import defaultdict
import json
with open('data.txt') as f:
content = f.readlines()
data = defaultdict(list)
for x in content:
if x != "\n":
x = x.strip()
tag = x.split()[0]
value = x.split('= ', 1)[1]
data[tag].append(value)
json_data = json.dumps(data, indent=4)
print (json_data)
Try that, although I've not tested it. However it assumes you have a file in the directory called data.txt, and the comments are removed from the file
IndexError: list index out of range
Remove the comments at the top and try again
I did it but same
traceback (most recent call last):
File "tojson.py", line 13, in <module>
value = x.split('= ', 1)[1]
IndexError: list index out of range
I've to remove all comments
Isn't that what I said?
this should work, thank you again
Yes it should, you can see it here, #bot-commands message
ids = db.session.query(MyModel.id).all()
bulk_data_objects = []
for x in my_records:
existing_id = list(filter(lambda z: z[0] == x['id'], ids))
if len(existing_id) > 0:
continue
r = MyModel(
type=x['type'],
text=x['text']
)
bulk_data_objects.append(r)
db.session.bulk_save_objects(bulk_data_objects)
db.session.flush()
db.session.commit()
print('Bulk updated to DB')```
I'm trying to add a bunch of query_results to my db, and want to check if they exits already beforehand
this is quite time consuming though
is the are way to 1). check faster if the id's already exist 2). add to db in bulk and just ignore the duplicated ones
highly appreciate your input
also if my general construction with .bulk_save_objects() makes sense
Which database are you using?
Oh I see, I thought you were making raw queries, which if you were you could use INSERT IGNORE, which would insert or ignore it if already exists. However since I don't use sqlalchemy, I'm not sure if it has a feature.
My first idea was to set id to unique in the Model
that way it will just throw an error when trying to add it to existing
but I guess that's a hack
Well that's kind of how the INSERT IGNORE works as well, except it doesn't throw an error but silently ignores it
Maybe sqlalchemy might complain about the error even if you did that?
Yes it should, you can see it here, #bot-commands message
@proven arrow something is wrong with a big file, how can I debug what line is failing?
there is no comments
I will look into INSERT IGNORE
I also think my lambda function is not particularly efficient
existing_id = list(filter(lambda z: z[0] == x['id'], ids))
@torn sphinx add it in a try catch, and in the catch print the line or the values
there are values with "" and : that fails
I did it with print() but not try: catch:
for example I've values that includes <symbol> = align="<othersymbol>"
[-1] seems to work
not, is not because I got duplicated values
"<newline>": [
"<cr><lf>",
"<cr><lf>",
"<cr><lf>",
"<cr><lf>",
If you want to ignore the index errors then put in try catch,
for x in content:
try:
# code here
except IndexError:
pass # or print(x) to get the line of error
You have the basic idea of how it works now and how it can be done. The code I sent originally works perfectly fine with that dataset. You should try to attempt to troubleshoot any errors yourself if you are able to.
right, thanks
@proven arrow any idea how can I add an extra square bracket to values? like "<symbol>" : [["a"],["b"],["c"]]
thanks!
I'm having a problem with an sql query, and peewee. Well, first I need to figure out correct sql query. I have a table with two columns, both ints. I want all values column A that shares two specific values in column B. so for example I have the pairs (1, 0), (1, 1), (1, 2), (2, 2), (2, 3) and the specific values are 1 and 2, I want the number 1 since that has both numbers in column B.
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
def __repr__(self):
return f"User('{self.username}', '{self.image_file}', '{self.image_file}')"
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
content = db.Column(db.Text, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def __repr__(self):
return f"User('{self.title}', '{self.date_posted}')"
When I try to input data I get this, following a tutorial and cant find the problem
>>> user_1 = User(username='admin', email='admin@protonmail.com', password='password')
sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class User->user'. Original exception was: When initializing mapper mapped class User->user, expression 'Post' failed to locate a name ('Post'). If this is a class name, consider adding this relationship() to the <class 'main.User'> class after both dependent classes have been defined.
does anyone else have issues with psycopg2/postgres taking forever to execute_values with 5000+ values every so often? every few times that I run it with 5000 values, it will take over an hour to execute, but most times it takes only a few seconds
lowering the number of values helps to a point, but there's really no change in behavior when lowering values below 5k
using python 3.8.6, the latest stable psycopg2, postgresql 13, and compiling the code with cython 3.0a6 and running on ubuntu 20.04
Does anyone know why my code is failing?
x = collection.aggregate(
[
{
'$match': {'UserID': ctx.author.id}
},
{
'$group':{
'DiscordID': '$UserID',
'Count': {'$sum': 1}
}
}
]
)
print(x)
pymongo.errors.OperationFailure: The field 'DiscordID' must be an accumulator object,
please I've been stuck on this for 45 minutes 😭
@fiery cypress it looks like you're trying to use a string instead of an accumulator object for the DiscordID field
this post on stack overflow might help:
https://stackoverflow.com/a/54440809
So i looked at that but I wasn't sure if it pertained to what I was trying to do. So I'm thinking like if I have 4 users [Max, Rye, Will, Max], with userIDs respectively [1, 2, 3, 4]
If Max with user 4 uses the command, if I try to do {$first : $userID} would it do 4, or 1?
If it returns 1, what acculumator object(?) would I have to do to match the userID to the author?
i want a db manager like elephant sql that is free
what should i use
ik elephant has a free one but it isnt enough space
pls ping me
hi
can someone whelp me why this code is showing wrong?
mydb = mysql.connector.connect(host="127.0.0.1", port=3306, user="root", passwd="pass", database="school")
cursor = mydb.cursor()
cursor.execute("CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3)")```
Traceback (most recent call last):
File "/Users/admin/Desktop/pyconnectsql.py", line 7, in <module>
cursor.execute("CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3))")
File "/Users/admin/anaconda3/lib/python3.7/site-packages/mysql/connector/cursor_cext.py", line 266, in execute
raw_as_string=self._raw_as_string)
File "/Users/admin/anaconda3/lib/python3.7/site-packages/mysql/connector/connection_cext.py", line 475, in cmd_query
sqlstate=exc.sqlstate)
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 'NUM(3), Sname VARCHAR(255), Smarks NUM(3))' at line 1
Missing parentheses
"CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3))"
Missing ) at the end
("CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3)")
you mean after the 3 or after the " ?
You have 5 ( but only 4 ) in there
"CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3))"
mydb = mysql.connector.connect(host="127.0.0.1", port=3306, user="root", passwd="pass", database="school")
cursor = mydb.cursor()
cursor.execute("CREATE TABLE student (SID NUM(3), Sname VARCHAR(255), Smarks NUM(3))")```
i type this and it still shows error
ohhh
😦
my bad
in noob
god its still not working
cursor.execute("CREATE TABLE student (SID int, Sname varchar(255), Smarks int")
Missing the ending ) again
oof
it worked
thanks a lot @modern mulch hope you didn't mind me being a noob
i just started with this python sql connectivity stuff
Not at all 😄
dEteBEESa
can somone help me set up a data base for my discord bot
i made one but i dont want to use local host
i want is hosted so when i host my bot it still works
anyone know hwo to do this or hep me
ping me pls
@torn sphinx You can still use localhost when you host it as well
If the database is running on the same host as your application then it's still considered as localhost
@torn sphinx You can still use localhost when you host it as well
@proven arrow i dont want my computer running 24/7 tho
hey what would fetchone return in asyncpg
It has fetchrow instead, fetchone is not a method
I See
@broken charm #❓|how-to-get-help
Hello, i have 4 columns (id, user_id, col1, col2). ID is the only unique key here. For each user i want to get the average of all his col1 total, and col2 total. All are int columns
So below table for example:
id, user_id, col1, col2
1 10 2 2
2 10 5 5
3 5 7 4
4 5 3 2
Should give the following result:
user_id, average
10, 7
5, 8
So basically, like this for the first user id 5 it is calculate like: ((7+3)+(4+2)) = 16 / 2 = 8
Hello, i have 4 columns
(id, user_id, col1, col2). ID is the only unique key here. For each user i want to get the average of all his col1 total, and col2 total. All are int columns
@torn sphinx just to be clear this is SQL?
yeah
oh sorry i meant 5 my mistake
that works, but the 2 can be more than 2
it should be how many columns this user has?
use AVG then
it should be how many columns this user has?
@torn sphinx but you said
each user has 2 columns?
do you mean rows?
user can have many rows in the table
so that would work what you sent?
let me try, thanks
sorry i meant devided by the number of rows it has
so if user_id has 10 rows, then it would divide by 10
then
that's different
from what you originally wanted
so you actually want the sum of the averages of each column?
so both columns should be added and then divided by the number of rows, for that user
AVG(col1) + AVG(col2)
next time
when you give an example
you should probably make it a bit bigger
so it's less ambiguous
anyway, that should work
Hello everyone, I was wondering if anyone could point me in the direction of a possible db for a discord bot. Im currently running sqlite and it is blocking. I'm looking to upgrade. I have been looking into MongoDB. suggestions?
@gaunt garden sqlite is only blocking if you use the non async module for it. You can use aiosqlite which is the async version for it.
Also MongoDB and SQLite are two different databases, where sqlite is relational and uses SQL, and MongoDB is not relational/NoSQL. So switching like this would require all your DB code to change as well.
is there a way that i can create just a database file to run for my application so like where i access sqlite but pass info to that file when i need to query, add or remove stuff? right now its physically in every code block and im hoping to condense my code a bit. sorry if thats a stupid or confusing question, ive seen it done, but dont really know how abouts to set it up. and i will look into aiosqlite. thanks!
You can make a single connection and access it whenever you need to, however that won't prevent your issue of blocking, since those I/O operations will still have to be done.
true.
what is the difference between HAVING and WHERE?
i am asking in databse channel so my question is related to that also
@torn sphinx The GROUP BY clause groups a set of rows into a set of summary rows or groups. Then the HAVING clause filters groups based on a specified condition. Note that the HAVING clause is applied after GROUP BY clause, whereas the WHERE clause is applied before the GROUP BY clause.
what a link xD
Ok let me read it thanks
They both filter the result so can we not just have where for both?
It's to do with the order of operations (certain clauses are evaluated before others).
WHERE applies the filter to each row individually, and happens before any aggregation. Whereas, HAVING filters after the aggregation/grouping is done.
Let me send a illustration of the order in how they are evaluated, will make more sense.
If you look at that WHERE happens before the grouping, so it's not possible to use after the group by, hence why we have HAVING.
ohhh right ok yes yes, makes sense
Hello developers ! I'm new on this Discord (forgive me for my english, I'm French '-').
I don't know if this channel is the right one for my subject.
Btw, I have a problem with Flask and its system of database. I followed this video : https://www.youtube.com/watch?v=4T5Gnrmzjak&t=927s
I'm trying to make a webService which returns you all availables hotels depending your booking request (Start Date, Number of Nights, Number of Rooms)
I made 2 database :
Bookings ( Contains every booking )
Hotels ( Contains every hotels )
My actual problem is that I can ask only one database per request. I don't realy understood how it works that's probably the main problem.
So when the client wants to know every available hotels with a (Start Date, n° nights and n° rooms) I need to get every hotels, stock them in a variable, and after that I get every booking to match the delta time of the requests and booking to know if the hotel is availabled during this period of time.
Learn how to think like a Computer Scientist at https://brilliant.org/jakewright
In this video I build the device registry service as a Flask app in Python.
Code
https://github.com/jakewright/tutorials/tree/master/home-automation/02-device-registry
My actual home automation...
#hotel.py
#...
def get_hotels_db():
db = getattr(g, "_database", None)
if db is None:
db = g._database = shelve.open("hotels.db")
return db
#...
#booking.py
def get_booking_db():
db = getattr(g, "_database", None)
if db is None:
db = g._database = shelve.open("booking.db")
return db
class AskBooking(Resource):
def get(self, start_date, nights, rooms):
actual_date = datetime.date.today()
array_start_date = start_date.split("_")
start_date = datetime.date(int(array_start_date[2]), int(array_start_date[1]), int(array_start_date[0]))
if(start_date < actual_date):
return {'messages': 'Date not correct ', 'data':{}}, 404
if(nights <= 0):
return {'messages': 'Night can\'t be nul or negative', 'data':{}}, 404
if(rooms <= 0 ):
return {'messages': 'Rooms can\'t be nul or negative', 'data':{}}, 404
shelf_hotels = hotel.get_hotels_db()
keys = list(shelf_hotels.keys())
available_hotels = []
for key in keys:
if(shelf_hotels[key]['rooms'] == rooms):
available_hotels.append(shelf_hotels[key])
print(available_hotels)
shelf_booking = get_booking_db()
keys = list(shelf_booking.keys())
bookings = []
for key in keys:
print(shelf_booking[key])
# if(shelf_booking[key]['hotel_identifier'] in available_hotels):
# pass
# print("key :",key)
# print("shelf_booking[key] :",shelf_booking[key]['name'])
bookings.append(shelf_booking[key])
return {'message': 'Success', 'data': bookings}, 200
#This line is in an other file (__init__.py)
api.add_resource(booking.AskBooking, '/ask_booking/<string:start_date>/<int:nights>/<int:rooms>')
Sorry for the big message ^^
how would i make mysql query inclusive? like if i have a date range 11-08-2020 through 11-09-2020, mysql doesn't include datapoints on 11-09-2020 it excludes them
So here in my example when I want to read get_booking_db() it returns me hotels database (I go running i'll be comeback in 1hour)
are both datasets on the same db @modest arrow
if not you'd need to define new connections
*not
If anyone needs help with PostgreSQL let me know
@glass gorge That is because your column probably has a time value to it as well. So when you do 2020-09-11 it just assumes until the starting of that day.
So as you did not specify the time, your query just assume the beginning of that day and so is being interpreted as everything between: 2020-11-08 00:00:00 and 2020-09-11 00:00:00. This is why it leaves out everything on the day 11/09
So you should change the last date to 2020-09-11 23:59:59
thx
i saw that stack overflow post as well xD
I should have deleted my question
thank you thank you
You should leave the question, in case someone in the future ever searches through ctrl f
🙂
different servers have different expectations
someone shamed me for not having self control on another server
sqlite3.OperationalError: database is locked
someone can help me with this error
?
@glass gorge Ok thanks i'll try
I want to start database integration on my Discord Bot, but i don't understand it at all, anyone got any good tutorials/tips or someone who could help me with it?
I want to start database integration on my Discord Bot, but i don't understand it at all, anyone got any good tutorials/tips or someone who could help me with it?
sqlite3
i have my database hosted on my server and it has an assigned static ip
used cloudflare dns to point my db.domainname.com to that ip
but now i can't connect to the database with that host name
ping me if you have a solution. I just want to connect to my database via my subdomain address so i don't have to remember my server ip all the time
may I ask someone to give a version of the one below in analytic function?
This one is a self join if I'm not wrong but they said using self join is an anti-pattern and expensive and said it is better to use analytic function is instead.
SELECT w2.id
FROM Weather AS w1 JOIN Weather AS w2 ON DATEDIFF(w1.recordDate, w2.recordDate) = -1
WHERE w2.Temperature > w1.Temperature
hey so i'm new to this discord server, i'm not sure if this is the right place but long story short, I really need help with my python coding homework. I'm not goood at coding however I have to take it for my major and i was wondering if this is the right place to maybe get some help?
Im so in over my head with this class and I can't find any tutors around me
when connecting to my DB that is hosted on a vps(digital ocean ) i get this error. py psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "db-postgresql-****-*****-do-user-********-0.b.db.ondigitalocean.com" (1**.**.**9.***) and accepting TCP/IP connections on port 5432? how do i fix this?
please ping me
Let's say I have a table where I have to reset the value of a row at a specific time? How do I do this in Postgres?
Do I constantly check the time every second in a python script and then run the query once the time matches or can I schedule it in PSQL or do I run a cron job that executes the query?
@quartz tusk Use a Cron job
@fiery wedge If you need guidance or assistance you can always ask in the relevent help channels.
@torn sphinx Is your database on the same server as the code you are trying to access it from?
hi can someone explain why it has to be replaced? and what does the prefixes 'b' and 'p' mean?
and whether if it's okay to use the first method.
this is for sql ^
@modern parcel They are both the same queries, and will give you the same result.
The b, and p are just aliases for the table name. So for example, Book b makes the letter b represent the name Book. So now instead of writing the Book each time, you can just reference it as b. You could call this whatever you like, as its just an alias (temporary name for that table just for that query). You can also have aliases for columns as well.
con = psycopg2.connect(database='db', user='postgres', host='localhost', password='2628')
db = con.cursor()
print(db)
db.execute("""create table if not exists eventsData (
key int primary key,
channelName text,
embedDict text,
eventActive boolean
)""")
msg = 1
db.execute("INSERT INTO eventsData (key) VALUES (?)", (msg,))
obj = db.execute("select from eventsData *")
print(obj)
con.close()
``` i just switched from sqlite3 to postgresql why is it throwing an error
psycopg2.errors.SyntaxError: LINE 1: INSERT INTO eventsData (key) VALUES (?)
@hasty juniper try %s instead of ?
why what
why %s instead of ?
I want to start database integration on my Discord Bot, but i don't understand it at all, anyone got any good tutorials/tips or someone who could help me with it? (sqlite3)
use asyncio @torn sphinx
as in aiosqlite?
why
%sinstead of?
@hasty juniper because that’s the driver’s syntax
yes
Traceback (most recent call last):
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\discord\ext\tasks_init_.py", line 101, in _loop
await self.coro(*args, **kwargs)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\cogs\general.py", line 22, in reklama_jobs
query6 = await self.client.conn.fetchrow(sql8)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\asyncpg\pool.py", line 567, in fetchrow
return await con.fetchrow(query, *args, timeout=timeout)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\asyncpg\connection.py", line 477, in fetchrow
data = await self._execute(query, args, 1, timeout)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\asyncpg\connection.py", line 1445, in _execute
result, _ = await self.__execute(
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\asyncpg\connection.py", line 1454, in __execute
return await self._do_execute(query, executor, timeout)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\asyncpg\connection.py", line 1476, in _do_execute
result = await executor(stmt, None)
File "asyncpg/protocol/protocol.pyx", line 196, in bind_execute
asyncpg.exceptions.InsufficientPrivilegeError: permission denied for table queue
i don't want to give my bot superuser permissions to database
use
asyncio@torn sphinx
@hasty juniper You got any good tutorials on it? or any tips?
i didn't set superuser
no tutorials on it, only docs
alright.
@torn sphinx check https://github.com/omnilib/aiosqlite
Yeah I'm currently on that haha
@torn sphinx Is your database on the same server as the code you are trying to access it from?
@proven arrow yeah i got it a while ago thank you
If I were to change an Embed Color using Sqlite3 DB, as what should I save the TABLE Type?
Integer, Text, Blob, Numeric or real? I assume Numeric, but i'm not 100% sure
@torn sphinx embed colour of what?
Of an embed?
What's the data look like?
As in the table? or?
The data you want to store
Well i'm trying to store the value of a color basically, so let's say someone wants the embed color to be #7289da, then they use the command to set it as #7289da
and then the embed color will be that color that they chose
For a discord embed?
You can store it as an integer. However when you insert it you need to either insert the decimal value of the colour, or prepend the hex with 0x. This would be the easiest way since im pretty sure discord accepts these formats directly.
And how would I do it in the code? because right now i'm doing:
color = discord.Color.value
e = discord.Embed(
colour=int(result5[0]).format(color=color),
and i'm getting this as an error: https://gyazo.com/777113e6e435c0113ab7e692b15fb94c
And I already had a feeling that it wouldn't work
this is how it's stored
The "color" is an integer in the DB
Integers dont have #
with a 0x at the beginning
ic
For example, if you had the table colours
CREATE TABLE IF NOT EXISTS colours (id integer PRIMARY KEY, colour integer);
Then you can insert it as:
INSERT INTO colours VALUES(1, 0x7289da);
INSERT INTO colours VALUES(2, 0xF1D44A);
It would store it as the decimal value, however discord should accept the decimal value as the colour
im trying to make a custom prefix for my dbot with sqlite3
but i get the error TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not function
the code is def get_prefix(client, message): c.execute('SELECT prefix FROM prefixes WHERE guild_id=?', (message.guild.id,)) pre = c.fetchone() return str(pre)
Thats not a database issue, but discord.py
ok
with a
0xat the beginning
@proven arrow Even if I use the0xat the beginning, it still gives me that same error.
Show the error
Whats the column type in the db?
Integer
Then that should work, show the code how you get the value and set the colour
Theres 200 lines there, what am i looking at?
Right, sorry uh, Line 48-53
that's where I get the value, but i'm sure I did it wrong
and if on how I update the color in the DB is line 177-195
I just noticed that's the wrong code, since it's without the colorvalue thingy
Correct code^
Try colour=result5[0]
After you get the colour add print(type(result5[0])) and see the output
well it is according to the db
Then that would say integer
You can manually try converting to int. Try this: colour=int(result5[0], 16)
You need to restructure your code/queries. You are making 6 queries, to get the same info you can get in a single query.
I'm just starting to learn this, so it's all pretty new, i'm sure it'll improve over time haha
And dont use f strings for queries. Its one of the cause of sql injections (you can read up on this)
👍 I will, thank you
morning
Hey, so I have a table with lots of data points (userid, level, date). I want to get the last 3 datapoints of all users, is that possible with one query or do i need 1 for each user?
@frosty barn you can do that with a window function. Assuming that you mean the latest 3 data points based on date, your query will look like this:
select * from (
select *, rank() over (partition by userid order by date desc) as rank_val
from table_name
) t1 where rank_val < 4
The sub-query uses a window function called rank to assign a rank ordered by date in descending order. Since you need it for each user, the table is partitioned by userid, so the ranking will restart every time the userid changes.
In the outer query, you then filter rows where the rank, denoted by the column name rank_val, is less than 4
t1 is just a name assigned to the table returned by the subquery. t1 and rank_val are like variable names, you can use whatever you want in place of those.
I am using heroku pg:push to push my local database to Heroku.
I get the following error:
throw er; //unhandled error event```
What's the best way to fix this?
@tepid cradle Thanks a lot my man! <3 I will need to read a bit more about window functions but i think i understand
@frosty barn yes, window functions seem a bit complicated initially. I remember struggling with them for quite a while before I could understand how to use them. But once you get a hang of them, it will open an entirely new world of advanced SQL queries.
@tepid cradle sounds fun, any good tutorial for this?
or i should first learn basic sql. actually i know the basics but keep forgetting
i mean it doesnt stick
@torn sphinx I don't know any tutorials for this, mostly learnt by using them whenever I needed.
Usually things don't stick unless you are using them on a regular basis. So if you are interested in SQL, a good way to learn is to design a project around an SQL database (PostgreSQL is a good option) and use raw SQL queries rather than an ORM.
You'll obviously need a reasonable understanding of basic SQL before you're able to fully leverage window functions.
When creating a Python-SQLite program that utilizes a Database class to (1) connect, (2) make a cursor and (3) execute to an SQLite table, is it best for that Database class to create its Connection in the init function? (edited
hello, i installed mongoDB and i wanna execute mongo commands in jupyter notebooks how to do this?
Why is pg giving me this unrecognized data block type (0) while searching archieve
query1 = 'SELECT "owner_id" FROM ads WHERE "guild_id" = $1'
wynik1 = await self.client.conn.fetchrow(query1, ctx.guild.id)
wynikx1 = wynik1[0]
wynikx1 = wynik1[0]
NoneType object is not subscriptable
asyncpg
plz help me... 😦
@brazen charm bro can you help me with my thing?
I am trying to push my pg database pg:push to Heroku but it gives me the following error:
unrecognized data block type (0) while searching archieve
anyone has good suggestions for local efficient database?
Hello Everyone
I'm unable to run SQL queries in Python
using SSMS
can anyone please help?
row = await conn.execute("SELECT server FROM lmessages WHERE value = $1", ctx.guild.id)``` why is this not working? it is supposed to look for teh row but it isnt
I'm trying to list all customer names and SSN for customers who made no transactions in 2018.
I tried this:
SELECT customer.CustomerName, customer.CustomerSSN FROM customer INNER JOIN transaction ON customer.CustomerSSN = transaction.CustomerSSN WHERE YEAR(transaction.TransactionDate) <> '2018' ORDER BY customer.CustomerSSN
I'm still getting customers who made purchases in 2018, it just displays their transactions in other years, how do i fix this?
!code
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.
sql instead of py
@wet steeple
Also are you sure that YEAR function returns a string?
umm not sure?
its still the same
What dialect are you using?
mysql?
SELECT customer.CustomerName, customer.CustomerSSN
FROM customer
INNER JOIN transaction ON customer.CustomerSSN = transaction.CustomerSSN
WHERE YEAR(transaction.TransactionDate) != 2018
ORDER BY customer.CustomerSSN
I didn't really change anything but maybe it will work?
where?
yeah customer ssn is pk
like this?
SELECT customer.CustomerName, customer.CustomerSSN
FROM customer
INNER JOIN transaction ON customer.CustomerSSN = transaction.CustomerSSN
WHERE YEAR(transaction.TransactionDate) = 2020
ORDER BY customer.CustomerSSN
is it your expected output? 🤔
well it was 2018 but even for 2019 you can see that Duncan is still there who made transactions in 2019
but he also made transactions in other years
yeah im trying to list all customers’ name and SSN for the customers who have made no transaction in the year 2018.
ty so much for helping
@wet steeple i think i figured it out
!
select customer.* from customer
where 2019 != all (select year(transaction.TransactionDate) from transaction where customer.CustomerSSN = transaction.CustomerSSN)
group by customer.CustomerSSN;
I have no way to test it
Tell me what error you will get 🙂
its only showing the one person
hm ,sec
what was the condition
select all persons that didn't make any transactions in some year?
say 2019
poggers
You could make view out of it
whats view?
so basically you can create a function in sql and name it
get_cutomers_without_transactions_in_year(year_param int)
and call it like
select * from get_cutomers_without_transactions_in_year(2018)
np
how would i make my database look like this:
items:
"id": id,
"name": name
this is what i have:
and this is the code im trying:
self.config.update_one({"id": ctx.author.id}, {"$push": {"items": {"id": id, "item": item}}})```
in postgres is it possible to just append to the end of an array, or do I have to extract the array into a variable and then append the item (in python cause using python) ?? or is there an actual function?
hey guys, can somone help me with normal forms i have a table with 1 normal form can somone help me simplify it to 3rd normal form or 4 normal form
its seems very bulky right now
i thought about divding it by gender(but didnt seem right) or if they are over 18
hey is there a way to set the name of a mysql database from a variable?
all the times i have tried to do it i get syntax error
Are all dbs the same?
Are all dbs the same?
@torn sphinx in what way
@Cog.listener()
async def on_guild_join(self, guild):
if await self.bot.conn.execute(f'SELECT EXISTS(SELECT FROM config WHERE guild_id = {guild.id})') != True:
print("was true")
# set guild config
await self.bot.conn.execute('INSERT INTO config(guild_id, command_prefix) VALUES({guild.id}, \'..\')')
# insert any existing roles into database
for role in guild.roles:
await self.bot.conn.execute('INSERT INTO roles(guild_id, role_id, category, assignable, earnable, locked) VALUES({guild.id}, {role}, NULL, false, false, true)')
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "{"
I have zero clue what is happening, also VSCode says that the variable 'roles' is not used, even though it is...
discordpy btw
postgres
You should use query parameters
what do u mean, am i not?
No you are not
the schemas are already set up
It's nothing to do with schema
I dont understand, what do you mean then
wait i am not useinf f string
i just noticed
Yeah and don't use f strings either
damn always the little things that get me
A parameterised query is a way of precompiling a query and send it to the database. Also known as prepared statements. So this way you send the query with placeholders for the values , and then the database knows exactly the query you are wanting. Thereafter it just needs you to provide the parameters that might fit into that placeholder.
("SELECT * FROM table_name WHERE value=$1, 1234)
This is an example of how it should be done. The $1 is just a placeholder for the value that should go there (in example above the value is 1234). The database will know what value goes there after compiling it, and so if someone was to inject some SQL then it would simply not work.
@torn sphinx
oh, so with my code sql injection is possible?
If you are taking in user input then yeah or if someone was to change the data that you were inputting into the dB.
I'm confused though, so I have the table schemas set, and they know which type of data goes in each column.
await bot.conn.execute('''
CREATE TABLE IF NOT EXISTS roles(
guild_id bigint,
role_id bigint,
category varchar(32),
assignable boolean,
earnable boolean,
locked boolean
)''')
here is one
They can get that information, if they want again through injection.
Let me give you example
user_input = "1234" # the input you expect
user_input = "1234; DROP TABLE students;" # the input you actually received. Note the extra DROP TABLE command.
cursor.execute(f"SELECT * FROM students WHERE value={user_input}")
What do you think will happen there?
holy shit, I see
Yeah it'll drop that entire table as well as it gets evaluated as SELECT * FROM students WHERE value=1234; DROP TABLE students;
alright, i deff want to do what you were talking about earlier, I'll go look into it, it's called Parameterised Query?
Yeah
cool, thanks a bunch!
db = sqlite3.connect('settings.sqlite')
cursor = db.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS settings(
guild_id TEXT,
prefix TEXT,
)
''')```
looks like i have done a mistake
cursor.execute('''
sqlite3.OperationalError: near ")": syntax error```
woops found the error
@worthy pawn why are you dynamically creating dbs
what?
hey is there a way to set the name of a mysql database from a variable?
@worthy pawn
is there a reason why you cant just hardcode a name
yeh i guess but is there any way to set it as a varibale
You can although its not recommended
Btw do you mean as a parameterised query or as a formatted string?
I'm pulling data from an API and putting it into a list, is there a way to query the list against my mongo database and return values that don't match?
for valids in db.find({"name": {"$in": mylist}}, {'registrar': 1}):
print(valids)
How would I make this return the values that didn't match?
for valids in db.find({"name": {"$in": mylist}}, {'registrar': 1}):
print(valids)
Hello sorry for the silly question but how can I paste my code in such a stylish way?
Thanks a lot!
Hey what is this error
print(dict(data_))
ValueError: dictionary update sequence element #0 has length 4; 2 is required
code :
data_ = await conn.fetch(
'''SELECT * FROM people WHERE user_id = 707472976454483988'''
)
print(dict(data_))
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Pool' object has no attribute 'fetchall'
@eternal raptor what database and library?
postgresql, library: asyncpg
Ok, well then it doesn't have a method called fetchall
It has fetch, fetchval, and fetchrow
I know, but which command replace?
Use fetch() to get all the rows
File "C:\Users\Internet\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\topology.py", line 215, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 5fac137b3e07ea5ec664c510, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('exo-database-shard-00-00.auixs.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('exo-database-shard-00-01.auixs.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('exo-database-shard-00-02.auixs.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>
post = {"_id": "0", "Servers": "0"}
collection.insert_one(post)
``` I'm trying to post to a mongodb collection but I get this error
Hello everyone, can anyone recommend a book that teaches SQL using Python. Thanks in advance.
I know basic SQL commands and have base knowledge of SQL generally.
I'd appreciate them. Kindly DM me.
Guys, Could you help me?
if anyone knows mongo db
how do i check if a variable exists by id?
(i can probably find by loading all the variables but im not sure if thats efficient)
Guys, Could you help me?
@eternal raptor What is the value ofwynik1?
wait
index out of range means the value you are trying to index by is not there
For example, the below would give index out of range since there are only three possible indices:
x = [1,2,3]
print(x[10])
Do print(wynik1) before you index it and check its value.
Then probably that record doesnt exist for that query
to string ctx.author.send
bot send ('owner_id')
but i want to bot send owner_id
without ( ' ' )
so
what should i do?
Do
print(wynik1)before you index it and check its value.
ooo
ok
@proven arrow Thank you so much <3, guy. I will check values this method.
If I'm using sqlite to print a certain part of a database such as the genre of movies
How do i insert an input into the WHERE bit, if that is where it even goes
select * from movies where genre = 'horror';
I think?
oh wait, u want to get all the movies and their genres from the db?
select name, genre from movies;
you right don't need a where if u want all
or do you want to just gent a list of all genres that exist in the db @marble osprey ?
select distinct genre from movies;
Basically i want to be able to input the genre and it return every movie of that genre
ah then my first one was actually right
select name from movies where genre = 'horror';
assuming each movie has just the single genre, if there are multiple it depends on how you store it and queries get a bit more complicated...
I'm having other problems that are preventing me from even trying it
I think i will give up for now :/
@marble osprey what issue are you having?
It was telling me that execute was not an attribute or something
Can you show the code and error?
I've already turned off the computer
Sorry
count = f"{len(client.guilds)}"
post = {"_id": "0", "Servers": "0"}
results = collection.update_one({"_id": 0}, {"$set":{"servers":count}})
``` Does anyone know why this doesn't work?
it doesn't update the servers field in mongodb for some reason
@silk vortex Isnt the method updateOne? https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/#db.collection.updateOne
I see, well i dont use mongodb so not too sure about that then.
ok
@marble osprey when u get back to it, at very least it doesnt sound like the issue is with the query then*
sry for the ping 😛
Well i haven't been able to test the query
Although the line it is erroring on is after it
maybe you're trying to execute on the connection instead of the connection's cursor
not sure tho, but the query should not be the fault at least, good luck
maybe you're trying to execute on the connection instead of the connection's cursor
@zinc maple That does not matter
yeah that's what I wasn't sure about
just saw in my own code that I was getting the cursor and then executing on that, but it does ring a bell that it shouldn't matter you're right
Well yeah that is how its done. Its just that with connection.execute it would get an intermediate cursor object for you, and then call cursor.execute for you as well.
so i have 2 of the same dictionarys in my array, how would i just delete one and not all
I am trying to make an todo commands , this is how my function and command looks like
async def make_todo(self,ctx,entry:str):
values = f"{ctx.author.id}, {entry}, {int(datetime.now().timestamp())} , {ctx.message.jump_url}"
await self.bot.db.execute(f"INSERT INTO todos(owner_id, todo_content, timestamp , jump_url) VALUES {values}")
@commands.group(invoke_without_command=True)
async def todo(self,ctx):
await ctx.send("Something!")
@todo.command(name="create")
async def todo_create(self, ctx , * ,entry:str):
await self.make_todo(ctx, entry)
await ctx.send(f"{emote.check} | Your todo was successfully added to the list.")
this is the error I get
Ignoring exception in command todo create:
Traceback (most recent call last):
File "C:\python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\Rohit\Desktop\discord bots\timepass\cogs\utility\todo.py", line 28, in todo_create
await self.make_todo(ctx, entry)
File "c:\Users\Rohit\Desktop\discord bots\timepass\cogs\utility\todo.py", line 17, in make_todo
await self.bot.db.execute(f"INSERT INTO todos(owner_id, todo_content, timestamp , jump_url) VALUES {values}")
File "C:\python38\lib\site-packages\asyncpg\pool.py", line 518, in execute
return await con.execute(query, *args, timeout=timeout)
File "C:\python38\lib\site-packages\asyncpg\connection.py", line 295, in execute
return await self._protocol.query(query, timeout)
File "asyncpg\protocol\protocol.pyx", line 316, in query
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "548163406537162782"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\python38\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\python38\lib\site-packages\discord\ext\commands\core.py", line 1329, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "C:\python38\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\python38\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: PostgresSyntaxError: syntax error at or near "548163406537162782"
I think that's something with the database that's why i asked it here
this is how columns look like, when I create them
id column changes to integer and not null after I save
await db.execute("INSERT INTO eventsData (key,eventActive) VALUES (%s,%s)", (msg.content,0))
await db.commit()
``` why i have error
asyncpg.exceptions.PostgresSyntaxError
error near "%"
Use $1, $2 instead for placeholder
now i have Command raised an exception: InterfaceError: the server expects 2 arguments for this query, 1 was passed
HINT: Check the query against the passed list of arguments @proven arrow
await db.execute("INSERT INTO eventsData (key,eventActive) VALUES ($1, $2)", (msg.content,0,))
@hasty juniper Remove the brackets around the parameters. So, await db.execute("query", msg.content, 0)
but tuple
No
i get this when i insert into mongodb something with the motor library, <Future pending cb=[run_on_executor.<locals>._call_check_cancel() at C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\motor\frameworks\asyncio\__init__.py:80]>, can anyone tell me what this is?
How do I push to heroku without sslmode.
I do heroku pg:push db_name DATABASE_URL --app myapp but it usually fails when it comes to processing the data within the database. I think that's a security issue.
So, what's the best way to push without sslmode or any alternative to push my local database to heroku?
@proven arrow hey man, can you help me with this please?
How do I deploy my local database to Elephantsql, I couldn't find any tutorial on it?
@dull scarab can you please help me with this?
You can't deploy it unless they have an import feature
You can write a script that reads all the entries of your local db, then connects to the postgres db and inserts them
but you need to create the tables first
As far as I see, they don't.
Oh yeah that's a good idea.
Or I can just import a backup? let's me see.
then
- create the tables you need, either manually or with a script
- fetch all rows from your local db
- connect to the online db, and insert each row in the same order
I can just import a backup and that's it? what do you think, Floppy?
¯_(ツ)_/¯
Have't done much in this domain
i just knew of the host, and know that it works as a host
so if I wanted to host my own database that I could access, where would I start?
I already have somewhere to host, but I cannot find anywhere online to help me get started
If anyone can help me, please ping, as I would really like to get this started
If it is needed, the computer I will host at is Debian based
@clear elbow you want to host so you can access from an application that is running on that server?
or you want something different?
I unfortunately am running an application elsewhere, so it will have to be accessiblge from elsewhere
it looks like I will have to set up MySQL on the server
yes of course that is neccessity yes
but to allow other computer to connect, you have to allow the connection from the sql server setting file.
that makes sense
I am not finding a way to install it using the command line, as that is all I have access to
ummm ok, let me see if i can find the command i used
you are on debian 10? @clear elbow
yes
ok so make follow this guide, https://www.digitalocean.com/community/tutorials/how-to-install-the-latest-mysql-on-debian-10
has all command inside
I am currently downloading it
mysql-apt-config pre-depends on lsb-release
lsb-release is not installed.
dpkg: error processing archive mysql-apt-config_0.8.16-1_all.deb (--install):
pre-dependency problem - not installing mysql-apt-config
Errors were encountered while processing```
This is the error I get when I run
`sudo dpkg -i mysql-apt-config*`
finally got it
hey guys can anyone help me with a sql select statement
i got it working but my method needs 5 select statements which takes a long time and isnt efficient at all
here is my selects: ```
routes = db.run('SELECT Route, COUNT(Route) AS count FROM hits WHERE Domain = %s AND Timestamp BETWEEN %s AND %s GROUP BY Route', (domain, d1, d2))
browsers = db.run('SELECT Browser, COUNT(Browser) AS count FROM hits WHERE Domain = %s AND Timestamp BETWEEN %s AND %s GROUP BY Browser', (domain, d1, d2))
locations = db.run('SELECT Location, COUNT(Location) AS count FROM hits WHERE Domain = %s AND Timestamp BETWEEN %s AND %s GROUP BY Location', (domain, d1, d2))
screens = db.run('SELECT Device, COUNT(Device) AS count FROM hits WHERE Domain = %s AND Timestamp BETWEEN %s AND %s GROUP BY Device', (domain, d1, d2))
referrals = db.run('SELECT Referrer, COUNT(Referrer) AS count FROM hits WHERE Domain = %s AND Timestamp BETWEEN %s AND %s GROUP BY Referrer', (domain, d1, d2))```
this is the table: CREATE TABLE IF NOT EXISTS hits ( ID INTEGER PRIMARY KEY AUTO_INCREMENT, Domain TEXT NOT NULL, Route TEXT NOT NULL, Timestamp INTEGER NOT NULL, Browser TEXT, Location TEXT, Device TEXT, Referrer TEXT )
i need to select the count of location, device, referrer etc where the domain is == "whatever"
Code line 2```
Heroku:
2020-11-12T14:19:47.776494+00:00 app[worker.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2020-11-12T14:19:47.776494+00:00 app[worker.1]: TCP/IP connections on port 5432?```
@commands.command(name="set-update")
@commands.guild_only()
@commands.is_owner()
async def set_update(self, ctx, *, update=None):
if update is None:
db = await self.bot.db.fetch("SELECT * FROM botinfo")
get_news = db["update"]
return await ctx.send(f"Current Bot update is\n\n``{get_news}``")
get_db = await self.bot.db.fetchrow("SELECT update FROM botinfo")
if get_db is None:
await self.bot.db.execute("INSERT INTO botinfo(update, time2) VALUES ($1, $2)", update, datetime.utcnow())
return await ctx.send(f"{emote.check} | Successfully updated bot-update.")
await self.bot.db.execute("UPDATE botinfo SET(update, time2) VALUES ($1, $2)", update, datetime.utcnow())
return await ctx.send(f"{emote.check} | Successfully updated bot-update.")
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: PostgresSyntaxError: syntax error at or near "VALUES"
this is my table
Your update syntax is wrong
See the correct syntax here, https://www.w3schools.com/sql/sql_update.asp
And you might want to add a WHERE clause, if you dont want it to update all the rows
what do i put after WHERE?
i mean there will be only 4 column
And you might want to add a WHERE clause, if you dont want it to update all the rows
columns and rows are different
Ok, i'm running this query: SELECT id, name, description, author FROM ``todos``WHERE id=1; on this database schema: sql CREATE TABLE todos ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, description TEXT NOT NULL, author TEXT NOT NULL )
But I just get all the results
wait nvm now it works
@shrewd geyser what error appears if you try to pip install asyncpg?
I forgot what it was so let me try and pip it again
what is the problem?
!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.
@wintry stream https://paste.pythondiscord.com/ekirudaruw.php
@ember turret Thats the error I get
Doesn't what
doesn't need requirements
Ohh, then I have no idea why it won't work
Installation
asyncpg has no external dependencies and the recommended way to install it is to use pip:
$ pip install asyncpg
Should I down grade to 3.8?
waiting for 3.9.0 to unistall....
hello i just started using python so could anyone tell me what to learn first
basics, and this is the wrong channel
i have a problem
<html lang="de" dir="ltr">
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
if(isset($_POST["submit"])){
require("mysql.php");
$stmt = $mysql->prepare("SELECT * FROM account where USERNAME = :user"); //UserName
$stmt->bindParam(":user", $_POST["username"]);
$stmt->execute();
$count = $stmt->rowCount();
if($count == 1){
$row = $stmt->fetch();
if(password_verify($_POST["password"], $row["PASSWORD"])){
session_start();
$_SESSION["uesername"] = $row["USERNAME"];
header("Location: search.php");
} else {
echo "Login Error1";
}
} else {
echo "Login Error";
}
}
?>
<form action="index.php" method="post">
<div class="login-box">
<h1>Login</h1>
<div class="textbox">
<input type="username" placeholder="Username" name="username" required><br>
</div>
<div class="textbox">
<input type="password" placeholder="Password" name="password" required><br>
</div>
<input class="btn" type="submit" name="submit" value="Log In">
</div>
</form>
</body>
</html>```
= index.php
```<?php
$host = "localhost";
$name = "database";
$user = "mysql-admin";
$passwort = "C0mmander admin";
try {
$mysql = new PDO("mysql:host=$host;dbname=$name", $user, $passwort)
} catch (\PDOException $e) {
echo "SQL Error: ".$e->getMessage();
}
?>```
mysql.php
```<?php
session_start();
if(isset($_SESSION["username"])) {
header("Location: index.php");
exit;
}
?>
<!DOCTYPE html>...```
and search.php
when i enter a correct username and password in index.php then i want to go to search.php . BUt i stay on the same site and the loginbox disapears
why?
how can I create a database in python with oracle?
hi
I'm trying to figure out how to use an Access file and upload its tables to a database where I can run a query
I need to automate this with minimal scripting
Hello everybody, I learn Flask-AppBuilder and I try to setup a "custom" database query in a decorator (@render) in a model.py. Someone knows how to call sqlalchemy on top of FAB ?
How can i put dict in postgres ?
How can i put dict in postgres ?
@hasty juniper there are JSON fields
but I would advise thinking about whether you can avoid doing so
it try put in json but discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DataError: invalid input for query argument $1: {'color': 4010, 'type': 'rich', 'descrip... (expected str, got dict)
oke
i fix that
Thx
Hi, I have a problem: I know that there is no such data in the table and I would like Python to not throw an error anyway: 'NoneType' object is not subscriptable, or what is the result1 = query1 [0] it displays error 'index list out of a range 'because there is no data there, but I know ... I want it to display None instead. I have this condition: if result1 is None:
It won't do it for me because it crashes the first or second error, it depends which one prints, and I'd like it to just treat result1 or resultx1 as None instead
code snippet:
query1 = 'SELECT "owner_id" FROM oferty WHERE "guild_id" = $1'
wynik1 = await self.client.conn.fetch(query1, ctx.guild.id)
wynikx1 = wynik1[0]
if ctx.message.author.id == ctx.guild.owner_id:
if ctx.message.mention_everyone in ctx.message.content:
if ctx.guild.owner_id in wynikx1:
sql01 = 'SELECT "owner_id" FROM blacklist WHERE "guild_id" = $1'
wynik01 = await self.client.conn.fetch(sql01, ctx.guild.id)
sql02 = 'SELECT "owner_id" FROM owners WHERE "guild_id" = $1'
wynik02 = await self.client.conn.fetch(sql02, ctx.guild.id)
sql03 = 'SELECT "owner_id" FROM oferty WHERE "guild_id = $1"'
wynik03 = await self.client.conn.fetch(sql03, ctx.guild.id)
wynik001 = wynik01[0]
wynik002 = wynik02[0]
wynik003 = wynik03[0]
Here I just gave a little more code so that there were more examples of indexes and I mean the third if, even if I put the result1 instead of resultx1, the effect is the same, but it will not stick to the index that it is out of range (as if this data were in the table, it would not stick to it, because now it is not there and points to Null (in python None)), it would stick to NoneType object is not subscriptable.
Do you have ideas about other queries or some changes in the code?
I'm using PostgreSQL, asyncpg (asyncio postgresql library for python), discord.py
second code snippet:
cant find at the moment but it was:
if result wynikx1 is None:
# do ... code
It will crash that list index out of a range
if it was instead of resultx1 -> result1
that would give 'NoneType object is not subscriptable'
I have my database on Elephantsql and I am trying to remotely connect to my bot.
I always get this error:
is the server accepting tcp/ip connections on port 5432 elephantsql
What's the best way to fix this?
Hii :)
Can anyone suggest any alternative to Popsql?
I am trying to install Popsql but, not working... And, also it's expensive..
@dreamy cedar maybe sqlite or Postgres?
I mean, I am using MySQL... But, I need some IED for better interaction because using Terminal is not easy 😅😅
@dreamy cedar maybe
sqliteorPostgres?
@lime echo I tried Popsql but, I feel i can't use it and have some issues 😞
@dreamy cedar yeah try something else.
If the database is small, just use sqlite3.
like I think
what @dreamy cedar is asking
is what database explorer/GUI to use
not what RDBMS
not what RDBMS
@shell ocean right..
@dreamy cedar ``WorkbenchorphpMyAdmin`.
It has a free plan as far as I know. @dreamy cedar
Do you have XAMPP? I think that I have a better solution for you.
If you have XAMPP just run your MySQL then open your browser and go to localhost/phpmyadmin. (that's it!)
Honestly speaking, i am just beginning to learn about DB... But, I will do as you say..
Never hear of XAMPP.. Let me Google it..
Hah, it's OK!
pgAdmin4 stucked in loading screen, anyone know the solution for it?
@torn sphinx just shut it down then restart it.
Oh, I don't know how to fix it to be honest. @torn sphinx
Maybe just reinstall it or something.
Yeah reinstalled and not worked lol, anyway thanks
I'm gonna grab a help channel
how can i get logs from heroku postgre database
or is there a way to check logs on heroku?
hi, im using pyodbc to connect to ms sql server, is there any way to do this asynchronously
ping me if u have an answer
hi im pretty new to databases i want to make a login system with username password and hwid how can i ask for them ??
def login():
mycursor = mydb.cursor()
print('Enter username: ')
username = input()
mycursor.execute('SELECT username FROM oasisacc WHERE username=?', (username,))
checkUsername = mycursor.fetchall()
if checkUsername != 0:
print('Username does not exist')
else:
print('Logged In!')
thats where im at currently
i made one, using text channels
wdym?
@proper totem what module are u using?
mysql.connector
try giving a wrong username, and print the result
i tried it doesnt even give me a answer its just an error
Hi, I have a problem: I know that there is no such data in the table and I would like Python to not throw an error anyway: 'NoneType' object is not subscriptable, or what is the result1 = query1 [0] it displays error 'index list out of a range 'because there is no data there, but I know ... I want it to display None instead. I have this condition: if result1 is None:
It won't do it for me because it crashes the first or second error, it depends which one prints, and I'd like it to just treat result1 or resultx1 as None instead
code snippet:
query1 = 'SELECT "owner_id" FROM oferty WHERE "guild_id" = $1'
wynik1 = await self.client.conn.fetch(query1, ctx.guild.id)
wynikx1 = wynik1[0]
if ctx.message.author.id == ctx.guild.owner_id:
if ctx.message.mention_everyone in ctx.message.content:
if ctx.guild.owner_id in wynikx1:
sql01 = 'SELECT "owner_id" FROM blacklist WHERE "guild_id" = $1'
wynik01 = await self.client.conn.fetch(sql01, ctx.guild.id)
sql02 = 'SELECT "owner_id" FROM owners WHERE "guild_id" = $1'
wynik02 = await self.client.conn.fetch(sql02, ctx.guild.id)
sql03 = 'SELECT "owner_id" FROM oferty WHERE "guild_id = $1"'
wynik03 = await self.client.conn.fetch(sql03, ctx.guild.id)
wynik001 = wynik01[0]
wynik002 = wynik02[0]
wynik003 = wynik03[0]
Here I just gave a little more code so that there were more examples of indexes and I mean the third if, even if I put the result1 instead of resultx1, the effect is the same, but it will not stick to the index that it is out of range (as if this data were in the table, it would not stick to it, because now it is not there and points to Null (in python None)), it would stick to NoneType object is not subscriptable.
Do you have ideas about other queries or some changes in the code?
I'm using PostgreSQL, asyncpg (asyncio postgresql library for python), discord.py
second code snippet:
cant find at the moment but it was:
if result wynikx1 is None:
# do ... code
It will crash that list index out of a range
if it was instead of resultx1 -> result1
that would give 'NoneType object is not subscriptable'
hi, im using pyodbc to connect to ms sql server, is there any way to do this asynchronously
I'm getting very often this error => http://sqlalche.me/e/13/2j85 I tried the pool_pre_ping thing, pool_recycle, etc... nothing seems to work, any suggestion ?
result = await collection.update_one({'_id': 0}, {'$set': {'servers': count}}) I'm trying to use motor to update my server count on a database but it isn't working for some reason. I'm trying to update my database with my servercount but it isn't.
bank = await conn.fetchrow('SELECT bank FROM economy WHERE id=$1', ctx.author.id)
the way i do it is like fetchrow("SELECT * FROM economy WHERE user_id = $1)
i set that to a var for example user
and i index it
no like user = <urbotvar>.fetchrow("SELECT * FROM economy WHERE id=$1")
and i index user
for example
user['money']
Ohh
you could try doing that
what did you do
balance = await conn.fetchrow('SELECT * FROM economy WHERE id=$1', ctx.author.id)
did you index it
wot
@finite ice VS Code is being weird
wdym
I fixed it
alr
@finite ice It worked thx
np
#databases message Can someone help me please?
Please explain what you mean by isn't working
it's not updating
it's just staying the same
I don't get an error either
@earnest parcel
dbclient = motor.motor_asyncio.AsyncIOMotorClient("mongodb+srv://my_username_and_password@exo-database.auixs.mongodb.net/exo-database?retryWrites=true&w=majority")
db = dbclient['exo_database']
collection = db['Servers']
this is the connection code
I have this code ```conn = sqlite3.connect("amounts.db")
c = conn.cursor()
# create a table
c.execute("""CREATE TABLE IF NOT EXIST amounts
(id TEXT, amount REAL)""")
conn.commit()``` which is meant to create a table, but I'm getting an error: `sqlite3.OperationalError: near "EXIST": syntax error`. Anyone have a fix?
@idle storm Exist is plural, so should be EXISTS
anyone here know how the repl database works
I saw, thank you!
Got another error tho
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS amounts (userid TEXT, amount INT)""")``` I used this code to make a table. However, when I try to insert values to it, I get this error: ```c.execute("INSERT INTO amounts (userid, amount) VALUES (?, ?)",(id, 100))
sqlite3.OperationalError: table amounts has no column named userid``` Anyone got a fix? Ping me with ur answer please
I'm tryna make a table with 2 columns, userid and amount. I then want to put a given user id with the variable id and a int of 100 into said table for context.
Do you have any idea @proven arrow?
@finite ice You still online?
Is this valid SQL ```py
await conn.execute('''UPDATE guilds(prefix) SET VALUE($2) WHERE id=$1''', ctx.guild.id, 'l!')
wtf is wrong with this, once it works, once it doesn't work (0 errors)

ALTER TABLE Users RENAME TO Test; I'm trying to do this but it says users relation is not found. The table name is Users so I'm not sure why this is happening.
Question
I know i could look this up on youtube but id rather hear it from you guys whats a good module for local databases?
i wanna get the hang of it before i start using it for active ones over the web.
@lime echo could help me.. I am getting this error when I am trying to open
loaclhost/phpmyadmin/
@lime echo could help me.. I am getting this error when I am trying to open
loaclhost/phpmyadmin/
@dreamy cedar
Or anyone know fix this?
@hazy shore : could you please help me to fix this 😞
I know i could look this up on youtube but id rather hear it from you guys whats a good module for local databases?
@merry arch i use mysql - mysql.connector module
you can use PostGRE SQL too
i dont think there is a lot of difference
but how do i get error logs of postgre db in heroku? using asyncpg
@lime echo could help me.. I am getting this error when I am trying to open
loaclhost/phpmyadmin/
@dreamy cedar sure you will get an error because you need to install XAMPP and launch it in order to use that.
Give me a moment.. Let me do that
@dreamy cedar sure you will get an error because you need to install XAMPP and launch it in order to use that.
@lime echo any official website?
@lime echo getting this error massage...
@lime echo getting this error massage...
@dreamy cedar idk what's that lmao but it sound like u cant install it because of UAC
Ya.. What to do? 😞
Try to solve it. Search on google or smth.
Does it look something like this?
I cant help you a lot today since in not that free... I have a bunch of stuff to do.
wtf is wrong with this, once it works, once it doesn't work (0 errors) :PEPE_hands: :PEPE_rope:
@noble root siema 🙂
Did it work?
Hi, I have a problem: I know that there is no such data in the table and I would like Python to not throw an error anyway: 'NoneType' object is not subscriptable, or what is the result1 = query1 [0] it displays error 'index list out of a range 'because there is no data there, but I know ... I want it to display None instead. I have this condition: if result1 is None:
It won't do it for me because it crashes the first or second error, it depends which one prints, and I'd like it to just treat result1 or resultx1 as None instead
code snippet:
It's okay :).. Yaa.. It showing me it's installing
query1 = 'SELECT "owner_id" FROM oferty WHERE "guild_id" = $1'
wynik1 = await self.client.conn.fetch(query1, ctx.guild.id)
wynikx1 = wynik1[0]
if ctx.message.author.id == ctx.guild.owner_id:
if ctx.message.mention_everyone in ctx.message.content:
if ctx.guild.owner_id in wynikx1:
sql01 = 'SELECT "owner_id" FROM blacklist WHERE "guild_id" = $1'
wynik01 = await self.client.conn.fetch(sql01, ctx.guild.id)
sql02 = 'SELECT "owner_id" FROM owners WHERE "guild_id" = $1'
wynik02 = await self.client.conn.fetch(sql02, ctx.guild.id)
sql03 = 'SELECT "owner_id" FROM oferty WHERE "guild_id = $1"'
wynik03 = await self.client.conn.fetch(sql03, ctx.guild.id)
wynik001 = wynik01[0]
wynik002 = wynik02[0]
wynik003 = wynik03[0]
Perfect good job!
Here I just gave a little more code so that there were more examples of indexes and I mean the third if, even if I put the result1 instead of resultx1, the effect is the same, but it will not stick to the index that it is out of range (as if this data were in the table, it would not stick to it, because now it is not there and points to Null (in python None)), it would stick to NoneType object is not subscriptable.
Do you have ideas about other queries or some changes in the code?
I'm using PostgreSQL, asyncpg (asyncio postgresql library for python), discord.py
second code snippet:
cant find at the moment but it was:
if result wynikx1 is None:
# do ... code
It will crash that list index out of a range
if it was instead of resultx1 -> result1
that would give 'NoneType object is not subscriptable'
Please not spam.. You might going to get warning 😬
Perfect good job!
@lime echo any link to setup XAMPP?
:/
I have repaired this since 1 week
I mean any good article..
@dreamy cedar google bro
😅 👌
Sorry for spamminf, but I really dunno what could I do if repair this.
data_ = await conn.fetch(
'''SELECT user_id FROM users'''
)
print(data_)
if 536875405819379733 in data_:
print("Working as expected")
else:
print("NOPE!!!!")
So this gives [<Record user_id=302281963455250434>, <Record user_id=707472976454483988>, <Record user_id=575252669443211264>, <Record user_id=536875405819379733>]
as the output, and 536875405819379733 is there but why does it print NOPE!!???
Because its a list of Record objects. The integer is not directly in that list like that.
You can take a look at https://magicstack.github.io/asyncpg/current/api/index.html#record-objects to see the operations you can do on the Records.
ohh ok thx a lot for that
that's for fetchrow though, and when I do fethcrow it only gives one value but there are 4
<Record user_id=302281963455250434>
Your query is asking for only 1 column, and fetchrow gives a single row, so that is the correct result your getting
@eternal raptor I don't understand what your issue is?
@proven arrow but table hasn't data and bot send: x = wynik1[0]
if x is None:
IndexError: List index out of a range
if wynik1 is None:
'NoneType' object is not subscriptable
I know, that is None, but i want to bot execute this if is None: do code
But bot doesn't want execute this.
@eternal raptor Then why cant you do it like this?
if not wynik01:
print("No value")
else:
wynik001 = wynik01[0]
You can also do fetchval since you are only requesting a single column value, and this way you wouldnt have to subscript it to get the value.
So you want 5?
In the example you gave, you can do something like:
sorted_results = sorted(my_dict, key=lambda x: (my_dict[x]['level']), reverse=True)
The above sorts by level by level, but if 2 dicts have the same level, and so if you want to sort by the xp, you can do the below:
sorted_results = sorted(my_dict, key=lambda x: (my_dict[x]['level'], my_dict[x]['exp']), reverse=True)
sorted_results will contain the list of keys sorted. Then you can use these keys to access elements of that dict. Maybe there might be a better/more efficient way to do this in python, but then you should ask that in another channel, since your question is not entirely Database related.
Get the first element of that list by index
first = sorted_results[0]
how to use add_log_listener in asyncpg module?
with dpy
do i define it as an event?
Unhandled exception in internal background task 'reklama_jobs'.
Traceback (most recent call last):
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\discord\ext\tasks__init__.py", line 101, in _loop
await self.coro(*args, **kwargs)
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\cogs\general.py", line 41, in reklama_jobs
await channel.send(f"Reklama właściciela: {query1} \n\n {query3}")
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\discord\abc.py", line 904, in send
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
File "C:\Users\sebik\Desktop\discordbot\NinjaManager\venv\lib\site-packages\discord\http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
Bot send a message only once and next... error
Guys, anyone know ?
insert = await connection.execute('insert into "public"."Join" (guild_id) values ($1)', guild_id)
values = await connection.execute('select guild_id from "public"."Join" where guild_id = $1', guild_id)
await ctx.send(values)
```I have this code and it works but is there a way I can return the actual data instead of `Select 1`?
I'm using asyncpg to contact a postgresql database
@silk vortex You need to use fetch when you want to get some data from the database, instead of execute. You can use fetch to get all rows, fetchrow to get a single row, or fetchval to get a single value. See the method here in the documentation, and also have a read of the two functions under it. https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.connection.Connection.fetch
oh ok
Thanks!
@proven arrow I have a question. I'm trying to do an enable command for my on_member_join. So, would each column be a server ID or would I name one column as guild_id and 1 column as channel_id?
What is an enable command?
like so a server owner can enable the join message. Once they enable it, they can get the join message in their server through my bot
I'm doing this for my bot btw
Well you would need to know which channel to send the message to so you would need to have a column for the channel id as well then
id | guild_id | channel_id | message should be the bare minimum you should store. Im not sure what other data is required for that process/command.
oh
I don't have the id column
but I was thinking of having the guild_id replace the id column
Well that was just me implying thats a Primary Key. You can have the guild_id as the Primary Key column instead
That would work also
Does sqlite support order by similarity? I know postgres supports it but there's small differences so i'm not sure
is anyone here good at using google sheets as a database? if so
im trying to check for a certain string in a column and once i find the column i want to get the row is that possible?
await con.execute(f"CREATE TABLE {name}("
f"userid numeric NOT NULL,"
f"points numeric NOT NULL,"
f"coins integer,"
f"items text[],"
f"PRIMARY KEY (userid)"
f")"
f"WITH (autovacuum_enabled = True)")
this is driving me insane it keeps saying syntax error at create i dont understand :/
await con.execute(f"CREATE TABLE {name}(" f"userid numeric NOT NULL," f"points numeric NOT NULL," f"coins integer," f"items text[]," f"PRIMARY KEY (userid)" f")" f"WITH (autovacuum_enabled = True)")this is driving me insane it keeps saying syntax error at create i dont understand :/
@trim knoll
Dont use format strings, use the execute parameters (should be in the library docs) if I recall it handles sql escape characters.
is there a way i can set the min to 0 for an int in mongodb
to make sure it doesnt go negative
Can't you check that directly in your python code?
this is driving me insane it keeps saying syntax error at create i dont understand :/
@trim knoll
When you're not using any variables, why are using f strings? Why not just plain string?
And for the error, for multi-line string, you either need a backslash at the end of every line, or start the string with triple quotes.
@trim knoll
Dont use format strings, use the execute parameters (should be in the library docs) if I recall it handles sql escape characters.
@sharp nest execute params dont work with the table name
@trim knoll
When you're not using any variables, why are using f strings? Why not just plain string?
And for the error, for multi-line string, you either need a backslash at the end of every line, or start the string with triple quotes.
@tepid cradle i am using variable for the table name, and the backslashes are redundant the indentation takes care of it. my error is query related not db related. moreover i have done similar stuff before this is the first time i am facing this stupid error
await con.execute("""
CREATE TABLE name(
userid numeric NOT NULL,
points numeric NOT NULL,
coins integer,
items text[],
PRIMARY KEY (userid)
)
WITH (autovacuum_enabled = True)
""")
tried, still the same error
Can you show code for that function you are running? Your error also seems to be showing another query in it
Can I use sqlite3, but make it so it sends the data to a database on another device?
Like if it's a public "application" (so other people can download it to their pc), that needs to save information. Then it saves the information somewhere online, or on my pc.
Hey everyone,
I want to store YouTube links with their title (mostly songs) associated with each user. For example : suppose a person named "A" has four songs in his playlist and the structure would looks like
{
'A':
{
'crawling': <YouTube link>,
'faint': <YouTube link>,
'Nothing else matters': <YL>
}
}
Here, I am not sure which method would be best to store and retrieve these links faster. I know about JSON obj but how will I create or store songs for Different users.. a nested dicitionary in json file or sql database ??
@torn sphinx sqlite isnt a network database, it cant communicate over a network
alright
You could have clients communicate with a web service, which would communicate with sqlite, but you would have to consider if you really want to do that
@steady lava You can store it in a database. There are SQL and NoSQL ones, and even most SQL dbs allow you to store JSON data as a column type as well.
@proven arrow thanks for replying ..
Actually I was thinking to create N number of json files for N number of users (if they want to save the playlist) is it okay to do so, and yes why SQL is more preferable than JSON ?
SQL will allow you to query the data. As an example, you could do something like "get me all the users who have song x in their playlist". Although this can still be done with your programming language, its not always as efficient/so easy to do especially if the data grows, whereas SQL is made to query such things. Also say you define you json structure to be like you do now, however in the future there is a need to maybe capture some extra data, then what do you then do with all of your current JSON objects, because updating these can be problematic, whereas with a DB its relatively straight forward. Also managing all these files for each user sounds really inefficient too, especially if your users will be rising. And have a read of this. #databases message Also you should just try googling it, because there will be plenty of more reasons to help you decide, and sometimes I find it difficult to get my message across with the language barrier. @steady lava
Hi, so i make tables some time ago. One table called Products, and another OrderItems. Now the id in Products table is the PK, and was used to link the table to order items. This ID is also the product code of the internal Product items. Now there is a need to change the Product IDs for some products, but as you might imagine this will cause issue because will also change order IDs on the orderitems table?
Easiest way would be to add an extra column to store the product ID. So something like product_id, and then use this to store your internal product ID values.
That way you wont be changing the id field, and those relations would stay as they are. So changing the product id, from here onwards would be just like changing the description or some other value (i.e. it wont affect the other data).
Maybe if you have a front end, then just change it so from now on it shows the value of the new column as the product id
Can you show code for that function you are running? Your error also seems to be showing another query in it
@proven arrow dammit you were absolutely right, the error was somewhere else. It was in the parent command (i am using dpy lib) and having some code in it was messing up the create table stuff in sub command
i should read my tracebacks better lol, thank you
Ahhh ok yes thats an easy fix, and help me understand better. Thanks so much i was worrying that someone at my work, will shout at me for this bad design i made 😅 . Thanks very much @proven arrow , i will have to just add this extra column.
Are you trying to connect on localhost?
If so then just use localhost as the host name
Then make sure that user exists, and has access to the database
oh ok
@proven arrow thank you very much for your answer. It makes sense now why sql is more preferable than using JSON, yeah JSON is just like any other dictionary object in python, only the difference is between dict objects in python store in memory at run time and then destroyed once the python process terminates, while we can save this dict. Object into a JSON file for later purpose.
I was planning to use sql but right now I don't have any experience with it.. so this might be a good chance to learn by implementing it. Also, Different JSON files for Different user is not so good idea hm.. it just increases memory, suppose having more than 5 users running the same CLI music player, and each have their own config files or playlist file. .
reading back a bit @trim knoll from your error one thing very clearly that i can see is that you are using fstrings for your queries
this is VERY dangerous and allows for SQL injection
Websites can still be hacked using SQL injection - Tom explains how sites written in PHP (and other languages too) can be vulnerable and have basic security issues.
More from Tom Scott: http://www.youtube.com/user/enyay and https://twitter.com/tomscott
Follow the Cookie Trai...
always use SQL arguments, don't use fstrings/format
@proven arrow i created new use and grant all permission, so it's working now
uh do i put this here?
So i want to look for a item in inventory with this code for thing in users[str(user.id)]["inv"]: n = thing["item"] a = thing["amount"]
but i want it to only look for the item fishingrod. how can i do that?
right now it scans al the items but i want to make it so it only looks for fishing rod and the ammount of fishingrods a person has
{"728265216453771274": {"wallet": 12839.0, "bank": 0, "inv": [{"item": "apple", "amount": 1}, {"item": "fishingrod", "amount": 0}]}
im using json btw
@trim knoll fair, i saw f string and was like "wtf" .
consider using sqlalchemy, makes it all nice and easy. https://docs.sqlalchemy.org/en/14/core/metadata.html
Is there a good method to updating a row where you may not know the data that changed? For example:
UUID | x | y | z | abc
The UUID wont change, but x, y, z, or even abc may change. However, you are just giving a block of data that contains x, y,z, and abc with no clue as to what changed.
I could just do on conflict do update set literally every single column but that just seems...inefficient?
anyone who uses asyncpg can help me?
async def add_new_value_to_db(name):
db_connection = await asyncpg.connect(host=host,
password=password,
user=user,
port=port,
dsn=dsn,
database=database)
try:
await db_connection.execute("CREATE TABLE IF NOT EXISTS BOTGAMEDB(Name TEXT(30) PRIMARY KEY,POINTS INT(10) NOT NULL,DEFAULT POINTS = 500)")
except:
pass
try:
await db_connection.execute(f'INSERT INTO BOTGAMEDB VALUES("{name}",500)')
await db_connection.commit()
except:
pass
await db_connection.close()
i call this function from a discord.py command
yes
what is you'r problem
it doesnt create the table
huh?
tuple
no it doesnt create the table in the database
ah
Syntax Error?
so i dont know how to get errors
I am not use asyncpg module
ahh ok
How do you make a database? (So people can download your program and add to the database)
IF thats possibly
what sort of database?
ahh ok
not for a website though
but first you gotta learn mysql
how do you make a discord bot with python
@torn sphinx easy
how do you make a discord bot with python
@torn sphinx #discord-bots
ok
i would suggest learning postgre for dpy tho
import mysql.connector
mydb = mysql.connector.connect(
database = "str_fivem",
host = "localhost",
user = "root",
password = ""
)
database = mydb.cursor()
def p(text):
print(text)
def str_reg(banned):
banned = input()
if banned == "1":
p("Succes")
str_sql = ("UPDATE vrp_users SET banned = '0' WHERE id = '%s'")
database.execute(str_sql, (banned))
mydb.commit()
else:
p("failed")
return banned```
UPDATE vrp_users SET banned = '0' WHERE id = '%s'```
why redef print for less readability?
it's not changing to 0
@ashen lintel Your statement is adding quotes where not necessary. Since you already have a placeholder (should be %s not #s), you don't ALSO need ''
@pseudo summit
