/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)scalarClient2.java	1.11 02/01/12
 */

package com.sun.cts.tests.jdbc.ee.escapeSyntax.scalar2;

import java.io.*;
import java.util.*;

import java.sql.*;
import javax.sql.*;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import com.sun.cts.tests.jdbc.ee.common.*;


// Merant DataSource class
//import com.merant.sequelink.jdbcx.datasource.*;


/**
 * The scalarClient2 class tests methods of scalar Functions interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 06/16/99
 */

public class scalarClient2 extends ServiceEETest  
{		  
	private static final String testName = "jdbc.ee.escapeSyntax";
	
	//Naming specific member variables
	private CTSNamingContextInterface jc = null;

	//Harness requirements 

	private transient Connection conn = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	private	String drManager=null;
	private fnSchema fnSch=null;
	private Properties props=null;

	/* Run test in standalone mode */
	public static void main(String[] args) 
	{
		scalarClient2 theTests = new scalarClient2();
		Status s=theTests.run(args, System.out, System.err);
		s.exit();
	}

	/*  Test setup: */
	
	/*
	 *   @class.setup_props: Driver, the Driver name;
	 *                       db1, the database name with url;
	 *                       user1, the database user name;
	 *                       password1, the database password;
	 *                       db2, the database name with url;
	 *                       user2, the database user name;
	 *                       password2, the database password;
	 *			 DriverManager, flag for DriverManager;
	 *                       ptable, the primary table;
	 *                       ftable, the foreign table;
	 *                       cofSize, the initial size of the ptable;
	 *                       cofTypeSize, the initial size of the ftable;
	 *                       binarySize, size of binary data type;
	 *                       varbinarySize, size of varbinary data type;
	 *                       longvarbinarySize, size of longvarbinary data type;
	 *  @class.testArgs:     -ap ctssql.stmt
	 */
	public void setup(String[] args, Properties p) throws Fault 
	{
		try 
		{
			try
			{
				props=p;
				drManager = p.getProperty("DriverManager","");
				if (drManager.length() == 0)
					throw new Fault("Invalid DriverManager Name");

				if(drManager.equals("yes"))
				{
					logMsg("Using DriverManager");
					DriverManagerConnection dmCon = new DriverManagerConnection();
					conn = dmCon.getConnection(p);
				}
				else 
				{
					logMsg("Using DataSource");
					DataSourceConnection dsCon = new DataSourceConnection();
					conn = dsCon.getConnection(p);
				}
				stmt=conn.createStatement();
				fnSch = new fnSchema();
				fnSch.createTable(p,conn);
				
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		} 
		catch  ( Exception e ) 
		{
			logErr("Setup Failed!");
		}
	}

	/*
	 * @testName:      testAbs
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The ABS(numval) should return Absolute value of numval; if
	 *                 ABS is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function abs.
	 *                 It should return a numeric value.
	 *
	 */
	public void testAbs() throws Fault
	{
		
		try
		{
			String queryString = null;
			//Query that contains a call to the function abs
			queryString = props.getProperty("Abs_Fn_Query","");

			rs=stmt.executeQuery(queryString);
			rs.next();
			String retString = rs.getString(1);
			logMsg("Absolute value : " + retString );
			rs.close();    
		}
		catch(SQLException sqle)
		{
			logErr("SQLException: " + sqle.getMessage());
			throw new Fault("Call to testAbs Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAbs Failed!", e);
		}
		
	}

	/*
	 * @testName:      testPower
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The POWER(numval, powerval) should return integer value
	 *                 representing numval raised to powerval; if POWER is supported 
	 *                 by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function power.
	 *                 It should return a numeric value.
	 *
	 */
	public void testPower() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("POWER",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function POWER  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function POWER is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testPower failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function power
				queryString = props.getProperty("Power_Fn_Query","");
	
				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Power value : " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testPower Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testPower Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testRound
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The ROUND(numval,placeval) should return an integer representing
	 *                 numval rounded to placeval places; if ROUND is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function round.
	 *                 It should return a numeric value.
	 *
	 */
	public void testRound() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("ROUND",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function ROUND  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function ROUND is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testRound failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function round
				queryString = props.getProperty("Round_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Rounded value : " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testRound Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testRound Failed!", e);
			}

		}
	}

	/*
	 * @testName:      testSign
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The SIGN(numval) should return -1 if numval is less than 0 (<0);
	 *                 0 if numval is equal to 0 (=0) and 1 if numval is greater 
	 *                 than 0 (>0); if SIGN is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function sign.
	 *                 It should return an integer.
	 *
	 */
	public void testSign() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("SIGN",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function SIGN  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function SIGN is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testSign failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function sign
				queryString = props.getProperty("Sign_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Sign value : " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testSign Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testSign Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testSqrt
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The SQRT(floatval) should return the square root of the floatval;
	 *                 if SQRT is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function sqrt.
	 *                 It should return a numeric value.
	 *
	 */
	public void testSqrt() throws Fault
	{
		
		try
		{
			String queryString = null;
			//Query that contains a call to the function sqrt
			queryString = props.getProperty("Sqrt_Fn_Query","");
			
			rs=stmt.executeQuery(queryString);
			rs.next();
			String retString = rs.getString(1);
			logMsg("Sqrt value : " + retString );
			rs.close();    
  
		}
		catch(SQLException sqle)
		{
			logErr("SQLException: " + sqle.getMessage());
			throw new Fault("Call to testSqrt Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testSqrt Failed!", e);
		}

	}

	/*
	 * @testName:      testTruncate
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The TRUNCATE(numval,placeval) should return integer representing
	 *                 numval truncated to placeval places; if TRUNCATE is supported
	 *                 by DBMS.
	 *                 

	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function truncate.
	 *                 It should return a numeric value.
	 *
	 */
	public void testTruncate() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("TRUNCATE",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function TRUNCATE  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function TRUNCATE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testTruncate failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function truncate
				queryString = props.getProperty("Truncate_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Truncated Number: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testTruncate Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testTruncate Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testMod
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The MOD(numval1, numval2) should return the remainder for 
	 *                 numval1/numval2; if MOD is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function mod.
	 *                 It should return an integer.
	 *
	 */
	public void testMod() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("MOD",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function MOD  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function MOD is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testMod failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function mod
				queryString = props.getProperty("Mod_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Remainder value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testMod Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testMod Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testFloor
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The FLOOR(numval) should return largest integer <= numval;
	 *                 if FLOOR is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function floor.
	 *                 It should return an integer.
	 *
	 */
	public void testFloor() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("FLOOR",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function FLOOR  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function FLOOR is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testFloor failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function floor
				queryString = props.getProperty("Floor_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Largest Integer: " + retString );
				rs.close();    
   	 
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testFloor Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testFloor Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testCeiling
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The CEILING(numval) should return smallest integer >= numval;
	 *                 if CEILING is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function ceiling.
	 *                 It should return an integer.
	 *
	 */
	public void testCeiling() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("CEILING",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function CEILING  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function CEILING is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testCeiling failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function ceiling
				queryString = props.getProperty("Ceiling_Fn_Query","");
	
				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Smallest Integer: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testCeiling Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testCeiling Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testLog10
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The LOG10(floatval) should return base 10 logarithm of floatval;
	 *                 if LOG10 is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function log10.
	 *                 It should return a numeric value.
	 *
	 */
	public void testLog10() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("LOG10",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function LOG10  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function LOG10 is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLog10 failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function log10
				queryString = props.getProperty("Log10_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Log10 value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testLog10 Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testLog10 Failed!", e);
			}
		}

	}

	/*
	 * @testName:      testLog
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The LOG(floatval) should return base e logarithm of floatval;
	 *                 if LOG is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function log.
	 *                 It should return a numeric value.
	 *
	 */
	public void testLog() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("LOG",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function LOG  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function LOG is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLog failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function log
				queryString = props.getProperty("Log_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Log e  value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testLog Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testLog Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testExp
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The EXP(floatval) should return Exponential function of 
	 *                 floatval; if EXP is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function exp.
	 *                 It should return a numeric value.
	 *
	 */
	public void testExp() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("EXP",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function EXP  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function EXP is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testExp failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function exp
				queryString = props.getProperty("Exp_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Exponential value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testExp Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testExp Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testCos
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The COS(floatval) should return cosine of floatval radians;
	 *                 if COS is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function cos.
	 *                 It should return a numeric value.
	 *
	 */
	public void testCos() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("COS",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function COS  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function COS is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testCos failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function cos
				queryString = props.getProperty("Cos_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("COS value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testCos Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testCos Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testTan
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The TAN(floatval) should return tangent of floatval radians;
	 *                 if TAN is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function tan.
	 *                 It should return a numeric value.
	 * 
	 */
	public void testTan() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("TAN",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function TAN  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function TAN is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testTan failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function tan
				queryString = props.getProperty("Tan_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("TAN value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testTan Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testTan Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testCot
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The COT(floatval) should return cotangent of floatval radians;
	 *                 if COT is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function cot.
	 *                 It should return a numeric value.
	 *
	 *
	 */
	public void testCot() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("COT",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function COT  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function COT is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testCot failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function cot
				queryString = props.getProperty("Cot_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("COT value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testCot Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testCot Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testCurdate
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The CURDATE() should return current date as a date value;
	 *                 if CURDATE is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function curdate.
	 *                 It should return a date value.
	 *
	 */
	public void testCurdate() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("CURDATE",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function CURDATE  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function CURDATE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testCurdate failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function curdate
				queryString = props.getProperty("Curdate_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Current Date  value: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testCurdate Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testCurdate Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testDayname
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The DAYNAME(dateval) should return a string representing the day
	 *                 component of dateval; if DAYNAME is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function dayname.
	 *                 It should return a character string.
	 *
	 */
	public void testDayname() throws Fault
	{
		boolean isFuncFound;
		try
		{
			if(fnSch.isTimeDateFuncFound("DAYNAME",conn)==true)
			{
				isFuncFound=true;
				logMsg("Time Date function DAYNAME  is supported by this DBMS");
			}
			else
			{
				isFuncFound=false;
				logMsg("Time Date function DAYNAME is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDayname failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				queryString = props.getProperty("Dayname_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Day Name: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testDayname Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testDayname Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testDayofmonth
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The DAYOFMONTH(dateval) should return an integer from 1 to 31
	 *                 representing the day of the month in dateval; if DAYOFMONTH
	 *                 is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function dayofmonth.
	 *                 It should return an integer.
	 *
	 */
	public void testDayofmonth() throws Fault
	{
		boolean isFuncFound;
		try
		{
			if(fnSch.isTimeDateFuncFound("DAYOFMONTH",conn)==true)
			{
				isFuncFound=true;
				logMsg("Time Date function DAYOFMONTH  is supported by this DBMS");
			}
			else
			{
				isFuncFound=false;
				logMsg("Time Date function DAYOFMONTH is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDayofmonth failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				queryString = props.getProperty("Dayofmonth_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Day of Month: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testDayofmonth Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testDayofmonth Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testDayofweek
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The DAYOFWEEK(dateval) should return an integer from 1 to 7
	 *                 representing the day of the week in dateval; if DAYOFWEEK
	 *                 is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function dayofweek.
	 *                 It should return an integer.
	 *
	 */
	public void testDayofweek() throws Fault
	{
		boolean isFuncFound;
		try
		{
			if(fnSch.isTimeDateFuncFound("DAYOFWEEK",conn)==true)
			{
				isFuncFound=true;
				logMsg("Time Date function DAYOFWEEK  is supported by this DBMS");
			}
			else
			{
				isFuncFound=false;
				logMsg("Time Date function DAYOFWEEK is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDayofweek failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				queryString = props.getProperty("Dayofweek_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Day of Week: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testDayofweek Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testDayofweek Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testDayofyear
	 *                 
	 * @assertion:     Scalar Functions may be supported by different DBMSs with 
	 *                 different syntax.  The driver should support the scalar 
	 *                 function if the DBMS supports it.  The driver may either map 
	 *                 the escaped function call into appropriate syntax or implement 
	 *                 the function directly itself. The scalar functions supported by 
	 *                 the DBMS can be found out by calling DatabaseMetaData methods.
	 *                 The DatabaseMetaData methods should return a comma separated 
	 *                 list of the Open Group CLI names of the supported scalar functions. 
	 *                 (See 40.1 & Appendix A.1.4 JDBC 2.0 API Reference & Tutorial).
	 *                 The DAYOFYEAR(dateval) should return an integer from 1 to 366
	 *                 representing the day of the year in dateval; if DAYOFYEAR
	 *                 is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function dayofyear.
	 *                 It should return an integer.
	 *
	 */
	public void testDayofyear() throws Fault
	{
		boolean isFuncFound;
		try
		{
			if(fnSch.isTimeDateFuncFound("DAYOFYEAR",conn)==true)
			{
				isFuncFound=true;
				logMsg("Time Date function DAYOFYEAR  is supported by this DBMS");
			}
			else
			{
				isFuncFound=false;
				logMsg("Time Date function DAYOFYEAR is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDayofyear failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				queryString = props.getProperty("Dayofyear_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Day of Year: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testDayofyear Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testDayofyear Failed!", e);
			}
		}
	}

	/* cleanup */
	public void cleanup() throws Fault
	{
		try
		{
			stmt.close();
			//Close the database
			fnSch.dropTable(props,conn);
			fnSch.dbUnConnect(conn);
			logMsg("Cleanup ok;");
		}
		catch(Exception e)
		{
			logErr("An error occurred while closing the database connection");
		}
	}

}

