sqlanywhere 0.1.0-i386-mswin32 → 0.1.1-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -1
- data/README +5 -1
- data/Rakefile +207 -0
- data/ext/Makefile +180 -0
- data/ext/extconf.rb +30 -0
- data/ext/sacapi.h +679 -0
- data/ext/sacapidll.c +162 -0
- data/ext/sacapidll.h +253 -0
- data/ext/sacapidll.obj +0 -0
- data/ext/sqlanywhere-i386-mswin32.def +2 -0
- data/ext/sqlanywhere-i386-mswin32.exp +0 -0
- data/ext/sqlanywhere-i386-mswin32.lib +0 -0
- data/ext/sqlanywhere-i386-mswin32.pdb +0 -0
- data/ext/sqlanywhere.c +200 -176
- data/ext/sqlanywhere.obj +0 -0
- data/ext/sqlanywhere.so +0 -0
- data/ext/vc60.pdb +0 -0
- data/lib/sqlanywhere.so +0 -0
- data/test/sqlanywhere_test.rb +1 -0
- metadata +20 -6
data/ext/sacapidll.c
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
//====================================================
|
2
|
+
//
|
3
|
+
// Copyright 2008 iAnywhere Solutions, Inc.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// 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
|
+
// While not a requirement of the license, if you do modify this file, we
|
19
|
+
// would appreciate hearing about it. Please email
|
20
|
+
// sqlany_interfaces@sybase.com
|
21
|
+
//
|
22
|
+
//====================================================
|
23
|
+
#include <string.h>
|
24
|
+
#include <stdlib.h>
|
25
|
+
#include <stdio.h>
|
26
|
+
|
27
|
+
#if defined( _WIN32 )
|
28
|
+
#include <windows.h>
|
29
|
+
#define DEFAULT_LIBRARY_NAME "dbcapi.dll"
|
30
|
+
#else
|
31
|
+
#include <dlfcn.h>
|
32
|
+
/* assume we are running on a UNIX platform */
|
33
|
+
#if defined( _REENTRANT ) || defined( _THREAD_SAFE ) \
|
34
|
+
|| defined( __USE_REENTRANT )
|
35
|
+
/* if building a thread-safe library, we need to load
|
36
|
+
the thread-safe dbcapi library */
|
37
|
+
#define DEFAULT_LIBRARY_NAME "libdbcapi_r.so"
|
38
|
+
#else
|
39
|
+
#define DEFAULT_LIBRARY_NAME "libdbcapi.so"
|
40
|
+
#endif
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#include "sacapidll.h"
|
44
|
+
|
45
|
+
static
|
46
|
+
void * loadLibrary( const char * name )
|
47
|
+
/*************************************/
|
48
|
+
{
|
49
|
+
void * handle;
|
50
|
+
#if defined( _WIN32 )
|
51
|
+
handle = LoadLibrary( name );
|
52
|
+
#else
|
53
|
+
handle = dlopen( name, RTLD_LAZY );
|
54
|
+
#endif
|
55
|
+
return handle;
|
56
|
+
}
|
57
|
+
|
58
|
+
static
|
59
|
+
void unloadLibrary( void * handle )
|
60
|
+
/**********************************/
|
61
|
+
{
|
62
|
+
#if defined( _WIN32 )
|
63
|
+
FreeLibrary( handle );
|
64
|
+
#else
|
65
|
+
dlclose( handle );
|
66
|
+
#endif
|
67
|
+
}
|
68
|
+
|
69
|
+
static
|
70
|
+
void * findSymbol( void * dll_handle, char * name )
|
71
|
+
/**************************************************/
|
72
|
+
{
|
73
|
+
#if defined( _WIN32 )
|
74
|
+
return GetProcAddress( dll_handle, name );
|
75
|
+
#else
|
76
|
+
return dlsym( dll_handle, name );
|
77
|
+
#endif
|
78
|
+
}
|
79
|
+
|
80
|
+
#define LookupSymbolAndCheck( api, sym ) \
|
81
|
+
api->sym = (sym ## _func)findSymbol( api->dll_handle, #sym ); \
|
82
|
+
if( api->sym == NULL ) { \
|
83
|
+
unloadLibrary( api->dll_handle ); \
|
84
|
+
return 0; \
|
85
|
+
}
|
86
|
+
|
87
|
+
int sqlany_initialize_interface( SQLAnywhereInterface * api, const char * path )
|
88
|
+
/*******************************************************************************/
|
89
|
+
{
|
90
|
+
char * env;
|
91
|
+
memset( api, 0, sizeof(*api));
|
92
|
+
|
93
|
+
if( path != NULL ) {
|
94
|
+
api->dll_handle = loadLibrary( path );
|
95
|
+
if( api->dll_handle != NULL ) {
|
96
|
+
goto loaded;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
env = getenv( "SQLANY_API_DLL" );
|
100
|
+
if( env != NULL ) {
|
101
|
+
api->dll_handle = loadLibrary( env );
|
102
|
+
if( api->dll_handle != NULL ) {
|
103
|
+
goto loaded;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
api->dll_handle = loadLibrary( DEFAULT_LIBRARY_NAME );
|
107
|
+
if( api->dll_handle != NULL ) {
|
108
|
+
goto loaded;
|
109
|
+
}
|
110
|
+
return 0;
|
111
|
+
|
112
|
+
loaded:
|
113
|
+
LookupSymbolAndCheck( api, sqlany_init );
|
114
|
+
LookupSymbolAndCheck( api, sqlany_fini );
|
115
|
+
LookupSymbolAndCheck( api, sqlany_new_connection );
|
116
|
+
LookupSymbolAndCheck( api, sqlany_free_connection );
|
117
|
+
LookupSymbolAndCheck( api, sqlany_make_connection );
|
118
|
+
LookupSymbolAndCheck( api, sqlany_connect );
|
119
|
+
LookupSymbolAndCheck( api, sqlany_disconnect );
|
120
|
+
LookupSymbolAndCheck( api, sqlany_execute_immediate );
|
121
|
+
LookupSymbolAndCheck( api, sqlany_prepare );
|
122
|
+
LookupSymbolAndCheck( api, sqlany_free_stmt );
|
123
|
+
LookupSymbolAndCheck( api, sqlany_num_params );
|
124
|
+
LookupSymbolAndCheck( api, sqlany_describe_bind_param );
|
125
|
+
LookupSymbolAndCheck( api, sqlany_bind_param );
|
126
|
+
LookupSymbolAndCheck( api, sqlany_send_param_data );
|
127
|
+
LookupSymbolAndCheck( api, sqlany_reset );
|
128
|
+
LookupSymbolAndCheck( api, sqlany_get_bind_param_info );
|
129
|
+
LookupSymbolAndCheck( api, sqlany_execute );
|
130
|
+
LookupSymbolAndCheck( api, sqlany_execute_direct );
|
131
|
+
LookupSymbolAndCheck( api, sqlany_fetch_absolute );
|
132
|
+
LookupSymbolAndCheck( api, sqlany_fetch_next );
|
133
|
+
LookupSymbolAndCheck( api, sqlany_get_next_result );
|
134
|
+
LookupSymbolAndCheck( api, sqlany_affected_rows );
|
135
|
+
LookupSymbolAndCheck( api, sqlany_num_cols );
|
136
|
+
LookupSymbolAndCheck( api, sqlany_num_rows );
|
137
|
+
LookupSymbolAndCheck( api, sqlany_get_column );
|
138
|
+
LookupSymbolAndCheck( api, sqlany_get_data );
|
139
|
+
LookupSymbolAndCheck( api, sqlany_get_data_info );
|
140
|
+
LookupSymbolAndCheck( api, sqlany_get_column_info );
|
141
|
+
LookupSymbolAndCheck( api, sqlany_commit );
|
142
|
+
LookupSymbolAndCheck( api, sqlany_rollback );
|
143
|
+
LookupSymbolAndCheck( api, sqlany_client_version );
|
144
|
+
LookupSymbolAndCheck( api, sqlany_error );
|
145
|
+
LookupSymbolAndCheck( api, sqlany_sqlstate );
|
146
|
+
LookupSymbolAndCheck( api, sqlany_clear_error );
|
147
|
+
api->initialized = 1;
|
148
|
+
return 1;
|
149
|
+
}
|
150
|
+
#undef LookupSymbolAndCheck
|
151
|
+
|
152
|
+
void sqlany_finalize_interface( SQLAnywhereInterface * api )
|
153
|
+
/***********************************************************/
|
154
|
+
{
|
155
|
+
if( !api->initialized ) {
|
156
|
+
return;
|
157
|
+
}
|
158
|
+
unloadLibrary( api->dll_handle );
|
159
|
+
memset( api, 0, sizeof(*api));
|
160
|
+
}
|
161
|
+
|
162
|
+
|
data/ext/sacapidll.h
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
/* ====================================================
|
2
|
+
*
|
3
|
+
* Copyright 2008 iAnywhere Solutions, Inc.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* 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
|
+
* While not a requirement of the license, if you do modify this file, we
|
19
|
+
* would appreciate hearing about it. Please email
|
20
|
+
* sqlany_interfaces@sybase.com
|
21
|
+
*
|
22
|
+
* ====================================================
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifndef SACAPIDLL_H
|
26
|
+
#define SACAPIDLL_H
|
27
|
+
|
28
|
+
#include "sacapi.h"
|
29
|
+
|
30
|
+
/** \file sacapidll.h
|
31
|
+
* \brief Header file for stub that can dynamically load the main API DLL.
|
32
|
+
* The user will need to include sacapidll.h in their source files and compile in sacapidll.c
|
33
|
+
*/
|
34
|
+
|
35
|
+
|
36
|
+
#if defined( __cplusplus )
|
37
|
+
extern "C" {
|
38
|
+
#endif
|
39
|
+
typedef sacapi_bool (*sqlany_init_func)( const char * app_name, sacapi_u32 api_version, sacapi_u32 * max_version );
|
40
|
+
typedef void (*sqlany_fini_func)();
|
41
|
+
typedef a_sqlany_connection * (*sqlany_new_connection_func)( );
|
42
|
+
typedef void (*sqlany_free_connection_func)( a_sqlany_connection *sqlany_conn );
|
43
|
+
typedef a_sqlany_connection * (*sqlany_make_connection_func)( void * arg );
|
44
|
+
typedef sacapi_bool (*sqlany_connect_func)( a_sqlany_connection * sqlany_conn, const char * str );
|
45
|
+
typedef sacapi_bool (*sqlany_disconnect_func)( a_sqlany_connection * sqlany_conn );
|
46
|
+
typedef sacapi_bool (*sqlany_execute_immediate_func)( a_sqlany_connection * sqlany_conn, const char * sql );
|
47
|
+
typedef a_sqlany_stmt * (*sqlany_prepare_func)( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
48
|
+
typedef void (*sqlany_free_stmt_func)( a_sqlany_stmt * sqlany_stmt );
|
49
|
+
typedef sacapi_i32 (*sqlany_num_params_func)( a_sqlany_stmt * sqlany_stmt );
|
50
|
+
typedef sacapi_bool (*sqlany_describe_bind_param_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * params );
|
51
|
+
typedef sacapi_bool (*sqlany_bind_param_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * params );
|
52
|
+
typedef sacapi_bool (*sqlany_send_param_data_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, char * buffer, size_t size );
|
53
|
+
typedef sacapi_bool (*sqlany_reset_func)( a_sqlany_stmt * sqlany_stmt );
|
54
|
+
typedef sacapi_bool (*sqlany_get_bind_param_info_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param_info * info );
|
55
|
+
typedef sacapi_bool (*sqlany_execute_func)( a_sqlany_stmt * sqlany_stmt );
|
56
|
+
typedef a_sqlany_stmt * (*sqlany_execute_direct_func)( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
57
|
+
typedef sacapi_bool (*sqlany_fetch_absolute_func)( a_sqlany_stmt * sqlany_result, sacapi_i32 row_num );
|
58
|
+
typedef sacapi_bool (*sqlany_fetch_next_func)( a_sqlany_stmt * sqlany_stmt );
|
59
|
+
typedef sacapi_bool (*sqlany_get_next_result_func)( a_sqlany_stmt * sqlany_stmt );
|
60
|
+
typedef sacapi_i32 (*sqlany_affected_rows_func)( a_sqlany_stmt * sqlany_stmt );
|
61
|
+
typedef sacapi_i32 (*sqlany_num_cols_func)( a_sqlany_stmt * sqlany_stmt );
|
62
|
+
typedef sacapi_i32 (*sqlany_num_rows_func)( a_sqlany_stmt * sqlany_stmt );
|
63
|
+
typedef sacapi_bool (*sqlany_get_column_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_value * buffer );
|
64
|
+
typedef sacapi_i32 (*sqlany_get_data_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, size_t offset, void * buffer, size_t size );
|
65
|
+
typedef sacapi_bool (*sqlany_get_data_info_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_info * buffer );
|
66
|
+
typedef sacapi_bool (*sqlany_get_column_info_func)( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_column_info * buffer );
|
67
|
+
typedef sacapi_bool (*sqlany_commit_func)( a_sqlany_connection * sqlany_conn );
|
68
|
+
typedef sacapi_bool (*sqlany_rollback_func)( a_sqlany_connection * sqlany_conn );
|
69
|
+
typedef sacapi_bool (*sqlany_client_version_func)( char * buffer, size_t len );
|
70
|
+
typedef sacapi_i32 (*sqlany_error_func)( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
71
|
+
typedef size_t (*sqlany_sqlstate_func)( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
72
|
+
typedef void (*sqlany_clear_error_func)( a_sqlany_connection * sqlany_conn );
|
73
|
+
|
74
|
+
#if defined( __cplusplus )
|
75
|
+
}
|
76
|
+
#endif
|
77
|
+
|
78
|
+
#define function( x ) x ## _func x
|
79
|
+
/** An API interface structure.
|
80
|
+
* The user would need only one instance of this in their environment. When the
|
81
|
+
* instance is initialized, the DLL will be loaded and all the entry points will be looked up.
|
82
|
+
*/
|
83
|
+
typedef struct SQLAnywhereInterface {
|
84
|
+
/** DLL handle.
|
85
|
+
*/
|
86
|
+
void * dll_handle;
|
87
|
+
|
88
|
+
/** Flag to know if initialized or not.
|
89
|
+
*/
|
90
|
+
int initialized;
|
91
|
+
|
92
|
+
/** Pointer to ::sqlany_init() function.
|
93
|
+
*/
|
94
|
+
function( sqlany_init );
|
95
|
+
|
96
|
+
/** Pointer to ::sqlany_fini() function.
|
97
|
+
*/
|
98
|
+
function( sqlany_fini );
|
99
|
+
|
100
|
+
/** Pointer to ::sqlany_new_connection() function.
|
101
|
+
*/
|
102
|
+
function( sqlany_new_connection );
|
103
|
+
|
104
|
+
/** Pointer to ::sqlany_free_connection() function.
|
105
|
+
*/
|
106
|
+
function( sqlany_free_connection );
|
107
|
+
|
108
|
+
/** Pointer to ::sqlany_make_connection() function.
|
109
|
+
*/
|
110
|
+
function( sqlany_make_connection );
|
111
|
+
|
112
|
+
/** Pointer to ::sqlany_connect() function.
|
113
|
+
*/
|
114
|
+
function( sqlany_connect );
|
115
|
+
|
116
|
+
/** Pointer to ::sqlany_disconnect() function.
|
117
|
+
*/
|
118
|
+
function( sqlany_disconnect );
|
119
|
+
|
120
|
+
/** Pointer to ::sqlany_execute_immediate() function.
|
121
|
+
*/
|
122
|
+
function( sqlany_execute_immediate );
|
123
|
+
|
124
|
+
/** Pointer to ::sqlany_prepare() function.
|
125
|
+
*/
|
126
|
+
function( sqlany_prepare );
|
127
|
+
|
128
|
+
/** Pointer to ::sqlany_free_stmt() function.
|
129
|
+
*/
|
130
|
+
function( sqlany_free_stmt );
|
131
|
+
|
132
|
+
/** Pointer to ::sqlany_num_params() function.
|
133
|
+
*/
|
134
|
+
function( sqlany_num_params );
|
135
|
+
|
136
|
+
/** Pointer to ::sqlany_describe_bind_param() function.
|
137
|
+
*/
|
138
|
+
function( sqlany_describe_bind_param );
|
139
|
+
|
140
|
+
/** Pointer to ::sqlany_bind_param() function.
|
141
|
+
*/
|
142
|
+
function( sqlany_bind_param );
|
143
|
+
|
144
|
+
/** Pointer to ::sqlany_send_param_data() function.
|
145
|
+
*/
|
146
|
+
function( sqlany_send_param_data );
|
147
|
+
|
148
|
+
/** Pointer to ::sqlany_reset() function.
|
149
|
+
*/
|
150
|
+
function( sqlany_reset );
|
151
|
+
|
152
|
+
/** Pointer to ::sqlany_get_bind_param_info() function.
|
153
|
+
*/
|
154
|
+
function( sqlany_get_bind_param_info );
|
155
|
+
|
156
|
+
/** Pointer to ::sqlany_execute() function.
|
157
|
+
*/
|
158
|
+
function( sqlany_execute );
|
159
|
+
|
160
|
+
/** Pointer to ::sqlany_execute_direct() function.
|
161
|
+
*/
|
162
|
+
function( sqlany_execute_direct );
|
163
|
+
|
164
|
+
/** Pointer to ::sqlany_fetch_absolute() function.
|
165
|
+
*/
|
166
|
+
function( sqlany_fetch_absolute );
|
167
|
+
|
168
|
+
/** Pointer to ::sqlany_fetch_next() function.
|
169
|
+
*/
|
170
|
+
function( sqlany_fetch_next );
|
171
|
+
|
172
|
+
/** Pointer to ::sqlany_get_next_result() function.
|
173
|
+
*/
|
174
|
+
function( sqlany_get_next_result );
|
175
|
+
|
176
|
+
/** Pointer to ::sqlany_affected_rows() function.
|
177
|
+
*/
|
178
|
+
function( sqlany_affected_rows );
|
179
|
+
|
180
|
+
/** Pointer to ::sqlany_num_cols() function.
|
181
|
+
*/
|
182
|
+
function( sqlany_num_cols );
|
183
|
+
|
184
|
+
/** Pointer to ::sqlany_num_rows() function.
|
185
|
+
*/
|
186
|
+
function( sqlany_num_rows );
|
187
|
+
|
188
|
+
/** Pointer to ::sqlany_get_column() function.
|
189
|
+
*/
|
190
|
+
function( sqlany_get_column );
|
191
|
+
|
192
|
+
/** Pointer to ::sqlany_get_data() function.
|
193
|
+
*/
|
194
|
+
function( sqlany_get_data );
|
195
|
+
|
196
|
+
/** Pointer to ::sqlany_get_data_info() function.
|
197
|
+
*/
|
198
|
+
function( sqlany_get_data_info );
|
199
|
+
|
200
|
+
/** Pointer to ::sqlany_get_column_info() function.
|
201
|
+
*/
|
202
|
+
function( sqlany_get_column_info );
|
203
|
+
|
204
|
+
/** Pointer to ::sqlany_commit() function.
|
205
|
+
*/
|
206
|
+
function( sqlany_commit );
|
207
|
+
|
208
|
+
/** Pointer to ::sqlany_rollback() function.
|
209
|
+
*/
|
210
|
+
function( sqlany_rollback );
|
211
|
+
|
212
|
+
/** Pointer to ::sqlany_client_version() function.
|
213
|
+
*/
|
214
|
+
function( sqlany_client_version );
|
215
|
+
|
216
|
+
/** Pointer to ::sqlany_error() function.
|
217
|
+
*/
|
218
|
+
function( sqlany_error );
|
219
|
+
|
220
|
+
/** Pointer to ::sqlany_sqlstate() function.
|
221
|
+
*/
|
222
|
+
function( sqlany_sqlstate );
|
223
|
+
|
224
|
+
/** Pointer to ::sqlany_clear_error() function.
|
225
|
+
*/
|
226
|
+
function( sqlany_clear_error );
|
227
|
+
|
228
|
+
} SQLAnywhereInterface;
|
229
|
+
#undef function
|
230
|
+
|
231
|
+
/** Initializes the SQLAnywhereInterface object and loads the DLL dynamically.
|
232
|
+
* This function attempts to load the SQL Anywhere C API DLL dynamically and looks up all
|
233
|
+
* the entry points of the DLL. The fields in the SQLAnywhereInterface structure will be
|
234
|
+
* populated to point to the corresponding functions in the DLL. If the optional path argument
|
235
|
+
* is NULL, the environment variable SQLANY_DLL_PATH will be checked. If the variable is set,
|
236
|
+
* the library will attempt to load the DLL specified by the environment variable. If that fails,
|
237
|
+
* the interface will attempt to load the DLL directly (this relies on the environment being
|
238
|
+
* setup correctly).
|
239
|
+
* \param api An API structure to initialize.
|
240
|
+
* \param optional_path_to_dll An optional argument that specifies a path to the DLL API to load.
|
241
|
+
* \return 1 on successful initialization, and 0 on failure.
|
242
|
+
*/
|
243
|
+
int sqlany_initialize_interface( SQLAnywhereInterface * api, const char * optional_path_to_dll );
|
244
|
+
|
245
|
+
/** Finalize and free resources associated with the SQL Anywhere C API DLL.
|
246
|
+
* This function will unload the library and uninitialize the supplied SQLAnywhereInterface
|
247
|
+
* structure.
|
248
|
+
* \param api An initialized structure to finalize.
|
249
|
+
*/
|
250
|
+
|
251
|
+
void sqlany_finalize_interface( SQLAnywhereInterface * api );
|
252
|
+
|
253
|
+
#endif
|
data/ext/sacapidll.obj
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|