Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-3971

Clob.getSubstring(int,int) returns empty or whole string

    XMLWordPrintable

Details

    • Hide

      DDL:

      CREATE FOREIGN TABLE smalla(
          intkey integer PRIMARY KEY OPTIONS(NAMEINSOURCE 'intkey', NATIVE_TYPE 'int4'),
          objectvalue clob OPTIONS(NAMEINSOURCE 'objectvalue', NATIVE_TYPE 'text'))
        OPTIONS(NAMEINSOURCE 'smalla');
      

      Query:

      SELECT * FROM smalla
      

      Java code:

      Connection con = org.teiid.jdbc.TeiidDriver.getInstance().connect("jdbc:teiid:test@mm://localhost:31000", info);
      ResultSet rs = con.createStatement().executeQuery("select * from source_pg.smalla");
      rs.next();
      LOG.info("CLOB: {}", rs.getClob(2).getClass());
      LOG.info("CLOB: {}", rs.getClob(2).getSubString(1, 1));
      LOG.info("CLOB: {}", rs.getClob(2).getSubString(1, 0));
      LOG.info("CLOB: {}", rs.getClob(2).getSubString(1, -1));
      con.close();

      Output:

      Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      08:03:44.089 [main] INFO  sandbox.MainClass - CLOB: class org.teiid.core.types.ClobImpl
      08:03:44.091 [main] INFO  sandbox.MainClass - CLOB: -24
      08:03:44.092 [main] INFO  sandbox.MainClass - CLOB: 
      Exception in thread "main" java.sql.SQLException: Invalid length argument to getSubString(): -1
      	at org.teiid.core.types.ClobImpl.getSubString(ClobImpl.java:154)
      	at sandbox.MainClass.main(MainClass.java:81)
      
      Show
      DDL: CREATE FOREIGN TABLE smalla( intkey integer PRIMARY KEY OPTIONS (NAMEINSOURCE 'intkey' , NATIVE_TYPE ' int4 ' ), objectvalue clob OPTIONS (NAMEINSOURCE 'objectvalue' , NATIVE_TYPE ' text ' )) OPTIONS (NAMEINSOURCE 'smalla' ); Query: SELECT * FROM smalla Java code: Connection con = org.teiid.jdbc.TeiidDriver.getInstance().connect( "jdbc:teiid:test@mm: //localhost:31000" , info); ResultSet rs = con.createStatement().executeQuery( "select * from source_pg.smalla" ); rs.next(); LOG.info( "CLOB: {}" , rs.getClob(2).getClass()); LOG.info( "CLOB: {}" , rs.getClob(2).getSubString(1, 1)); LOG.info( "CLOB: {}" , rs.getClob(2).getSubString(1, 0)); LOG.info( "CLOB: {}" , rs.getClob(2).getSubString(1, -1)); con.close(); Output: Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml 08:03:44.089 [main] INFO sandbox.MainClass - CLOB: class org.teiid.core.types.ClobImpl 08:03:44.091 [main] INFO sandbox.MainClass - CLOB: -24 08:03:44.092 [main] INFO sandbox.MainClass - CLOB: Exception in thread "main" java.sql.SQLException: Invalid length argument to getSubString(): -1 at org.teiid.core.types.ClobImpl.getSubString(ClobImpl.java:154) at sandbox.MainClass.main(MainClass.java:81)

    Description

      Method java.sql.Clob.getSubstring(int,int) returns either empty string (if second argument, length, is 0) or whole string (if length >= 1).

      Attachments

        Activity

          People

            rhn-engineering-shawkins Steven Hawkins
            jdurani Juraj DurĂ¡ni (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: