From 0ff62180b457672bbe8e8ae4b64240813370b22f Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Thu, 11 Jul 2013 23:43:02 +0200 Subject: [PATCH] fix value tracing of partial empty fetches/selects --- modtest/ref/gory | 74 ++++++++++++++++++++++++++++++++---------------- modtest/ref/sql | 19 +++++++++---- prettyprint.c | 6 ++-- wrap.c | 23 ++++++++------- 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/modtest/ref/gory b/modtest/ref/gory index 82b430f..7ec9db1 100644 --- a/modtest/ref/gory +++ b/modtest/ref/gory @@ -778,6 +778,7 @@ Iterations: 1 (of 1) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SQL-Code: 1403, ORA-01403: no data found (select str ,n from example_tbl where n<:b0 order by n ) +--------------------------------------------------------------------------- =========================================================================== stmt # 25, type CLOSE (15), line 320, #para 0 (in 0) (offset 579) (foff: 0) --------------------------------------------------------------------------- @@ -942,49 +943,49 @@ SQL-Code: 1403, ORA-01403: no data found (select str ,n into :s1:s2 ,:s3:s4 fr Iterations: 6 (of 512) Iteration: 0 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |a| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |0| IN paramter (a=2) Type: INT (3), Length: 4, Size: 4, Ind 0 Value: |6| Iteration: 1 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |a| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |0| Iteration: 2 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |a| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |0| Iteration: 3 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |b| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |1| Iteration: 4 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |b| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |1| Iteration: 5 OUT paramter (a=0) - Type: STRING0 (5), Length: 32, Size: 36, Ind -1 - Value: |NULL| + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |c| OUT paramter (a=1) - Type: INT (3), Length: 4, Size: 36, Ind -1 - Value: |NULL| + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |4| --------------------------------------------------------------------------- =========================================================================== stmt # 28, type OPEN cursor (9), line 400, #para 1 (in 1) (offset 816) (foff: 0) @@ -1051,6 +1052,22 @@ Iterations: 1 (of 4) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SQL-Code: 1403, ORA-01403: no data found (select str ,n from example_tbl where n<:b0 order by n ) +Iterations: 2 (of 4) + Iteration: 0 + OUT paramter (a=0) + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |b| + OUT paramter (a=1) + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |1| + Iteration: 1 + OUT paramter (a=0) + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |c| + OUT paramter (a=1) + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |4| +--------------------------------------------------------------------------- =========================================================================== stmt # 28, type CLOSE (15), line 419, #para 0 (in 0) (offset 858) (foff: 0) --------------------------------------------------------------------------- @@ -1185,6 +1202,15 @@ Iterations: 1 (of 4) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SQL-Code: 1403, ORA-01403: no data found (SELECT str, n FROM example_tbl WHERE n < :x ORDER BY n) +Iterations: 1 (of 4) + Iteration: 0 + OUT paramter (a=0) + Type: STRING0 (5), Length: 32, Size: 36, Ind 0 + Value: |b| + OUT paramter (a=1) + Type: INT (3), Length: 4, Size: 36, Ind 0 + Value: |1| +--------------------------------------------------------------------------- =========================================================================== stmt # 31, type CLOSE (15), line 482, #para 0 (in 0) (offset 991) (foff: 0) --------------------------------------------------------------------------- diff --git a/modtest/ref/sql b/modtest/ref/sql index b765a05..455fa51 100644 --- a/modtest/ref/sql +++ b/modtest/ref/sql @@ -449,6 +449,8 @@ select str ,n from example_tbl where n<5 order by n ; -- example/main.pc:314 -- Pseudo-SQL: FETCH -- PREFETCH=1 (# of prefetched rows) +( ; +-- --------------------------------------------------------------------------- -- ########################################################################### @@ -564,12 +566,12 @@ select str ,n into :s1:s2 ,:s3:s4 from example_tbl where n<6 order by n ; -- =========================================================================== -- After execution (errorcode: 1403, ORA-01403: no data found, select str ,n into :s1:s2 ,:s3:s4 from example_tbl where n<:b2 order): -- example/main.pc:374 -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; -select str ,n into NULL ,NULL from example_tbl where n<6 order by n ; +select str ,n into 'a' ,0 from example_tbl where n<6 order by n ; +select str ,n into 'a' ,0 from example_tbl where n<6 order by n ; +select str ,n into 'a' ,0 from example_tbl where n<6 order by n ; +select str ,n into 'b' ,1 from example_tbl where n<6 order by n ; +select str ,n into 'b' ,1 from example_tbl where n<6 order by n ; +select str ,n into 'c' ,4 from example_tbl where n<6 order by n ; -- --------------------------------------------------------------------------- @@ -606,6 +608,9 @@ select str ,n from example_tbl where n<6 order by n ; -- example/main.pc:406 -- Pseudo-SQL: FETCH -- PREFETCH=1 (# of prefetched rows) +( 'b', 1 ); +( 'c', 4 ); +-- --------------------------------------------------------------------------- -- ########################################################################### @@ -721,6 +726,8 @@ DELETE FROM example_tbl WHERE n = 4; -- example/main.pc:468 -- Pseudo-SQL: FETCH -- PREFETCH=1 (# of prefetched rows) +( 'b', 1 ); +-- --------------------------------------------------------------------------- -- ########################################################################### diff --git a/prettyprint.c b/prettyprint.c index b57f3f5..c2fa781 100644 --- a/prettyprint.c +++ b/prettyprint.c @@ -170,6 +170,7 @@ int pp_after_gory(const Statement *stmt, if (!stmt->errorcode || stmt->errorcode == 1403 || stmt->errorcode == 100) { tprintf("\n"); } + //tprintf("Fetched rows: %zu\n", stmt->acc_fetched_rows); return 0; } @@ -212,12 +213,10 @@ int pp_sql(const Statement *stmt, void *user_ptr) } else if (stmt->number_of_params) sql_pseudo_tokenize(stmt->number_of_params, &s->tokens, &s->tokens_size); } + s->tokens_pos = 0; SQL_Token *i = s->tokens + s->tokens_pos; - // don't print (possibly) tons of NULL fetch results - if (stmt->type == FETCH && (stmt->errorcode == 1403 || stmt->errorcode == 100)) - return 0; if (s->tokens_pos < s->tokens_size && i->begin && !i->host_var) { tprintf("%.*s", (int) (i->end - i->begin), i->begin); @@ -334,7 +333,6 @@ int pp_para_sql(const Statement *stmt, SQL_PP_State *s = user_ptr; - if (!p->pos && p->iteration && s->tokens) { s->tokens_pos = 0; tprintf(";\n"); diff --git a/wrap.c b/wrap.c index c7cbc5b..291816a 100644 --- a/wrap.c +++ b/wrap.c @@ -1432,11 +1432,16 @@ static size_t determine_iterations(bool before, const Statement *stmt) if (before) iterations = 1; else { - size_t mod = stmt->acc_fetched_rows % stmt->iterations; - if (mod) - iterations = mod; - else - iterations = stmt->iterations; + // for single fetches + if (stmt->iterations == 1 && stmt->errorcode) { + iterations = 0; + } else { + size_t mod = stmt->acc_fetched_rows % stmt->iterations; + if (mod) + iterations = mod; + else + iterations = stmt->iterations; + } } break; default: @@ -1500,8 +1505,8 @@ static int pp_para(const sqlexd *d, bool before, // don't print OUT-parameters on errors if (!before && p.direction == PARA_OUT - && !(!stmt->errorcode ) //|| stmt->errorcode == 1403 || stmt->errorcode == 100) - ) { + && stmt->errorcode != 0 && stmt->errorcode != 1403 + && stmt->errorcode != 100) { p.indicator = -1; } @@ -1649,10 +1654,6 @@ static int pp_sql_after(const sqlexd *d, Statement *stmt, state.callbacks[callback_nr].user_ptr); } - // don't print (possibly) tons of NULL fetch results - if (stmt->type == FETCH && (stmt->errorcode == 1403 || stmt->errorcode == 100)) - return 0; - pp_para(d, false, stmt, callback_nr); if (state.callbacks[callback_nr].after_end_fn) {