sqlanywhere 0.1.6-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/LICENSE +23 -0
- data/README +134 -0
- data/Rakefile +196 -0
- data/ext/Makefile +215 -0
- data/ext/extconf.rb +30 -0
- data/ext/sacapi.h +909 -0
- data/ext/sacapidll.c +182 -0
- data/ext/sacapidll.h +332 -0
- data/ext/sacapidll.o +0 -0
- data/ext/sqlanywhere-i386-mingw32.def +2 -0
- data/ext/sqlanywhere.c +1753 -0
- data/ext/sqlanywhere.o +0 -0
- data/ext/sqlanywhere.so +0 -0
- data/lib/sqlanywhere.so +0 -0
- data/test/sqlanywhere_test.rb +423 -0
- data/test/test.sql +92 -0
- metadata +73 -0
data/ext/sqlanywhere.o
ADDED
Binary file
|
data/ext/sqlanywhere.so
ADDED
Binary file
|
data/lib/sqlanywhere.so
ADDED
Binary file
|
@@ -0,0 +1,423 @@
|
|
1
|
+
#====================================================
|
2
|
+
#
|
3
|
+
# Copyright 2008-2010 iAnywhere Solutions, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
#
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# While not a requirement of the license, if you do modify this file, we
|
20
|
+
# would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#====================================================
|
24
|
+
|
25
|
+
require 'test/unit'
|
26
|
+
require 'date'
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rubygems'
|
30
|
+
unless defined? SQLAnywhere
|
31
|
+
require 'sqlanywhere'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Types
|
36
|
+
A_INVALID_TYPE= 0
|
37
|
+
A_BINARY = 1
|
38
|
+
A_STRING = 2
|
39
|
+
A_DOUBLE = 3
|
40
|
+
A_VAL64 = 4
|
41
|
+
A_UVAL64 = 5
|
42
|
+
A_VAL32 = 6
|
43
|
+
A_UVAL32 = 7
|
44
|
+
A_VAL16 = 8
|
45
|
+
A_UVAL16 = 9
|
46
|
+
A_VAL8 = 10
|
47
|
+
A_UVAL8 = 11
|
48
|
+
end
|
49
|
+
|
50
|
+
class Direction
|
51
|
+
DD_INVALID = 0
|
52
|
+
DD_INPUT = 1
|
53
|
+
DD_OUTPUT = 2
|
54
|
+
DD_INPUT_OUTPUT = 3
|
55
|
+
end
|
56
|
+
|
57
|
+
class SQLAnywhere_Test < Test::Unit::TestCase
|
58
|
+
def setup
|
59
|
+
@api = SQLAnywhere::SQLAnywhereInterface.new()
|
60
|
+
assert_not_nil @api
|
61
|
+
assert_nothing_raised do
|
62
|
+
SQLAnywhere::API.sqlany_initialize_interface( @api )
|
63
|
+
end
|
64
|
+
assert_nothing_raised do
|
65
|
+
@api.sqlany_init()
|
66
|
+
end
|
67
|
+
@conn = @api.sqlany_new_connection()
|
68
|
+
assert_not_nil @conn
|
69
|
+
conn_str = "eng=test;uid=dba;pwd=sql"
|
70
|
+
assert_succeeded @api.sqlany_connect(@conn, conn_str)
|
71
|
+
end
|
72
|
+
|
73
|
+
def teardown
|
74
|
+
assert_succeeded @api.sqlany_execute_immediate(@conn, 'SELECT * FROM dummy')
|
75
|
+
assert_nil @api.sqlany_disconnect(@conn)
|
76
|
+
assert_failed @api.sqlany_execute_immediate(@conn, 'SELECT * FROM dummy')
|
77
|
+
assert_nil @api.sqlany_free_connection(@conn)
|
78
|
+
assert_nothing_raised do
|
79
|
+
@api.sqlany_fini()
|
80
|
+
end
|
81
|
+
assert_nothing_raised do
|
82
|
+
SQLAnywhere::API.sqlany_finalize_interface( @api )
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_execute_immediate
|
87
|
+
assert_succeeded @api.sqlany_execute_immediate(@conn, 'SELECT * FROM dummy')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_errors
|
91
|
+
sql = "INSERT INTO test(\"id\") VALUES('test');"
|
92
|
+
assert_failed @api.sqlany_execute_immediate(@conn, sql)
|
93
|
+
code, msg = @api.sqlany_error(@conn)
|
94
|
+
assert_equal -157, code
|
95
|
+
assert_not_equal "", msg
|
96
|
+
assert_equal "53018\000", @api.sqlany_sqlstate(@conn)
|
97
|
+
assert_nil @api.sqlany_clear_error(@conn)
|
98
|
+
code, msg = @api.sqlany_error(@conn)
|
99
|
+
assert_equal 0, code
|
100
|
+
assert_equal "", msg
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_rollback
|
104
|
+
id = setup_transaction
|
105
|
+
@api.sqlany_rollback(@conn)
|
106
|
+
sql = "SELECT * FROM test where \"id\" = " + id.to_s + ";"
|
107
|
+
rs = exec_direct_with_test(sql)
|
108
|
+
assert_failed @api.sqlany_fetch_next(rs)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_commit
|
112
|
+
id = setup_transaction
|
113
|
+
@api.sqlany_commit(@conn)
|
114
|
+
sql = "SELECT * FROM test where \"id\" = " + id.to_s + ";"
|
115
|
+
rs = exec_direct_with_test(sql)
|
116
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
117
|
+
res, ret_id = @api.sqlany_get_column(rs, 0)
|
118
|
+
assert_succeeded res
|
119
|
+
assert_not_nil ret_id
|
120
|
+
assert_equal id, ret_id
|
121
|
+
assert_failed @api.sqlany_fetch_next(rs)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_column_info
|
125
|
+
is_iq = is_iq_table?("types")
|
126
|
+
rs = exec_direct_with_test("SELECT TOP 2 * FROM \"types\" ORDER BY \"id\"")
|
127
|
+
assert_equal 22, @api.sqlany_num_cols(rs)
|
128
|
+
assert_column_info(rs, 0, "id", Types::A_VAL32, 4)
|
129
|
+
assert_column_info(rs, 1, "_binary_", Types::A_BINARY, 8)
|
130
|
+
assert_column_info(rs, 2, "_numeric_", Types::A_STRING, 2)
|
131
|
+
assert_column_info(rs, 3, "_decimal_", Types::A_STRING, 2)
|
132
|
+
assert_column_info(rs, 4, "_bounded_string_", Types::A_STRING, 255)
|
133
|
+
assert_column_info(rs, 5, "_unbounded_string_", Types::A_STRING, (2 * (2**30)) - 1)
|
134
|
+
assert_column_info(rs, 6, "_signed_bigint_", Types::A_VAL64, 8)
|
135
|
+
assert_column_info(rs, 7, "_unsigned_bigint_", Types::A_UVAL64, 8)
|
136
|
+
assert_column_info(rs, 8, "_signed_int_", Types::A_VAL32, 4)
|
137
|
+
assert_column_info(rs, 9, "_unsigned_int_", Types::A_UVAL32, 4)
|
138
|
+
assert_column_info(rs, 10, "_signed_smallint_", Types::A_VAL16, 2)
|
139
|
+
assert_column_info(rs, 11, "_unsigned_smallint_", Types::A_UVAL16, 2) unless is_iq #IQ Does not have an unsigned small int datatype
|
140
|
+
assert_column_info(rs, 12, "_signed_tinyint_", Types::A_UVAL8, 1)
|
141
|
+
assert_column_info(rs, 13, "_unsigned_tinyint_", Types::A_UVAL8, 1)
|
142
|
+
assert_column_info(rs, 14, "_bit_", Types::A_VAL8, 1)
|
143
|
+
assert_column_info(rs, 15, "_date_", Types::A_STRING, 10)
|
144
|
+
assert_column_info(rs, 16, "_datetime_", Types::A_STRING, 23)
|
145
|
+
assert_column_info(rs, 17, "_smalldatetime_", Types::A_STRING, 23)
|
146
|
+
assert_column_info(rs, 18, "_timestamp_", Types::A_STRING, 23)
|
147
|
+
assert_column_info(rs, 19, "_double_", Types::A_DOUBLE, 8)
|
148
|
+
assert_column_info(rs, 20, "_float_", Types::A_DOUBLE, 4)
|
149
|
+
assert_column_info(rs, 21, "_real_", Types::A_DOUBLE, 4)
|
150
|
+
assert_nil @api.sqlany_free_stmt(rs)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_bounds_on_types
|
154
|
+
is_iq = is_iq_table?("types")
|
155
|
+
rs = exec_direct_with_test("SELECT TOP 2 * FROM \"types\" ORDER BY \"id\"")
|
156
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
157
|
+
assert_class_and_value(rs, String, 1, "x")
|
158
|
+
assert_class_and_value(rs, String, 2, "1.1")
|
159
|
+
assert_class_and_value(rs, String, 3, "1.1")
|
160
|
+
assert_class_and_value(rs, String, 4, 'Bounded String Test')
|
161
|
+
assert_class_and_value(rs, String, 5, 'Unbounded String Test')
|
162
|
+
assert_class_and_value(rs, Bignum, 6, 9223372036854775807)
|
163
|
+
assert_class_and_value(rs, Bignum, 7, 18446744073709551615)
|
164
|
+
assert_class_and_value(rs, Bignum, 8, 2147483647)
|
165
|
+
assert_class_and_value(rs, Bignum, 9, 4294967295)
|
166
|
+
assert_class_and_value(rs, Fixnum, 10, 32767)
|
167
|
+
assert_class_and_value(rs, Fixnum, 11, 65535) unless is_iq #IQ Does not have an unsigned small int datatype
|
168
|
+
assert_class_and_value(rs, Fixnum, 12, 255)
|
169
|
+
assert_class_and_value(rs, Fixnum, 13, 255)
|
170
|
+
assert_class_and_value(rs, Fixnum, 14, 1)
|
171
|
+
assert_date_and_time(rs, Date, 15, Date.new(1999, 1, 2))
|
172
|
+
assert_date_and_time(rs, DateTime, 16, DateTime.new(1999, 1, 2, 21, 20, 53))
|
173
|
+
assert_date_and_time(rs, DateTime, 17, DateTime.new(1999, 1, 2, 21, 20, 53))
|
174
|
+
assert_date_and_time(rs, DateTime, 18, DateTime.new(1999, 1, 2, 21, 20, 53))
|
175
|
+
assert_class_and_float_value(rs, Float, 19, 1.79769313486231e+308, 1e+293 )
|
176
|
+
assert_class_and_float_value(rs, Float, 20, 3.402823e+38, 1e+32 )
|
177
|
+
assert_class_and_float_value(rs, Float, 21, 3.402823e+38, 1e+32 )
|
178
|
+
|
179
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
180
|
+
assert_class_and_value(rs, String, 1, 255.chr)
|
181
|
+
assert_class_and_value(rs, String, 2, "-1.1")
|
182
|
+
assert_class_and_value(rs, String, 3, "-1.1")
|
183
|
+
assert_class_and_value(rs, String, 4, '')
|
184
|
+
assert_class_and_value(rs, String, 5, '')
|
185
|
+
assert_class_and_value(rs, Bignum, 6, -9223372036854775808)
|
186
|
+
assert_class_and_value(rs, Fixnum, 7, 0)
|
187
|
+
assert_class_and_value(rs, Bignum, 8, -2147483648)
|
188
|
+
assert_class_and_value(rs, Fixnum, 9, 0)
|
189
|
+
assert_class_and_value(rs, Fixnum, 10, -32768)
|
190
|
+
assert_class_and_value(rs, Fixnum, 11, 0) unless is_iq #IQ Does not have an unsigned small int datatype
|
191
|
+
assert_class_and_value(rs, Fixnum, 12, 0)
|
192
|
+
assert_class_and_value(rs, Fixnum, 13, 0)
|
193
|
+
assert_class_and_value(rs, Fixnum, 14, 0)
|
194
|
+
assert_class_and_value(rs, NilClass, 15, nil)
|
195
|
+
assert_class_and_value(rs, NilClass, 16, nil)
|
196
|
+
assert_class_and_value(rs, NilClass, 17, nil)
|
197
|
+
assert_class_and_value(rs, NilClass, 18, nil)
|
198
|
+
assert_class_and_float_value(rs, Float, 19, -1.79769313486231e+308, 1e+293 )
|
199
|
+
assert_class_and_float_value(rs, Float, 20, -3.402823e+38, 1e+32 )
|
200
|
+
assert_class_and_float_value(rs, Float, 21, -3.402823e+38, 1e+32 )
|
201
|
+
assert_nil @api.sqlany_free_stmt(rs)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_prepared_stmt
|
205
|
+
is_iq = is_iq_table?("types")
|
206
|
+
stmt = @api.sqlany_prepare(@conn, "SELECT * FROM \"types\" WHERE \"id\" = ?")
|
207
|
+
assert_not_nil stmt
|
208
|
+
assert_failed @api.sqlany_execute(stmt) unless is_iq #IQ does not throw an error here
|
209
|
+
assert_equal 1, @api.sqlany_num_params(stmt)
|
210
|
+
res, param = @api.sqlany_describe_bind_param(stmt, 0)
|
211
|
+
assert_not_equal 0, res
|
212
|
+
assert_equal "?", param.get_name()
|
213
|
+
assert_equal Direction::DD_INPUT, param.get_direction()
|
214
|
+
|
215
|
+
assert_nil param.set_value(0);
|
216
|
+
@api.sqlany_bind_param(stmt, 0, param)
|
217
|
+
assert_succeeded @api.sqlany_execute(stmt)
|
218
|
+
assert_succeeded @api.sqlany_fetch_next(stmt)
|
219
|
+
assert_class_and_value(stmt, String, 4, "Bounded String Test")
|
220
|
+
|
221
|
+
assert_nil param.set_value(1);
|
222
|
+
@api.sqlany_bind_param(stmt, 0, param)
|
223
|
+
assert_succeeded @api.sqlany_execute(stmt)
|
224
|
+
assert_succeeded @api.sqlany_fetch_next(stmt)
|
225
|
+
assert_class_and_value(stmt, String, 4, "")
|
226
|
+
|
227
|
+
assert_nil @api.sqlany_free_stmt(stmt)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_insert_binary
|
231
|
+
assert_insert("_binary_", "x", String)
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_insert_numeric
|
235
|
+
assert_insert("_numeric_", "1.1", String)
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_insert_decimal
|
239
|
+
assert_insert("_decimal_", "1.1", String)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_insert_bounded_string
|
243
|
+
assert_insert("_bounded_string_", "Bounded String Test", String)
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_insert_unbounded_string
|
247
|
+
assert_insert("_unbounded_string_", "Unbounded String Test", String)
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_insert_int64
|
251
|
+
assert_insert("_signed_bigint_", 9223372036854775807, Bignum)
|
252
|
+
assert_insert("_signed_bigint_", -9223372036854775808, Bignum)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_insert_uint64
|
256
|
+
assert_insert("_unsigned_bigint_", 9223372036854775807, Bignum)
|
257
|
+
assert_insert("_unsigned_bigint_", 0, Fixnum)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_insert_int32
|
261
|
+
assert_insert("_signed_int_", 2147483647, Bignum)
|
262
|
+
assert_insert("_signed_int_", -2147483648, Bignum)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_insert_uint32
|
266
|
+
assert_insert("_unsigned_int_", 4294967295, Bignum)
|
267
|
+
assert_insert("_unsigned_int_", 0, Fixnum)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_insert_int16
|
271
|
+
assert_insert("_signed_smallint_", 32767, Fixnum)
|
272
|
+
assert_insert("_signed_smallint_", -32768, Fixnum)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_insert_uint16
|
276
|
+
is_iq = is_iq_table?("types") #IQ Does not have an unsigned small int datatype
|
277
|
+
assert_insert("_unsigned_smallint_", 65535, Fixnum) unless is_iq
|
278
|
+
assert_insert("_unsigned_smallint_", 0, Fixnum) unless is_iq
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_insert_int8
|
282
|
+
assert_insert("_signed_smallint_", 255, Fixnum)
|
283
|
+
assert_insert("_signed_smallint_", 0, Fixnum)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_insert_uint8
|
287
|
+
is_iq = is_iq_table?("types") #IQ Does not have an unsigned small int datatype
|
288
|
+
assert_insert("_unsigned_smallint_", 255, Fixnum) unless is_iq
|
289
|
+
assert_insert("_unsigned_smallint_", 0, Fixnum) unless is_iq
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_insert_date
|
293
|
+
assert_insert("_date_", Date.new(1999, 1, 2), Date)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_insert_datetime
|
297
|
+
assert_insert("_datetime_", DateTime.new(1999, 1, 2, 21, 20, 53), DateTime)
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_insert_smalldate
|
301
|
+
assert_insert("_smalldatetime_", DateTime.new(1999, 1, 2, 21, 20, 53), DateTime)
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_insert_timestamp
|
305
|
+
assert_insert("_timestamp_", DateTime.new(1999, 1, 2, 21, 20, 53), DateTime)
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_insert_double
|
309
|
+
assert_insert("_double_", 1.79769313486231e+308, Float, 1e+293)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_insert_float
|
313
|
+
assert_insert("_float_", 3.402823e+38, Float, 1e+32)
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_insert_real
|
317
|
+
assert_insert("_real_", 3.402823e+38, Float, 1e+32)
|
318
|
+
end
|
319
|
+
|
320
|
+
def is_iq_table?(table_name)
|
321
|
+
rs = @api.sqlany_execute_direct(@conn, "SELECT server_type FROM SYS.SYSTABLE WHERE table_name = '#{table_name}'")
|
322
|
+
@api.sqlany_fetch_next(rs)
|
323
|
+
return @api.sqlany_get_column(rs, 0)[1] == 'IQ'
|
324
|
+
end
|
325
|
+
|
326
|
+
def assert_insert(column_name, value, type, delta = nil)
|
327
|
+
stmt = @api.sqlany_prepare(@conn, 'INSERT INTO "types"("id", "' + column_name + '", "_bit_") VALUES(3, ?, 1)')
|
328
|
+
assert_not_nil stmt
|
329
|
+
res, param = @api.sqlany_describe_bind_param(stmt, 0)
|
330
|
+
if type == Date or type == DateTime then
|
331
|
+
assert_nil param.set_value(value.strftime("%F %T"));
|
332
|
+
else
|
333
|
+
assert_nil param.set_value(value);
|
334
|
+
end
|
335
|
+
@api.sqlany_bind_param(stmt, 0, param)
|
336
|
+
assert_succeeded @api.sqlany_execute(stmt)
|
337
|
+
assert_nil @api.sqlany_free_stmt(stmt)
|
338
|
+
|
339
|
+
rs = exec_direct_with_test('SELECT "' + column_name + '" FROM "types" WHERE "id" = 3')
|
340
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
341
|
+
if type == Date or type == DateTime then
|
342
|
+
assert_date_and_time(rs, type, 0, value)
|
343
|
+
elsif type == Float
|
344
|
+
assert_class_and_float_value(rs, type, 0, value, delta)
|
345
|
+
else
|
346
|
+
assert_class_and_value(rs, type, 0, value)
|
347
|
+
end
|
348
|
+
|
349
|
+
assert_nil @api.sqlany_free_stmt(rs)
|
350
|
+
|
351
|
+
@api.sqlany_rollback(@conn)
|
352
|
+
end
|
353
|
+
|
354
|
+
def assert_column_info(rs, pos, expected_col_name, expected_col_type, expected_col_size)
|
355
|
+
res, col_num, col_name, col_type, col_native_type, col_precision, col_scale, col_size, col_nullable = @api.sqlany_get_column_info(rs, pos);
|
356
|
+
assert_succeeded res
|
357
|
+
assert_equal expected_col_name, col_name
|
358
|
+
assert_equal expected_col_type, col_type
|
359
|
+
assert_equal expected_col_size, col_size
|
360
|
+
end
|
361
|
+
|
362
|
+
def assert_class_and_float_value(rs, cl, pos, expected_value, allowed_delta)
|
363
|
+
res, val = @api.sqlany_get_column(rs, pos)
|
364
|
+
assert_succeeded res
|
365
|
+
assert_not_nil val unless expected_value.nil?
|
366
|
+
assert_in_delta expected_value, val, allowed_delta
|
367
|
+
assert_instance_of cl, val
|
368
|
+
end
|
369
|
+
|
370
|
+
def assert_date_and_time(rs, cl, pos, expected_value)
|
371
|
+
res, val = @api.sqlany_get_column(rs, pos)
|
372
|
+
assert_succeeded res
|
373
|
+
assert_not_nil val unless expected_value.nil?
|
374
|
+
parsed = cl.parse(val)
|
375
|
+
assert_equal expected_value, parsed
|
376
|
+
assert_instance_of cl, parsed
|
377
|
+
end
|
378
|
+
|
379
|
+
def assert_class_and_value(rs, cl, pos, expected_value)
|
380
|
+
res, val = @api.sqlany_get_column(rs, pos)
|
381
|
+
assert_succeeded res
|
382
|
+
assert_not_nil val unless expected_value.nil?
|
383
|
+
assert_equal expected_value, val
|
384
|
+
assert_instance_of cl, val
|
385
|
+
end
|
386
|
+
|
387
|
+
def setup_transaction
|
388
|
+
sql = "INSERT INTO test VALUES( DEFAULT );"
|
389
|
+
assert_succeeded @api.sqlany_execute_immediate(@conn, sql)
|
390
|
+
|
391
|
+
rs = exec_direct_with_test("SELECT @@identity")
|
392
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
393
|
+
res, id = @api.sqlany_get_column(rs, 0)
|
394
|
+
assert_succeeded res
|
395
|
+
assert_not_nil id
|
396
|
+
|
397
|
+
sql = "SELECT * FROM test where \"id\" = " + id.to_s + ";"
|
398
|
+
rs = @api.sqlany_execute_direct(@conn, sql)
|
399
|
+
assert_not_nil rs
|
400
|
+
|
401
|
+
assert_succeeded @api.sqlany_fetch_next(rs)
|
402
|
+
assert_failed @api.sqlany_fetch_next(rs)
|
403
|
+
assert_nil @api.sqlany_free_stmt(rs)
|
404
|
+
id
|
405
|
+
end
|
406
|
+
|
407
|
+
def exec_direct_with_test(sql)
|
408
|
+
rs = @api.sqlany_execute_direct(@conn, sql)
|
409
|
+
code, msg = @api.sqlany_error(@conn)
|
410
|
+
assert_not_nil rs, "SQL Code: #{code}; Message: #{msg}"
|
411
|
+
rs
|
412
|
+
end
|
413
|
+
|
414
|
+
def assert_succeeded(val)
|
415
|
+
assert_not_equal 0, val, @api.sqlany_error(@conn)
|
416
|
+
end
|
417
|
+
|
418
|
+
def assert_failed(val)
|
419
|
+
assert_equal 0, val, @api.sqlany_error(@conn)
|
420
|
+
end
|
421
|
+
|
422
|
+
end
|
423
|
+
|
data/test/test.sql
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
// *****************************************************
|
2
|
+
// Copyright (c) 2008-2010 iAnywhere Solutions, Inc.
|
3
|
+
// Portions copyright (c) 1988-2010 Sybase, Inc.
|
4
|
+
// All rights reserved. All unpublished rights reserved.
|
5
|
+
// *****************************************************
|
6
|
+
IF EXISTS( SELECT * FROM "SYS"."SYSTAB" WHERE "table_name" = 'test') THEN
|
7
|
+
DROP TABLE "test";
|
8
|
+
END IF;
|
9
|
+
|
10
|
+
IF EXISTS( SELECT * FROM "SYS"."SYSTAB" WHERE "table_name" = 'types') THEN
|
11
|
+
DROP TABLE "types";
|
12
|
+
END IF;
|
13
|
+
|
14
|
+
CREATE TABLE "test" (
|
15
|
+
"id" INTEGER NOT NULL DEFAULT AUTOINCREMENT,
|
16
|
+
PRIMARY KEY("id")
|
17
|
+
);
|
18
|
+
|
19
|
+
CREATE TABLE "types" (
|
20
|
+
"id" INTEGER PRIMARY KEY,
|
21
|
+
"_binary_" BINARY(8) DEFAULT NULL,
|
22
|
+
"_numeric_" NUMERIC(2,1),
|
23
|
+
"_decimal_" DECIMAL(2,1),
|
24
|
+
"_bounded_string_" CHAR(255) DEFAULT NULL,
|
25
|
+
"_unbounded_string_" LONG VARCHAR DEFAULT NULL,
|
26
|
+
"_signed_bigint_" BIGINT DEFAULT NULL,
|
27
|
+
"_unsigned_bigint_" UNSIGNED BIGINT DEFAULT NULL,
|
28
|
+
"_signed_int_" INTEGER DEFAULT NULL,
|
29
|
+
"_unsigned_int_" UNSIGNED INTEGER DEFAULT NULL,
|
30
|
+
"_signed_smallint_" SMALLINT DEFAULT NULL,
|
31
|
+
"_unsigned_smallint_" UNSIGNED SMALLINT DEFAULT NULL,
|
32
|
+
"_signed_tinyint_" TINYINT DEFAULT NULL,
|
33
|
+
"_unsigned_tinyint_" UNSIGNED TINYINT DEFAULT NULL,
|
34
|
+
"_bit_" BIT,
|
35
|
+
"_date_" DATE DEFAULT NULL,
|
36
|
+
"_datetime_" DATETIME DEFAULT NULL,
|
37
|
+
"_smalldatetime_" SMALLDATETIME DEFAULT NULL,
|
38
|
+
"_timestamp_" TIMESTAMP DEFAULT NULL,
|
39
|
+
"_double_" DOUBLE DEFAULT NULL,
|
40
|
+
"_float_" FLOAT DEFAULT NULL,
|
41
|
+
"_real_" REAL DEFAULT NULL
|
42
|
+
);
|
43
|
+
|
44
|
+
INSERT INTO types VALUES
|
45
|
+
( 0,
|
46
|
+
CAST ( 0x78 AS BINARY ),
|
47
|
+
1.1,
|
48
|
+
1.1,
|
49
|
+
'Bounded String Test',
|
50
|
+
'Unbounded String Test',
|
51
|
+
9223372036854775807,
|
52
|
+
18446744073709551615,
|
53
|
+
2147483647,
|
54
|
+
4294967295,
|
55
|
+
32767,
|
56
|
+
65535,
|
57
|
+
255,
|
58
|
+
255,
|
59
|
+
1,
|
60
|
+
DATE( '1999-01-02 21:20:53' ),
|
61
|
+
DATETIME( '1999-01-02 21:20:53' ),
|
62
|
+
DATETIME( '1999-01-02 21:20:53' ),
|
63
|
+
DATETIME( '1999-01-02 21:20:53' ),
|
64
|
+
1.79769313486231e+308,
|
65
|
+
3.402823e+38,
|
66
|
+
3.402823e+38
|
67
|
+
)
|
68
|
+
|
69
|
+
INSERT INTO types VALUES
|
70
|
+
( 1,
|
71
|
+
CAST ( 0xFF AS BINARY ),
|
72
|
+
-1.1,
|
73
|
+
-1.1,
|
74
|
+
'',
|
75
|
+
'',
|
76
|
+
-9223372036854775808,
|
77
|
+
0,
|
78
|
+
-2147483648,
|
79
|
+
0,
|
80
|
+
-32768,
|
81
|
+
0,
|
82
|
+
0,
|
83
|
+
0,
|
84
|
+
0,
|
85
|
+
NULL,
|
86
|
+
NULL,
|
87
|
+
NULL,
|
88
|
+
NULL,
|
89
|
+
-1.79769313486231e+308,
|
90
|
+
-3.402823e+38,
|
91
|
+
-3.402823e+38
|
92
|
+
)
|