之前没试过, 我正在努力执行 Ruby Cucumber Step定义中的SQL查询。 完全不确定在建立连接后该怎么做。
连接(作品)
然后(/ ^ TC-0001-Bill-Of-Laiding Query onleLisa(Lisa_One)访问现有的Bill of laiding Order $ /)做
conn = DBI.connect('DBI:ODBC:GPAutomation','XXXXX','XXXXX')
conn.connected?
Framework Setup
require 'rubygems'
require 'watir-webdriver'
require 'watir'
require 'rspec'
require 'cucumber'
require 'selenium-webdriver'
require 'win32ole'
require 'rufus/scheduler'
require 'yaml'
require 'dbi'
The Query that I want to execute
select h.bol_id, * from bol_header h (nolock)
inner join bol_header_info hi (nolock) on h.bol_id = hi.bol_id
where h.facility_id = '505' and h.Status = 'O' and hi.order_type = 'S'
任何专业提示将不胜感激......
答案 0 :(得分:0)
您还没有告诉我们您的后端数据库。假设它是SQLite3软件。你会
gem install sqlite3
Ruby代码看起来像:
require 'rubygems'
require 'sqlite3'
DBNAME = "hello.sqlite"
File.delete(DBNAME) if File.exists?DBNAME
DB = SQLite3::Database.new( DBNAME )
DB.execute("CREATE TABLE testdata(class_name, method_name)")
# Looping through some Ruby data classes
insert_query = "INSERT INTO testdata(class_name, method_name) VALUES(?, ?)"
[Numeric, String, Array, IO, Kernel, SQLite3, NilClass, MatchData].each do |klass|
puts "Inserting methods for #{klass}"
# a second loop: iterate through each method
klass.methods.each do |method_name|
# Note: method_name is actually a Symbol, so we need to convert it to a String
# via .to_s
DB.execute(insert_query, klass.to_s, method_name.to_s)
end
end
我是从Dan Nguyen网页上提取的。看那里更多。