Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Задание 1
- ### slide::
- ### title:: Exercises
- # Assuming this table:
- #
- # CREATE TABLE employee (
- # emp_id INTEGER PRIMARY KEY,
- # emp_name VARCHAR(30)
- # }
- #
- # And using the "engine.execute()" method to invoke a statement:
- #
- # 1. Execute an INSERT statement that will insert the row with emp_name='dilbert'.
- # The primary key column can be omitted so that it is generated automatically.
- # 2. SELECT all rows from the employee table.
- #Создаем таблицу
- from sqlalchemy import create_engine
- import os
- if os.path.exists("some.db"):
- os.remove("some.db")
- e = create_engine("sqlite:///some.db")
- e.execute("""
- create table employee (
- emp_id INTEGER PRIMARY KEY,
- emp_name VARCHAR(30)
- )
- """)
- #Добавляем строку
- e.execute("""insert into employee(emp_name) values ('dilbert')""")
- #Выводим результат
- result = e.execute("select * from employee")
- for row in result:
- print(row)
- #Ответ
- marina@debian:~$ python lab5.py
- (1, u'dilbert')
Add Comment
Please, Sign In to add comment