Advertisement
Guest User

Untitled

a guest
Jun 16th, 2018
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. i have this code
  2.  
  3. #!/usr/local/bin/python3
  4. locationId=3106
  5. import mysql.connector
  6. con = mysql.connector.connect(host="localhost",database="racktables",user="root",password="fullmoon")
  7. cur1 = con.cursor()
  8. query1 = "SELECT r.name AS rowName, r.id AS rowId FROM Object AS r INNER JOIN EntityLink AS e ON r.id = e.child_entity_id WHERE e.parent_entity_id = \""+str(locationId)+"\" ORDER BY r.name"
  9. print(query1)
  10. result1 = cur1.execute(query1)
  11. for (rowName, rowId) in result1:
  12. print(rowName, rowId)
  13.  
  14. the generated query works when i use it in mysql
  15.  
  16. mysql> SELECT r.name AS rowName, r.id AS rowId FROM Object AS r INNER JOIN EntityLink AS e ON r.id = e.child_entity_id WHERE e.parent_entity_id = "3106" ORDER BY r.name;
  17. +---------+-------+
  18. | rowName | rowId |
  19. +---------+-------+
  20. | Row A | 2519 |
  21. | Row B | 3107 |
  22. | Row C | 7983 |
  23. | Row D | 7985 |
  24. | Row E | 14277 |
  25. | Row F | 14319 |
  26. | Zero-U | 4639 |
  27. +---------+-------+
  28.  
  29. but when i run my code i get this...
  30.  
  31. Traceback (most recent call last):
  32. File "./blah.py", line 9, in <module>
  33. for (rowName, rowId) in result1:
  34. TypeError: 'NoneType' object is not iterable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement