Class Database

All Implemented Interfaces:
DataFactory, com.inet.report.database.sql.SqlSyntax, Serializable

public class Database extends JdbcData implements Serializable, com.inet.report.database.sql.SqlSyntax
This class is a layer between a DBMS or any other data source and i-net Clear Reports. It compensate the differences between the different DBMS. This class is the default implementation and should work with any SQL99 compatible database. The major information are:
  • whether a JDBC driver is used to fetch the data or if you want to set the data directly via engine.setData() or engine.setResultSet()
  • whether or not the data must be fetched for every instance of the sub-report on only once
  • the string that this database uses to represent a boolean

Additionally this class provides a method which is called to fetch the data from the database. This method is called when the report engine is executed and fetches the data for both, the main report and all its sub-reports. You may override this method and use engine.setData() if you want to fetch the report data yourself.

We first describe how data for the main report is fetched:

  • We check which DataSourceConfiguration is used in the report template. You can override the DataSourceConfiguration via the Datasource.setup or via the URL parameter datasource=.
  • The appropriate driver is loaded with the appropriate URL and the appropriate properties.
  • A connection to the database is opened. This only happens when the maximum number of connections (MaxConnections=5 in the i-net Clear Reports configuration) is not exceeded---and if the method database.useJdbcDriver() returns true.
  • The meta-data is examined and the appropriate database class is loaded
  • An SQL statement is created and executed in the database if database.useJdbcDriver() returns true.
  • The report data is fetched by calling the method getReportData(). The data is fetched, unnecessary records are discarded, the data is sorted and grouped and stored into the engine by using the method engine.setData().
  • The connection is closed immediately.

Fetching data for sub-reports is more complicated. Each sub-report is a complete report in its own right and thus consumes one connection to the database. Also a sub-report may be called more than once for each main report. For a given main report a sub-report must be re-executed and its report data must be fetched again if it is called with different set of parameters. This means that the database connection for a sub-report cannot be closed immediately, instead it will be closed after the main report has finished executing.
In the i-net Clear Reports configuration the maximum of connections is set to 5 (MaxConnections=5). If your main report consumes one connection then your sub-reports can only consume MaxConnections-1 connections. So please set MaxConnections to an appropriate value. For example if you have a report which consumes a database connection and 5 sub-reports where each sub-report also consume one database connection set the value MaxConnections=6. However, if your reports use more than 2 or 3 sub-reports, you should better change the layout of your report.
If you override the method getReportData(), you could specify if the method getReportData() should be called whenever the set of parameters changes for the sub-report or only once. You do this by overriding the method getReportDataPerInstance() to return true.
Since:
1.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a default Database class instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Checks whether an identifier can be used right away or has to be quoted due to invalid characters or keywords.
    convertModOperation(String dividend, String divisor)
    Returns a valid sql expression to evaluate the remainder of an division.
    convertStringToSQLSyntax(String s, boolean isFunctionParam)
    This function transfoms a java String to a SQL String representation.
    The default implementation surrounds the String with ' char.
    So the String hello will transformed to 'hello'.
    If passed String contains the qote character, it will be quoted.
    So the String Hello 'World' will transformed to 'Hello ''World'''.

    This function can be used to transform the String that multilanguage characters will supported.
    convertToBoolean(boolean value)
    Returns the representation of a boolean value in the query language of the database.
    convertToBoolean(String fieldReference, boolean invert)
    If required, this function modifies a field reference to convert the value of the field to a boolean.
    Returns a valid sql expression to convert the given parameter to a Time data type.
    convertToDate(String year, String month, String day)
    Returns a valid sql expression to convert the given parameters to a Date data type.
    Returns a valid sql expression to convert the given parameter to a Double data type.
    convertToInt(String parameter)
    Returns a valid sql expression to convert the given parameter to a Integer data type.
    Returns a valid sql expression to convert the given parameter to a String data type.
    Returns a valid sql expression to convert the given parameter to a Time data type.
    convertToTime(String hour, String minute, String sec)
    Returns a valid sql expression to convert the given parameters to a Time data type.
    convertToTimeStamp(String year, String month, String day, String hour, String minute, String sec)
    Returns a valid sql expression to convert the given parameters to a Timestamp data type.
    void
    fetchData(Engine engine, FetchTables fetchTables, DataCollector dataCollector)
    Fetches the part of the report data for which this data factory is responsible.
    protected void
    Tries to find column labels for the columns of the provided TableSource.
    Overwrite this method if the used database uses another sign than "+" as add operator.
    Deprecated.
    As of i-net Clear Reports 13.1, replaced by getConfiguration().getAliasToken()
    protected String
    getColumnName(String colName, String alias, int driverVersion, TableSource ts, int colIdx)
    Returns the column name dependent of the database.
    protected int
    getCursorType(int dataType)
    Returns the SQL data type for a cursor if the stored procedure parameter is a cursor.
    Returns the string used to quote SQL identifiers.
    int
    Returns the maximum length of the alias name.
    protected ResultSet
    getProcedureColumns(Datasource ds, String catalog, String schema, String procedure)
    Is used from #getColumns(TableSource) if the TableSource based on a stored procedure.
    protected ResultSet
    Is used from #getTableSourceInfos(Datasource, String) to find a list of stored procedures.
    protected String
    getSourceNameWithChange(TableSource ts, boolean escapeEverything)
    Returns the source name like catalog.schema.table.
    protected String
    getSqlIdentifier(Datasource ds, String identifier, boolean escapeEverything)
    Returns the SQL identifier regarding the settings of getIdentifierQuoteString(), escapeEverything and needQuote(String).
    com.inet.report.database.sql.SqlSyntax
    Returns the SQL syntax definition instance for this data factory.
    protected ResultSet
    getTables(Datasource ds, String catalog)
    Is used from #getTableSourceInfos(Datasource, String) to find a list of tables and views.
    protected void
    Init transient variables after serialize.
    boolean
    isCursor(int sqlType)
    FOR INTERNAL USE ONLY test if the given sql type is a cursor type
    boolean
    Returns the value of the flag escapeEverything.
    protected boolean
    isKeyword(String identifier)
    Returns true when the specified identifier is a keyword of this database.
    boolean
    Indicates whether an ORDER BY clause is allowed for the sql statement.
    This flag is relevant if tables and one Datasource is used only.
    boolean
    Indicates whether parentheses are allowed in FROM clause of the sql statement.
    For example the SAPDB does not support parentheses in JOIN syntax.
    This flag is relevant if tables and one Datasource is used only.
    boolean
    Indicates whether table names and column names have to be quoted
    For example, this property can be necessary for Oracle/PostgreSQL databases, if table/column where created with quotes and lower (Oracle) or upper (PostgreSQL) case characters.
    boolean
    Indicates whether the SQL statement can contain the join condition in SQL92 syntax or not.
    boolean
    Indicates whether the SQL statement can contain the WHERE clause or not.
    This flag is relevant if tables and one Datasource is used only.
    protected boolean
    needQuote(String identifier)
    Returns if the supplied SQL identifier needs to be put in quotes.
    protected String[]
    Splits the provided name of a SQL source (name of a table, view or stored procedure) into three parts.
    protected void
    This method will detect which String should be used to quote database identifiers for the supplied Datasource.
    protected boolean
    scanSourceType(TableSource ts, com.inet.report.ParameterList dataTypeScale, boolean useMetaDataCache)
    FOR INTERNAL USE ONLY Ermittelt den Typ der Datenquelle true, bei Stored Procedure false(default)
    protected boolean
    scanSourceTypeParameters(Connection con, String srcCatalog, String srcSchema, ResultSet rs, com.inet.report.ParameterList parameters)
    FOR INTERNAL USE ONLY Scans the result set whith a column format as defined by DatabaseMetaData.getProcedureColumns(String, String, String, String) and adds all columns found to a ParameterList.
    protected void
    scanSourceTypeParameterSingle(ResultSet rs, com.inet.report.ParameterList parameters)
    FOR INTERNAL USE ONLY Add a single parameter, does not change the ResultSet position.
    void
    setAliasToken(String aliasToken)
    Deprecated.
    As of i-net Clear Reports 13.1, replaced by getConfiguration().setAliasToken(String)
    void
    This method is for adapt the sql statement for a specific database.
    Sets the string used to quote SQL identifiers.
    void
    setUseEscapeEverything(boolean escapeEvreything)
    This method is for adapt the sql statement for a specific database.
    This flag influence the way SQL identifier are written to SQL statement.
    void
    setUseOrderBy(boolean useOrderBy)
    This method is for adapt the sql statement for a specific database.
    Set this flag to false if the database does not support the ORDER BY clause.
    void
    setUseParenthesiseForJoin(boolean useParenthesiseForJoin)
    This method is for adapt the sql statement for a specific database.
    Set here whether the sql statement can have parentheses in FROM clause or not.
    For example the SAPDB does not support parentheses in JOIN syntax.
    This flag is relevant if tables and one Datasource is used only.
    void
    setUseQuoteLowerCase(boolean useQuoteLowerCase)
    This method is for adapt the sql statement for a specific database.
    Set here whether table names and column names have to be quoted.
    For example, this property can be necessary for Oracle/PostgreSQL databases, if table/column where created with quotes and lower (Oracle) or upper (PostgreSQL) case characters.
    void
    setUseSQL92syntax(boolean useSQL92syntax)
    This method is for adapt the sql statement for a specific database.
    Set here whether the SQL statement can contain the join condition in SQL92 syntax or not.
    If set on true, the join is contained in FROM clause, otherwise in WHERE clause.
    Note: full outer join is not possible in WHERE clause.
    void
    setUseWhereClause(boolean useWhereClause)
    This method is for adapt the sql statement for a specific database.
    Set this flag to false if the database does not support the WHERE clause.
    sqlConcat(Object leftOperant, Object rightOperant)
    Returns a valid sql statement concatenating two expressions.
    toSQL92(String function, Field field)
    Creates a SQL92 expression with function and one parameter.

    Methods inherited from class com.inet.report.database.BaseDataFactory

    getColumns, getConfiguration, getTableSourceData, setConfiguration

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.inet.report.database.DataFactory

    getVersion

    Methods inherited from interface com.inet.report.database.sql.SqlSyntax

    getValidateMessage
  • Constructor Details

    • Database

      public Database()
      Create a default Database class instance.
      Since:
      1.0
  • Method Details

    • initTransient

      protected void initTransient()
      Init transient variables after serialize.
      Since:
      8.0
    • scanSourceType

      protected boolean scanSourceType(TableSource ts, com.inet.report.ParameterList dataTypeScale, boolean useMetaDataCache) throws SQLException, ReportException
      FOR INTERNAL USE ONLY Ermittelt den Typ der Datenquelle true, bei Stored Procedure false(default)
      Throws:
      SQLException
      ReportException
    • scanIdentifierQuoteString

      protected void scanIdentifierQuoteString(Datasource dc) throws SQLException, ReportException
      This method will detect which String should be used to quote database identifiers for the supplied Datasource. For JDBC drivers this will call DatabaseMetaData.getIdentifierQuoteString(). The identifier quote string detected should be applied to this Database using setIdentifierQuoteString(String).
      Overriding classes can use this method to detect the identifier quote string on their own.
      Parameters:
      dc - The Datasource providing the connection information.
      Throws:
      SQLException - If a SQL error occurred during request of database meta data.
      ReportException - If an error occurred during establishing a database connection.
      Since:
      8.0
    • scanSourceTypeParameters

      protected boolean scanSourceTypeParameters(Connection con, String srcCatalog, String srcSchema, ResultSet rs, com.inet.report.ParameterList parameters) throws SQLException
      FOR INTERNAL USE ONLY Scans the result set whith a column format as defined by DatabaseMetaData.getProcedureColumns(String, String, String, String) and adds all columns found to a ParameterList.
      Parameters:
      con - the used connection
      srcCatalog - the catalog from the source of the procedure
      srcSchema - the schema from the source of the procedure
      rs - the result set of the getProcedureColumns method call, must not be null
      parameters - the list to add the parameter specs to, must not be null
      Returns:
      true, if at least one dataset is in the result set, false if it's empty
      Throws:
      SQLException - if a database access error occurs
      Since:
      23.10
    • scanSourceTypeParameterSingle

      protected void scanSourceTypeParameterSingle(ResultSet rs, com.inet.report.ParameterList parameters) throws SQLException
      FOR INTERNAL USE ONLY Add a single parameter, does not change the ResultSet position. DatabaseMetaData.getProcedureColumns(String, String, String, String) and adds all columns found to a ParameterList.
      Parameters:
      rs - the result set of the getProcedureColumns method call, must not be null
      parameters - the list to add the parameter specs to, must not be null
      Throws:
      SQLException - if a database access error occurs
      Since:
      23.10
    • parseSourceName

      protected String[] parseSourceName(String sqlSource)
      Splits the provided name of a SQL source (name of a table, view or stored procedure) into three parts. The name can consist of the following parts: [[catalog.]schema.]name. The array returned contains these three parts each part set to null if not set.
      Parameters:
      sqlSource - The name of the SQL source which may contain catalog or schema qualifier.
      Returns:
      A string array of dimension 3 with the following values for the three indexes:
      • array[0] the catalog or null if no catalog is set
      • array[1] the schema or null if no schema is set
      • array[2] the name (never null)
      Since:
      8.0
    • getColumnName

      protected String getColumnName(String colName, String alias, int driverVersion, TableSource ts, int colIdx)
      Returns the column name dependent of the database.
      Overrides:
      getColumnName in class JdbcData
      Parameters:
      colName - the column name
      alias - the column alias (required for MySQL Connector5.x only)
      driverVersion - the driver version (required for MySQL Connector5.x only)
      ts - the table source
      colIdx - the column index (required for Informix only)
      Returns:
      the name
    • needQuote

      protected boolean needQuote(String identifier)
      Returns if the supplied SQL identifier needs to be put in quotes. Usually this is the case if the identifier contains special characters or is equal to a SQL keyword.
      Parameters:
      identifier - The SQL identifier to be checked.
      Returns:
      True if the SQL identifier should be put in quotes false otherwise.
      Since:
      3.0
    • isKeyword

      protected boolean isKeyword(String identifier)
      Returns true when the specified identifier is a keyword of this database.
      Parameters:
      identifier - the identifier
      Returns:
      true when the specified identifier is a keyword of this database
      Since:
      15.0
    • getSqlIdentifier

      protected String getSqlIdentifier(Datasource ds, String identifier, boolean escapeEverything)
      Returns the SQL identifier regarding the settings of getIdentifierQuoteString(), escapeEverything and needQuote(String). If getIdentifierQuoteString() is empty the provided identifier will be returned without modification. If escapeEverything returns true the whole identifier provided should be put in the quotes returned by getIdentifierQuoteString(). Otherwise each part of the SQL identifier will be checked with needQuote(String) and put in quotes if necessary. The identifier can consist of catalog, schema and name like this: [[catalog.]schema.]name.
      Parameters:
      ds - The Datasource object of the report which uses the provided SQL identifier.
      identifier - The identifier which should be prepared for SQL.
      escapeEverything - True if the complete sql identifier should be quoted false otherwise
      Returns:
      The identifier which can be used in a SQL statement.
      Since:
      15.0
    • getSourceNameWithChange

      protected String getSourceNameWithChange(TableSource ts, boolean escapeEverything)
      Returns the source name like catalog.schema.table. Overwrites the catalog and schema names if these was changed in the Datasource.
      Specified by:
      getSourceNameWithChange in class JdbcData
      Parameters:
      ts - the table source
      escapeEverything - True if the complete sql identifier should be quoted false otherwise
      Returns:
      the name
      Since:
      13.0
    • getAddOp

      public String getAddOp()
      Overwrite this method if the used database uses another sign than "+" as add operator.
      Returns:
      The SQL String representation of the add operator.
      Since:
      3.0
    • sqlConcat

      public String sqlConcat(Object leftOperant, Object rightOperant)
      Returns a valid sql statement concatenating two expressions. The default implementation is:
      leftOperant + getAddOp() + rightOperant
      Example implemantation of MySQL:
      " concat("+leftOperant+","+rightOperant+") "
      Specified by:
      sqlConcat in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      leftOperant - the left operand
      rightOperant - the right operand
      Returns:
      A SQL String representation
      Since:
      4.0
      See Also:
    • getTables

      protected ResultSet getTables(Datasource ds, String catalog) throws SQLException, ReportException
      Is used from #getTableSourceInfos(Datasource, String) to find a list of tables and views.
      Specified by:
      getTables in class JdbcData
      Parameters:
      ds - The current Datasource containing the Connection.
      catalog - The catalog/database set in login dialog of i-net Designer.
      Returns:
      A ResultSet with the structure of DatabaseMetaData.getTables()
      Throws:
      SQLException - if a database access error occurs
      ReportException - if the creation of a Connection failed.
    • getProcedures

      protected ResultSet getProcedures(Datasource ds, String catalog) throws SQLException, ReportException
      Is used from #getTableSourceInfos(Datasource, String) to find a list of stored procedures. Returns the procedures meta data for a datasource and catalog as defined by DatabaseMetaData.getProcedures(String, String, String)
      Specified by:
      getProcedures in class JdbcData
      Parameters:
      ds - the datasource to connect to (if not already connected)
      catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
      Returns:
      each row is a procedure description
      Throws:
      SQLException - if a database access error occurs
      ReportException - if creating a Connection failed.
    • getProcedureColumns

      protected ResultSet getProcedureColumns(Datasource ds, String catalog, String schema, String procedure) throws SQLException, ReportException
      Is used from #getColumns(TableSource) if the TableSource based on a stored procedure.
      Specified by:
      getProcedureColumns in class JdbcData
      Parameters:
      ds - The Datasource containing the Connection.
      catalog - The catalog/database set in login dialog of i-net Designer.
      schema - The table owner or null.
      procedure - The procedure name.
      Returns:
      A ResultSet with the structure of DatabaseMetaData.getProcedureColumns
      Throws:
      SQLException - This SQLException will be show in a message box in i-net Designer.
      ReportException - if the creation of a Connection failed.
    • isCursor

      public boolean isCursor(int sqlType)
      FOR INTERNAL USE ONLY test if the given sql type is a cursor type
      Parameters:
      sqlType - The sql type to test if it should be treated as cursor.
      Returns:
      True if the supplied sql type should be treated as a cursor false otherwise.
      Since:
      3.3
    • getCursorType

      protected int getCursorType(int dataType)
      Returns the SQL data type for a cursor if the stored procedure parameter is a cursor. If no special SQL data type exists for a cursor then the original data type will be returned.
      The default implementation returns the original data type always.
      Parameters:
      dataType - The original SQL data type for the stored procedure parameter which should be used as cursor.
      Returns:
      The SQL data type for a cursor.
      Since:
      4.0
    • getMaxAliasNameLength

      public int getMaxAliasNameLength()
      Returns the maximum length of the alias name. Some databases have restrictions to the length of the alias name. So this method will return 18 as the default value. Databases which allow alias names to have more than 18 characters can overwrite this method and return a higher value.
      Returns:
      The maximum length of an alias name.
      Since:
      6.0
    • convertToString

      public String convertToString(String parameter) throws ReportException
      Returns a valid sql expression to convert the given parameter to a String data type. This method is required for transforming the record selection formula and the group to a valid SQL Statement. The base implementation does the following:
      return "{fn CONVERT( "+parameter+", SQL_CHAR ) }";
      The class DatabaseAccess for example overwrites that method and returns:
      return "Cstr("+parameter+")";
      Specified by:
      convertToString in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      parameter - set in ToText(parameter)
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToInt

      public String convertToInt(String parameter) throws ReportException
      Returns a valid sql expression to convert the given parameter to a Integer data type. This method is required for transforming the record selection formula and the group to a valid SQL Statement. The base implementation does the following:
      return "{fn CONVERT( "+parameter+", SQL_INTEGER ) }";
      The class DatabaseAccess for example overwrites that method and returns:
      return "Cint("+parameter+")";
      Specified by:
      convertToInt in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      parameter - set in Int(parameter),Truncate(parameter)
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToDouble

      public String convertToDouble(String parameter) throws ReportException
      Returns a valid sql expression to convert the given parameter to a Double data type. This method is required for transforming the record selection formula and the group to a valid SQL Statement. The base implementation does the following:
      return "{fn CONVERT( "+parameter+", SQL_DOUBLE ) }";
      The class DatabaseAccess for example overwrites that method and returns:
      return "Cdbl("+parameter+")";
      Specified by:
      convertToDouble in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      parameter - set in Cdbl(parameter),ToNumber(parameter)
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToTime

      public String convertToTime(String time) throws ReportException
      Returns a valid sql expression to convert the given parameter to a Time data type. This method is required for transforming the record selection formula and the group to a valid SQL Statement. The base implementation does the following:
      return "{fn CONVERT( "+parameter+", SQL_TIME ) }";
      The class DatabaseOracle for example overwrites that method and returns:
      return "to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')";
      Specified by:
      convertToTime in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      time - parameter set in TimeValue(parameter),CTime(parameter)
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToDate

      public String convertToDate(String date) throws ReportException
      Returns a valid sql expression to convert the given parameter to a Time data type. This method is required for transforming the record selection formula and the group to a valid SQL Statement. The base implementation does the following:
      return "{fn CONVERT( "+parameter+", SQL_TIME ) }";
      The class DatabaseOracle for example overwrites that method and returns:
      return "to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')";
      Specified by:
      convertToDate in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      date - parameter set in TimeValue(parameter),CTime(parameter)
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToDate

      public String convertToDate(String year, String month, String day) throws ReportException
      Returns a valid sql expression to convert the given parameters to a Date data type. This method must be overwritten if you use the function CDate(YYYY, MM, DD) or Date(YYYY, MM, DD) and at least one of the parameters is a dynamic parameter. The parameter is dynamic if it is a table column for example. The returned sql expression must be database specific, because there exists no escape function with three parameter.
      Example solution for SQL Server:
      "convert(datetime, right( '0000' + convert(varchar,"+year+"),4) + right( '00' + convert(varchar,"+month+"), 2) + right( '00' + convert(varchar,"+day+"), 2))"
      Example solution for Oracle Server:
      "to_date("+year+"||'/'||"+month+"||'/'||"+day+",'YYYY/mm/dd')"
      Specified by:
      convertToDate in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      year - The year of the date to convert.
      month - The month of the date to convert.
      day - The day of the date to convert.
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToTime

      public String convertToTime(String hour, String minute, String sec) throws ReportException
      Returns a valid sql expression to convert the given parameters to a Time data type. This method must be overwritten if you use the function CTime(HH, MM, SS) or Time(HH, MM, SS) and at least one of the parameters is a dynamic parameter. The parameter is dynamic if it is a table column for example. The returned sql expression must be database specific, because there exists no escape function with three parameter.
      Example solution for SQL Server:
      "convert(datetime, right( '00' + convert(varchar,"+hour+"),2)+ ':'+ right( '00' + convert(varchar,"+minute+"), 2) +':'+ right( '00' + convert(varchar,"+sec+"),2),8)"
      Example solution for Oracle Server:
      "to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')"
      Specified by:
      convertToTime in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      hour - The hour of the time to convert.
      minute - The minute of the time to convert.
      sec - The second of the time to convert.
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertToTimeStamp

      public String convertToTimeStamp(String year, String month, String day, String hour, String minute, String sec) throws ReportException
      Returns a valid sql expression to convert the given parameters to a Timestamp data type. This method must be overwritten if you use the function DateTime(YYYY, MM, DD, HH, MM, SS) or DateTimeValueTime(YYYY, MM, DD, HH, MM, SS) and at least one of the parameters is a dynamic parameter. The parameter is dynamic if it is a table column for example. The returned sql expression must be database specific, because there exists no escape function with three parameter.
      Example solution for SQL Server:
      "convert(datetime, right( '0000' + convert(varchar,"+year+"),4) + '-' + right( '00' + convert(varchar,"+month+"), 2) + '-' +right( '00' + convert(varchar,"+day+"),2)+' '+right( '00' + convert(varchar,"+hour+"),2)+ ':'+ right( '00' + convert(varchar,"+minute+"), 2) +':'+ right( '00' + convert(varchar,"+sec+"),2),20)"
      Specified by:
      convertToTimeStamp in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      year - The year of the date to convert.
      month - The month of the date to convert.
      day - The day of the date to convert.
      hour - The hour of the time to convert.
      minute - The minute of the time to convert.
      sec - The second of the time to convert.
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertModOperation

      public String convertModOperation(String dividend, String divisor) throws ReportException
      Returns a valid sql expression to evaluate the remainder of an division. The given parameter are the divisor and the dividend of the division. This method must be overwritten if you use the mod operation and at least one of the parameters is a dynamic parameter. The parameter is dynamic if it is a table column for example. The returned sql expression must be database specific.
      The default implementation is:
      dividend+"%"+divisor Example solution for Oracle Server:
      "mod("+dividend+","+divisor+")"
      Specified by:
      convertModOperation in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      dividend - The dividend of the mod operation to convert.
      divisor - The divisor of the mod operation to convert.
      Returns:
      The SQL String representation.
      Throws:
      ReportException - if that convert function is not possible in the database. In this case the function will be evaluated by i-net Clear Reports.
      Since:
      4.0
    • convertStringToSQLSyntax

      public String convertStringToSQLSyntax(String s, boolean isFunctionParam)
      This function transfoms a java String to a SQL String representation.
      The default implementation surrounds the String with ' char.
      So the String hello will transformed to 'hello'.
      If passed String contains the qote character, it will be quoted.
      So the String Hello 'World' will transformed to 'Hello ''World'''.

      This function can be used to transform the String that multilanguage characters will supported. For MS SQL Server for example the class DatabaseSqlServer prefix the N. So the String Hello 'World' will transformed to N'Hello ''World'''.
      Specified by:
      convertStringToSQLSyntax in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      s - The String that have to transformed to SQL representation.
      isFunctionParam - Shows that this flag is a constant parameter to be used by a function. This is important for parameters which can not be written as multi-language parameters. For example, the first parameter of the function TIMESTAMPADD cannot be a multi-language parameter for a Microsoft SQL Server database.
      Returns:
      The SQL String representation.
      Since:
      7.0
    • isUseOrderBy

      public boolean isUseOrderBy()
      Indicates whether an ORDER BY clause is allowed for the sql statement.
      This flag is relevant if tables and one Datasource is used only.
      Returns:
      True if the sql statement can contain an ORDER BY clause false otherwise.
      Since:
      6.1
      See Also:
    • setUseOrderBy

      public void setUseOrderBy(boolean useOrderBy)
      This method is for adapt the sql statement for a specific database.
      Set this flag to false if the database does not support the ORDER BY clause. In this case the record sorting will be done from i-net Clear Reports.
      This flag is relevant if tables and one Datasource is used only.
      Parameters:
      useOrderBy - Whether the sql statement can have an ORDER BY clause or not.
      Since:
      6.1
      See Also:
    • isUseParenthesiseForJoin

      public boolean isUseParenthesiseForJoin()
      Indicates whether parentheses are allowed in FROM clause of the sql statement.
      For example the SAPDB does not support parentheses in JOIN syntax.
      This flag is relevant if tables and one Datasource is used only.
      Returns:
      True if parantheses are allowed in the FROM clause false otherwise.
      Since:
      6.1
      See Also:
    • setUseParenthesiseForJoin

      public void setUseParenthesiseForJoin(boolean useParenthesiseForJoin)
      This method is for adapt the sql statement for a specific database.
      Set here whether the sql statement can have parentheses in FROM clause or not.
      For example the SAPDB does not support parentheses in JOIN syntax.
      This flag is relevant if tables and one Datasource is used only.
      Parameters:
      useParenthesiseForJoin - Whether the sql statement can have parentheses in FROM clause or not.
      Since:
      5.0
      See Also:
    • isUseQuoteLowerCase

      public boolean isUseQuoteLowerCase()
      Indicates whether table names and column names have to be quoted
      For example, this property can be necessary for Oracle/PostgreSQL databases, if table/column where created with quotes and lower (Oracle) or upper (PostgreSQL) case characters.
      Returns:
      True if column and table name need to be quoted false otherwise.
      Since:
      6.1
      See Also:
    • setUseQuoteLowerCase

      public void setUseQuoteLowerCase(boolean useQuoteLowerCase)
      This method is for adapt the sql statement for a specific database.
      Set here whether table names and column names have to be quoted.
      For example, this property can be necessary for Oracle/PostgreSQL databases, if table/column where created with quotes and lower (Oracle) or upper (PostgreSQL) case characters.
      Parameters:
      useQuoteLowerCase - Whether table names and column names have to be quoted.
      Since:
      6.1
      See Also:
    • isUseSQL92syntax

      public boolean isUseSQL92syntax()
      Indicates whether the SQL statement can contain the join condition in SQL92 syntax or not.
      Returns:
      True if the SQL statement can contain the join condition in SQL92 syntax false if not.
      Since:
      6.1
      See Also:
    • setUseSQL92syntax

      public void setUseSQL92syntax(boolean useSQL92syntax)
      This method is for adapt the sql statement for a specific database.
      Set here whether the SQL statement can contain the join condition in SQL92 syntax or not.
      If set on true, the join is contained in FROM clause, otherwise in WHERE clause.
      Note: full outer join is not possible in WHERE clause.
      Parameters:
      useSQL92syntax - Whether the SQL statement can contain the join condition in SQL92 syntax or not.
      Since:
      6.1
      See Also:
    • isUseWhereClause

      public boolean isUseWhereClause()
      Indicates whether the SQL statement can contain the WHERE clause or not.
      This flag is relevant if tables and one Datasource is used only.
      Returns:
      True if the database supports WHERE clauses false otherwiese.
      Since:
      6.1
      See Also:
    • setUseWhereClause

      public void setUseWhereClause(boolean useWhereClause)
      This method is for adapt the sql statement for a specific database.
      Set this flag to false if the database does not support the WHERE clause. In this case the record filtering will be done from i-net Clear Reports.
      This flag is relevant if tables and one Datasource is used only.
      Parameters:
      useWhereClause - True if the database supports WHERE clauses false otherwiese.
      Since:
      6.1
      See Also:
    • getAliasToken

      @Deprecated public String getAliasToken()
      Deprecated.
      As of i-net Clear Reports 13.1, replaced by getConfiguration().getAliasToken()
      Returns the SQL keyword that is required to define an alias name in a SQL statement.
      For some databases a whitespace have to be set between table name and table alias. Other database expect the keyword "AS".
      Returns:
      The keyword used to define an alias name.
      Since:
      6.1
      See Also:
    • setAliasToken

      @Deprecated public void setAliasToken(String aliasToken)
      Deprecated.
      As of i-net Clear Reports 13.1, replaced by getConfiguration().setAliasToken(String)
      This method is for adapt the sql statement for a specific database.
      Sets the SQL keyword that will be put between table name and table alias.
      E.g. the database PostgreSql requires the keyword "AS". Many databases do not need a special keyword to indicate that a alias name is followed.
      Parameters:
      aliasToken - The keyword used to define an alias name.
      Since:
      6.1
      See Also:
    • getIdentifierQuoteString

      public String getIdentifierQuoteString()
      Returns the string used to quote SQL identifiers.
      Returns:
      The string used to quote SQL identifiers.
      Since:
      6.1
      See Also:
    • setIdentifierQuoteString

      public void setIdentifierQuoteString(String quoteString)
      This method is for adapt the sql statement for a specific database.
      Sets the string used to quote SQL identifiers. For most databases it is a " character.
      Parameters:
      quoteString - The string which should be used to quote the SQL identifiers.
      Since:
      6.1
      See Also:
    • isEscapeEverything

      public boolean isEscapeEverything()
      Returns the value of the flag escapeEverything.
      Returns:
      True if the complete sql identifier will be quoted false otherwise.
      Since:
      6.5
      See Also:
    • setUseEscapeEverything

      public void setUseEscapeEverything(boolean escapeEvreything)
      This method is for adapt the sql statement for a specific database.
      This flag influence the way SQL identifier are written to SQL statement. Per default it is false and should be kept false for most of database.
      If the flag is set to true, the complete table identifier will enclosed with quotes.
      If the table identifier contains catalog/schema information, the complete expression will enclosed with quotes.
      Example - escape everything is true:
      the original table identifier is "atable" in catalog "aCatalog".
      The resulting expression for the table in the sql statement will be : select ... from "aCatalog.aTable"
      note: this syntax is not allowed for most of databases. The only known case setting this flag to true is using i-net FOSITEX driver for csv data files.
      Parameters:
      escapeEvreything - True if the complete sql identifier should be quoted false otherwise.
      Since:
      6.5
      See Also:
    • findColumnLabels

      protected void findColumnLabels(TableSource tableSource)
      Tries to find column labels for the columns of the provided TableSource. Overriding classes can use this method to query meta data information about the columns of the provided TableSource. They can use the connection provided by the report. (TableSource.getDatasource().getConnection()) If any column label is found overriding classes should update the database field with the column lable using DatabaseField.setColumnLabel(String).
      Parameters:
      tableSource - The TableSource to find the column labels for.
      Since:
      8.0
    • toSQL92

      public String toSQL92(String function, Field field) throws ReportException
      Creates a SQL92 expression with function and one parameter.
      Specified by:
      toSQL92 in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      function - the function
      field - the parameter field
      Returns:
      the result expression
      Throws:
      ReportException - the data access failed
      Since:
      11.0
    • convertToBoolean

      public String convertToBoolean(boolean value)
      Returns the representation of a boolean value in the query language of the database. The result depends of the ability of the database to resolve boolean constants.
      Specified by:
      convertToBoolean in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      value - the boolean value to convert
      Returns:
      the database dependent representation of a boolean
      Since:
      11.0
    • convertToBoolean

      public String convertToBoolean(String fieldReference, boolean invert)
      If required, this function modifies a field reference to convert the value of the field to a boolean. This is required in case the database has no real boolean representation and uses a bit or number instead.
      Specified by:
      convertToBoolean in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      fieldReference - the plain field reference for the column which is supposed to contain a boolean value
      invert - set whether to invert the value of the field
      Returns:
      the modified field reference, may be the original one in case the database supports boolean columns
      Since:
      11.0
    • convertIdentifier

      public String convertIdentifier(Datasource ds, String identifier)
      Checks whether an identifier can be used right away or has to be quoted due to invalid characters or keywords. If the identifier requires to be modified, this method will return a modified and valid identifier. Otherwise the original string is returned.
      Specified by:
      convertIdentifier in interface com.inet.report.database.sql.SqlSyntax
      Parameters:
      ds - the description of all tables used in the current database; required to avoid using table names as identifier. may be null
      identifier - the identifier to convert to a valid SQL identifier, must not be null
      Returns:
      a valid SQL identifier
      Since:
      14.0
    • getSqlSyntax

      public com.inet.report.database.sql.SqlSyntax getSqlSyntax()
      Returns the SQL syntax definition instance for this data factory.
      Specified by:
      getSqlSyntax in interface DataFactory
      Specified by:
      getSqlSyntax in class JdbcData
      Returns:
      the SQL syntax definition instance for this data factory
    • fetchData

      public void fetchData(Engine engine, FetchTables fetchTables, DataCollector dataCollector) throws ReportException
      Fetches the part of the report data for which this data factory is responsible. A description about what tables are required to fetch is given in the specified FetchTables instance. The resulting fetched data is put to the specified DataCollector during execution of this method.

      An example implementation for this method:

      
       for( TableSource tableSource : fetchDef.getTableSources() ) {
           TableData tableData;
           
            // retrieve data for table source "tableSource"
           tableData = [...]
           
           // deliver the data to the collector:
           collector.addUnjoinedData( tableSource, tableData );
       }
       
      Specified by:
      fetchData in interface DataFactory
      Overrides:
      fetchData in class BaseDataFactory
      Parameters:
      engine - the engine of the report to render
      fetchTables - a model of joining table describing the data this data factory needs to deliver
      dataCollector - the collector which receives any resulting data
      Throws:
      ReportException - on failures during data fetching