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

/*
 * @(#)scalarClient1.java	1.10 02/01/12
 */

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

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

public class scalarClient1 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) 
	{
		scalarClient1 theTests = new scalarClient1();
		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:      testConcat
	 *                 
	 * @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 CONCAT(str1, str2) should return the string formed by
	 *                 appending str2 to str1; if a string is null, the result is
	 *                 DBMS-dependent; if CONCAT is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call executeQuery(String) method. 
	 *                 The query contains the concat scalar function.  
	 *                 It should return the concatenated string.
	 *
	 */
	public void testConcat() throws Fault
	{
		try
		{

			String queryString = null;
			//Query that contains a call to the function concat.
			queryString=props.getProperty("Concat_Fn_Query","");
			rs=stmt.executeQuery(queryString);
			rs.next();
			String retString = rs.getString(1);
			logMsg("Concatenated String: " + retString);
			rs.close();
		}
		catch(SQLException sqle)
		{
			logErr("SQLException: " + sqle.getMessage());
			throw new Fault("Call to testConcat Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testConcat Failed!", e);
		}

	}

	/*
	 * @testName:      testAscii
	 *                 
	 * @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 ASCII(str) should return integer value representing the
	 *                 ASCII code value of the leftmost character in str; if ASCII
	 *                 is supported by DBMS.
	 * 
	 * @test_Strategy: Get a statement object and call executeQuery method.  
	 *                 The query contains the ascii function call.  
	 *                 It should return an integer.
	 *
	 *
	 */
	public void testAscii() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("ASCII",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function ASCII is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function ASCII is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testAscii Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function ascii
				queryString = props.getProperty("Ascii_Fn_Query","");

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

	}

	/*
	 * @testName:      testInsert
	 *                 
	 * @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 INSERT(str1,startlength, str2) should return the string 
	 *                 formed by deleting length characters from str1 beginning at
	 *                 start and inserting str1 into str2 at start; if INSERT is
	 *                 supported by DBMS.
	 * 	               
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function insert.
	 *                 It should return a string.
	 *
	 */
	public void testInsert() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("INSERT",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function INSERT is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function INSERT is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testInsert Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function insert
				queryString = props.getProperty("Insert_Fn_Query","");

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

	}

	/*
	 * @testName:      testLcase
	 *                 
	 * @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 LCASE(str) should return the string with all upper case 
	 * 	               characters of str converted into lower case; if LCASE is 
	 *                 supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statment object and call the method executeQuery.
	 *                 The query contains a call to the function lcase.
	 *                 It should return a string.
	 *
	 *
	 */
	public void testLcase() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("LCASE",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function LCASE is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function LCASE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLcase Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function lcase
				queryString = props.getProperty("Lcase_Fn_Query","");

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

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

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("The first 2 chars: <" + retString + ">");
				rs.close();
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testLeft Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testLeft Failed!", e);
			}
		}
	}
	
	
	/*
	 * @testName:      testLength
	 *
	 * @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 LENGTH(str) should return an integer value representing
	 *                 the number of characters in str, excluding trailing blanks; if
	 *                 the function LENGTH is supported by DBMS.
	 * 	               
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function length.
	 *                 It should return a number.
	 *
	 *
	 */
	public void testLength() throws Fault
	{

		try
		{
			String queryString = null;
			//Query that contains a call to the function length
			queryString = props.getProperty("Length_Fn_Query","");
				
			rs=stmt.executeQuery(queryString);
			rs.next();
			String retString = rs.getString(1);
			logMsg("String length=" + retString);
			rs.close();
   
		}
		catch(SQLException sqle)
		{
			logErr("SQLException: " + sqle.getMessage());
			throw new Fault("Call to testLength Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLength Failed!", e);
		}
	}

	/*
	 * @testName:      testLocate01
	 *                 
	 * @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 the beginning of str2; 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 testLocate01() 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 testLocate01 Failed!", sqle);
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testLocate01 Failed!", e);
		}

	}

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

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

		}
	}

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

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

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

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("The last 3 chars: <" + retString + ">");
				rs.close();
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testRight Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testRight Failed!", e);
			}
		}

	}

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

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

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

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

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

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

	/*
	 * @testName:      testSubstring
	 *                 
	 * @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 SUBSTRING(str1,startlength) should return a String 
	 *                 formed by extracting length characters from str1 beginning 
	 *                 at start; if SUBSTRING is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function substring.
	 *                 It should return a string.
	 *
	 */
	public void testSubstring() throws Fault
	{

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

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

	/*
	 * @testName:      testUcase
	 *                 
	 * @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 UCASE(str) should return the string with all lower case 
	 * 	               characters of str converted into upper case; if UCASE is 
	 *                 supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function ucase.
	 *                 It should return a string.
	 *
	 */
	public void testUcase() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("UCASE",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function UCASE is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function UCASE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testUcase Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function ucase
				queryString = props.getProperty("Ucase_Fn_Query","");

				rs=stmt.executeQuery(queryString);
				rs.next();
				String retString = rs.getString(1);
				logMsg("Uppercase String: " + retString);
				rs.close();
    
			}
			catch(SQLException sqle)
			{
				logErr("SQLException: " + sqle.getMessage());
				throw new Fault("Call to testUcase Failed!", sqle);
			}
			catch(Exception e)
			{
				logErr("Unexpected Exception: " + e.getMessage());
				throw new Fault("Call to testUcase Failed!", e);
			}
		}
	}
	/*
	 * @testName:      testChar
	 *                 
	 * @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 CHAR(code) should return the characters with ASCII value
	 *                 equal to code, where code is between 0 and 255; if Char is 
	 *                 supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function char.
	 *                 It should return a character.
	 *
	 */
	public void testChar() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("CHAR",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function CHAR is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function CHAR is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testChar Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function char
				queryString = props.getProperty("Char_Fn_Query","");

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

	/*
	 * @testName:      testReplace
	 *                 
	 * @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 REPLACE(str1, str2, str3) should return 
	 *                 a string after replacing all occurences of str2 in str1 with
	 * 	               str3; if REPLACE is supported by DBMS.
	 *                 
	 * @test_Strategy: Get a Statement object and call the method executeQuery.
	 *                 The query contains a call to the function replace.
	 *                 It should return a string.
	 *
	 */
	public void testReplace() throws Fault
	{
		boolean isFuncFound;
		try
		{
			//Check if the function is supported by the DBMS
			if(fnSch.isStringFuncFound("REPLACE",conn)==true)
			{
				//Function is supported by the DBMS
				isFuncFound=true;
				logMsg("String function REPLACE is supported by this DBMS");
			}
			else
			{
				//Function is not supported by the DBMS
				isFuncFound=false;
				logMsg("String function REPLACE is not supported by this DBMS");
			}
		}
		catch(Exception e)
		{
			logErr("Unexpected Exception: " + e.getMessage());
			throw new Fault("Call to testReplace Failed!", e);
		}
		if(isFuncFound==true)
		{
			try
			{
				String queryString = null;
				//Query that contains a call to the function replace
				queryString = props.getProperty("Replace_Fn_Query","");

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

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

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

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

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

		}
	}

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

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

}

