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