advantage 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,164 @@
1
+ /* ====================================================
2
+ *
3
+ * Copyright 2008-2012 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
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * ====================================================
19
+ */
20
+
21
+ #include <string.h>
22
+ #include <stdlib.h>
23
+ #include <stdio.h>
24
+
25
+ #if defined(_WIN32)
26
+ #include <windows.h>
27
+ #ifdef x64
28
+ #define DEFAULT_LIBRARY_NAME "ace64.dll"
29
+ #else
30
+ #define DEFAULT_LIBRARY_NAME "ace32.dll"
31
+ #endif
32
+ #else
33
+ #include <dlfcn.h>
34
+ #define DEFAULT_LIBRARY_NAME "libace.so"
35
+ #endif
36
+ #include "ace.h"
37
+ #include "adscapidll.h"
38
+
39
+ static void *loadLibrary(const char *name)
40
+ /*************************************/
41
+ {
42
+ void *handle;
43
+ #if defined(_WIN32)
44
+ handle = LoadLibrary(name);
45
+ #else
46
+ handle = dlopen(name, RTLD_LAZY);
47
+ #endif
48
+ return handle;
49
+ }
50
+
51
+ static void unloadLibrary(void *handle)
52
+ /**********************************/
53
+ {
54
+ #if defined(_WIN32)
55
+ FreeLibrary(handle);
56
+ #else
57
+ dlclose(handle);
58
+ #endif
59
+ }
60
+
61
+ static void *findSymbol(void *dll_handle, const char *name)
62
+ /**************************************************/
63
+ {
64
+ #if defined(_WIN32)
65
+ return GetProcAddress(dll_handle, name);
66
+ #else
67
+ return dlsym(dll_handle, name);
68
+ #endif
69
+ }
70
+
71
+ #define LookupSymbol(api, sym) \
72
+ api->sym = (sym##_func)findSymbol(api->dll_handle, #sym);
73
+
74
+ #define LookupSymbolAndCheck(api, sym) \
75
+ api->sym = (sym##_func)findSymbol(api->dll_handle, #sym); \
76
+ if (api->sym == NULL) \
77
+ { \
78
+ unloadLibrary(api->dll_handle); \
79
+ return 0; \
80
+ }
81
+
82
+ int ads_initialize_interface(AdvantageInterface *api, const char *path)
83
+ /*******************************************************************************/
84
+ {
85
+ char *env;
86
+ memset(api, 0, sizeof(*api));
87
+
88
+ if (path != NULL)
89
+ {
90
+ api->dll_handle = loadLibrary(path);
91
+ if (api->dll_handle != NULL)
92
+ {
93
+ goto loaded;
94
+ }
95
+ }
96
+ env = getenv("ADS_API_DLL");
97
+ if (env != NULL)
98
+ {
99
+ api->dll_handle = loadLibrary(env);
100
+ if (api->dll_handle != NULL)
101
+ {
102
+ goto loaded;
103
+ }
104
+ }
105
+ api->dll_handle = loadLibrary(DEFAULT_LIBRARY_NAME);
106
+ if (api->dll_handle != NULL)
107
+ {
108
+ goto loaded;
109
+ }
110
+ return 0;
111
+
112
+ loaded:
113
+ LookupSymbolAndCheck(api, ads_init);
114
+ LookupSymbolAndCheck(api, ads_fini);
115
+ LookupSymbolAndCheck(api, ads_new_connection);
116
+ LookupSymbolAndCheck(api, ads_free_connection);
117
+ LookupSymbolAndCheck(api, ads_make_connection);
118
+ LookupSymbolAndCheck(api, ads_connect);
119
+ LookupSymbolAndCheck(api, ads_disconnect);
120
+ LookupSymbolAndCheck(api, ads_execute_immediate);
121
+ LookupSymbolAndCheck(api, ads_prepare);
122
+ LookupSymbolAndCheck(api, ads_free_stmt);
123
+ LookupSymbolAndCheck(api, ads_num_params);
124
+ LookupSymbolAndCheck(api, ads_describe_bind_param);
125
+ LookupSymbolAndCheck(api, ads_bind_param);
126
+ LookupSymbolAndCheck(api, ads_send_param_data);
127
+ LookupSymbolAndCheck(api, ads_reset);
128
+ LookupSymbolAndCheck(api, ads_get_bind_param_info);
129
+ LookupSymbolAndCheck(api, ads_execute);
130
+ LookupSymbolAndCheck(api, ads_execute_direct);
131
+ LookupSymbolAndCheck(api, ads_fetch_absolute);
132
+ LookupSymbolAndCheck(api, ads_fetch_next);
133
+ LookupSymbolAndCheck(api, ads_get_next_result);
134
+ LookupSymbolAndCheck(api, ads_affected_rows);
135
+ LookupSymbolAndCheck(api, ads_num_cols);
136
+ LookupSymbolAndCheck(api, ads_num_rows);
137
+ LookupSymbolAndCheck(api, ads_get_column);
138
+ LookupSymbolAndCheck(api, ads_get_data);
139
+ LookupSymbolAndCheck(api, ads_get_data_info);
140
+ LookupSymbolAndCheck(api, ads_get_column_info);
141
+ LookupSymbolAndCheck(api, ads_commit);
142
+ LookupSymbolAndCheck(api, ads_rollback);
143
+ LookupSymbolAndCheck(api, ads_client_version);
144
+ LookupSymbolAndCheck(api, ads_error);
145
+ LookupSymbolAndCheck(api, ads_sqlstate);
146
+ LookupSymbolAndCheck(api, ads_clear_error);
147
+ LookupSymbolAndCheck(api, ads_cancel);
148
+ LookupSymbolAndCheck(api, AdsBeginTransaction);
149
+
150
+ api->initialized = 1;
151
+ return 1;
152
+ }
153
+ #undef LookupSymbolAndCheck
154
+
155
+ void ads_finalize_interface(AdvantageInterface *api)
156
+ /***********************************************************/
157
+ {
158
+ if (!api->initialized)
159
+ {
160
+ return;
161
+ }
162
+ unloadLibrary(api->dll_handle);
163
+ memset(api, 0, sizeof(*api));
164
+ }
@@ -0,0 +1,245 @@
1
+ /* ====================================================
2
+ *
3
+ * Copyright 2008-2012 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
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * ====================================================
19
+ */
20
+
21
+ #ifndef ADSCAPIDLL_H
22
+ #define ADSCAPIDLL_H
23
+
24
+ #include "ace.h"
25
+ #include "dbcapi.h"
26
+
27
+ #if defined(__cplusplus)
28
+ extern "C"
29
+ {
30
+ #endif
31
+ typedef UNSIGNED32(WINAPI *ads_affected_rows_func)(ADSHANDLE hStatement);
32
+ typedef UNSIGNED32(WINAPI *AdsBeginTransaction_func)(ADSHANDLE hConnect);
33
+ typedef UNSIGNED32(WINAPI *ads_bind_param_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, a_ads_bind_param *param);
34
+ typedef void(WINAPI *ads_cancel_func)(a_ads_connection *poConnect);
35
+ typedef void(WINAPI *ads_clear_error_func)(a_ads_connection *poConnect);
36
+ typedef UNSIGNED32(WINAPI *ads_client_version_func)(UNSIGNED8 *pucBuffer, UNSIGNED32 ulLength);
37
+ typedef UNSIGNED32(WINAPI *ads_commit_func)(a_ads_connection *poConnect);
38
+ typedef UNSIGNED32(WINAPI *ads_connect_func)(a_ads_connection *poConnect, UNSIGNED8 *pucConnectString);
39
+ typedef UNSIGNED32(WINAPI *ads_describe_bind_param_func)(ADSHANDLE ads_stmt, UNSIGNED32 index, a_ads_bind_param *params);
40
+ typedef UNSIGNED32(WINAPI *ads_disconnect_func)(a_ads_connection *poConnect);
41
+ typedef UNSIGNED32(WINAPI *ads_error_func)(a_ads_connection *poConnect, UNSIGNED8 *pucError, UNSIGNED32 ulLength);
42
+ typedef UNSIGNED32(WINAPI *ads_execute_func)(ADSHANDLE hStatement);
43
+ typedef ADSHANDLE(WINAPI *ads_execute_direct_func)(a_ads_connection *poConnect, UNSIGNED8 *pucSQL);
44
+ typedef UNSIGNED32(WINAPI *ads_execute_immediate_func)(a_ads_connection *poConnect, UNSIGNED8 *pucSQL);
45
+ typedef UNSIGNED32(WINAPI *ads_fetch_absolute_func)(ADSHANDLE hStatement, UNSIGNED32 ulRowNum);
46
+ typedef UNSIGNED32(WINAPI *ads_fetch_next_func)(ADSHANDLE hStatement);
47
+ typedef UNSIGNED32(WINAPI *ads_fini_func)();
48
+ typedef UNSIGNED32(WINAPI *ads_free_connection_func)(a_ads_connection *poConnect);
49
+ typedef UNSIGNED32(WINAPI *ads_free_stmt_func)(ADSHANDLE hStatement);
50
+ typedef UNSIGNED32(WINAPI *ads_get_bind_param_info_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, a_ads_bind_param_info *info);
51
+ typedef UNSIGNED32(WINAPI *ads_get_column_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, a_ads_data_value *buffer);
52
+ typedef UNSIGNED32(WINAPI *ads_get_column_info_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, a_ads_column_info *buffer);
53
+ typedef UNSIGNED32(WINAPI *ads_get_data_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, UNSIGNED32 ulOffset, void *buffer, UNSIGNED32 ulLength);
54
+ typedef UNSIGNED32(WINAPI *ads_get_data_info_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, a_ads_data_info *buffer);
55
+ typedef UNSIGNED32(WINAPI *ads_get_next_result_func)(ADSHANDLE hStatement);
56
+ typedef UNSIGNED32(WINAPI *ads_init_func)(UNSIGNED8 *app_name, UNSIGNED32 api_version, UNSIGNED32 *max_version);
57
+ typedef a_ads_connection_ptr(WINAPI *ads_make_connection_func)(void *arg);
58
+ typedef a_ads_connection_ptr(WINAPI *ads_new_connection_func)();
59
+ typedef UNSIGNED32(WINAPI *ads_num_cols_func)(ADSHANDLE hStatement);
60
+ typedef UNSIGNED32(WINAPI *ads_num_params_func)(ADSHANDLE hStatement);
61
+ typedef UNSIGNED32(WINAPI *ads_num_rows_func)(ADSHANDLE hStatement);
62
+ typedef ADSHANDLE(WINAPI *ads_prepare_func)(a_ads_connection *poConnect, UNSIGNED8 *pucSQL, UNSIGNED8 ucIsUnicode);
63
+ typedef UNSIGNED32(WINAPI *ads_reset_func)(ADSHANDLE hStatement);
64
+ typedef UNSIGNED32(WINAPI *ads_rollback_func)(a_ads_connection *poConnect);
65
+ typedef UNSIGNED32(WINAPI *ads_send_param_data_func)(ADSHANDLE hStatement, UNSIGNED32 ulIndex, UNSIGNED8 *pucBuffer, UNSIGNED32 ulLength);
66
+ typedef UNSIGNED32(WINAPI *ads_sqlstate_func)(a_ads_connection *poConnect, UNSIGNED8 *pucBuffer, UNSIGNED32 ulLength);
67
+
68
+ #if defined(__cplusplus)
69
+ }
70
+ #endif
71
+
72
+ /// @internal
73
+ #define function(x) x##_func x
74
+
75
+ typedef struct AdvantageInterface
76
+ {
77
+ /** DLL handle.
78
+ */
79
+ void *dll_handle;
80
+
81
+ /** Flag to know if initialized or not.
82
+ */
83
+ int initialized;
84
+
85
+ /** Pointer to ::ads_init() function.
86
+ */
87
+ function(ads_init);
88
+
89
+ /** Pointer to ::ads_fini() function.
90
+ */
91
+ function(ads_fini);
92
+
93
+ /** Pointer to ::ads_new_connection() function.
94
+ */
95
+ function(ads_new_connection);
96
+
97
+ /** Pointer to ::ads_free_connection() function.
98
+ */
99
+ function(ads_free_connection);
100
+
101
+ /** Pointer to ::ads_make_connection() function.
102
+ */
103
+ function(ads_make_connection);
104
+
105
+ /** Pointer to ::ads_connect() function.
106
+ */
107
+ function(ads_connect);
108
+
109
+ /** Pointer to ::ads_disconnect() function.
110
+ */
111
+ function(ads_disconnect);
112
+
113
+ /** Pointer to ::ads_execute_immediate() function.
114
+ */
115
+ function(ads_execute_immediate);
116
+
117
+ /** Pointer to ::ads_prepare() function.
118
+ */
119
+ function(ads_prepare);
120
+
121
+ /** Pointer to ::ads_free_stmt() function.
122
+ */
123
+ function(ads_free_stmt);
124
+
125
+ /** Pointer to ::ads_num_params() function.
126
+ */
127
+ function(ads_num_params);
128
+
129
+ /** Pointer to ::ads_describe_bind_param() function.
130
+ */
131
+ function(ads_describe_bind_param);
132
+
133
+ /** Pointer to ::ads_bind_param() function.
134
+ */
135
+ function(ads_bind_param);
136
+
137
+ /** Pointer to ::ads_send_param_data() function.
138
+ */
139
+ function(ads_send_param_data);
140
+
141
+ /** Pointer to ::ads_reset() function.
142
+ */
143
+ function(ads_reset);
144
+
145
+ /** Pointer to ::ads_get_bind_param_info() function.
146
+ */
147
+ function(ads_get_bind_param_info);
148
+
149
+ /** Pointer to ::ads_execute() function.
150
+ */
151
+ function(ads_execute);
152
+
153
+ /** Pointer to ::ads_execute_direct() function.
154
+ */
155
+ function(ads_execute_direct);
156
+
157
+ /** Pointer to ::ads_fetch_absolute() function.
158
+ */
159
+ function(ads_fetch_absolute);
160
+
161
+ /** Pointer to ::ads_fetch_next() function.
162
+ */
163
+ function(ads_fetch_next);
164
+
165
+ /** Pointer to ::ads_get_next_result() function.
166
+ */
167
+ function(ads_get_next_result);
168
+
169
+ /** Pointer to ::ads_affected_rows() function.
170
+ */
171
+ function(ads_affected_rows);
172
+
173
+ /** Pointer to ::ads_num_cols() function.
174
+ */
175
+ function(ads_num_cols);
176
+
177
+ /** Pointer to ::ads_num_rows() function.
178
+ */
179
+ function(ads_num_rows);
180
+
181
+ /** Pointer to ::ads_get_column() function.
182
+ */
183
+ function(ads_get_column);
184
+
185
+ /** Pointer to ::ads_get_data() function.
186
+ */
187
+ function(ads_get_data);
188
+
189
+ /** Pointer to ::ads_get_data_info() function.
190
+ */
191
+ function(ads_get_data_info);
192
+
193
+ /** Pointer to ::ads_get_column_info() function.
194
+ */
195
+ function(ads_get_column_info);
196
+
197
+ /** Pointer to ::ads_commit() function.
198
+ */
199
+ function(ads_commit);
200
+
201
+ /** Pointer to ::ads_rollback() function.
202
+ */
203
+ function(ads_rollback);
204
+
205
+ /** Pointer to ::ads_client_version() function.
206
+ */
207
+ function(ads_client_version);
208
+
209
+ /** Pointer to ::ads_error() function.
210
+ */
211
+ function(ads_error);
212
+
213
+ /** Pointer to ::ads_sqlstate() function.
214
+ */
215
+ function(ads_sqlstate);
216
+
217
+ /** Pointer to ::ads_clear_error() function.
218
+ */
219
+ function(ads_clear_error);
220
+
221
+ /** Pointer to ::ads_cancel() function.
222
+ */
223
+ function(ads_cancel);
224
+
225
+ /** Pointer to ::AdsBeginTransaction() function.
226
+ */
227
+ function(AdsBeginTransaction);
228
+
229
+ } AdvantageInterface;
230
+ #undef function
231
+
232
+ #if defined(__cplusplus)
233
+ extern "C"
234
+ {
235
+ #endif
236
+
237
+ int ads_initialize_interface(AdvantageInterface *api, const char *optional_path_to_dll);
238
+
239
+ void ads_finalize_interface(AdvantageInterface *api);
240
+
241
+ #if defined(__cplusplus)
242
+ }
243
+ #endif
244
+
245
+ #endif
@@ -0,0 +1,1836 @@
1
+ /*====================================================
2
+ *
3
+ * Copyright 2008-2010 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
+ *
20
+ *====================================================*/
21
+ #include "ruby.h"
22
+ #include "adscapidll.h"
23
+
24
+ const char *VERSION = "0.1.2";
25
+
26
+ typedef struct imp_drh_st
27
+ {
28
+ AdvantageInterface api;
29
+ void *adscapi_context;
30
+ } imp_drh_st;
31
+
32
+ // Defining the Ruby Modules
33
+ static VALUE mAdvantage;
34
+ static VALUE mAPI;
35
+ static VALUE cAdvantageInterface;
36
+
37
+ // Defining binder for DBCAPI types
38
+ static VALUE cA_ads_connection;
39
+ static VALUE cA_ads_data_value;
40
+ static VALUE cA_ads_bind_param;
41
+ static VALUE cA_ads_bind_param_info;
42
+
43
+ // This function is called when the module is first loaded by ruby.
44
+ // The name of this function MUST match be Init_<modulename>.
45
+ void Init_advantage();
46
+
47
+ // Wrapper functions for the DBICAPI functions
48
+
49
+ static VALUE
50
+ static_API_ads_initialize_interface(VALUE module, VALUE imp_drh);
51
+
52
+ static VALUE
53
+ static_API_ads_finalize_interface(VALUE module, VALUE imp_drh);
54
+
55
+ static VALUE
56
+ static_AdvantageInterface_alloc(VALUE class);
57
+
58
+ static VALUE
59
+ static_AdvantageInterface_ads_init(VALUE class);
60
+
61
+ static VALUE
62
+ static_AdvantageInterface_ads_new_connection(VALUE class);
63
+
64
+ static VALUE
65
+ static_AdvantageInterface_ads_client_version(VALUE imp_drh);
66
+
67
+ static VALUE
68
+ static_AdvantageInterface_ads_connect(VALUE imp_drh, VALUE ads_conn, VALUE str);
69
+
70
+ static VALUE
71
+ static_AdvantageInterface_ads_disconnect(VALUE imp_drh, VALUE ads_conn);
72
+
73
+ static VALUE
74
+ static_AdvantageInterface_ads_free_connection(VALUE imp_drh, VALUE ads_conn);
75
+
76
+ static VALUE
77
+ static_AdvantageInterface_ads_fini(VALUE imp_drh);
78
+
79
+ static VALUE
80
+ static_AdvantageInterface_ads_error(VALUE imp_drh, VALUE ads_conn);
81
+
82
+ static VALUE
83
+ static_AdvantageInterface_ads_execute_immediate(VALUE imp_drh, VALUE ads_conn, VALUE sql);
84
+
85
+ static VALUE
86
+ static_AdvantageInterface_ads_execute_direct(VALUE imp_drh, VALUE ads_conn, VALUE sql);
87
+
88
+ static VALUE
89
+ static_AdvantageInterface_ads_num_cols(VALUE imp_drh, VALUE ads_stmt);
90
+
91
+ static VALUE
92
+ static_AdvantageInterface_ads_num_rows(VALUE imp_drh, VALUE ads_stmt);
93
+
94
+ static VALUE
95
+ static_AdvantageInterface_ads_get_column(VALUE imp_drh, VALUE ads_stmt, VALUE col_num);
96
+
97
+ static VALUE
98
+ static_AdvantageInterface_ads_fetch_next(VALUE imp_drh, VALUE ads_stmt);
99
+
100
+ static VALUE
101
+ static_AdvantageInterface_ads_get_column_info(VALUE imp_drh, VALUE ads_stmt, VALUE col_num);
102
+
103
+ static VALUE
104
+ static_AdvantageInterface_AdsBeginTransaction(VALUE imp_drh, VALUE ads_conn);
105
+
106
+ static VALUE
107
+ static_AdvantageInterface_ads_commit(VALUE imp_drh, VALUE ads_conn);
108
+
109
+ static VALUE
110
+ static_AdvantageInterface_ads_rollback(VALUE imp_drh, VALUE ads_conn);
111
+
112
+ static VALUE
113
+ static_AdvantageInterface_ads_prepare(VALUE imp_drh, VALUE ads_conn, VALUE sql);
114
+
115
+ static VALUE
116
+ static_AdvantageInterface_ads_free_stmt(VALUE imp_drh, VALUE ads_stmt);
117
+
118
+ static VALUE
119
+ static_AdvantageInterface_ads_reset(VALUE imp_drh, VALUE ads_stmt);
120
+
121
+ static VALUE
122
+ static_AdvantageInterface_ads_execute(VALUE imp_drh, VALUE ads_stmt);
123
+
124
+ static VALUE
125
+ static_AdvantageInterface_ads_affected_rows(VALUE imp_drh, VALUE ads_stmt);
126
+
127
+ static VALUE
128
+ static_AdvantageInterface_ads_describe_bind_param(VALUE imp_drh, VALUE ads_stmt, VALUE index);
129
+
130
+ /*
131
+ * C to Ruby Data conversion function to convert DBCAPI column type into the correct Ruby type
132
+ */
133
+ static VALUE C2RB(a_ads_data_value *value)
134
+ {
135
+ VALUE tdata;
136
+
137
+ if (value == NULL || value->buffer == NULL || value->is_null == NULL)
138
+ {
139
+ rb_raise(rb_eTypeError, "Operation not allowed. Has no value.");
140
+ }
141
+ else if (*value->is_null)
142
+ {
143
+ tdata = Qnil;
144
+ }
145
+ else
146
+ {
147
+ switch (value->type)
148
+ {
149
+ case A_BINARY:
150
+ tdata = rb_str_new((char *)value->buffer, *value->length);
151
+ break;
152
+ case A_STRING:
153
+ case A_DATE:
154
+ case A_TIME:
155
+ case A_TIMESTAMP:
156
+ case A_NCHAR:
157
+ case A_DECIMAL:
158
+ tdata = rb_str_new((char *)value->buffer, *value->length);
159
+ break;
160
+ case A_DOUBLE:
161
+ tdata = rb_float_new(*(double *)value->buffer);
162
+ break;
163
+ case A_VAL64:
164
+ tdata = LL2NUM(*(LONG_LONG *)value->buffer);
165
+ break;
166
+ case A_UVAL64:
167
+ tdata = ULL2NUM(*(unsigned LONG_LONG *)value->buffer);
168
+ break;
169
+ case A_VAL32:
170
+ tdata = INT2FIX(*(int *)value->buffer);
171
+ break;
172
+ case A_UVAL32:
173
+ tdata = UINT2NUM(*(unsigned int *)value->buffer);
174
+ break;
175
+ case A_VAL16:
176
+ tdata = INT2FIX(*(short *)value->buffer);
177
+ break;
178
+ case A_UVAL16:
179
+ tdata = UINT2NUM(*(unsigned short *)value->buffer);
180
+ break;
181
+ case A_VAL8:
182
+ tdata = CHR2FIX(*(unsigned char *)value->buffer);
183
+ break;
184
+ case A_UVAL8:
185
+ tdata = CHR2FIX(*(unsigned char *)value->buffer);
186
+ break;
187
+ default:
188
+ rb_raise(rb_eTypeError, "Invalid Data Type");
189
+ tdata = Qnil;
190
+ break;
191
+ }
192
+ }
193
+
194
+ return tdata;
195
+ }
196
+
197
+ /*
198
+ * call-seq:
199
+ * ads_initialize_interface( VALUE imp_drh ) -> int result
200
+ *
201
+ * Initializes the AdvantageInterface object and loads the DLL dynamically.
202
+ *
203
+ * This function attempts to load the Advantage C API DLL dynamically and
204
+ * looks up all the entry points of the DLL.
205
+ *
206
+ * <b>Parameters</b>:
207
+ * - <tt>VALUE imp_drh</tt> -- An API structure to initialize.
208
+ *
209
+ * <b>Returns</b>:
210
+ * - <tt>result</tt>: <tt>1</tt> on successful initialization, <tt>0</tt> on failure.
211
+ *
212
+ */
213
+ static VALUE
214
+ static_API_ads_initialize_interface(VALUE module, VALUE imp_drh)
215
+ {
216
+ imp_drh_st *s_imp_drh;
217
+ int result;
218
+
219
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
220
+
221
+ result = ads_initialize_interface(&(s_imp_drh->api), NULL);
222
+
223
+ return (INT2FIX(result));
224
+ }
225
+
226
+ /*
227
+ * call-seq:
228
+ * ads_finalize_interface( VALUE imp_drh ) -> nil
229
+ *
230
+ * Finalize and free resources associated with the Advantage C API DLL.
231
+ *
232
+ * This function will unload the library and uninitialize the supplied
233
+ * AdvantageInterface structure.
234
+ *
235
+ * <b>Parameters</b>:
236
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
237
+ *
238
+ * <b>Returns</b>:
239
+ * - <tt>nil</tt>.
240
+ *
241
+ */
242
+ static VALUE
243
+ static_API_ads_finalize_interface(VALUE module, VALUE imp_drh)
244
+ {
245
+ imp_drh_st *s_imp_drh;
246
+
247
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
248
+
249
+ ads_finalize_interface(&(s_imp_drh->api));
250
+
251
+ free(&(s_imp_drh->api));
252
+
253
+ return (Qnil);
254
+ }
255
+
256
+ static VALUE
257
+ static_AdvantageInterface_alloc(VALUE class)
258
+ {
259
+ imp_drh_st *imp_drh = NULL;
260
+ VALUE tdata;
261
+
262
+ imp_drh = malloc(sizeof(imp_drh_st));
263
+ memset(imp_drh, 0, sizeof(imp_drh_st));
264
+
265
+ tdata = Data_Wrap_Struct(class, 0, 0, imp_drh);
266
+ return tdata;
267
+ }
268
+
269
+ /*
270
+ * call-seq:
271
+ * ads_init( VALUE imp_drh ) -> [VALUE result, VALUE version]
272
+ *
273
+ * Initializes the interface.
274
+ *
275
+ * <b>Parameters</b>:
276
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
277
+ *
278
+ * <b>Returns</b>:
279
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
280
+ * - <tt>VALUE version</tt>: The maximum API version that is supported.
281
+ *
282
+ */
283
+ static VALUE
284
+ static_AdvantageInterface_ads_init(VALUE imp_drh)
285
+ {
286
+ imp_drh_st *s_imp_drh;
287
+ UNSIGNED32 result;
288
+ UNSIGNED32 s_version_available;
289
+ VALUE multi_result;
290
+
291
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
292
+
293
+ multi_result = rb_ary_new();
294
+
295
+ if (&(s_imp_drh->api) == NULL)
296
+ {
297
+ rb_ary_push(multi_result, INT2FIX(0));
298
+ rb_ary_push(multi_result, Qnil);
299
+ }
300
+ else
301
+ {
302
+ result = s_imp_drh->api.ads_init((UNSIGNED8 *)"RUBY", 1, &s_version_available);
303
+ rb_ary_push(multi_result, INT2FIX(result));
304
+ rb_ary_push(multi_result, INT2FIX(s_version_available));
305
+ }
306
+
307
+ return (multi_result);
308
+ }
309
+
310
+ /*
311
+ * call-seq:
312
+ * ads_new_connection( VALUE imp_drh ) -> VALUE connection
313
+ *
314
+ * Creates a connection object.
315
+ *
316
+ * An API connection object needs to be created before a database connection
317
+ * is established. Errors can be retrieved from the connection object. Only
318
+ * one request can be processed on a connection at a time.
319
+ *
320
+ * <b>Parameters</b>:
321
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
322
+ *
323
+ * <b>Returns</b>:
324
+ * - <tt>VALUE connection</tt>: A connection object.
325
+ *
326
+ */
327
+ static VALUE
328
+ static_AdvantageInterface_ads_new_connection(VALUE imp_drh)
329
+ {
330
+ imp_drh_st *s_imp_drh;
331
+ a_ads_connection *ptr;
332
+ VALUE tdata;
333
+
334
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
335
+ ptr = s_imp_drh->api.ads_new_connection();
336
+
337
+ tdata = Data_Wrap_Struct(cA_ads_connection, 0, 0, ptr);
338
+
339
+ return (tdata);
340
+ }
341
+
342
+ /*
343
+ * call-seq:
344
+ * ads_client_version( VALUE imp_drh ) -> [VALUE verstr]
345
+ *
346
+ * Retrieves the client version as a string.
347
+ *
348
+ * This function can be used to retrieve the client version.
349
+ *
350
+ * <b>Parameters</b>:
351
+ * - <tt>VALUE imp_drh</tt> -- an initialized API structure to finalize
352
+ *
353
+ * <b>Returns</b>:
354
+ * - <tt>VALUE verstr</tt>: The client version string.
355
+ *
356
+ */
357
+
358
+ static VALUE
359
+ static_AdvantageInterface_ads_client_version(VALUE imp_drh)
360
+ {
361
+ imp_drh_st *s_imp_drh;
362
+ char s_buffer[255];
363
+
364
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
365
+
366
+ s_imp_drh->api.ads_client_version((UNSIGNED8 *)s_buffer, 255);
367
+
368
+ return (rb_str_new2(s_buffer));
369
+ }
370
+
371
+ /*
372
+ * call-seq:
373
+ * ads_connect( VALUE imp_drh, VALUE ads_conn, VALUE str ) -> VALUE result
374
+ *
375
+ * Creates a connection object.
376
+ *
377
+ * An API connection object needs to be created before a database connection
378
+ * is established. Errors can be retrieved from the connection object. Only
379
+ * one request can be processed on a connection at a time.
380
+ *
381
+ * <b>Parameters</b>:
382
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
383
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was created by ads_new_connection( ).
384
+ * - <tt>VALUE str</tt> -- A connection string.
385
+ *
386
+ * <b>Returns</b>:
387
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
388
+ *
389
+ */
390
+ static VALUE
391
+ static_AdvantageInterface_ads_connect(VALUE imp_drh, VALUE ads_conn, VALUE str)
392
+ {
393
+ imp_drh_st *s_imp_drh;
394
+ a_ads_connection *s_ads_conn;
395
+ char *s_str;
396
+ UNSIGNED32 result;
397
+
398
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
399
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
400
+
401
+ s_str = StringValueCStr(str);
402
+
403
+ result = s_imp_drh->api.ads_connect(s_ads_conn, (UNSIGNED8 *)s_str);
404
+
405
+ return (INT2FIX(result));
406
+ }
407
+
408
+ /*
409
+ * call-seq:
410
+ * ads_disconnect( VALUE imp_drh, VALUE ads_conn ) -> nil
411
+ *
412
+ * Disconnect an already established connection.
413
+ *
414
+ * This function disconnects the connection. Any
415
+ * uncommitted transactions will be rolled back.
416
+ *
417
+ * <b>Parameters</b>:
418
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
419
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
420
+ *
421
+ * <b>Returns</b>:
422
+ * - <tt>nil</tt>.
423
+ *
424
+ */
425
+ static VALUE
426
+ static_AdvantageInterface_ads_disconnect(VALUE imp_drh, VALUE ads_conn)
427
+ {
428
+ imp_drh_st *s_imp_drh;
429
+ a_ads_connection *s_ads_conn;
430
+
431
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
432
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
433
+
434
+ s_imp_drh->api.ads_disconnect(s_ads_conn);
435
+
436
+ return (Qnil);
437
+ }
438
+
439
+ /*
440
+ * call-seq:
441
+ * ads_free_connection( VALUE imp_drh, VALUE ads_conn ) -> nil
442
+ *
443
+ * Frees the resources associated with a connection object.
444
+ *
445
+ * <b>Parameters</b>:
446
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
447
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was disconnected by ads_disconnect( ).
448
+ *
449
+ * <b>Returns</b>:
450
+ * - <tt>nil</tt>.
451
+ *
452
+ */
453
+ static VALUE
454
+ static_AdvantageInterface_ads_free_connection(VALUE imp_drh, VALUE ads_conn)
455
+ {
456
+ imp_drh_st *s_imp_drh;
457
+ a_ads_connection *s_ads_conn;
458
+
459
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
460
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
461
+
462
+ s_imp_drh->api.ads_free_connection(s_ads_conn);
463
+
464
+ return (Qnil);
465
+ }
466
+
467
+ /*
468
+ * call-seq:
469
+ * ads_fini( VALUE imp_drh ) -> nil
470
+ *
471
+ * Finalizes the interface.
472
+ *
473
+ * Thus function frees any resources allocated by the API.
474
+ *
475
+ * <b>Parameters</b>:
476
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
477
+ *
478
+ * <b>Returns</b>:
479
+ * - <tt>nil</tt>.
480
+ *
481
+ */
482
+ static VALUE
483
+ static_AdvantageInterface_ads_fini(VALUE imp_drh)
484
+ {
485
+ imp_drh_st *s_imp_drh;
486
+
487
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
488
+
489
+ s_imp_drh->api.ads_fini();
490
+
491
+ return (Qnil);
492
+ }
493
+
494
+ /*
495
+ * call-seq:
496
+ * ads_error( VALUE imp_drh, VALUE ads_conn ) -> [VALUE result, VALUE errstr]
497
+ *
498
+ * Retrieves the last error code and message.
499
+ *
500
+ * This function can be used to retrieve the last error code and message
501
+ * stored in the connection object.
502
+ *
503
+ * <b>Parameters</b>:
504
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
505
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
506
+ *
507
+ * <b>Returns</b>:
508
+ * - <tt>VALUE result</tt>: The last error code. Positive values are warnings, negative values are errors, and <tt>0</tt> is success.
509
+ * - <tt>VALUE errstr</tt>: The error message corresponding to the error code.
510
+ *
511
+ */
512
+
513
+ static VALUE
514
+ static_AdvantageInterface_ads_error(VALUE imp_drh, VALUE ads_conn)
515
+ {
516
+ imp_drh_st *s_imp_drh;
517
+ a_ads_connection *s_ads_conn;
518
+ char s_buffer[255];
519
+ UNSIGNED32 result;
520
+ VALUE multi_result;
521
+
522
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
523
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
524
+
525
+ result = s_imp_drh->api.ads_error(s_ads_conn, (UNSIGNED8 *)s_buffer, 255);
526
+
527
+ multi_result = rb_ary_new();
528
+
529
+ rb_ary_push(multi_result, INT2FIX(result));
530
+ rb_ary_push(multi_result, rb_str_new2(s_buffer));
531
+
532
+ return (multi_result);
533
+ }
534
+
535
+ /*
536
+ * call-seq:
537
+ * ads_execute_immediate( VALUE imp_drh, VALUE ads_conn, VALUE sql ) -> VALUE result
538
+ *
539
+ * Executes a SQL statement immediately without returning a result set.
540
+ *
541
+ * This function executes the specified SQL statement immediately. It is
542
+ * useful for SQL statements that do not return a result set.
543
+ *
544
+ *
545
+ * <b>Parameters</b>:
546
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
547
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
548
+ * - <tt>VALUE sql</tt> -- A SQL query string.
549
+ *
550
+ * <b>Returns</b>:
551
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
552
+ *
553
+ */
554
+ static VALUE
555
+ static_AdvantageInterface_ads_execute_immediate(VALUE imp_drh, VALUE ads_conn, VALUE sql)
556
+ {
557
+ imp_drh_st *s_imp_drh;
558
+ a_ads_connection *s_ads_conn;
559
+ char *s_sql;
560
+ UNSIGNED32 result;
561
+
562
+ s_sql = StringValueCStr(sql);
563
+
564
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
565
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
566
+
567
+ result = s_imp_drh->api.ads_execute_immediate(s_ads_conn, (UNSIGNED8 *)s_sql);
568
+
569
+ return (INT2FIX(result));
570
+ }
571
+
572
+ /*
573
+ * call-seq:
574
+ * ads_execute_direct( VALUE imp_drh, VALUE ads_conn, VALUE sql ) -> VALUE resultset
575
+ *
576
+ * Executes a SQL statement and possibly returns a result set.
577
+ *
578
+ * This function executes the SQL statement specified by the string argument.
579
+ * This function is suitable if you want to prepare and then execute a
580
+ * statement, and can be used instead of calling ads_prepare( ) followed
581
+ * by ads_execute( ).
582
+ *
583
+ * This function cannot be used for executing a SQL statement with
584
+ * parameters.
585
+ *
586
+ * <b>Parameters</b>:
587
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
588
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
589
+ * - <tt>VALUE sql</tt> -- A SQL query string.
590
+ *
591
+ * <b>Returns</b>:
592
+ * - <tt>VALUE result</tt>: A query result set if successful, nil if failed.
593
+ *
594
+ */
595
+ static VALUE
596
+ static_AdvantageInterface_ads_execute_direct(VALUE imp_drh, VALUE ads_conn, VALUE sql)
597
+ {
598
+ imp_drh_st *s_imp_drh;
599
+ a_ads_connection *s_ads_conn;
600
+ ADSHANDLE resultset = 0;
601
+ char *s_sql;
602
+ VALUE tdata;
603
+
604
+ s_sql = StringValueCStr(sql);
605
+
606
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
607
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
608
+
609
+ resultset = s_imp_drh->api.ads_execute_direct(s_ads_conn, (UNSIGNED8 *)s_sql);
610
+
611
+ if (resultset)
612
+ {
613
+ tdata = INT2FIX(resultset);
614
+ }
615
+ else
616
+ {
617
+ tdata = Qnil;
618
+ }
619
+
620
+ return (tdata);
621
+ }
622
+
623
+ /*
624
+ * call-seq:
625
+ * ads_num_cols( VALUE imp_drh, VALUE ads_stmt ) -> VALUE num_cols
626
+ *
627
+ * Returns number of columns in the result set.
628
+ *
629
+ * <b>Parameters</b>:
630
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
631
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
632
+ *
633
+ * <b>Returns</b>:
634
+ * - <tt>VALUE num_cols</tt>: The number of columns in the result set or <tt>-1</tt> on a failure.
635
+ *
636
+ */
637
+ static VALUE
638
+ static_AdvantageInterface_ads_num_cols(VALUE imp_drh, VALUE ads_stmt)
639
+ {
640
+ imp_drh_st *s_imp_drh;
641
+ ADSHANDLE s_stmt;
642
+ UNSIGNED32 result;
643
+
644
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
645
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
646
+ s_stmt = NUM2ULONG(ads_stmt);
647
+
648
+ result = s_imp_drh->api.ads_num_cols(s_stmt);
649
+
650
+ return (INT2NUM(result));
651
+ }
652
+
653
+ /*
654
+ * call-seq:
655
+ * ads_num_rows( VALUE imp_drh, VALUE ads_stmt ) -> VALUE num_rows
656
+ *
657
+ * Returns number of rows in the result set.
658
+ *
659
+ * <b>Parameters</b>:
660
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
661
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
662
+ *
663
+ * <b>Returns</b>:
664
+ * - <tt>VALUE num_rows</tt>: The number of rows in the result set or <tt>-1</tt> on a failure.
665
+ *
666
+ */
667
+ static VALUE
668
+ static_AdvantageInterface_ads_num_rows(VALUE imp_drh, VALUE ads_stmt)
669
+ {
670
+ imp_drh_st *s_imp_drh;
671
+ ADSHANDLE s_stmt;
672
+ UNSIGNED32 result;
673
+
674
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
675
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
676
+ s_stmt = NUM2ULONG(ads_stmt);
677
+
678
+ result = s_imp_drh->api.ads_num_rows(s_stmt);
679
+
680
+ return (INT2FIX(result));
681
+ }
682
+
683
+ /*
684
+ * call-seq:
685
+ * ads_get_column( VALUE imp_drh, VALUE ads_stmt, VALUE col_num ) -> [VALUE result, VALUE column_value]
686
+ *
687
+ * Retrieves the data fetched for the specified column.
688
+ *
689
+ * <b>Parameters</b>:
690
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
691
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
692
+ * - <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and ads_num_cols( ) - 1.
693
+ *
694
+ * <b>Returns</b>:
695
+ * - <tt>VALUE column_value</tt>: The value of the column. nil is returned if the value was NULL.
696
+ *
697
+ */
698
+ static VALUE
699
+ static_AdvantageInterface_ads_get_column(VALUE imp_drh, VALUE ads_stmt, VALUE col_num)
700
+ {
701
+ imp_drh_st *s_imp_drh;
702
+ ADSHANDLE s_stmt;
703
+ UNSIGNED32 s_col_num;
704
+ a_ads_data_value value;
705
+ UNSIGNED32 result;
706
+ VALUE multi_result;
707
+
708
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
709
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
710
+ s_stmt = NUM2ULONG(ads_stmt);
711
+ s_col_num = NUM2INT(col_num);
712
+
713
+ result = s_imp_drh->api.ads_get_column(s_stmt, s_col_num, &value);
714
+
715
+ multi_result = rb_ary_new();
716
+ rb_ary_push(multi_result, INT2FIX(result));
717
+
718
+ if (!result)
719
+ {
720
+ rb_ary_push(multi_result, Qnil);
721
+ }
722
+ else
723
+ {
724
+ if (*value.is_null)
725
+ {
726
+ rb_ary_push(multi_result, Qnil);
727
+ }
728
+ else
729
+ {
730
+ rb_ary_push(multi_result, C2RB(&value));
731
+ }
732
+ }
733
+
734
+ return (multi_result);
735
+ }
736
+
737
+ /*
738
+ * call-seq:
739
+ * ads_fetch_next( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
740
+ *
741
+ * Fetches the next row from the result set.
742
+ *
743
+ * This function fetches the next row from the result set. When the result
744
+ * object is first created, the current row pointer is set to point before
745
+ * the first row ( that is, row 0 ).
746
+ * This function advances the row pointer first and then fetches the data
747
+ * at the new row.
748
+ *
749
+ * <b>Parameters</b>:
750
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
751
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
752
+ *
753
+ * <b>Returns</b>:
754
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful fetch, <tt>0</tt> otherwise.
755
+ *
756
+ */
757
+ static VALUE
758
+ static_AdvantageInterface_ads_fetch_next(VALUE imp_drh, VALUE ads_stmt)
759
+ {
760
+ imp_drh_st *s_imp_drh;
761
+ ADSHANDLE s_stmt;
762
+ UNSIGNED32 result;
763
+
764
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
765
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
766
+ s_stmt = NUM2ULONG(ads_stmt);
767
+
768
+ result = s_imp_drh->api.ads_fetch_next(s_stmt);
769
+
770
+ return (INT2FIX(result));
771
+ }
772
+
773
+ /*
774
+ * call-seq:
775
+ * ads_get_column_info( VALUE imp_drh, VALUE ads_stmt, VALUE col_num ) -> [VALUE result, VALUE col_num, VALUE name, VALUE type, VALUE max_size]
776
+ *
777
+ * Fetches the next row from the result set.
778
+ *
779
+ * This function fetches the next row from the result set. When the result
780
+ * object is first created, the current row pointer is set to point before
781
+ * the first row ( that is, row 0 ).
782
+ * This function advances the row pointer first and then fetches the data
783
+ * at the new row.
784
+ *
785
+ * <b>Parameters</b>:
786
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
787
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
788
+ * - <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and ads_num_cols( ) - 1.
789
+ *
790
+ * <b>Returns</b>:
791
+ * - <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.
792
+ * - <tt>VALUE col_num</tt>: The number of the column retrieved.
793
+ * - <tt>VALUE name</tt>: The name of the column.
794
+ * - <tt>VALUE type</tt>: The type of the column data.
795
+ * - <tt>VALUE native_type</tt>: The Advantage native type of the column data.
796
+ * - <tt>VALUE precision</tt>: The precision of the column.
797
+ * - <tt>VALUE scale</tt>: The scale of the column.
798
+ * - <tt>VALUE max_size</tt>: The maximum size a data value in this column can take.
799
+ * - <tt>VALUE nullable</tt>: The nullability of the column.
800
+ *
801
+ */
802
+ static VALUE
803
+ static_AdvantageInterface_ads_get_column_info(VALUE imp_drh, VALUE ads_stmt, VALUE col_num)
804
+ {
805
+ imp_drh_st *s_imp_drh;
806
+ ADSHANDLE s_stmt;
807
+ UNSIGNED32 s_col_num;
808
+ a_ads_column_info info;
809
+ UNSIGNED32 result;
810
+ VALUE multi_result;
811
+
812
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
813
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
814
+ s_stmt = NUM2ULONG(ads_stmt);
815
+ s_col_num = NUM2INT(col_num);
816
+
817
+ result = s_imp_drh->api.ads_get_column_info(s_stmt, s_col_num, &info);
818
+
819
+ multi_result = rb_ary_new();
820
+ rb_ary_push(multi_result, INT2FIX(result));
821
+ rb_ary_push(multi_result, col_num);
822
+ rb_ary_push(multi_result, rb_str_new2((char *)info.name));
823
+ rb_ary_push(multi_result, INT2FIX(info.type));
824
+ rb_ary_push(multi_result, INT2FIX(info.native_type));
825
+ rb_ary_push(multi_result, INT2FIX(info.precision));
826
+ rb_ary_push(multi_result, INT2FIX(info.scale));
827
+ rb_ary_push(multi_result, INT2FIX(info.max_size));
828
+ rb_ary_push(multi_result, INT2FIX(info.nullable));
829
+
830
+ return (multi_result);
831
+ }
832
+
833
+ /*
834
+ * call-seq:
835
+ * AdsBeginTransaction( VALUE imp_drh, VALUE ads_conn ) -> VALUE result
836
+ *
837
+ * Starts a transaction on the current connection.
838
+ *
839
+ * <b>Parameters</b>:
840
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
841
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
842
+ *
843
+ * <b>Returns</b>:
844
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful begining a transaction, <tt>0</tt> otherwise.
845
+ *
846
+ */
847
+ static VALUE
848
+ static_AdvantageInterface_AdsBeginTransaction(VALUE imp_drh, VALUE ads_conn)
849
+ {
850
+ imp_drh_st *s_imp_drh;
851
+ a_ads_connection *s_ads_conn;
852
+ UNSIGNED32 result;
853
+
854
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
855
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
856
+
857
+ result = s_imp_drh->api.AdsBeginTransaction(s_ads_conn->hConnect);
858
+ if (result == 0)
859
+ return (INT2FIX(1));
860
+ else
861
+ return (INT2FIX(0));
862
+ }
863
+
864
+ /*
865
+ * call-seq:
866
+ * ads_commit( VALUE imp_drh, VALUE ads_conn ) -> VALUE result
867
+ *
868
+ * Commits the current transaction.
869
+ *
870
+ * <b>Parameters</b>:
871
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
872
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
873
+ *
874
+ * <b>Returns</b>:
875
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful commit, <tt>0</tt> otherwise.
876
+ *
877
+ */
878
+ static VALUE
879
+ static_AdvantageInterface_ads_commit(VALUE imp_drh, VALUE ads_conn)
880
+ {
881
+ imp_drh_st *s_imp_drh;
882
+ a_ads_connection *s_ads_conn;
883
+ UNSIGNED32 result;
884
+
885
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
886
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
887
+
888
+ result = s_imp_drh->api.ads_commit(s_ads_conn);
889
+
890
+ return (INT2FIX(result));
891
+ }
892
+
893
+ /*
894
+ * call-seq:
895
+ * ads_rollback( VALUE imp_drh, VALUE ads_conn ) -> VALUE result
896
+ *
897
+ * Rolls back the current transaction.
898
+ *
899
+ * <b>Parameters</b>:
900
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
901
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
902
+ *
903
+ * <b>Returns</b>:
904
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful rollback, <tt>0</tt> otherwise.
905
+ *
906
+ */
907
+ static VALUE
908
+ static_AdvantageInterface_ads_rollback(VALUE imp_drh, VALUE ads_conn)
909
+ {
910
+ imp_drh_st *s_imp_drh;
911
+ a_ads_connection *s_ads_conn;
912
+ UNSIGNED32 result;
913
+
914
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
915
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
916
+
917
+ result = s_imp_drh->api.ads_rollback(s_ads_conn);
918
+
919
+ return (INT2FIX(result));
920
+ }
921
+
922
+ /*
923
+ * call-seq:
924
+ * ads_prepare( VALUE imp_drh, VALUE ads_conn, VALUE sql ) -> VALUE stmt
925
+ *
926
+ * Prepares a SQL statement.
927
+ *
928
+ * This function prepares the supplied SQL string. Execution does not
929
+ * happen until ads_execute( ) is called. The returned statement object
930
+ * should be freed using ads_free_stmt( ).
931
+ *
932
+ *
933
+ * <b>Parameters</b>:
934
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
935
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
936
+ * - <tt>VALUE sql</tt> -- SQL query to prepare.
937
+ *
938
+ * <b>Returns</b>:
939
+ * - <tt>VALUE stmt</tt>: A statement object, or nil on failure. The statement object can be used by ads_execute( ) to execute the statement.
940
+ *
941
+ */
942
+ static VALUE
943
+ static_AdvantageInterface_ads_prepare(VALUE imp_drh, VALUE ads_conn, VALUE sql)
944
+ {
945
+ imp_drh_st *s_imp_drh;
946
+ a_ads_connection *s_ads_conn;
947
+ ADSHANDLE s_stmt = 0;
948
+ char *s_sql;
949
+ VALUE tdata;
950
+
951
+ s_sql = StringValueCStr(sql);
952
+
953
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
954
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
955
+
956
+ //EJS Passing FALSE for isUnicode
957
+ s_stmt = s_imp_drh->api.ads_prepare(s_ads_conn, (UNSIGNED8 *)s_sql, '\0');
958
+
959
+ if (s_stmt)
960
+ {
961
+ tdata = INT2FIX(s_stmt);
962
+ }
963
+ else
964
+ {
965
+ tdata = Qnil;
966
+ }
967
+
968
+ return (tdata);
969
+ }
970
+
971
+ /*
972
+ * call-seq:
973
+ * ads_free_stmt( VALUE imp_drh, VALUE ads_stmt ) -> nil
974
+ *
975
+ * Frees resources associated with a prepared statement object.
976
+ *
977
+ * This function frees the resources associated with a prepared statement
978
+ * object.
979
+ *
980
+ * <b>Parameters</b>:
981
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
982
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
983
+ *
984
+ * <b>Returns</b>:
985
+ * - <tt>nil</tt>.
986
+ *
987
+ */
988
+ static VALUE
989
+ static_AdvantageInterface_ads_free_stmt(VALUE imp_drh, VALUE ads_stmt)
990
+ {
991
+ imp_drh_st *s_imp_drh;
992
+ ADSHANDLE s_stmt;
993
+ int i;
994
+ int number_of_params = 0;
995
+ a_ads_bind_param_info bind_info;
996
+
997
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
998
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
999
+ s_stmt = NUM2ULONG(ads_stmt);
1000
+
1001
+ number_of_params = s_imp_drh->api.ads_num_params(s_stmt);
1002
+
1003
+ for (i = 0; i < number_of_params; i++)
1004
+ {
1005
+ if (s_imp_drh->api.ads_get_bind_param_info(s_stmt, i, &bind_info))
1006
+ {
1007
+ // We don't free bind_info.name as it's not allocated
1008
+ // if ( bind_info.name ) {free ( bind_info.name );}
1009
+
1010
+ if (bind_info.input_value.is_null)
1011
+ {
1012
+ free(bind_info.input_value.is_null);
1013
+ }
1014
+ if (bind_info.input_value.length)
1015
+ {
1016
+ free(bind_info.input_value.length);
1017
+ }
1018
+ if (bind_info.input_value.buffer)
1019
+ {
1020
+ free(bind_info.input_value.buffer);
1021
+ }
1022
+
1023
+ if (bind_info.output_value.is_null)
1024
+ {
1025
+ free(bind_info.output_value.is_null);
1026
+ }
1027
+ if (bind_info.output_value.length)
1028
+ {
1029
+ free(bind_info.output_value.length);
1030
+ }
1031
+ if (bind_info.output_value.buffer)
1032
+ {
1033
+ free(bind_info.output_value.buffer);
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ s_imp_drh->api.ads_free_stmt(s_stmt);
1039
+
1040
+ return (Qnil);
1041
+ }
1042
+
1043
+ /*
1044
+ * call-seq:
1045
+ * ads_reset( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
1046
+ *
1047
+ *
1048
+ * <b>Parameters</b>:
1049
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1050
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
1051
+ *
1052
+ * <b>Returns</b>:
1053
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.
1054
+ *
1055
+ */
1056
+ static VALUE
1057
+ static_AdvantageInterface_ads_reset(VALUE imp_drh, VALUE ads_stmt)
1058
+ {
1059
+ imp_drh_st *s_imp_drh;
1060
+ ADSHANDLE s_stmt;
1061
+ UNSIGNED32 result;
1062
+
1063
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1064
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1065
+ s_stmt = NUM2ULONG(ads_stmt);
1066
+
1067
+ result = s_imp_drh->api.ads_reset(s_stmt);
1068
+
1069
+ return (INT2FIX(result));
1070
+ }
1071
+
1072
+ /*
1073
+ * call-seq:
1074
+ * ads_execute( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
1075
+ *
1076
+ * Executes a prepared statement.
1077
+ *
1078
+ * <b>Parameters</b>:
1079
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1080
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare( ) or ads_execute_direct( ).
1081
+ *
1082
+ * <b>Returns</b>:
1083
+ * - <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.
1084
+ *
1085
+ */
1086
+ static VALUE
1087
+ static_AdvantageInterface_ads_execute(VALUE imp_drh, VALUE ads_stmt)
1088
+ {
1089
+ imp_drh_st *s_imp_drh;
1090
+ ADSHANDLE s_stmt;
1091
+ UNSIGNED32 result;
1092
+
1093
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1094
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1095
+ s_stmt = NUM2ULONG(ads_stmt);
1096
+
1097
+ //printf( "CEXT s_ads_stmt: %d \n", s_stmt );
1098
+ result = s_imp_drh->api.ads_execute(s_stmt);
1099
+ /*if ( result != AE_SUCCESS )
1100
+ return ( 0 );
1101
+ else
1102
+ return ( 1 );*/
1103
+ return (INT2FIX(result));
1104
+ }
1105
+
1106
+ /*
1107
+ * call-seq:
1108
+ * ads_affected_rows( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
1109
+ *
1110
+ * Returns the number of rows affected by execution of the prepared
1111
+ * statement.
1112
+ *
1113
+ * <b>Parameters</b>:
1114
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1115
+ * - <tt>VALUE ads_stmt</tt> -- A statement that was prepared and executed successfully with no result set returned.
1116
+ *
1117
+ * <b>Returns</b>:
1118
+ * - <tt>VALUE result</tt>: The number of rows affected or <tt>-1</tt> on failure.
1119
+ *
1120
+ */
1121
+ static VALUE
1122
+ static_AdvantageInterface_ads_affected_rows(VALUE imp_drh, VALUE ads_stmt)
1123
+ {
1124
+ imp_drh_st *s_imp_drh;
1125
+ ADSHANDLE s_stmt;
1126
+ UNSIGNED32 result;
1127
+
1128
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1129
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1130
+ s_stmt = NUM2ULONG(ads_stmt);
1131
+
1132
+ result = s_imp_drh->api.ads_affected_rows(s_stmt);
1133
+
1134
+ return (INT2FIX(result));
1135
+ }
1136
+
1137
+ /*
1138
+ * call-seq:
1139
+ * ads_describe_bind_param( VALUE imp_drh, VALUE ads_stmt, VALUE index ) -> [VALUE result, VALUE bind_param]
1140
+ *
1141
+ * Describes the bind parameters of a prepared statement.
1142
+ *
1143
+ * This function allows the caller to determine information about parameters
1144
+ * to a prepared statement. Depending on the type of the prepared statement
1145
+ * ( call to stored procedure or a DML ), only some information will be
1146
+ * provided. The information that will always be provided is the direction
1147
+ * of the parameters ( input, output, or input-output ).
1148
+ *
1149
+ * <b>Parameters</b>:
1150
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1151
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare( ).
1152
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params( )- 1.
1153
+ *
1154
+ * <b>Returns</b>:
1155
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1156
+ * - <tt>VALUE bind_param</tt>: The described param object.
1157
+ *
1158
+ */
1159
+ static VALUE
1160
+ static_AdvantageInterface_ads_describe_bind_param(VALUE imp_drh, VALUE ads_stmt, VALUE index)
1161
+ {
1162
+ imp_drh_st *s_imp_drh;
1163
+ ADSHANDLE s_stmt;
1164
+ a_ads_bind_param *s_ads_bind_param;
1165
+ UNSIGNED32 result;
1166
+ UNSIGNED32 s_index;
1167
+ VALUE tdata;
1168
+ VALUE multi_result;
1169
+
1170
+ s_ads_bind_param = malloc(sizeof(a_ads_bind_param));
1171
+ memset(s_ads_bind_param, 0, sizeof(a_ads_bind_param));
1172
+
1173
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1174
+ s_stmt = NUM2ULONG(ads_stmt);
1175
+ s_index = NUM2INT(index);
1176
+
1177
+ result = s_imp_drh->api.ads_describe_bind_param(s_stmt, s_index, s_ads_bind_param);
1178
+
1179
+ //FIXME handle failed result
1180
+
1181
+ multi_result = rb_ary_new();
1182
+
1183
+ rb_ary_push(multi_result, INT2FIX(result));
1184
+
1185
+ tdata = Data_Wrap_Struct(cA_ads_bind_param, 0, 0, s_ads_bind_param);
1186
+ rb_ary_push(multi_result, tdata);
1187
+
1188
+ return (multi_result);
1189
+ }
1190
+
1191
+ /*
1192
+ * call-seq:
1193
+ * ads_bind_param( VALUE imp_drh, VALUE ads_stmt, VALUE index, VALUE ads_bind_param ) -> VALUE result
1194
+ *
1195
+ * Binds a user supplied buffer as a parameter to the prepared statement.
1196
+ *
1197
+ * <b>Parameters</b>:
1198
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1199
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare( ).
1200
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params( ) - 1.
1201
+ * - <tt>VALUE ads_bind_param</tt> -- A filled bind object retrieved from ads_describe_bind_param( ).
1202
+ *
1203
+ * <b>Returns</b>:
1204
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1205
+ *
1206
+ */
1207
+ static VALUE
1208
+ static_AdvantageInterface_ads_bind_param(VALUE imp_drh, VALUE ads_stmt, VALUE index, VALUE ads_bind_param)
1209
+ {
1210
+ imp_drh_st *s_imp_drh;
1211
+ ADSHANDLE s_stmt;
1212
+ a_ads_bind_param *s_ads_bind_param;
1213
+ UNSIGNED32 result;
1214
+ UNSIGNED32 s_index;
1215
+
1216
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1217
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1218
+ s_stmt = NUM2ULONG(ads_stmt);
1219
+ Data_Get_Struct(ads_bind_param, a_ads_bind_param, s_ads_bind_param);
1220
+ s_index = NUM2INT(index);
1221
+
1222
+ result = s_imp_drh->api.ads_bind_param(s_stmt, s_index, s_ads_bind_param);
1223
+
1224
+ return (INT2FIX(result));
1225
+ }
1226
+
1227
+ /*
1228
+ * call-seq:
1229
+ * ads_get_bind_param_info( VALUE imp_drh, VALUE ads_stmt, VALUE index ) -> [VALUE result, VALUE bind_param]
1230
+ *
1231
+ * Gets bound parameter info.
1232
+ *
1233
+ * This function retrieves information about the parameters that were
1234
+ * bound using ads_bind_param( ).
1235
+ *
1236
+ * <b>Parameters</b>:
1237
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1238
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare( ).
1239
+ * - <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params( ) - 1.
1240
+ *
1241
+ * <b>Returns</b>:
1242
+ * - <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
1243
+ * - <tt>VALUE bind_param</tt>: The described param object.
1244
+ *
1245
+ */
1246
+ static VALUE
1247
+ static_AdvantageInterface_ads_get_bind_param_info(VALUE imp_drh, VALUE ads_stmt, VALUE index)
1248
+ {
1249
+ imp_drh_st *s_imp_drh;
1250
+ ADSHANDLE s_stmt;
1251
+ a_ads_bind_param_info s_ads_bind_param_info;
1252
+ UNSIGNED32 result;
1253
+ UNSIGNED32 s_index;
1254
+ VALUE tdata;
1255
+ VALUE multi_result;
1256
+
1257
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1258
+ s_stmt = NUM2ULONG(ads_stmt);
1259
+ s_index = NUM2INT(index);
1260
+
1261
+ result = s_imp_drh->api.ads_get_bind_param_info(s_stmt, s_index, &s_ads_bind_param_info);
1262
+
1263
+ //FIXME handle failed result
1264
+ multi_result = rb_ary_new();
1265
+
1266
+ rb_ary_push(multi_result, INT2FIX(result));
1267
+
1268
+ // FIXME: Is this safe to be on the stack?
1269
+ tdata = Data_Wrap_Struct(cA_ads_bind_param_info, 0, 0, &s_ads_bind_param_info);
1270
+ rb_ary_push(multi_result, tdata);
1271
+
1272
+ return (multi_result);
1273
+ }
1274
+
1275
+ /*
1276
+ * call-seq:
1277
+ * ads_num_params( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
1278
+ *
1279
+ * Returns the number of parameters that are expected for a prepared
1280
+ * statement.
1281
+ *
1282
+ * This function retrieves information about the parameters that were bound
1283
+ * using ads_bind_param( ).
1284
+ *
1285
+ * <b>Parameters</b>:
1286
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1287
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare( ).
1288
+ *
1289
+ * <b>Returns</b>:
1290
+ * - <tt>VALUE result</tt>: The number of parameters that are expected. <tt>-1</tt> if the ads_stmt object is not valid.
1291
+ *
1292
+ */
1293
+ static VALUE
1294
+ static_AdvantageInterface_ads_num_params(VALUE imp_drh, VALUE ads_stmt)
1295
+ {
1296
+ imp_drh_st *s_imp_drh;
1297
+ ADSHANDLE s_stmt;
1298
+ UNSIGNED32 result;
1299
+
1300
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1301
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1302
+ s_stmt = NUM2ULONG(ads_stmt);
1303
+
1304
+ result = s_imp_drh->api.ads_num_params(s_stmt);
1305
+
1306
+ return (INT2FIX(result));
1307
+ }
1308
+
1309
+ /*
1310
+ * call-seq:
1311
+ * ads_get_next_result( VALUE imp_drh, VALUE ads_stmt ) -> VALUE result
1312
+ *
1313
+ * Advances to the next result set in a multiple result set query.
1314
+ *
1315
+ * If a query ( such as a call to a stored procedure ) returns multiple result
1316
+ * sets, then this function advances from the current result set to the next.
1317
+ *
1318
+ *
1319
+ * <b>Parameters</b>:
1320
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1321
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was executed by ads_execute( ) or ads_execute_direct( ).
1322
+ *
1323
+ * <b>Returns</b>:
1324
+ * - <tt>VALUE result</tt>: <tt>1</tt> if was successfully able to advance to the next result set, <tt>0</tt> otherwise.
1325
+ *
1326
+ */
1327
+ static VALUE
1328
+ static_AdvantageInterface_ads_get_next_result(VALUE imp_drh, VALUE ads_stmt)
1329
+ {
1330
+ imp_drh_st *s_imp_drh;
1331
+ ADSHANDLE s_stmt;
1332
+ UNSIGNED32 result;
1333
+
1334
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1335
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1336
+ s_stmt = NUM2ULONG(ads_stmt);
1337
+
1338
+ result = s_imp_drh->api.ads_get_next_result(s_stmt);
1339
+
1340
+ return (INT2FIX(result));
1341
+ }
1342
+
1343
+ /*
1344
+ * call-seq:
1345
+ * ads_fetch_absolute( VALUE imp_drh, VALUE ads_stmt, VALUE offset ) -> VALUE result
1346
+ *
1347
+ * Fetches data at a specific row number in the result set.
1348
+ *
1349
+ * This function moves the current row in the result set to the row number
1350
+ * specified and fetches the data at that row.
1351
+ *
1352
+ * <b>Parameters</b>:
1353
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1354
+ * - <tt>VALUE ads_stmt</tt> -- A statement object that was executed by ads_execute( ) or ads_execute_direct( ).
1355
+ * - <tt>VALUE offset</tt> -- The row number to be fetched. The first row is <tt>1</tt>, the last row is <tt>-1</tt>.
1356
+ *
1357
+ * <b>Returns</b>:
1358
+ * - <tt>VALUE result</tt>: <tt>1</tt> if the fetch was successfully, <tt>0</tt> otherwise.
1359
+ *
1360
+ */
1361
+ static VALUE
1362
+ static_AdvantageInterface_ads_fetch_absolute(VALUE imp_drh, VALUE ads_stmt, VALUE offset)
1363
+ {
1364
+ imp_drh_st *s_imp_drh;
1365
+ ADSHANDLE s_stmt;
1366
+ UNSIGNED32 s_offset;
1367
+ UNSIGNED32 result;
1368
+
1369
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1370
+ //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
1371
+ s_stmt = NUM2ULONG(ads_stmt);
1372
+ s_offset = NUM2INT(offset);
1373
+ result = s_imp_drh->api.ads_fetch_absolute(s_stmt, s_offset);
1374
+
1375
+ return (INT2FIX(result));
1376
+ }
1377
+
1378
+ /*
1379
+ * call-seq:
1380
+ * ads_sqlstate( VALUE imp_drh, VALUE ads_conn ) -> VALUE sqlstate_str
1381
+ *
1382
+ * Retrieves the current SQL state.
1383
+ *
1384
+ * <b>Parameters</b>:
1385
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1386
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
1387
+ *
1388
+ * <b>Returns</b>:
1389
+ * - <tt>VALUE sqlstate_str</tt>: The SQL State.
1390
+ *
1391
+ */
1392
+ static VALUE
1393
+ static_AdvantageInterface_ads_sqlstate(VALUE imp_drh, VALUE ads_conn)
1394
+ {
1395
+ imp_drh_st *s_imp_drh;
1396
+ a_ads_connection *s_ads_conn;
1397
+ UNSIGNED32 result;
1398
+ char s_buffer[255];
1399
+
1400
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1401
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
1402
+
1403
+ result = s_imp_drh->api.ads_sqlstate(s_ads_conn, (UNSIGNED8 *)s_buffer, sizeof(s_buffer));
1404
+
1405
+ if (result)
1406
+ return (rb_str_new(s_buffer, strlen(s_buffer)));
1407
+ else
1408
+ return Qnil;
1409
+ }
1410
+
1411
+ /*
1412
+ * call-seq:
1413
+ * ads_clear_error( VALUE imp_drh, VALUE ads_conn ) -> nil
1414
+ *
1415
+ * Clears the last stored error code.
1416
+ *
1417
+ * <b>Parameters</b>:
1418
+ * - <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
1419
+ * - <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect( ).
1420
+ *
1421
+ * <b>Returns</b>:
1422
+ * - <tt>nil</tt>:.
1423
+ *
1424
+ */
1425
+ static VALUE
1426
+ static_AdvantageInterface_ads_clear_error(VALUE imp_drh, VALUE ads_conn)
1427
+ {
1428
+ imp_drh_st *s_imp_drh;
1429
+ a_ads_connection *s_ads_conn;
1430
+
1431
+ Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
1432
+ Data_Get_Struct(ads_conn, a_ads_connection, s_ads_conn);
1433
+
1434
+ s_imp_drh->api.ads_clear_error(s_ads_conn);
1435
+
1436
+ return (Qnil);
1437
+ }
1438
+
1439
+ /*
1440
+ * call-seq:
1441
+ * get_name( VALUE bind ) -> VALUE name
1442
+ *
1443
+ * Gets the name of the bound parameter.
1444
+ *
1445
+ * <b>Parameters</b>:
1446
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1447
+ *
1448
+ * <b>Returns</b>:
1449
+ * - <tt>VALUE name</tt>: The bound variable's name.
1450
+ *
1451
+ */
1452
+ static VALUE
1453
+ static_Bind_get_name(VALUE bind)
1454
+ {
1455
+ a_ads_bind_param *s_bind;
1456
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1457
+ return (rb_str_new2((char *)s_bind->name));
1458
+ }
1459
+
1460
+ /*
1461
+ * call-seq:
1462
+ * set_value( VALUE bind, VALUE val ) -> nil
1463
+ *
1464
+ * Sets the value of a bind parameter.
1465
+ *
1466
+ * This function is used to bind a Ruby VALUE to a given parameter in a
1467
+ * prepared statement. If the bind_direction is INPUT only, the type INPUT
1468
+ * will be bound based on the RUBY type:
1469
+ *
1470
+ * +-------------+------------+
1471
+ * | Ruby Type | Bind Type |
1472
+ * +-------------+------------+
1473
+ * | T_STRING => A_STRING |
1474
+ * | T_FIXNUM => A_VAL_32 |
1475
+ * | T_BIGNUM => A_DOUBLE |
1476
+ * | T_FLOAT => A_DOUBLE |
1477
+ * | T_STRING => A_STRING |
1478
+ * | T_NIL => isnull = 1 |
1479
+ * +--------------------------+
1480
+ *
1481
+ * If the bind direction is OUTPUT, instead use the DBCAPI type to set the
1482
+ * size of the buffer.
1483
+ *
1484
+ * In the case of INOUT parameters, it is the application's job to call this
1485
+ * method twice, once to bind the INPUT, and once to bind the OUTPUT.
1486
+ *
1487
+ * <b>Parameters</b>:
1488
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1489
+ * - <tt>VALUE val</tt> -- The value to bind into the bound variable.
1490
+ *
1491
+ * <b>Returns</b>:
1492
+ * - <tt>nil</tt>.
1493
+ */
1494
+ static VALUE
1495
+ static_Bind_set_value(VALUE bind, VALUE val)
1496
+ {
1497
+ a_ads_bind_param *s_bind;
1498
+ int length;
1499
+
1500
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1501
+
1502
+ // FIXME: use Ruby's allocation routines?
1503
+ s_bind->value.is_null = malloc(sizeof(UNSIGNED32));
1504
+ *s_bind->value.is_null = 0;
1505
+
1506
+ if (s_bind->direction == DD_INPUT)
1507
+ {
1508
+ switch (TYPE(val))
1509
+ {
1510
+ case T_STRING:
1511
+ s_bind->value.length = malloc(sizeof(size_t));
1512
+ length = RSTRING_LEN(val);
1513
+ *s_bind->value.length = length;
1514
+ s_bind->value.buffer = malloc(length);
1515
+ memcpy(s_bind->value.buffer, RSTRING_PTR(val), length);
1516
+ s_bind->value.type = A_STRING;
1517
+ break;
1518
+ case T_FIXNUM:
1519
+ if (sizeof(void *) == 4) //32-bit
1520
+ {
1521
+ s_bind->value.length = malloc(sizeof(size_t));
1522
+ s_bind->value.buffer = malloc(sizeof(int));
1523
+ *((int *)s_bind->value.buffer) = FIX2INT(val);
1524
+ s_bind->value.type = A_VAL32;
1525
+ length = 1;
1526
+ *s_bind->value.length = length;
1527
+ }
1528
+ else //64-bit
1529
+ {
1530
+ s_bind->value.length = malloc(sizeof(size_t));
1531
+ s_bind->value.buffer = malloc(sizeof(long));
1532
+ *((long *)s_bind->value.buffer) = FIX2LONG(val);
1533
+ s_bind->value.type = A_VAL64;
1534
+ length = 1;
1535
+ *s_bind->value.length = length;
1536
+ }
1537
+ break;
1538
+ case T_BIGNUM:
1539
+ s_bind->value.length = malloc(sizeof(size_t));
1540
+ s_bind->value.buffer = malloc(sizeof(LONG_LONG));
1541
+ *((LONG_LONG *)s_bind->value.buffer) = rb_num2ll(val);
1542
+ s_bind->value.type = A_VAL64;
1543
+ length = 1;
1544
+ *s_bind->value.length = length;
1545
+ break;
1546
+ case T_FLOAT:
1547
+ s_bind->value.length = malloc(sizeof(size_t));
1548
+ s_bind->value.buffer = malloc(sizeof(double));
1549
+ *((double *)s_bind->value.buffer) = NUM2DBL(val);
1550
+ s_bind->value.type = A_DOUBLE;
1551
+ length = 1;
1552
+ *s_bind->value.length = length;
1553
+ break;
1554
+ case T_FALSE:
1555
+ s_bind->value.length = malloc(sizeof(size_t));
1556
+ s_bind->value.buffer = malloc(sizeof(short));
1557
+ *((int *)s_bind->value.buffer) = ADS_FALSE;
1558
+ s_bind->value.type = A_UVAL16;
1559
+ length = 1;
1560
+ *s_bind->value.length = length;
1561
+ break;
1562
+ case T_TRUE:
1563
+ s_bind->value.length = malloc(sizeof(size_t));
1564
+ s_bind->value.buffer = malloc(sizeof(short));
1565
+ *((int *)s_bind->value.buffer) = ADS_TRUE;
1566
+ s_bind->value.type = A_UVAL16;
1567
+ length = 1;
1568
+ *s_bind->value.length = length;
1569
+ break;
1570
+ case T_NIL:
1571
+ s_bind->value.length = malloc(sizeof(size_t));
1572
+ *s_bind->value.is_null = 1;
1573
+ s_bind->value.buffer = malloc(sizeof(int));
1574
+ s_bind->value.type = A_VAL32;
1575
+ length = 1;
1576
+ *s_bind->value.length = length;
1577
+ break;
1578
+ default:
1579
+ rb_raise(rb_eTypeError, "Cannot convert type. Must be STRING, FIXNUM, BIGNUM, FLOAT, or NIL");
1580
+ break;
1581
+ }
1582
+ }
1583
+ else
1584
+ {
1585
+ switch (s_bind->value.type)
1586
+ {
1587
+ case A_STRING:
1588
+ s_bind->value.buffer = malloc(s_bind->value.buffer_size);
1589
+ break;
1590
+ case A_DOUBLE:
1591
+ s_bind->value.buffer = malloc(sizeof(float));
1592
+ break;
1593
+ case A_VAL64:
1594
+ case A_UVAL64:
1595
+ s_bind->value.buffer = malloc(sizeof(LONG_LONG));
1596
+ break;
1597
+ case A_VAL32:
1598
+ case A_UVAL32:
1599
+ s_bind->value.buffer = malloc(sizeof(int));
1600
+ break;
1601
+ case A_VAL16:
1602
+ case A_UVAL16:
1603
+ s_bind->value.buffer = malloc(sizeof(short));
1604
+ break;
1605
+ case A_VAL8:
1606
+ case A_UVAL8:
1607
+ s_bind->value.buffer = malloc(sizeof(char));
1608
+ break;
1609
+ default:
1610
+ rb_raise(rb_eTypeError, "Type unknown");
1611
+ break;
1612
+ }
1613
+ }
1614
+ return (Qnil);
1615
+ }
1616
+
1617
+ /*
1618
+ * call-seq:
1619
+ * set_direction( VALUE bind, VALUE direction ) -> nil
1620
+ *
1621
+ * Sets the direction of the bound parameter before binding.
1622
+ *
1623
+ * <b>Parameters</b>:
1624
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1625
+ * - <tt>VALUE direction</tt> -- The direction of the binding variable.
1626
+ *
1627
+ * <b>Returns</b>:
1628
+ * - <tt>nil</tt>.
1629
+ *
1630
+ */
1631
+ static VALUE
1632
+ static_Bind_set_direction(VALUE bind, VALUE direction)
1633
+ {
1634
+ a_ads_bind_param *s_bind;
1635
+
1636
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1637
+
1638
+ s_bind->direction = NUM2CHR(direction);
1639
+
1640
+ return (Qnil);
1641
+ }
1642
+
1643
+ /*
1644
+ * call-seq:
1645
+ * set_buffer_size( VALUE bind, VALUE size ) -> nil
1646
+ *
1647
+ * Sets the buffer size of INOUT and OUT parameters for string and binary
1648
+ * data.
1649
+ *
1650
+ * <b>Parameters</b>:
1651
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1652
+ * - <tt>VALUE size</tt> -- The size of the buffer to hold the INOUT or OUT parameter.
1653
+ *
1654
+ * <b>Returns</b>:
1655
+ * - <tt>nil</tt>.
1656
+ *
1657
+ */
1658
+ static VALUE
1659
+ static_Bind_set_buffer_size(VALUE bind, VALUE size)
1660
+ {
1661
+ a_ads_bind_param *s_bind;
1662
+
1663
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1664
+
1665
+ s_bind->value.buffer_size = NUM2INT(size);
1666
+
1667
+ return (Qnil);
1668
+ }
1669
+
1670
+ /*
1671
+ * call-seq:
1672
+ * get_direction( VALUE bind ) -> VALUE direction
1673
+ *
1674
+ * Gets the direction of the bound parameter.
1675
+ *
1676
+ * <b>Parameters</b>:
1677
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1678
+ *
1679
+ * <b>Returns</b>:
1680
+ * - <tt>VALUE name</tt>: The direction of the bound parameter.
1681
+ *
1682
+ */
1683
+ static VALUE
1684
+ static_Bind_get_direction(VALUE bind)
1685
+ {
1686
+ a_ads_bind_param *s_bind;
1687
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1688
+
1689
+ return (CHR2FIX(s_bind->direction));
1690
+ }
1691
+
1692
+ /*
1693
+ * call-seq:
1694
+ * finish( VALUE bind ) -> nil
1695
+ *
1696
+ * Frees the resources associated with the bound parameter.
1697
+ *
1698
+ * <b>Parameters</b>:
1699
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1700
+ *
1701
+ * <b>Returns</b>:
1702
+ * - <tt>nil</tt>.
1703
+ *
1704
+ */
1705
+ static VALUE
1706
+ static_Bind_finish(VALUE bind)
1707
+ {
1708
+ a_ads_bind_param *s_bind;
1709
+
1710
+ Data_Get_Struct(bind, a_ads_bind_param, s_bind);
1711
+
1712
+ // FIXME: use Ruby's allocation routines?
1713
+ if (s_bind)
1714
+ {
1715
+ free(s_bind);
1716
+ };
1717
+
1718
+ return (Qnil);
1719
+ }
1720
+
1721
+ /*
1722
+ * call-seq:
1723
+ * get_info_direction( VALUE bind ) -> VALUE direction
1724
+ *
1725
+ * Gets the name of the bound parameter info object.
1726
+ *
1727
+ * <b>Parameters</b>:
1728
+ * - <tt>VALUE bind</tt> -- Bound parameter info retrieved from ads_describe_bind_param_info( ).
1729
+ *
1730
+ * <b>Returns</b>:
1731
+ * - <tt>VALUE direction</tt>: The bound variable's direction.
1732
+ *
1733
+ */
1734
+ static VALUE
1735
+ static_Bind_get_info_direction(VALUE bind)
1736
+ {
1737
+ a_ads_bind_param_info *s_bind;
1738
+ Data_Get_Struct(bind, a_ads_bind_param_info, s_bind);
1739
+
1740
+ return (CHR2FIX(s_bind->direction));
1741
+ }
1742
+
1743
+ /*
1744
+ * call-seq:
1745
+ * get_info_output( VALUE bind ) -> VALUE name
1746
+ *
1747
+ * Gets the value of a bound parameter after execution.
1748
+ *
1749
+ * <b>Parameters</b>:
1750
+ * - <tt>VALUE bind</tt> -- Bound parameter retrieved from ads_describe_bind_param( ).
1751
+ *
1752
+ * <b>Returns</b>:
1753
+ * - <tt>VALUE name</tt>: The bound variable value.
1754
+ *
1755
+ */
1756
+ static VALUE
1757
+ static_Bind_get_info_output(VALUE bind)
1758
+ {
1759
+ a_ads_bind_param_info *s_bind;
1760
+ Data_Get_Struct(bind, a_ads_bind_param_info, s_bind);
1761
+ return (C2RB(&s_bind->output_value));
1762
+ }
1763
+
1764
+ /*
1765
+ *
1766
+ */
1767
+ void Init_advantage()
1768
+ {
1769
+ // Define top leve 'Advantage' module
1770
+ mAdvantage = rb_define_module("Advantage");
1771
+
1772
+ // Define a sub-module name 'API' under Advantage.
1773
+ // In Ruby, this is accessed as Advantage::API
1774
+ mAPI = rb_define_module_under(mAdvantage, "API");
1775
+
1776
+ // Define ads interface functions
1777
+ rb_define_module_function(mAPI, "ads_initialize_interface", static_API_ads_initialize_interface, 1);
1778
+ rb_define_module_function(mAPI, "ads_finalize_interface", static_API_ads_finalize_interface, 1);
1779
+ rb_define_const(mAPI, "VERSION", rb_str_new2(VERSION));
1780
+
1781
+ // Define interface classes under the Advantage module
1782
+ cAdvantageInterface = rb_define_class_under(mAdvantage, "AdvantageInterface", rb_cObject);
1783
+ rb_define_alloc_func(cAdvantageInterface, static_AdvantageInterface_alloc);
1784
+
1785
+ // Define all of the DBCAPI functions as methods under an interface instance
1786
+ rb_define_method(cAdvantageInterface, "ads_init", static_AdvantageInterface_ads_init, 0);
1787
+ rb_define_method(cAdvantageInterface, "ads_new_connection", static_AdvantageInterface_ads_new_connection, 0);
1788
+ rb_define_method(cAdvantageInterface, "ads_client_version", static_AdvantageInterface_ads_client_version, 0);
1789
+ rb_define_method(cAdvantageInterface, "ads_connect", static_AdvantageInterface_ads_connect, 2);
1790
+ rb_define_method(cAdvantageInterface, "ads_disconnect", static_AdvantageInterface_ads_disconnect, 1);
1791
+ rb_define_method(cAdvantageInterface, "ads_free_connection", static_AdvantageInterface_ads_free_connection, 1);
1792
+ rb_define_method(cAdvantageInterface, "ads_fini", static_AdvantageInterface_ads_fini, 0);
1793
+ rb_define_method(cAdvantageInterface, "ads_error", static_AdvantageInterface_ads_error, 1);
1794
+ rb_define_method(cAdvantageInterface, "ads_execute_immediate", static_AdvantageInterface_ads_execute_immediate, 2);
1795
+ rb_define_method(cAdvantageInterface, "ads_execute_direct", static_AdvantageInterface_ads_execute_direct, 2);
1796
+ rb_define_method(cAdvantageInterface, "ads_num_cols", static_AdvantageInterface_ads_num_cols, 1);
1797
+ rb_define_method(cAdvantageInterface, "ads_num_rows", static_AdvantageInterface_ads_num_rows, 1);
1798
+ rb_define_method(cAdvantageInterface, "ads_get_column", static_AdvantageInterface_ads_get_column, 2);
1799
+ rb_define_method(cAdvantageInterface, "ads_fetch_next", static_AdvantageInterface_ads_fetch_next, 1);
1800
+ rb_define_method(cAdvantageInterface, "ads_get_column_info", static_AdvantageInterface_ads_get_column_info, 2);
1801
+ rb_define_method(cAdvantageInterface, "AdsBeginTransaction", static_AdvantageInterface_AdsBeginTransaction, 1);
1802
+ rb_define_method(cAdvantageInterface, "ads_commit", static_AdvantageInterface_ads_commit, 1);
1803
+ rb_define_method(cAdvantageInterface, "ads_rollback", static_AdvantageInterface_ads_rollback, 1);
1804
+ rb_define_method(cAdvantageInterface, "ads_prepare", static_AdvantageInterface_ads_prepare, 2);
1805
+ rb_define_method(cAdvantageInterface, "ads_free_stmt", static_AdvantageInterface_ads_free_stmt, 1);
1806
+ rb_define_method(cAdvantageInterface, "ads_reset", static_AdvantageInterface_ads_reset, 1);
1807
+ rb_define_method(cAdvantageInterface, "ads_execute", static_AdvantageInterface_ads_execute, 1);
1808
+ rb_define_method(cAdvantageInterface, "ads_affected_rows", static_AdvantageInterface_ads_affected_rows, 1);
1809
+ rb_define_method(cAdvantageInterface, "ads_describe_bind_param", static_AdvantageInterface_ads_describe_bind_param, 2);
1810
+ rb_define_method(cAdvantageInterface, "ads_bind_param", static_AdvantageInterface_ads_bind_param, 3);
1811
+ rb_define_method(cAdvantageInterface, "ads_get_bind_param_info", static_AdvantageInterface_ads_get_bind_param_info, 2);
1812
+ rb_define_method(cAdvantageInterface, "ads_num_params", static_AdvantageInterface_ads_num_params, 1);
1813
+ rb_define_method(cAdvantageInterface, "ads_get_next_result", static_AdvantageInterface_ads_get_next_result, 1);
1814
+ rb_define_method(cAdvantageInterface, "ads_fetch_absolute", static_AdvantageInterface_ads_fetch_absolute, 2);
1815
+ rb_define_method(cAdvantageInterface, "ads_sqlstate", static_AdvantageInterface_ads_sqlstate, 1);
1816
+ rb_define_method(cAdvantageInterface, "ads_clear_error", static_AdvantageInterface_ads_clear_error, 1);
1817
+
1818
+ // Define classes for accessing structures under Advantage module
1819
+ cA_ads_connection = rb_define_class_under(mAdvantage, "a_ads_connection", rb_cObject);
1820
+ cA_ads_data_value = rb_define_class_under(mAdvantage, "a_ads_data_value", rb_cObject);
1821
+ //cA_ads_stmt = rb_define_class_under ( mAdvantage, "ADSHANDLE", rb_cObject );
1822
+ cA_ads_bind_param = rb_define_class_under(mAdvantage, "a_ads_bind_param", rb_cObject);
1823
+ cA_ads_bind_param_info = rb_define_class_under(mAdvantage, "a_ads_bind_param_info", rb_cObject);
1824
+
1825
+ // Define methods for obtaining bind_parameter fields
1826
+ rb_define_method(cA_ads_bind_param, "get_name", static_Bind_get_name, 0);
1827
+ rb_define_method(cA_ads_bind_param, "set_value", static_Bind_set_value, 1);
1828
+ rb_define_method(cA_ads_bind_param, "get_direction", static_Bind_get_direction, 0);
1829
+ rb_define_method(cA_ads_bind_param, "set_direction", static_Bind_set_direction, 1);
1830
+ rb_define_method(cA_ads_bind_param, "set_buffer_size", static_Bind_set_buffer_size, 1);
1831
+ rb_define_method(cA_ads_bind_param, "finish", static_Bind_finish, 0);
1832
+
1833
+ // Define methods for obtaining bind_parameter_info fields
1834
+ rb_define_method(cA_ads_bind_param_info, "get_direction", static_Bind_get_info_direction, 0);
1835
+ rb_define_method(cA_ads_bind_param_info, "get_output", static_Bind_get_info_output, 0);
1836
+ }