Database Reference
In-Depth Information
(portfolio_id, ticker, current_price,
current_change, current_change_percent)
VALUES
(756716f7-2e54-4715-9f00-91dcbea6cf50,
'GOOG', 889.07, -4.00, -0.45);
CQL
row_two = <<-CQL
INSERT INTO portfolio_demo.portfolio
(portfolio_id, ticker, current_price,
current_change, current_change_percent)
VALUES
(756716f7-2e54-4715-9f00-91dcbea6cf50,
'AMZN', 297.92, -0.94, -0.31);
CQL
@cluster.execute(row_one)
@cluster.execute(row_two)
end
def print_results
fields = %w(ticker current_price current_change
current_change_percent)
results_query = <<-CQL
SELECT * FROM portfolio_demo.portfolio
WHERE portfolio_id =
756716f7-2e54-4715-9f00-91dcbea6cf50;
CQL
puts "Ticker\tPrice\tChange\tPCT"
puts '........+........+........+........'
results = @cluster.execute(results_query)
results.each do |row|
puts "%s\t%0.2f\t%0.2f\t%0.2f" % fields.map{|f|
row[f] }
end
end
Search WWH ::




Custom Search