Class: SQLAnywhere::SQLAnywhereInterface
- Inherits:
-
Object
- Object
- SQLAnywhere::SQLAnywhereInterface
- Defined in:
- ext/sqlanywhere.c
Instance Method Summary collapse
-
#sqlany_affected_rows(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns the number of rows affected by execution of the prepared statement.
-
#sqlany_bind_param(VALUEapi, VALUEsqlany_stmt, VALUEindex, VALUEsqlany_bind_param) ⇒ Object
Binds a user supplied buffer as a parameter to the prepared statement.
-
#sqlany_clear_error(VALUEapi, VALUEsqlany_conn) ⇒ nil
Clears the last stored error code.
-
#sqlany_client_version(VALUEapi) ⇒ Array
Retrieves the client version as a string.
-
#sqlany_commit(VALUEapi, VALUEsqlany_conn) ⇒ Object
Commits the current transaction.
-
#sqlany_connect(VALUEapi, VALUEsqlany_conn, VALUEstr) ⇒ Object
Creates a connection object.
-
#sqlany_describe_bind_param(VALUEapi, VALUEsqlany_stmt, VALUEindex) ⇒ Array
Describes the bind parameters of a prepared statement.
-
#sqlany_disconnect(VALUEapi, VALUEsqlany_conn) ⇒ nil
Disconnect an already established connection.
-
#sqlany_error(VALUEapi, VALUEsqlany_conn) ⇒ Array
Retrieves the last error code and message.
-
#sqlany_execute(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Executes a prepared statement.
-
#sqlany_execute_direct(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Executes a SQL statement and possibly returns a result set.
-
#sqlany_execute_immediate(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Executes a SQL statement immediately without returning a result set.
-
#sqlany_fetch_absolute(VALUEapi, VALUEsqlany_stmt, VALUEoffset) ⇒ Object
Fetches data at a specific row number in the result set.
-
#sqlany_fetch_next(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Fetches the next row from the result set.
-
#sqlany_fini(VALUEapi) ⇒ nil
Finalizes the interface.
-
#sqlany_free_connection(VALUEapi, VALUEsqlany_conn) ⇒ nil
Frees the resources associated with a connection object.
-
#sqlany_free_stmt(VALUEapi, VALUEsqlany_stmt) ⇒ nil
Frees resources associated with a prepared statement object.
-
#sqlany_get_bind_param_info(VALUEapi, VALUEsqlany_stmt, VALUEindex) ⇒ Array
Gets bound parameter info.
-
#sqlany_get_column(VALUEapi, VALUEsqlany_stmt, VALUEcol_num) ⇒ Array
Retrieves the data fetched for the specified column.
-
#sqlany_get_column_info(VALUEapi, VALUEsqlany_stmt, VALUEcol_num) ⇒ Array
Fetches the next row from the result set.
-
#sqlany_get_next_result(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Advances to the next result set in a multiple result set query.
-
#sqlany_init(VALUEapi) ⇒ Array
Initializes the interface.
-
#sqlany_new_connection(VALUEapi) ⇒ Object
Creates a connection object.
-
#sqlany_num_cols(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns number of columns in the result set.
-
#sqlany_num_params(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns the number of parameters that are expected for a prepared statement.
-
#sqlany_num_rows(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns number of rows in the result set.
-
#sqlany_prepare(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Prepares a SQL statement.
-
#sqlany_rollback(VALUEapi, VALUEsqlany_conn) ⇒ Object
Rolls back the current transaction.
-
#sqlany_sqlstate(VALUEapi, VALUEsqlany_conn) ⇒ Object
Retrieves the current SQL state.
Instance Method Details
#sqlany_affected_rows(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns the number of rows affected by execution of the prepared
statement.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement that was prepared and executed successfully with no result set returned.
<b>Returns</b>:
- <tt>VALUE result</tt>: The number of rows affected or <tt>-1</tt> on failure.
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'ext/sqlanywhere.c', line 1020
static VALUE
static_SQLAnywhereInterface_sqlany_affected_rows(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
sacapi_i32 result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
result = s_api->sqlany_affected_rows(s_sqlany_stmt);
return ( INT2NUM(result) );
}
|
#sqlany_bind_param(VALUEapi, VALUEsqlany_stmt, VALUEindex, VALUEsqlany_bind_param) ⇒ Object
Binds a user supplied buffer as a parameter to the prepared statement.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
- <tt>VALUE sqlany_bind_param</tt> -- A filled bind object retrieved from sqlany_describe_bind_param().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'ext/sqlanywhere.c', line 1105
static VALUE
static_SQLAnywhereInterface_sqlany_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index, VALUE sqlany_bind_param )
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
a_sqlany_bind_param* s_sqlany_bind_param;
sacapi_bool result;
sacapi_u32 s_index;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
Data_Get_Struct(sqlany_bind_param, a_sqlany_bind_param, s_sqlany_bind_param);
s_index = NUM2INT(index);
result = s_api->sqlany_bind_param(s_sqlany_stmt, s_index, s_sqlany_bind_param);
return( INT2NUM(result) );
}
|
#sqlany_clear_error(VALUEapi, VALUEsqlany_conn) ⇒ nil
Clears the last stored error code.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>nil</tt>:.
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
# File 'ext/sqlanywhere.c', line 1316
static VALUE
static_SQLAnywhereInterface_sqlany_clear_error(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
s_api->sqlany_clear_error(s_sqlany_conn);
return( Qnil );
}
|
#sqlany_client_version(VALUEapi) ⇒ Array
Retrieves the client version as a string.
This function can be used to retrieve the client version.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- an initialized API structure to finalize
<b>Returns</b>:
- <tt>VALUE verstr</tt>: The client version string.
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'ext/sqlanywhere.c', line 338
static VALUE
static_SQLAnywhereInterface_sqlany_client_version(VALUE api)
{
SQLAnywhereInterface* s_api;
size_t s_size;
char s_buffer[255];
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
s_api->sqlany_client_version(s_buffer, 255);
return (rb_str_new2(s_buffer));
}
|
#sqlany_commit(VALUEapi, VALUEsqlany_conn) ⇒ Object
Commits the current transaction.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful commit, <tt>0</tt> otherwise.
829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'ext/sqlanywhere.c', line 829
static VALUE
static_SQLAnywhereInterface_sqlany_commit(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
result = s_api->sqlany_commit(s_sqlany_conn);
return( INT2NUM(result) );
}
|
#sqlany_connect(VALUEapi, VALUEsqlany_conn, VALUEstr) ⇒ Object
Creates a connection object.
An API connection object needs to be created before a database connection
is established. Errors can be retrieved from the connection object. Only
one request can be processed on a connection at a time.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was created by sqlany_new_connection().
- <tt>VALUE str</tt> -- A SQL Anywhere connection string.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'ext/sqlanywhere.c', line 371
static VALUE
static_SQLAnywhereInterface_sqlany_connect(VALUE api, VALUE sqlany_conn, VALUE str)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
char* s_str;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
s_str = StringValueCStr( str );
result = s_api->sqlany_connect( s_sqlany_conn, s_str );
return( INT2NUM(result) );
}
|
#sqlany_describe_bind_param(VALUEapi, VALUEsqlany_stmt, VALUEindex) ⇒ Array
Describes the bind parameters of a prepared statement.
This function allows the caller to determine information about parameters
to a prepared statement. Depending on the type of the prepared statement
(call to stored procedure or a DML), only some information will be
provided. The information that will always be provided is the direction
of the parameters (input, output, or input-output).
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params()- 1.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
- <tt>VALUE bind_param</tt>: The described param object.
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
# File 'ext/sqlanywhere.c', line 1057
static VALUE
static_SQLAnywhereInterface_sqlany_describe_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
a_sqlany_bind_param* s_sqlany_bind_param;
sacapi_bool result;
sacapi_u32 s_index;
VALUE tdata;
VALUE multi_result;
s_sqlany_bind_param = malloc(sizeof(a_sqlany_bind_param));
memset( s_sqlany_bind_param, 0, sizeof(a_sqlany_bind_param) );
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
s_index = NUM2INT(index);
result = s_api->sqlany_describe_bind_param(s_sqlany_stmt, s_index, s_sqlany_bind_param);
//FIXME handle failed result
multi_result = rb_ary_new();
rb_ary_push(multi_result, INT2NUM(result));
tdata = Data_Wrap_Struct(cA_sqlany_bind_param, 0, 0, s_sqlany_bind_param);
rb_ary_push(multi_result, tdata);
return( multi_result );
}
|
#sqlany_disconnect(VALUEapi, VALUEsqlany_conn) ⇒ nil
Disconnect an already established connection.
This function disconnects a SQL Anywhere connection. Any
uncommitted transactions will be rolled back.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>nil</tt>.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'ext/sqlanywhere.c', line 406
static VALUE
static_SQLAnywhereInterface_sqlany_disconnect(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
s_api->sqlany_disconnect( s_sqlany_conn );
return( Qnil );
}
|
#sqlany_error(VALUEapi, VALUEsqlany_conn) ⇒ Array
Retrieves the last error code and message.
This function can be used to retrieve the last error code and message
stored in the connection object.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>VALUE result</tt>: The last error code. Positive values are warnings, negative values are errors, and <tt>0</tt> is success.
- <tt>VALUE errstr</tt>: The error message corresponding to the error code.
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'ext/sqlanywhere.c', line 496
static VALUE
static_SQLAnywhereInterface_sqlany_error(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
size_t s_size;
char s_buffer[255];
sacapi_i32 result;
VALUE multi_result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
result = s_api->sqlany_error(s_sqlany_conn, s_buffer, 255);
multi_result = rb_ary_new();
rb_ary_push(multi_result, INT2NUM(result));
rb_ary_push(multi_result, rb_str_new2(s_buffer));
return( multi_result );
}
|
#sqlany_execute(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Executes a prepared statement.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
# File 'ext/sqlanywhere.c', line 990
static VALUE
static_SQLAnywhereInterface_sqlany_execute(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
result = s_api->sqlany_execute(s_sqlany_stmt);
return (INT2NUM(result));
}
|
#sqlany_execute_direct(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Executes a SQL statement and possibly returns a result set.
This function executes the SQL statement specified by the string argument.
This function is suitable if you want to prepare and then execute a
statement, and can be used instead of calling sqlany_prepare() followed
by sqlany_execute().
This function cannot be used for executing a SQL statement with
parameters.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
- <tt>VALUE sql</tt> -- A SQL query string.
<b>Returns</b>:
- <tt>VALUE result</tt>: A query result set if successful, nil if failed.
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'ext/sqlanywhere.c', line 579
static VALUE
static_SQLAnywhereInterface_sqlany_execute_direct(VALUE api, VALUE sqlany_conn, VALUE sql)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
a_sqlany_stmt* resultset = NULL;
char* s_sql;
VALUE tdata;
s_sql = StringValueCStr( sql );
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
resultset = s_api->sqlany_execute_direct(s_sqlany_conn, s_sql);
if (resultset)
{
tdata = Data_Wrap_Struct(cA_sqlany_stmt, 0, 0, resultset);
}
else
{
tdata = Qnil;
}
return (tdata);
}
|
#sqlany_execute_immediate(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Executes a SQL statement immediately without returning a result set.
This function executes the specified SQL statement immediately. It is
useful for SQL statements that do not return a result set.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
- <tt>VALUE sql</tt> -- A SQL query string.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'ext/sqlanywhere.c', line 538
static VALUE
static_SQLAnywhereInterface_sqlany_execute_immediate(VALUE api, VALUE sqlany_conn, VALUE sql)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
char* s_sql;
sacapi_bool result;
s_sql = StringValueCStr( sql );
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
result = s_api->sqlany_execute_immediate(s_sqlany_conn, s_sql);
return( INT2NUM(result) );
}
|
#sqlany_fetch_absolute(VALUEapi, VALUEsqlany_stmt, VALUEoffset) ⇒ Object
Fetches data at a specific row number in the result set.
This function moves the current row in the result set to the row number
specified and fetches the data at that row.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was executed by sqlany_execute() or sqlany_execute_direct().
- <tt>VALUE offset</tt> -- The row number to be fetched. The first row is <tt>1</tt>, the last row is <tt>-1</tt>.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> if the fetch was successfully, <tt>0</tt> otherwise.
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 |
# File 'ext/sqlanywhere.c', line 1256
static VALUE
static_SQLAnywhereInterface_sqlany_fetch_absolute(VALUE api, VALUE sqlany_stmt, VALUE offset)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
sacapi_i32 s_offset;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
s_offset = NUM2INT(offset);
result = s_api->sqlany_fetch_absolute(s_sqlany_stmt, s_offset);
return( INT2NUM(result) );
}
|
#sqlany_fetch_next(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Fetches the next row from the result set.
This function fetches the next row from the result set. When the result
object is first created, the current row pointer is set to point before
the first row (that is, row 0).
This function advances the row pointer first and then fetches the data
at the new row.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful fetch, <tt>0</tt> otherwise.
741 742 743 744 745 746 747 748 749 750 751 752 753 754 |
# File 'ext/sqlanywhere.c', line 741
static VALUE
static_SQLAnywhereInterface_sqlany_fetch_next(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_stmt;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
result = s_api->sqlany_fetch_next(s_stmt);
return( INT2NUM(result) );
}
|
#sqlany_fini(VALUEapi) ⇒ nil
Finalizes the interface.
Thus function frees any resources allocated by the API.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
<b>Returns</b>:
- <tt>nil</tt>.
465 466 467 468 469 470 471 472 473 474 475 |
# File 'ext/sqlanywhere.c', line 465
static VALUE
static_SQLAnywhereInterface_sqlany_fini(VALUE api)
{
SQLAnywhereInterface* s_api;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
s_api->sqlany_fini();
return( Qnil );
}
|
#sqlany_free_connection(VALUEapi, VALUEsqlany_conn) ⇒ nil
Frees the resources associated with a connection object.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was disconnected by sqlany_disconnect().
<b>Returns</b>:
- <tt>nil</tt>.
435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'ext/sqlanywhere.c', line 435
static VALUE
static_SQLAnywhereInterface_sqlany_free_connection(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
s_api->sqlany_free_connection( s_sqlany_conn );
return( Qnil );
}
|
#sqlany_free_stmt(VALUEapi, VALUEsqlany_stmt) ⇒ nil
Frees resources associated with a prepared statement object.
This function frees the resources associated with a prepared statement
object.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>nil</tt>.
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'ext/sqlanywhere.c', line 940
static VALUE
static_SQLAnywhereInterface_sqlany_free_stmt(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
int i;
int number_of_params = 0;
a_sqlany_bind_param_info bind_info;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
number_of_params = s_api->sqlany_num_params(s_sqlany_stmt);
for (i = 0; i < number_of_params; i++)
{
if( s_api->sqlany_get_bind_param_info(s_sqlany_stmt, i, &bind_info) )
{
// We don't free bind_info.name as it's not allocated
// if (bind_info.name) {free (bind_info.name);}
if (bind_info.input_value.is_null) {free(bind_info.input_value.is_null); }
if (bind_info.input_value.length) {free(bind_info.input_value.length); }
if (bind_info.input_value.buffer) {free(bind_info.input_value.buffer); }
if (bind_info.output_value.is_null) {free(bind_info.output_value.is_null); }
if (bind_info.output_value.length) {free(bind_info.output_value.length); }
if (bind_info.output_value.buffer) {free(bind_info.output_value.buffer); }
}
}
s_api->sqlany_free_stmt(s_sqlany_stmt);
return ( Qnil );
}
|
#sqlany_get_bind_param_info(VALUEapi, VALUEsqlany_stmt, VALUEindex) ⇒ Array
Gets bound parameter info.
This function retrieves information about the parameters that were
bound using sqlany_bind_param().
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
- <tt>VALUE bind_param</tt>: The described param object.
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 |
# File 'ext/sqlanywhere.c', line 1143
static VALUE
static_SQLAnywhereInterface_sqlany_get_bind_param_info(VALUE api, VALUE sqlany_stmt, VALUE index)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
a_sqlany_bind_param_info s_sqlany_bind_param_info;
sacapi_bool result;
sacapi_u32 s_index;
VALUE tdata;
VALUE multi_result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
s_index = NUM2INT(index);
result = s_api->sqlany_get_bind_param_info(s_sqlany_stmt, s_index, &s_sqlany_bind_param_info);
//FIXME handle failed result
multi_result = rb_ary_new();
rb_ary_push(multi_result, INT2NUM(result));
// FIXME: Is this safe to be on the stack?
tdata = Data_Wrap_Struct(cA_sqlany_bind_param_info, 0, 0, &s_sqlany_bind_param_info);
rb_ary_push(multi_result, tdata);
return( multi_result );
}
|
#sqlany_get_column(VALUEapi, VALUEsqlany_stmt, VALUEcol_num) ⇒ Array
Retrieves the data fetched for the specified column.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
- <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and sqlany_num_cols() - 1.
<b>Returns</b>:
- <tt>VALUE column_value</tt>: The value of the column. nil is returned if the value was NULL.
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'ext/sqlanywhere.c', line 684
static VALUE
static_SQLAnywhereInterface_sqlany_get_column(VALUE api, VALUE sqlany_stmt, VALUE col_num)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_stmt;
sacapi_u32 s_col_num;
a_sqlany_data_value value;
sacapi_bool result;
VALUE multi_result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
s_col_num = NUM2INT(col_num);
result = s_api->sqlany_get_column(s_stmt, s_col_num, &value );
multi_result = rb_ary_new();
rb_ary_push(multi_result, INT2NUM(result));
if( !result ) {
rb_ary_push(multi_result, Qnil);
}
else
{
if( *value.is_null )
{
rb_ary_push(multi_result, Qnil);
}
else
{
rb_ary_push(multi_result, C2RB(&value));
}
}
return( multi_result );
}
|
#sqlany_get_column_info(VALUEapi, VALUEsqlany_stmt, VALUEcol_num) ⇒ Array
Fetches the next row from the result set.
This function fetches the next row from the result set. When the result
object is first created, the current row pointer is set to point before
the first row (that is, row 0).
This function advances the row pointer first and then fetches the data
at the new row.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
- <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and sqlany_num_cols() - 1.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success. Returns <tt>0</tt> if the column index is out of range, or if the statement does not return a result set.
- <tt>VALUE col_num</tt>: The number of the column retrieved.
- <tt>VALUE name</tt>: The name of the column.
- <tt>VALUE type</tt>: The type of the column data.
- <tt>VALUE native_type</tt>: The SQL Anywhere native type of the column data.
- <tt>VALUE precision</tt>: The precision of the column.
- <tt>VALUE scale</tt>: The scale of the column.
- <tt>VALUE max_size</tt>: The maximum size a data value in this column can take.
- <tt>VALUE nullable</tt>: The nullability of the column.
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'ext/sqlanywhere.c', line 785
static VALUE
static_SQLAnywhereInterface_sqlany_get_column_info(VALUE api, VALUE sqlany_stmt, VALUE col_num)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_stmt;
sacapi_u32 s_col_num;
a_sqlany_column_info info;
sacapi_bool result;
VALUE multi_result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
s_col_num = NUM2INT(col_num);
result = s_api->sqlany_get_column_info(s_stmt, s_col_num, &info );
multi_result = rb_ary_new();
rb_ary_push(multi_result, INT2NUM(result));
rb_ary_push(multi_result, col_num );
rb_ary_push(multi_result, rb_str_new2(info.name));
rb_ary_push(multi_result, INT2NUM(info.type));
rb_ary_push(multi_result, INT2NUM(info.native_type));
rb_ary_push(multi_result, INT2NUM(info.precision));
rb_ary_push(multi_result, INT2NUM(info.scale));
rb_ary_push(multi_result, INT2NUM(info.max_size));
rb_ary_push(multi_result, INT2NUM(info.nullable));
return( multi_result );
}
|
#sqlany_get_next_result(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Advances to the next result set in a multiple result set query.
If a query (such as a call to a stored procedure) returns multiple result
sets, then this function advances from the current result set to the next.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was executed by sqlany_execute() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> if was successfully able to advance to the next result set, <tt>0</tt> otherwise.
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
# File 'ext/sqlanywhere.c', line 1223
static VALUE
static_SQLAnywhereInterface_sqlany_get_next_result(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
result = s_api->sqlany_get_next_result(s_sqlany_stmt);
return( INT2NUM(result) );
}
|
#sqlany_init(VALUEapi) ⇒ Array
Initializes the interface.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
- <tt>VALUE version</tt>: The maximum API version that is supported.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'ext/sqlanywhere.c', line 266
static VALUE
static_SQLAnywhereInterface_sqlany_init(VALUE api)
{
SQLAnywhereInterface* s_api;
sacapi_bool result;
sacapi_u32 s_version_available;
VALUE multi_result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
multi_result = rb_ary_new();
if( s_api == NULL ) {
rb_ary_push(multi_result, INT2NUM(0));
rb_ary_push(multi_result, Qnil );
} else {
result = s_api->sqlany_init("RUBY", SQLANY_CURRENT_API_VERSION , &s_version_available );
rb_ary_push(multi_result, INT2NUM(result));
rb_ary_push(multi_result, INT2NUM(s_version_available));
}
return( multi_result );
}
|
#sqlany_new_connection(VALUEapi) ⇒ Object
Creates a connection object.
An API connection object needs to be created before a database connection
is established. Errors can be retrieved from the connection object. Only
one request can be processed on a connection at a time.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
<b>Returns</b>:
- <tt>VALUE connection</tt>: A connection object.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'ext/sqlanywhere.c', line 307
static VALUE
static_SQLAnywhereInterface_sqlany_new_connection(VALUE api)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* ptr;
VALUE tdata;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
ptr = s_api->sqlany_new_connection();
tdata = Data_Wrap_Struct(cA_sqlany_connection, 0, 0, ptr);
return (tdata);
}
|
#sqlany_num_cols(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns number of columns in the result set.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>VALUE num_cols</tt>: The number of columns in the result set or <tt>-1</tt> on a failure.
621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'ext/sqlanywhere.c', line 621
static VALUE
static_SQLAnywhereInterface_sqlany_num_cols(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_stmt;
sacapi_i32 result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
result = s_api->sqlany_num_cols(s_stmt);
return( INT2NUM(result) );
}
|
#sqlany_num_params(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns the number of parameters that are expected for a prepared
statement.
This function retrieves information about the parameters that were bound
using sqlany_bind_param().
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
<b>Returns</b>:
- <tt>VALUE result</tt>: The number of parameters that are expected. <tt>-1</tt> if the sqlany_stmt object is not valid.
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 |
# File 'ext/sqlanywhere.c', line 1190
static VALUE
static_SQLAnywhereInterface_sqlany_num_params(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_sqlany_stmt;
sacapi_i32 result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
result = s_api->sqlany_num_params(s_sqlany_stmt);
return( INT2NUM(result) );
}
|
#sqlany_num_rows(VALUEapi, VALUEsqlany_stmt) ⇒ Object
Returns number of rows in the result set.
By default, this function only returns an estimate. To return an exact
count, users must set the ROW_COUNTS option on the connection.
Refer to SQL Anywhere documentation for the SQL syntax to set this option.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
<b>Returns</b>:
- <tt>VALUE num_rows</tt>: The number of rows in the result set or <tt>-1</tt> on a failure.
654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'ext/sqlanywhere.c', line 654
static VALUE
static_SQLAnywhereInterface_sqlany_num_rows(VALUE api, VALUE sqlany_stmt)
{
SQLAnywhereInterface* s_api;
a_sqlany_stmt* s_stmt;
sacapi_i32 result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
result = s_api->sqlany_num_rows(s_stmt);
return( INT2NUM(result) );
}
|
#sqlany_prepare(VALUEapi, VALUEsqlany_conn, VALUEsql) ⇒ Object
Prepares a SQL statement.
This function prepares the supplied SQL string. Execution does not
happen until sqlany_execute() is called. The returned statement object
should be freed using sqlany_free_stmt().
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
- <tt>VALUE sql</tt> -- SQL query to prepare.
<b>Returns</b>:
- <tt>VALUE stmt</tt>: A statement object, or nil on failure. The statement object can be used by sqlany_execute() to execute the statement.
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
# File 'ext/sqlanywhere.c', line 894
static VALUE
static_SQLAnywhereInterface_sqlany_prepare(VALUE api, VALUE sqlany_conn, VALUE sql)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
a_sqlany_stmt* ptr = NULL;
char* s_sql;
int result;
VALUE tdata;
s_sql = StringValueCStr( sql );
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
ptr = s_api->sqlany_prepare(s_sqlany_conn, s_sql);
if (ptr)
{
tdata = Data_Wrap_Struct(cA_sqlany_stmt, 0, 0, ptr);
}
else
{
tdata = Qnil;
}
return (tdata);
}
|
#sqlany_rollback(VALUEapi, VALUEsqlany_conn) ⇒ Object
Rolls back the current transaction.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful rollback, <tt>0</tt> otherwise.
859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'ext/sqlanywhere.c', line 859
static VALUE
static_SQLAnywhereInterface_sqlany_rollback(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
sacapi_bool result;
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
result = s_api->sqlany_rollback(s_sqlany_conn);
return( INT2NUM(result) );
}
|
#sqlany_sqlstate(VALUEapi, VALUEsqlany_conn) ⇒ Object
Retrieves the current SQL state.
<b>Parameters</b>:
- <tt>VALUE api</tt> -- An initialized API structure to finalize.
- <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
<b>Returns</b>:
- <tt>VALUE sqlstate_str</tt>: The SQL State.
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 |
# File 'ext/sqlanywhere.c', line 1286
static VALUE
static_SQLAnywhereInterface_sqlany_sqlstate(VALUE api, VALUE sqlany_conn)
{
SQLAnywhereInterface* s_api;
a_sqlany_connection* s_sqlany_conn;
size_t s_size;
char s_buffer[255];
Data_Get_Struct(api, SQLAnywhereInterface, s_api);
Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
s_size = s_api->sqlany_sqlstate(s_sqlany_conn, s_buffer, sizeof(s_buffer));
return( rb_str_new(s_buffer, s_size));
}
|