Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 (中文) » SQL Anywhere 服务器 - 编程 » Ruby 支持

 

SQL Anywhere Ruby API 参考

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 16 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 程序输出的结果集的前两行如下所示:



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 函数
列类型
本地列类型