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

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

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

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 scalarClient3 class tests methods of scalar Functions interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 06/16/99
 */

public class scalarClient3 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) 
	{
		scalarClient3 theTests = new scalarClient3();
		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:      testWeek
	 *                 
	 * @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 WEEK(dateval) should return integer value ranging from 
	 *                 1 to 53 representing the week of the year in dateval; 
	 *                 if WEEK is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function week.
	 *                 It should return an integer.
	 *
	 */
	public void testWeek() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("WEEK",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function WEEK  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function WEEK is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testWeek failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function week
				queryString = props.getProperty("Week_Fn_Query","");

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

	/*
	 * @testName:      testMonth
	 *                 
	 * @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 MONTH(dateval) should return integer value ranging from 
	 *                 1 to 12 representing the month component of dateval; 
	 *                 if MONTH is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function month.
	 *                 It should return an integer.
	 *
	 */
	public void testMonth() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("MONTH",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function MONTH  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function MONTH is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testMonth failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function month
				queryString = props.getProperty("Month_Fn_Query","");

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

	/*
	 * @testName:      testYear
	 *                 
	 * @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 YEAR(dateval) should return integer value representing
	 *                 the year component of the dateval; if YEAR is supported 
	 *                 by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function year.
	 *                 It should return an integer.
	 *
	 */
	public void testYear() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("YEAR",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function YEAR  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function YEAR is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testYear failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function year
				queryString = props.getProperty("Year_Fn_Query","");

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

	/*
	 * @testName:      testMonthname
	 *                 
	 * @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 MONTHNAME(dateval) should return a string representing
	 *                 the month component of the dateval; if MONTHNAME is supported 
	 *                 by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function monthname.
	 *                 It should return a character string.
	 *
	 */
	public void testMonthname() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("MONTHNAME",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function MONTHNAME  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function MONTHNAME is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testMonthname failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function monthname
				queryString = props.getProperty("Monthname_Fn_Query","");
	
				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Month Name: " + retString );
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testMonthname Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testMonthname Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testQuarter
	 *                 
	 * @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 QUARTER(dateval) should return integer value ranging from
	 *                 1 to 4 representing the quarter in the dateval; if QUARTER is 
	 *                 supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function quarter.
	 *                 It should return an integer.
	 *
	 */
	public void testQuarter() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("QUARTER",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function QUARTER  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function QUARTER is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testQuarter failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function quarter
				queryString = props.getProperty("Quarter_Fn_Query","");

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

	/*
	 * @testName:      testNow
	 *                 
	 * @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 NOW() should return a timestamp value representing the 
	 *                 current date and time; if NOW is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function now.
	 *                 It should return a timestamp value.
	 *
	 */
	public void testNow() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("NOW",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function NOW  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function NOW is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testNow failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function now
				queryString = props.getProperty("Now_Fn_Query","");

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

	/*
	 * @testName:      testHour
	 *                 
	 * @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 HOUR(timeval) should return integer value ranging from
	 *                 0 to 23 representing the hour component of timeval; if 
	 *                 HOUR is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function hour.
	 *                 It should return an integer.
	 *
	 */
	public void testHour() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("HOUR",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function HOUR  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function HOUR is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testHour failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function hour
				queryString = props.getProperty("Hour_Fn_Query","");

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

	/*
	 * @testName:      testMinute
	 *                 
	 * @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 MINUTE(timeval) should return integer value ranging from 
	 *                 0 to 59 representing the Minute component of timeval; 
	 *                 if MINUTE is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function minute.
	 *                 It should return an integer.
	 *
	 */
	public void testMinute() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("MINUTE",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function MINUTE  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function MINUTE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testMinute failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function minute
				queryString = props.getProperty("Minute_Fn_Query","");

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

	/*
	 * @testName:      testSecond
	 *                 
	 * @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 SECOND(timeval) should return integer value ranging from 
	 *                 0 to 59 representing the Second component of timeval; 
	 *                 if SECOND is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function second.
	 *                 It should return an integer.
	 *
	 */
	public void testSecond() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isTimeDateFuncFound("SECOND",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Time Date function SECOND  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Time Date function SECOND is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testSecond failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function second
				queryString = props.getProperty("Second_Fn_Query","");

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

	/*
	 * @testName:      testDatabase
	 *                 
	 * @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 DATABASE() should return string representing the 
	 *                 name of the database; if DATABASE is supported by DBMS.
	 *                 	 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function database.
	 *                 It should return a string.
	 *
	 */
	public void testDatabase() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isSystemFuncFound("DATABASE",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("System function DATABASE is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("System function DATABASE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDatabase Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function database
				queryString = props.getProperty("Database_Fn_Query","");

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


	/*
	 * @testName:      testAcos
	 *                 
	 * @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 ACOS(floatval) should return arccosine of floatval radians;
	 *                 if ACOS is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function acos.
	 *                 It should return a numeric value.
	 *
	 */
	public void testAcos() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("ACOS",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function ACOS  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function ACOS is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAcos failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function acos
				queryString = props.getProperty("Acos_Fn_Query","");

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

	/*
	 * @testName:      testAsin
	 *                 
	 * @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 ASIN(floatval) should return arcsine of floatval radians;
	 *                 if ASIN is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function asin.
	 *                 It should return a numeric value.
	 *
	 */
	public void testAsin() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("ASIN",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function ASIN  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function ASIN is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAsin failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function asin
				queryString = props.getProperty("Asin_Fn_Query","");

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

	/*
	 * @testName:      testAtan
	 *                 
	 * @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 ATAN(floatval) should return arctangent of floatval radians;
	 *                 if ATAN is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function atan.
	 *                 It should return a numeric value.
	 *
	 */
	public void testAtan() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("ATAN",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function ATAN  is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function ATAN is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAtan failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function atan
				queryString = props.getProperty("Atan_Fn_Query","");

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

	/*
	 * @testName:      testAtan2
	 *                 
	 * @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 ATAN(floatval1,floatval2) should return arctangent 
	 *                 of floatval1/floatval2 radians; if ATAN is supported by DBMS.
	 *                 
	 * @assertion:     The function atan2(float1,float2) should return the
	 *                 arctangent of float2/float1 radians.
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function atan2.
	 *                 It should return a numeric value.
	 *
	 */
	public void testAtan2() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("ATAN2",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function ATAN2 is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function ATAN2 is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAtan2 failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function atan2
				queryString = props.getProperty("Atan2_Fn_Query","");

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

	/*
	 * @testName:      testDegrees
	 *                 
	 * @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 DEGREES(numval) should return degrees in numval radians;
	 *                 if DEGREES is supported by DBMS.
	 *                 
	 * @assertion:     The function degrees(number) should return the
	 *                 degrees in number radians.
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function degrees.
	 *                 It should return a numeric value.
	 *
	 */
	public void testDegrees() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("DEGREES",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function DEGREES is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function DEGREES is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDegrees failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function degrees
				queryString = props.getProperty("Degrees_Fn_Query","");

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

	/*
	 * @testName:      testRadians
 	 *                 
	 * @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 RADIANS(numval) should return radians in numval degrees;
	 *                 if RADIANS is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function radians.
	 *                 It should return a numeric value.
	 *
	 */
	public void testRadians() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("RADIANS",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function RADIANS is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function RADIANS is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testRadians failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function radians
				queryString = props.getProperty("Radians_Fn_Query","");

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

	/*
	 * @testName:      testPi
	 *                 
	 * @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 PI() should return the constant PI; if PI is supported
	 *                 by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function pi.
	 *                 It should return the constant value of PI.
	 *
	 */
	public void testPi() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("PI",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function PI is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function PI is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testPi failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function pi
				queryString = props.getProperty("Pi_Fn_Query","");

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

	/*
	 * @testName:      testRand
	 *                 
	 * @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 RAND(numval) should return floating point for seed numval;
	 *                 if RAND is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function rand.
	 *                 It should return a numeric value.
	 *
	 */
	public void testRand() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isNumericFuncFound("RAND",conn)==true)
			{
				//Function is supported
				isFuncFound=true;
				logMsg("Numeric function RAND is supported by this DBMS");
			}
			else
			{
				//Function is not supported
				isFuncFound=false;
				logMsg("Numeric function RAND is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testRand failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function rand
				queryString = props.getProperty("Rand_Fn_Query","");

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

	/*
	 * @testName:      testDifference
	 *                 
	 * @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 DIFFERENCE(str1, str2) should return an integer indicating;
	 *                 the difference between the values returned by the function 
	 *                 soundex for str1 and str2; if DIFFERENCE is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function difference.
	 *                 It should return an integer.
	 *
	 */
	public void testDifference() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("DIFFERENCE",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function DIFFERENCE is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function DIFFERENCE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testDifference Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function difference
				queryString = props.getProperty("Difference_Fn_Query","");
				
				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("DIFFERENCE value: <" + retString + ">");
				rs.close();    
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testDifference Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testDifference Failed!", e);
			}
		}
	}

	/*
	 * @testName:      testLocate02
	 *                 
	 * @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 LOCATE(str1,str2) should return an integer value 
	 *                 representing the Position in str2 of the first occurence of 
	 *                 str1, searching from position start; if LOCATE 
	 *                 function is supported by DBMS
	 * 	               
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function locate.
	 *                 It should return an integer.
	 *
	 */
	public void testLocate02() throws Fault
	{

		try
		{
			String queryString = null;
			//Query that contains a call to the function locate
			queryString = props.getProperty("Locate_Fn_Query","");

			rs=stmt.executeQuery(queryString);
			rs.next();
			String retString = rs.getString(1);
			logMsg("str1 starts at " + retString + " of str2");
			rs.close();    
   
		}
		catch(SQLException sqle)
		{
			logErr("SQLException: " + sqle.getMessage());
			throw new Fault("Call to testLocate02 Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLocate02 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");
		}
	}

}

