Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
//-----------------------------------------------------------------------------
// Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
// This program is free software: you can modify it and/or redistribute it
// under the terms of:
//
// (i)  the Universal Permissive License v 1.0 or at your option, any
//      later version (http://oss.oracle.com/licenses/upl); and/or
//
// (ii) the Apache License v 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// TestQueries.c
//   Test suite for testing queries.
//-----------------------------------------------------------------------------

#include "TestLib.h"

//-----------------------------------------------------------------------------
// dpiTest__execStatement() [INTERNAL]
//   Prepare and execute statements and, if necessary, check number of rows.
//-----------------------------------------------------------------------------
int dpiTest__execStatement(dpiTestCase *testCase, dpiConn *conn,
        const char *sql, int cols)
{
    uint32_t numQueryColumns;
    dpiStmt *stmt;

    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_release(stmt);
    if (cols >= 0) {
        if (dpiTestCase_expectUintEqual(testCase, numQueryColumns, cols) < 0)
            return DPI_FAILURE;
    }
    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest__insertIntoTestLongs() [INTERNAL]
//   Inserts rows into table.
//-----------------------------------------------------------------------------
int dpiTest__insertIntoTestLongs(dpiTestCase *testCase, dpiConn *conn)
{
    uint32_t longValueLength, numQueryColumns, arraySize =3, numOfRows = 2;
    const char *insertSql = "insert into TestLongs values (:1, :2)";
    const char *dropSql = "delete from TestLongs";
    uint32_t iter, sizeIncrement = 50000;
    dpiData *intColValue, *longColValue;
    dpiVar *intColVar, *longColVar;
    char *longValue;
    dpiStmt *stmt;

    if (dpiTest__execStatement(testCase, conn, dropSql, -1) < 0)
        return DPI_FAILURE;
    if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_INT64,
            arraySize, 0, 0, 0, NULL, &intColVar, &intColValue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_LONG_VARCHAR,
            DPI_NATIVE_TYPE_BYTES, arraySize, 0, 0, 0, NULL, &longColVar,
            &longColValue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // insert the requested number of rows
    if (dpiConn_prepareStmt(conn, 0, insertSql, strlen(insertSql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    for (iter = 1; iter <= numOfRows; iter++) {
        if (dpiStmt_bindByPos(stmt, 1, intColVar) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (dpiStmt_bindByPos(stmt, 2, longColVar) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        longValueLength = iter * sizeIncrement;
        longValue = malloc(longValueLength);
        if (!longValue)
            return dpiTestCase_setFailed(testCase, "Out of memory!");
        memset(longValue, 'A', longValueLength);
        intColValue->isNull = 0;
        intColValue->value.asInt64 = iter;
        if (dpiVar_setFromBytes(longColVar, 0, longValue, longValueLength) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        free(longValue);
        if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }
    if (dpiConn_commit(conn) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    dpiStmt_release(stmt);
    dpiVar_release(intColVar);
    dpiVar_release(longColVar);
    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_700_checkFetchArraySize()
//   Prepare any statement; call dpiStmt_getFetchArraySize() and verify the
// value returned is the default value of 100; call dpiStmt_setFetchArraySize()
// with any value except zero and then call dpiStmt_getFetchArraySize() to
// verify the value returned matches the value that was set; call
// dpiStmt_setFetchArraySize() with the value 0 and then call
// dpiStmt_getFetchArraySize() and verify the value returned is the default
// value of 100 (no error).
//-----------------------------------------------------------------------------
int dpiTest_700_checkFetchArraySize(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs order by IntCol";
    uint32_t arraySize, setArraySize = 3;
    dpiConn *conn;
    dpiStmt *stmt;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql),
            NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getFetchArraySize(stmt, &arraySize)< 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, arraySize, 100) < 0)
        return DPI_FAILURE;
    if (dpiStmt_setFetchArraySize(stmt, setArraySize) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getFetchArraySize(stmt, &arraySize)< 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, arraySize, setArraySize) < 0)
        return DPI_FAILURE;
    setArraySize = 0;
    if (dpiStmt_setFetchArraySize(stmt, setArraySize) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getFetchArraySize(stmt, &arraySize)< 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, arraySize, 100) < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_701_fetchArraySizeTooLarge()
//   Prepare and execute any query; create and define variables needed to
// support the query; call dpiStmt_setFetchArraySize() with a value that is
// larger than the array size used to create at least one of the variables
// (error DPI-1015).
//-----------------------------------------------------------------------------
int dpiTest_701_fetchArraySizeTooLarge(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs order by IntCol";
    uint32_t arraySize = 3, setArraySize = 3333;
    uint32_t numQueryColumns;
    dpiData *intColValue;
    dpiVar *intColVar;
    dpiConn *conn;
    dpiStmt *stmt;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql),
            NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_INT64,
            arraySize, 0, 0, 0, NULL, &intColVar, &intColValue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_define(stmt, 1, intColVar) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_setFetchArraySize(stmt, setArraySize);
    if (dpiTestCase_expectError(testCase, "DPI-1015:") < 0)
        return DPI_FAILURE;
    dpiVar_release(intColVar);
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_702_fetchArraySizeTooSmall()
//   Prepare and execute any query; call dpiStmt_setFetchArraySize() with any
// value; create and define a variable with an array size smaller than the
// value used to call dpiStmt_setFetchArraySize(); call dpiStmt_fetch()
// (error  DPI-1018).
//-----------------------------------------------------------------------------
int dpiTest_702_fetchArraySizeTooSmall(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs order by IntCol";
    uint32_t numQueryColumns, bufferRowIndex;
    uint32_t arraySize = 3, setArraySize = 5;
    dpiData *intColValue;
    dpiVar *intColVar;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;

    if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_INT64,
            arraySize, 0, 0, 0, NULL, &intColVar, &intColValue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql),
            NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_setFetchArraySize(stmt, setArraySize) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_define(stmt, 1, intColVar) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_fetch(stmt, &found, &bufferRowIndex);
    if (dpiTestCase_expectError(testCase, "DPI-1018:") < 0)
        return DPI_FAILURE;
    dpiVar_release(intColVar);
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_703_getQueryValueNoDefine()
//   Prepare and execute any query but do not create any variables or perform
// any defines; call dpiStmt_fetch() followed by dpiStmt_getQueryValue() and
// verify that the values returned match the expected values (no error).
//-----------------------------------------------------------------------------
int dpiTest_703_getQueryValueNoDefine(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs";
    uint32_t numQueryColumns, bufferRowIndex;
    dpiNativeTypeNum nativeTypeNum;
    dpiConn *conn;
    dpiStmt *stmt;
    dpiData *data;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__insertIntoTestLongs(testCase, conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getQueryValue(stmt, 1, &nativeTypeNum, &data) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, nativeTypeNum,
            DPI_NATIVE_TYPE_INT64) < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_704_getQueryValueDiffPos()
//   Prepare and execute any query; call dpiStmt_fetch(), then call
// dpiStmt_getQueryValue() with position 0 as well as a position that exceeds
// the number of columns being fetched (error DPI-1028).
//-----------------------------------------------------------------------------
int dpiTest_704_getQueryValueDiffPos(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs";
    uint32_t numQueryColumns, bufferRowIndex;
    dpiNativeTypeNum nativeTypeNum;
    dpiData *data;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_getQueryValue(stmt, 0, &nativeTypeNum, &data);
    if (dpiTestCase_expectError(testCase, "DPI-1028:") < 0)
        return DPI_FAILURE;
    dpiStmt_getQueryValue(stmt, 3, &nativeTypeNum, &data);
    if (dpiTestCase_expectError(testCase, "DPI-1028:") < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_705_getQueryValueNoQuery()
//   Prepare any query; call dpiStmt_getQueryValue() with any position
// (error DPI-1007).
//-----------------------------------------------------------------------------
int dpiTest_705_getQueryValueNoQuery(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *sql = "select * from TestLongs";
    dpiNativeTypeNum nativeTypeNum;
    dpiData *data;
    dpiConn *conn;
    dpiStmt *stmt;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql),
            NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_getQueryValue(stmt, 0, &nativeTypeNum, &data);
    if (dpiTestCase_expectError(testCase, "DPI-1007:") < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_706_getQueryValueAfterFetch()
//   Prepare and execute any query; call dpiStmt_fetch() until no rows are
// found; call dpiStmt_getQueryValue() with any valid position
// (error DPI-1029).
//-----------------------------------------------------------------------------
int dpiTest_706_getQueryValueAfterFetch(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *querySql = "select * from TestLongs";
    const char *deleteSql = "delete from TestLongs";
    uint32_t numQueryColumns, bufferRowIndex;
    dpiNativeTypeNum nativeTypeNum;
    dpiData *data;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, deleteSql, -1) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, querySql, strlen(querySql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_getQueryValue(stmt, 1, &nativeTypeNum, &data);
    if (dpiTestCase_expectError(testCase, "DPI-1029:") < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_707_getQueryInfo()
//   Prepare and execute any query; call dpiStmt_getQueryInfo() and verify
// that the type information returned matches that expected (no error).
//-----------------------------------------------------------------------------
int dpiTest_707_getQueryInfo(dpiTestCase *testCase, dpiTestParams *params)
{
    const char *sql = "select * from TestLongs";
    uint32_t numQueryColumns, bufferRowIndex;
    dpiQueryInfo info;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getQueryInfo(stmt, 1, &info) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase,
            info.typeInfo.defaultNativeTypeNum, DPI_NATIVE_TYPE_INT64) < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_708_queryAfterDropColumn()
//   Prepare and execute a "select *" type query and fetch from it, then close
// the statement; execute an alter statement that removes a column from the
// table or view being queried; prepare, execute and fetch from the first query
// again and confirm the number of columns has changed and no error has been
// raised (no error).
//-----------------------------------------------------------------------------
int dpiTest_708_queryAfterDropColumn(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *querySql = "select * from TestLongsAlter";
    const char *alterDropSql =
            "alter table TestLongsAlter drop column IntCol";
    const char *dropSql = "drop table TestLongsAlter";
    const char *createSql =
            "create table TestLongsAlter (IntCol number(9), LongCol long)";
    dpiConn *conn;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, dropSql, -1) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, createSql, -1) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, querySql, 2) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, alterDropSql, -1) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, querySql, 1) < 0)
        return DPI_FAILURE;
    if (dpiTest__execStatement(testCase, conn, querySql, -1) < 0)
        return DPI_FAILURE;

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_709_fetchRowCheckCount()
//   Prepare and execute any query; call dpiStmt_fetch() multiple times and
// confirm that after each call a call to dpiStmt_getRowCount() results in a
// row count that is one larger than the previous iteration (no error).
//-----------------------------------------------------------------------------
int dpiTest_709_fetchRowCheckCount(dpiTestCase *testCase,
        dpiTestParams *params)
{
    uint32_t numQueryColumns, bufferRowIndex, iter, numOfRows = 2;
    const char *sql = "select * from TestLongs";
    uint64_t rowCount;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    for (iter = 1; iter <= numOfRows; iter++) {
        if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (dpiStmt_getRowCount(stmt, &rowCount) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (dpiTestCase_expectUintEqual(testCase, rowCount, iter) < 0)
            return DPI_FAILURE;
        if (!found)
            return DPI_FAILURE;
    }
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_710_fetchRowsCheckCount()
//   Prepare and execute any query; call dpiStmt_fetchRows() and confirm that
// the value returned by dpiStmt_getRowCount() increases by the number of rows
// that were returned (no error).
//-----------------------------------------------------------------------------
int dpiTest_710_fetchRowsCheckCount(dpiTestCase *testCase,
        dpiTestParams *params)
{
    uint32_t numQueryColumns, bufferRowIndex, numRowsFetched, maxRows = 2;
    const char *sql = "select * from TestLongs";
    uint64_t rowCount;
    dpiConn *conn;
    dpiStmt *stmt;
    int moreRows;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__insertIntoTestLongs(testCase, conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, &numQueryColumns) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_fetchRows(stmt, maxRows, &bufferRowIndex, &numRowsFetched,
            &moreRows) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_getRowCount(stmt, &rowCount) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, rowCount, maxRows) < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_711_verifyStmtFuncs()
//   Prepare any query but do not execute it; call dpiStmt_fetch(),
// dpiStmt_getQueryInfo() and dpiStmt_define() and confirm each receives
// an error (error ORA-24338).
//-----------------------------------------------------------------------------
int dpiTest_711_verifyStmtFuncs(dpiTestCase *testCase, dpiTestParams *params)
{
    const char *expectedError = "ORA-24338:";
    const char *sql = "select * from TestLongs";
    uint32_t bufferRowIndex;
    dpiQueryInfo info;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_fetch(stmt, &found, &bufferRowIndex);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiStmt_getQueryInfo(stmt, 1, &info);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiStmt_define(stmt, 1, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiStmt_release(stmt);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_712_fetchDataToSmallLenStrVar()
//   Create a string variable with a size that is smaller than at least some
// of the data that is subsequently fetched (error DPI-1037)
//-----------------------------------------------------------------------------
int dpiTest_712_fetchDataToSmallLenStrVar(dpiTestCase *testCase,
        dpiTestParams *params)
{
    const char *insertSql = "insert into TestTempTable values(1,'TestString')";
    const char *selectSql = "select StringCol from TestTempTable";
    const char *truncateSql = "truncate table TestTempTable";
    uint32_t bufferRowIndex;
    dpiConn *conn;
    dpiStmt *stmt;
    int found;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;

    // truncate table
    if (dpiConn_prepareStmt(conn, 0, truncateSql, strlen(truncateSql),
            NULL, 0, &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, 0, NULL) < 0)
        dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_release(stmt) < 0)
        dpiTestCase_setFailedFromError(testCase);

    // insert a row with a string of known size into the table
    if (dpiConn_prepareStmt(conn, 0, insertSql, strlen(insertSql), NULL, 0,
            &stmt) < 0)
        dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, 0, NULL) < 0)
        dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_release(stmt) < 0)
        dpiTestCase_setFailedFromError(testCase);

    // perform fetch into string of smaller size
    if (dpiConn_prepareStmt(conn, 0, selectSql, strlen(selectSql), NULL, 0,
            &stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_execute(stmt, 0, NULL) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiStmt_defineValue(stmt, 1, DPI_ORACLE_TYPE_VARCHAR,
            DPI_NATIVE_TYPE_BYTES, 2, 1, NULL) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiStmt_fetch(stmt, &found, &bufferRowIndex);
    if (dpiTestCase_expectError(testCase, "DPI-1037:") < 0)
        return DPI_FAILURE;
    if (dpiStmt_release(stmt) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// main()
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
    dpiTestSuite_initialize(700);
    dpiTestSuite_addCase(dpiTest_700_checkFetchArraySize,
            "check get / set array size with various values");
    dpiTestSuite_addCase(dpiTest_701_fetchArraySizeTooLarge,
            "dpiStmt_setFetchArraySize() with value too large");
    dpiTestSuite_addCase(dpiTest_702_fetchArraySizeTooSmall,
            "dpiStmt_setFetchArraySize() with value too small");
    dpiTestSuite_addCase(dpiTest_703_getQueryValueNoDefine,
            "dpiStmt_getQueryValue() without define");
    dpiTestSuite_addCase(dpiTest_704_getQueryValueDiffPos,
            "dpiStmt_getQueryValue() with invalid position values");
    dpiTestSuite_addCase(dpiTest_705_getQueryValueNoQuery,
            "dpiStmt_getQueryValue() called when no query has been executed");
    dpiTestSuite_addCase(dpiTest_706_getQueryValueAfterFetch,
            "dpiStmt_getQueryValue() called after all rows fetched");
    dpiTestSuite_addCase(dpiTest_707_getQueryInfo,
            "dpiStmt_getQueryInfo() information is correct");
    dpiTestSuite_addCase(dpiTest_708_queryAfterDropColumn,
            "query all columns from table before and after column dropped");
    dpiTestSuite_addCase(dpiTest_709_fetchRowCheckCount,
            "dpiStmt_fetch() increments rowcount");
    dpiTestSuite_addCase(dpiTest_710_fetchRowsCheckCount,
            "dpiStmt_fetchRows() increments rowcount");
    dpiTestSuite_addCase(dpiTest_711_verifyStmtFuncs,
            "dpiStmt_fetchRows() increments rowcount");
    dpiTestSuite_addCase(dpiTest_712_fetchDataToSmallLenStrVar,
            "fetch data to a string variable which is smaller and verify");
    return dpiTestSuite_run();
}