Search code examples
mysqlsqlsql-serverhsqldbprocedure

hsqldb procedure with date Input parameter


I need to write a test for some download operation. This operation call procedure from MSSQL database, take result set and java make some stuf. For test I use hsqldb.

My procedure:
CREATE PROCEDURE map.Get1(IN packageName varchar(100), 
IN downloadDate DATE) 
READS SQL DATA DYNAMIC RESULT SETS 1 BEGIN ATOMIC
DECLARE result CURSOR WITH RETURN FOR SELECT * FROM map.tvschedule FOR READ ONLY; 
OPEN result; 
END

This procedure wan't work, i have an exception

call map.GET1('Genre','2018-03-10');

[42561][-5561] incompatible data type in conversion
java.lang.RuntimeException: org.hsqldb.HsqlException: incompatible data type 
in conversion

But this(without date parameter) work well:

CREATE PROCEDURE map.Get1(IN packageName varchar(100)) 
READS SQL DATA DYNAMIC RESULT SETS 1 BEGIN ATOMIC
DECLARE result CURSOR WITH RETURN FOR SELECT * FROM map.tvschedule FOR READ ONLY; 
OPEN result; 
END

call map.GET1('Genre');

first needed row

second needed row

I am not going to use input parameter, but i need this procedure to be looking i am going to.

My question is How to use date input parameter with hsqldb procedures?

UPDATE1: I used TO_DATE and now it works well, but i have no data in my result set, my java code is:

try (CallableStatement callableStatement = connection.prepareCall("{ call 
map.GetGenreProtocol( ?, ? ) }")) {
        callableStatement.setString(1, packageName);
        callableStatement.setDate(2, date);
        callableStatement.execute();
        ResultSet resultSet = callableStatement.getResultSet();


        while (resultSet.next()) {

           Interval Interval = new Interval();
            Interval.setDuration(resultSet.getInt("duration"));
           Interval.setMappingTargetId(resultSet.getInt("mappingTargetId"));
            Interval.setGenreId(resultSet.getInt("genreId"));
            Interval.setStart(resultSet.getLong("start"));
            Interval.setCategoryId(resultSet.getInt("categoryId"));
            Interval.setCategoryName(resultSet.getString("categoryName"));
            Interval.setGenreName(resultSet.getString("genreName"));
            Interval.setDescription(resultSet.getString("description"));

            Intervals.add(Interval);
        }
    }

Solution

  • Use the TO_DATE function.

    For example:

    call map.GET1('Genre', TO_DATE('2018-03-10', 'YYYY-MM-DD'));
    

    I guess you need to create a function that returns a table instead of a procedure:

    CREATE FUNCTION map.Get1(IN packageName  VARCHAR(100),
                             IN downloadDate DATE)
      RETURNS TABLE(.....)
      READS SQL DATA
    BEGIN ATOMIC
      ....
    END;