Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sql_stuff(self):
- cnx = pymysql.connect(user='root',
- password='ptekm8n8',
- host='127.0.0.1',
- database='toiletdb')
- cursor = cnx.cursor()
- zip_code = self.lineEdit.text()
- adress = self.lineEdit_2.text()
- rating = self.dropdown_rating.currentText()
- if rating == "Ingen":
- rating = None
- if zip_code:
- if rating:
- query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND t.zipcode LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
- cursor.execute(query1, ('%' + adress + '%', '%' + zip_code +'%', rating))
- fetchq = cursor.fetchall()
- query2 = ("""SELECT t.adress, r.rating, d.description from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND t.zipcode LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
- cursor.execute(query2, ('%' + adress + '%', '%' + zip_code +'%', rating))
- fetchq2 = cursor.fetchall()
- else:
- query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s and t.zipcode LIKE %s ORDER BY toilet_id""")
- cursor.execute(query1, ('%' + adress + '%', '%' + zip_code +'%'))
- fetchq = cursor.fetchall()
- query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s and t.zipcode LIKE %s ORDER BY toilet_id""")
- cursor.execute(query2, ('%' + adress + '%', '%' + zip_code +'%'))
- fetchq2 = cursor.fetchall()
- else:
- if rating:
- query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
- cursor.execute(query1, ('%' + adress + '%', rating))
- fetchq = cursor.fetchall()
- query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
- cursor.execute(query2, ('%' + adress + '%', rating))
- fetchq2 = cursor.fetchall()
- else:
- query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s ORDER BY toilet_id""")
- cursor.execute(query1, ('%' + adress + '%'))
- fetchq = cursor.fetchall()
- query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
- NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s ORDER BY toilet_id""")
- cursor.execute(query2, ('%' + adress + '%'))
- fetchq2 = cursor.fetchall()
- query3 = ('SELECT zipcode, cityname FROM zipcodedb ORDER BY zipcode')
- cursor.execute(query3)
- fetchq3 = cursor.fetchall()
- self.Placering_table.setRowCount(0)
- self.rating_table.setRowCount(0)
- self.tableWidget.setRowCount(0)
- for row_number, row_data in enumerate(fetchq):
- self.Placering_table.insertRow(row_number)
- for column_number, data in enumerate(row_data):
- self.Placering_table.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
- for row_number, row_data in enumerate(fetchq2):
- self.rating_table.insertRow(row_number)
- for column_number, data in enumerate(row_data):
- self.rating_table.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
- for row_number, row_data in enumerate(fetchq3):
- self.tableWidget.insertRow(row_number)
- for column_number, data in enumerate(row_data):
- self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement