~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/odbc/test/odbc_query_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2002-2011. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
 
 
20
%%
 
21
 
 
22
-module(odbc_query_SUITE).
 
23
 
 
24
%% Note: This directive should only be used in test suites.
 
25
-compile(export_all).
 
26
 
 
27
-include_lib("common_test/include/ct.hrl").
 
28
-include("test_server_line.hrl").
 
29
-include("odbc_test.hrl").
 
30
 
 
31
%%--------------------------------------------------------------------
 
32
%% all(Arg) -> [Doc] | [Case] | {skip, Comment}
 
33
%% Arg - doc | suite
 
34
%% Doc - string()
 
35
%% Case - atom() 
 
36
%%      Name of a test case function. 
 
37
%% Comment - string()
 
38
%% Description: Returns documentation/test cases in this test suite
 
39
%%              or a skip tuple if the platform is not supported.  
 
40
%%--------------------------------------------------------------------
 
41
suite() -> [{ct_hooks,[ts_install_cth]}].
 
42
 
 
43
all() -> 
 
44
    case odbc_test_lib:odbc_check() of
 
45
        ok ->
 
46
            [sql_query, first, last, next, prev, select_count,
 
47
             select_next, select_relative, select_absolute,
 
48
             create_table_twice, delete_table_twice, duplicate_key,
 
49
             not_connection_owner, no_result_set, query_error,
 
50
             multiple_select_result_sets, multiple_mix_result_sets,
 
51
             multiple_result_sets_error,
 
52
             {group, parameterized_queries}, {group, describe_table},
 
53
             delete_nonexisting_row];
 
54
        Other -> {skip, Other}
 
55
    end.
 
56
 
 
57
groups() -> 
 
58
    [{parameterized_queries, [],
 
59
      [{group, param_integers}, param_insert_decimal,
 
60
       param_insert_numeric, {group, param_insert_string},
 
61
       param_insert_float, param_insert_real,
 
62
       param_insert_double, param_insert_mix, param_update,
 
63
       param_delete, param_select]},
 
64
     {param_integers, [],
 
65
      [param_insert_tiny_int, param_insert_small_int,
 
66
       param_insert_int, param_insert_integer]},
 
67
     {param_insert_string, [],
 
68
      [param_insert_char, param_insert_character,
 
69
       param_insert_char_varying,
 
70
       param_insert_character_varying]},
 
71
     {describe_table, [],
 
72
      [describe_integer, describe_string, describe_floating,
 
73
       describe_dec_num, describe_no_such_table]}].
 
74
 
 
75
init_per_group(_GroupName, Config) ->
 
76
    Config.
 
77
 
 
78
end_per_group(_GroupName, Config) ->
 
79
    Config.
 
80
 
 
81
                                          
 
82
 
 
83
 
 
84
%%--------------------------------------------------------------------
 
85
%% Function: init_per_suite(Config) -> Config
 
86
%% Config - [tuple()]
 
87
%%   A list of key/value pairs, holding the test case configuration.
 
88
%% Description: Initiation before the whole suite
 
89
%%
 
90
%% Note: This function is free to add any key/value pairs to the Config
 
91
%% variable, but should NOT alter/remove any existing entries.
 
92
%%--------------------------------------------------------------------
 
93
init_per_suite(Config) when is_list(Config) ->
 
94
    application:start(odbc),
 
95
    [{tableName, odbc_test_lib:unique_table_name()}| Config].
 
96
 
 
97
%%--------------------------------------------------------------------
 
98
%% Function: end_per_suite(Config) -> _
 
99
%% Config - [tuple()]
 
100
%%   A list of key/value pairs, holding the test case configuration.
 
101
%% Description: Cleanup after the whole suite
 
102
%%--------------------------------------------------------------------
 
103
end_per_suite(_Config) ->
 
104
    application:stop(odbc),
 
105
    ok.
 
106
 
 
107
%%--------------------------------------------------------------------
 
108
%% Function: init_per_testcase(Case, Config) -> Config
 
109
%% Case - atom()
 
110
%%   Name of the test case that is about to be run.
 
111
%% Config - [tuple()]
 
112
%%   A list of key/value pairs, holding the test case configuration.
 
113
%%
 
114
%% Description: Initiation before each test case
 
115
%%
 
116
%% Note: This function is free to add any key/value pairs to the Config
 
117
%% variable, but should NOT alter/remove any existing entries.
 
118
%%--------------------------------------------------------------------
 
119
init_per_testcase(_Case, Config) ->
 
120
    {ok, Ref} = odbc:connect(?RDBMS:connection_string(), []),
 
121
    Dog = test_server:timetrap(?default_timeout),
 
122
    Temp = lists:keydelete(connection_ref, 1, Config),
 
123
    NewConfig = lists:keydelete(watchdog, 1, Temp),
 
124
    [{watchdog, Dog}, {connection_ref, Ref} | NewConfig].
 
125
 
 
126
%%--------------------------------------------------------------------
 
127
%% Function: end_per_testcase(Case, Config) -> _
 
128
%% Case - atom()
 
129
%%   Name of the test case that is about to be run.
 
130
%% Config - [tuple()]
 
131
%%   A list of key/value pairs, holding the test case configuration.
 
132
%% Description: Cleanup after each test case
 
133
%%--------------------------------------------------------------------
 
134
end_per_testcase(_Case, Config) ->
 
135
    Ref = ?config(connection_ref, Config),
 
136
    ok = odbc:disconnect(Ref),
 
137
    %% Clean up if needed 
 
138
    Table = ?config(tableName, Config),
 
139
    {ok, NewRef} = odbc:connect(?RDBMS:connection_string(), []),
 
140
    odbc:sql_query(NewRef, "DROP TABLE " ++ Table), 
 
141
    odbc:disconnect(NewRef),
 
142
    Dog = ?config(watchdog, Config),
 
143
    test_server:timetrap_cancel(Dog),
 
144
    ok.
 
145
 
 
146
%%-------------------------------------------------------------------------
 
147
%% Test cases starts here.
 
148
%%-------------------------------------------------------------------------
 
149
sql_query(doc)->
 
150
    ["Test the common cases"];
 
151
sql_query(suite) -> [];
 
152
sql_query(Config) when is_list(Config) ->
 
153
    Ref = ?config(connection_ref, Config),
 
154
    Table = ?config(tableName, Config),
 
155
 
 
156
    {updated, _} =
 
157
        odbc:sql_query(Ref, 
 
158
                       "CREATE TABLE " ++ Table ++ 
 
159
                       " (ID integer, DATA varchar(10))"),
 
160
 
 
161
    {updated, Count} = 
 
162
        odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
 
163
 
 
164
    true = odbc_test_lib:check_row_count(1, Count),
 
165
 
 
166
    InsertResult = ?RDBMS:insert_result(),
 
167
    InsertResult = 
 
168
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
169
 
 
170
    {updated, NewCount} = 
 
171
        odbc:sql_query(Ref, "UPDATE " ++ Table ++ 
 
172
                       " SET DATA = 'foo' WHERE ID = 1"),
 
173
    
 
174
    true = odbc_test_lib:check_row_count(1, NewCount),
 
175
 
 
176
    UpdateResult = ?RDBMS:update_result(),
 
177
    UpdateResult = 
 
178
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
179
 
 
180
    {updated,  NewCount1} = odbc:sql_query(Ref, "DELETE FROM " ++ Table ++ 
 
181
                                  " WHERE ID = 1"),
 
182
    
 
183
    true = odbc_test_lib:check_row_count(1, NewCount1),
 
184
 
 
185
    {selected, Fields, []} =
 
186
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
187
 
 
188
    ["ID","DATA"] = odbc_test_lib:to_upper(Fields),
 
189
    ok.
 
190
 
 
191
%%-------------------------------------------------------------------------
 
192
select_count(doc) -> 
 
193
    ["Tests select_count/[2,3]'s timeout, "
 
194
     " select_count's functionality will be better tested by other tests "
 
195
     " such as first."];
 
196
select_count(sute) -> [];
 
197
select_count(Config) when is_list(Config) ->
 
198
    Ref = ?config(connection_ref, Config),
 
199
    Table = ?config(tableName, Config),
 
200
 
 
201
    {updated, _} = odbc:sql_query(Ref, 
 
202
                                  "CREATE TABLE " ++ Table ++
 
203
                                  " (ID integer)"),
 
204
 
 
205
    {updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
206
                                  " VALUES(1)"),
 
207
    true = odbc_test_lib:check_row_count(1, Count),
 
208
    {ok, _} = 
 
209
        odbc:select_count(Ref, "SELECT * FROM " ++ Table, ?TIMEOUT),
 
210
    {'EXIT', {function_clause, _}} = 
 
211
        (catch odbc:select_count(Ref, "SELECT * FROM ", -1)),
 
212
    ok.
 
213
%%-------------------------------------------------------------------------
 
214
first(doc) ->
 
215
    ["Tests first/[1,2]"];
 
216
first(suite) -> [];
 
217
first(Config) when is_list(Config) ->
 
218
    Ref = ?config(connection_ref, Config),
 
219
    Table = ?config(tableName, Config),
 
220
 
 
221
    {updated, _} = odbc:sql_query(Ref, 
 
222
                                  "CREATE TABLE " ++ Table ++
 
223
                                  " (ID integer)"),
 
224
    
 
225
    {updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
226
                                  " VALUES(1)"),
 
227
    true = odbc_test_lib:check_row_count(1, Count),
 
228
    {updated, NewCount} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
229
                                  " VALUES(2)"),
 
230
    true = odbc_test_lib:check_row_count(1, NewCount),
 
231
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
 
232
 
 
233
 
 
234
    FirstResult = ?RDBMS:selected_ID(1, first),
 
235
    FirstResult = odbc:first(Ref),
 
236
    FirstResult = odbc:first(Ref, ?TIMEOUT), 
 
237
    {'EXIT', {function_clause, _}} = (catch odbc:first(Ref, -1)),
 
238
    ok.
 
239
 
 
240
%%-------------------------------------------------------------------------
 
241
last(doc) ->
 
242
    ["Tests last/[1,2]"];
 
243
last(suite) -> [];
 
244
last(Config) when is_list(Config) ->
 
245
    Ref = ?config(connection_ref, Config),
 
246
    Table = ?config(tableName, Config),
 
247
 
 
248
    {updated, _} = odbc:sql_query(Ref, 
 
249
                                  "CREATE TABLE " ++ Table ++
 
250
                                  " (ID integer)"),
 
251
 
 
252
    {updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
253
                                  " VALUES(1)"),
 
254
    true = odbc_test_lib:check_row_count(1, Count),
 
255
    {updated, NewCount} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
256
                                  " VALUES(2)"),
 
257
    true = odbc_test_lib:check_row_count(1, NewCount),
 
258
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
 
259
 
 
260
    LastResult = ?RDBMS:selected_ID(2, last),
 
261
    LastResult = odbc:last(Ref),
 
262
 
 
263
    LastResult = odbc:last(Ref, ?TIMEOUT), 
 
264
    {'EXIT', {function_clause, _}} = (catch odbc:last(Ref, -1)),
 
265
    ok.
 
266
 
 
267
%%-------------------------------------------------------------------------
 
268
next(doc) ->
 
269
    ["Tests next/[1,2]"];
 
270
next(suite) -> [];
 
271
next(Config) when is_list(Config) ->
 
272
    Ref = ?config(connection_ref, Config),
 
273
    Table = ?config(tableName, Config),
 
274
 
 
275
    {updated, _} = odbc:sql_query(Ref, 
 
276
                                  "CREATE TABLE " ++ Table ++
 
277
                                  " (ID integer)"),
 
278
 
 
279
    {updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
280
                                  " VALUES(1)"),
 
281
    true = odbc_test_lib:check_row_count(1, Count),
 
282
    {updated, NewCount} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
283
                                  " VALUES(2)"),
 
284
    true = odbc_test_lib:check_row_count(1, NewCount),
 
285
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
 
286
 
 
287
    NextResult = ?RDBMS:selected_ID(1, next),
 
288
    NextResult = odbc:next(Ref),
 
289
    NextResult2 = ?RDBMS:selected_ID(2, next),
 
290
    NextResult2 = odbc:next(Ref, ?TIMEOUT), 
 
291
    {'EXIT', {function_clause, _}} = (catch odbc:next(Ref, -1)),
 
292
    ok.
 
293
%%-------------------------------------------------------------------------
 
294
prev(doc) ->
 
295
    ["Tests prev/[1,2]"];
 
296
prev(suite) -> [];
 
297
prev(Config) when is_list(Config) ->
 
298
    Ref = ?config(connection_ref, Config),
 
299
    Table = ?config(tableName, Config),
 
300
 
 
301
    {updated, _} = odbc:sql_query(Ref, 
 
302
                                  "CREATE TABLE " ++ Table ++
 
303
                                  " (ID integer)"),
 
304
 
 
305
    {updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
306
                                  " VALUES(1)"),
 
307
    true = odbc_test_lib:check_row_count(1, Count),
 
308
    {updated, NewCount} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
309
                                  " VALUES(2)"),
 
310
    true = odbc_test_lib:check_row_count(1, NewCount),
 
311
 
 
312
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
 
313
 
 
314
    odbc:last(Ref), % Position cursor last so there will be a prev
 
315
    PrevResult = ?RDBMS:selected_ID(1, prev),
 
316
    PrevResult = odbc:prev(Ref),
 
317
 
 
318
    odbc:last(Ref), % Position cursor last so there will be a prev
 
319
    PrevResult = odbc:prev(Ref, ?TIMEOUT), 
 
320
    {'EXIT', {function_clause, _}} = (catch odbc:prev(Ref, -1)),
 
321
    ok.
 
322
%%-------------------------------------------------------------------------
 
323
select_next(doc) ->
 
324
    ["Tests select/[4,5] with CursorRelation = next "];
 
325
select_next(suit) -> [];
 
326
select_next(Config) when is_list(Config) ->
 
327
    Ref = ?config(connection_ref, Config),
 
328
    Table = ?config(tableName, Config),
 
329
 
 
330
    {updated, _} = odbc:sql_query(Ref, 
 
331
                                  "CREATE TABLE " ++ Table ++
 
332
                                  " (ID integer)"),
 
333
 
 
334
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
335
                                  " VALUES(1)"),
 
336
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
337
                                  " VALUES(2)"),
 
338
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
339
                                  " VALUES(3)"),
 
340
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
341
                                  " VALUES(4)"),
 
342
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
343
                                  " VALUES(5)"),
 
344
 
 
345
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table), 
 
346
 
 
347
    SelectResult1 = ?RDBMS:selected_next_N(1),
 
348
    SelectResult1 = odbc:select(Ref, next, 3),
 
349
 
 
350
    %% Test that selecting stops at the end of the result set
 
351
    SelectResult2 = ?RDBMS:selected_next_N(2),
 
352
    SelectResult2 = odbc:select(Ref, next, 3, ?TIMEOUT), 
 
353
    {'EXIT',{function_clause, _}} = 
 
354
        (catch odbc:select(Ref, next, 2, -1)),
 
355
 
 
356
    %% If you try fetching data beyond the the end of result set,
 
357
    %% you get an empty list.
 
358
    {selected, Fields, []} = odbc:select(Ref, next, 1),
 
359
 
 
360
    ["ID"] = odbc_test_lib:to_upper(Fields),
 
361
    ok.
 
362
 
 
363
%%-------------------------------------------------------------------------
 
364
select_relative(doc) ->
 
365
    ["Tests select/[4,5] with CursorRelation = relative "];
 
366
select_relative(suit) -> [];
 
367
select_relative(Config) when is_list(Config) ->
 
368
    Ref = ?config(connection_ref, Config),
 
369
    Table = ?config(tableName, Config),
 
370
 
 
371
    {updated, _} = odbc:sql_query(Ref, 
 
372
                                  "CREATE TABLE " ++ Table ++
 
373
                                  " (ID integer)"),
 
374
 
 
375
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
376
                                  " VALUES(1)"),
 
377
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
378
                                  " VALUES(2)"), 
 
379
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
380
                                  " VALUES(3)"),
 
381
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
382
                                  " VALUES(4)"),
 
383
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
384
                                  " VALUES(5)"),
 
385
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
386
                                  " VALUES(6)"),
 
387
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
388
                                  " VALUES(7)"),
 
389
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
390
                                  " VALUES(8)"),
 
391
 
 
392
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
 
393
 
 
394
    SelectResult1 = ?RDBMS:selected_relative_N(1),
 
395
    SelectResult1 = odbc:select(Ref, {relative, 2}, 3),
 
396
 
 
397
    %% Test that selecting stops at the end of the result set
 
398
    SelectResult2 = ?RDBMS:selected_relative_N(2),
 
399
    SelectResult2 = odbc:select(Ref, {relative, 3}, 3, ?TIMEOUT),
 
400
    {'EXIT',{function_clause, _}} = 
 
401
        (catch odbc:select(Ref, {relative, 3} , 2, -1)),
 
402
    ok.
 
403
 
 
404
%%-------------------------------------------------------------------------
 
405
select_absolute(doc) ->
 
406
    ["Tests select/[4,5] with CursorRelation = absolute "];
 
407
select_absolute(suit) -> [];
 
408
select_absolute(Config) when is_list(Config) ->
 
409
    Ref = ?config(connection_ref, Config),
 
410
    Table = ?config(tableName, Config),
 
411
 
 
412
    {updated, _} = odbc:sql_query(Ref, 
 
413
                                  "CREATE TABLE " ++ Table ++
 
414
                                  " (ID integer)"),
 
415
 
 
416
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
417
                                  " VALUES(1)"),
 
418
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
419
                                  " VALUES(2)"),
 
420
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
421
                                  " VALUES(3)"),
 
422
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
423
                                  " VALUES(4)"),
 
424
    {updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
 
425
                                  " VALUES(5)"),
 
426
    {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table), 
 
427
 
 
428
    SelectResult1 = ?RDBMS:selected_absolute_N(1),
 
429
    SelectResult1 = odbc:select(Ref, {absolute, 1}, 3),
 
430
 
 
431
    %% Test that selecting stops at the end of the result set
 
432
    SelectResult2 = ?RDBMS:selected_absolute_N(2),
 
433
    SelectResult2 = odbc:select(Ref, {absolute, 1}, 6, ?TIMEOUT),
 
434
    {'EXIT',{function_clause, _}} = 
 
435
        (catch odbc:select(Ref, {absolute, 1}, 2, -1)),
 
436
    ok.
 
437
 
 
438
%%-------------------------------------------------------------------------
 
439
create_table_twice(doc) ->
 
440
    ["Test what happens if you try to create the same table twice."];
 
441
create_table_twice(suite) -> [];
 
442
create_table_twice(Config) when is_list(Config) ->
 
443
    Ref = ?config(connection_ref, Config),   
 
444
    Table = ?config(tableName, Config),
 
445
 
 
446
    {updated, _} = 
 
447
        odbc:sql_query(Ref, 
 
448
                       "CREATE TABLE " ++ Table ++
 
449
                       " (ID integer, DATA varchar(10))"),
 
450
    {error, Error} = 
 
451
        odbc:sql_query(Ref, 
 
452
                       "CREATE TABLE " ++ Table ++
 
453
                       " (ID integer, DATA varchar(10))"),
 
454
    is_driver_error(Error),
 
455
    ok.
 
456
 
 
457
%%-------------------------------------------------------------------------
 
458
delete_table_twice(doc) ->
 
459
    ["Test what happens if you try to delete the same table twice."];
 
460
delete_table_twice(suite) -> [];
 
461
delete_table_twice(Config) when is_list(Config) ->
 
462
    Ref = ?config(connection_ref, Config),   
 
463
    Table = ?config(tableName, Config),
 
464
 
 
465
    {updated, _} = 
 
466
        odbc:sql_query(Ref, 
 
467
                       "CREATE TABLE " ++ Table ++
 
468
                       " (ID integer, DATA varchar(10))"),
 
469
    {updated, _} = odbc:sql_query(Ref, "DROP TABLE " ++ Table),
 
470
    {error, Error} = odbc:sql_query(Ref, "DROP TABLE " ++ Table),
 
471
    is_driver_error(Error),
 
472
    ok.
 
473
 
 
474
%-------------------------------------------------------------------------
 
475
duplicate_key(doc) ->
 
476
    ["Test what happens if you try to use the same key twice"];
 
477
duplicate_key(suit) -> [];
 
478
duplicate_key(Config) when is_list(Config) ->
 
479
    Ref = ?config(connection_ref, Config),   
 
480
    Table = ?config(tableName, Config),
 
481
 
 
482
    {updated, _} = 
 
483
        odbc:sql_query(Ref, 
 
484
                       "CREATE TABLE " ++ Table ++
 
485
                       " (ID integer, DATA char(10), PRIMARY KEY(ID))"),
 
486
 
 
487
    {updated, 1} = 
 
488
        odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
 
489
 
 
490
    {error, Error} =
 
491
        odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'foo')"),
 
492
    is_driver_error(Error),
 
493
    ok.
 
494
 
 
495
%%-------------------------------------------------------------------------
 
496
not_connection_owner(doc) ->
 
497
    ["Test what happens if a process that did not start the connection"
 
498
     " tries to acess it."];
 
499
not_connection_owner(suite) -> [];
 
500
not_connection_owner(Config) when is_list(Config) ->
 
501
    Ref = ?config(connection_ref, Config),   
 
502
    Table = ?config(tableName, Config),
 
503
 
 
504
    spawn_link(?MODULE, not_owner, [self(), Ref, Table]),
 
505
 
 
506
    receive 
 
507
        continue ->
 
508
            ok
 
509
    end.
 
510
 
 
511
not_owner(Pid, Ref, Table) ->
 
512
    {error, process_not_owner_of_odbc_connection} =
 
513
        odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++ " (ID integer)"),
 
514
 
 
515
    {error, process_not_owner_of_odbc_connection} =
 
516
        odbc:disconnect(Ref),
 
517
 
 
518
    Pid ! continue.
 
519
 
 
520
%%-------------------------------------------------------------------------
 
521
no_result_set(doc) ->
 
522
    ["Tests what happens if you try to use a function that needs an "
 
523
     "associated result set when there is none."];
 
524
no_result_set(suite) -> [];
 
525
no_result_set(Config) when is_list(Config) ->
 
526
    Ref = ?config(connection_ref, Config),   
 
527
 
 
528
    {error, result_set_does_not_exist} = odbc:first(Ref),
 
529
    {error, result_set_does_not_exist} = odbc:last(Ref),
 
530
    {error, result_set_does_not_exist} = odbc:next(Ref),
 
531
    {error, result_set_does_not_exist} = odbc:prev(Ref),
 
532
    {error, result_set_does_not_exist} = odbc:select(Ref, next, 1),
 
533
    {error, result_set_does_not_exist} = 
 
534
        odbc:select(Ref, {absolute, 2}, 1),
 
535
    {error, result_set_does_not_exist} = 
 
536
        odbc:select(Ref, {relative, 2}, 1),
 
537
    ok.
 
538
%%-------------------------------------------------------------------------
 
539
query_error(doc) ->
 
540
    ["Test what happens if there is an error in the query."];
 
541
query_error(suite) ->
 
542
    [];
 
543
query_error(Config) when is_list(Config) ->
 
544
    Ref = ?config(connection_ref, Config),   
 
545
    Table = ?config(tableName, Config),
 
546
 
 
547
    {updated, _} = 
 
548
        odbc:sql_query(Ref, 
 
549
                       "CREATE TABLE " ++ Table ++
 
550
                       " (ID integer, DATA char(10), PRIMARY KEY(ID))"),
 
551
    {updated, 1} = 
 
552
        odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
 
553
 
 
554
    {error, _} = 
 
555
        odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
 
556
 
 
557
    {error, _} = 
 
558
        odbc:sql_query(Ref, "INSERT ONTO " ++ Table ++ " VALUES(1,'bar')"),
 
559
    ok.
 
560
 
 
561
%%-------------------------------------------------------------------------
 
562
multiple_select_result_sets(doc) ->
 
563
    ["Test what happens if you have a batch of select queries."];
 
564
multiple_select_result_sets(suite) ->
 
565
    [];
 
566
multiple_select_result_sets(Config) when is_list(Config) ->
 
567
    case ?RDBMS of
 
568
        sqlserver ->
 
569
            Ref = ?config(connection_ref, Config),   
 
570
            Table = ?config(tableName, Config),
 
571
            
 
572
            {updated, _} = 
 
573
                odbc:sql_query(Ref, 
 
574
                               "CREATE TABLE " ++ Table ++
 
575
                               " (ID integer, DATA varchar(10), "
 
576
                               "PRIMARY KEY(ID))"),
 
577
            {updated, 1} = 
 
578
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
579
                               " VALUES(1,'bar')"),
 
580
            
 
581
            {updated, 1} = 
 
582
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
583
                               " VALUES(2, 'foo')"),
 
584
            
 
585
            MultipleResult = ?RDBMS:multiple_select(),
 
586
            
 
587
            MultipleResult = 
 
588
                odbc:sql_query(Ref, "SELECT * FROM " ++ Table ++ 
 
589
                               "; SELECT DATA FROM "++ Table ++ 
 
590
                               " WHERE ID=2"),
 
591
            ok;
 
592
        _ ->
 
593
            {skip, "multiple result_set not supported"}
 
594
    end.
 
595
            
 
596
%%-------------------------------------------------------------------------
 
597
multiple_mix_result_sets(doc) ->
 
598
    ["Test what happens if you have a batch of select and other type of"
 
599
     " queries."];
 
600
multiple_mix_result_sets(suite) ->
 
601
    [];
 
602
multiple_mix_result_sets(Config) when is_list(Config) ->
 
603
    case ?RDBMS of
 
604
        sqlserver ->
 
605
            Ref = ?config(connection_ref, Config),   
 
606
            Table = ?config(tableName, Config),
 
607
            
 
608
            {updated, _} = 
 
609
                odbc:sql_query(Ref, 
 
610
                               "CREATE TABLE " ++ Table ++
 
611
                               " (ID integer, DATA varchar(10), "
 
612
                               "PRIMARY KEY(ID))"),
 
613
            {updated, 1} = 
 
614
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
615
                               " VALUES(1,'bar')"),
 
616
 
 
617
            MultipleResult = ?RDBMS:multiple_mix(),
 
618
            
 
619
            MultipleResult = 
 
620
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
621
                               " VALUES(2,'foo'); UPDATE " ++ Table ++ 
 
622
                               " SET DATA = 'foobar' WHERE ID =1;SELECT "
 
623
                               "* FROM " 
 
624
                               ++ Table ++ ";DELETE FROM " ++ Table ++
 
625
                               " WHERE ID =1; SELECT DATA FROM " ++ Table),
 
626
            ok;
 
627
        _ ->
 
628
            {skip, "multiple result_set not supported"}
 
629
    end.
 
630
%%-------------------------------------------------------------------------
 
631
multiple_result_sets_error(doc) ->
 
632
    ["Test what happens if one of the batched queries fails."];
 
633
multiple_result_sets_error(suite) ->
 
634
    [];
 
635
multiple_result_sets_error(Config) when is_list(Config) ->
 
636
    case ?RDBMS of
 
637
        sqlserver ->
 
638
            Ref = ?config(connection_ref, Config),   
 
639
            Table = ?config(tableName, Config),
 
640
            
 
641
            {updated, _} = 
 
642
                odbc:sql_query(Ref, 
 
643
                               "CREATE TABLE " ++ Table ++
 
644
                               " (ID integer, DATA varchar(10), "
 
645
                               "PRIMARY KEY(ID))"),
 
646
            {updated, 1} = 
 
647
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
648
                               " VALUES(1,'bar')"),
 
649
            
 
650
            {error, Error} = 
 
651
                odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ 
 
652
                               " VALUES(1,'foo'); SELECT * FROM " ++ Table),
 
653
            is_driver_error(Error),
 
654
            
 
655
            {error, NewError} = 
 
656
                odbc:sql_query(Ref, "SELECT * FROM " 
 
657
                               ++ Table ++ ";INSERT INTO " ++ Table ++ 
 
658
                       " VALUES(1,'foo')"),
 
659
            is_driver_error(NewError),
 
660
            ok;
 
661
        _ ->
 
662
            {skip, "multiple result_set not supported"}
 
663
    end.   
 
664
 
 
665
%%-------------------------------------------------------------------------
 
666
 
 
667
%%-------------------------------------------------------------------------
 
668
%%-------------------------------------------------------------------------
 
669
param_insert_tiny_int(doc)->
 
670
    ["Test insertion of tiny ints by parameterized queries."];
 
671
param_insert_tiny_int(suite) ->
 
672
    [];
 
673
param_insert_tiny_int(Config) when is_list(Config) ->
 
674
    case ?RDBMS of 
 
675
        sqlserver ->
 
676
            Ref = ?config(connection_ref, Config),   
 
677
            Table = ?config(tableName, Config),
 
678
            
 
679
            {updated, _} = 
 
680
                odbc:sql_query(Ref, 
 
681
                               "CREATE TABLE " ++ Table ++
 
682
                               " (FIELD TINYINT)"),
 
683
            
 
684
            {updated, Count} = 
 
685
                odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
686
                                 "(FIELD) VALUES(?)", 
 
687
                                 [{sql_tinyint, [1, 2]}],
 
688
                                 ?TIMEOUT),%Make sure to test timeout clause
 
689
            
 
690
            true = odbc_test_lib:check_row_count(2, Count),
 
691
            
 
692
            InsertResult = ?RDBMS:param_select_tiny_int(),
 
693
            
 
694
            InsertResult = 
 
695
                odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
696
            
 
697
            {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
698
                (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
699
                                "(FIELD) VALUES(?)",
 
700
                                        [{sql_tinyint, [1, "2"]}])),
 
701
            ok;
 
702
        _  ->
 
703
            {skip, "Type tiniyint not supported"}
 
704
    end.
 
705
%%-------------------------------------------------------------------------
 
706
param_insert_small_int(doc)->
 
707
    ["Test insertion of small ints by parameterized queries."];
 
708
param_insert_small_int(suite) ->
 
709
    [];
 
710
param_insert_small_int(Config) when is_list(Config) ->
 
711
    Ref = ?config(connection_ref, Config),   
 
712
    Table = ?config(tableName, Config),
 
713
 
 
714
    {updated, _} = 
 
715
        odbc:sql_query(Ref, 
 
716
                       "CREATE TABLE " ++ Table ++
 
717
                       " (FIELD SMALLINT)"),
 
718
 
 
719
    {updated, Count} = 
 
720
        odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
721
                         "(FIELD) VALUES(?)", [{sql_smallint, [1, 2]}],
 
722
                         ?TIMEOUT), %% Make sure to test timeout clause
 
723
 
 
724
    true = odbc_test_lib:check_row_count(2, Count),
 
725
 
 
726
    InsertResult = ?RDBMS:param_select_small_int(),
 
727
 
 
728
    InsertResult = 
 
729
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
730
 
 
731
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
732
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
733
                                "(FIELD) VALUES(?)",
 
734
                                [{sql_smallint, [1, "2"]}])),    
 
735
    ok.
 
736
 
 
737
%%-------------------------------------------------------------------------
 
738
param_insert_int(doc)->
 
739
    ["Test insertion of ints by parameterized queries."];
 
740
param_insert_int(suite) ->
 
741
    [];
 
742
param_insert_int(Config) when is_list(Config) ->
 
743
    Ref = ?config(connection_ref, Config),   
 
744
    Table = ?config(tableName, Config),
 
745
 
 
746
    {updated, _} = 
 
747
        odbc:sql_query(Ref, 
 
748
                       "CREATE TABLE " ++ Table ++
 
749
                       " (FIELD INT)"),
 
750
 
 
751
    Int = ?RDBMS:small_int_max() + 1,
 
752
 
 
753
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
754
                                   "(FIELD) VALUES(?)", 
 
755
                                   [{sql_integer, [1, Int]}]),
 
756
    true = odbc_test_lib:check_row_count(2, Count),
 
757
    
 
758
    InsertResult = ?RDBMS:param_select_int(),
 
759
 
 
760
    InsertResult = 
 
761
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
762
 
 
763
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
764
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
765
                                "(FIELD) VALUES(?)",
 
766
                                [{sql_integer, [1, "2"]}])),
 
767
    ok.
 
768
 
 
769
%%-------------------------------------------------------------------------
 
770
param_insert_integer(doc)->
 
771
    ["Test insertion of integers by parameterized queries."];
 
772
param_insert_integer(suite) ->
 
773
    [];
 
774
param_insert_integer(Config) when is_list(Config) ->
 
775
    Ref = ?config(connection_ref, Config),   
 
776
    Table = ?config(tableName, Config),
 
777
 
 
778
    {updated, _} = 
 
779
        odbc:sql_query(Ref, 
 
780
                       "CREATE TABLE " ++ Table ++
 
781
                       " (FIELD INTEGER)"),
 
782
 
 
783
    Int = ?RDBMS:small_int_max() + 1,
 
784
 
 
785
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
786
                                    "(FIELD) VALUES(?)", 
 
787
                                    [{sql_integer, [1, Int]}]),
 
788
    true = odbc_test_lib:check_row_count(2, Count),
 
789
 
 
790
    InsertResult = ?RDBMS:param_select_int(),
 
791
 
 
792
    InsertResult = 
 
793
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
794
 
 
795
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
796
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
797
                                "(FIELD) VALUES(?)", 
 
798
                                [{sql_integer, [1, 2.3]}])),  
 
799
    ok.
 
800
 
 
801
%%-------------------------------------------------------------------------
 
802
param_insert_decimal(doc)->
 
803
    ["Test insertion of decimal numbers by parameterized queries."];
 
804
param_insert_decimal(suite) ->
 
805
    [];
 
806
param_insert_decimal(Config) when is_list(Config) ->
 
807
    Ref = ?config(connection_ref, Config),   
 
808
    Table = ?config(tableName, Config),
 
809
 
 
810
    {updated, _} = 
 
811
        odbc:sql_query(Ref, 
 
812
                       "CREATE TABLE " ++ Table ++
 
813
                       " (FIELD DECIMAL (3,0))"),
 
814
 
 
815
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
816
                                    "(FIELD) VALUES(?)", 
 
817
                                    [{{sql_decimal, 3, 0}, [1, 2]}]),
 
818
    true = odbc_test_lib:check_row_count(2, Count),
 
819
    
 
820
    InsertResult = ?RDBMS:param_select_decimal(),
 
821
 
 
822
    InsertResult = 
 
823
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
824
 
 
825
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
826
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
827
                                "(FIELD) VALUES(?)", 
 
828
                                [{{sql_decimal, 3, 0}, [1, "2"]}])),
 
829
 
 
830
 
 
831
    odbc:sql_query(Ref, "DROP TABLE " ++ Table),
 
832
 
 
833
    {updated, _} = 
 
834
        odbc:sql_query(Ref, 
 
835
                       "CREATE TABLE " ++ Table ++
 
836
                       " (FIELD DECIMAL (3,1))"),
 
837
 
 
838
    {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
839
                                           "(FIELD) VALUES(?)", 
 
840
                                    [{{sql_decimal, 3, 1}, [0.25]}]),
 
841
    true = odbc_test_lib:check_row_count(1, NewCount),
 
842
    
 
843
    {selected, Fields, [{Value}]} = 
 
844
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
845
 
 
846
    ["FIELD"] = odbc_test_lib:to_upper(Fields),
 
847
    
 
848
    odbc_test_lib:match_float(Value, 0.3, 0.01),
 
849
    
 
850
    ok.
 
851
 
 
852
%%-------------------------------------------------------------------------
 
853
param_insert_numeric(doc)->
 
854
    ["Test insertion of numeric numbers by parameterized queries."];
 
855
param_insert_numeric(suite) ->
 
856
    [];
 
857
param_insert_numeric(Config) when is_list(Config) ->
 
858
    Ref = ?config(connection_ref, Config),   
 
859
    Table = ?config(tableName, Config),
 
860
 
 
861
    {updated, _} = 
 
862
        odbc:sql_query(Ref, 
 
863
                       "CREATE TABLE " ++ Table ++
 
864
                       " (FIELD NUMERIC (3,0))"),
 
865
 
 
866
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
867
                                   "(FIELD) VALUES(?)", 
 
868
                                   [{{sql_numeric,3,0}, [1, 2]}]),
 
869
 
 
870
    true = odbc_test_lib:check_row_count(2, Count),
 
871
 
 
872
    InsertResult = ?RDBMS:param_select_numeric(),
 
873
 
 
874
    InsertResult = 
 
875
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
876
 
 
877
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
878
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
879
                                "(FIELD) VALUES(?)", 
 
880
                                [{{sql_decimal, 3, 0}, [1, "2"]}])),    
 
881
 
 
882
    odbc:sql_query(Ref, "DROP TABLE " ++ Table),
 
883
 
 
884
    {updated, _} = 
 
885
        odbc:sql_query(Ref, 
 
886
                       "CREATE TABLE " ++ Table ++
 
887
                       " (FIELD NUMERIC (3,1))"),
 
888
 
 
889
    {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
890
                                    "(FIELD) VALUES(?)", 
 
891
                                    [{{sql_numeric, 3, 1}, [0.25]}]),
 
892
 
 
893
    true = odbc_test_lib:check_row_count(1, NewCount),
 
894
 
 
895
    {selected, Fileds, [{Value}]} = 
 
896
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
897
 
 
898
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
899
 
 
900
    odbc_test_lib:match_float(Value, 0.3, 0.01),
 
901
    ok.
 
902
 
 
903
%%-------------------------------------------------------------------------
 
904
 
 
905
%%-------------------------------------------------------------------------
 
906
param_insert_char(doc)->
 
907
    ["Test insertion of fixed length string by parameterized queries."];
 
908
param_insert_char(suite) ->
 
909
    [];
 
910
param_insert_char(Config) when is_list(Config) ->
 
911
    Ref = ?config(connection_ref, Config),   
 
912
    Table = ?config(tableName, Config),
 
913
 
 
914
    {updated, _} = 
 
915
        odbc:sql_query(Ref, 
 
916
                       "CREATE TABLE " ++ Table ++
 
917
                       " (FIELD CHAR (10))"),
 
918
 
 
919
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
920
                                   "(FIELD) VALUES(?)", 
 
921
                                   [{{sql_char, 10}, 
 
922
                                     ["foofoofoof", "0123456789"]}]),
 
923
    true = odbc_test_lib:check_row_count(2, Count),
 
924
 
 
925
    {selected,Fileds,[{"foofoofoof"}, {"0123456789"}]} =
 
926
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
927
 
 
928
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
929
 
 
930
    {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
931
                                  "(FIELD) VALUES(?)", 
 
932
                                  [{{sql_char, 10}, 
 
933
                                    ["foo", "01234567890"]}]),
 
934
 
 
935
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
936
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
937
                                "(FIELD) VALUES(?)",
 
938
                                [{{sql_char, 10}, ["1", 2.3]}])), 
 
939
    ok.
 
940
 
 
941
%%-------------------------------------------------------------------------
 
942
param_insert_character(doc)->
 
943
    ["Test insertion of fixed length string by parameterized queries."];
 
944
param_insert_character(suite) ->
 
945
    [];
 
946
param_insert_character(Config) when is_list(Config) ->
 
947
    Ref = ?config(connection_ref, Config),   
 
948
    Table = ?config(tableName, Config),
 
949
 
 
950
    {updated, _} = 
 
951
        odbc:sql_query(Ref, 
 
952
                       "CREATE TABLE " ++ Table ++
 
953
                       " (FIELD CHARACTER (10))"),
 
954
 
 
955
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
956
                                   "(FIELD) VALUES(?)", 
 
957
                                   [{{sql_char, 10}, 
 
958
                                     ["foofoofoof", "0123456789"]}]),
 
959
 
 
960
    true = odbc_test_lib:check_row_count(2, Count),
 
961
 
 
962
    {selected, Fileds, [{"foofoofoof"}, {"0123456789"}]} =
 
963
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
964
 
 
965
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
966
 
 
967
    {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
968
                                  "(FIELD) VALUES(?)", 
 
969
                                  [{{sql_char, 10}, 
 
970
                                    ["foo", "01234567890"]}]),
 
971
 
 
972
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
973
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
974
                                "(FIELD) VALUES(?)", 
 
975
                                [{{sql_char, 10}, ["1", 2]}])), 
 
976
    ok.
 
977
 
 
978
%%------------------------------------------------------------------------
 
979
param_insert_char_varying(doc)->
 
980
    ["Test insertion of variable length strings by parameterized queries."];
 
981
param_insert_char_varying(suite) ->
 
982
    [];
 
983
param_insert_char_varying(Config) when is_list(Config) ->
 
984
    Ref = ?config(connection_ref, Config),   
 
985
    Table = ?config(tableName, Config),
 
986
 
 
987
    {updated, _} = 
 
988
        odbc:sql_query(Ref, 
 
989
                       "CREATE TABLE " ++ Table ++
 
990
                       " (FIELD CHAR VARYING(10))"),
 
991
 
 
992
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
993
                                   "(FIELD) VALUES(?)", 
 
994
                                   [{{sql_varchar, 10}, 
 
995
                                     ["foo", "0123456789"]}]),
 
996
    
 
997
    true = odbc_test_lib:check_row_count(2, Count),
 
998
 
 
999
    {selected, Fileds, [{"foo"}, {"0123456789"}]} =
 
1000
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1001
 
 
1002
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
1003
 
 
1004
    {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1005
                                  "(FIELD) VALUES(?)", 
 
1006
                                  [{{sql_varchar, 10}, 
 
1007
                                    ["foo", "01234567890"]}]),
 
1008
 
 
1009
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
1010
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1011
                                "(FIELD) VALUES(?)", 
 
1012
                                [{{sql_varchar, 10}, ["1", 2.3]}])), 
 
1013
    ok.
 
1014
 
 
1015
%%-------------------------------------------------------------------------
 
1016
param_insert_character_varying(doc)->
 
1017
    ["Test insertion of variable length strings by parameterized queries."];
 
1018
param_insert_character_varying(suite) ->
 
1019
    [];
 
1020
param_insert_character_varying(Config) when is_list(Config) ->
 
1021
    Ref = ?config(connection_ref, Config),   
 
1022
    Table = ?config(tableName, Config),
 
1023
 
 
1024
    {updated, _} = 
 
1025
        odbc:sql_query(Ref, 
 
1026
                       "CREATE TABLE " ++ Table ++
 
1027
                       " (FIELD CHARACTER VARYING(10))"),
 
1028
 
 
1029
 
 
1030
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1031
                                   "(FIELD) VALUES(?)", 
 
1032
                                   [{{sql_varchar, 10}, 
 
1033
                                     ["foo", "0123456789"]}]),
 
1034
 
 
1035
    true = odbc_test_lib:check_row_count(2, Count),
 
1036
 
 
1037
    {selected, Fileds, [{"foo"}, {"0123456789"}]} =
 
1038
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1039
 
 
1040
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
1041
 
 
1042
    {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1043
                                  "(FIELD) VALUES(?)", 
 
1044
                                  [{{sql_varchar, 10}, 
 
1045
                                    ["foo", "01234567890"]}]),
 
1046
 
 
1047
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
1048
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1049
                                "(FIELD) VALUES(?)", 
 
1050
                                [{{sql_varchar, 10}, ["1", 2]}])), 
 
1051
    ok.
 
1052
%%-------------------------------------------------------------------------
 
1053
param_insert_float(doc)->
 
1054
    ["Test insertion of floats by parameterized queries."];
 
1055
param_insert_float(suite) ->
 
1056
    [];
 
1057
param_insert_float(Config) when is_list(Config) ->
 
1058
    Ref = ?config(connection_ref, Config),   
 
1059
    Table = ?config(tableName, Config),
 
1060
 
 
1061
    {updated, _} = 
 
1062
        odbc:sql_query(Ref, 
 
1063
                       "CREATE TABLE " ++ Table ++
 
1064
                       " (FIELD FLOAT(5))"),
 
1065
 
 
1066
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1067
                                    "(FIELD) VALUES(?)", 
 
1068
                                    [{{sql_float,5}, [1.3, 1.2]}]),
 
1069
 
 
1070
    true = odbc_test_lib:check_row_count(2, Count),
 
1071
 
 
1072
    {selected, Fileds, [{Float1},{Float2}]} =
 
1073
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1074
 
 
1075
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
1076
 
 
1077
    case (odbc_test_lib:match_float(Float1, 1.3, 0.000001) and 
 
1078
          odbc_test_lib:match_float(Float2, 1.2, 0.000001)) of
 
1079
        true ->
 
1080
            ok;
 
1081
        false ->
 
1082
            test_server:fail(float_numbers_do_not_match)
 
1083
    end,
 
1084
 
 
1085
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
1086
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1087
                                "(FIELD) VALUES(?)",
 
1088
                                [{{sql_float, 5}, [1.0, "2"]}])),
 
1089
    ok.
 
1090
 
 
1091
%%-------------------------------------------------------------------------
 
1092
param_insert_real(doc)->
 
1093
    ["Test insertion of real numbers by parameterized queries."];
 
1094
param_insert_real(suite) ->
 
1095
    [];
 
1096
param_insert_real(Config) when is_list(Config) ->
 
1097
    Ref = ?config(connection_ref, Config),   
 
1098
    Table = ?config(tableName, Config),
 
1099
 
 
1100
    {updated, _} = 
 
1101
        odbc:sql_query(Ref, 
 
1102
                       "CREATE TABLE " ++ Table ++
 
1103
                       " (FIELD REAL)"),
 
1104
 
 
1105
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1106
                                   "(FIELD) VALUES(?)", 
 
1107
                                   [{sql_real, [1.3, 1.2]}]),
 
1108
 
 
1109
    true = odbc_test_lib:check_row_count(2, Count),
 
1110
 
 
1111
    %_InsertResult = ?RDBMS:param_select_real(),
 
1112
 
 
1113
    {selected, Fileds, [{Real1},{Real2}]} =
 
1114
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1115
 
 
1116
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
1117
 
 
1118
    case (odbc_test_lib:match_float(Real1, 1.3, 0.000001) and 
 
1119
          odbc_test_lib:match_float(Real2, 1.2, 0.000001)) of
 
1120
        true ->
 
1121
            ok;
 
1122
        false ->
 
1123
            test_server:fail(real_numbers_do_not_match)
 
1124
    end,
 
1125
 
 
1126
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
1127
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1128
                                "(FIELD) VALUES(?)",
 
1129
                                [{sql_real,[1.0, "2"]}])),
 
1130
    ok.
 
1131
 
 
1132
%%-------------------------------------------------------------------------
 
1133
param_insert_double(doc)->
 
1134
    ["Test insertion of doubles by parameterized queries."];
 
1135
param_insert_double(suite) ->
 
1136
    [];
 
1137
param_insert_double(Config) when is_list(Config) ->
 
1138
    Ref = ?config(connection_ref, Config),   
 
1139
    Table = ?config(tableName, Config),
 
1140
 
 
1141
    {updated, _} = 
 
1142
        odbc:sql_query(Ref, 
 
1143
                       "CREATE TABLE " ++ Table ++
 
1144
                       " (FIELD DOUBLE PRECISION)"),
 
1145
 
 
1146
    {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1147
                                   "(FIELD) VALUES(?)", 
 
1148
                                   [{sql_double, [1.3, 1.2]}]),
 
1149
 
 
1150
    true = odbc_test_lib:check_row_count(2, Count),
 
1151
 
 
1152
    {selected, Fileds, [{Double1},{Double2}]} =
 
1153
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1154
 
 
1155
    ["FIELD"] = odbc_test_lib:to_upper(Fileds),
 
1156
 
 
1157
    case (odbc_test_lib:match_float(Double1, 1.3, 0.000001) and 
 
1158
          odbc_test_lib:match_float(Double2, 1.2, 0.000001)) of
 
1159
        true ->
 
1160
            ok;
 
1161
        false ->
 
1162
            test_server:fail(double_numbers_do_not_match)
 
1163
    end,
 
1164
 
 
1165
    {'EXIT',{badarg,odbc,param_query,'Params'}} = 
 
1166
        (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1167
                                "(FIELD) VALUES(?)", 
 
1168
                                [{sql_double, [1.0, "2"]}])),
 
1169
    ok.
 
1170
 
 
1171
%%-------------------------------------------------------------------------
 
1172
param_insert_mix(doc)->
 
1173
    ["Test insertion of a mixture of datatypes by parameterized queries."];
 
1174
param_insert_mix(suite) ->
 
1175
    [];
 
1176
param_insert_mix(Config) when is_list(Config) ->
 
1177
    Ref = ?config(connection_ref, Config),   
 
1178
    Table = ?config(tableName, Config),
 
1179
 
 
1180
    {updated, _} = 
 
1181
        odbc:sql_query(Ref, 
 
1182
                       "CREATE TABLE " ++ Table ++
 
1183
                       " (ID INTEGER, DATA CHARACTER VARYING(10),"
 
1184
                       " PRIMARY KEY(ID))"),
 
1185
 
 
1186
    {updated, Count}  = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1187
                                    "(ID, DATA) VALUES(?, ?)",
 
1188
                                    [{sql_integer, [1, 2]}, 
 
1189
                                     {{sql_varchar, 10}, ["foo", "bar"]}]),
 
1190
 
 
1191
    true = odbc_test_lib:check_row_count(2, Count),
 
1192
 
 
1193
    InsertResult = ?RDBMS:param_select_mix(),
 
1194
 
 
1195
    InsertResult = 
 
1196
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1197
    ok.
 
1198
%%-------------------------------------------------------------------------
 
1199
param_update(doc)->
 
1200
    ["Test parameterized update query."];
 
1201
param_update(suite) ->
 
1202
    [];
 
1203
param_update(Config) when is_list(Config) ->
 
1204
    Ref = ?config(connection_ref, Config),   
 
1205
    Table = ?config(tableName, Config),
 
1206
 
 
1207
    {updated, _} = 
 
1208
        odbc:sql_query(Ref, 
 
1209
                       "CREATE TABLE " ++ Table ++
 
1210
                       " (ID INTEGER, DATA CHARACTER VARYING(10),"
 
1211
                       " PRIMARY KEY(ID))"),
 
1212
 
 
1213
    {updated, Count}  = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1214
                                    "(ID, DATA) VALUES(?, ?)",
 
1215
                                    [{sql_integer, [1, 2, 3]}, 
 
1216
                                     {{sql_varchar, 10}, 
 
1217
                                      ["foo", "bar", "baz"]}]),
 
1218
 
 
1219
    true = odbc_test_lib:check_row_count(3, Count),
 
1220
 
 
1221
    {updated, NewCount}  = odbc:param_query(Ref, "UPDATE " ++ Table ++
 
1222
                                    " SET DATA = 'foobar' WHERE ID = ?",
 
1223
                                    [{sql_integer, [1, 2]}]), 
 
1224
 
 
1225
     true = odbc_test_lib:check_row_count(2, NewCount),
 
1226
 
 
1227
    UpdateResult = ?RDBMS:param_update(),
 
1228
 
 
1229
    UpdateResult = 
 
1230
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1231
    ok.
 
1232
 
 
1233
%%-------------------------------------------------------------------------
 
1234
delete_nonexisting_row(doc) ->          % OTP-5759
 
1235
    ["Make a delete...where with false conditions (0 rows deleted). ",
 
1236
     "This used to give an error message (see ticket OTP-5759)."];
 
1237
delete_nonexisting_row(Config) when is_list(Config) ->
 
1238
    Ref = ?config(connection_ref, Config),   
 
1239
    Table = ?config(tableName, Config),
 
1240
 
 
1241
    {updated, _} =
 
1242
        odbc:sql_query(Ref, "CREATE TABLE " ++ Table
 
1243
                       ++ " (ID INTEGER, DATA CHARACTER VARYING(10))"),
 
1244
    {updated, Count} =
 
1245
        odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1246
                         "(ID, DATA) VALUES(?, ?)",
 
1247
                         [{sql_integer, [1, 2, 3]},
 
1248
                          {{sql_varchar, 10}, ["foo", "bar", "baz"]}]),
 
1249
     
 
1250
    true = odbc_test_lib:check_row_count(3, Count),
 
1251
 
 
1252
    {updated, NewCount} =
 
1253
        odbc:sql_query(Ref, "DELETE FROM " ++ Table ++ " WHERE ID = 8"),
 
1254
 
 
1255
    true = odbc_test_lib:check_row_count(0, NewCount),
 
1256
 
 
1257
    {updated, _} =
 
1258
        odbc:sql_query(Ref, "DROP TABLE "++ Table),
 
1259
 
 
1260
    ok.
 
1261
 
 
1262
%%-------------------------------------------------------------------------
 
1263
param_delete(doc) ->
 
1264
    ["Test parameterized delete query."];
 
1265
param_delete(suite) ->
 
1266
    [];
 
1267
param_delete(Config) when is_list(Config) ->
 
1268
    Ref = ?config(connection_ref, Config),   
 
1269
    Table = ?config(tableName, Config),
 
1270
 
 
1271
    {updated, _} = 
 
1272
        odbc:sql_query(Ref, 
 
1273
                       "CREATE TABLE " ++ Table ++
 
1274
                       " (ID INTEGER, DATA CHARACTER VARYING(10),"
 
1275
                       " PRIMARY KEY(ID))"),
 
1276
 
 
1277
    {updated, Count}  = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1278
                                    "(ID, DATA) VALUES(?, ?)",
 
1279
                                    [{sql_integer, [1, 2, 3]}, 
 
1280
                                     {{sql_varchar, 10}, 
 
1281
                                      ["foo", "bar", "baz"]}]),
 
1282
    true = odbc_test_lib:check_row_count(3, Count),
 
1283
 
 
1284
    {updated, NewCount}  = odbc:param_query(Ref, "DELETE FROM " ++ Table ++
 
1285
                                    " WHERE ID = ?",
 
1286
                                    [{sql_integer, [1, 2]}]), 
 
1287
 
 
1288
    true = odbc_test_lib:check_row_count(2, NewCount),
 
1289
 
 
1290
    UpdateResult = ?RDBMS:param_delete(),
 
1291
 
 
1292
    UpdateResult = 
 
1293
        odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
 
1294
    ok.
 
1295
 
 
1296
 
 
1297
%%-------------------------------------------------------------------------
 
1298
param_select(doc) ->
 
1299
    ["Test parameterized select query."];
 
1300
param_select(suite) ->
 
1301
    [];
 
1302
param_select(Config) when is_list(Config) ->
 
1303
    Ref = ?config(connection_ref, Config),   
 
1304
    Table = ?config(tableName, Config),
 
1305
 
 
1306
    {updated, _} = 
 
1307
        odbc:sql_query(Ref, 
 
1308
                       "CREATE TABLE " ++ Table ++
 
1309
                       " (ID INTEGER, DATA CHARACTER VARYING(10),"
 
1310
                       " PRIMARY KEY(ID))"),
 
1311
 
 
1312
    {updated, Count}  = odbc:param_query(Ref, "INSERT INTO " ++ Table ++ 
 
1313
                                    "(ID, DATA) VALUES(?, ?)",
 
1314
                                    [{sql_integer, [1, 2, 3]}, 
 
1315
                                     {{sql_varchar, 10}, 
 
1316
                                      ["foo", "bar", "foo"]}]),
 
1317
 
 
1318
    true = odbc_test_lib:check_row_count(3, Count),
 
1319
 
 
1320
    SelectResult = ?RDBMS:param_select(),
 
1321
 
 
1322
    SelectResult = odbc:param_query(Ref, "SELECT * FROM " ++ Table ++
 
1323
                                    " WHERE DATA = ?",
 
1324
                                    [{{sql_varchar, 10}, ["foo"]}]), 
 
1325
    ok.
 
1326
 
 
1327
%%-------------------------------------------------------------------------
 
1328
 
 
1329
%%-------------------------------------------------------------------------
 
1330
describe_integer(doc) ->
 
1331
    ["Test describe_table/[2,3] for integer columns."];
 
1332
describe_integer(suite) ->
 
1333
    [];
 
1334
describe_integer(Config) when is_list(Config) ->    
 
1335
    Ref = ?config(connection_ref, Config),   
 
1336
    Table = ?config(tableName, Config),
 
1337
 
 
1338
    {updated, _} = 
 
1339
        odbc:sql_query(Ref, 
 
1340
                       "CREATE TABLE " ++ Table ++
 
1341
                       " (int1 SMALLINT, int2 INT, int3 INTEGER)"),
 
1342
 
 
1343
    Decs = ?RDBMS:describe_integer(),
 
1344
    %% Make sure to test timeout clause
 
1345
    Decs = odbc:describe_table(Ref, Table, ?TIMEOUT), 
 
1346
    ok.
 
1347
 
 
1348
%%-------------------------------------------------------------------------
 
1349
describe_string(doc) ->
 
1350
    ["Test describe_table/[2,3] for string columns."];
 
1351
describe_string(suite) ->
 
1352
    [];
 
1353
describe_string(Config) when is_list(Config) ->
 
1354
    Ref = ?config(connection_ref, Config),   
 
1355
    Table = ?config(tableName, Config),
 
1356
 
 
1357
    {updated, _} = 
 
1358
        odbc:sql_query(Ref, 
 
1359
                       "CREATE TABLE " ++ Table ++
 
1360
                       " (str1 char(10), str2 character(10), "
 
1361
                       "str3 CHAR VARYING(10), str4 "
 
1362
                       "CHARACTER VARYING(10))"),
 
1363
 
 
1364
    Decs = ?RDBMS:describe_string(),
 
1365
 
 
1366
    Decs = odbc:describe_table(Ref, Table),
 
1367
    ok.
 
1368
 
 
1369
%%-------------------------------------------------------------------------
 
1370
describe_floating(doc) ->
 
1371
    ["Test describe_table/[2,3] for floting columns."];
 
1372
describe_floating(suite) ->
 
1373
    [];
 
1374
describe_floating(Config) when is_list(Config) ->
 
1375
    Ref = ?config(connection_ref, Config),   
 
1376
    Table = ?config(tableName, Config),
 
1377
 
 
1378
    {updated, _} = 
 
1379
        odbc:sql_query(Ref, 
 
1380
                       "CREATE TABLE " ++ Table ++
 
1381
                       " (f FLOAT(5), r REAL, "
 
1382
                       "d DOUBLE PRECISION)"),
 
1383
 
 
1384
    Decs = ?RDBMS:describe_floating(),
 
1385
 
 
1386
    Decs = odbc:describe_table(Ref, Table),
 
1387
    ok.
 
1388
 
 
1389
%%-------------------------------------------------------------------------
 
1390
describe_dec_num(doc) ->
 
1391
    ["Test describe_table/[2,3] for decimal and numerical columns"];
 
1392
describe_dec_num(suite) ->
 
1393
    [];
 
1394
describe_dec_num(Config) when is_list(Config) ->
 
1395
 
 
1396
    Ref = ?config(connection_ref, Config),   
 
1397
    Table = ?config(tableName, Config),
 
1398
 
 
1399
    {updated, _} = 
 
1400
        odbc:sql_query(Ref, 
 
1401
                       "CREATE TABLE " ++ Table ++
 
1402
                       " (dec DECIMAL(9,3), num NUMERIC(9,2))"),
 
1403
 
 
1404
    Decs = ?RDBMS:describe_dec_num(),
 
1405
 
 
1406
    Decs = odbc:describe_table(Ref, Table),
 
1407
    ok.
 
1408
 
 
1409
 
 
1410
%%-------------------------------------------------------------------------
 
1411
describe_timestamp(doc) ->
 
1412
    ["Test describe_table/[2,3] for tinmestap columns"];
 
1413
describe_timestamp(suite) ->
 
1414
    [];
 
1415
describe_timestamp(Config) when is_list(Config) ->
 
1416
    
 
1417
    Ref = ?config(connection_ref, Config),   
 
1418
    Table = ?config(tableName, Config),
 
1419
    
 
1420
    {updated, _} =  % Value == 0 || -1 driver dependent!
 
1421
        odbc:sql_query(Ref,  "CREATE TABLE " ++ Table ++ 
 
1422
                       ?RDBMS:create_timestamp_table()),
 
1423
 
 
1424
    Decs = ?RDBMS:describe_timestamp(),
 
1425
 
 
1426
    Decs = odbc:describe_table(Ref, Table),
 
1427
    ok.
 
1428
 
 
1429
%%-------------------------------------------------------------------------
 
1430
describe_no_such_table(doc) ->
 
1431
    ["Test what happens if you try to describe a table that does not exist."];
 
1432
describe_no_such_table(suite) ->
 
1433
    [];
 
1434
describe_no_such_table(Config) when is_list(Config) ->
 
1435
 
 
1436
    Ref = ?config(connection_ref, Config),   
 
1437
    Table = ?config(tableName, Config),
 
1438
 
 
1439
    {error, _ } = odbc:describe_table(Ref, Table),
 
1440
    ok.
 
1441
 
 
1442
%%-------------------------------------------------------------------------
 
1443
%% Internal functions
 
1444
%%-------------------------------------------------------------------------
 
1445
 
 
1446
is_driver_error(Error) ->
 
1447
    case is_list(Error) of
 
1448
        true ->
 
1449
            test_server:format("Driver error ~p~n", [Error]),
 
1450
            ok;
 
1451
        false ->
 
1452
            test_server:fail(Error)
 
1453
    end.