sqlanywhere 0.1.3-i386-mswin32 → 0.1.4-i386-mswin32

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