direct.py 634 B

1234567891011121314151617181920212223242526272829
  1. import sqlite3
  2. def Operate_sqlite3(dbPath, commands):
  3. con = sqlite3.connect(dbPath)
  4. cur = con.cursor()
  5. # 1. exist check
  6. try:
  7. res = cur.execute(commands)
  8. con.commit()
  9. print("res.fetchone() is None: ", res.fetchone() is None)
  10. # syntax right but not exist:
  11. if res.fetchone() is None == True:
  12. print("err <Code>: could not found, creat? y/n")
  13. except:
  14. print("err <Code>: Syntax error")
  15. con.close()
  16. if __name__ == "__main__":
  17. while(1):
  18. # syi = input("sql: ").split()
  19. sy_i = input("sql: ")
  20. Operate_sqlite3("dev.db", sy_i)