1
0

queries.py 827 B

123456789101112131415
  1. def create_ifnot_onrecord(self, table, name):
  2. record = self.db.one("SELECT name, network FROM " + table + " WHERE LOWER(name)=LOWER(%s) AND LOWER(network)=LOWER(%s)", (name, self.network, ))
  3. if record: # On record.
  4. # Correct capitalisation of network name, if needed.
  5. if not self.network == record[1]:
  6. self.db.run("UPDATE networks SET name=%s WHERE LOWER(name)=LOWER(%s)", (self.network, self.network, ))
  7. # Correct capitalisation if needed.
  8. if not name == record[0]:
  9. self.db.run("UPDATE " + table + " SET name=%s WHERE LOWER(name)=LOWER(%s) AND network=%s", (name, name, self.network, ))
  10. # Create record.
  11. else: # Not on record.
  12. self.db.run("INSERT INTO " + table + " (name, network) VALUES (%s, %s)", (name, self.network, ))