Skip to content

Commit

Permalink
add module tests for empty selects/fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
gsauthof committed Jul 11, 2013
1 parent 0ff6218 commit 8a680a2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
30 changes: 30 additions & 0 deletions example/main.pc
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,30 @@ static int call()
EXEC ORACLE OPTION (char_map=charz);
}

static int empty_sel()
{
int x = 0;
EXEC SQL SELECT 0 INTO :x FROM DUAL WHERE 0=1;
if (sqlca.sqlcode != 1403)
IFSQLRET(0, -1);
return 0;
}
static int empty_arr()
{
struct Row { char str[32]; int n; };
struct Row rows[512] = {0};
struct Ind { short a; short b; };
struct Ind inds[512] = {0};

int x = 6;
EXEC ORACLE OPTION (char_map=string);
EXEC SQL SELECT str, n INTO :rows:inds FROM example_tbl WHERE 1 = 0 ORDER BY n;
EXEC ORACLE OPTION (char_map=charz);
if (sqlca.sqlcode != 1403)
IFSQLRET(0, -1);
return 0;
}

int main(int argc, char **argv)
{
// silence unused warning:
Expand Down Expand Up @@ -592,6 +616,12 @@ int main(int argc, char **argv)
ret = call();
IFTRUERET(ret, 0, 1);

ret = empty_sel();
IFTRUERET(ret, 0, 1);

ret = empty_arr();
IFTRUERET(ret, 0, 1);

if (argc > 1)
ret = proc_disconnect_rollback();
else
Expand Down
20 changes: 20 additions & 0 deletions modtest/ref/gory
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,26 @@ Iterations: 1 (of 1)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
|
---------------------------------------------------------------------------
===========================================================================
stmt # 34, type SELECT (4), line 534, #para 1 (in 0) (offset 1071) (foff: 0)
SQL: select 0 into :b0 from DUAL where 0=1
Iterations: 1 (of 1)
Iteration: 0
---------------------------------------------------------------------------
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL-Code: 1403, ORA-01403: no data found (select 0 into :b0 from DUAL where 0=1)

---------------------------------------------------------------------------
===========================================================================
stmt # 35, type SELECT (4), line 548, #para 2 (in 0) (offset 1090) (foff: 0)
SQL: select str ,n into :s1:s2 ,:s3:s4 from example_tbl where 1=0 order by n
Iterations: 1 (of 512)
Iteration: 0
---------------------------------------------------------------------------
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL-Code: 1403, ORA-01403: no data found (select str ,n into :s1:s2 ,:s3:s4 from example_tbl where 1=0 order b)

---------------------------------------------------------------------------
===========================================================================
stmt # 3, type COMMIT RELEASE (30), line 85, #para 0 (in 0) (offset 71) (foff: 0)
Expand Down
23 changes: 23 additions & 0 deletions modtest/ref/oci
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,29 @@ OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_STMT_TYPE) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_STMT_TYPE) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_STMT_TYPE) => OCI_SUCCESS (0)
OCIStmtPrepare(select 0 into :b0 from DUAL where 0=1) => OCI_SUCCESS (0)
OCIDefineByPos(pos= 1, FLAGNOTFOUND) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDSCL) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDPRC) => OCI_SUCCESS (0)
OCIStmtExecute(iters=1, rowoff=0, FLAGNOTFOUND) => OCI_NO_DATA (100)
OCIAttrGet(OCI_ATTR_SQLFNCODE, SELECT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_PARSE_ERROR_OFFSET) => OCI_SUCCESS (0)
OCIStmtPrepare(select str ,n into :s1:s2 ,:s3:s4 from example_tbl where 1=0 order by n ) => OCI_SUCCESS (0)
OCIDefineByPos(pos= 1, FLAGNOTFOUND) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDSCL) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDPRC) => OCI_SUCCESS (0)
OCIDefineByPos(pos= 2, FLAGNOTFOUND) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDSCL) => OCI_SUCCESS (0)
OCIAttrSet(OCI_ATTR_PDPRC) => OCI_SUCCESS (0)
OCIStmtExecute(iters=512, rowoff=0, OCI_EXACT_FETCH) => OCI_NO_DATA (100)
OCIAttrGet(OCI_ATTR_SQLFNCODE, SELECT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_ROW_COUNT) => OCI_SUCCESS (0)
OCIAttrGet(OCI_ATTR_PARSE_ERROR_OFFSET) => OCI_SUCCESS (0)
OCITransCommit(OCI_DEFAULT) => OCI_SUCCESS (0)
OCIHandleFree(HANDLE_011 type=4 ) => OCI_SUCCESS (0)
OCIHandleFree(HANDLE_012 type=4 ) => OCI_SUCCESS (0)
Expand Down
28 changes: 28 additions & 0 deletions modtest/ref/sql
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,34 @@ call DBMS_METADATA.GET_DDL('TABLE','EXAMPLE_TBL') into '
-- ---------------------------------------------------------------------------


-- ###########################################################################
-- Before execution:
-- example/main.pc:534
select 0 into :b0 from DUAL where 0=1;
-- ---------------------------------------------------------------------------


-- ===========================================================================
-- After execution (errorcode: 1403, ORA-01403: no data found, select 0 into :b0 from DUAL where 0=1):
-- example/main.pc:534
select 0 into ;
-- ---------------------------------------------------------------------------


-- ###########################################################################
-- Before execution:
-- example/main.pc:548
select str ,n into :s1:s2 ,:s3:s4 from example_tbl where 1=0 order by n ;
-- ---------------------------------------------------------------------------


-- ===========================================================================
-- After execution (errorcode: 1403, ORA-01403: no data found, select str ,n into :s1:s2 ,:s3:s4 from example_tbl where 1=0 order b):
-- example/main.pc:548
select str ,n into ;
-- ---------------------------------------------------------------------------


-- ###########################################################################
-- Before execution:
-- proc_util.pc:85
Expand Down
6 changes: 4 additions & 2 deletions wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,8 +1432,10 @@ static size_t determine_iterations(bool before, const Statement *stmt)
if (before)
iterations = 1;
else {
// for single fetches
if (stmt->iterations == 1 && stmt->errorcode) {
// for single fetches
if ( (stmt->iterations == 1 && stmt->errorcode)
// for completely empty array fetches
|| (!stmt->acc_fetched_rows) ) {
iterations = 0;
} else {
size_t mod = stmt->acc_fetched_rows % stmt->iterations;
Expand Down

0 comments on commit 8a680a2

Please sign in to comment.