sqlite.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import sqlite3
  2. import Stateful
  3. deType = "sqlite3"
  4. dbPath = "d<EV>.db"
  5. def is_exist(tableName, columnName):
  6. pass
  7. def Secondary_response():
  8. pass
  9. def Operate_sqlite3(dbPath, commands):
  10. # Command e.g.
  11. # 0 1 2 3 4 5 6
  12. # [add]
  13. # ['add', 'board', '<KB>']
  14. # ['add', 'class', '<CL>', 'to', '<KB>']
  15. # ['add', 'event', '<EV>', 'to', '<KB>', '/', '<CL>'] <- 这个应该报错
  16. # ['add', 'event', '<EV>', 'to', '<KB>/<CL>']
  17. # [edit]
  18. # ['edit', 'board', '<KB>', 'to', '<KB>']
  19. # ['edit', 'class', '<KB>', 'to', '<KB>']
  20. # ['edit', 'class', '<CL>', 'to', '<CL>']
  21. # ['edit', 'class', '<CL>', 'to', '<CL>']
  22. # ['edit', 'event', '<EV>', 'to', '<EV>']
  23. # ['edit', 'event', '<EV>', 'in', '<KB>', '/', '<CL>'] <- 这个应该报错
  24. # ['edit', 'event', '<EV>', 'in', '<KB>/<CL>']
  25. # [delete]
  26. # ['delete', 'board', '<KB>']
  27. # ['delete', 'class', '<CL>']
  28. # ['delete', 'event', '<EV>']
  29. # ['delete', 'event', '<EV>', 'in', '<KB>', '/', '<CL>'] <- 这个应该报错
  30. # ['delete', 'event', '<EV>', 'in', '<KB>/<CL>']
  31. # [move]
  32. # ['move', 'class', '<CL>', 'to', '<KB>']
  33. # ['move', 'event', '<EV>', 'to', '<KB>']
  34. # ['move', 'event', '<EV>', 'to', '<CL>']
  35. # ['move', 'event', '<EV>', 'in', '<KB>', '/', '<CL>'] <- 这个应该报错
  36. # ['move', 'event', '<EV>', 'in', '<KB>/<CL>']
  37. # [select]
  38. # ['select', 'board', '<KB>']
  39. # ['select', 'class', '<CL>']
  40. # ['select', 'event', '<EV>']
  41. # ['select', 'event', '<EV>', 'in', '<KB>', '/', '<CL>'] <- 这个应该报错
  42. # ['select', 'event', '<EV>', 'in', '<KB>/<CL>']
  43. # [..]
  44. # [/]
  45. v = "SELECT * FROM {tableName} WHERE name={name}".format(tableName=str(commands[1]).capitalize(), name="'"+commands[2]+"'")
  46. con = sqlite3.connect(dbPath)
  47. cur = con.cursor()
  48. # 1. exist check
  49. try:
  50. res = cur.execute(v)
  51. con.commit()
  52. print("res: ", res.fetchone() is None)
  53. # syntax right but not exist:
  54. if res.fetchone() is None == True:
  55. print("err <Code>: could not found, creat? y/n")
  56. # Secondary_response()
  57. # 2. exec command
  58. matched = Stateful.MatchTomlKeys('d<EV>_config.toml', commands, 'sqlite3')
  59. print(matched)
  60. except:
  61. print("err <Code>: Syntax error")
  62. con.close()
  63. if __name__ == "__main__":
  64. while(1):
  65. sy_i = input("sql: ").split(" ")
  66. Operate_sqlite3(dbPath, sy_i)