Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/usr/bin/python
  2. import psycopg2
  3. ##INGRESOS DE DATOS A LA TABLA VENTA
  4. id =input ("Ingrese un id: ")
  5. id_stock= raw_input ("Ingrese un nombre: ")
  6. cantidad = input ("Ingrese cantidad: ")
  7. bd = psycopg2.connect(database="stock", user="postgres", password="usuario", host="127.0.0.1", port="5432")
  8. cursor = bd.cursor()
  9. sql = "INSERT INTO venta VALUES ('%s', '%s','%s')" %(id,id_stock,cantidad)
  10. cursor.execute(sql)
  11. bd.commit()
  12.  
  13. ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA VENTA
  14. recu = "select cantidad from venta where id = %s;" %id
  15. cursor.execute(recu)
  16. dato= cursor.fetchall()
  17. print "se vendio %s cantidades de mercaderia" %dato[0]
  18.  
  19. ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA STOCK
  20. recu2 = "select cantidad from stock where id_stock = %s;" %id_stock
  21. cursor.execute(recu2)
  22. dato2= cursor.fetchall()
  23. print "existia %s cantidad de mercaderia" %dato2[0]
  24.  
  25. ##RESTANDO AMBOS VALORES
  26. valor=dato2[0][0] - dato[0][0]
  27.  
  28. ##RECUPERANDO EL VALOR DE LA COLUMNA CANTIDAD /TABLA STOCK
  29. recu3 = "update stock set cantidad ='%s' where id_stock=%s" %(valor,id_stock)
  30. cursor.execute(recu3)
  31. bd.commit()
  32. print "solo quedan %s mercaderias en stock." %valor
  33. bd.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement