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

Sign up to get free protection for your applications and to get access to all the features.
data/ext/sacapidll.c CHANGED
@@ -1,167 +1,167 @@
1
- //====================================================
2
- //
3
- // Copyright 2008-2009 iAnywhere Solutions, Inc.
4
- //
5
- // Licensed under the Apache License, Version 2.0 (the "License");
6
- // you may not use this file except in compliance with the License.
7
- // You may obtain a copy of the License at
8
- //
9
- // 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( __APPLE__ )
34
- #define LIB_EXT "dylib"
35
- #else
36
- #define LIB_EXT "so"
37
- #endif
38
- #if defined( _REENTRANT ) || defined( _THREAD_SAFE ) \
39
- || defined( __USE_REENTRANT )
40
- /* if building a thread-safe library, we need to load
41
- the thread-safe dbcapi library */
42
- #define DEFAULT_LIBRARY_NAME "libdbcapi_r." LIB_EXT
43
- #else
44
- #define DEFAULT_LIBRARY_NAME "libdbcapi." LIB_EXT
45
- #endif
46
- #endif
47
-
48
- #include "sacapidll.h"
49
-
50
- static
51
- void * loadLibrary( const char * name )
52
- /*************************************/
53
- {
54
- void * handle;
55
- #if defined( _WIN32 )
56
- handle = LoadLibrary( name );
57
- #else
58
- handle = dlopen( name, RTLD_LAZY );
59
- #endif
60
- return handle;
61
- }
62
-
63
- static
64
- void unloadLibrary( void * handle )
65
- /**********************************/
66
- {
67
- #if defined( _WIN32 )
68
- FreeLibrary( handle );
69
- #else
70
- dlclose( handle );
71
- #endif
72
- }
73
-
74
- static
75
- void * findSymbol( void * dll_handle, char * name )
76
- /**************************************************/
77
- {
78
- #if defined( _WIN32 )
79
- return GetProcAddress( dll_handle, name );
80
- #else
81
- return dlsym( dll_handle, name );
82
- #endif
83
- }
84
-
85
- #define LookupSymbolAndCheck( api, sym ) \
86
- api->sym = (sym ## _func)findSymbol( api->dll_handle, #sym ); \
87
- if( api->sym == NULL ) { \
88
- unloadLibrary( api->dll_handle ); \
89
- return 0; \
90
- }
91
-
92
- int sqlany_initialize_interface( SQLAnywhereInterface * api, const char * path )
93
- /*******************************************************************************/
94
- {
95
- char * env;
96
- memset( api, 0, sizeof(*api));
97
-
98
- if( path != NULL ) {
99
- api->dll_handle = loadLibrary( path );
100
- if( api->dll_handle != NULL ) {
101
- goto loaded;
102
- }
103
- }
104
- env = getenv( "SQLANY_API_DLL" );
105
- if( env != NULL ) {
106
- api->dll_handle = loadLibrary( env );
107
- if( api->dll_handle != NULL ) {
108
- goto loaded;
109
- }
110
- }
111
- api->dll_handle = loadLibrary( DEFAULT_LIBRARY_NAME );
112
- if( api->dll_handle != NULL ) {
113
- goto loaded;
114
- }
115
- return 0;
116
-
117
- loaded:
118
- LookupSymbolAndCheck( api, sqlany_init );
119
- LookupSymbolAndCheck( api, sqlany_fini );
120
- LookupSymbolAndCheck( api, sqlany_new_connection );
121
- LookupSymbolAndCheck( api, sqlany_free_connection );
122
- LookupSymbolAndCheck( api, sqlany_make_connection );
123
- LookupSymbolAndCheck( api, sqlany_connect );
124
- LookupSymbolAndCheck( api, sqlany_disconnect );
125
- LookupSymbolAndCheck( api, sqlany_execute_immediate );
126
- LookupSymbolAndCheck( api, sqlany_prepare );
127
- LookupSymbolAndCheck( api, sqlany_free_stmt );
128
- LookupSymbolAndCheck( api, sqlany_num_params );
129
- LookupSymbolAndCheck( api, sqlany_describe_bind_param );
130
- LookupSymbolAndCheck( api, sqlany_bind_param );
131
- LookupSymbolAndCheck( api, sqlany_send_param_data );
132
- LookupSymbolAndCheck( api, sqlany_reset );
133
- LookupSymbolAndCheck( api, sqlany_get_bind_param_info );
134
- LookupSymbolAndCheck( api, sqlany_execute );
135
- LookupSymbolAndCheck( api, sqlany_execute_direct );
136
- LookupSymbolAndCheck( api, sqlany_fetch_absolute );
137
- LookupSymbolAndCheck( api, sqlany_fetch_next );
138
- LookupSymbolAndCheck( api, sqlany_get_next_result );
139
- LookupSymbolAndCheck( api, sqlany_affected_rows );
140
- LookupSymbolAndCheck( api, sqlany_num_cols );
141
- LookupSymbolAndCheck( api, sqlany_num_rows );
142
- LookupSymbolAndCheck( api, sqlany_get_column );
143
- LookupSymbolAndCheck( api, sqlany_get_data );
144
- LookupSymbolAndCheck( api, sqlany_get_data_info );
145
- LookupSymbolAndCheck( api, sqlany_get_column_info );
146
- LookupSymbolAndCheck( api, sqlany_commit );
147
- LookupSymbolAndCheck( api, sqlany_rollback );
148
- LookupSymbolAndCheck( api, sqlany_client_version );
149
- LookupSymbolAndCheck( api, sqlany_error );
150
- LookupSymbolAndCheck( api, sqlany_sqlstate );
151
- LookupSymbolAndCheck( api, sqlany_clear_error );
152
- api->initialized = 1;
153
- return 1;
154
- }
155
- #undef LookupSymbolAndCheck
156
-
157
- void sqlany_finalize_interface( SQLAnywhereInterface * api )
158
- /***********************************************************/
159
- {
160
- if( !api->initialized ) {
161
- return;
162
- }
163
- unloadLibrary( api->dll_handle );
164
- memset( api, 0, sizeof(*api));
165
- }
166
-
167
-
1
+ //====================================================
2
+ //
3
+ // Copyright 2008-2009 iAnywhere Solutions, Inc.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // 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( __APPLE__ )
34
+ #define LIB_EXT "dylib"
35
+ #else
36
+ #define LIB_EXT "so"
37
+ #endif
38
+ #if defined( _REENTRANT ) || defined( _THREAD_SAFE ) \
39
+ || defined( __USE_REENTRANT )
40
+ /* if building a thread-safe library, we need to load
41
+ the thread-safe dbcapi library */
42
+ #define DEFAULT_LIBRARY_NAME "libdbcapi_r." LIB_EXT
43
+ #else
44
+ #define DEFAULT_LIBRARY_NAME "libdbcapi." LIB_EXT
45
+ #endif
46
+ #endif
47
+
48
+ #include "sacapidll.h"
49
+
50
+ static
51
+ void * loadLibrary( const char * name )
52
+ /*************************************/
53
+ {
54
+ void * handle;
55
+ #if defined( _WIN32 )
56
+ handle = LoadLibrary( name );
57
+ #else
58
+ handle = dlopen( name, RTLD_LAZY );
59
+ #endif
60
+ return handle;
61
+ }
62
+
63
+ static
64
+ void unloadLibrary( void * handle )
65
+ /**********************************/
66
+ {
67
+ #if defined( _WIN32 )
68
+ FreeLibrary( handle );
69
+ #else
70
+ dlclose( handle );
71
+ #endif
72
+ }
73
+
74
+ static
75
+ void * findSymbol( void * dll_handle, char * name )
76
+ /**************************************************/
77
+ {
78
+ #if defined( _WIN32 )
79
+ return GetProcAddress( dll_handle, name );
80
+ #else
81
+ return dlsym( dll_handle, name );
82
+ #endif
83
+ }
84
+
85
+ #define LookupSymbolAndCheck( api, sym ) \
86
+ api->sym = (sym ## _func)findSymbol( api->dll_handle, #sym ); \
87
+ if( api->sym == NULL ) { \
88
+ unloadLibrary( api->dll_handle ); \
89
+ return 0; \
90
+ }
91
+
92
+ int sqlany_initialize_interface( SQLAnywhereInterface * api, const char * path )
93
+ /*******************************************************************************/
94
+ {
95
+ char * env;
96
+ memset( api, 0, sizeof(*api));
97
+
98
+ if( path != NULL ) {
99
+ api->dll_handle = loadLibrary( path );
100
+ if( api->dll_handle != NULL ) {
101
+ goto loaded;
102
+ }
103
+ }
104
+ env = getenv( "SQLANY_API_DLL" );
105
+ if( env != NULL ) {
106
+ api->dll_handle = loadLibrary( env );
107
+ if( api->dll_handle != NULL ) {
108
+ goto loaded;
109
+ }
110
+ }
111
+ api->dll_handle = loadLibrary( DEFAULT_LIBRARY_NAME );
112
+ if( api->dll_handle != NULL ) {
113
+ goto loaded;
114
+ }
115
+ return 0;
116
+
117
+ loaded:
118
+ LookupSymbolAndCheck( api, sqlany_init );
119
+ LookupSymbolAndCheck( api, sqlany_fini );
120
+ LookupSymbolAndCheck( api, sqlany_new_connection );
121
+ LookupSymbolAndCheck( api, sqlany_free_connection );
122
+ LookupSymbolAndCheck( api, sqlany_make_connection );
123
+ LookupSymbolAndCheck( api, sqlany_connect );
124
+ LookupSymbolAndCheck( api, sqlany_disconnect );
125
+ LookupSymbolAndCheck( api, sqlany_execute_immediate );
126
+ LookupSymbolAndCheck( api, sqlany_prepare );
127
+ LookupSymbolAndCheck( api, sqlany_free_stmt );
128
+ LookupSymbolAndCheck( api, sqlany_num_params );
129
+ LookupSymbolAndCheck( api, sqlany_describe_bind_param );
130
+ LookupSymbolAndCheck( api, sqlany_bind_param );
131
+ LookupSymbolAndCheck( api, sqlany_send_param_data );
132
+ LookupSymbolAndCheck( api, sqlany_reset );
133
+ LookupSymbolAndCheck( api, sqlany_get_bind_param_info );
134
+ LookupSymbolAndCheck( api, sqlany_execute );
135
+ LookupSymbolAndCheck( api, sqlany_execute_direct );
136
+ LookupSymbolAndCheck( api, sqlany_fetch_absolute );
137
+ LookupSymbolAndCheck( api, sqlany_fetch_next );
138
+ LookupSymbolAndCheck( api, sqlany_get_next_result );
139
+ LookupSymbolAndCheck( api, sqlany_affected_rows );
140
+ LookupSymbolAndCheck( api, sqlany_num_cols );
141
+ LookupSymbolAndCheck( api, sqlany_num_rows );
142
+ LookupSymbolAndCheck( api, sqlany_get_column );
143
+ LookupSymbolAndCheck( api, sqlany_get_data );
144
+ LookupSymbolAndCheck( api, sqlany_get_data_info );
145
+ LookupSymbolAndCheck( api, sqlany_get_column_info );
146
+ LookupSymbolAndCheck( api, sqlany_commit );
147
+ LookupSymbolAndCheck( api, sqlany_rollback );
148
+ LookupSymbolAndCheck( api, sqlany_client_version );
149
+ LookupSymbolAndCheck( api, sqlany_error );
150
+ LookupSymbolAndCheck( api, sqlany_sqlstate );
151
+ LookupSymbolAndCheck( api, sqlany_clear_error );
152
+ api->initialized = 1;
153
+ return 1;
154
+ }
155
+ #undef LookupSymbolAndCheck
156
+
157
+ void sqlany_finalize_interface( SQLAnywhereInterface * api )
158
+ /***********************************************************/
159
+ {
160
+ if( !api->initialized ) {
161
+ return;
162
+ }
163
+ unloadLibrary( api->dll_handle );
164
+ memset( api, 0, sizeof(*api));
165
+ }
166
+
167
+
data/ext/sacapidll.h CHANGED
@@ -1,253 +1,253 @@
1
- /* ====================================================
2
- *
3
- * Copyright 2008-2009 iAnywhere Solutions, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * 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
1
+ /* ====================================================
2
+ *
3
+ * Copyright 2008-2009 iAnywhere Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * 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