Guest User

Untitled

a guest
Nov 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Задание 1
  2. ### slide::
  3. ### title:: Exercises
  4. # Assuming this table:
  5. #
  6. # CREATE TABLE employee (
  7. # emp_id INTEGER PRIMARY KEY,
  8. # emp_name VARCHAR(30)
  9. # }
  10. #
  11. # And using the "engine.execute()" method to invoke a statement:
  12. #
  13. # 1. Execute an INSERT statement that will insert the row with emp_name='dilbert'.
  14. # The primary key column can be omitted so that it is generated automatically.
  15. # 2. SELECT all rows from the employee table.
  16.  
  17. #Создаем таблицу
  18. from sqlalchemy import create_engine
  19. import os
  20. if os.path.exists("some.db"):
  21. os.remove("some.db")
  22. e = create_engine("sqlite:///some.db")
  23. e.execute("""
  24. create table employee (
  25. emp_id INTEGER PRIMARY KEY,
  26. emp_name VARCHAR(30)
  27. )
  28. """)
  29. #Добавляем строку
  30. e.execute("""insert into employee(emp_name) values ('dilbert')""")
  31. #Выводим результат
  32. result = e.execute("select * from employee")
  33. for row in result:
  34. print(row)
  35.  
  36. #Ответ
  37. marina@debian:~$ python lab5.py
  38. (1, u'dilbert')
Add Comment
Please, Sign In to add comment