Strings.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. def index_value(data, value):
  2. try:
  3. index = data.index(value)
  4. except ValueError:
  5. index = -1
  6. return index
  7. def delete_table(database, table, where=None):
  8. if where is not None:
  9. wheres = " where "
  10. for key in where:
  11. wheres = wheres + key + " = " + where[key] + " and "
  12. wheres = wheres[:-5]
  13. else:
  14. wheres = ""
  15. return "delete from " + database + "." + table + wheres + ";"
  16. def insert_table(database, table, fields, values):
  17. return "insert into " + database + "." + table + " (" + fields + ") values (" + values + ");"
  18. def get_values(list_values):
  19. values = ""
  20. for value in list_values:
  21. if isinstance(value, str) and not value == "now()" and not value == "null":
  22. values = values + "\'" + value + "\', "
  23. else:
  24. values = values + str(value) + ", "
  25. return values[:-2]
  26. def get_values_delete(list_values):
  27. values = {}
  28. for value in list_values:
  29. if isinstance(list_values[value], str) and not list_values[value] == "now()":
  30. values[value] = "'" + list_values[value] + "'"
  31. else:
  32. values[value] = str(list_values[value])
  33. return values