SQL Anywhere provides a low-level interface to the SQL Anywhere C API. The API described in the following sections permits the rapid development of SQL applications. To demonstrate the power of Ruby application development, consider the following sample Ruby program. It loads the SQL Anywhere Ruby extension, connects to the sample database, lists column values from the Products table, disconnects, and terminates.
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 ) |
The first two rows of the result set output from this Ruby program are shown below:
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 |
The following sections describe each of the supported functions.
sqlany_affected_rows
sqlany_bind_param function
sqlany_clear_error function
sqlany_client_version function
sqlany_commit function
sqlany_connect function
sqlany_describe_bind_param function
sqlany_disconnect function
sqlany_error function
sqlany_execute function
sqlany_execute_direct function
sqlany_execute_immediate function
sqlany_fetch_absolute function
sqlany_fetch_next function
sqlany_fini function
sqlany_free_connection function
sqlany_free_stmt function
sqlany_get_bind_param_info function
sqlany_get_column function
sqlany_get_column_info function
sqlany_get_next_result function
sqlany_init function
sqlany_new_connection function
sqlany_num_cols function
sqlany_num_params function
sqlany_num_rows function
sqlany_prepare function
sqlany_rollback function
sqlany_sqlstate function
Column types
Native column types
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |