#databases
1 messages ยท Page 72 of 1
oh
same procedure
hm
ok
one sec
ok
done
by the way, thanks for helping me with this. takes a lot of patience i presume.
now, how the hell do i go about everything else is the question.
No problem man, I remember having to go through this myself as well...
It gets confusing.
now, how the hell do i go about everything else is the question.
Depends on what 'everything else' is ๐
like
querying
and
just
adding items, etc
more importantly, using the references (foreign keys)
Looking up material for that
ah
Cause I'm not actually sure if they automatically update for that, since I use an ORM
And it's all automatic there ๐
Fair enough ๐
Looking for help on off-topic mySQL stuff
hey guys
can you guys help me
what is wrong with this ```@client.command()
async def auth(ctx, playerAuth: str):
mycursor = mydb.cursor()
sql = "SELECT COUNT(*) FROM playeraccount WHERE playerAuth = %s"
mycursor.execute(sql, (playerAuth,))
myresult = mycursor.fetchone()
for x in myresult:
print(x)
if myresult[0] > 0:
mycursor = mydb.cursor()
check = "SELECT ingamePass FROM playeraccount WHERE playerAuth = %s"
mycursor.execute(check, (playerAuth,))
myresult2 = mycursor.fetchone()
for x2 in myresult2:
print(x2)
await ctx.send(f'We have found your account in our system, your ingame Password is ""{myresult2[0]}"')
else:
await ctx.send('Your Account does not exist in our files please try again later.')```
I get this error :d
File "C:\Users\Crossfire StationXd\PycharmProjects\untitled1\cogs\leveling.py", line 99, in on_message
SQL.execute(f'update Experience set Server_Name = {server_name} where Server_ID = ? and Member_ID = ?', (server_id, author_id))
sqlite3.OperationalError: near "Of": syntax error
What happens when I make my server name 1; drop table Experience; --?
SQL.execute(f'update Experience set Server_Name = 1; drop table Experience')
is what happens
It's called SQL injections
what does drop table do? ๐ค
what is called SQL injetions? ๐ฑ scary
I can not let that happen\
But how does that relate? ๐ค
The ? syntax that you use for the other inputs prevents it
If you replace your other format string input with a ? and an appropriate parameter, I suspect your issue will go away
it seems like you're just dropping the server name in
๐ฎ
oh so if I do Server_Name = ? instead of {server_name} you mean?
It's a lack of quotes that was your original problem, but the solution is to pass parameters properly instead
Oky,I will try to do this because I think I understand you ๐
good luck
:P
what about this:
SQL.execute(f'select Exp from Experience where Server_ID="{server_id}" and Member_ID="{author_id}"')
```?
could this be SQL injected?
Yes
0.0
given that ID's are set by discord, and guaranteed to be numbers, that code should not cause problems
But I would still suggest using ? syntax there
yes
= ? and after values(?) ?
๐ I = try that
SELECT * FROM Experience WHERE server_name = ? and user_id = ?
yes
and after just ,(server_id, author_id)
no values
right?
because it is not in the parenthesis
you pass it into the execute command
something like this:
SQL.execute(f'update Experience set Server_Name =? where Server_ID = ? and Member_ID = ?', (server_name, server_id, author_id))
```?
cursor.execute("UPDATE users SET user_name = ? WHERE user_id = ? ", (user_name, user_id))
yeeeeee
yes
๐
oh
so where it is only 1 thingy instead of 2 like
(user_name, user_id))
I don't need parenthesis
makes sense
Perhaps not, but it's been my experience that you'd have to wrap it in a proper tuple-- (user_name,)
There's also an alternative named syntax too:
no I mean
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
I get the green underline saying 'you don't need that' basically
If you missed the extra ,, then you probably would
1 sec
dude
took me 5 minutes to get this text thingy to stay so I can take a photo of it lol
(thing**,**)
REALLY?
yep..
I need that? ๐ฎ
yes
even if I will not be putting anything else inside?
!e ```python
print(repr(("a")))
print(repr(("a",)))
@rich trout Your eval job has completed with return code 0.
001 | 'a'
002 | ('a',)
๐ค
!e ```python
print(type(("a",)))
@rich trout Your eval job has completed with return code 0.
<class 'tuple'>
๐
I learn something new everyday ๐
THANKS It works ๐
Juses! I have a lot of those ๐ to fix
hey guys
why doesnt this work ?
val = (ctx.author.id, ctx.author.name, username, location, isp, creation_date)
async with conn.cursor() as mycursor:
await mycursor.execute(sql, val)
await conn.commit()
print('created')
await ctx.send('Your request has been sent through')
await conn.close()```
it doesnt put anything my database
put it prints the values ..
that doesn't seem like it should be necessary - a comma after the last item in a tuple is optional and only required for single-element tuples.
how do you tell it didn't put anything in the database?
Guys, someone knows SQL?
I have to modify that VIEW
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `eskycrawler_dev`.`offers_viewer` AS
SELECT
`eskycrawler_dev`.`offers`.`price` AS `price`,
`out_flights`.`flight_number` AS `departure_number`,
`out_airports`.`name` AS `departure_airport`,
`out_cities`.`name` AS `departure_city`,
`out_countries`.`name` AS `departure_country`,
FROM_UNIXTIME((`out_flights`.`from_date` / 1000)) AS `departure_date`,
`in_flights`.`flight_number` AS `arrival_number`,
`in_airports`.`name` AS `arrival_airport`,
`in_cities`.`name` AS `arrival_city`,
`in_countries`.`name` AS `arrival_country`,
FROM_UNIXTIME((`in_flights`.`to_date` / 1000)) AS `arrival_date`,
`eskycrawler_dev`.`offers`.`url` AS `offer_url`
FROM
((((((((`eskycrawler_dev`.`offers`
JOIN `eskycrawler_dev`.`flights` `out_flights` ON ((`eskycrawler_dev`.`offers`.`outbound_flight_id` = `out_flights`.`id`)))
JOIN `eskycrawler_dev`.`flights` `in_flights` ON ((`eskycrawler_dev`.`offers`.`inbound_flight_id` = `in_flights`.`id`)))
JOIN `eskycrawler_dev`.`airports` `out_airports` ON ((`out_flights`.`from_airport_id` = `out_airports`.`id`)))
JOIN `eskycrawler_dev`.`airports` `in_airports` ON ((`in_flights`.`from_airport_id` = `in_airports`.`id`)))
JOIN `eskycrawler_dev`.`cities` `out_cities` ON ((`out_airports`.`city_id` = `out_cities`.`id`)))
JOIN `eskycrawler_dev`.`cities` `in_cities` ON ((`in_airports`.`city_id` = `in_cities`.`id`)))
JOIN `eskycrawler_dev`.`countries` `out_countries` ON ((`out_cities`.`country_id` = `out_countries`.`id`)))
JOIN `eskycrawler_dev`.`countries` `in_countries` ON ((`in_cities`.`country_id` = `in_countries`.`id`)))
ORDER BY FROM_UNIXTIME((`out_flights`.`from_date` / 1000)) , FROM_UNIXTIME((`in_flights`.`to_date` / 1000))
I got OFFERS main table. That view get all offers and show informations instead of all foreign keys id.
just converts id to information from other tables
I got a problem, because I have to add one more thing. My Offers table got new column "search_id" foreign key from table SEARCHES.
this is SEARCHES table
Now in VIEW I have to get all offers only with the last search.
How to do that?
- Get last id of searches
- Get offers only with that search_id
SQL.execute(f'select Member_ID from Staff_List where Server_ID = ?', (server_ID))
ValueError: parameters are of unsupported type
WUT IS WRONG HERE :d
@torn sphinx (server_ID) is the same as server_ID
you want (server_ID,)
or [server_ID]
what do you mean
id doesn't matter what name it is
right
WOW apparently it does???
why
@torn sphinx the params must be a sequence of some kind, i.e. a tuple or list
Maybe a comma at the end of that tuple?
of course
End of the first element
Did it work
I am fixing this 5 minutes before I need to go to the dentist hahaha
yes it did,much love! have a nice day
Nice
I need help..
So I have database filled out like this:
BUT
when I run this line of code:
I get this printed out:
and that is 1 ID only..
I am confusion
lol
not funny xd
sry
yw
SQL.execute('insert into Staff_List(Server_ID, Server_Name, Member_ID) values(?,?,?)', (server_ID, server_name, member_ID,))
sqlite3.OperationalError: database is locked
I added a timeout time
nope still that error
and by that I mean
db = sqlite3.connect(os.path.join(DIR, "staff.db"), timeout=5)
does anybody know how to import mysql connector python
not me
@frozen fossil did u install it?
i did
dev:~ raizo$ pip3 show mysql-connector-python
Name: mysql-connector-python
Version: 8.0.17
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
Author-email: UNKNOWN
License: GNU GPLv2 (with FOSS License Exception)
Location: /usr/local/lib/python3.7/site-packages
Requires: protobuf
Required-by:
dev:~ raizo$
did u look into the docs?
Yes,I am,sir!
ur using the green triangle to run the bot?
whats ur working dir?
yeah i have these
in which have u installed the package and which one are u using to run the program
@torn sphinx go to edit config and see the working dir there
๐ค
both versions dont work of 3.7.4
ahh choose the last option
not working
owo
ye
C:\Users\Crossfire StationXd\PycharmProjects\untitled
this is,sir!
but the database is not in that directory ๐
should it be? ๐ค
inside it in some folder
try running the command again, for which u got error
i have never got that kind of error,lol
OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.
what does this mean:
DIR = os.path.dirname(__file__)?
0.0
I have this:
DIR = os.path.dirname(__file__)
db = sqlite3.connect(os.path.join(DIR, "staff.db"), timeout=5)
#db.execute("PRAGMA busy_timeout = 30000")
SQL = db.cursor()
but it did not change the directory..
use regular path insted of OS , im not the best with os module, lol
?
show me ur project structure
I am asking if you maybe know if I can replace 'file' with the other path?
WHAT? ๐ฆ
_ file _
where is the db located at
u can just do sqlite3.connect("cogs/staff.db")
YEEE
I will try that
but I put the whole path in
because in the past it bugged on me
ur working dir is untitled so just doing cogs/staff.db should work
if ur using that green triangle run button
not yet,BUT I get 0 errors ๐
nono,I think my code is bad
i belive u set timeout on servers
u added timeout and it fixed?
again
SQL.execute('insert into Staff_List(Server_ID, Server_Name, Member_ID) values(?,?,?)', (server_ID, server_name, member_ID,))
sqlite3.OperationalError: database is locked
I JUST ADDED A 'RETURN' TO THE CODE
๐ก
๐ญ
SQL.execute(f'select Member_ID from Staff_list where Server_ID = ?', (server_ID,))
member_dbID = SQL.fetchall()
print(member_dbID)
for i in member_dbID:
print(i[0])
if i[0] == member_ID:
await ctx.send("This member is already on the staff list.")
return
if not i[0] == member_ID:
SQL.execute('insert into Staff_List(Server_ID, Server_Name, Member_ID) values(?,?,?)', (server_ID, server_name, member_ID,))
db.commit()
await ctx.send("Member has been added to the list.")
This my code
This for loop may be the cause of it :/
are u closing connection? (dunno if its related but just wanna make sure)
u should close db connection
._.
what have u named ur connection object
db
db.close()
remove comma after member_ID and try
im not sure whats going on :/
lemme get someone who is better at this
paste it some(paste bin or i belive pydis has something like that)\
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.
this?
yea
please dont create tables in commands
have a seperate python file where u do table creating n stuff
make a file called sql_setup.py and run python script for creating table in db
and create table only once(i mean run only once)
so like setup a function that when called creates a table?
yea
and how will I only know only once?
u should do it once cuz u cannot make duplicate table
๐ค makes sense
something like this:
DIR = os.path.dirname("C:\\Users\\Crossfire StationXd\\PycharmProjects\\untitled1\\")
db = sqlite3.connect(os.path.join(DIR, "staff.db"), timeout=5)
SQL = db.cursor()
SQL.execute('create table if not exists Staff_List("ID" integer not null primary key autoincrement,"Server_ID" integer, "Server_Name" text, "Member_ID" integer)')
db.commit()
return SQL
```?
the returning thingy xd
also I tried using else's,elif's
no that i not what i ment
https://github.com/RohanJnr/Gator_Bot_no_Gspread/blob/master/sqlite_setup.py
u need a different file like this
๐ฎ
HOW do I ..
do I ummm just connected to the database everytime I rune the 'addstaff'command?
so everything else except the creating table part?
copy this code and try
@harsh pulsar can u look into this issue, im not able to solve it
about db being locked
elif
use do else:
use this
db = sqlite3.connect("cogs/staff.db")
SQL = db.cursor()```
๐บ
n try
dont use os
bro
it will go again instied cogs
wait wt.f
it is not in cogs anymore
I moved it to the main folder lol
then
db = sqlite3.connect("staff.db")
SQL = db.cursor()```
did u put the code which i gave?
i dont understand how can working with db be so complex, i never had these issues ๐ค
id say move this issue to one of the help channels, more activity there, sorry im not able to solve this
@torn sphinx i suggest maybe moving a little more carefully
:d
instead of "trying things" maybe spend some time reading documentation and understanding how things work and are intended to work
from your questions here it seems like you just throw down some code that looks like it might work
i dont understand why its locked
which is fine, but eventually becomes frustrating both for you and the people trying to help you
never experienced it before
@tawny sail can you state the issue
he is having db being locked for some reason
๐ฆ
can u paste ur code again, so salt can look
1minute
I mean I did spent my whole day on this ,salt
if that counts about being careful
i still dont understand why u need that timeout
okay
Hi, how to select only offers with the greatest "search_id" value? (It should return only last found offers)
*sorry for cut off
@pliant oxide groupby and max?
yes DESC order
but how that SQL should be looked
get the max value and another query to filter out all values = that max value
hmm
@torn sphinx writing to a sqlite database locks the database. it looks like either you're attempting to do concurrent writes, or you're failing to release something after writing
since discord.py is inherently async, you will need to implement some kind of access control around the database
which will require a more "structured" application if you want to stay sane
SELECT MAX(ur col name) from table name i belive
so now
SELECT MAX(search_id) FROM eskycrawler_dev.offers;
try it
:d
do you have a primary key @pliant oxide
@pliant oxide what are you grouping by, to find the max?
or you just want the max in the whole table
how do you mean access control? I am not a fucking computer scientist ๐ญ
The problem is: I got OFFERS table where I store my offers. In the first search all founded offers got search_id = 1. When I start program again (second search) it should search_id = 2.
And... I just care only about last founded offers
I apologise for my language
did you forget to save in the db browser
it was probably holding a lock open
anyways
no im still going to look at your code
there are a few places for improvement here
first of all that chdir is scary and not needed
How do I get rid of the FOR LOOP things? ๐ฆ it prints to the server both
Member has been added to the list.
This member is already on the staff list.
I have a 'return' if the member is added to the list
@tawny sail
SELECT * FROM eskycrawler_dev.offers WHERE search_id == SELECT MAX(search_id) FROM eskycrawler_dev.offers;```
that doesn't work ;c
@pliant oxide that doesnt make sense and isnt valid syntax
last time I did not have it,the database got saved to the /cogs folder
SELECT * FROM eskycrawler_dev.offers WHERE search_id == MAX(search_id)
@pliant oxide
@torn sphinx you can put the full path in the .connect
not just a filename
sqlite3.connect("C:\\Users\\Crossfire StationXd\\PycharmProjects\\untitled1\\staff.db")
you can write that
._.
@pliant oxide that's why I deleted it that time, sorry, I guess I'm using orm and sqlalchemy more these days ๐
Salt I think he can provide only the dB name cuz his working dir is set to untitled1
I am more safe with
db = sqlite3.connect("C:\\Users\\Crossfire StationXd\\PycharmProjects\\untitled1\\staff.db", timeout=5)
I myself couldn't understand :/, dint be of any help
@torn sphinx have you considered setting uniqueness constraints on your table?
what code did you run to create the table?
I never heard of 'uniqueness constraints'
oh i see
I told him have a separate file to create table once
SQL.execute('create table if not exists Staff_List("ID" integer not null primary key autoincrement,"Server_ID" integer, "Server_Name" text, "Member_ID" integer)')
db.commit()
db.close()
``` SIR
Yes,I did make one, Iceman! ๐
Nice
why are you re-creating the table whenever staffhelp is called
@commands.command()
async def staffhelp(self, ctx):
author = ctx.message.author
author_ID = ctx.message.author.id
server_name = str(ctx.guild)
server_ID = ctx.guild.id
db = sqlite3.connect(self.staff_dbfile, timeout=5)
SQL = db.cursor()
SQL.execute('create table if not exists Staff_List("ID" integer not null primary key autoincrement,"Server_ID" integer, "Server_Name" text, "Member_ID" integer)')
db.commit()
what
oh yeah, so quick change
class StaffCommand(commands.Cog):
staff_dbfile = "C:\\Users\\Crossfire StationXd\\PycharmProjects\\untitled1\\staff.db"
now you can get the filename from self.staff_dbfile
Know oop?
Okay good
U can access the file location with the name mentioned by salt
But I have not used them more or less
OH
so you mean
I can get a variable?
from self.staff_dbfile.VAR?
So now dB = sqlite3.connect(self.staff_dbfile)
._.
Okay I gotta go now, geting late for me :/, almost mid night, I guess salt will be here
Sorry
Thanks @harsh pulsar n sry for the tag before
Thank you,Iceman for your hours! ๐
Bless you
But that did not help me solve https://discordapp.com/channels/267624335836053506/342318764227821568/626115886729920515 :d
i also recommend removing server_name from your table
it doesn't help and it can go out of date at any time
you can always get the server name with self.client.get_guild(server_ID).name
I know,but it is used just so I know what to edit if needed
and it is updated on every event on_message
I = stupid,but with lots of time I = smort :3
sometimes*
you strugling?
If you are taking your time,no problem xD I am just joking around,I appreciate any help! I am chilling meanwhile anyways soo ๐
..please reply
using sqlite3 how do i count up how many times a specific value is present
whats that
here an example:
db.commit()
db.close()
so for every row
the ID from the table adds a +1
so for example:46
ID SERVER_ ID SERVER_NAME MEMBER_id
1 57636345346 SERVER-1 3463463
2 3474554636345 server-2 34637345
@tawny sail
SELECT * FROM eskycrawler_dev.offers WHERE search_id = MAX(search_id)
Still that doesn't work
I maybe found an answer
but I don't understand that
That's actually not what derek was asking lmao
@torn sphinx
@ivory turtle maybe you know how to fix it?
I am trying my best @ivory turtle ๐ฆ I really hoped it was the answer
@pliant oxide gimme a sec, multitasking
great. thank you!
it's ok, I can wait ๐
wait it worked @obsidian iron ?
no, i said thanks for the idea
oh :d
@torn sphinx what's the purpose of the check in staffhelp, you just want to see if the member is in the staff list?
im going to see if it works i just said thanks for the help
Ok, I think I found a solution
also i got one big question
im creating a discord bot and need to add database functionality
yeah?
is closing the database NECESSARY if the bot is on 24/7?
it is good to close it
considering i'll be using definitions to add to the database, if need be where would i close it
but if it is necasseraly ๐ค I may not know
@torn sphinx https://paste.pydis.com/gulizafeqo.py
i commented out the last function because that part is your homework
note i added a new function at the end which creates a table using a UNIQUE constraint
cool
@obsidian iron no problem ๐
yeah the last function was the first thing that cought my eye
you will probably want to keep this as a reference https://www.sqlite.org/lang.html
bookmarked
anybody know if i should close the database connection in a python bot
and if im using definitions for functions where should i close it considering the bot is online 24/7 and at no point will i need to stop database functionality
eh
not necessary i think
but you might need some functionality to restart the db connection if it craps out
@obsidian iron In answer to your earlier question
using sqlite3 how do i count up how many times a specific value is present
SELECT COUNT(column_name) FROM table_name WHERE condition;
@pliant oxide done multi tasking, lemme check
I know already
SELECT * FROM eskycrawler_dev.offers WHERE search_id = (SELECT MAX(search_id) FROM eskycrawler_dev.offers)
@ivory turtle I had to make nested SELECT
;f
Didn't read it, mind reposting your 2nd quetsions?
anybody know if i should close the database connection in a python bot
and if im using definitions for functions where should i close it considering the bot is online 24/7 and at no point will i need to stop database functionality
@pliant oxide I see, that's some funky SQL stuff eh ;P
Ah
Yes, so normally
You'd init a db
And start connection whenever you need to fetch/store
then close
i see
Mainly for the purpose of safe coding iirc
could i do something like that
def add_infraction(connection,imember,ireason):
with connection:
c.execute("INSERT INTO infractions VALUES (:member, :reason)",{'member':imember,'reason':ireason})
add_infraction(sqlite.connect("infractions.db"),"test","test")
I believe I read that the correct handling of opening/closing connections happens outside of the function, but so far I've seen most people close/open connections inside functions
I'm honestly not too well versed in sqlite, but it doesn't look wrong to me ๐
and then i'd be able to close it inside the function right? @ivory turtle
yes
This sums it up quite nicely I think
Also, I wouldn't pass connection as an arg, seeing as that'd allow it to be dynamic, when you very much want that function to work in the same database always?
Or maybe you want to switch databases for that one function eh?
~~crossed out~~
Double tilde on both side
test
NOOL
So this should be crossed out!
epic!
thanks
wow
I will absorb knowledge like a spunge from salt rock lamp's code they sent me
I was suspicious about if a try block can have an 'else:' statement
search up discord markdown
!e
def do_thing(x):
print(f'INPUT: {x!r}')
try:
int(x)
except ValueError:
print('An error occurred')
else:
print('An error did not occur')
finally:
print('This part always executes')
do_thing('3')
print()
do_thing('a')
@harsh pulsar Your eval job has completed with return code 0.
001 | INPUT: '3'
002 | An error did not occur
003 | This part always executes
004 |
005 | INPUT: 'a'
006 | An error occurred
007 | This part always executes
Question actually regarding exception types
!e
emoji = "๐"
try:
emoji_id = await commands.EmojiConverter().convert(ctx, emoji)
emoji_id = emoji_id.id
except Exception as e:
print(e)
Sorry, but you may only use this command within #bot-commands.
oh.
or would i execute it? i'm new to databases as a whole
I'm not allowed to eval here huh
would i use .execute(..)
@obsidian iron Which response of mine? The part where I mentioned not wanting to dynamically parse a connection ?
๐
Oh, the result?
From your query?
basically what you just said yes
var = c.execute()
iirc
but lemme dig in sqlite docs ๐ฎ
SELECT COUNT(column_name) FROM table_name WHERE condition;
i realised i pasted the wrong one earlier
still same answer
make conn execute that query
store in var
Judging from this example from the docs
def select_all_tasks(conn):
"""
Query all rows in the tasks table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM tasks")
rows = cur.fetchall()
for row in rows:
print(row)
I'd assume you could also just
def select_all_tasks(conn):
"""
Query all rows in the tasks table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT COUNT(column_name) FROM table_name WHERE condition; ")
result = cur
print(result)
Seeing as you only got 1 result
although you might have to use cur.fetchone()
(Depending on the type of returned result)
one more thing lunar!
for the conditions
does it differ from python conditions
say i'd be looking for the number 5
WHERE 5
right? @ivory turtle
one more thing
That confused me.
how do i refer to parameters inside sql statements if they're just strings
many different methods tbf
All with their pros and cons
I mainly use fstring
same as when you'd use the print function
that works
print(f"{variable_name} is of type {type(variable_name)}")
Works
print('{} {}'.format(variable_name, 'two'))
also works
iirc
cur = conn.cursor()
cur.execute("SELECT COUNT(column_name) FROM table_name WHERE condition; ")
result = cur
More on .format here
for this i got the object
instead of the value
yeah i keep getting the cursor object
c.execute(qry)
y=c.fetchone()[0]
print y
Did a quick SO search
This should return one result from conn with position 0 (not sure if that part is neccesary for you, since you should only have one result)
awesome, that works
Awesome
thank you very much, appreciated
No problem man, good learning moments for me too
I got a crawler which run search every few hours. I get flight offers from website and store in OFFERS table with important primary key "search_id" which reference in what search it found that offer.
For example:
it's the offers from 1st and 2nd search
Haha
ok, bฤdzie trochฤ ลatwiej, ale nikt nas nie zrozumie
Yeaaah, sorry
I tried to learn polish with polish friend of mine ages ago
Didn't work out
haha, ok, don't worry; let's continue in english
Keine ahnung oder was ;P
How to SELECT only new offers. <- so we have to SELECT all last found offers (for example search_id=2) and remove offers from search_id=1
I just want to know only new offers
I don't understand that much Deutch xd
English, focus focus
Dw dw, we're pursueing higher level programming languages anyways
Not like, actual languages :^)
So, you want to select new offers
The 'newest' only?
Or anything that's newer than x hours
Two distinct options of course;
For the offers released within x hours from now;
-Store datetime of moment when released
-Check condition against that with datetime.now
For only the actual newest,
-While selecting sort by ascending/descending, limit selection to top 10
Greatest search ID?
oh yes of course
So
I want to select only NEW offers. So offers that are on search_id = 2, but not on search_id = 1.
nah nah
what exactly do you wanna do
But... do you understand what I want to achieve?
what do you classify as new
Yes, I think I understand
Get offers with the greatest search_id (last found offers) and then remove from those offers with "greatest search_id - 1"
Basically for column search_id, get the highest current value, then select everything matching that value for same column
Right?
then remove from those offers with "greatest search_id - 1"
Huh?
SELECT * FROM eskycrawler_dev.offers WHERE search_id = (SELECT MAX(search_id) FROM eskycrawler_dev.offers)
This gives me last found offers
Now
Okay, yes, what's the next step?
I want to remove from that SELECT offers which were in the search_id-1
Ah, how to explain that xD
Example:
@ivory turtle @hallow cloud
fuck
wait
Now it's better
You see?
Because they're "new"
๐
You got Paris in search 1
so we have to remove Paris from search 2
the same with Szczecin
Duplicate entries from older column
Is there anything that makes them unique?
URI's ?
what database engine is this @pliant oxide
MySQL
Okay so what I meant is
If you get search results
And those with search_id 1 and 2 are the same
Can they be matched against each other
Without confusing them with other similar search results?
Are they, in a way, unique ?
We can say that results are the same if "outbound_flight_id" and "inbound_flight_id" pair is the same (that pair is unique).
hmm
So either some very intricate single query
Or just multiple queries
I'm leaning towards the latter tbh lol
Salt, thoughts?
wait how does that even make sense
?
MAX(search_id) returns exactly 1 number
Ok, but what's the question?
?
SELECT *
FROM eskycrawler_dev.offers
WHERE search_id = MAX(search_id)
this is the starting point, we still didn't remove Paris and Szczecin records
and I don't know how to do it
and how do you know you want to remove Paris?
If Paris was in MAX(search_id) - 1 I remove it
ah i see
how do you know which record "paris" is
what is the common identifier in your data
inbound/outbound flight id?
yes, that pair is unique
SELECT t1.*
FROM (
SELECT *
FROM eskycrawler_dev.offers
WHERE search_id = MAX(search_id)
) AS t1
JOIN (
SELECT *
FROM eskycrawler_dev.offers
WHERE search_id = MAX(search_id) - 1
) AS t2 ON
t1.inbound_flight_id <> t2.inbound_flight_id AND
t1.outbound_flight_id <> t2.outbound_flight_id
I'm waiting
I think in your solution I also get "London" in results (I don't wnat London in results):
yeah thats what i realized
Still we can duplicate ourselves. Just SELECT again MAXed search_id
oh yeah mysql is garbage and doesnt allow you to write MAX in WHERE anyway
Yes, that's why I have to write:
SELECT * FROM eskycrawler_dev.offers WHERE search_id = (SELECT MAX(search_id) FROM eskycrawler_dev.offers)
that works
btw, can you explain me, what does "t1.*" means?
im not sure if its even valid mysql syntax
it was just shorthand for "use t1 to prefix everything"
hah, ok
do you want to exclude all earlier searches or just max-1
@ivory turtle
hey my dude
i was wondering
hm.
how do i explain
hm
say i have three sets of records
id: 5, level: 6
id: 5, level : 8
id 5:, level: 10
@harsh pulsar exclude just max-1
how do i loop through each record, checking if the id is 5 and making each of the levels 2 for example
I think it's even easier to exlude just max-1
yes
great, thats what i needed
All rows where id = 5
oh you want to only show results which had not been seen before in other id's
that's all you needed to say ๐
@hallow cloud yes xd do you know how to do it?
I think @harsh pulsar is doing something
it shouldn't be too hard
im fiddling with a correlated subquery but its not quite right
select all names and then remove all the names that are in all other id's except the specified one
it only sounds like it's easy ;f
this is as far as i got, i gotta get back to work. it's not working right though
select *
from offers o
where
o.search_id = (select max(search_id) from offers)
and
not exists (
select 1
from offers o1
where o1.search_id = (select max(search_id) - 1 from offers)
)
@harsh pulsar check #help-coconut
what do tou mean "it's not working"? just syntax? or logic?
https://www.db-fiddle.com/f/f29VDiG4wMghj4p1fafGux/0
its giving 0 results instead of 1
An online SQL database playground for testing, debugging and sharing SQL snippets.
what?
hm
i don't think it's hard, im a bit rusty in with my sql but lemme give it a twirl:
select names from offers
where offers.name in (
select name
from offers
) and offers.name not in (
select name
from offers
where offers.id!=ID)
something like this
(probably would throw a syntax erorr but you get the jist of it)
am i thinking in the right way
Ok guys, I got some idea, I will try to fix your codes to work and paste it just for information
oh..you litteraly use id to sort by date, as in id represents the chronological order of the items
yikes
use time formats for that next time please ๐
If a table is dynamically modified with a schema modifying transaction while everything is running, is there a way to keep the graphql schema up to date?
@hallow cloud what? I'm using timestamp
wdym arent u searching by search_ids
it's my searches table
but in that case I described, I'm using search_id
to get the right order
belive me, it's fine ;p
roite, you got a solution now :P?
I have a list of 4 ids (BIGINT) That can be in one of 4 colums in a table, how can i check for this?
Do i just need to do a really long check?
uh what are the four columns?
but yeah, your options are basically "check each column separately with OR" or "redesign your schema", and I'd give serious thought to the latter
creator, member1, member2, member3
what if it needs more than 3 members
ok
will always be 4 members
hey guys
i have this code
sql = "INSERT INTO passwordrecovery (discordID, discordName, ingameName, countryCreated, internetProvider, dateCreated) VALUES (%s, %s, %s, %s, %s, %s)"
val = (ctx.author.id, ctx.author.name, username, location, isp, creation_date)
try:
async with get_conn as conn:
async with conn.cursor() as cur:
await cur.execute(sql, val)
await conn.commit()
print('created')
await ctx.send('Your request has been sent through')
await conn.close()
except Exception as e:
print(e)
raise```
when i print exception
```__aexit__```
i get this
and whatever im doing
its not putting it in my database
am i doing something wrong ?
Has anyone gotten the error "WinError 10013" when trying to connect to a MySQL database that is hosted on your own pc? I have a few python files trying to connect to it to input information and read from it but when I run my init file I get that error
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions Full error message I'm given
that error is normally associated with a port already being in use... are you sure that's at the point where it's connecting to mysql, not where it's setting up the web server?
@silent wyvern
are you able to get a traceback
server_address = ('localhost', 3306) this is what I'm using to define the connection to the server, Am I not supposed to use the same port as what I setup the server to use? this is my first time using MySQL so I'm still learning this stuff
I decided to add the database to it last minute so I'm just trying to get it connected
no I'm not
what kind of application are you building
are you able to get a traceback for what line the error is happening on
Yeah I can post the whole thing
File "C:/Users/mattt/PycharmProjects/Test/Automatic Youtube Uploader/YouTube Bot Server/initserver.py", line 53, in <module>
init()
File "C:/Users/mattt/PycharmProjects/Test/Automatic Youtube Uploader/YouTube Bot Server/initserver.py", line 40, in init
socketserver.startServer()
File "C:\Users\mattt\PycharmProjects\Test\Automatic Youtube Uploader\YouTube Bot Server\socketserver.py", line 21, in startServer
socket.bind(server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
The errors are coming from socket_address which is what I have set as my MySQL hostname and port to define them
ok so you are building a server
yeah
yeah, you don't want to be using the mysql port for your python script's server's address
and...... automatic youtube uploading sounds like probably something we can't help with, sorry (though i can't think of why you'd need to run a server for that)
but creating a socket server has nothing to do with connecting to mysql so there's no reason you'd use the same port for that
quick question
inner join vs left join
is it really different for this case:
A is a subset of B.. I'm trying to join A with B because B has more fields but I only want to complete the information available for common field between A and B
hey guys i am just wondering how cna i send a gmail from python, but doing so securely
make sure to enable the less secure connections on your gmail account
otherwise you could accidentally lock your account for 24h
Hello this is kind of a dumb question but my brain is fried right now. I have the schemas I posted above. I have multiple entries with the same identifier on GameClass but different locale so the primary key is locale, identifier. The issue is it's not letting me set up relationship because GameClass.identifier is not unique.
This is how the GameClass table data looks like.
id | locale | identifier | class
----+--------+-------------+------------------
| en-US | knight | Knight
| es-AR | knight | Caballero
How can I set up the relationship between those two (GameArtifact.exclusive and GameClass.identifier) columns?
it depends on what kind of relation you have, one to one, one to many, many to many
well i think of it, one exclusive can be output in multiple languages
the issue is if i try to set the reference on gameartifact to gameclass it will complain it's not unique. I feel like I'm missing something there lol.
yeah, foreignkey constraint should either target a unique key or a primary key (which is unique anyways)
so you can either reference game artifact in game class table
but I guess this is not desired
our just not use foreignkey constraint, what for are you going to use it?
of course there is a third option to use additional table that references all the gameclasses for a given game artifact
yea that isnt desired. well every artifact (and another table, which i didnt work on yet) have a class (each with their unique identifier), which i assume in terms of how a database is designed should have a relationship to the gameclass table which holds the identifier and it's translation in multiple different locales
would be far easier if i didn't have the locale column lol
should i download postgresql from terminal or enterpriseDB?
@harsh pulsar I am on your code from yesterday now..
I have an error ...this is kinda a rookie error if you ever worked with discord.py:
await ctx.send("Please try this command in a server.")
^
SyntaxError: 'await' outside async function```
Guys, thouhts on a many-to-many relationship with only 1 table involded?
IE;
Table filled with users, however duplicate users exist since they belong to different guilds (so different unique PK, but identical user_id)
Users can gift eachother gifts, but within a set limit, ergo me wanting to store the transactions;
intermediary table
column 1 and 2 being Foreign keys of course, but both pointing to primary key of the user table, other columns holding datetime stamps of the transactions and whatnot.
Question being, is this even possible? table having a many-to-many relationship with itself? If not, is there a better way to do this by chance?
@torn sphinx Error says it all. You need to use await inside an async function
I see, sorry misread that.
what do you think,I started programming using Discord yesterday? no,30 days ago ๐
Same difference tbh ๐
I've seen people work with it for years and make the same mistakes still lol
Thanks ๐
I know it is a easy fix,though
unless it HAS to be outside function to simply work fast
yeah,I think they put that block of code in the wrong spot
because they are calling it by self.function
but it not even inside the class ๐
or just to teach me ๐ค
It does not add the database @harsh pulsar