Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 371963 - StatementProcessor.dump() produces *** UNPARSED *** for SQL PLAIN Log when statements contains '?'
Summary: StatementProcessor.dump() produces *** UNPARSED *** for SQL PLAIN Log when st...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Scout (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-18 02:21 EST by Jeremie Bresson CLA
Modified: 2021-08-19 11:24 EDT (History)
2 users (show)

See Also:
zimmermann: juno+


Attachments
test for bug 371963 (6.20 KB, application/octet-stream)
2012-02-18 02:26 EST, Jeremie Bresson CLA
no flags Details
Patch for bug 371963 (2.16 KB, patch)
2012-02-18 02:31 EST, Jeremie Bresson CLA
ivan.motsch: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremie Bresson CLA 2012-02-18 02:21:56 EST
Build Identifier: 

Consider the statement :
select '?', :myText from dual

Expected SQL with binds:
    SELECT    '?',
              :myText
    FROM      DUAL
    IN  :myText => ? [CHAR lorem]


Expected SQL PLAIN Log:
    SELECT    '?',
              'lorem'
    FROM      DUAL

But is:
    SQL PLAIN Log:
    SELECT    '' LOREM
    *** UNPARSED ***
    '' , ? FROM DUAL

because the first '?' is interpreted as a placeholder for the parameter :myText.


Responsible is calculation of pos:
	at org.eclipse.scout.rt.server.services.common.jdbc.internal.exec.StatementProcessor.createSqlDump(StatementProcessor.java:690)

Solution: 
use a RegEx that do not find ? between single quotes.

Reproducible: Always
Comment 1 Jeremie Bresson CLA 2012-02-18 02:26:43 EST
Created attachment 211226 [details]
test for bug 371963

Unit Test to illustrate the problem.
testSelectPlainText() contains the case described in the bug description.

To be run with as normal JUnit Test.
Dependency on EasyMock.
Comment 2 Jeremie Bresson CLA 2012-02-18 02:31:46 EST
Created attachment 211227 [details]
Patch for bug 371963

Patch proposition.

There is maybe a better possible implementation for the find() function.
RegEx optimization and so on...

Here a test for this function:

  @Test
  public void testFind() throws Exception {
    runFind(-1, null, 0);

    runFind(0, "?", 0);
    runFind(3, "xx ?", 0);
    runFind(3, "xx ? xxx", 0);
    runFind(-1, "?", 1);
    runFind(3, "xx ?", 1);
    runFind(3, "xx ? xxx", 1);
    runFind(-1, "xx ?", 4);
    runFind(-1, "xx ? xxx", 4);

    runFind(0, "??", 0);
    runFind(3, "xx ??", 0);
    runFind(3, "xx ??", 3);
    runFind(4, "xx ??", 4);
    runFind(3, "xx ? ?", 3);
    runFind(5, "xx ? ?", 4);
    runFind(7, "xx ? xx?x", 4);

    runFind(-1, "'?'", 0);
    runFind(4, "'?' ? x", 0);
    runFind(7, "xx '?' ? x", 0);
    runFind(3, "xx ? xx '?' '?' ? x", 0);
    runFind(16, "xx ? xx '?' '?' ? x", 4);
    runFind(-1, "xx ? xx '?' '?' ? x", 17);
    runFind(-1, "xx '?' xx", 0);
    runFind(-1, "xx '????' xx", 0);
    runFind(12, "xx '????' x ? x", 0);
    runFind(8, "xx '' x ? x", 0);
    runFind(-1, "xx '' xx", 0);
    runFind(-1, "xx ' '' ? '' ' xx", 0);
    runFind(-1, "xx ''' ? ' ' ' xx", 0);
    runFind(6, "xx '' ? '' xx", 0);
    runFind(6, " '''' ? '' xx", 0);
  }

  private void runFind(int expected, String s, int start) {
    Assert.assertEquals(expected, StatementProcessor.find(s, start));
  }


An other possibility is to extend this StatementProcessor.find(..) function to be more generic:

StringUtility.findExcludingTocken(String s, String what, String excludedTocken, int start)

Should be consistent with: StringUtility.find(..)


Please add the JUnit test case at the appropriate place.
Comment 3 Ivan Motsch CLA 2012-02-20 05:51:39 EST
Applied patch with small modifications, marked contributed by J.B.
Comment 4 Ivan Motsch CLA 2012-02-20 05:59:59 EST
Many thanks to Jeremie, good work.
Comment 5 Matthias Zimmermann CLA 2012-07-09 06:50:18 EDT
ticket closed.
deliverd as part of eclipse scout 3.8.0 (juno release train)