Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import psycopg2
- ##INGRESOS DE DATOS A LA TABLA VENTA
- id =input ("Ingrese un id: ")
- id_stock= raw_input ("Ingrese un nombre: ")
- cantidad = input ("Ingrese cantidad: ")
- bd = psycopg2.connect(database="stock", user="postgres", password="usuario", host="127.0.0.1", port="5432")
- cursor = bd.cursor()
- sql = "INSERT INTO venta VALUES ('%s', '%s','%s')" %(id,id_stock,cantidad)
- cursor.execute(sql)
- bd.commit()
- ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA VENTA
- recu = "select cantidad from venta where id = %s;" %id
- cursor.execute(recu)
- dato= cursor.fetchall()
- print "se vendio %s cantidades de mercaderia" %dato[0]
- ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA STOCK
- recu2 = "select cantidad from stock where id_stock = %s;" %id_stock
- cursor.execute(recu2)
- dato2= cursor.fetchall()
- print "existia %s cantidad de mercaderia" %dato2[0]
- ##RESTANDO AMBOS VALORES
- valor=dato2[0][0] - dato[0][0]
- ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA STOCK
- recu3 = "update stock set cantidad ='%s' where id_stock=%s" %(valor,id_stock)
- cursor.execute(recu3)
- bd.commit()
- print "solo quedan %s mercaderias en stock." %valor
- bd.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement