forked from mdcnz/sqlanywhere
/
sacapi.h
1393 lines (1287 loc) · 60.2 KB
/
sacapi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ***************************************************************************
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
// While not a requirement of the license, if you do modify this file, we
// would appreciate hearing about it. Please email
// sqlany_interfaces@sap.com
//
// ***************************************************************************
#ifndef SACAPI_H
#define SACAPI_H
/** \mainpage SQL Anywhere C API
*
* \section intro_sec Introduction
* The SQL Anywhere C application programming interface (API) is a data
* access API for the C / C++ languages. The C API specification defines
* a set of functions, variables and conventions that provide a consistent
* database interface independent of the actual database being used. Using
* the SQL Anywhere C API, your C / C++ applications have direct access to
* SQL Anywhere database servers.
*
* The SQL Anywhere C API simplifies the creation of C and C++ wrapper
* drivers for several interpreted programming languages including PHP,
* Perl, Python, and Ruby. The SQL Anywhere C API is layered on top of the
* DBLIB package and it was implemented with Embedded SQL.
*
* Although it is not a replacement for DBLIB, the SQL Anywhere C API
* simplifies the creation of applications using C and C++. You do not need
* an advanced knowledge of embedded SQL to use the SQL Anywhere C API.
*
* \section distribution Distribution of the API
* The API is built as a dynamic link library (DLL) (\b dbcapi.dll) on
* Microsoft Windows systems and as a shared object (\b libdbcapi.so) on
* Unix systems. The DLL is statically linked to the DBLIB package of the
* SQL Anywhere version on which it is built. When the dbcapi.dll file is
* loaded, the corresponding dblibX.dll file is loaded by the operating
* system. Applications using dbcapi.dll can either link directly to it
* or load it dynamically. For more information about dynamic loading, see
* the section "Dynamically Loading the DLL".
*
* Descriptions of the SQL Anywhere C API data types and entry points are
* provided in the main header file (\b sacapi.h).
*
* \section dynamic_loading Dynamically Loading the DLL
* The code to dynamically load the DLL is contained in the sacapidll.c
* source file. Applications must use the sacapidll.h header file and
* include the source code in sacapidll.c. You can use the
* sqlany_initialize_interface method to dynamically load the DLL and
* look up the entry points. Examples are provided with the SQL Anywhere
* installation.
*
* \section threading_support Threading Support
* The C API library is thread-unaware, meaning that the library does not
* perform any tasks that require mutual exclusion. In order to allow the
* library to work in threaded applications, there is only one rule to
* follow: <b>no more than one request is allowed on a single connection </b>.
* With this rule, the application is responsible for doing mutual exclusion
* when accessing any connection-specific resource. This includes
* connection handles, prepared statements, and result set objects.
*
* \version 2.0
*/
/** \file sacapi.h
* Main API header file.
* This file describes all the data types and entry points of the API.
*/
/** Version 1 was the initial version of the C/C++ API.
*
* You must define _SACAPI_VERSION as 1 or higher for this functionality.
*/
#define SQLANY_API_VERSION_1 1
/** Version 2 introduced the "_ex" functions and the ability to cancel requests.
*
* You must define _SACAPI_VERSION as 2 or higher for this functionality.
*/
#define SQLANY_API_VERSION_2 2
/** Version 3 introduced the "callback" function.
*
* You must define _SACAPI_VERSION as 3 or higher for this functionality.
*/
#define SQLANY_API_VERSION_3 3
/** Version 4 introduced NCHAR support and wide inserts.
*
* You must define _SACAPI_VERSION as 4 or higher for this functionality.
*/
#define SQLANY_API_VERSION_4 4
/** Version 5 introduced a way to reset sent data through sqlany_send_param_data()
* and the A_FLOAT data type
*
* You must define _SACAPI_VERSION as 5 or higher for this functionality.
*/
#define SQLANY_API_VERSION_5 5
/** Version 6 introduced a way to set/get autocommit
*
* You must define _SACAPI_VERSION as 6 or higher for this functionality.
*/
#define SQLANY_API_VERSION_6 6
/** If the command line does not specify which version to build,
* then build the latest version.
*/
#ifndef _SACAPI_VERSION
#define _SACAPI_VERSION SQLANY_API_VERSION_6
#endif
/** Returns the minimal error buffer size.
*/
#define SACAPI_ERROR_SIZE 512
#if defined(__cplusplus)
extern "C" {
#endif
/** A handle to an interface context
*/
typedef struct a_sqlany_interface_context a_sqlany_interface_context;
/** A handle to a connection object
*/
typedef struct a_sqlany_connection a_sqlany_connection;
/** A handle to a statement object
*/
typedef struct a_sqlany_stmt a_sqlany_stmt;
/** A portable 32-bit signed value */
typedef signed int sacapi_i32;
/** A portable 32-bit unsigned value */
typedef unsigned int sacapi_u32;
/** 64-bit signed integer */
typedef signed long long sacapi_i64;
#if defined(DBCAPI_STRICT)
/** A boolean type for strict type checking */
typedef enum sacapi_bool {
sacapi_false = 0,
sacapi_true = 1
};
#else
/** A boolean type that is portable */
typedef sacapi_i32 sacapi_bool;
#define sacapi_false 0
#define sacapi_true 1
#endif
// TODO:Character set issues
/** The run-time calling convention in use (Windows only).
*/
#ifdef _WIN32
#define _sacapi_entry_ __stdcall
#endif
#ifndef _sacapi_entry_
#define _sacapi_entry_
#endif
/** Callback function type
*/
#define SQLANY_CALLBACK _sacapi_entry_
/** Parameter type for sqlany_register_callback function used to specify the address of the callback routine.
*/
typedef int (SQLANY_CALLBACK *SQLANY_CALLBACK_PARM)();
typedef void (SQLANY_CALLBACK *SACAPI_CALLBACK_PARM)( a_sqlany_stmt * stmt,
const char * warning_message,
sacapi_i32 warning_code,
const char * sql_state,
void * user_data );
/** Specifies the data type being passed in or retrieved.
*/
typedef enum a_sqlany_data_type
{
/// Invalid data type.
A_INVALID_TYPE,
/// Binary data. Binary data is treated as-is and no character set conversion is performed.
A_BINARY,
/// String data. The data where character set conversion is performed.
A_STRING,
/// Double data. Includes float values.
A_DOUBLE,
/// 64-bit integer.
A_VAL64,
/// 64-bit unsigned integer.
A_UVAL64,
/// 32-bit integer.
A_VAL32,
/// 32-bit unsigned integer.
A_UVAL32,
/// 16-bit integer.
A_VAL16,
/// 16-bit unsigned integer.
A_UVAL16,
/// 8-bit integer.
A_VAL8,
/// 8-bit unsigned integer.
A_UVAL8
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_5
,
//// Float precision data.
A_FLOAT
#endif
} a_sqlany_data_type;
/** Returns a description of the attributes of a data value.
*
* To view examples of the a_sqlany_data_value structure in use,
* see any of the following sample files in the <dfn>sdk\\dbcapi\\examples</dfn> directory
* of your SQL Anywhere installation:
*
* <ul>
* <li>dbcapi_isql.cpp
* <li>fetching_a_result_set.cpp
* <li>send_retrieve_full_blob.cpp
* <li>preparing_statements.cpp
* </ul>
*/
typedef struct a_sqlany_data_value
{
/// A pointer to user supplied buffer of data.
char * buffer;
/// The size of the buffer.
size_t buffer_size;
/// A pointer to the number of valid bytes in the buffer. This value must be less than buffer_size.
size_t * length;
/// The type of the data
a_sqlany_data_type type;
/// A pointer to indicate whether the last fetched data is NULL.
sacapi_bool * is_null;
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_4
/// Indicates whether the buffer value is an pointer to the actual value.
sacapi_bool is_address;
#endif
} a_sqlany_data_value;
/** A data direction enumeration.
*/
typedef enum a_sqlany_data_direction
{
/// Invalid data direction.
DD_INVALID = 0x0,
/// Input-only host variables.
DD_INPUT = 0x1,
/// Output-only host variables.
DD_OUTPUT = 0x2,
/// Input and output host variables.
DD_INPUT_OUTPUT = 0x3
} a_sqlany_data_direction;
/** A bind parameter structure used to bind parameter and prepared statements.
*
* To view examples of the a_sqlany_bind_param structure in use,
* see any of the following sample files in the <dfn>sdk\\dbcapi\\examples</dfn> directory
* of your SQL Anywhere installation:
*
* <ul>
* <li>preparing_statements.cpp
* <li>send_retrieve_full_blob.cpp
* <li>send_retrieve_part_blob.cpp
* </ul>
* \sa sqlany_execute()
*/
typedef struct a_sqlany_bind_param
{
/// The direction of the data. (input, output, input_output)
a_sqlany_data_direction direction;
/// The actual value of the data.
a_sqlany_data_value value;
/// Name of the bind parameter. This is only used by sqlany_describe_bind_param().
char *name;
} a_sqlany_bind_param;
/** An enumeration of the native types of values as described by the server.
*
* The value types correspond to the embedded SQL data types.
*
* \hideinitializers
* \sa sqlany_get_column_info(), a_sqlany_column_info
*/
typedef enum a_sqlany_native_type
{
/// No data type.
DT_NOTYPE = 0,
/// Null-terminated character string that is a valid date.
DT_DATE = 384,
/// Null-terminated character string that is a valid time.
DT_TIME = 388,
/// Null-terminated character string that is a valid timestamp.
DT_TIMESTAMP = 392,
/// Varying length character string, in the CHAR character set, with a two-byte length field. The maximum length is 32765 bytes. When sending data, you must set the length field. When fetching data, the database server sets the length field. The data is not null-terminated or blank-padded.
DT_VARCHAR = 448,
/// Fixed-length blank-padded character string, in the CHAR character set. The maximum length, specified in bytes, is 32767. The data is not null-terminated.
DT_FIXCHAR = 452,
/// Long varying length character string, in the CHAR character set.
DT_LONGVARCHAR = 456,
/// Null-terminated character string, in the CHAR character set. The string is blank-padded if the database is initialized with blank-padded strings.
DT_STRING = 460,
/// 8-byte floating-point number.
DT_DOUBLE = 480,
/// 4-byte floating-point number.
DT_FLOAT = 482,
/// Packed decimal number (proprietary format).
DT_DECIMAL = 484,
/// 32-bit signed integer.
DT_INT = 496,
/// 16-bit signed integer.
DT_SMALLINT = 500,
/// Varying length binary data with a two-byte length field. The maximum length is 32765 bytes. When supplying information to the database server, you must set the length field. When fetching information from the database server, the server sets the length field.
DT_BINARY = 524,
/// Long binary data.
DT_LONGBINARY = 528,
/// 8-bit signed integer.
DT_TINYINT = 604,
/// 64-bit signed integer.
DT_BIGINT = 608,
/// 32-bit unsigned integer.
DT_UNSINT = 612,
/// 16-bit unsigned integer.
DT_UNSSMALLINT = 616,
/// 64-bit unsigned integer.
DT_UNSBIGINT = 620,
/// 8-bit signed integer.
DT_BIT = 624,
/// Null-terminated character string, in the NCHAR character set. The string is blank-padded if the database is initialized with blank-padded strings.
DT_NSTRING = 628,
/// Fixed-length blank-padded character string, in the NCHAR character set. The maximum length, specified in bytes, is 32767. The data is not null-terminated.
DT_NFIXCHAR = 632,
/// Varying length character string, in the NCHAR character set, with a two-byte length field. The maximum length is 32765 bytes. When sending data, you must set the length field. When fetching data, the database server sets the length field. The data is not null-terminated or blank-padded.
DT_NVARCHAR = 636,
/// Long varying length character string, in the NCHAR character set.
DT_LONGNVARCHAR = 640
} a_sqlany_native_type;
/** Returns column metadata information.
*
* sqlany_get_column_info() can be used to populate this structure.
*
* To view an example of the a_sqlany_column_info structure in use,
* see the following sample file in the <dfn>sdk\\dbcapi\\examples</dfn>
* directory of your SQL Anywhere installation.
*
* <ul>
* <li>dbcapi_isql.cpp
* </ul>
*/
typedef struct a_sqlany_column_info
{
/// The name of the column (null-terminated).
/// The string can be referenced as long as the result set object is not freed.
char * name;
/// The column data type.
a_sqlany_data_type type;
/// The native type of the column in the database.
a_sqlany_native_type native_type;
/// The precision.
unsigned short precision;
/// The scale.
unsigned short scale;
/// The maximum size a data value in this column can take.
size_t max_size;
/// Indicates whether a value in the column can be null.
sacapi_bool nullable;
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_4
/// The name of the table (null-terminated).
/// The string can be referenced as long as the result set object is not freed.
char * table_name;
/// The name of the owner (null-terminated).
/// The string can be referenced as long as the result set object is not freed.
char * owner_name;
/// Indicates whether the column is bound to a user buffer.
sacapi_bool is_bound;
/// Information about the bound column.
a_sqlany_data_value binding;
#endif
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_6
/// For systems that support both alias name and column name (internal use only).
char * column_name;
#endif
} a_sqlany_column_info;
/** Gets information about the currently bound parameters.
*
* sqlany_get_bind_param_info() can be used to populate this structure.
*
* To view examples of the a_sqlany_bind_param_info structure in use,
* see any of the following sample files in the <dfn>sdk\\dbcapi\\examples</dfn>
* directory of your SQL Anywhere installation.
*
* <ul>
* <li>preparing_statements.cpp
* <li>send_retrieve_full_blob.cpp
* <li>send_retrieve_part_blob.cpp
* </ul>
* \sa sqlany_execute()
*/
typedef struct a_sqlany_bind_param_info
{
/// A pointer to the name of the parameter.
char * name;
/// The direction of the parameter.
a_sqlany_data_direction direction;
/// Information about the bound input value.
a_sqlany_data_value input_value;
/// Information about the bound output value.
a_sqlany_data_value output_value;
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_4
/// The native type of the column in the database.
a_sqlany_native_type native_type;
/// The precision.
unsigned short precision;
/// The scale.
unsigned short scale;
/// The maximum size a data value in this column can take.
size_t max_size;
#endif
} a_sqlany_bind_param_info;
/** Returns metadata information about a column value in a result set.
*
* sqlany_get_data_info() can be used
* to populate this structure with information about what was last retrieved by a fetch operation.
*
* To view an example of the a_sqlany_data_info structure in use,
* see the following sample file in the <dfn>sdk\\dbcapi\\examples</dfn> directory
* of your SQL Anywhere installation:
*
* <ul>
* <li>send_retrieve_part_blob.cpp
* </ul>
* \sa sqlany_get_data_info()
*/
typedef struct a_sqlany_data_info
{
/// The type of the data in the column.
a_sqlany_data_type type;
/// Indicates whether the last fetched data is NULL.
/// This field is only valid after a successful fetch operation.
sacapi_bool is_null;
/// The total number of bytes available to be fetched.
/// This field is only valid after a successful fetch operation.
size_t data_size;
} a_sqlany_data_info;
/** An enumeration of the callback types.
*
* The callback types correspond to the embedded SQL callback types.
*
* \hideinitializers
* \sa sqlany_register_callback()
*/
typedef enum a_sqlany_callback_type {
/// This function is called just before a database request is sent to the server.
/// CALLBACK_START is used only on Windows operating systems.
CALLBACK_START = 0,
/// This function is called repeatedly by the interface library while the database server or client library is busy processing your database request.
CALLBACK_WAIT,
/// This function is called after the response to a database request has been received by the DBLIB interface DLL.
/// CALLBACK_FINISH is used only on Windows operating systems.
CALLBACK_FINISH,
/// This function is called when messages are received from the server during the processing of a request.
/// Messages can be sent to the client application from the database server using the SQL MESSAGE statement.
/// Messages can also be generated by long running database server statements.
CALLBACK_MESSAGE = 7,
/// This function is called when the database server is about to drop a connection because of a liveness timeout,
/// through a DROP CONNECTION statement, or because the database server is being shut down.
/// The connection name conn_name is passed in to allow you to distinguish between connections.
/// If the connection was not named, it has a value of NULL.
CALLBACK_CONN_DROPPED,
/// This function is called once for each debug message and is passed a null-terminated string containing the text of the debug message.
/// A debug message is a message that is logged to the LogFile file. In order for a debug message to be passed to this callback, the LogFile
/// connection parameter must be used. The string normally has a newline character (\n) immediately before the terminating null character.
CALLBACK_DEBUG_MESSAGE,
/// This function is called when a file transfer requires validation.
/// If the client data transfer is being requested during the execution of indirect statements such as from within a stored procedure,
/// the client library will not allow a transfer unless the client application has registered a validation callback and the response from
/// the callback indicates that the transfer may take place.
CALLBACK_VALIDATE_FILE_TRANSFER
} a_sqlany_callback_type;
/** An enumeration of the message types for the MESSAGE callback.
*
* \hideinitializers
* \sa sqlany_register_callback()
*/
typedef enum a_sqlany_message_type {
/// The message type was INFO.
MESSAGE_TYPE_INFO = 0,
/// The message type was WARNING.
MESSAGE_TYPE_WARNING,
/// The message type was ACTION.
MESSAGE_TYPE_ACTION,
/// The message type was STATUS.
MESSAGE_TYPE_STATUS,
/// The message type was PROGRESS.
/// This type of message is generated by long running database server statements such as BACKUP DATABASE and LOAD TABLE.
MESSAGE_TYPE_PROGRESS
} a_sqlany_message_type;
/** Initializes the interface.
*
* The following example demonstrates how to initialize the SQL Anywhere C API DLL:
*
* <pre>
* sacapi_u32 api_version;
* if( sqlany_init( "PHP", SQLANY_API_VERSION_1, &api_version ) ) {
* printf( "Interface initialized successfully!\n" );
* } else {
* printf( "Failed to initialize the interface! Supported version=%d\n", api_version );
* }
* </pre>
*
* \param app_name A string that names the application that is using the API. For example, "PHP", "PERL", or "RUBY".
* \param api_version The version of the compiled application.
* \param version_available An optional argument to return the maximum supported API version.
* \return sacapi_true on success, sacapi_false otherwise
* \sa sqlany_fini()
*/
sacapi_bool sqlany_init( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
/** Initializes the interface using a context.
*
* \param app_name A string that names the API used, for example "PHP", "PERL", or "RUBY".
* \param api_version The current API version that the application is using.
* This should normally be one of the SQLANY_API_VERSION_* macros
* \param version_available An optional argument to return the maximum API version that is supported.
* \return a context object on success and NULL on failure.
* \sa sqlany_fini_ex()
*/
a_sqlany_interface_context *sqlany_init_ex( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
#endif
/** Finalizes the interface.
*
* Frees any resources allocated by the API.
*
* \sa sqlany_init()
*/
void sqlany_fini();
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
/** Finalize the interface that was created using the specified context.
* Frees any resources allocated by the API.
* \param context A context object that was returned from sqlany_init_ex()
* \sa sqlany_init_ex()
*/
void sqlany_fini_ex( a_sqlany_interface_context *context );
#endif
/** Creates a connection object.
*
* You must create an API connection object before establishing a database connection. Errors can be retrieved
* from the connection object. Only one request can be processed on a connection at a time. In addition,
* not more than one thread is allowed to access a connection object at a time. Undefined behavior or a failure
* occurs when multiple threads attempt to access a connection object simultaneously.
*
* \return A connection object
* \sa sqlany_connect(), sqlany_disconnect()
*/
a_sqlany_connection * sqlany_new_connection( void );
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
/** Creates a connection object using a context.
* An API connection object needs to be created before a database connection is established. Errors can be retrieved
* from the connection object. Only one request can be processed on a connection at a time. In addition,
* not more than one thread is allowed to access a connection object at a time. If multiple threads attempt
* to access a connection object simultaneously, then undefined behavior/crashes will occur.
* \param context A context object that was returned from sqlany_init_ex()
* \return A connection object
* \sa sqlany_connect(), sqlany_disconnect(), sqlany_init_ex()
*/
a_sqlany_connection *sqlany_new_connection_ex( a_sqlany_interface_context *context );
#endif
/** Frees the resources associated with a connection object.
*
* \param sqlany_conn A connection object created with sqlany_new_connection().
* \sa sqlany_new_connection()
*/
void sqlany_free_connection( a_sqlany_connection *sqlany_conn );
/** Creates a connection object based on a supplied DBLIB SQLCA pointer.
*
* \param arg A void * pointer to a DBLIB SQLCA object.
* \return A connection object.
* \sa sqlany_new_connection(), sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
*/
a_sqlany_connection * sqlany_make_connection( void * arg );
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
/** Creates a connection object based on a supplied DBLIB SQLCA pointer and context.
* \param context A valid context object that was created by sqlany_init_ex()
* \param arg A void * pointer to a DBLIB SQLCA object.
* \return A connection object.
* \sa sqlany_init_ex(), sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
*/
a_sqlany_connection *sqlany_make_connection_ex( a_sqlany_interface_context *context, void *arg );
#endif
/** Creates a connection to a SQL Anywhere database server using the supplied connection object and connection string.
*
* The supplied connection object must first be allocated using sqlany_new_connection().
*
* The following example demonstrates how to retrieve the error code of a failed connection attempt:
*
* <pre>
* a_sqlany_connection * sqlany_conn;
* sqlany_conn = sqlany_new_connection();
* if( !sqlany_connect( sqlany_conn, "uid=dba;pwd=passwd" ) ) {
* char reason[SACAPI_ERROR_SIZE];
* sacapi_i32 code;
* code = sqlany_error( sqlany_conn, reason, sizeof(reason) );
* printf( "Connection failed. Code: %d Reason: %s\n", code, reason );
* } else {
* printf( "Connected successfully!\n" );
* sqlany_disconnect( sqlany_conn );
* }
* sqlany_free_connection( sqlany_conn );
* </pre>
*
* \param sqlany_conn A connection object created by sqlany_new_connection().
* \param str A SQL Anywhere connection string.
* \return sacapi_true if the connection is established successfully or sacapi_false when the connection fails. Use sqlany_error() to
* retrieve the error code and message.
* \sa sqlany_new_connection(), sqlany_error()
*/
sacapi_bool sqlany_connect( a_sqlany_connection * sqlany_conn, const char * str );
/** Disconnects an already established SQL Anywhere connection.
*
* All uncommitted transactions are rolled back.
*
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_connect(), sqlany_new_connection()
*/
sacapi_bool sqlany_disconnect( a_sqlany_connection * sqlany_conn );
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
/** Cancel an outstanding request on a connection.
* This function can be used to cancel an outstanding request on a specific connection.
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
*/
void sqlany_cancel( a_sqlany_connection * sqlany_conn );
#endif
/** Executes the supplied SQL statement immediately without returning a result set.
*
* This function is useful for SQL statements that do not return a result set.
*
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
* \param sql A string representing the SQL statement to be executed.
* \return sacapi_true on success or sacapi_false on failure.
*/
sacapi_bool sqlany_execute_immediate( a_sqlany_connection * sqlany_conn, const char * sql );
/** Prepares a supplied SQL string.
*
* Execution does not happen until sqlany_execute() is
* called. The returned statement object should be freed using sqlany_free_stmt().
*
* The following statement demonstrates how to prepare a SELECT SQL string:
*
* <pre>
* char * str;
* a_sqlany_stmt * stmt;
*
* str = "select * from employees where salary >= ?";
* stmt = sqlany_prepare( sqlany_conn, str );
* if( stmt == NULL ) {
* // Failed to prepare statement, call sqlany_error() for more info
* }
* </pre>
*
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
* \param sql_str The SQL statement to be prepared.
* \return A handle to a SQL Anywhere statement object. The statement object can be used by sqlany_execute()
* to execute the statement.
* \sa sqlany_free_stmt(), sqlany_connect(), sqlany_execute(), sqlany_num_params(), sqlany_describe_bind_param(), sqlany_bind_param()
*/
a_sqlany_stmt * sqlany_prepare( a_sqlany_connection * sqlany_conn, const char * sql_str );
/** Frees resources associated with a prepared statement object.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare() or sqlany_execute_direct().
* \sa sqlany_prepare(), sqlany_execute_direct()
*/
void sqlany_free_stmt( a_sqlany_stmt * sqlany_stmt );
/** Returns the number of parameters expected for a prepared statement.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \return The number of parameters in the statement.
* \sa sqlany_prepare()
*/
sacapi_i32 sqlany_num_params( a_sqlany_stmt * sqlany_stmt );
/** Describes the bind parameters of a prepared statement.
*
* This function allows the caller to determine information about prepared statement parameters. The type of prepared
* statement, stored procedured or a DML, determines the amount of information provided. The direction of the parameters
* (input, output, or input-output) are always provided.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \param index The index of the parameter. This number must be between 0 and sqlany_num_params() - 1.
* \param param An a_sqlany_bind_param structure that is populated with information.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_param(), sqlany_prepare()
*/
sacapi_bool sqlany_describe_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
/** Bind a user-supplied buffer as a parameter to the prepared statement.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \param index The index of the parameter. This number must be between 0 and sqlany_num_params() - 1.
* \param param An a_sqlany_bind_param structure description of the parameter to be bound.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_describe_bind_param()
*/
sacapi_bool sqlany_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
/** Sends data as part of a bound parameter.
*
* This method can be used to send a large amount of data for a bound parameter in chunks.
* This method can be used only when the batch size is 1.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
* \param buffer The data to be sent.
* \param size The number of bytes to send.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_prepare()
*/
sacapi_bool sqlany_send_param_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, char * buffer, size_t size );
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_5
/** Clears param data that was previously been set using \sa sqlany_send_param_data()
*
* This method can be used to clear data that was previously been sent using sqlany_send_param_data()
* If no param data was previously sent, nothing is changed.
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params() - 1.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_prepare(), sqlany_send_param_data()
*/
sacapi_bool sqlany_reset_param_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index );
/** Retrieves the length of the last error message stored in the connection object
* including the NULL terminator. If there is no error, 0 is returned.
*
* \param sqlany_conn A connection object returned from sqlany_new_connection().
* \return The length of the last error message including the NULL terminator.
*/
size_t sqlany_error_length( a_sqlany_connection * sqlany_conn );
#endif
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_4
/** Sets the size of the row array for a batch execute.
*
* The batch size is used only for an INSERT statement. The default batch size is 1.
* A value greater than 1 indicates a wide insert.
*
* \param sqlany_stmt A valid statement object.
* \param num_rows The number of rows for batch execution. The value must be 1 or greater.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_param(), sqlany_get_batch_size()
*/
sacapi_bool sqlany_set_batch_size( a_sqlany_stmt * sqlany_stmt, sacapi_u32 num_rows );
/** Sets the bind type of parameters.
*
* The default value is 0, which indicates column-wise binding. A non-zero value indicates
* row-wise binding and specifies the byte size of the data structure that stores the row.
* The parameter is bound to the first element in a contiguous array of values. The address
* offset to the next element is computed based on the bind type:
*
* <ul>
* <li>Column-wise binding - the byte size of the parameter type</li>
* <li>Row-wise binding - the row_size</li>
* </ul>
*
* \param sqlany_stmt A statement object returned by the successful execution of sqlany_prepare().
* \param row_size The byte size of the row. A value of 0 indicates column-wise binding and a positive value indicates row-wise binding.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_param()
*/
sacapi_bool sqlany_set_param_bind_type( a_sqlany_stmt * sqlany_stmt, size_t row_size );
/** Retrieves the size of the row array for a batch execute.
*
* \param sqlany_stmt A valid statement object.
* \return The size of the row array.
* \sa sqlany_set_batch_size()
*/
sacapi_u32 sqlany_get_batch_size( a_sqlany_stmt * sqlany_stmt );
/** Sets the size of the row set to be fetched by the sqlany_fetch_absolute() and sqlany_fetch_next() functions.
*
* The default size of the row set is 1. Specifying num_rows to be a value greater than 1 indicates a wide fetch.
*
* \param sqlany_stmt A valid statement object.
* \param num_rows The size of the row set. The value must be 1 or greater.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_column(), sqlany_fetch_absolute(), sqlany_fetch_next(), sqlany_get_rowset_size()
*/
sacapi_bool sqlany_set_rowset_size( a_sqlany_stmt * sqlany_stmt, sacapi_u32 num_rows );
/** Retrieves the size of the row set to be fetched by the sqlany_fetch_absolute() and sqlany_fetch_next() functions.
*
* \param sqlany_stmt A valid statement object.
* \return The size of the row set, or 0 if the statement does not return a result set.
* \sa sqlany_set_rowset_size(), sqlany_fetch_absolute(), sqlany_fetch_next()
*/
sacapi_u32 sqlany_get_rowset_size( a_sqlany_stmt * sqlany_stmt );
/** Sets the bind type of columns.
*
* The default value is 0, which indicates column-wise binding. A non-zero value indicates
* row-wise binding and specifies the byte size of the data structure that stores the row.
* The column is bound to the first element in a contiguous array of values. The address
* offset to the next element is computed based on the bind type:
*
* <ul>
* <li>Column-wise binding - the byte size of the column type</li>
* <li>Row-wise binding - the row_size</li>
* </ul>
*
* \param sqlany_stmt A valid statement object.
* \param row_size The byte size of the row. A value of 0 indicates column-wise binding and a positive value indicates row-wise binding.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_column()
*/
sacapi_bool sqlany_set_column_bind_type( a_sqlany_stmt * sqlany_stmt, sacapi_u32 row_size );
/** Binds a user-supplied buffer as a result set column to the prepared statement.
*
* If the size of the fetched row set is greater than 1, the buffer must be large enough to
* hold the data of all of the rows in the row set. This function can also be used to clear the
* binding of a column by specifying value to be NULL.
*
* \param sqlany_stmt A valid statement object.
* \param index The index of the column. This number must be between 0 and sqlany_num_cols() - 1.
* \param value An a_sqlany_data_value structure describing the bound buffers, or NULL to clear previous binding information.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_clear_column_bindings(), sqlany_set_rowset_size()
*/
sacapi_bool sqlany_bind_column( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_data_value * value );
/** Removes all column bindings defined using sqlany_bind_column().
*
* \param sqlany_stmt A valid statement object.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_column()
*/
sacapi_bool sqlany_clear_column_bindings( a_sqlany_stmt * sqlany_stmt );
/** Returns the number of rows fetched.
*
* In general, the number of rows fetched is equal to the size specified by the sqlany_set_rowset_size() function. The
* exception is when there are fewer rows from the fetch position to the end of the result set than specified, in which
* case the number of rows fetched is smaller than the specified row set size. The function returns -1 if the last fetch
* was unsuccessful or if the statement has not been executed. The function returns 0 if the statement has been executed
* but no fetching has been done.
*
* \param sqlany_stmt A valid statement object.
* \return The number of rows fetched or -1 if a cursor is not open.
* \sa sqlany_bind_column(), sqlany_fetch_next(), sqlany_fetch_absolute()
*/
sacapi_i32 sqlany_fetched_rows( a_sqlany_stmt * sqlany_stmt );
/** Sets the current row in the fetched row set.
*
* When a sqlany_fetch_absolute() or sqlany_fetch_next() function is executed, a row set
* is created and the current row is set to be the first row in the row set. The functions
* sqlany_get_column(), sqlany_get_data(), sqlany_get_data_info() are used to retrieve data
* at the current row.
*
* \param sqlany_stmt A valid statement object.
* \param row_num The row number within the row set. The valid values are from 0 to sqlany_fetched_rows() - 1.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_set_rowset_size(), sqlany_get_column(), sqlany_get_data(), sqlany_get_data_info(), sqlany_fetch_absolute(), sqlany_fetch_next()
*/
sacapi_bool sqlany_set_rowset_pos( a_sqlany_stmt * sqlany_stmt, sacapi_u32 row_num );
#endif
/** Resets a statement to its prepared state condition.
*
* \param sqlany_stmt A valid statement object.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_prepare()
*/
sacapi_bool sqlany_reset( a_sqlany_stmt * sqlany_stmt );
/** Retrieves information about the parameters that were bound using sqlany_bind_param().
*
* \param sqlany_stmt A valid statement object.
* \param index The index of the parameter. This number should be between 0 and sqlany_num_params() - 1.
* \param info A sqlany_bind_param_info buffer to be populated with the bound parameter's information.
* \return sacapi_true when successful or sacapi_false when unsuccessful.
* \sa sqlany_bind_param(), sqlany_describe_bind_param(), sqlany_prepare()
*/
sacapi_bool sqlany_get_bind_param_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param_info * info );
/** Executes a prepared statement.
*
* You can use sqlany_num_cols() to verify if the executed statement returned a result set.
*
* The following example shows how to execute a statement that does not return a result set:
*
* <pre>
* a_sqlany_stmt * stmt;
* int i;
* a_sqlany_bind_param param;
*
* stmt = sqlany_prepare( sqlany_conn, "insert into moe(id,value) values( ?,? )" );
* if( stmt ) {
* sqlany_describe_bind_param( stmt, 0, ¶m );
* param.value.buffer = (char *)\&i;
* param.value.type = A_VAL32;
* sqlany_bind_param( stmt, 0, ¶m );
*
* sqlany_describe_bind_param( stmt, 1, ¶m );
* param.value.buffer = (char *)\&i;
* param.value.type = A_VAL32;
* sqlany_bind_param( stmt, 1, ¶m );
*
* for( i = 0; i < 10; i++ ) {
* if( !sqlany_execute( stmt ) ) {
* // call sqlany_error()
* }
* }
* sqlany_free_stmt( stmt );
* }
* </pre>
*
* \param sqlany_stmt A valid statement object.
* \return sacapi_true when statement is executed successfully or sacapi_false otherwise.
* \sa sqlany_prepare()
*/
sacapi_bool sqlany_execute( a_sqlany_stmt * sqlany_stmt );
/** Executes the SQL statement specified by the string argument and possibly returns a result set.
*
* Use this method to prepare and execute a statement,
* or instead of calling sqlany_prepare() followed by sqlany_execute().
*
* The following example shows how to execute a statement that returns a result set:
*
* <pre>
* a_sqlany_stmt * stmt;
*
* stmt = sqlany_execute_direct( sqlany_conn, "select * from employees" );
* if( stmt && sqlany_num_cols( stmt ) > 0 ) {
* while( sqlany_fetch_next( stmt ) ) {
* int i;
* for( i = 0; i < sqlany_num_cols( stmt ); i++ ) {
* // Get column i data
* }
* }
* sqlany_free_stmt( stmt );
* }
* </pre>
*
* <em>Note:</em> This function cannot be used for executing a SQL statement with parameters.
*
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
* \param sql_str A SQL string. The SQL string should not have parameters such as ?.
* \return A statement handle if the function executes successfully, NULL when the function executes unsuccessfully.
* \sa sqlany_fetch_absolute(), sqlany_fetch_next(), sqlany_num_cols(), sqlany_get_column()
*/
a_sqlany_stmt * sqlany_execute_direct( a_sqlany_connection * sqlany_conn, const char * sql_str );
/** Moves the current row in the result set to the specified row number and then fetches