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