debugging

posted in Off Topic
View:
Threaded
Linear
Linear
#1
Foxym
0
Frags
+
–

its not fun

the error is not even explainable for me
im doing an SQL query with python (sqlite3)
now when i ask it to get me the team id of the team with the matching name
it messes up

the query basically looks like this

SELECT Id FROM Teams WHERE Name = BBL Esport 

or

SELECT Id FROM Teams WHERE Name = Eternal Fire 

BBL is team id 1 in the Teams table
Eternal Fire is team id 2
yet
for BBL it returns 2
for Eternal Fire it returns NONE

im confused as hell

edit: i figured it out
the way an Sqlite query works in python appears to be 1 request at a time no matter the variable name
so for example my error was:

Team1_id = [sql query]
Team2_id = [sql query]

Team1_id = Team1_id.fetchone() <- would return the result of the second query
Team2_id = Team2_id.fetchone() <- would return nothing since the result was already fetched

solution was simply to move the lines like this

Team1_id = [sql query]
Team1_id = Team1_id.fetchone() 

Team2_id = [sql query]
Team2_id = Team2_id.fetchone() 

no idea why since they have diffrent variable names, but hey, i figured it out

#2
N0tdoing
0
Frags
+
–

add 'or 1=1'

#3
Foxym
0
Frags
+
–
N0tdoing [#2]

add 'or 1=1'

this is an automated system im making here
for the program im making i need it to return the team id
i just cant hard code it for all the Tier 1 teams

#4
Aminbg02
0
Frags
+
–

last time i checked you gotta put the quotes when u check for strings

#5
Foxym
0
Frags
+
–
Aminbg02 [#4]

last time i checked you gotta put the quotes when u check for strings

its diffrent when you use Python for the request
it needs to be formatted like this

cur.execute("SELECT * FROM Table WHERE Name = ?",(Name, ))

the * to select all
the ? will be replaced with the given Variable in the tuple (the Variable in the brackets followed by the comma)

thats how it works with sqlite in python

i figured my issue out though
just a simple line error it appears

#6
Foxym
0
Frags
+
–
N0tdoing [#2]

add 'or 1=1'

i figured out my issue
for some stupid reason, even when you clarify diffrent variables for the job, you need to fetch the result of the first query before the second
EVEN THOUGH THEY HAVE DIFFRENT VARIABLES ATTACHED TO THEM
i dont get it

  • Preview
  • Edit
› check that that your post follows the forum rules and guidelines or get formatting help
Sign up or log in to post a comment