异常处理:# 异常一: AttributeError,对象属性不存在
with engine.connect() as conn:
trans = conn.begin()
s = select([users])
try:
r = conn.execute(s)
for record in r:
print record.Password
except AttributeError, e:
print 'found errors: {0}'.format(e)
trans.rollback()
# 异常二: IntegrityError,唯一约束错误
with engine.connect() as conn:
trans = conn.begin()
ins = users.insert().values(
id=2,
customer_number=2,
username='limanman',
email_address='xmdevops@vip.qq.com',
phone='11011011011',
password='2',
created_on='2016-11-06',
updated_on='2016-11-06',
)
from sqlalchemy.exc import IntegrityError
try:
res = conn.execute(ins)