sqlanywhere 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/sqlanywhere.c ADDED
@@ -0,0 +1,1648 @@
1
+ /*====================================================
2
+ *
3
+ * Copyright 2008 iAnywhere Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ *
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * While not a requirement of the license, if you do modify this file, we
20
+ * would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
+ *:
22
+ *
23
+ *====================================================*/
24
+ #include "ruby.h"
25
+ #include "sacapidll.h"
26
+
27
+ const char* VERSION = "0.1.1";
28
+
29
+ // Defining the Ruby Modules
30
+ static VALUE mSQLAnywhere;
31
+ static VALUE mAPI;
32
+ static VALUE cSQLAnywhereInterface;
33
+
34
+ // Defining binder for DBCAPI types
35
+ static VALUE cA_sqlany_connection;
36
+ static VALUE cA_sqlany_data_value;
37
+ static VALUE cA_sqlany_stmt;
38
+ static VALUE cA_sqlany_bind_param;
39
+ static VALUE cA_sqlany_bind_param_info;
40
+
41
+ // This function is called when the module is first loaded by ruby.
42
+ // The name of this function MUST match be Init_<modulename>.
43
+ void Init_sqlanywhere();
44
+
45
+ // Wrapper functions for the DBICAPI functions
46
+
47
+ static VALUE
48
+ static_API_sqlany_initialize_interface(VALUE module, VALUE api);
49
+
50
+ static VALUE
51
+ static_API_sqlany_finalize_interface(VALUE module, VALUE api);
52
+
53
+ static VALUE
54
+ static_SQLAnywhereInterface_alloc(VALUE class);
55
+
56
+ static VALUE
57
+ static_SQLAnywhereInterface_sqlany_init(VALUE class);
58
+
59
+ static VALUE
60
+ static_SQLAnywhereInterface_sqlany_new_connection(VALUE class);
61
+
62
+ static VALUE
63
+ static_SQLAnywhereInterface_sqlany_disconnect(VALUE api, VALUE sqlany_conn);
64
+
65
+ static VALUE
66
+ static_SQLAnywhereInterface_sqlany_free_connection(VALUE api, VALUE sqlany_conn);
67
+
68
+ static VALUE
69
+ static_SQLAnywhereInterface_sqlany_fini(VALUE api);
70
+
71
+ static VALUE
72
+ static_SQLAnywhereInterface_sqlany_error(VALUE api, VALUE sqlany_conn);
73
+
74
+ static VALUE
75
+ static_SQLAnywhereInterface_sqlany_execute_immediate(VALUE api, VALUE sqlany_conn, VALUE sql);
76
+
77
+ static VALUE
78
+ static_SQLAnywhereInterface_sqlany_execute_direct(VALUE api, VALUE sqlany_conn, VALUE sql);
79
+
80
+ static VALUE
81
+ static_SQLAnywhereInterface_sqlany_num_cols(VALUE api, VALUE sqlany_stmt);
82
+
83
+ static VALUE
84
+ static_SQLAnywhereInterface_sqlany_num_rows(VALUE api, VALUE sqlany_stmt);
85
+
86
+ static VALUE
87
+ static_SQLAnywhereInterface_sqlany_get_column(VALUE api, VALUE sqlany_stmt, VALUE col_num);
88
+
89
+ static VALUE
90
+ static_SQLAnywhereInterface_sqlany_fetch_next(VALUE api, VALUE sqlany_stmt);
91
+
92
+ static VALUE
93
+ static_SQLAnywhereInterface_sqlany_get_column_info(VALUE api, VALUE sqlany_stmt, VALUE col_num);
94
+
95
+ static VALUE
96
+ static_SQLAnywhereInterface_sqlany_commit(VALUE api, VALUE sqlany_conn);
97
+
98
+ static VALUE
99
+ static_SQLAnywhereInterface_sqlany_rollback(VALUE api, VALUE sqlany_conn);
100
+
101
+ static VALUE
102
+ static_SQLAnywhereInterface_sqlany_prepare(VALUE api, VALUE sqlany_conn, VALUE sql);
103
+
104
+ static VALUE
105
+ static_SQLAnywhereInterface_sqlany_free_stmt(VALUE api, VALUE sqlany_stmt);
106
+
107
+ static VALUE
108
+ static_SQLAnywhereInterface_sqlany_execute(VALUE api, VALUE sqlany_stmt);
109
+
110
+ static VALUE
111
+ static_SQLAnywhereInterface_sqlany_affected_rows(VALUE api, VALUE sqlany_stmt);
112
+
113
+ static VALUE
114
+ static_SQLAnywhereInterface_sqlany_describe_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index);
115
+
116
+ /*
117
+ * C to Ruby Data conversion function to convert DBCAPI column type into the correct Ruby type
118
+ */
119
+ static VALUE C2RB(a_sqlany_data_value* value)
120
+ {
121
+ VALUE tdata;
122
+
123
+ switch( value->type ) {
124
+ case A_BINARY:
125
+ tdata = rb_str_new(value->buffer, *value->length);
126
+ break;
127
+ case A_STRING:
128
+ tdata = rb_str_new(value->buffer, *value->length);
129
+ break;
130
+ case A_DOUBLE:
131
+ tdata = rb_float_new(*(double*) value->buffer);
132
+ break;
133
+ case A_VAL64:
134
+ tdata = LL2NUM(*(LONG_LONG*)value->buffer);
135
+ break;
136
+ case A_UVAL64:
137
+ tdata = ULL2NUM(*(unsigned LONG_LONG*)value->buffer);
138
+ break;
139
+ case A_VAL32:
140
+ tdata = INT2NUM(*(int *)value->buffer);
141
+ break;
142
+ case A_UVAL32:
143
+ tdata = UINT2NUM(*(unsigned int *)value->buffer);
144
+ break;
145
+ case A_VAL16:
146
+ tdata = INT2NUM(*(short *)value->buffer);
147
+ break;
148
+ case A_UVAL16:
149
+ tdata = UINT2NUM(*( unsigned short *)value->buffer);
150
+ break;
151
+ case A_VAL8:
152
+ tdata = CHR2FIX(*(unsigned char *)value->buffer);
153
+ break;
154
+ case A_UVAL8:
155
+ tdata = CHR2FIX(*(unsigned char *)value->buffer);
156
+ break;
157
+ default:
158
+ rb_raise(rb_eTypeError, "Invalid Data Type");
159
+ tdata = Qnil;
160
+ break;
161
+ }
162
+
163
+ return tdata;
164
+ }
165
+
166
+ /*
167
+ * call-seq:
168
+ * sqlany_initialize_interface(VALUE api) -> int result
169
+ *
170
+ * Initializes the SQLAnywhereInterface object and loads the DLL dynamically.
171
+ *
172
+ * This function attempts to load the SQL Anywhere C API DLL dynamically and
173
+ * looks up all the entry points of the DLL.
174
+ *
175
+ * <b>Parameters</b>:
176
+ * - <tt>VALUE api</tt> -- An API structure to initialize.
177
+ *
178
+ * <b>Returns</b>:
179
+ * - <tt>result</tt>: <tt>1</tt> on successful initialization, <tt>0</tt> on failure.
180
+ *
181
+ */
182
+ static VALUE
183
+ static_API_sqlany_initialize_interface(VALUE module, VALUE api)
184
+ {
185
+ SQLAnywhereInterface* s_api;
186
+ int result;
187
+
188
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
189
+
190
+ result = sqlany_initialize_interface( s_api, NULL );
191
+
192
+ return( INT2NUM(result) );
193
+ }
194
+
195
+ /*
196
+ * call-seq:
197
+ * sqlany_finalize_interface(VALUE api) -> nil
198
+ *
199
+ * Finalize and free resources associated with the SQL Anywhere C API DLL.
200
+ *
201
+ * This function will unload the library and uninitialize the supplied
202
+ * SQLAnywhereInterface structure.
203
+ *
204
+ * <b>Parameters</b>:
205
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
206
+ *
207
+ * <b>Returns</b>:
208
+ * - <tt>nil</tt>.
209
+ *
210
+ */
211
+ static VALUE
212
+ static_API_sqlany_finalize_interface(VALUE module, VALUE api)
213
+ {
214
+ SQLAnywhereInterface* s_api;
215
+
216
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
217
+
218
+ sqlany_finalize_interface(s_api);
219
+
220
+ free(s_api);
221
+
222
+ return( Qnil );
223
+ }
224
+
225
+ static VALUE
226
+ static_SQLAnywhereInterface_alloc(VALUE class)
227
+ {
228
+ SQLAnywhereInterface *s_api = NULL;
229
+ VALUE tdata;
230
+
231
+ s_api = malloc( sizeof(SQLAnywhereInterface) );
232
+ memset( s_api, 0, sizeof(SQLAnywhereInterface));
233
+
234
+ tdata = Data_Wrap_Struct(class, 0, 0, s_api);
235
+ return tdata;
236
+ }
237
+
238
+ /*
239
+ * call-seq:
240
+ * sqlany_init(VALUE api) -> [VALUE result, VALUE version]
241
+ *
242
+ * Initializes the interface.
243
+ *
244
+ * <b>Parameters</b>:
245
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
246
+ *
247
+ * <b>Returns</b>:
248
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
249
+ * - <tt>VALUE version</tt>: The maximum API version that is supported.
250
+ *
251
+ */
252
+ static VALUE
253
+ static_SQLAnywhereInterface_sqlany_init(VALUE api)
254
+ {
255
+ SQLAnywhereInterface* s_api;
256
+ sacapi_bool result;
257
+ sacapi_u32 s_version_available;
258
+ VALUE multi_result;
259
+
260
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
261
+
262
+ multi_result = rb_ary_new();
263
+
264
+ if( s_api == NULL ) {
265
+ rb_ary_push(multi_result, INT2NUM(0));
266
+ rb_ary_push(multi_result, Qnil );
267
+ } else {
268
+ result = s_api->sqlany_init("RUBY", SQLANY_CURRENT_API_VERSION , &s_version_available );
269
+ rb_ary_push(multi_result, INT2NUM(result));
270
+ rb_ary_push(multi_result, INT2NUM(s_version_available));
271
+ }
272
+
273
+ return( multi_result );
274
+ }
275
+
276
+ /*
277
+ * call-seq:
278
+ * sqlany_new_connection(VALUE api) -> VALUE connection
279
+ *
280
+ * Creates a connection object.
281
+ *
282
+ * An API connection object needs to be created before a database connection
283
+ * is established. Errors can be retrieved from the connection object. Only
284
+ * one request can be processed on a connection at a time.
285
+ *
286
+ * <b>Parameters</b>:
287
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
288
+ *
289
+ * <b>Returns</b>:
290
+ * - <tt>VALUE connection</tt>: A connection object.
291
+ *
292
+ */
293
+ static VALUE
294
+ static_SQLAnywhereInterface_sqlany_new_connection(VALUE api)
295
+ {
296
+ SQLAnywhereInterface* s_api;
297
+ a_sqlany_connection* ptr;
298
+ VALUE tdata;
299
+
300
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
301
+ ptr = s_api->sqlany_new_connection();
302
+
303
+ tdata = Data_Wrap_Struct(cA_sqlany_connection, 0, 0, ptr);
304
+
305
+ return (tdata);
306
+ }
307
+
308
+ /*
309
+ * call-seq:
310
+ * sqlany_connect(VALUE api, VALUE sqlany_conn, VALUE str) -> VALUE result
311
+ *
312
+ * Creates a connection object.
313
+ *
314
+ * An API connection object needs to be created before a database connection
315
+ * is established. Errors can be retrieved from the connection object. Only
316
+ * one request can be processed on a connection at a time.
317
+ *
318
+ * <b>Parameters</b>:
319
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
320
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was created by sqlany_new_connection().
321
+ * - <tt>VALUE str</tt> -- A SQL Anywhere connection string.
322
+ *
323
+ * <b>Returns</b>:
324
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
325
+ *
326
+ */
327
+ static VALUE
328
+ static_SQLAnywhereInterface_sqlany_connect(VALUE api, VALUE sqlany_conn, VALUE str)
329
+ {
330
+ SQLAnywhereInterface* s_api;
331
+ a_sqlany_connection* s_sqlany_conn;
332
+ char* s_str;
333
+ sacapi_bool result;
334
+
335
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
336
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
337
+
338
+ s_str = StringValueCStr( str );
339
+
340
+ result = s_api->sqlany_connect( s_sqlany_conn, s_str );
341
+
342
+ return( INT2NUM(result) );
343
+ }
344
+
345
+ /*
346
+ * call-seq:
347
+ * sqlany_disconnect(VALUE api, VALUE sqlany_conn) -> nil
348
+ *
349
+ * Disconnect an already established connection.
350
+ *
351
+ * This function disconnects a SQL Anywhere connection. Any
352
+ * uncommitted transactions will be rolled back.
353
+ *
354
+ * <b>Parameters</b>:
355
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
356
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
357
+ *
358
+ * <b>Returns</b>:
359
+ * - <tt>nil</tt>.
360
+ *
361
+ */
362
+ static VALUE
363
+ static_SQLAnywhereInterface_sqlany_disconnect(VALUE api, VALUE sqlany_conn)
364
+ {
365
+ SQLAnywhereInterface* s_api;
366
+ a_sqlany_connection* s_sqlany_conn;
367
+
368
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
369
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
370
+
371
+
372
+ s_api->sqlany_disconnect( s_sqlany_conn );
373
+
374
+ return( Qnil );
375
+ }
376
+
377
+ /*
378
+ * call-seq:
379
+ * sqlany_free_connection(VALUE api, VALUE sqlany_conn) -> nil
380
+ *
381
+ * Frees the resources associated with a connection object.
382
+ *
383
+ * <b>Parameters</b>:
384
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
385
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was disconnected by sqlany_disconnect().
386
+ *
387
+ * <b>Returns</b>:
388
+ * - <tt>nil</tt>.
389
+ *
390
+ */
391
+ static VALUE
392
+ static_SQLAnywhereInterface_sqlany_free_connection(VALUE api, VALUE sqlany_conn)
393
+ {
394
+ SQLAnywhereInterface* s_api;
395
+ a_sqlany_connection* s_sqlany_conn;
396
+
397
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
398
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
399
+
400
+
401
+ s_api->sqlany_free_connection( s_sqlany_conn );
402
+
403
+ return( Qnil );
404
+ }
405
+
406
+ /*
407
+ * call-seq:
408
+ * sqlany_fini(VALUE api) -> nil
409
+ *
410
+ * Finalizes the interface.
411
+ *
412
+ * Thus function frees any resources allocated by the API.
413
+ *
414
+ * <b>Parameters</b>:
415
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
416
+ *
417
+ * <b>Returns</b>:
418
+ * - <tt>nil</tt>.
419
+ *
420
+ */
421
+ static VALUE
422
+ static_SQLAnywhereInterface_sqlany_fini(VALUE api)
423
+ {
424
+ SQLAnywhereInterface* s_api;
425
+
426
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
427
+
428
+ s_api->sqlany_fini();
429
+
430
+ return( Qnil );
431
+ }
432
+
433
+ /*
434
+ * call-seq:
435
+ * sqlany_error(VALUE api, VALUE sqlany_conn) -> [VALUE result, VALUE errstr]
436
+ *
437
+ * Retrieves the last error code and message.
438
+ *
439
+ * This function can be used to retrieve the last error code and message
440
+ * stored in the connection object.
441
+ *
442
+ * <b>Parameters</b>:
443
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
444
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
445
+ *
446
+ * <b>Returns</b>:
447
+ * - <tt>VALUE result</tt>: The last error code. Positive values are warnings, negative values are errors, and <tt>0</tt> is success.
448
+ * - <tt>VALUE errstr</tt>: The error message corresponding to the error code.
449
+ *
450
+ */
451
+
452
+ static VALUE
453
+ static_SQLAnywhereInterface_sqlany_error(VALUE api, VALUE sqlany_conn)
454
+ {
455
+ SQLAnywhereInterface* s_api;
456
+ a_sqlany_connection* s_sqlany_conn;
457
+ size_t s_size;
458
+ char s_buffer[255];
459
+ sacapi_i32 result;
460
+ VALUE multi_result;
461
+
462
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
463
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
464
+
465
+ result = s_api->sqlany_error(s_sqlany_conn, s_buffer, 255);
466
+
467
+ multi_result = rb_ary_new();
468
+
469
+ rb_ary_push(multi_result, INT2NUM(result));
470
+ rb_ary_push(multi_result, rb_str_new2(s_buffer));
471
+
472
+ return( multi_result );
473
+ }
474
+
475
+ /*
476
+ * call-seq:
477
+ * sqlany_execute_immediate(VALUE api, VALUE sqlany_conn, VALUE sql) -> VALUE result
478
+ *
479
+ * Executes a SQL statement immediately without returning a result set.
480
+ *
481
+ * This function executes the specified SQL statement immediately. It is
482
+ * useful for SQL statements that do not return a result set.
483
+ *
484
+ *
485
+ * <b>Parameters</b>:
486
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
487
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
488
+ * - <tt>VALUE sql</tt> -- A SQL query string.
489
+ *
490
+ * <b>Returns</b>:
491
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
492
+ *
493
+ */
494
+ static VALUE
495
+ static_SQLAnywhereInterface_sqlany_execute_immediate(VALUE api, VALUE sqlany_conn, VALUE sql)
496
+ {
497
+ SQLAnywhereInterface* s_api;
498
+ a_sqlany_connection* s_sqlany_conn;
499
+ char* s_sql;
500
+ sacapi_bool result;
501
+
502
+ s_sql = StringValueCStr( sql );
503
+
504
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
505
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
506
+
507
+ result = s_api->sqlany_execute_immediate(s_sqlany_conn, s_sql);
508
+
509
+ return( INT2NUM(result) );
510
+ }
511
+
512
+ /*
513
+ * call-seq:
514
+ * sqlany_execute_direct(VALUE api, VALUE sqlany_conn, VALUE sql) -> VALUE resultset
515
+ *
516
+ * Executes a SQL statement and possibly returns a result set.
517
+ *
518
+ * This function executes the SQL statement specified by the string argument.
519
+ * This function is suitable if you want to prepare and then execute a
520
+ * statement, and can be used instead of calling sqlany_prepare() followed
521
+ * by sqlany_execute().
522
+ *
523
+ * This function cannot be used for executing a SQL statement with
524
+ * parameters.
525
+ *
526
+ * <b>Parameters</b>:
527
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
528
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
529
+ * - <tt>VALUE sql</tt> -- A SQL query string.
530
+ *
531
+ * <b>Returns</b>:
532
+ * - <tt>VALUE result</tt>: A query result set if successful, nil if failed.
533
+ *
534
+ */
535
+ static VALUE
536
+ static_SQLAnywhereInterface_sqlany_execute_direct(VALUE api, VALUE sqlany_conn, VALUE sql)
537
+ {
538
+ SQLAnywhereInterface* s_api;
539
+ a_sqlany_connection* s_sqlany_conn;
540
+ a_sqlany_stmt* resultset = NULL;
541
+ char* s_sql;
542
+ VALUE tdata;
543
+
544
+ s_sql = StringValueCStr( sql );
545
+
546
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
547
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
548
+
549
+ resultset = s_api->sqlany_execute_direct(s_sqlany_conn, s_sql);
550
+
551
+ if (resultset)
552
+ {
553
+ tdata = Data_Wrap_Struct(cA_sqlany_stmt, 0, 0, resultset);
554
+ }
555
+ else
556
+ {
557
+ tdata = Qnil;
558
+ }
559
+
560
+ return (tdata);
561
+ }
562
+
563
+ /*
564
+ * call-seq:
565
+ * sqlany_num_cols(VALUE api, VALUE sqlany_stmt) -> VALUE num_cols
566
+ *
567
+ * Returns number of columns in the result set.
568
+ *
569
+ * <b>Parameters</b>:
570
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
571
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
572
+ *
573
+ * <b>Returns</b>:
574
+ * - <tt>VALUE num_cols</tt>: The number of columns in the result set or <tt>-1</tt> on a failure.
575
+ *
576
+ */
577
+ static VALUE
578
+ static_SQLAnywhereInterface_sqlany_num_cols(VALUE api, VALUE sqlany_stmt)
579
+ {
580
+ SQLAnywhereInterface* s_api;
581
+ a_sqlany_stmt* s_stmt;
582
+ sacapi_i32 result;
583
+
584
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
585
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
586
+
587
+ result = s_api->sqlany_num_cols(s_stmt);
588
+
589
+ return( INT2NUM(result) );
590
+ }
591
+
592
+ /*
593
+ * call-seq:
594
+ * sqlany_num_rows(VALUE api, VALUE sqlany_stmt) -> VALUE num_rows
595
+ *
596
+ * Returns number of rows in the result set.
597
+ *
598
+ * By default, this function only returns an estimate. To return an exact
599
+ * count, users must set the ROW_COUNTS option on the connection.
600
+ * Refer to SQL Anywhere documentation for the SQL syntax to set this option.
601
+ *
602
+ * <b>Parameters</b>:
603
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
604
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
605
+ *
606
+ * <b>Returns</b>:
607
+ * - <tt>VALUE num_rows</tt>: The number of rows in the result set or <tt>-1</tt> on a failure.
608
+ *
609
+ */
610
+ static VALUE
611
+ static_SQLAnywhereInterface_sqlany_num_rows(VALUE api, VALUE sqlany_stmt)
612
+ {
613
+ SQLAnywhereInterface* s_api;
614
+ a_sqlany_stmt* s_stmt;
615
+ sacapi_i32 result;
616
+
617
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
618
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
619
+
620
+ result = s_api->sqlany_num_rows(s_stmt);
621
+
622
+ return( INT2NUM(result) );
623
+ }
624
+
625
+ /*
626
+ * call-seq:
627
+ * sqlany_get_column(VALUE api, VALUE sqlany_stmt, VALUE col_num) -> [VALUE result, VALUE column_value]
628
+ *
629
+ * Retrieves the data fetched for the specified column.
630
+ *
631
+ * <b>Parameters</b>:
632
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
633
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
634
+ * - <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and sqlany_num_cols() - 1.
635
+ *
636
+ * <b>Returns</b>:
637
+ * - <tt>VALUE column_value</tt>: The value of the column. nil is returned if the value was NULL.
638
+ *
639
+ */
640
+ static VALUE
641
+ static_SQLAnywhereInterface_sqlany_get_column(VALUE api, VALUE sqlany_stmt, VALUE col_num)
642
+ {
643
+ SQLAnywhereInterface* s_api;
644
+ a_sqlany_stmt* s_stmt;
645
+ sacapi_u32 s_col_num;
646
+ a_sqlany_data_value value;
647
+ sacapi_bool result;
648
+ VALUE multi_result;
649
+
650
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
651
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
652
+ s_col_num = NUM2INT(col_num);
653
+
654
+ result = s_api->sqlany_get_column(s_stmt, s_col_num, &value );
655
+
656
+ multi_result = rb_ary_new();
657
+ rb_ary_push(multi_result, INT2NUM(result));
658
+
659
+ if( !result ) {
660
+ rb_ary_push(multi_result, Qnil);
661
+ }
662
+ else
663
+ {
664
+ if( *value.is_null )
665
+ {
666
+ rb_ary_push(multi_result, Qnil);
667
+ }
668
+ else
669
+ {
670
+ rb_ary_push(multi_result, C2RB(&value));
671
+ }
672
+ }
673
+
674
+ return( multi_result );
675
+ }
676
+
677
+ /*
678
+ * call-seq:
679
+ * sqlany_fetch_next(VALUE api, VALUE sqlany_stmt) -> VALUE result
680
+ *
681
+ * Fetches the next row from the result set.
682
+ *
683
+ * This function fetches the next row from the result set. When the result
684
+ * object is first created, the current row pointer is set to point before
685
+ * the first row (that is, row 0).
686
+ * This function advances the row pointer first and then fetches the data
687
+ * at the new row.
688
+ *
689
+ * <b>Parameters</b>:
690
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
691
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
692
+ *
693
+ * <b>Returns</b>:
694
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful fetch, <tt>0</tt> otherwise.
695
+ *
696
+ */
697
+ static VALUE
698
+ static_SQLAnywhereInterface_sqlany_fetch_next(VALUE api, VALUE sqlany_stmt)
699
+ {
700
+ SQLAnywhereInterface* s_api;
701
+ a_sqlany_stmt* s_stmt;
702
+ sacapi_bool result;
703
+
704
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
705
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
706
+
707
+ result = s_api->sqlany_fetch_next(s_stmt);
708
+
709
+ return( INT2NUM(result) );
710
+ }
711
+
712
+ /*
713
+ * call-seq:
714
+ * sqlany_get_column_info(VALUE api, VALUE sqlany_stmt, VALUE col_num) -> [VALUE result, VALUE col_num, VALUE name, VALUE type, VALUE max_size]
715
+ *
716
+ * Fetches the next row from the result set.
717
+ *
718
+ * This function fetches the next row from the result set. When the result
719
+ * object is first created, the current row pointer is set to point before
720
+ * the first row (that is, row 0).
721
+ * This function advances the row pointer first and then fetches the data
722
+ * at the new row.
723
+ *
724
+ * <b>Parameters</b>:
725
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
726
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
727
+ * - <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and sqlany_num_cols() - 1.
728
+ *
729
+ * <b>Returns</b>:
730
+ * - <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.
731
+ * - <tt>VALUE col_num</tt>: The number of the column retrieved.
732
+ * - <tt>VALUE name</tt>: The name of the column.
733
+ * - <tt>VALUE type</tt>: The type of the column data.
734
+ * - <tt>VALUE native_type</tt>: The SQL Anywhere native type of the column data.
735
+ * - <tt>VALUE precision</tt>: The precision of the column.
736
+ * - <tt>VALUE scale</tt>: The scale of the column.
737
+ * - <tt>VALUE max_size</tt>: The maximum size a data value in this column can take.
738
+ * - <tt>VALUE nullable</tt>: The nullability of the column.
739
+ *
740
+ */
741
+ static VALUE
742
+ static_SQLAnywhereInterface_sqlany_get_column_info(VALUE api, VALUE sqlany_stmt, VALUE col_num)
743
+ {
744
+ SQLAnywhereInterface* s_api;
745
+ a_sqlany_stmt* s_stmt;
746
+ sacapi_u32 s_col_num;
747
+ a_sqlany_column_info info;
748
+ sacapi_bool result;
749
+ VALUE multi_result;
750
+
751
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
752
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_stmt);
753
+ s_col_num = NUM2INT(col_num);
754
+
755
+ result = s_api->sqlany_get_column_info(s_stmt, s_col_num, &info );
756
+
757
+ multi_result = rb_ary_new();
758
+ rb_ary_push(multi_result, INT2NUM(result));
759
+ rb_ary_push(multi_result, col_num );
760
+ rb_ary_push(multi_result, rb_str_new2(info.name));
761
+ rb_ary_push(multi_result, INT2NUM(info.type));
762
+ rb_ary_push(multi_result, INT2NUM(info.native_type));
763
+ rb_ary_push(multi_result, INT2NUM(info.precision));
764
+ rb_ary_push(multi_result, INT2NUM(info.scale));
765
+ rb_ary_push(multi_result, INT2NUM(info.max_size));
766
+ rb_ary_push(multi_result, INT2NUM(info.nullable));
767
+
768
+ return( multi_result );
769
+ }
770
+
771
+ /*
772
+ * call-seq:
773
+ * sqlany_commit(VALUE api, VALUE sqlany_conn) -> VALUE result
774
+ *
775
+ * Commits the current transaction.
776
+ *
777
+ * <b>Parameters</b>:
778
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
779
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
780
+ *
781
+ * <b>Returns</b>:
782
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful commit, <tt>0</tt> otherwise.
783
+ *
784
+ */
785
+ static VALUE
786
+ static_SQLAnywhereInterface_sqlany_commit(VALUE api, VALUE sqlany_conn)
787
+ {
788
+ SQLAnywhereInterface* s_api;
789
+ a_sqlany_connection* s_sqlany_conn;
790
+ sacapi_bool result;
791
+
792
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
793
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
794
+
795
+ result = s_api->sqlany_commit(s_sqlany_conn);
796
+
797
+ return( INT2NUM(result) );
798
+ }
799
+
800
+
801
+ /*
802
+ * call-seq:
803
+ * sqlany_rollback(VALUE api, VALUE sqlany_conn) -> VALUE result
804
+ *
805
+ * Rolls back the current transaction.
806
+ *
807
+ * <b>Parameters</b>:
808
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
809
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
810
+ *
811
+ * <b>Returns</b>:
812
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful rollback, <tt>0</tt> otherwise.
813
+ *
814
+ */
815
+ static VALUE
816
+ static_SQLAnywhereInterface_sqlany_rollback(VALUE api, VALUE sqlany_conn)
817
+ {
818
+ SQLAnywhereInterface* s_api;
819
+ a_sqlany_connection* s_sqlany_conn;
820
+ sacapi_bool result;
821
+
822
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
823
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
824
+
825
+ result = s_api->sqlany_rollback(s_sqlany_conn);
826
+
827
+ return( INT2NUM(result) );
828
+ }
829
+
830
+ /*
831
+ * call-seq:
832
+ * sqlany_prepare(VALUE api, VALUE sqlany_conn, VALUE sql) -> VALUE stmt
833
+ *
834
+ * Prepares a SQL statement.
835
+ *
836
+ * This function prepares the supplied SQL string. Execution does not
837
+ * happen until sqlany_execute() is called. The returned statement object
838
+ * should be freed using sqlany_free_stmt().
839
+ *
840
+ *
841
+ * <b>Parameters</b>:
842
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
843
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
844
+ * - <tt>VALUE sql</tt> -- SQL query to prepare.
845
+ *
846
+ * <b>Returns</b>:
847
+ * - <tt>VALUE stmt</tt>: A statement object, or nil on failure. The statement object can be used by sqlany_execute() to execute the statement.
848
+ *
849
+ */
850
+ static VALUE
851
+ static_SQLAnywhereInterface_sqlany_prepare(VALUE api, VALUE sqlany_conn, VALUE sql)
852
+ {
853
+ SQLAnywhereInterface* s_api;
854
+ a_sqlany_connection* s_sqlany_conn;
855
+ a_sqlany_stmt* ptr = NULL;
856
+ char* s_sql;
857
+ int result;
858
+ VALUE tdata;
859
+
860
+ s_sql = StringValueCStr( sql );
861
+
862
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
863
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
864
+
865
+ ptr = s_api->sqlany_prepare(s_sqlany_conn, s_sql);
866
+
867
+ if (ptr)
868
+ {
869
+ tdata = Data_Wrap_Struct(cA_sqlany_stmt, 0, 0, ptr);
870
+ }
871
+ else
872
+ {
873
+ tdata = Qnil;
874
+ }
875
+
876
+ return (tdata);
877
+ }
878
+
879
+ /*
880
+ * call-seq:
881
+ * sqlany_free_stmt(VALUE api, VALUE sqlany_stmt) -> nil
882
+ *
883
+ * Frees resources associated with a prepared statement object.
884
+ *
885
+ * This function frees the resources associated with a prepared statement
886
+ * object.
887
+ *
888
+ * <b>Parameters</b>:
889
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
890
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
891
+ *
892
+ * <b>Returns</b>:
893
+ * - <tt>nil</tt>.
894
+ *
895
+ */
896
+ static VALUE
897
+ static_SQLAnywhereInterface_sqlany_free_stmt(VALUE api, VALUE sqlany_stmt)
898
+ {
899
+ SQLAnywhereInterface* s_api;
900
+ a_sqlany_stmt* s_sqlany_stmt;
901
+ int i;
902
+ int number_of_params = 0;
903
+ a_sqlany_bind_param_info bind_info;
904
+
905
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
906
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
907
+
908
+ number_of_params = s_api->sqlany_num_params(s_sqlany_stmt);
909
+
910
+ for (i = 0; i < number_of_params; i++)
911
+ {
912
+ if( s_api->sqlany_get_bind_param_info(s_sqlany_stmt, i, &bind_info) )
913
+ {
914
+ // We don't free bind_info.name as it's not allocated
915
+ // if (bind_info.name) {free (bind_info.name);}
916
+
917
+ if (bind_info.input_value.is_null) {free(bind_info.input_value.is_null); }
918
+ if (bind_info.input_value.length) {free(bind_info.input_value.length); }
919
+ if (bind_info.input_value.buffer) {free(bind_info.input_value.buffer); }
920
+
921
+ if (bind_info.output_value.is_null) {free(bind_info.output_value.is_null); }
922
+ if (bind_info.output_value.length) {free(bind_info.output_value.length); }
923
+ if (bind_info.output_value.buffer) {free(bind_info.output_value.buffer); }
924
+ }
925
+ }
926
+
927
+ s_api->sqlany_free_stmt(s_sqlany_stmt);
928
+
929
+ return ( Qnil );
930
+ }
931
+
932
+ /*
933
+ * call-seq:
934
+ * sqlany_execute(VALUE api, VALUE sqlany_stmt) -> VALUE result
935
+ *
936
+ * Executes a prepared statement.
937
+ *
938
+ * <b>Parameters</b>:
939
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
940
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
941
+ *
942
+ * <b>Returns</b>:
943
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.
944
+ *
945
+ */
946
+ static VALUE
947
+ static_SQLAnywhereInterface_sqlany_execute(VALUE api, VALUE sqlany_stmt)
948
+ {
949
+ SQLAnywhereInterface* s_api;
950
+ a_sqlany_stmt* s_sqlany_stmt;
951
+ sacapi_bool result;
952
+
953
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
954
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
955
+
956
+ result = s_api->sqlany_execute(s_sqlany_stmt);
957
+
958
+ return (INT2NUM(result));
959
+ }
960
+
961
+ /*
962
+ * call-seq:
963
+ * sqlany_affected_rows(VALUE api, VALUE sqlany_stmt) -> VALUE result
964
+ *
965
+ * Returns the number of rows affected by execution of the prepared
966
+ * statement.
967
+ *
968
+ * <b>Parameters</b>:
969
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
970
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement that was prepared and executed successfully with no result set returned.
971
+ *
972
+ * <b>Returns</b>:
973
+ * - <tt>VALUE result</tt>: The number of rows affected or <tt>-1</tt> on failure.
974
+ *
975
+ */
976
+ static VALUE
977
+ static_SQLAnywhereInterface_sqlany_affected_rows(VALUE api, VALUE sqlany_stmt)
978
+ {
979
+ SQLAnywhereInterface* s_api;
980
+ a_sqlany_stmt* s_sqlany_stmt;
981
+ sacapi_i32 result;
982
+
983
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
984
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
985
+
986
+ result = s_api->sqlany_affected_rows(s_sqlany_stmt);
987
+
988
+ return ( INT2NUM(result) );
989
+ }
990
+
991
+ /*
992
+ * call-seq:
993
+ * sqlany_describe_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index) -> [VALUE result, VALUE bind_param]
994
+ *
995
+ * Describes the bind parameters of a prepared statement.
996
+ *
997
+ * This function allows the caller to determine information about parameters
998
+ * to a prepared statement. Depending on the type of the prepared statement
999
+ * (call to stored procedure or a DML), only some information will be
1000
+ * provided. The information that will always be provided is the direction
1001
+ * of the parameters (input, output, or input-output).
1002
+ *
1003
+ * <b>Parameters</b>:
1004
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1005
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
1006
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params()- 1.
1007
+ *
1008
+ * <b>Returns</b>:
1009
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1010
+ * - <tt>VALUE bind_param</tt>: The described param object.
1011
+ *
1012
+ */
1013
+ static VALUE
1014
+ static_SQLAnywhereInterface_sqlany_describe_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index)
1015
+ {
1016
+ SQLAnywhereInterface* s_api;
1017
+ a_sqlany_stmt* s_sqlany_stmt;
1018
+ a_sqlany_bind_param* s_sqlany_bind_param;
1019
+ sacapi_bool result;
1020
+ sacapi_u32 s_index;
1021
+ VALUE tdata;
1022
+ VALUE multi_result;
1023
+
1024
+ s_sqlany_bind_param = malloc(sizeof(a_sqlany_bind_param));
1025
+ memset( s_sqlany_bind_param, 0, sizeof(a_sqlany_bind_param) );
1026
+
1027
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1028
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1029
+ s_index = NUM2INT(index);
1030
+
1031
+ result = s_api->sqlany_describe_bind_param(s_sqlany_stmt, s_index, s_sqlany_bind_param);
1032
+
1033
+ //FIXME handle failed result
1034
+
1035
+ multi_result = rb_ary_new();
1036
+
1037
+ rb_ary_push(multi_result, INT2NUM(result));
1038
+
1039
+ tdata = Data_Wrap_Struct(cA_sqlany_bind_param, 0, 0, s_sqlany_bind_param);
1040
+ rb_ary_push(multi_result, tdata);
1041
+
1042
+ return( multi_result );
1043
+ }
1044
+
1045
+ /*
1046
+ * call-seq:
1047
+ * sqlany_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index, VALUE sqlany_bind_param) -> VALUE result
1048
+ *
1049
+ * Binds a user supplied buffer as a parameter to the prepared statement.
1050
+ *
1051
+ * <b>Parameters</b>:
1052
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1053
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
1054
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
1055
+ * - <tt>VALUE sqlany_bind_param</tt> -- A filled bind object retrieved from sqlany_describe_bind_param().
1056
+ *
1057
+ * <b>Returns</b>:
1058
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1059
+ *
1060
+ */
1061
+ static VALUE
1062
+ static_SQLAnywhereInterface_sqlany_bind_param(VALUE api, VALUE sqlany_stmt, VALUE index, VALUE sqlany_bind_param )
1063
+ {
1064
+ SQLAnywhereInterface* s_api;
1065
+ a_sqlany_stmt* s_sqlany_stmt;
1066
+ a_sqlany_bind_param* s_sqlany_bind_param;
1067
+ sacapi_bool result;
1068
+ sacapi_u32 s_index;
1069
+
1070
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1071
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1072
+ Data_Get_Struct(sqlany_bind_param, a_sqlany_bind_param, s_sqlany_bind_param);
1073
+ s_index = NUM2INT(index);
1074
+
1075
+ result = s_api->sqlany_bind_param(s_sqlany_stmt, s_index, s_sqlany_bind_param);
1076
+
1077
+ return( INT2NUM(result) );
1078
+ }
1079
+
1080
+ /*
1081
+ * call-seq:
1082
+ * sqlany_get_bind_param_info(VALUE api, VALUE sqlany_stmt, VALUE index) -> [VALUE result, VALUE bind_param]
1083
+ *
1084
+ * Gets bound parameter info.
1085
+ *
1086
+ * This function retrieves information about the parameters that were
1087
+ * bound using sqlany_bind_param().
1088
+ *
1089
+ * <b>Parameters</b>:
1090
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1091
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
1092
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
1093
+ *
1094
+ * <b>Returns</b>:
1095
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1096
+ * - <tt>VALUE bind_param</tt>: The described param object.
1097
+ *
1098
+ */
1099
+ static VALUE
1100
+ static_SQLAnywhereInterface_sqlany_get_bind_param_info(VALUE api, VALUE sqlany_stmt, VALUE index)
1101
+ {
1102
+ SQLAnywhereInterface* s_api;
1103
+ a_sqlany_stmt* s_sqlany_stmt;
1104
+ a_sqlany_bind_param_info s_sqlany_bind_param_info;
1105
+ sacapi_bool result;
1106
+ sacapi_u32 s_index;
1107
+ VALUE tdata;
1108
+ VALUE multi_result;
1109
+
1110
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1111
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1112
+ s_index = NUM2INT(index);
1113
+
1114
+ result = s_api->sqlany_get_bind_param_info(s_sqlany_stmt, s_index, &s_sqlany_bind_param_info);
1115
+
1116
+ //FIXME handle failed result
1117
+ multi_result = rb_ary_new();
1118
+
1119
+ rb_ary_push(multi_result, INT2NUM(result));
1120
+
1121
+ // FIXME: Is this safe to be on the stack?
1122
+ tdata = Data_Wrap_Struct(cA_sqlany_bind_param_info, 0, 0, &s_sqlany_bind_param_info);
1123
+ rb_ary_push(multi_result, tdata);
1124
+
1125
+ return( multi_result );
1126
+ }
1127
+
1128
+ /*
1129
+ * call-seq:
1130
+ * sqlany_num_params(VALUE api, VALUE sqlany_stmt) -> VALUE result
1131
+ *
1132
+ * Returns the number of parameters that are expected for a prepared
1133
+ * statement.
1134
+ *
1135
+ * This function retrieves information about the parameters that were bound
1136
+ * using sqlany_bind_param().
1137
+ *
1138
+ * <b>Parameters</b>:
1139
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1140
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was returned from sqlany_prepare().
1141
+ *
1142
+ * <b>Returns</b>:
1143
+ * - <tt>VALUE result</tt>: The number of parameters that are expected. <tt>-1</tt> if the sqlany_stmt object is not valid.
1144
+ *
1145
+ */
1146
+ static VALUE
1147
+ static_SQLAnywhereInterface_sqlany_num_params(VALUE api, VALUE sqlany_stmt)
1148
+ {
1149
+ SQLAnywhereInterface* s_api;
1150
+ a_sqlany_stmt* s_sqlany_stmt;
1151
+ sacapi_i32 result;
1152
+
1153
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1154
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1155
+
1156
+ result = s_api->sqlany_num_params(s_sqlany_stmt);
1157
+
1158
+ return( INT2NUM(result) );
1159
+ }
1160
+
1161
+ /*
1162
+ * call-seq:
1163
+ * sqlany_get_next_result(VALUE api, VALUE sqlany_stmt) -> VALUE result
1164
+ *
1165
+ * Advances to the next result set in a multiple result set query.
1166
+ *
1167
+ * If a query (such as a call to a stored procedure) returns multiple result
1168
+ * sets, then this function advances from the current result set to the next.
1169
+ *
1170
+ *
1171
+ * <b>Parameters</b>:
1172
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1173
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was executed by sqlany_execute() or sqlany_execute_direct().
1174
+ *
1175
+ * <b>Returns</b>:
1176
+ * - <tt>VALUE result</tt>: <tt>1</tt> if was successfully able to advance to the next result set, <tt>0</tt> otherwise.
1177
+ *
1178
+ */
1179
+ static VALUE
1180
+ static_SQLAnywhereInterface_sqlany_get_next_result(VALUE api, VALUE sqlany_stmt)
1181
+ {
1182
+ SQLAnywhereInterface* s_api;
1183
+ a_sqlany_stmt* s_sqlany_stmt;
1184
+ sacapi_bool result;
1185
+
1186
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1187
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1188
+
1189
+ result = s_api->sqlany_get_next_result(s_sqlany_stmt);
1190
+
1191
+ return( INT2NUM(result) );
1192
+ }
1193
+
1194
+ /*
1195
+ * call-seq:
1196
+ * sqlany_fetch_absolute(VALUE api, VALUE sqlany_stmt, VALUE offset) -> VALUE result
1197
+ *
1198
+ * Fetches data at a specific row number in the result set.
1199
+ *
1200
+ * This function moves the current row in the result set to the row number
1201
+ * specified and fetches the data at that row.
1202
+ *
1203
+ * <b>Parameters</b>:
1204
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1205
+ * - <tt>VALUE sqlany_stmt</tt> -- A statement object that was executed by sqlany_execute() or sqlany_execute_direct().
1206
+ * - <tt>VALUE offset</tt> -- The row number to be fetched. The first row is <tt>1</tt>, the last row is <tt>-1</tt>.
1207
+ *
1208
+ * <b>Returns</b>:
1209
+ * - <tt>VALUE result</tt>: <tt>1</tt> if the fetch was successfully, <tt>0</tt> otherwise.
1210
+ *
1211
+ */
1212
+ static VALUE
1213
+ static_SQLAnywhereInterface_sqlany_fetch_absolute(VALUE api, VALUE sqlany_stmt, VALUE offset)
1214
+ {
1215
+ SQLAnywhereInterface* s_api;
1216
+ a_sqlany_stmt* s_sqlany_stmt;
1217
+ sacapi_i32 s_offset;
1218
+ sacapi_bool result;
1219
+
1220
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1221
+ Data_Get_Struct(sqlany_stmt, a_sqlany_stmt, s_sqlany_stmt);
1222
+ s_offset = NUM2INT(offset);
1223
+ result = s_api->sqlany_fetch_absolute(s_sqlany_stmt, s_offset);
1224
+
1225
+ return( INT2NUM(result) );
1226
+ }
1227
+
1228
+ /*
1229
+ * call-seq:
1230
+ * sqlany_sqlstate(VALUE api, VALUE sqlany_conn) -> VALUE sqlstate_str
1231
+ *
1232
+ * Retrieves the current SQL state.
1233
+ *
1234
+ * <b>Parameters</b>:
1235
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1236
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
1237
+ *
1238
+ * <b>Returns</b>:
1239
+ * - <tt>VALUE sqlstate_str</tt>: The SQL State.
1240
+ *
1241
+ */
1242
+ static VALUE
1243
+ static_SQLAnywhereInterface_sqlany_sqlstate(VALUE api, VALUE sqlany_conn)
1244
+ {
1245
+ SQLAnywhereInterface* s_api;
1246
+ a_sqlany_connection* s_sqlany_conn;
1247
+ size_t s_size;
1248
+ char s_buffer[255];
1249
+
1250
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1251
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
1252
+
1253
+ s_size = s_api->sqlany_sqlstate(s_sqlany_conn, s_buffer, sizeof(s_buffer));
1254
+
1255
+ return( rb_str_new(s_buffer, s_size));
1256
+ }
1257
+
1258
+ /*
1259
+ * call-seq:
1260
+ * sqlany_clear_error(VALUE api, VALUE sqlany_conn) -> nil
1261
+ *
1262
+ * Clears the last stored error code.
1263
+ *
1264
+ * <b>Parameters</b>:
1265
+ * - <tt>VALUE api</tt> -- An initialized API structure to finalize.
1266
+ * - <tt>VALUE sqlany_conn</tt> -- A connection object that was connected by sqlany_connect().
1267
+ *
1268
+ * <b>Returns</b>:
1269
+ * - <tt>nil</tt>:.
1270
+ *
1271
+ */
1272
+ static VALUE
1273
+ static_SQLAnywhereInterface_sqlany_clear_error(VALUE api, VALUE sqlany_conn)
1274
+ {
1275
+ SQLAnywhereInterface* s_api;
1276
+ a_sqlany_connection* s_sqlany_conn;
1277
+
1278
+ Data_Get_Struct(api, SQLAnywhereInterface, s_api);
1279
+ Data_Get_Struct(sqlany_conn, a_sqlany_connection, s_sqlany_conn);
1280
+
1281
+ s_api->sqlany_clear_error(s_sqlany_conn);
1282
+
1283
+ return( Qnil );
1284
+ }
1285
+
1286
+ /*
1287
+ * call-seq:
1288
+ * get_name(VALUE bind) -> VALUE name
1289
+ *
1290
+ * Gets the name of the bound parameter.
1291
+ *
1292
+ * <b>Parameters</b>:
1293
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1294
+ *
1295
+ * <b>Returns</b>:
1296
+ * - <tt>VALUE name</tt>: The bound variable's name.
1297
+ *
1298
+ */
1299
+ static VALUE
1300
+ static_Bind_get_name(VALUE bind)
1301
+ {
1302
+ a_sqlany_bind_param* s_bind;
1303
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1304
+ return (rb_str_new2(s_bind->name));
1305
+ }
1306
+
1307
+ /*
1308
+ * call-seq:
1309
+ * set_value(VALUE bind, VALUE val) -> nil
1310
+ *
1311
+ * Sets the value of a bind parameter.
1312
+ *
1313
+ * This function is used to bind a Ruby VALUE to a given parameter in a
1314
+ * prepared statement. If the bind_direction is INPUT only, the type INPUT
1315
+ * will be bound based on the RUBY type:
1316
+ *
1317
+ * +-------------+------------+
1318
+ * | Ruby Type | Bind Type |
1319
+ * +-------------+------------+
1320
+ * | T_STRING => A_STRING |
1321
+ * | T_FIXNUM => A_VAL_32 |
1322
+ * | T_BIGNUM => A_DOUBLE |
1323
+ * | T_FLOAT => A_DOUBLE |
1324
+ * | T_STRING => A_STRING |
1325
+ * | T_NIL => isnull = 1 |
1326
+ * +--------------------------+
1327
+ *
1328
+ * If the bind direction is OUTPUT, instead use the DBCAPI type to set the
1329
+ * size of the buffer.
1330
+ *
1331
+ * In the case of INOUT parameters, it is the application's job to call this
1332
+ * method twice, once to bind the INPUT, and once to bind the OUTPUT.
1333
+ *
1334
+ * <b>Parameters</b>:
1335
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1336
+ * - <tt>VALUE val</tt> -- The value to bind into the bound variable.
1337
+ *
1338
+ * <b>Returns</b>:
1339
+ * - <tt>nil</tt>.
1340
+ */
1341
+ static VALUE
1342
+ static_Bind_set_value(VALUE bind, VALUE val)
1343
+ {
1344
+ a_sqlany_bind_param* s_bind;
1345
+ int length;
1346
+
1347
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1348
+
1349
+ // FIXME: use Ruby's allocation routines?
1350
+ s_bind->value.is_null = malloc(sizeof(sacapi_bool));
1351
+ *s_bind->value.is_null = 0;
1352
+
1353
+ if (s_bind->direction == DD_INPUT)
1354
+ {
1355
+ switch(TYPE(val))
1356
+ {
1357
+ case T_STRING:
1358
+ s_bind->value.length = malloc(sizeof(size_t));
1359
+ length = RSTRING(val)->len;
1360
+ *s_bind->value.length = length;
1361
+ s_bind->value.buffer = malloc(length);
1362
+ memcpy(s_bind->value.buffer, RSTRING(val)->ptr, length);
1363
+ s_bind->value.type = A_STRING;
1364
+ break;
1365
+ case T_FIXNUM:
1366
+ s_bind->value.buffer = malloc(sizeof(int));
1367
+ *((int*)s_bind->value.buffer) = FIX2INT(val);
1368
+ s_bind->value.type = A_VAL32;
1369
+ break;
1370
+ case T_BIGNUM:
1371
+ s_bind->value.buffer = malloc(sizeof(LONG_LONG));
1372
+ *((LONG_LONG*)s_bind->value.buffer) = rb_num2ll(val);
1373
+ s_bind->value.type = A_VAL64;
1374
+ break;
1375
+ case T_FLOAT:
1376
+ s_bind->value.buffer = malloc(sizeof(double));
1377
+ *((double*)s_bind->value.buffer) = NUM2DBL(val);
1378
+ s_bind->value.type = A_DOUBLE;
1379
+ break;
1380
+ case T_NIL:
1381
+ *s_bind->value.is_null = 1;
1382
+ s_bind->value.buffer = malloc(sizeof(int));
1383
+ s_bind->value.type = A_VAL32;
1384
+ break;
1385
+ default:
1386
+ rb_raise(rb_eTypeError, "Cannot convert type. Must be STRING, FIXNUM, BIGNUM, FLOAT, or NIL");
1387
+ break;
1388
+ }
1389
+ }
1390
+ else
1391
+ {
1392
+ switch (s_bind->value.type)
1393
+ {
1394
+ case A_STRING:
1395
+ s_bind->value.buffer = malloc(s_bind->value.buffer_size);
1396
+ break;
1397
+ case A_DOUBLE:
1398
+ s_bind->value.buffer = malloc(sizeof(float));
1399
+ break;
1400
+ case A_VAL64:
1401
+ case A_UVAL64:
1402
+ s_bind->value.buffer = malloc(sizeof(LONG_LONG));
1403
+ break;
1404
+ case A_VAL32:
1405
+ case A_UVAL32:
1406
+ s_bind->value.buffer = malloc(sizeof(int));
1407
+ break;
1408
+ case A_VAL16:
1409
+ case A_UVAL16:
1410
+ s_bind->value.buffer = malloc(sizeof(short));
1411
+ break;
1412
+ case A_VAL8:
1413
+ case A_UVAL8:
1414
+ s_bind->value.buffer = malloc(sizeof(char));
1415
+ break;
1416
+ default:
1417
+ rb_raise(rb_eTypeError, "Type unknown");
1418
+ break;
1419
+ }
1420
+ }
1421
+ return (Qnil);
1422
+ }
1423
+
1424
+ /*
1425
+ * call-seq:
1426
+ * set_direction(VALUE bind, VALUE direction) -> nil
1427
+ *
1428
+ * Sets the direction of the bound parameter before binding.
1429
+ *
1430
+ * <b>Parameters</b>:
1431
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1432
+ * - <tt>VALUE direction</tt> -- The direction of the binding variable.
1433
+ *
1434
+ * <b>Returns</b>:
1435
+ * - <tt>nil</tt>.
1436
+ *
1437
+ */
1438
+ static VALUE
1439
+ static_Bind_set_direction(VALUE bind, VALUE direction)
1440
+ {
1441
+ a_sqlany_bind_param* s_bind;
1442
+
1443
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1444
+
1445
+ s_bind->direction = NUM2CHR(direction);
1446
+
1447
+ return (Qnil);
1448
+ }
1449
+
1450
+ /*
1451
+ * call-seq:
1452
+ * set_buffer_size(VALUE bind, VALUE size) -> nil
1453
+ *
1454
+ * Sets the buffer size of INOUT and OUT parameters for string and binary
1455
+ * data.
1456
+ *
1457
+ * <b>Parameters</b>:
1458
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1459
+ * - <tt>VALUE size</tt> -- The size of the buffer to hold the INOUT or OUT parameter.
1460
+ *
1461
+ * <b>Returns</b>:
1462
+ * - <tt>nil</tt>.
1463
+ *
1464
+ */
1465
+ static VALUE
1466
+ static_Bind_set_buffer_size(VALUE bind, VALUE size)
1467
+ {
1468
+ a_sqlany_bind_param* s_bind;
1469
+
1470
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1471
+
1472
+ s_bind->value.buffer_size = NUM2INT(size);
1473
+
1474
+ return (Qnil);
1475
+ }
1476
+
1477
+ /*
1478
+ * call-seq:
1479
+ * get_direction(VALUE bind) -> VALUE direction
1480
+ *
1481
+ * Gets the direction of the bound parameter.
1482
+ *
1483
+ * <b>Parameters</b>:
1484
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1485
+ *
1486
+ * <b>Returns</b>:
1487
+ * - <tt>VALUE name</tt>: The direction of the bound parameter.
1488
+ *
1489
+ */
1490
+ static VALUE
1491
+ static_Bind_get_direction(VALUE bind)
1492
+ {
1493
+ a_sqlany_bind_param* s_bind;
1494
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1495
+
1496
+ return (CHR2FIX(s_bind->direction));
1497
+ }
1498
+
1499
+ /*
1500
+ * call-seq:
1501
+ * finish(VALUE bind) -> nil
1502
+ *
1503
+ * Frees the resources associated with the bound parameter.
1504
+ *
1505
+ * <b>Parameters</b>:
1506
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1507
+ *
1508
+ * <b>Returns</b>:
1509
+ * - <tt>nil</tt>.
1510
+ *
1511
+ */
1512
+ static VALUE
1513
+ static_Bind_finish(VALUE bind)
1514
+ {
1515
+ a_sqlany_bind_param* s_bind;
1516
+
1517
+ Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
1518
+
1519
+ // FIXME: use Ruby's allocation routines?
1520
+ if (s_bind) { free(s_bind);};
1521
+
1522
+ return (Qnil);
1523
+ }
1524
+
1525
+ /*
1526
+ * call-seq:
1527
+ * get_info_direction(VALUE bind) -> VALUE direction
1528
+ *
1529
+ * Gets the name of the bound parameter info object.
1530
+ *
1531
+ * <b>Parameters</b>:
1532
+ * - <tt>VALUE bind</tt> -- Bound parameter info retrieved from sqlany_describe_bind_param_info().
1533
+ *
1534
+ * <b>Returns</b>:
1535
+ * - <tt>VALUE direction</tt>: The bound variable's direction.
1536
+ *
1537
+ */
1538
+ static VALUE
1539
+ static_Bind_get_info_direction(VALUE bind)
1540
+ {
1541
+ a_sqlany_bind_param_info* s_bind;
1542
+ Data_Get_Struct(bind, a_sqlany_bind_param_info, s_bind);
1543
+
1544
+ return (CHR2FIX(s_bind->direction));
1545
+ }
1546
+
1547
+ /*
1548
+ * call-seq:
1549
+ * get_info_output(VALUE bind) -> VALUE name
1550
+ *
1551
+ * Gets the value of a bound parameter after execution.
1552
+ *
1553
+ * <b>Parameters</b>:
1554
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
1555
+ *
1556
+ * <b>Returns</b>:
1557
+ * - <tt>VALUE name</tt>: The bound variable value.
1558
+ *
1559
+ */
1560
+ static VALUE
1561
+ static_Bind_get_info_output(VALUE bind)
1562
+ {
1563
+ a_sqlany_bind_param_info* s_bind;
1564
+ Data_Get_Struct(bind, a_sqlany_bind_param_info, s_bind);
1565
+
1566
+ if( *s_bind->output_value.is_null ) {
1567
+ return( Qnil );
1568
+ }
1569
+ else
1570
+ {
1571
+ return(C2RB(&s_bind->output_value));
1572
+ }
1573
+ }
1574
+
1575
+ /*
1576
+ *
1577
+ */
1578
+ void Init_sqlanywhere()
1579
+ {
1580
+ // Define top leve 'SQLAnywhere' module
1581
+ mSQLAnywhere = rb_define_module( "SQLAnywhere" );
1582
+
1583
+ // Define a sub-module name 'API' under SQLAnywhere.
1584
+ // In Ruby, this is accessed as SQLAnywhere::API
1585
+ mAPI = rb_define_module_under( mSQLAnywhere, "API" );
1586
+
1587
+ // Define sqlany interface functions
1588
+ rb_define_module_function( mAPI, "sqlany_initialize_interface", static_API_sqlany_initialize_interface, 1 );
1589
+ rb_define_module_function( mAPI, "sqlany_finalize_interface", static_API_sqlany_finalize_interface, 1 );
1590
+ rb_define_const(mAPI, "VERSION", rb_str_new2(VERSION));
1591
+
1592
+
1593
+ // Define interface classes under the SQLAnywhere module
1594
+ cSQLAnywhereInterface = rb_define_class_under( mSQLAnywhere, "SQLAnywhereInterface", rb_cObject);
1595
+ rb_define_alloc_func(cSQLAnywhereInterface, static_SQLAnywhereInterface_alloc);
1596
+
1597
+ // Define all of the DBCAPI functions as methods under an interface instance
1598
+ rb_define_method(cSQLAnywhereInterface, "sqlany_init", static_SQLAnywhereInterface_sqlany_init, 0);
1599
+ rb_define_method(cSQLAnywhereInterface, "sqlany_new_connection", static_SQLAnywhereInterface_sqlany_new_connection, 0);
1600
+ rb_define_method(cSQLAnywhereInterface, "sqlany_connect", static_SQLAnywhereInterface_sqlany_connect, 2);
1601
+ rb_define_method(cSQLAnywhereInterface, "sqlany_disconnect", static_SQLAnywhereInterface_sqlany_disconnect, 1);
1602
+ rb_define_method(cSQLAnywhereInterface, "sqlany_free_connection", static_SQLAnywhereInterface_sqlany_free_connection, 1);
1603
+ rb_define_method(cSQLAnywhereInterface, "sqlany_fini", static_SQLAnywhereInterface_sqlany_fini, 0);
1604
+ rb_define_method(cSQLAnywhereInterface, "sqlany_error", static_SQLAnywhereInterface_sqlany_error, 1);
1605
+ rb_define_method(cSQLAnywhereInterface, "sqlany_execute_immediate", static_SQLAnywhereInterface_sqlany_execute_immediate, 2);
1606
+ rb_define_method(cSQLAnywhereInterface, "sqlany_execute_direct", static_SQLAnywhereInterface_sqlany_execute_direct, 2);
1607
+ rb_define_method(cSQLAnywhereInterface, "sqlany_num_cols", static_SQLAnywhereInterface_sqlany_num_cols, 1);
1608
+ rb_define_method(cSQLAnywhereInterface, "sqlany_num_rows", static_SQLAnywhereInterface_sqlany_num_rows, 1);
1609
+ rb_define_method(cSQLAnywhereInterface, "sqlany_get_column", static_SQLAnywhereInterface_sqlany_get_column, 2);
1610
+ rb_define_method(cSQLAnywhereInterface, "sqlany_fetch_next", static_SQLAnywhereInterface_sqlany_fetch_next, 1);
1611
+ rb_define_method(cSQLAnywhereInterface, "sqlany_get_column_info", static_SQLAnywhereInterface_sqlany_get_column_info, 2);
1612
+ rb_define_method(cSQLAnywhereInterface, "sqlany_commit", static_SQLAnywhereInterface_sqlany_commit, 1);
1613
+ rb_define_method(cSQLAnywhereInterface, "sqlany_rollback", static_SQLAnywhereInterface_sqlany_rollback, 1);
1614
+ rb_define_method(cSQLAnywhereInterface, "sqlany_prepare", static_SQLAnywhereInterface_sqlany_prepare, 2);
1615
+ rb_define_method(cSQLAnywhereInterface, "sqlany_free_stmt", static_SQLAnywhereInterface_sqlany_free_stmt, 1);
1616
+ rb_define_method(cSQLAnywhereInterface, "sqlany_execute", static_SQLAnywhereInterface_sqlany_execute, 1);
1617
+ rb_define_method(cSQLAnywhereInterface, "sqlany_affected_rows", static_SQLAnywhereInterface_sqlany_affected_rows, 1);
1618
+ rb_define_method(cSQLAnywhereInterface, "sqlany_describe_bind_param", static_SQLAnywhereInterface_sqlany_describe_bind_param, 2);
1619
+ rb_define_method(cSQLAnywhereInterface, "sqlany_bind_param", static_SQLAnywhereInterface_sqlany_bind_param, 3);
1620
+ rb_define_method(cSQLAnywhereInterface, "sqlany_get_bind_param_info", static_SQLAnywhereInterface_sqlany_get_bind_param_info, 2);
1621
+ rb_define_method(cSQLAnywhereInterface, "sqlany_num_params", static_SQLAnywhereInterface_sqlany_num_params, 1);
1622
+ rb_define_method(cSQLAnywhereInterface, "sqlany_get_next_result", static_SQLAnywhereInterface_sqlany_get_next_result, 1);
1623
+ rb_define_method(cSQLAnywhereInterface, "sqlany_fetch_absolute", static_SQLAnywhereInterface_sqlany_fetch_absolute, 2);
1624
+ rb_define_method(cSQLAnywhereInterface, "sqlany_sqlstate", static_SQLAnywhereInterface_sqlany_sqlstate, 1);
1625
+ rb_define_method(cSQLAnywhereInterface, "sqlany_clear_error", static_SQLAnywhereInterface_sqlany_clear_error, 1);
1626
+
1627
+ // Define classes for accessing structures under SQLAnywhere module
1628
+ cA_sqlany_connection = rb_define_class_under (mSQLAnywhere, "a_sqlany_connection", rb_cObject);
1629
+ cA_sqlany_data_value = rb_define_class_under (mSQLAnywhere, "a_sqlany_data_value", rb_cObject);
1630
+ cA_sqlany_stmt = rb_define_class_under (mSQLAnywhere, "a_sqlany_stmt", rb_cObject);
1631
+ cA_sqlany_bind_param = rb_define_class_under (mSQLAnywhere, "a_sqlany_bind_param", rb_cObject);
1632
+ cA_sqlany_bind_param_info = rb_define_class_under (mSQLAnywhere, "a_sqlany_bind_param_info", rb_cObject);
1633
+
1634
+
1635
+ // Define methods for obtaining bind_parameter fields
1636
+ rb_define_method(cA_sqlany_bind_param, "get_name", static_Bind_get_name, 0);
1637
+ rb_define_method(cA_sqlany_bind_param, "set_value", static_Bind_set_value, 1);
1638
+ rb_define_method(cA_sqlany_bind_param, "get_direction", static_Bind_get_direction, 0);
1639
+ rb_define_method(cA_sqlany_bind_param, "set_direction", static_Bind_set_direction, 1);
1640
+ rb_define_method(cA_sqlany_bind_param, "set_buffer_size", static_Bind_set_buffer_size, 1);
1641
+ rb_define_method(cA_sqlany_bind_param, "finish", static_Bind_finish, 0);
1642
+
1643
+ // Define methods for obtaining bind_parameter_info fields
1644
+ rb_define_method(cA_sqlany_bind_param_info, "get_direction", static_Bind_get_info_direction, 0);
1645
+ rb_define_method(cA_sqlany_bind_param_info, "get_output", static_Bind_get_info_output, 0);
1646
+ }
1647
+
1648
+