SQL Anywhere には、SQL Anywhere C API への低レベルのインターフェイスがあります。以降の各項で説明する API によって、SQL アプリケーションの迅速な開発が可能になります。Ruby によるアプリケーション開発の長所を示すために、次の Ruby のサンプルプログラムについて考えてみます。このプログラムは、SQL Anywhere Ruby 拡張をロードし、サンプルデータベースに接続し、Products テーブルのカラム値を表示し、接続を切断し、終了します。
begin require 'rubygems' gem 'sqlanywhere' unless defined? SQLAnywhere require 'sqlanywhere' end end api = SQLAnywhere::SQLAnywhereInterface.new() SQLAnywhere::API.sqlany_initialize_interface( api ) api.sqlany_init() conn = api.sqlany_new_connection() api.sqlany_connect( conn, "DSN=SQL Anywhere 12 Demo" ) stmt = api.sqlany_execute_direct( conn, "SELECT * FROM Products" ) num_rows = api.sqlany_num_rows( stmt ) num_rows.times { api.sqlany_fetch_next( stmt ) num_cols = api.sqlany_num_cols( stmt ) for col in 1..num_cols do info = api.sqlany_get_column_info( stmt, col - 1 ) unless info[3]==1 # Don't do binary rc, value = api.sqlany_get_column( stmt, col - 1 ) print "#{info[2]}=#{value}\n" end end print "\n" } api.sqlany_free_stmt( stmt ) api.sqlany_disconnect(conn) api.sqlany_free_connection(conn) api.sqlany_fini() SQLAnywhere::API.sqlany_finalize_interface( api ) |
この Ruby プログラムの結果セットから出力される最初の 2 つのローは、次のとおりです。
ID=300 Name=Tee Shirt Description=Tank Top Size=Small Color=White Quantity=28 UnitPrice=9.00 ID=301 Name=Tee Shirt Description=V-neck Size=Medium Color=Orange Quantity=54 UnitPrice=14.00 |
以降の各項では、サポートされている各関数について説明します。
sqlany_affected_rows
sqlany_bind_param 関数
sqlany_clear_error 関数
sqlany_client_version 関数
sqlany_commit 関数
sqlany_connect 関数
sqlany_describe_bind_param 関数
sqlany_disconnect 関数
sqlany_error 関数
sqlany_execute 関数
sqlany_execute_direct 関数
sqlany_execute_immediate 関数
sqlany_fetch_absolute 関数
sqlany_fetch_next 関数
sqlany_fini 関数
sqlany_free_connection 関数
sqlany_free_stmt 関数
sqlany_get_bind_param_info 関数
sqlany_get_column 関数
sqlany_get_column_info 関数
sqlany_get_next_result 関数
sqlany_init 関数
sqlany_new_connection 関数
sqlany_num_cols 関数
sqlany_num_params 関数
sqlany_num_rows 関数
sqlany_prepare 関数
sqlany_rollback 関数
sqlany_sqlstate 関数
カラムの型
ネイティブのカラム型
![]() |
DocCommentXchange で意見交換できます
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |