tags:

views:

703

answers:

1

Is it possible to make the schema name dynamic in a BIRT query.

I tried this:

SELECT CURRENT DATE AS DATE, 
(CASE WHEN DAYOFWEEK(CURRENT DATE) = 1 THEN 'SUNDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 2 THEN 'MONDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 3 THEN 'TUESDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 4 THEN 'WEDNESDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 5 THEN 'THURSDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 6 THEN 'FRIDAY'
      WHEN DAYOFWEEK(CURRENT DATE) = 7 THEN 'SATURDAY'
      END) AS DAYOFWEEK
FROM **?**.COBOL_CALENDAR
 WHERE SERVICE_DATE = CURRENT DATE"

This generates the following error: The following items have errors:

ReportDesign (id = 1): 
+ Cannot get the result set metadata.
SQL statement does not return a ResultSet object.
SQL error #1: [IBM][CLI Driver][DB2] SQL0104N  An unexpected token "?" was found following "".  Expected tokens may include:  "( TABLE FINAL <IDENTIFIER> XMLTABLE".  SQLSTATE=42601

But the ? only seems to work for the where clause.

I need to pass the schema as a param and use dynamically because it changes based on dev/cat/prod

is there not some way to genereate sql outsite of the birt xml and inject it somehow??

I did some more searching on the subject and found this solution

<method name="beforeOpen"><![CDATA[this.queryText = "SELECT CURRENT DATE AS DATE, "+
"(CASE WHEN DAYOFWEEK(CURRENT DATE) = 1 THEN 'SUNDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 2 THEN 'MONDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 3 THEN 'TUESDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 4 THEN 'WEDNESDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 5 THEN 'THURSDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 6 THEN 'FRIDAY'"+
"      WHEN DAYOFWEEK(CURRENT DATE) = 7 THEN 'SATURDAY'"+
"      END) AS DAYOFWEEK"+
"FROM "+params["SCHEMA"]+".COBOL_CALENDAR"+
" WHERE SERVICE_DATE = CURRENT DATE";]]></method>

However regardless of how many examples that are out there on this issue injecting sql in this manner only generates the following error.

ReportDesign (id = 1): 
+ Cannot get the result set metadata.
SQL statement does not return a ResultSet object.
SQL error #1: [IBM][CLI Driver][DB2] SQL0104N  An unexpected token "SCHEMANAME" was found following "".  Expected tokens may include:  ", FROM INTO".  SQLSTATE=42601

I even tried the reportContext.getParameterValue("SCHEMANAME") route with the same results.

+1  A: 

ARRRGH it was a stupid problem with spaces!!

" END) AS DAYOFWEEK"+ "FROM "+params["SCHEMA"]+".COBOL_CALENDAR"+

Adding a space in front of the FROM fixed it.

bangs head on lcd display.

mugafuga