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
|
//-----------------------------------------------------------------------------
// Copyright (c) 2017, 2025, Oracle and/or its affiliates.
//
// This software is dual-licensed to you under the Universal Permissive License
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
// either license.
//
// If you elect to accept the software under the Apache License, Version 2.0,
// the following applies:
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// test_4200_rowids.c
// Test suite for testing all the rowid related test cases.
//-----------------------------------------------------------------------------
#include "TestLib.h"
//-----------------------------------------------------------------------------
// dpiTest_4200()
// Prepare and execute any query that selects rowid on a regular table.
// Convert one of these rowids to string by calling dpiRowid_getStringValue()
// and perform a second query specifically for the row matching that rowid.
//-----------------------------------------------------------------------------
int dpiTest_4200(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sqlQuery1 = "select rowid from TestStrings where IntCol = 7";
const char *sqlQuery2 = "select IntCol from TestStrings where rowid = :1";
uint32_t bufferRowIndex, rowidAsStringLength;
dpiData *queryValue, bindValue;
dpiNativeTypeNum nativeTypeNum;
const char *rowidAsString;
dpiStmt *stmt1, *stmt2;
dpiConn *conn;
int found;
// perform first query to get rowid
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_prepareStmt(conn, 0, sqlQuery1, strlen(sqlQuery1), NULL, 0,
&stmt1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt1, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt1, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for first query!");
if (dpiStmt_getQueryValue(stmt1, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_getStringValue(queryValue->value.asRowid, &rowidAsString,
&rowidAsStringLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
// perform second query to get row using rowid
if (dpiConn_prepareStmt(conn, 0, sqlQuery2, strlen(sqlQuery2), NULL, 0,
&stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiData_setBytes(&bindValue, (char*) rowidAsString, rowidAsStringLength);
if (dpiStmt_bindValueByPos(stmt2, 1, DPI_NATIVE_TYPE_BYTES,
&bindValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt2, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt2, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for second query!");
if (dpiStmt_getQueryValue(stmt2, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, queryValue->value.asInt64,
7) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiStmt_release(stmt1) < 0)
dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4201()
// Prepare and execute any query that selects rowid on an index organized
// table. convert one of these rowids to string by calling
// dpiRowid_getStringValue() and perform a second query specifically
// for the row matching that rowid.
//-----------------------------------------------------------------------------
int dpiTest_4201(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sqlQuery1 = "select rowid from TestOrgIndex where IntCol = 3";
const char *sqlQuery2 = "select IntCol from TestOrgIndex where rowid = :1";
uint32_t bufferRowIndex, rowidAsStringLength;
dpiData *queryValue, bindValue;
dpiNativeTypeNum nativeTypeNum;
const char *rowidAsString;
dpiStmt *stmt1, *stmt2;
dpiConn *conn;
int found;
// perform first query to get rowid
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_prepareStmt(conn, 0, sqlQuery1, strlen(sqlQuery1), NULL, 0,
&stmt1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt1, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt1, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for first query!");
if (dpiStmt_getQueryValue(stmt1, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_getStringValue(queryValue->value.asRowid, &rowidAsString,
&rowidAsStringLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
// perform second query to get row using rowid
if (dpiConn_prepareStmt(conn, 0, sqlQuery2, strlen(sqlQuery2), NULL, 0,
&stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiData_setBytes(&bindValue, (char*) rowidAsString, rowidAsStringLength);
if (dpiStmt_bindValueByPos(stmt2, 1, DPI_NATIVE_TYPE_BYTES,
&bindValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt2, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt2, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for second query!");
if (dpiStmt_getQueryValue(stmt2, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, queryValue->value.asInt64,
3) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiStmt_release(stmt1) < 0)
dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4202()
// Fetch any rowid; close statement that fetched that rowid; call
// dpiRowid_release() twice (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_4202(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "select rowid from TestOrgIndex where IntCol = 6";
dpiNativeTypeNum nativeTypeNum;
uint32_t bufferRowIndex;
dpiData *rowidValue;
dpiRowid *rowid;
dpiStmt *stmt;
dpiConn *conn;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase, "row not found!");
if (dpiStmt_getQueryValue(stmt, 1, &nativeTypeNum, &rowidValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
rowid = rowidValue->value.asRowid;
if (dpiRowid_addRef(rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_release(rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiRowid_release(rowid);
if (dpiTestCase_expectError(testCase, "DPI-1002:") < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4203()
// Call dpiRowid_getStringValue() with a NULL rowid (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_4203(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t rowidAsStringLength;
const char *rowidAsString;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
dpiRowid_getStringValue(NULL, &rowidAsString, &rowidAsStringLength);
if (dpiTestCase_expectError(testCase, "DPI-1002:") < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4204()
// Prepare and execute any query which selects a rowid from a regular table.
// Use one of these rowids to perform a second query specifically for the row
// matching that rowid.
//-----------------------------------------------------------------------------
int dpiTest_4204(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sqlQuery1 = "select rowid from TestStrings where IntCol = 9";
const char *sqlQuery2 = "select IntCol from TestStrings where rowid = :1";
dpiNativeTypeNum nativeTypeNum;
uint32_t bufferRowIndex;
dpiStmt *stmt1, *stmt2;
dpiData *queryValue;
dpiConn *conn;
int found;
// perform first query to get rowid
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_prepareStmt(conn, 0, sqlQuery1, strlen(sqlQuery1), NULL, 0,
&stmt1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt1, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt1, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for first query!");
if (dpiStmt_getQueryValue(stmt1, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
// perform second query to get row using rowid
if (dpiConn_prepareStmt(conn, 0, sqlQuery2, strlen(sqlQuery2), NULL, 0,
&stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_bindValueByPos(stmt2, 1, DPI_NATIVE_TYPE_ROWID,
queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt2, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt2, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for second query!");
if (dpiStmt_getQueryValue(stmt2, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, queryValue->value.asInt64,
9) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiStmt_release(stmt1) < 0)
dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4205()
// prepare and execute any query which selects rowid on an index organized
// table. use one of these rowids to perform a second query specifically
// for the row matching that rowid.
//-----------------------------------------------------------------------------
int dpiTest_4205(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sqlQuery1 = "select rowid from TestOrgIndex where IntCol = 8";
const char *sqlQuery2 = "select IntCol from TestOrgIndex where rowid = :1";
dpiNativeTypeNum nativeTypeNum;
uint32_t bufferRowIndex;
dpiStmt *stmt1, *stmt2;
dpiData *queryValue;
dpiConn *conn;
int found;
// perform first query to get rowid
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_prepareStmt(conn, 0, sqlQuery1, strlen(sqlQuery1), NULL, 0,
&stmt1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt1, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt1, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for first query!");
if (dpiStmt_getQueryValue(stmt1, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
// perform second query to get row using rowid
if (dpiConn_prepareStmt(conn, 0, sqlQuery2, strlen(sqlQuery2), NULL, 0,
&stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_bindValueByPos(stmt2, 1, DPI_NATIVE_TYPE_ROWID,
queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt2, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt2, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!found)
return dpiTestCase_setFailed(testCase,
"row not found for second query!");
if (dpiStmt_getQueryValue(stmt2, 1, &nativeTypeNum, &queryValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, queryValue->value.asInt64,
8) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiStmt_release(stmt1) < 0)
dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt2) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4206()
// Call dpiStmt_getLastRowid() before calling dpiStmt_execute() and verify
// that it returns NULL (no error).
//-----------------------------------------------------------------------------
int dpiTest_4206(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "select IntCol from TestOrgIndex";
dpiRowid *rowid;
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_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (rowid)
return dpiTestCase_setFailed(testCase, "Non-NULL rowid returned.");
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4207()
// Call dpiStmt_getLastRowid() after calling dpiStmt_execute() on a non-DML
// statement and verify it returns NULL (no error).
//-----------------------------------------------------------------------------
int dpiTest_4207(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "truncate table TestTempTable";
dpiRowid *rowid;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (rowid)
return dpiTestCase_setFailed(testCase, "Non-NULL rowid returned.");
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4208()
// Call dpiStmt_getLastRowid() after calling dpiStmt_execute() with a DML
// statement that doesn't affect any rows and verify it returns NULL (no
// error).
//-----------------------------------------------------------------------------
int dpiTest_4208(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "select IntCol from TestOrgIndex where rownum < 1";
dpiRowid *rowid;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (rowid)
return dpiTestCase_setFailed(testCase, "Non-NULL rowid returned.");
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4209()
// Call dpiStmt_getLastRowid() after calling dpiStmt_execute() with a DML
// statement that affects one row and verify it returns a rowid (no error).
//-----------------------------------------------------------------------------
int dpiTest_4209(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "insert into TestTempTable values (1, 'test1')";
uint32_t rowidAsStringLength;
const char *rowidAsString;
dpiRowid *rowid;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_getStringValue(rowid, &rowidAsString,
&rowidAsStringLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4210()
// Call dpiStmt_getLastRowid() after calling dpiStmt_execute() with a DML
// statement that affects multiple rows and verify it returns a rowid (no
// error).
//-----------------------------------------------------------------------------
int dpiTest_4210(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "insert into TestTempTable values (:1, :2)";
uint32_t rowidAsStringLength, numRows = 5, i;
dpiData *intData, *strData;
const char *rowidAsString;
dpiVar *intVar, *strVar;
char buffer[100];
dpiRowid *rowid;
dpiConn *conn;
dpiStmt *stmt;
// get connection
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
// prepare and bind insert statement
if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_INT64,
numRows, 0, 0, 0, NULL, &intVar, &intData) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_bindByPos(stmt, 1, intVar) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_newVar(conn, DPI_ORACLE_TYPE_VARCHAR, DPI_NATIVE_TYPE_BYTES,
numRows, 100, 1, 0, NULL, &strVar, &strData) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_bindByPos(stmt, 2, strVar) < 0)
return dpiTestCase_setFailedFromError(testCase);
// populate some dummy data
for (i = 0; i < numRows; i++) {
dpiData_setInt64(&intData[i], i + 1);
sprintf(buffer, "Dummy data %d", i + 1);
if (dpiVar_setFromBytes(strVar, i, buffer, strlen(buffer)) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiStmt_executeMany(stmt, DPI_MODE_EXEC_DEFAULT, numRows) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_getStringValue(rowid, &rowidAsString,
&rowidAsStringLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiVar_release(intVar) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiVar_release(strVar) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4211()
// Call dpiStmt_execute() with a DML statement that affects one row, verify
// dpiStmt_getLastRowid() returns a rowid and call dpiRowid_addRef() to acquire
// an independent reference, then release the statement and verify the rowid
// can still be used (no error).
//-----------------------------------------------------------------------------
int dpiTest_4211(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql = "insert into TestTempTable values (1, 'test1')";
uint32_t rowidAsStringLength;
const char *rowidAsString;
dpiRowid *rowid;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_addRef(rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_getStringValue(rowid, &rowidAsString,
&rowidAsStringLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiRowid_release(rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_4212()
// Call dpiStmt_getLastRowid() after calling dpiStmt_execute() with an INSERT
// ALL statement that affects many rows and verify it returns NULL (no error).
//-----------------------------------------------------------------------------
int dpiTest_4212(dpiTestCase *testCase, dpiTestParams *params)
{
const char *sql =
"insert all "
"into TestTempTable(IntCol, StringCol) values (1, 'test1') "
"into TestTempTable(IntCol, StringCol) values (2, 'test2') "
"into TestTempTable(IntCol, StringCol) values (3, 'test3') "
"select * from dual";
dpiRowid *rowid;
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, 0, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getLastRowid(stmt, &rowid) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (rowid)
return dpiTestCase_setFailed(testCase, "Non-NULL rowid returned.");
if (dpiStmt_release(stmt) < 0)
dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// main()
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
dpiTestSuite_initialize(4200);
dpiTestSuite_addCase(dpiTest_4200,
"fetch rowid and refetch row via string rep (normal table)");
dpiTestSuite_addCase(dpiTest_4201,
"fetch rowid and refetch row via string rep (index org table)");
dpiTestSuite_addCase(dpiTest_4202,
"call dpiRowid_release() twice");
dpiTestSuite_addCase(dpiTest_4203,
"verify dpiRowid_getStringValue() with NULL rowid");
dpiTestSuite_addCase(dpiTest_4204,
"fetch rowid and refetch row (normal table)");
dpiTestSuite_addCase(dpiTest_4205,
"fetch rowid and refetch row (index org table)");
dpiTestSuite_addCase(dpiTest_4206,
"call dpiStmt_getLastRowid() before calling dpiStmt_execute");
dpiTestSuite_addCase(dpiTest_4207,
"call dpiStmt_getLastRowid() after executing non-DML");
dpiTestSuite_addCase(dpiTest_4208,
"call dpiStmt_getLastRowid() after executing DML (no rows)");
dpiTestSuite_addCase(dpiTest_4209,
"call dpiStmt_getLastRowid() after executing DML (one row)");
dpiTestSuite_addCase(dpiTest_4210,
"call dpiStmt_getLastRowid() after executing DML (many rows)");
dpiTestSuite_addCase(dpiTest_4211,
"call dpiRowid_addRef() to verify independent reference");
dpiTestSuite_addCase(dpiTest_4212,
"call dpiStmt_getLastRowid() after INSERT ALL statement");
return dpiTestSuite_run();
}
|