sqlite.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import sqlite3
  2. import Stateful
  3. deType = "sqlite3"
  4. dbPath = "dev.db"
  5. def is_exist(tablePath, name):
  6. pass
  7. def Operate_sqlite3(dbPath, commands):
  8. # 0 1 2 3 4 5 6
  9. # commands e.g.['add', 'board', 'KB4']
  10. # commands e.g.['add', 'class', 'CL1', 'to', 'KB4']
  11. # commands e.g.['add', 'event', 'EV1', 'to', 'KB4', '/', 'CL2']
  12. # commands e.g.['add', 'event', 'EV2', 'to', 'KB4/CL3']
  13. matched = []
  14. matched = Stateful.MatchTomlKeys(commands)
  15. sqls = ""
  16. # 1. exist check
  17. # 2. exec command
  18. con = sqlite3.connect(dbPath)
  19. cur = con.cursor()
  20. res = cur.execute(sqls)
  21. con.commit()
  22. print("res: ", res.fetchone())
  23. con.close()
  24. if __name__ == "__main__":
  25. sy = "CREATE TABLE Board(board_uid, board_name, status)"
  26. sy1 = "INSERT INTO Board VALUES('1', 'board1', 'live');"
  27. sy2 = "DROP TABLE test;"
  28. sy3 = "DROP TABLE Board"
  29. sy4 = "CREATE TABLE Board(uid, name, status)"
  30. sy5 = "INSERT INTO Board VALUES('1', 'KB1', 'live');"
  31. sy6 = ['add', 'board', 'KB1']
  32. while(1):
  33. sy_i = input("sql: ")
  34. Operate_sqlite3(dbPath, sy_i)