2016-04-15 11 views
0

Ruby Cucumberステップ定義内からSQLクエリを実行しようとしています。 接続が完了した後に何をすべきか全く分かりません。Ruby Cucumberステップ定義内からsqlクエリを実行

接続(ワークス)次に

(/^TC-0001-ビル・オブ・LaidingクエリonleLisa(Lisa_One)はlaiding既存のビルにアクセスするために$ /)を行う

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

あなたはsequel - http://sequel.jeremyevans.net/をチェックしてみるとよいでしょう。 SQLクエリを実行するには - http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html#label-Arbitrary+SQL+queries。 – alannichols

+0

あなたのDBに接続する - http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html#label-Using+the+Sequel.connect+method – alannichols

答えて

0

あなたは私たちにあなたのバックエンドデータベースを教えていません。それがSQLite3ソフトウェアであると仮定します。私はDan Nguyen Webページからこれを引っ張っ

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 

:あなたは

gem install sqlite3 

Rubyのコードは次のようになります。そこをもっと見る。

+0

あなたのrespnseに感謝...それはSQL – KWC

+0

Sequelを使用して生のSQLを実行しようとしています... – KWC

+0

@ user3233238データベースエンジンを教えてください。例えば。 Oracle、MySql、Microsoft SQL Server、DB2、Microsoft Access、SQLLiteなど。私の助言はgoogle <あなたのSQLエンジン> **ルビーの例です。** – MikeJRamsey56

関連する問題