From 8a680a25a952729ca0e2126dc9f840755cfbd9b6 Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Fri, 12 Jul 2013 00:00:55 +0200 Subject: [PATCH] add module tests for empty selects/fetches --- example/main.pc | 30 ++++++++++++++++++++++++++++++ modtest/ref/gory | 20 ++++++++++++++++++++ modtest/ref/oci | 23 +++++++++++++++++++++++ modtest/ref/sql | 28 ++++++++++++++++++++++++++++ wrap.c | 6 ++++-- 5 files changed, 105 insertions(+), 2 deletions(-) diff --git a/example/main.pc b/example/main.pc index 895f1ea..a626645 100644 --- a/example/main.pc +++ b/example/main.pc @@ -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: @@ -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 diff --git a/modtest/ref/gory b/modtest/ref/gory index 7ec9db1..5fb8a6f 100644 --- a/modtest/ref/gory +++ b/modtest/ref/gory @@ -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) diff --git a/modtest/ref/oci b/modtest/ref/oci index 32a0a59..e126a31 100644 --- a/modtest/ref/oci +++ b/modtest/ref/oci @@ -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) diff --git a/modtest/ref/sql b/modtest/ref/sql index 455fa51..022d82f 100644 --- a/modtest/ref/sql +++ b/modtest/ref/sql @@ -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 diff --git a/wrap.c b/wrap.c index 291816a..a9d93e1 100644 --- a/wrap.c +++ b/wrap.c @@ -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;