//****************************************************************************************
// File:			PLSQLQueries.cs
// Description:		Demo of PLSQL Queries with .NET Access Provider
// Created by:		Stefan Arvidsson
// 
// Compile with csc /reference:Ifs.Fnd.AccessProvider.dll;Ifs.Fnd.Data.dll;Ifs.Fnd.Core.dll PLSQLQueries.cs
//****************************************************************************************

using System;
using Ifs.Fnd;
using Ifs.Fnd.Data;
using Ifs.Fnd.AccessProvider;
using Ifs.Fnd.AccessProvider.PLSQL;

public abstract class PLSQLQueries
{
	private static FndConnection conn;

	public static void Main(string [] pars)
	{
		try
		{
			if(pars.Length != 3)
			{
				Console.WriteLine("Syntax : PLSQLQueries.exe connectstring identity password");
				Console.WriteLine("Press Enter to continue");
				Console.Read();
				return;
			}

			// If you want to have a login dialog, use constructor with only first parameter instead
			conn = new FndConnection(pars[0], pars[1], pars[2]);
			// I set CatchExceptions = false since I'm in a try block
			conn.CatchExceptions = false;

			FndPLSQLSelectCommand cmd = new FndPLSQLSelectCommand(conn, "SELECT * FROM FND_USER WHERE DESCRIPTION LIKE :DESC");
			cmd.BindVariables.Add(new FndBindVariable(FndBindVariableDirection.In, "DESC", new FndTextAttribute("A%")));

			FndDataTable table = cmd.ExecuteReader("FND_USER");

			for(int i = 0; i < table.Rows.Count; i++)
			{
				Console.WriteLine(table.Rows[i]["DESCRIPTION"].ToString());
			}
		}
		catch(FndException err)
		{
			err.Show();
		}
	}
}