Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sqlalchemy import *
- from sqlalchemy import exc
- user = 'afi'
- pwd = 'afi16'
- host='localhost'
- database ='afi2016'
- cad='mysql://'+user+':'+pwd+'@'+host+'/'+database
- try:
- engine=create_engine(cad)
- engine.connect()
- engine.eco=False
- except exc.OperationalError,e:
- print('error:',e.args[0])
- #clientes=Table('cleintes18',metadata,autoload=True)
- metada=MetaData(engine)
- clientes=Table('clientes18',metada,
- Column('Id',Integer,primary_key=True),
- Column('Nombre',String(40)),
- Column('Apellidos',String(100)),
- Column('Edad',Integer),
- Column('Email',String(100)),
- Column('Password',String(20)),
- )
- if not clientes.exists():
- clientes.create()
- ins=clientes.insert()
- print ins
- ins.execute(Nombre='Maria',Apellidos='Fdez Fdez', Edad=30,
- Email='maria@hotmail.com', Password='secreto')
- ins.execute(
- {'Nombre':'Juan', 'Apellidos':'Diaz', 'Edad':50, 'Email':'juan@udc.com'},
- {'Nombre':'Pepe', 'Apellidos':'Alvarez', 'Edad':20, 'Email':'pepe@udc.com'}
- )
- s=clientes.select()
- rs=s.execute()
- row=rs.fetchone()
- nombres=row.keys()
- rs.fetchone()
- #print row.keys()
- print 'ID=', row[0]
- print 'Nombre', row['Nombre']
- print 'Edad=', row.Edad
- print 'Pwd=', row[clientes.c.Password]
- #for row in rs:
- # for k in range(0, len(nombres)):
- # print nombres[k]+':', row[k]
- s=clientes
- print 'Edad >30'
- for rows in rs:
- print row.Nombre+ ''+row.Apellidos+''+row[clientes.c.Email]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement