Ruby でODBC 経由でSage 200 に接続して、モダンなクラウド連携アプリを開発。
CData ODBC Driver for Sage 200 を使うと、簡単にRuby アプリケーションにリアルタイムSage 200 データを連携・統合できます。 Tこの記事では、Sage 200] データにリアルタイムに連携するRuby アプリケーションを構築して、クエリを実行し、結果を表示してみます。
Sage 200 データのODBC 接続を設定
通常はCData ODBC Driver のインストール後にODBC DSN 接続ウィザードが立ち上がり、設定を行うことができます。 もしODBC DSN 接続が未済の場合には、Microsoft ODBC データソースアドミニストレータでODBC DSN を作成および設定することができます。
- Schema: Determines which Sage 200 edition you are connecting to. Specify either StandardUK or ProfessionalUK.
- Subscription Key: Provides access to the APIs that are used to establish a connection. You will first need to log into the Sage 200 API website and subscribe to the API edition that matches your account. You can do so here: https://developer.columbus.sage.com/docs/services/api/uk. Afterwards, the subscription key may be found in your profile after logging into Sage 200.
Ruby および必要なGem のインストール
If you do not have Ruby installed, refer to the Ruby インストールページ. Ruby をインストールしたら、次にruby-dbi、dbd-odbc、ruby-odbc gems をインストールします:
gem install dbi
gem install dbd-odbc
gem install ruby-odbc
Sage 200 データに連携するRuby アプリケーションの作成
Ruby ファイル (例: Sage200Select.rb) を作成し、テキストエディタで開きます。ファイルに次のコードをコピーします:
#connect to the DSN
require 'DBI'
cnxn = DBI.connect('DBI:ODBC:CData Sage200 Source','','')
#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT Id, Code FROM Banks WHERE Code = '12345'")
#display the names of the columns
resultSet.column_names.each do |name|
print name, "\t"
end
puts
#display the results
while row = resultSet.fetch do
(0..resultSet.column_names.size - 1).each do |n|
print row[n], "\t"
end
puts
end
resultSet.finish
#close the connection
cnxn.disconnect if cnxn
これで、Ruby で Sage 200 データが接続できるようになります。簡単にコマンドラインからファイルを叩いて接続を確認してみましょう。:
ruby Sage200Select.rb
Sage 200 へのSQL-92 企画のSQL を使って、Ruby に簡単にSage 200 を連携できます。是非、トライアルで試してみてください。