
package org.eclipse.birt.tests.data.engine.regression;

import org.eclipse.birt.data.engine.api.IResultIterator;
import org.eclipse.birt.data.engine.api.querydefn.ConditionalExpression;
import org.eclipse.birt.data.engine.api.querydefn.FilterDefinition;
import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition;
import org.eclipse.birt.data.engine.api.querydefn.ScriptExpression;

import testutil.APITestCase;
import testutil.ConfigText;

/**
 * <b>Bug description</b>
 * <p>
 * Description:
 * <p>
 * Set the filter operator-between on the 'datatime' data type, an error is
 * thrown out
 * <p>
 * <ol>
 * Steps to reproduce:
 * <li>new a sample datasource
 * <li>input "select * from CLASSICMODELS.ORDERS " in the query text
 * <li>add a filter
 * <P>
 * expression: row["ORDERDATE"] Operator: between value1: "Feb 11, 2003 12:00:00
 * AM" Value2: "Apr 4, 2003 12:00:00 AM"
 * <li>Preview
 * </ol>
 * <p>
 * <b>Test description</b>
 * <p>
 * Set operator-between on the 'datatime' type in dataset filter, and compare
 * the result with the golden file.
 * 
 * 
 */
public class Regression_136296 extends APITestCase
{

	// Use database in test framework
	protected DataSourceInfo getDataSourceInfo( )
	{
		return new DataSourceInfo( ConfigText
				.getString( "Api.TestData.TableName" ), ConfigText
				.getString( "Api.TestData.TableSQL" ), ConfigText
				.getString( "Api.TestData.TestDataFileName" ) );
	}

	public void testFilterOnDateType( ) throws Exception
	{

		FilterDefinition filterDefn = new FilterDefinition(
				new ConditionalExpression( "row.SALE_DATE",
						ConditionalExpression.OP_BETWEEN,
						"\'2004-02-11 12:00:00\'", "\'2004-04-04 12:00:00\'" ) );
		this.dataSet.addFilter( filterDefn );

		QueryDefinition queryDefn = newReportQuery( );

		// column mapping
		String[] name = new String[]{"Country", "City", "SALE_DATE"};
		ScriptExpression[] se = new ScriptExpression[name.length];
		se[0] = new ScriptExpression( "dataSetRow.COUNTRY" );
		se[1] = new ScriptExpression( "dataSetRow.CITY" );
		se[2] = new ScriptExpression( "dataSetRow.SALE_DATE" );
		for ( int i = 0; i < name.length; i++ )
			queryDefn.addResultSetExpression( name[i], se[i] );

		IResultIterator ri = executeQuery( queryDefn );
		while ( ri.next( ) )
		{
			String str = "";
			for ( int i = 0; i < name.length; i++ )
			{
				str += ri.getValue( name[i] );

				if ( i < name.length - 1 )
					str += ", ";
			}
			testPrintln( str );
		}

		checkOutputFile( );
	}

}