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