sqlanywhere 0.1.6-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/ext/extconf.rb ADDED
@@ -0,0 +1,30 @@
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
+ # While not a requirement of the license, if you do modify this file, we
20
+ # would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
+ #
22
+ #
23
+ #====================================================
24
+
25
+ require 'mkmf'
26
+
27
+ dir_config('SQLANY')
28
+
29
+ create_makefile("sqlanywhere")
30
+
data/ext/sacapi.h ADDED
@@ -0,0 +1,909 @@
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
+ * 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 SACAPI_H
26
+ #define SACAPI_H
27
+
28
+ /** \mainpage SQL Anywhere C API
29
+ *
30
+ * \section intro_sec Introduction
31
+ * The purpose of this API is to simplify creating C/C++ wrapper drivers for various interpreted languages
32
+ * such as PHP, Perl, Python, Ruby, and others. This API layer sits on top of DBLIB and was implemented
33
+ * using Embedded SQL. This API is not a replacement of DBLIB. It is just a way to simplify creating applications
34
+ * from C/C++ code without having to learn all the details of Embedded SQL.
35
+ *
36
+ * \section distribution Distribution of the API
37
+ * The API is built as a DLL (shared object on UNIX). The name of the DLL is \b dbcapi.dll
38
+ * ( \b libdbcapi.so on UNIX). This DLL is linked statically to DBLIB of the SQL Anywhere version that it was
39
+ * built against. When dbcapi.dll is loaded, the corresponding dblibX.dll is loaded by the OS. Applications that
40
+ * interface with dbcapi.dll can either link directly to it or load it dynamically. For dynamic
41
+ * loading of the DLL, please refer to the Dynamic Loading section below.
42
+ *
43
+ * The file sacapi.h is the main header file for the API. It describes all the data types and the entry
44
+ * points of the API.
45
+ *
46
+ * \section dynamic_loading Dynamically Loading the DLL
47
+ * The header file sacapidll.h contains the proper code to dynamically load the DLL. An application would
48
+ * need to include the sacapidll.h header file and compile in sacapidll.c with their source.
49
+ * sqlany_initialize_interface() can be used to dynamically load the DLL and lookup all the entry points.
50
+ *
51
+ * \section threading_support Threading Support
52
+ * The C API library is thread-unaware, meaning that the library does not perform any tasks that require
53
+ * mutual exclusion. In order to allow the library to work in threaded applications, there is only one rule to
54
+ * follow: <b>no more than one request is allowed on a single connection </b>. With this rule, the application
55
+ * is responsible for doing mutual exclusion when accessing any connection-specific resource. This includes
56
+ * connection handles, prepared statements, and result set objects.
57
+ *
58
+ * \version 2.0
59
+ */
60
+
61
+ /** \file sacapi.h
62
+ * Main API header file.
63
+ * This file describes all the data types and entry points of the API.
64
+ */
65
+
66
+ /** Defines to indicate the API versions
67
+ */
68
+ #define SQLANY_API_VERSION_1 1
69
+
70
+ /** Version 2 introduced the "_ex" functions and the ability to cancel requests.
71
+ */
72
+ #define SQLANY_API_VERSION_2 2
73
+
74
+ /** Returns the minimal error buffer size.
75
+ */
76
+ #define SACAPI_ERROR_SIZE 256
77
+
78
+ #if defined(__cplusplus)
79
+ extern "C" {
80
+ #endif
81
+
82
+ /** A handle to an interface context
83
+ */
84
+ typedef struct a_sqlany_interface_context a_sqlany_interface_context;
85
+
86
+ /** A handle to a connection object
87
+ */
88
+ typedef struct a_sqlany_connection a_sqlany_connection;
89
+
90
+ /** A handle to a statement object
91
+ */
92
+ typedef struct a_sqlany_stmt a_sqlany_stmt;
93
+
94
+ #ifdef WIN32
95
+ /** A portable 32-bit signed value */
96
+ typedef __int32 sacapi_i32;
97
+ /** A portable 32-bit unsigned value */
98
+ typedef unsigned __int32 sacapi_u32;
99
+ /** A portable boolean value */
100
+ typedef sacapi_i32 sacapi_bool;
101
+ #else
102
+ /** A portable 32-bit signed value */
103
+ typedef signed int sacapi_i32;
104
+ /** A portable 32-bit unsigned value */
105
+ typedef unsigned int sacapi_u32;
106
+ /** A portable boolean value */
107
+ typedef sacapi_i32 sacapi_bool;
108
+ #endif
109
+
110
+ // TODO:Character set issues
111
+
112
+
113
+ /** Specifies the data type being passed in or retrieved.
114
+ */
115
+ typedef enum a_sqlany_data_type
116
+ {
117
+ /// Invalid data type.
118
+ A_INVALID_TYPE,
119
+ /// Binary data. Binary data is treated as-is and no character set conversion is performed.
120
+ A_BINARY,
121
+ /// String data. The data where character set conversion is performed.
122
+ A_STRING,
123
+ /// Double data. Includes float values.
124
+ A_DOUBLE,
125
+ /// 64-bit integer.
126
+ A_VAL64,
127
+ /// 64-bit unsigned integer.
128
+ A_UVAL64,
129
+ /// 32-bit integer.
130
+ A_VAL32,
131
+ /// 32-bit unsigned integer.
132
+ A_UVAL32,
133
+ /// 16-bit integer.
134
+ A_VAL16,
135
+ /// 16-bit unsigned integer.
136
+ A_UVAL16,
137
+ /// 8-bit integer.
138
+ A_VAL8,
139
+ /// 8-bit unsigned integer.
140
+ A_UVAL8
141
+ } a_sqlany_data_type;
142
+
143
+ /** Returns a description of the attributes of a data value.
144
+ *
145
+ * To view examples of the a_sqlany_data_value structure in use, see the following topics:
146
+ *
147
+ * <ul>
148
+ * <li>\salink{dbcapi_isql.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-dbcapi-isql-cpp.html", "programming", "pg-c-api-dbcapi-isql-cpp"}
149
+ * <li>\salink{fetching_a_result_set.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-fetching-a-result-set-cpp.html", "programming", "pg-c-api-fetching-a-result-set-cpp"}
150
+ * <li>\salink{send_retrieve_full_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-full-blob-cpp.html", "programming", "pg-c-api-send-retrieve-full-blob-cpp"}
151
+ * <li>\salink{preparing_statements.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-preparing-statements-cpp.html", "programming", "pg-c-api-preparing-statements-cpp"}
152
+ * </ul>
153
+ */
154
+ typedef struct a_sqlany_data_value
155
+ {
156
+ /// A pointer to user supplied buffer of data.
157
+ char * buffer;
158
+ /// The size of the buffer.
159
+ size_t buffer_size;
160
+ /// A pointer to the number of valid bytes in the buffer. This value must be less than buffer_size.
161
+ size_t * length;
162
+ /// The type of the data
163
+ a_sqlany_data_type type;
164
+ /// A pointer to indicate whether the last fetched data is NULL.
165
+ sacapi_bool * is_null;
166
+ } a_sqlany_data_value;
167
+
168
+ /** A data direction enumeration.
169
+ */
170
+ typedef enum a_sqlany_data_direction
171
+ {
172
+ /// Invalid data direction.
173
+ DD_INVALID = 0x0,
174
+ /// Input-only host variables.
175
+ DD_INPUT = 0x1,
176
+ /// Output-only host variables.
177
+ DD_OUTPUT = 0x2,
178
+ /// Input and output host variables.
179
+ DD_INPUT_OUTPUT = 0x3
180
+ } a_sqlany_data_direction;
181
+
182
+ /** A bind parameter structure used to bind parameter and prepared statements.
183
+ *
184
+ * To view examples of the a_sqlany_bind_param structure in use, see the following topics:
185
+ *
186
+ * <ul>
187
+ * <li>\salink{preparing_statements.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-preparing-statements-cpp.html", "programming", "pg-c-api-preparing-statements-cpp"}
188
+ * <li>\salink{send_retrieve_full_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-full-blob-cpp.html", "programming", "pg-c-api-send-retrieve-full-blob-cpp"}
189
+ * <li>\salink{send_retrieve_part_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-part-blob-cpp.html", "programming", "pg-c-api-send-retrieve-part-blob-cpp"}
190
+ * </ul>
191
+ * \sa sqlany_execute()
192
+ */
193
+ typedef struct a_sqlany_bind_param
194
+ {
195
+ /// The direction of the data. (input, output, input_output)
196
+ a_sqlany_data_direction direction;
197
+ /// The actual value of the data.
198
+ a_sqlany_data_value value;
199
+ /// Name of the bind parameter. This is only used by sqlany_describe_bind_param().
200
+ char *name;
201
+ } a_sqlany_bind_param;
202
+
203
+ /** An enumeration of the native types of values as described by the server.
204
+ *
205
+ * The value types correspond to the embedded SQL data types.
206
+ * For more information on embedded SQL data types, see
207
+ * \salink{Embedded SQL data types, "http://dcx.sybase.com/1200en/dbprogramming/esqlvar.html", "programming", "esqlvar"}.
208
+ *
209
+ * \hideinitializers
210
+ * \sa sqlany_get_column_info(), a_sqlany_column_info
211
+ */
212
+ typedef enum a_sqlany_native_type
213
+ {
214
+ /// No data type.
215
+ DT_NOTYPE = 0,
216
+ /// Null-terminated character string that is a valid date.
217
+ DT_DATE = 384,
218
+ /// Null-terminated character string that is a valid time.
219
+ DT_TIME = 388,
220
+ /// Null-terminated character string that is a valid timestamp.
221
+ DT_TIMESTAMP = 392,
222
+ /// Varying length character string, in the CHAR character set, with a two-byte length field. The maximum length is 32765 bytes . When sending data, you must set the length field. When fetching data, the database server sets the length field. The data is not null-terminated or blank-padded.
223
+ DT_VARCHAR = 448,
224
+ /// Fixed-length blank-padded character string, in the CHAR character set. The maximum length, specified in bytes, is 32767. The data is not null-terminated.
225
+ DT_FIXCHAR = 452,
226
+ /// Long varying length character string, in the CHAR character set.
227
+ DT_LONGVARCHAR = 456,
228
+ /// Null-terminated character string, in the CHAR character set. The string is blank-padded if the database is initialized with blank-padded strings.
229
+ DT_STRING = 460,
230
+ /// 8-byte floating-point number.
231
+ DT_DOUBLE = 480,
232
+ /// 4-byte floating-point number.
233
+ DT_FLOAT = 482,
234
+ /// Packed decimal number (proprietary format).
235
+ DT_DECIMAL = 484,
236
+ /// 32-bit signed integer.
237
+ DT_INT = 496,
238
+ /// 16-bit signed integer.
239
+ DT_SMALLINT = 500,
240
+ /// Varying length binary data with a two-byte length field. The maximum length is 32765 bytes. When supplying information to the database server, you must set the length field. When fetching information from the database server, the server sets the length field.
241
+ DT_BINARY = 524,
242
+ /// Long binary data.
243
+ DT_LONGBINARY = 528,
244
+ /// 8-bit signed integer.
245
+ DT_TINYINT = 604,
246
+ /// 64-bit signed integer.
247
+ DT_BIGINT = 608,
248
+ /// 32-bit unsigned integer.
249
+ DT_UNSINT = 612,
250
+ /// 16-bit unsigned integer.
251
+ DT_UNSSMALLINT = 616,
252
+ /// 64-bit unsigned integer.
253
+ DT_UNSBIGINT = 620,
254
+ /// 8-bit signed integer.
255
+ DT_BIT = 624,
256
+ /// Long varying length character string, in the NCHAR character set.
257
+ DT_LONGNVARCHAR = 640
258
+ } a_sqlany_native_type;
259
+
260
+ /** Returns column metadata information.
261
+ *
262
+ * sqlany_get_column_info() can be used to populate this structure.
263
+ *
264
+ * To view an example of the a_sqlany_column_info structure in use, see
265
+ * \salink{dbcapi_isql.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-dbcapi-isql-cpp.html", "programming", "pg-c-api-dbcapi-isql-cpp"}.
266
+ */
267
+ typedef struct a_sqlany_column_info
268
+ {
269
+ /// The name of the column (null-terminated).
270
+ /// The string can be referenced as long as the result set object is not freed.
271
+ char * name;
272
+ /// The column data type.
273
+ a_sqlany_data_type type;
274
+ /// The native type of the column in the database.
275
+ a_sqlany_native_type native_type;
276
+ /// The precision.
277
+ unsigned short precision;
278
+ /// The scale.
279
+ unsigned short scale;
280
+ /// The maximum size a data value in this column can take.
281
+ size_t max_size;
282
+ /// Indicates whether a value in the column can be null.
283
+ sacapi_bool nullable;
284
+ } a_sqlany_column_info;
285
+
286
+ /** Gets information about the currently bound parameters.
287
+ *
288
+ * sqlany_get_bind_param_info() can be used to populate this structure.
289
+ *
290
+ * To view examples of the a_sqlany_bind_param_info structure in use, see the following topics:
291
+ *
292
+ * <ul>
293
+ * <li>\salink{preparing_statements.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-preparing-statements-cpp.html", "programming", "pg-c-api-preparing-statements-cpp"}
294
+ * <li>\salink{send_retrieve_full_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-full-blob-cpp.html", "programming", "pg-c-api-send-retrieve-full-blob-cpp"}
295
+ * <li>\salink{send_retrieve_part_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-part-blob-cpp.html", "programming", "pg-c-api-send-retrieve-part-blob-cpp"}
296
+ * </ul>
297
+ * \sa sqlany_execute()
298
+ */
299
+ typedef struct a_sqlany_bind_param_info
300
+ {
301
+ /// A pointer to the name of the parameter.
302
+ char * name;
303
+ /// The direction of the parameter.
304
+ a_sqlany_data_direction direction;
305
+ /// Information about the bound input value.
306
+ a_sqlany_data_value input_value;
307
+ /// Information about the bound output value.
308
+ a_sqlany_data_value output_value;
309
+ } a_sqlany_bind_param_info;
310
+
311
+ /** Returns metadata information about a column value in a result set.
312
+ *
313
+ * sqlany_get_data_info() can be used
314
+ * to populate this structure with information about what was last retrieved by a fetch operation.
315
+ *
316
+ * To view an example of the a_sqlany_data_data_info structure in use, see
317
+ * \salink{send_retrieve_part_blob.cpp, "http://dcx.sybase.com/1200en/dbprogramming/pg-c-api-send-retrieve-part-blob-cpp.html", "programming", "pg-c-api-send-retrieve-part-blob-cpp"}.
318
+ * \sa sqlany_get_data_info()
319
+ */
320
+ typedef struct a_sqlany_data_info
321
+ {
322
+ /// The type of the data in the column.
323
+ a_sqlany_data_type type;
324
+ /// Indicates whether the last fetched data is NULL.
325
+ /// This field is only valid after a successful fetch operation.
326
+ sacapi_bool is_null;
327
+ /// The total number of bytes available to be fetched.
328
+ /// This field is only valid after a successful fetch operation.
329
+ size_t data_size;
330
+ } a_sqlany_data_info;
331
+
332
+ /** Initializes the interface.
333
+ *
334
+ * The following example demonstrates how to initialize the SQL Anywhere C API DLL:
335
+ *
336
+ * <pre>
337
+ * sacapi_u32 api_version;
338
+ * if( sqlany_init( "PHP", SQLANY_API_VERSION_1, &api_version ) ) {
339
+ * printf( "Interface initialized successfully!\n" );
340
+ * } else {
341
+ * printf( "Failed to initialize the interface! Supported version=%d\n", api_version );
342
+ * }
343
+ * </pre>
344
+ *
345
+ * \param app_name A string that names the application that is using the API. For example, "PHP", "PERL", or "RUBY".
346
+ * \param api_version The version of the compiled application.
347
+ * \param version_available An optional argument to return the maximum supported API version.
348
+ * \return 1 on success, 0 otherwise
349
+ * \sa sqlany_fini()
350
+ */
351
+ sacapi_bool sqlany_init( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
352
+
353
+ #if _SACAPI_VERSION+0 >= 2
354
+ /** Initializes the interface using a context.
355
+ *
356
+ * \param app_name A string that names the API used, for example "PHP", "PERL", or "RUBY".
357
+ * \param api_version The current API version that the application is using.
358
+ * This should normally be one of the SQLANY_API_VERSION_* macros
359
+ * \param version_available An optional argument to return the maximum API version that is supported.
360
+ * \return a context object on success and NULL on failure.
361
+ * \sa sqlany_fini_ex()
362
+ */
363
+ a_sqlany_interface_context *sqlany_init_ex( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
364
+ #endif
365
+
366
+ /** Finalizes the interface.
367
+ *
368
+ * Frees any resources allocated by the API.
369
+ *
370
+ * \sa sqlany_init()
371
+ */
372
+ void sqlany_fini();
373
+ #if _SACAPI_VERSION+0 >= 2
374
+ /** Finalize the interface that was created using the specified context.
375
+ * Frees any resources allocated by the API.
376
+ * \param context A context object that was returned from sqlany_init_ex()
377
+ * \sa sqlany_init_ex()
378
+ */
379
+ void sqlany_fini_ex( a_sqlany_interface_context *context );
380
+ #endif
381
+
382
+ /** Creates a connection object.
383
+ *
384
+ * You must create an API connection object before establishing a database connection. Errors can be retrieved
385
+ * from the connection object. Only one request can be processed on a connection at a time. In addition,
386
+ * not more than one thread is allowed to access a connection object at a time. Undefined behavior or a failure
387
+ * occurs when multiple threads attempt to access a connection object simultaneously.
388
+ *
389
+ * \return A connection object
390
+ * \sa sqlany_connect(), sqlany_disconnect()
391
+ */
392
+ a_sqlany_connection * sqlany_new_connection( void );
393
+ #if _SACAPI_VERSION+0 >= 2
394
+ /** Creates a connection object using a context.
395
+ * An API connection object needs to be created before a database connection is established. Errors can be retrieved
396
+ * from the connection object. Only one request can be processed on a connection at a time. In addition,
397
+ * not more than one thread is allowed to access a connection object at a time. If multiple threads attempt
398
+ * to access a connection object simultaneously, then undefined behaviour/crashes will occur.
399
+ * \param context A context object that was returned from sqlany_init_ex()
400
+ * \return A connection object
401
+ * \sa sqlany_connect(), sqlany_disconnect(), sqlany_init_ex()
402
+ */
403
+ a_sqlany_connection *sqlany_new_connection_ex( a_sqlany_interface_context *context );
404
+ #endif
405
+
406
+ /** Frees the resources associated with a connection object.
407
+ *
408
+ * \param sqlany_conn A connection object created with sqlany_new_connection().
409
+ * \sa sqlany_new_connection()
410
+ */
411
+ void sqlany_free_connection( a_sqlany_connection *sqlany_conn );
412
+
413
+ /** Creates a connection object based on a supplied DBLIB SQLCA pointer.
414
+ *
415
+ * \param arg A void * pointer to a DBLIB SQLCA object.
416
+ * \return A connection object.
417
+ * \sa sqlany_new_connection(), sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
418
+ */
419
+ a_sqlany_connection * sqlany_make_connection( void * arg );
420
+ #if _SACAPI_VERSION+0 >= 2
421
+ /** Creates a connection object based on a supplied DBLIB SQLCA pointer and context.
422
+ * \param context A valid context object that was created by sqlany_init_ex()
423
+ * \param arg A void * pointer to a DBLIB SQLCA object.
424
+ * \return A connection object.
425
+ * \sa sqlany_init_ex(), sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
426
+ */
427
+ a_sqlany_connection *sqlany_make_connection_ex( a_sqlany_interface_context *context, void *arg );
428
+ #endif
429
+
430
+ /** Creates a connection to a SQL Anywhere database server using the supplied connection object and connection string.
431
+ *
432
+ * The supplied connection object must first be allocated using sqlany_new_connection().
433
+ *
434
+ * The following example demonstrates how to retrieve the error code of a failed connection attempt:
435
+ *
436
+ * <pre>
437
+ * a_sqlany_connection * sqlany_conn;
438
+ * sqlany_conn = sqlany_new_connection();
439
+ * if( !sqlany_connect( sqlany_conn, "uid=dba;pwd=sql" ) ) {
440
+ * char reason[SACAPI_ERROR_SIZE];
441
+ * sacapi_i32 code;
442
+ * code = sqlany_error( sqlany_conn, reason, sizeof(reason) );
443
+ * printf( "Connection failed. Code: %d Reason: %s\n", code, reason );
444
+ * } else {
445
+ * printf( "Connected successfully!\n" );
446
+ * sqlany_disconnect( sqlany_conn );
447
+ * }
448
+ * sqlany_free_connection( sqlany_conn );
449
+ * </pre>
450
+ *
451
+ * For more information on connecting to a SQL Anywhere database server, see
452
+ * \salink{Connection parameters, "http://dcx.sybase.com/1200en/dbadmin/da-conparm.html", "dbadmin", "da-conparm"} and
453
+ * \salink{SQL Anywhere database connections, "http://dcx.sybase.com/1200en/dbadmin/da-dbconnections.html", "dbadmin", "da-dbconnections"}.
454
+ *
455
+ * \param sqlany_conn A connection object created by sqlany_new_connection().
456
+ * \param str A SQL Anywhere connection string.
457
+ * \return 1 if the connection is established successfully or 0 when the connection fails. Use sqlany_error() to
458
+ * retrieve the error code and message.
459
+ * \sa sqlany_new_connection(), sqlany_error()
460
+ */
461
+ sacapi_bool sqlany_connect( a_sqlany_connection * sqlany_conn, const char * str );
462
+
463
+ /** Disconnects an already established SQL Anywhere connection.
464
+ *
465
+ * All uncommited transactions are rolled back.
466
+ *
467
+ * \param sqlany_conn A connection object with a connection established using sqlany_connect().
468
+ * \return 1 when successful or 0 when unsuccessful.
469
+ * \sa sqlany_connect(), sqlany_new_connection()
470
+ */
471
+ sacapi_bool sqlany_disconnect( a_sqlany_connection * sqlany_conn );
472
+
473
+ #if _SACAPI_VERSION+0 >= 2
474
+ /** Cancel an outstanding request on a connection
475
+ * This function can be used to cancel an outstanding request on a specific connection.
476
+ * \param sqlany_conn A connection object with a connection established using sqlany_connect().
477
+ */
478
+ void sqlany_cancel( a_sqlany_connection * sqlany_conn );
479
+ #endif
480
+
481
+ /** Executes the supplied SQL statement immediately without returning a result set.
482
+ *
483
+ * This function is useful for SQL statements that do not return a result set.
484
+ *
485
+ * \param sqlany_conn A connection object with a connection established using sqlany_connect().
486
+ * \param sql A string representing the SQL statement to be executed.
487
+ * \return 1 on success or 0 on failure.
488
+ */
489
+ sacapi_bool sqlany_execute_immediate( a_sqlany_connection * sqlany_conn, const char * sql );
490
+
491
+ /** Prepares a supplied SQL string.
492
+ *
493
+ * Execution does not happen until sqlany_execute() is
494
+ * called. The returned statement object should be freed using sqlany_free_stmt().
495
+ *
496
+ * The following statement demonstrates how to prepare a SELECT SQL string:
497
+ *
498
+ * <pre>
499
+ * char * str;
500
+ * a_sqlany_stmt * stmt;
501
+ *
502
+ * str = "select * from employees where salary >= ?";
503
+ * stmt = sqlany_prepare( sqlany_conn, str );
504
+ * if( stmt == NULL ) {
505
+ * // Failed to prepare statement, call sqlany_error() for more info
506
+ * }
507
+ * </pre>
508
+ *
509
+ * \param sqlany_conn A connection object with a connection established using sqlany_connect().
510
+ * \param sql_str The SQL statement to be prepared.
511
+ * \return A handle to a SQL Anywhere statement object. The statement object can be used by sqlany_execute()
512
+ * to execute the statement.
513
+ * \sa sqlany_free_stmt(), sqlany_connect(), sqlany_execute(), sqlany_num_params(), sqlany_describe_bind_param(), sqlany_bind_param()
514
+ */
515
+ a_sqlany_stmt * sqlany_prepare( a_sqlany_connection * sqlany_conn, const char * sql_str );
516
+
517
+ /** Frees resources associated with a prepared statement object.
518
+ *
519
+ * \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare() or sqlany_execute_direct().
520
+ * \sa sqlany_prepare(), sqlany_execute_direct()
521
+ */
522
+ void sqlany_free_stmt( a_sqlany_stmt * sqlany_stmt );
523
+
524
+ /** Returns the number of parameters expected for a prepared statement.
525
+ *
526
+ * \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
527
+ * \return The expected number of parameters, or -1 if the statement object is not valid.
528
+ * \sa sqlany_prepare()
529
+ */
530
+ sacapi_i32 sqlany_num_params( a_sqlany_stmt * sqlany_stmt );
531
+
532
+ /** Describes the bind parameters of a prepared statement.
533
+ *
534
+ * This function allows the caller to determine information about prepared statement parameters. The type of prepared
535
+ * statement, stored procedured or a DML, determines the amount of information provided. The direction of the parameters
536
+ * (input, output, or input-output) are always provided.
537
+ *
538
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
539
+ * \param index The index of the parameter. This number must be between 0 and sqlany_num_params() - 1.
540
+ * \param param A a_sqlany_bind_param structure that is populated with information.
541
+ * \return 1 when successful or 0 when unsuccessful.
542
+ * \sa sqlany_bind_param(), sqlany_prepare()
543
+ */
544
+ sacapi_bool sqlany_describe_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
545
+
546
+ /** Bind a user-supplied buffer as a parameter to the prepared statement.
547
+ *
548
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
549
+ * \param index The index of the parameter. This number must be between 0 and sqlany_num_params() - 1.
550
+ * \param param A a_sqlany_bind_param structure description of the parameter to be bound.
551
+ * \return 1 on success or 0 on unsuccessful.
552
+ * \sa sqlany_describe_bind_param()
553
+ */
554
+ sacapi_bool sqlany_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
555
+
556
+ /** Sends data as part of a bound parameter.
557
+ *
558
+ * This method can be used to send a large amount of data for a bound parameter in chunks.
559
+ *
560
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
561
+ * \param index The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
562
+ * \param buffer The data to be sent.
563
+ * \param size The number of bytes to send.
564
+ * \return 1 on success or 0 on failure.
565
+ * \sa sqlany_prepare()
566
+ */
567
+ sacapi_bool sqlany_send_param_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, char * buffer, size_t size );
568
+
569
+ /** Resets a statement to its prepared state condition.
570
+ *
571
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
572
+ * \return 1 on success, 0 on failure.
573
+ * \sa sqlany_prepare()
574
+ */
575
+ sacapi_bool sqlany_reset( a_sqlany_stmt * sqlany_stmt );
576
+
577
+ /** Retrieves information about the parameters that were bound using sqlany_bind_param().
578
+ *
579
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
580
+ * \param index The index of the parameter. This number should be between 0 and sqlany_num_params() - 1.
581
+ * \param info A sqlany_bind_param_info buffer to be populated with the bound parameter's information.
582
+ * \return 1 on success or 0 on failure.
583
+ * \sa sqlany_bind_param(), sqlany_describe_bind_param(), sqlany_prepare()
584
+ */
585
+ sacapi_bool sqlany_get_bind_param_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param_info * info );
586
+
587
+ /** Executes a prepared statement.
588
+ *
589
+ * You can use sqlany_num_cols() to verify if the executed statement returned a result set.
590
+ *
591
+ * The following example shows how to execute a statement that does not return a result set:
592
+ *
593
+ * <pre>
594
+ * a_sqlany_stmt * stmt;
595
+ * int i;
596
+ * a_sqlany_bind_param param;
597
+ *
598
+ * stmt = sqlany_prepare( sqlany_conn, "insert into moe(id,value) values( ?,? )" );
599
+ * if( stmt ) {
600
+ * sqlany_describe_bind_param( stmt, 0, &param );
601
+ * param.value.buffer = (char *)\&i;
602
+ * param.value.type = A_VAL32;
603
+ * sqlany_bind_param( stmt, 0, &param );
604
+ *
605
+ * sqlany_describe_bind_param( stmt, 1, &param );
606
+ * param.value.buffer = (char *)\&i;
607
+ * param.value.type = A_VAL32;
608
+ * sqlany_bind_param( stmt, 1, &param );
609
+ *
610
+ * for( i = 0; i < 10; i++ ) {
611
+ * if( !sqlany_execute( stmt ) ) {
612
+ * // call sqlany_error()
613
+ * }
614
+ * }
615
+ * sqlany_free_stmt( stmt );
616
+ * }
617
+ * </pre>
618
+ *
619
+ * \param sqlany_stmt A statement prepared successfully using sqlany_prepare().
620
+ * \return 1 if the statement is executed successfully or 0 on failure.
621
+ * \sa sqlany_prepare()
622
+ */
623
+ sacapi_bool sqlany_execute( a_sqlany_stmt * sqlany_stmt );
624
+
625
+ /** Executes the SQL statement specified by the string argument and possibly returns a result set.
626
+ *
627
+ * Use this method if you want to prepare and execute a statement,
628
+ * or instead of calling sqlany_prepare() followed by sqlany_execute().
629
+ *
630
+ * The following example shows how to execute a statement that returns a result set:
631
+ *
632
+ * <pre>
633
+ * stmt = sqlany_execute_direct( sqlany_conn, "select * from employees" ) ) {
634
+ * if( stmt && sqlany_num_cols( stmt ) > 0 ) {
635
+ * while( sqlany_fetch_next( stmt ) ) {
636
+ * int i;
637
+ * for( i = 0; i < sqlany_num_cols( stmt ); i++ ) {
638
+ * // Get column i data
639
+ * }
640
+ * }
641
+ * sqlany_free_stmt( stmt );
642
+ * }
643
+ * </pre>
644
+ *
645
+ * <em>Note:</em> This function can not be used for executing a SQL statement with parameters.
646
+ *
647
+ * \param sqlany_conn A connection object with a connection established using sqlany_connect().
648
+ * \param sql_str A SQL string. The SQL string should not have parameters such as ?.
649
+ * \return A statement handle if the function executes successfully, NULL when the function executes unsuccessfully.
650
+ * \sa sqlany_fetch_absolute(), sqlany_fetch_next(), sqlany_num_cols(), sqlany_get_column()
651
+ */
652
+ a_sqlany_stmt * sqlany_execute_direct( a_sqlany_connection * sqlany_conn, const char * sql_str );
653
+
654
+ /** Moves the current row in the result set to the row number specified and then fetches the data at that row.
655
+ *
656
+ * \param sqlany_stmt A statement object that was executed by
657
+ * sqlany_execute() or sqlany_execute_direct().
658
+ * \param row_num The row number to be fetched. The first row is 1, the last row is -1.
659
+ * \return 1 if the fetch was successfully, 0 when the fetch is unsuccessful.
660
+ * \sa sqlany_execute_direct(), sqlany_execute(), sqlany_error(), sqlany_fetch_next()
661
+ */
662
+ sacapi_bool sqlany_fetch_absolute( a_sqlany_stmt * sqlany_stmt, sacapi_i32 row_num );
663
+
664
+ /** Returns the next row from the result set.
665
+ *
666
+ * This function fetches the next row from the result set.
667
+ * When the result object is first created, the current row
668
+ * pointer is set to before the first row (i.e. row 0).
669
+ * This function first advances the row pointer and then fetches
670
+ * the data at the new row.
671
+ *
672
+ * \param sqlany_stmt A statement object that was executed by
673
+ * sqlany_execute() or sqlany_execute_direct().
674
+ * \return 1 if the fetch was successfully, 0 when the fetch is unsuccessful.
675
+ * \sa sqlany_fetch_absolute(), sqlany_execute_direct(), sqlany_execute(), sqlany_error()
676
+ */
677
+ sacapi_bool sqlany_fetch_next( a_sqlany_stmt * sqlany_stmt );
678
+
679
+ /** Advances to the next result set in a multiple result set query.
680
+ *
681
+ * If a query (such as a call to a stored procedure) returns multiple result sets, then this function
682
+ * advances from the current result set to the next.
683
+ *
684
+ * The following example demonstrates how to advance to the next result set in a multiple result set query:
685
+ *
686
+ * <pre>
687
+ * stmt = sqlany_execute_direct( sqlany_conn, "call my_multiple_results_procedure()" );
688
+ * if( result ) {
689
+ * do {
690
+ * while( sqlany_fetch_next( stmt ) ) {
691
+ * // get column data
692
+ * }
693
+ * } while( sqlany_get_next_result( stmt ) );
694
+ * sqlany_free_stmt( stmt );
695
+ * }
696
+ * </pre>
697
+ *
698
+ * \param sqlany_stmt A statement object executed by
699
+ * sqlany_execute() or sqlany_execute_direct().
700
+ * \return 1 if the statement successfully advances to the next result set, 0 otherwise.
701
+ * \sa sqlany_execute_direct(), sqlany_execute()
702
+ */
703
+ sacapi_bool sqlany_get_next_result( a_sqlany_stmt * sqlany_stmt );
704
+
705
+ /** Returns the number of rows affected by execution of the prepared statement.
706
+ *
707
+ * \param sqlany_stmt A statement that was prepared and executed successfully with no result set returned.
708
+ * For example, an INSERT, UPDATE or DELETE statement was executed.
709
+ * \return The number of rows affected or -1 on failure.
710
+ * \sa sqlany_execute(), sqlany_execute_direct()
711
+ */
712
+ sacapi_i32 sqlany_affected_rows( a_sqlany_stmt * sqlany_stmt );
713
+
714
+ /** Returns number of columns in the result set.
715
+ *
716
+ * \param sqlany_stmt A statement object created by sqlany_prepare() or sqlany_execute_direct().
717
+ * \return The number of columns in the result set or -1 on a failure.
718
+ * \sa sqlany_execute(), sqlany_execute_direct(), sqlany_prepare()
719
+ */
720
+ sacapi_i32 sqlany_num_cols( a_sqlany_stmt * sqlany_stmt );
721
+
722
+ /** Returns the number of rows in the result set.
723
+ *
724
+ * By default this function only returns an estimate. To return an exact count, set the row_counts option
725
+ * on the connection. For more information on the row_counts option, see
726
+ * \salink{row_counts option [database], "http://dcx.sybase.com/1200en/dbadmin/row-counts-option.html", "dbadmin", "row-counts-option"}.
727
+ *
728
+ * \param sqlany_stmt A statement object that was executed by
729
+ * sqlany_execute() or sqlany_execute_direct().
730
+ * \return The number rows in the result set. If the number of rows is an estimate, the number returned is
731
+ * negative and the estimate is the absolute value of the returned integer. The value returned is positive
732
+ * if the number of rows is exact.
733
+ * \sa sqlany_execute_direct(), sqlany_execute()
734
+ */
735
+ sacapi_i32 sqlany_num_rows( a_sqlany_stmt * sqlany_stmt );
736
+
737
+ /** Fills the supplied buffer with the value fetched for the specified column.
738
+ *
739
+ * For A_BINARY and A_STRING * data types,
740
+ * value->buffer points to an internal buffer associated with the result set.
741
+ * Do not rely upon or alter the content of the pointer buffer as it changes when a
742
+ * new row is fetched or when the result set object is feed. Users should copy the
743
+ * data out of those pointers into their own buffers.
744
+ *
745
+ * The value->length field indicates the number of valid characters that
746
+ * value->buffer points to. The data returned in value->buffer is not
747
+ * null-terminated. This function fetches all the returned values from the SQL
748
+ * Anywhere database server. For example, if the column contains
749
+ * a 2GB blob, this function attempts to allocate enough memory to hold that value.
750
+ * If you do not want to allocate memory, use sqlany_get_data() instead.
751
+ *
752
+ * \param sqlany_stmt A statement object executed by
753
+ * sqlany_execute() or sqlany_execute_direct().
754
+ * \param col_index The number of the column to be retrieved.
755
+ * A column number is between 0 and sqlany_num_cols() - 1.
756
+ * \param buffer A a_sqlany_data_value object to be filled with the data fetched for column col_index.
757
+ * \return 1 on success or 0 for failure. A failure can happen if any of the parameters are invalid or if there is
758
+ * not enough memory to retrieve the full value from the SQL Anywhere database server.
759
+ * \sa sqlany_execute_direct(), sqlany_execute(), sqlany_fetch_absolute(), sqlany_fetch_next()
760
+ */
761
+ sacapi_bool sqlany_get_column( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_value * buffer );
762
+
763
+ /** Retrieves the data fetched for the specified column into the supplied buffer memory.
764
+ *
765
+ * \param sqlany_stmt A statement object executed by
766
+ * sqlany_execute() or sqlany_execute_direct().
767
+ * \param col_index The number of the column to be retrieved.
768
+ * A column number is between 0 and sqlany_num_cols() - 1.
769
+ * \param offset The starting offset of the data to get.
770
+ * \param buffer A buffer to be filled with the contents of the column. The buffer pointer must be aligned correctly
771
+ * for the data type copied into it.
772
+ * \param size The size of the buffer in bytes. The function fails
773
+ * if you specify a size greater than 2GB.
774
+ * \return The number of bytes successfully copied into the supplied buffer.
775
+ * This number must not exceed 2GB.
776
+ * 0 indicates that no data remains to be copied. -1 indicates a failure.
777
+ * \sa sqlany_execute(), sqlany_execute_direct(), sqlany_fetch_absolute(), sqlany_fetch_next()
778
+ */
779
+ sacapi_i32 sqlany_get_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, size_t offset, void * buffer, size_t size );
780
+
781
+ /** Retrieves information about the data that was fetched by the last fetch operation.
782
+ *
783
+ * \param sqlany_stmt A statement object executed by
784
+ * sqlany_execute() or sqlany_execute_direct().
785
+ * \param col_index The column number between 0 and sqlany_num_cols() - 1.
786
+ * \param buffer A data info buffer to be filled with the metadata about the data fetched.
787
+ * \return 1 on success, and 0 on failure. Failure is returned when any of the supplied parameters are invalid.
788
+ * \sa sqlany_execute(), sqlany_execute_direct(), sqlany_fetch_absolute(), sqlany_fetch_next()
789
+ */
790
+ sacapi_bool sqlany_get_data_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_info * buffer );
791
+
792
+ /** Retrieves column metadata information and fills the a_sqlany_column_info structure with information about the column.
793
+ *
794
+ * \param sqlany_stmt A statement object created by sqlany_prepare() or sqlany_execute_direct().
795
+ * \param col_index The column number between 0 and sqlany_num_cols() - 1.
796
+ * \param buffer A column info structure to be filled with column information.
797
+ * \return 1 on success or 0 if the column index is out of range,
798
+ * or if the statement does not return a result set.
799
+ * \sa sqlany_execute(), sqlany_execute_direct(), sqlany_prepare()
800
+ */
801
+ sacapi_bool sqlany_get_column_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_column_info * buffer );
802
+
803
+ /** Commits the current transaction.
804
+ *
805
+ * \param sqlany_conn The connection object on which the commit operation is performed.
806
+ * \return 1 when successful or 0 when unsuccessful.
807
+ * \sa sqlany_rollback()
808
+ */
809
+ sacapi_bool sqlany_commit( a_sqlany_connection * sqlany_conn );
810
+
811
+ /** Rolls back the current transaction.
812
+ *
813
+ * \param sqlany_conn The connection object on which the rollback operation is to be performed.
814
+ * \return 1 on success, 0 otherwise.
815
+ * \sa sqlany_commit()
816
+ */
817
+ sacapi_bool sqlany_rollback( a_sqlany_connection * sqlany_conn );
818
+
819
+ /** Returns the current client version.
820
+ *
821
+ * This method fills the buffer passed with the major, minor, patch, and build number of the client library.
822
+ * The buffer will be null-terminated.
823
+ *
824
+ * \param buffer The buffer to be filled with the client version string.
825
+ * \param len The length of the buffer supplied.
826
+ * \return 1 when successful or 0 when unsuccessful.
827
+ */
828
+ sacapi_bool sqlany_client_version( char * buffer, size_t len );
829
+ #if _SACAPI_VERSION+0 >= 2
830
+ /** Returns the current client version.
831
+ *
832
+ * This method fills the buffer passed with the major, minor, patch, and build number of the client library.
833
+ * The buffer will be null-terminated.
834
+ *
835
+ * \param context object that was create with sqlany_init_ex()
836
+ * \param buffer The buffer to be filled with the client version string.
837
+ * \param len The length of the buffer supplied.
838
+ * \return 1 when successful or 0 when unsuccessful.
839
+ * \sa sqlany_init_ex()
840
+ */
841
+ sacapi_bool sqlany_client_version_ex( a_sqlany_interface_context *context, char *buffer, size_t len );
842
+ #endif
843
+
844
+ /** Retrieves the last error code and message stored in the connection object.
845
+ *
846
+ * For more information on SQLCODE error messages, see
847
+ * \salink{SQL Anywhere error messages sorted by SQLCODE, "http://dcx.sybase.com/1200en/saerrors/sa-errors-by-sqlcode.html", "errors", "sa-errors-by-sqlcode"}.
848
+ *
849
+ * \param sqlany_conn A connection object returned from sqlany_new_connection().
850
+ * \param buffer A buffer to be filled with the error message.
851
+ * \param size The size of the supplied buffer.
852
+ * \return The last error code. Positive values are warnings, negative values are errors, and 0 indicates success.
853
+ * \sa sqlany_connect()
854
+ */
855
+ sacapi_i32 sqlany_error( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
856
+
857
+ /** Retrieves the current SQLSTATE.
858
+ *
859
+ * For more information on SQLSTATE error messages, see
860
+ * \salink{SQL Anywhere error messages sorted by SQLSTATE, "http://dcx.sybase.com/1200en/saerrors/sa-errors-by-sqlstate.html", "errors", "sa-errors-by-sqlstate"}.
861
+ *
862
+ * \param sqlany_conn A connection object returned from sqlany_new_connection().
863
+ * \param buffer A buffer to be filled with the current 5-character SQLSTATE.
864
+ * \param size The buffer size.
865
+ * \return The number of bytes copied into the buffer.
866
+ * \sa sqlany_error()
867
+ */
868
+ size_t sqlany_sqlstate( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
869
+
870
+ /** Clears the last stored error code
871
+ *
872
+ * \param sqlany_conn A connection object returned from sqlany_new_connection().
873
+ * \sa sqlany_new_connection()
874
+ */
875
+ void sqlany_clear_error( a_sqlany_connection * sqlany_conn );
876
+
877
+ #if defined(__cplusplus)
878
+ }
879
+ #endif
880
+
881
+ /** \example connecting.cpp
882
+ * This is an example of how to create a connection object and connect with it to SQL Anywhere.
883
+ */
884
+
885
+ /** \example fetching_a_result_set.cpp
886
+ * This example shows how to fetch data from a result set.
887
+ */
888
+
889
+ /** \example preparing_statements.cpp
890
+ * This example shows how to prepare and execute a statement.
891
+ */
892
+
893
+ /** \example fetching_multiple_from_sp.cpp
894
+ * This example shows how to fetch multiple result sets from a stored procedure.
895
+ */
896
+
897
+ /** \example send_retrieve_part_blob.cpp
898
+ * This example shows how to insert a blob in chunks and retrieve it in chunks too.
899
+ */
900
+
901
+ /** \example send_retrieve_full_blob.cpp
902
+ * This example shows how to insert and retrieve a blob in one chunk .
903
+ */
904
+
905
+ /** \example dbcapi_isql.cpp
906
+ * This example shows how to write an ISQL application using dbcapi.
907
+ */
908
+
909
+ #endif