Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. def sql_stuff(self):
  2.  
  3. cnx = pymysql.connect(user='root',
  4. password='ptekm8n8',
  5. host='127.0.0.1',
  6. database='toiletdb')
  7. cursor = cnx.cursor()
  8.  
  9. zip_code = self.lineEdit.text()
  10. adress = self.lineEdit_2.text()
  11. rating = self.dropdown_rating.currentText()
  12. if rating == "Ingen":
  13. rating = None
  14.  
  15.  
  16. if zip_code:
  17. if rating:
  18. query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
  19. 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""")
  20.  
  21. cursor.execute(query1, ('%' + adress + '%', '%' + zip_code +'%', rating))
  22. fetchq = cursor.fetchall()
  23.  
  24. query2 = ("""SELECT t.adress, r.rating, d.description from toiletdata t
  25. 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""")
  26. cursor.execute(query2, ('%' + adress + '%', '%' + zip_code +'%', rating))
  27. fetchq2 = cursor.fetchall()
  28.  
  29. else:
  30. query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
  31. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s and t.zipcode LIKE %s ORDER BY toilet_id""")
  32.  
  33. cursor.execute(query1, ('%' + adress + '%', '%' + zip_code +'%'))
  34. fetchq = cursor.fetchall()
  35.  
  36. query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
  37. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s and t.zipcode LIKE %s ORDER BY toilet_id""")
  38. cursor.execute(query2, ('%' + adress + '%', '%' + zip_code +'%'))
  39. fetchq2 = cursor.fetchall()
  40.  
  41.  
  42.  
  43. else:
  44. if rating:
  45. query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
  46. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
  47.  
  48. cursor.execute(query1, ('%' + adress + '%', rating))
  49. fetchq = cursor.fetchall()
  50.  
  51. query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
  52. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s AND r.rating >= %s ORDER BY toilet_id""")
  53. cursor.execute(query2, ('%' + adress + '%', rating))
  54. fetchq2 = cursor.fetchall()
  55.  
  56.  
  57.  
  58. else:
  59. query1 = ("""SELECT t.adress, t.zipcode, t.status from toiletdata t
  60. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s ORDER BY toilet_id""")
  61.  
  62. cursor.execute(query1, ('%' + adress + '%'))
  63. fetchq = cursor.fetchall()
  64.  
  65. query2 = ("""SELECT t.adress, r.rating, description from toiletdata t
  66. NATURAL LEFT JOIN descriptiondb d NATURAL LEFT JOIN ratingdb r WHERE t.adress LIKE %s ORDER BY toilet_id""")
  67. cursor.execute(query2, ('%' + adress + '%'))
  68. fetchq2 = cursor.fetchall()
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. query3 = ('SELECT zipcode, cityname FROM zipcodedb ORDER BY zipcode')
  76. cursor.execute(query3)
  77. fetchq3 = cursor.fetchall()
  78.  
  79.  
  80. self.Placering_table.setRowCount(0)
  81. self.rating_table.setRowCount(0)
  82. self.tableWidget.setRowCount(0)
  83.  
  84.  
  85. for row_number, row_data in enumerate(fetchq):
  86. self.Placering_table.insertRow(row_number)
  87.  
  88. for column_number, data in enumerate(row_data):
  89.  
  90. self.Placering_table.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
  91.  
  92. for row_number, row_data in enumerate(fetchq2):
  93. self.rating_table.insertRow(row_number)
  94.  
  95. for column_number, data in enumerate(row_data):
  96.  
  97. self.rating_table.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
  98.  
  99. for row_number, row_data in enumerate(fetchq3):
  100. self.tableWidget.insertRow(row_number)
  101.  
  102. for column_number, data in enumerate(row_data):
  103.  
  104. self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
  105.  
  106. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement