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/sacapi.h
ADDED
@@ -0,0 +1,679 @@
|
|
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 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
|
+
* For more information on the implementation, please refer to the file sqlany_imp.sqc.
|
36
|
+
*
|
37
|
+
* \section distribution Distribution of the API
|
38
|
+
* The API is built as a DLL (shared object on UNIX). The name of the DLL is \b dbcapi.dll
|
39
|
+
* ( \b libdbcapi.so on UNIX). This DLL is linked statically to DBLIB of the SQL Anywhere version that it was
|
40
|
+
* built against. When dbcapi.dll is loaded, the corresponding dblibX.dll is loaded by the OS. Applications that
|
41
|
+
* interface with dbcapi.dll can either link directly to it or load it dynamically. For dynamic
|
42
|
+
* loading of the DLL, please refer to the Dynamic Loading section below.
|
43
|
+
*
|
44
|
+
* The file sacapi.h is the main header file for the API. It describes all the data types and the entry
|
45
|
+
* points of the API.
|
46
|
+
*
|
47
|
+
* \section dynamic_loading Dynamically Loading the DLL
|
48
|
+
* The header file sacapidll.h contains the proper code to dynamically load the DLL. An application would
|
49
|
+
* need to include the sacapidll.h header file and compile in sacapidll.c with their source.
|
50
|
+
* sqlany_initialize_interface() can be used to dynamically load the DLL and lookup all the entry points.
|
51
|
+
*
|
52
|
+
* \section threading_support Threading Support
|
53
|
+
* The C API library is thread-unaware, meaning that the library does not perform any tasks that require
|
54
|
+
* mutual exclusion. In order to allow the library to work in threaded applications, there is only one rule to
|
55
|
+
* follow: <b>no more than one request is allowed on a single connection </b>. With this rule, the application
|
56
|
+
* is responsible for doing mutual exclusion when accessing any connection-specific resource. This includes
|
57
|
+
* connection handles, prepared statements, and result set objects.
|
58
|
+
*
|
59
|
+
* \version 1.0
|
60
|
+
*/
|
61
|
+
|
62
|
+
/** \file sacapi.h
|
63
|
+
* Main API header file.
|
64
|
+
* This file describes all the data types and entry points of the API.
|
65
|
+
*/
|
66
|
+
|
67
|
+
/** A define to indicate the current API level
|
68
|
+
*/
|
69
|
+
#define SQLANY_CURRENT_API_VERSION 0x1
|
70
|
+
|
71
|
+
/** Error buffer size
|
72
|
+
*/
|
73
|
+
#define SACAPI_ERROR_SIZE 256
|
74
|
+
|
75
|
+
#if defined(__cplusplus)
|
76
|
+
extern "C" {
|
77
|
+
#endif
|
78
|
+
|
79
|
+
/** A handle to a connection object
|
80
|
+
*/
|
81
|
+
typedef struct a_sqlany_connection a_sqlany_connection;
|
82
|
+
|
83
|
+
/** A handle to a statement object
|
84
|
+
*/
|
85
|
+
typedef struct a_sqlany_stmt a_sqlany_stmt;
|
86
|
+
|
87
|
+
#ifdef WIN32
|
88
|
+
/** A portable 32-bit signed value */
|
89
|
+
typedef __int32 sacapi_i32;
|
90
|
+
/** A portable 32-bit unsigned value */
|
91
|
+
typedef unsigned __int32 sacapi_u32;
|
92
|
+
/** A portable boolean value */
|
93
|
+
typedef sacapi_i32 sacapi_bool;
|
94
|
+
#else
|
95
|
+
/** A portable 32-bit signed value */
|
96
|
+
typedef signed int sacapi_i32;
|
97
|
+
/** A portable 32-bit unsigned value */
|
98
|
+
typedef unsigned int sacapi_u32;
|
99
|
+
/** A portable boolean value */
|
100
|
+
typedef sacapi_i32 sacapi_bool;
|
101
|
+
#endif
|
102
|
+
|
103
|
+
// TODO:Character set issues
|
104
|
+
|
105
|
+
|
106
|
+
/** Data type enumeration.
|
107
|
+
* This enum is used to specify the data type that is being passed in or retrieved.
|
108
|
+
*/
|
109
|
+
typedef enum a_sqlany_data_type
|
110
|
+
{
|
111
|
+
A_INVALID_TYPE, /*!< Invalid data type */
|
112
|
+
A_BINARY, /*!< Binary data : binary data is treated as-is and no character set conversion is performed */
|
113
|
+
A_STRING, /*!< String data : data where character set conversion is performed */
|
114
|
+
A_DOUBLE, /*!< Double data : includes float values */
|
115
|
+
A_VAL64, /*!< 64-bit integer */
|
116
|
+
A_UVAL64, /*!< 64-bit unsigned integer */
|
117
|
+
A_VAL32, /*!< 32-bit integer */
|
118
|
+
A_UVAL32, /*!< 32-bit unsigned integer */
|
119
|
+
A_VAL16, /*!< 16-bit integer */
|
120
|
+
A_UVAL16, /*!< 16-bit unsigned integer */
|
121
|
+
A_VAL8, /*!< 8-bit integer */
|
122
|
+
A_UVAL8 /*!< 8-bit unsigned integer */
|
123
|
+
} a_sqlany_data_type;
|
124
|
+
|
125
|
+
/** A data value structure.
|
126
|
+
* This structure describes the attributes of a data value.
|
127
|
+
*/
|
128
|
+
typedef struct a_sqlany_data_value
|
129
|
+
{
|
130
|
+
char * buffer; /*!< Pointer to user supplied buffer of data */
|
131
|
+
size_t buffer_size; /*!< The size of the buffer */
|
132
|
+
size_t * length; /*!< The number of valid bytes in the buffer. Must be less than buffer_size */
|
133
|
+
a_sqlany_data_type type; /*!< The type of the data */
|
134
|
+
sacapi_bool * is_null; /*!< Whether the value is NULL or not */
|
135
|
+
} a_sqlany_data_value;
|
136
|
+
|
137
|
+
/** A data direction enumeration.
|
138
|
+
*/
|
139
|
+
typedef enum a_sqlany_data_direction
|
140
|
+
{
|
141
|
+
DD_INVALID = 0x0, /*!< Invalid data direction */
|
142
|
+
DD_INPUT = 0x1, /*!< Input only host variables */
|
143
|
+
DD_OUTPUT = 0x2, /*!< Output only host variables */
|
144
|
+
DD_INPUT_OUTPUT = 0x3 /*!< Input and Output host variables */
|
145
|
+
} a_sqlany_data_direction;
|
146
|
+
|
147
|
+
/** A bind parameter structure.
|
148
|
+
* This structure is used to bind parameters for prepared statements for execution.
|
149
|
+
* \sa sqlany_execute()
|
150
|
+
*/
|
151
|
+
typedef struct a_sqlany_bind_param
|
152
|
+
{
|
153
|
+
a_sqlany_data_direction direction; /*!< The direction of the data (input, output, input_output) */
|
154
|
+
a_sqlany_data_value value; /*!< The actual value of the data */
|
155
|
+
char *name; /*!< Name of the bind parameter. This is only used by
|
156
|
+
sqlany_describe_bind_param(). */
|
157
|
+
} a_sqlany_bind_param;
|
158
|
+
|
159
|
+
/** An enumeration of the native types of values as described by the server.
|
160
|
+
* \sa sqlany_get_column_info(), a_sqlany_column_info
|
161
|
+
*/
|
162
|
+
typedef enum a_sqlany_native_type
|
163
|
+
{
|
164
|
+
DT_NOTYPE = 0,
|
165
|
+
DT_DATE = 384,
|
166
|
+
DT_TIME = 388,
|
167
|
+
DT_TIMESTAMP = 392,
|
168
|
+
DT_VARCHAR = 448,
|
169
|
+
DT_FIXCHAR = 452,
|
170
|
+
DT_LONGVARCHAR = 456,
|
171
|
+
DT_STRING = 460,
|
172
|
+
DT_DOUBLE = 480,
|
173
|
+
DT_FLOAT = 482,
|
174
|
+
DT_DECIMAL = 484,
|
175
|
+
DT_INT = 496,
|
176
|
+
DT_SMALLINT = 500,
|
177
|
+
DT_BINARY = 524,
|
178
|
+
DT_LONGBINARY = 528,
|
179
|
+
DT_TINYINT = 604,
|
180
|
+
DT_BIGINT = 608,
|
181
|
+
DT_UNSINT = 612,
|
182
|
+
DT_UNSSMALLINT = 616,
|
183
|
+
DT_UNSBIGINT = 620,
|
184
|
+
DT_BIT = 624,
|
185
|
+
DT_LONGNVARCHAR = 640
|
186
|
+
} a_sqlany_native_type;
|
187
|
+
|
188
|
+
/** A column info structure.
|
189
|
+
* This structure returns metadata information about a column.
|
190
|
+
* sqlany_get_column_info() can be used to populate this structure.
|
191
|
+
*/
|
192
|
+
typedef struct a_sqlany_column_info
|
193
|
+
{
|
194
|
+
char * name; /*!< The name of the column (null-terminated ).
|
195
|
+
The string can be referenced
|
196
|
+
as long as the result set object is not freed. */
|
197
|
+
a_sqlany_data_type type; /*!< The type of the column data */
|
198
|
+
a_sqlany_native_type native_type; /*!< The native type of the column in the
|
199
|
+
database */
|
200
|
+
unsigned short precision; /*!< Precision */
|
201
|
+
unsigned short scale; /*!< Scale */
|
202
|
+
size_t max_size; /*!< The maximum size a data value in this column
|
203
|
+
can take */
|
204
|
+
sacapi_bool nullable; /*!< If a value in the column can be null or not */
|
205
|
+
} a_sqlany_column_info;
|
206
|
+
|
207
|
+
/** A bind parameter info structure.
|
208
|
+
* This structure allows the user to get information about the currently bound parameters.
|
209
|
+
* sqlany_get_bind_param_info() can be used to populate this structure.
|
210
|
+
*/
|
211
|
+
typedef struct a_sqlany_bind_param_info
|
212
|
+
{
|
213
|
+
char * name; /*!< Name of the parameter */
|
214
|
+
a_sqlany_data_direction direction; /*!< Parameter direction */
|
215
|
+
|
216
|
+
a_sqlany_data_value input_value; /*!< Information about the bound input value */
|
217
|
+
a_sqlany_data_value output_value; /*!< Information about the bound output value */
|
218
|
+
} a_sqlany_bind_param_info;
|
219
|
+
|
220
|
+
/** A data info structure.
|
221
|
+
* This structure returns metadata information about a column value in a result set.
|
222
|
+
* sqlany_get_data_info() can be used
|
223
|
+
* to populate this structure with information about what was last retrieved by a fetch operation.
|
224
|
+
*/
|
225
|
+
typedef struct a_sqlany_data_info
|
226
|
+
{
|
227
|
+
a_sqlany_data_type type; /*!< Type of the data in the column. */
|
228
|
+
sacapi_bool is_null; /*!< If the last fetched data is NULL or not.
|
229
|
+
This field is only valid after a successful fetch operation. */
|
230
|
+
size_t data_size; /*!< The total number of bytes available to be fetched.
|
231
|
+
This field is only valid after a successful fetch operation. */
|
232
|
+
} a_sqlany_data_info;
|
233
|
+
|
234
|
+
/** Initialize the interface.
|
235
|
+
* \param app_name A string that names the API used, for example "PHP", "PERL", or "RUBY".
|
236
|
+
* \param api_version The current API version that the application is using.
|
237
|
+
* This should normally be SQLANY_CURRENT_API_VERSION.
|
238
|
+
* \param version_available An optional argument to return the maximum API version that is supported.
|
239
|
+
* \return 1 on success, 0 otherwise
|
240
|
+
* \sa sqlany_fini()
|
241
|
+
* \par Quick Example:
|
242
|
+
* \code
|
243
|
+
sacapi_u32 api_version;
|
244
|
+
if( sqlany_init( "PHP", SQLANY_CURRENT_API_VERSION, &api_version ) ) {
|
245
|
+
printf( "Interface initialized successfully!\n" );
|
246
|
+
} else {
|
247
|
+
printf( "Failed to initialize the interface! Supported version=%d\n", api_version );
|
248
|
+
}
|
249
|
+
* \endcode
|
250
|
+
*/
|
251
|
+
sacapi_bool sqlany_init( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
|
252
|
+
|
253
|
+
/** Finalize the interface.
|
254
|
+
* Frees any resources allocated by the API.
|
255
|
+
* \sa sqlany_init()
|
256
|
+
*/
|
257
|
+
void sqlany_fini( void );
|
258
|
+
|
259
|
+
/** Creates a connection object.
|
260
|
+
* An API connection object needs to be created before a database connection is established. Errors can be retrieved
|
261
|
+
* from the connection object. Only one request can be processed on a connection at a time. In addition,
|
262
|
+
* not more than one thread is allowed to access a connection object at a time. If multiple threads attempt
|
263
|
+
* to access a connection object simultaneously, then undefined behaviour/crashes will occur.
|
264
|
+
* \return A connection object
|
265
|
+
* \sa sqlany_connect(), sqlany_disconnect()
|
266
|
+
*/
|
267
|
+
a_sqlany_connection * sqlany_new_connection( void );
|
268
|
+
|
269
|
+
/** Frees the resources associated with a connection object.
|
270
|
+
* \param sqlany_conn A connection object that was created by sqlany_new_connection().
|
271
|
+
*/
|
272
|
+
void sqlany_free_connection( a_sqlany_connection *sqlany_conn );
|
273
|
+
|
274
|
+
/** Creates a connection object based on a supplied DBLIB SQLCA pointer.
|
275
|
+
* \param arg A void * pointer to a DBLIB SQLCA object.
|
276
|
+
* \return A connection object.
|
277
|
+
* \sa sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
|
278
|
+
*/
|
279
|
+
a_sqlany_connection * sqlany_make_connection( void * arg );
|
280
|
+
|
281
|
+
/** Establish a connection.
|
282
|
+
* This function establishes a connection to a SQL Anywhere server using the supplied connection object and
|
283
|
+
* the supplied connection string. The connection object must first be allocated using sqlany_new_connection().
|
284
|
+
* \param sqlany_conn A connection object that was created by sqlany_new_connection().
|
285
|
+
* \param str A SQL Anywhere connection string.
|
286
|
+
* \return 1 if the connection was established successfully, or 0 otherwise. The error code and message can be
|
287
|
+
* retrieved using sqlany_error().
|
288
|
+
* \sa sqlany_new_connection(), sqlany_error()
|
289
|
+
* \par Quick Example:
|
290
|
+
* \code
|
291
|
+
a_sqlany_connection * sqlany_conn;
|
292
|
+
sqlany_conn = sqlany_new_connection();
|
293
|
+
if( !sqlany_connect( sqlany_conn, "uid=dba;pwd=sql" ) ) {
|
294
|
+
char reason[SACAPI_ERROR_SIZE];
|
295
|
+
sacapi_i32 code;
|
296
|
+
code = sqlany_error( sqlany_conn, reason, sizeof(reason) );
|
297
|
+
printf( "Connection failed. Code: %d Reason: %s\n", code, reason );
|
298
|
+
} else {
|
299
|
+
printf( "Connected successfully!\n" );
|
300
|
+
sqlany_disconnect( sqlany_conn );
|
301
|
+
}
|
302
|
+
sqlany_free_connection( sqlany_conn );
|
303
|
+
* \endcode
|
304
|
+
*/
|
305
|
+
sacapi_bool sqlany_connect( a_sqlany_connection * sqlany_conn, const char * str );
|
306
|
+
|
307
|
+
/** Disconnect an already established connection.
|
308
|
+
* This function disconnects a SQL Anywhere connection.
|
309
|
+
* Any uncommited transactions will be rolled back.
|
310
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
311
|
+
* \return 1 on success; 0 otherwise
|
312
|
+
* \sa sqlany_connect()
|
313
|
+
*/
|
314
|
+
sacapi_bool sqlany_disconnect( a_sqlany_connection * sqlany_conn );
|
315
|
+
|
316
|
+
/** Execute a SQL statement immediately without returning a result set.
|
317
|
+
* Execute the specified SQL statement immediately.
|
318
|
+
* This function is useful for SQL statements that do not return a result set.
|
319
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
320
|
+
* \param sql A string respresenting the SQL statement to be executed.
|
321
|
+
* \return 1 on success, 0 otherwise
|
322
|
+
*/
|
323
|
+
sacapi_bool sqlany_execute_immediate( a_sqlany_connection * sqlany_conn, const char * sql );
|
324
|
+
|
325
|
+
/** Prepare a SQL statement.
|
326
|
+
* This function prepares the supplied SQL string. Execution does not happen until sqlany_execute() is
|
327
|
+
* called. The returned statement object should be freed using sqlany_free_stmt().
|
328
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
329
|
+
* \param sql_str The SQL statement to be prepared.
|
330
|
+
* \return A handle to a SQL Anywhere statement object. The statement object can be used by sqlany_execute()
|
331
|
+
* to execute the statement.
|
332
|
+
* \sa sqlany_free_stmt(), sqlany_connect(), sqlany_execute()
|
333
|
+
* \par Quick Example:
|
334
|
+
* \code
|
335
|
+
char * str;
|
336
|
+
a_sqlany_stmt * stmt;
|
337
|
+
|
338
|
+
str = "select * from employees where salary >= ?";
|
339
|
+
stmt = sqlany_prepare( sqlany_conn, str );
|
340
|
+
if( stmt == NULL ) {
|
341
|
+
// Failed to prepare statement, call sqlany_error() for more info
|
342
|
+
}
|
343
|
+
* \endcode
|
344
|
+
*/
|
345
|
+
a_sqlany_stmt * sqlany_prepare( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
346
|
+
|
347
|
+
/** Frees resources associated with a prepared statement object.
|
348
|
+
* This function frees the resources associated with a prepared statement object.
|
349
|
+
* \param sqlany_stmt A statement object that was returned from sqlany_prepare().
|
350
|
+
* \sa sqlany_prepare()
|
351
|
+
*/
|
352
|
+
void sqlany_free_stmt( a_sqlany_stmt * sqlany_stmt );
|
353
|
+
|
354
|
+
/** Returns the number of parameters that are expected for a prepared statement.
|
355
|
+
* \param sqlany_stmt A statement object that was returned from sqlany_prepare().
|
356
|
+
* \return The number of parameters that are expected. -1 if the sqlany_stmt object is not valid.
|
357
|
+
*/
|
358
|
+
sacapi_i32 sqlany_num_params( a_sqlany_stmt * sqlany_stmt );
|
359
|
+
|
360
|
+
/** Describes the bind parameters of a prepared statement.
|
361
|
+
* This function allows the caller to determine information about parameters to a prepared statement. Depending
|
362
|
+
* on the type of the prepared statement (call to stored procedured or a DML), only some information will be provided.
|
363
|
+
* The information that will always be provided is the direction of the parameters (input, output, or input-output).
|
364
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
365
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1;
|
366
|
+
* \param param A a_sqlany_bind_param structure that will be populated with information.
|
367
|
+
* \return 1 on success or 0 on failure.
|
368
|
+
*/
|
369
|
+
sacapi_bool sqlany_describe_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
|
370
|
+
|
371
|
+
/** Bind a user supplied buffer as a parameter to the prepared statement.
|
372
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
373
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
374
|
+
* \param param A a_sqlany_bind_param structure that describes the parameter that is to be bound.
|
375
|
+
* \return 1 on success or 0 on failure.
|
376
|
+
*/
|
377
|
+
sacapi_bool sqlany_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
|
378
|
+
|
379
|
+
/** Send data as part of a bound parameter.
|
380
|
+
* This function can be used to send a large amount of data for a bound parameter.
|
381
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
382
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
383
|
+
* \param buffer The data to be sent.
|
384
|
+
* \param size The number of bytes to send.
|
385
|
+
* \return 1 on success or 0 on failure.
|
386
|
+
* \sa sa_prepare()
|
387
|
+
*/
|
388
|
+
sacapi_bool sqlany_send_param_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, char * buffer, size_t size );
|
389
|
+
|
390
|
+
/** Reset a statement to its prepared state condition.
|
391
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
392
|
+
* \return 1 on success, 0 on failure.
|
393
|
+
* \sa sqlany_prepare()
|
394
|
+
*/
|
395
|
+
sacapi_bool sqlany_reset( a_sqlany_stmt * sqlany_stmt );
|
396
|
+
|
397
|
+
/** Get bound parameter info.
|
398
|
+
* This function retrieves information about the parameters that were bound using sqlany_bind_param().
|
399
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
400
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
401
|
+
* \param info A sqlany_bind_param_info buffer that will be populated with the bound parameter's information.
|
402
|
+
* \return 1 on success or 0 on failure.
|
403
|
+
* \sa sqlany_bind_param(), sqlany_describe_bind_param(), sqlany_prepare()
|
404
|
+
*/
|
405
|
+
sacapi_bool sqlany_get_bind_param_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param_info * info );
|
406
|
+
|
407
|
+
/** Execute a prepared statement.
|
408
|
+
* This function executes a prepared statement.
|
409
|
+
* The user can check if the statement returns a result set or not
|
410
|
+
* by checking the result of sqlany_num_cols().
|
411
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
412
|
+
* \return 1 if the statement is executed successfully, 0 otherwise.
|
413
|
+
* \sa sqlany_prepare()
|
414
|
+
* \par Quick Example:
|
415
|
+
* \code
|
416
|
+
// This example shows how to execute a statement that does not return a result set
|
417
|
+
a_sqlany_stmt * stmt;
|
418
|
+
int i;
|
419
|
+
a_sqlany_bind_param param;
|
420
|
+
|
421
|
+
stmt = sqlany_prepare( sqlany_conn, "insert into moe(id,value) values( ?,? )" );
|
422
|
+
if( stmt ) {
|
423
|
+
sqlany_describe_bind_param( stmt, 0, ¶m );
|
424
|
+
param.value.buffer = (char *)&i;
|
425
|
+
param.value.type = A_VAL32;
|
426
|
+
sqlany_bind_param( stmt, 0, ¶m );
|
427
|
+
|
428
|
+
sqlany_describe_bind_param( stmt, 1, ¶m );
|
429
|
+
param.value.buffer = (char *)&i;
|
430
|
+
param.value.type = A_VAL32;
|
431
|
+
sqlany_bind_param( stmt, 1, ¶m );
|
432
|
+
|
433
|
+
for( i = 0; i < 10; i++ ) {
|
434
|
+
if( !sqlany_execute( stmt ) ) {
|
435
|
+
// call sqlany_error()
|
436
|
+
}
|
437
|
+
}
|
438
|
+
sqlany_free_stmt( stmt );
|
439
|
+
}
|
440
|
+
* \endcode
|
441
|
+
*/
|
442
|
+
sacapi_bool sqlany_execute( a_sqlany_stmt * sqlany_stmt );
|
443
|
+
|
444
|
+
/** Executes a SQL statement and possibly returns a result set.
|
445
|
+
* This function executes the SQL statement specified by the string argument.
|
446
|
+
* This function is suitable if you want to prepare and then execute a statement,
|
447
|
+
* and can be used instead of calling sqlany_prepare() followed by sqlany_execute().
|
448
|
+
* This function can \b not be used for executing a SQL statement with parameters.
|
449
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
450
|
+
* \param sql_str A SQL string. The SQL string should not have parameters (i.e. '?' marks ).
|
451
|
+
* \return A statement handle if the function executes successfully, NULL otherwise.
|
452
|
+
* \sa sqlany_fetch_absolute(), sqlany_fetch_next(), sqlany_num_cols(), sqlany_get_column()
|
453
|
+
* \par Quick Example:
|
454
|
+
* \code
|
455
|
+
stmt = sqlany_execute_direct( sqlany_conn, "select * from employees" ) ) {
|
456
|
+
if( stmt ) {
|
457
|
+
while( sqlany_fetch_next( stmt ) ) {
|
458
|
+
int i;
|
459
|
+
for( i = 0; i < sqlany_num_cols( stmt ); i++ ) {
|
460
|
+
// Get column i data
|
461
|
+
}
|
462
|
+
}
|
463
|
+
sqlany_free_stmt( stmt );
|
464
|
+
}
|
465
|
+
* \endcode
|
466
|
+
*/
|
467
|
+
a_sqlany_stmt * sqlany_execute_direct( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
468
|
+
|
469
|
+
/** Fetch data at a specific row number in the result set.
|
470
|
+
* This function moves the current row in the result set to the row number specified and fetches the data at that row.
|
471
|
+
* \param sqlany_stmt A statement object that was executed by
|
472
|
+
* sqlany_execute() or sqlany_execute_direct().
|
473
|
+
* \param row_num The row number to be fetched. The first row is 1, the last row is -1.
|
474
|
+
* \return 1 if the fetch was successfully, 0 otherwise.
|
475
|
+
* \sa sqlany_execute_direct(), sqlany_execute(), sqlany_error(), sqlany_fetch_next()
|
476
|
+
*/
|
477
|
+
sacapi_bool sqlany_fetch_absolute( a_sqlany_stmt * sqlany_stmt, sacapi_i32 row_num );
|
478
|
+
|
479
|
+
/** Fetch the next row from the result set.
|
480
|
+
* This function fetches the next row from the result set.
|
481
|
+
* When the result object is first created, the current row
|
482
|
+
* pointer is set to before the first row (i.e. row 0).
|
483
|
+
* This function first advances the row pointer and then fetches
|
484
|
+
* the data at the new row.
|
485
|
+
* \param sqlany_stmt A statement object that was executed by
|
486
|
+
* sqlany_execute() or sqlany_execute_direct().
|
487
|
+
* \return 1 if a row was fetched successfully, 0 otherwise.
|
488
|
+
* \sa sqlany_fetch_absolute(), sqlany_execute_direct(), sqlany_execute(), sqlany_error()
|
489
|
+
*/
|
490
|
+
sacapi_bool sqlany_fetch_next( a_sqlany_stmt * sqlany_stmt );
|
491
|
+
|
492
|
+
/** Advance to the next result set in a multiple result set query.
|
493
|
+
* If a query (such as a call to a stored procedure) returns multiple result sets, then this function
|
494
|
+
* advances from the current result set to the next.
|
495
|
+
* \param sqlany_stmt A statement object that was executed by
|
496
|
+
* sqlany_execute() or sqlany_execute_direct().
|
497
|
+
* \return 1 if was successfully able to advance to the next result set, 0 otherwise.
|
498
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
499
|
+
* \par Quick Example:
|
500
|
+
* \code
|
501
|
+
stmt = sqlany_execute_direct( sqlany_conn, "call my_multiple_results_procedure()" );
|
502
|
+
if( result ) {
|
503
|
+
do {
|
504
|
+
while( sqlany_fetch_next( stmt ) ) {
|
505
|
+
// get column data
|
506
|
+
}
|
507
|
+
} while( sqlany_get_next_result( stmt ) );
|
508
|
+
sqlany_free_stmt( stmt );
|
509
|
+
}
|
510
|
+
* \endcode
|
511
|
+
*/
|
512
|
+
sacapi_bool sqlany_get_next_result( a_sqlany_stmt * sqlany_stmt );
|
513
|
+
|
514
|
+
/** Returns the number of rows affected by execution of the prepared statement.
|
515
|
+
* \param sqlany_stmt A statement that was prepared and executed successfully with no result set returned.
|
516
|
+
* \return The number of rows affected or -1 on failure.
|
517
|
+
* \sa sqlany_execute(), sqlany_execute_direct()
|
518
|
+
*/
|
519
|
+
sacapi_i32 sqlany_affected_rows( a_sqlany_stmt * sqlany_stmt );
|
520
|
+
|
521
|
+
/** Returns number of columns in the result set.
|
522
|
+
* \param sqlany_stmt A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
|
523
|
+
* \return The number of columns in the result set or -1 on a failure.
|
524
|
+
* \sa sqlany_execute_direct(), sqlany_prepare()
|
525
|
+
*/
|
526
|
+
sacapi_i32 sqlany_num_cols( a_sqlany_stmt * sqlany_stmt );
|
527
|
+
|
528
|
+
/** Returns number of rows in the result set.
|
529
|
+
* By default this function only returns an estimate. To return an exact count, users must set the ROW_COUNTS option
|
530
|
+
* on the connection. Refer to SQL Anywhere documentation for the SQL syntax to set this option.
|
531
|
+
* \param sqlany_stmt A statement object that was executed by
|
532
|
+
* sqlany_execute() or sqlany_execute_direct().
|
533
|
+
* \return The number rows in the result set. If the number of rows is an estimate, the number returned will be
|
534
|
+
* negative and the estimate is the absolute value of the returned integer. If the number of rows is exact, then the
|
535
|
+
* value returned will be positive.
|
536
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
537
|
+
*/
|
538
|
+
sacapi_i32 sqlany_num_rows( a_sqlany_stmt * sqlany_stmt );
|
539
|
+
|
540
|
+
/** Retrieve the data fetched for the specified column.
|
541
|
+
* This function fills the supplied buffer with the value fetched for the
|
542
|
+
* specified column. For A_BINARY and A_STRING * data types,
|
543
|
+
* buffer->buffer will point to an internal buffer associated with the result set.
|
544
|
+
* The content of the pointer buffer should not be relied on or altered
|
545
|
+
* as it will change when a new row is fetched or when the result set
|
546
|
+
* object is freed. Users should copy the data out of those pointers into their
|
547
|
+
* own buffers. The length field indicates the number of valid characters that
|
548
|
+
* buffer->buffer points to. The data returned in buffer->buffer is \b not
|
549
|
+
* null-terminated. This function fetches all of the returned value from the server.
|
550
|
+
* For example, if the column contains
|
551
|
+
* a 2GB blob, this function will attempt to allocate enough memory to hold that value.
|
552
|
+
* If this is not desired, sqlany_get_data() should be used instead.
|
553
|
+
* \param sqlany_stmt A statement object that was executed by
|
554
|
+
* sqlany_execute() or sqlany_execute_direct().
|
555
|
+
* \param col_index The number of the column to be retrieved.
|
556
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
557
|
+
* \param buffer A a_sqlany_data_value object that will be filled with the data fetched for column col_index.
|
558
|
+
* \return 1 on success or 0 for failure. A failure can happen if any of the parameters is invalid or if there is
|
559
|
+
* not enough memory to retrieve the full value from the server.
|
560
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
561
|
+
*/
|
562
|
+
sacapi_bool sqlany_get_column( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_value * buffer );
|
563
|
+
|
564
|
+
/** Retrieve the data fetched for the specified column into the supplied buffer memory.
|
565
|
+
* \param sqlany_stmt A statement object that was executed by
|
566
|
+
* sqlany_execute() or sqlany_execute_direct().
|
567
|
+
* \param col_index The number of the column to be retrieved.
|
568
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
569
|
+
* \param offset The starting offset of the data to get.
|
570
|
+
* \param buffer A buffer to be filled with the contents of the column. The buffer pointer must be aligned correctly
|
571
|
+
* for the data type that will be copied into it.
|
572
|
+
* \param size The size of the buffer in bytes. The function will fail
|
573
|
+
* if a size greater than 2GB is specified.
|
574
|
+
* \return The number of bytes successfully copied into the supplied buffer.
|
575
|
+
* This number will not exceed 2GB.
|
576
|
+
* 0 indicates no data remains to be copied. A -1 indicates a failure.
|
577
|
+
*/
|
578
|
+
sacapi_i32 sqlany_get_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, size_t offset, void * buffer, size_t size );
|
579
|
+
|
580
|
+
/** Retrieves information about the data that was fetched by the last fetch operation.
|
581
|
+
* \param sqlany_stmt A statement object that was executed by
|
582
|
+
* sqlany_execute() or sqlany_execute_direct().
|
583
|
+
* \param col_index The column number.
|
584
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
585
|
+
* \param buffer A data info buffer to be filled with the metadata about the data fetched.
|
586
|
+
* \return 1 on success, and 0 on failure. Failure is returned if any of the supplied parameters is invalid.
|
587
|
+
*/
|
588
|
+
sacapi_bool sqlany_get_data_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_info * buffer );
|
589
|
+
|
590
|
+
/** Retrieves column metadata information.
|
591
|
+
* This function fills the a_sqlany_column_info structure with information about the column.
|
592
|
+
* \param sqlany_stmt A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
|
593
|
+
* \param col_index The column number.
|
594
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
595
|
+
* \param buffer A column info structure to be filled with information about the column.
|
596
|
+
* \return 1 on success. Returns 0 if the column index is out of range,
|
597
|
+
* or if the statement does not return a result set.
|
598
|
+
* \sa sqlany_execute_direct(), sqlany_prepare()
|
599
|
+
*/
|
600
|
+
sacapi_bool sqlany_get_column_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_column_info * buffer );
|
601
|
+
|
602
|
+
/** Commit the current transaction.
|
603
|
+
* \param sqlany_conn The connection object on which the commit operation is to be performed.
|
604
|
+
* \return 1 on success, 0 otherwise.
|
605
|
+
* \sa sqlany_rollback()
|
606
|
+
*/
|
607
|
+
sacapi_bool sqlany_commit( a_sqlany_connection * sqlany_conn );
|
608
|
+
|
609
|
+
/** Rollback the current transaction.
|
610
|
+
* \param sqlany_conn The connection object on which the rollback operation is to be performed.
|
611
|
+
* \return 1 on success, 0 otherwise.
|
612
|
+
* \sa sqlany_commit()
|
613
|
+
*/
|
614
|
+
sacapi_bool sqlany_rollback( a_sqlany_connection * sqlany_conn );
|
615
|
+
|
616
|
+
/** Returns the current client version.
|
617
|
+
* This function fills the buffer passed with the major, minor, patch, and build number of the client library.
|
618
|
+
* The buffer will be null-terminated.
|
619
|
+
* \param buffer The buffer to be filled with the client version.
|
620
|
+
* \param len The length of the buffer.
|
621
|
+
* \return 1 on success; 0 otherwise
|
622
|
+
*/
|
623
|
+
sacapi_bool sqlany_client_version( char * buffer, size_t len );
|
624
|
+
|
625
|
+
/** Retrieves the last error code and message.
|
626
|
+
* This function can be used to retrieve the last error code and message stored in the connection object.
|
627
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
628
|
+
* \param buffer A buffer that will be filled with the error message.
|
629
|
+
* \param size Size of the supplied buffer.
|
630
|
+
* \return The last error code. Positive values are warnings, negative values are errors, and 0 is success.
|
631
|
+
*/
|
632
|
+
sacapi_i32 sqlany_error( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
633
|
+
|
634
|
+
/** Retrieve the current SQL state.
|
635
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
636
|
+
* \param buffer A buffer that will be filled with the SQL state.
|
637
|
+
* \param size The size of the buffer.
|
638
|
+
* \return The number of bytes copied into the buffer.
|
639
|
+
*/
|
640
|
+
size_t sqlany_sqlstate( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
641
|
+
|
642
|
+
/** Clears the last stored error code
|
643
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
644
|
+
*/
|
645
|
+
void sqlany_clear_error( a_sqlany_connection * sqlany_conn );
|
646
|
+
|
647
|
+
#if defined(__cplusplus)
|
648
|
+
}
|
649
|
+
#endif
|
650
|
+
|
651
|
+
/** \example connecting.cpp
|
652
|
+
* This is an example of how to create a connection object and connect with it to SQL Anywhere.
|
653
|
+
*/
|
654
|
+
|
655
|
+
/** \example fetching_a_result_set.cpp
|
656
|
+
* This example shows how to fetch data from a result set.
|
657
|
+
*/
|
658
|
+
|
659
|
+
/** \example preparing_statements.cpp
|
660
|
+
* This example shows how to prepare and execute a statement.
|
661
|
+
*/
|
662
|
+
|
663
|
+
/** \example fetching_multiple_from_sp.cpp
|
664
|
+
* This example shows how to fetch multiple result sets from a stored procedure.
|
665
|
+
*/
|
666
|
+
|
667
|
+
/** \example send_retrieve_part_blob.cpp
|
668
|
+
* This example shows how to insert a blob in chunks and retrieve it in chunks too.
|
669
|
+
*/
|
670
|
+
|
671
|
+
/** \example send_retrieve_full_blob.cpp
|
672
|
+
* This example shows how to insert and retrieve a blob in one chunk .
|
673
|
+
*/
|
674
|
+
|
675
|
+
/** \example dbcapi_isql.cpp
|
676
|
+
* This example shows how to write an ISQL application using dbcapi.
|
677
|
+
*/
|
678
|
+
|
679
|
+
#endif
|