matkant_invoice/update.rb

21 lines
534 B
Ruby

require 'mysql2'
load 'config.rb'
db = Mysql2::Client.new(:host => DB_HOST, :username => DB_USER, :database => DB_DB)
person = ARGV[0]
product = ARGV[1]
amount = ARGV[2]
log_dir = "./log/"
amount = 1.0 unless amount
statement = db.prepare("INSERT INTO transactions (buyer, product, amount) VALUES (?, ?, ?)")
result = statement.execute(person,product,amount)
puts result
#output = File.open("#{log_dir}/matkant-#{Time.now.strftime('%Y%W')}.log","a+")
#output << "#{Time.now.to_i};#{person};#{product};#{amount}\n"
#output.close