Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,3 @@
2006-02-26 Konstantin Triger <kostat@mainsoft.com>
* OracleCommand_CommandType.cs: Port OleDb invocation style to that of OracleClient.

View File

@ -0,0 +1,368 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient;
using MonoTests.System.Data.Utils;
using MonoTests.System.Data.Utils.Data;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_CommandText : GHTBase
{
private Exception exp = null;
private OracleCommand cmd;
const string TEST_CASE_ID = "48341_";
public static void Main()
{
OracleCommand_CommandText tc = new OracleCommand_CommandText();
Exception exp = null;
try
{
tc.BeginTest("OleDBCommandText");
tc.run();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
public void run()
{
SetInConstractor();
SetByProperty();
UseSemiColonAsValue();
UseColonAsValue();
UseQuestionMarkAsValue();
UseExclamationMarkAsValue();
UseApostropheAsValue();
UseCommaAsValue();
UseDotAsValue();
UseAtAsValue();
UseQuoteAsValue();
UseDollarAsValue();
UsePercentAsValue();
UseHatAsValue();
UseAmpersnadAsValue();
UseStartAsValue();
UseParentesesAsValue();
UsePlusAsValue();
UseMinusAsValue();
UseUnderscoreAsValue();
UseSpaceAsValue();
UseEqualAsValue();
UseSlashAsValue();
UseBackSlashAsValue();
UseTildeAsValue();
UseNOTAsValue();
UseORAsValue();
UseANDAsValue();
UseSELECTAsValue();
UseFROMAsValue();
UseWHEREAsValue();
UseINSERTAsValue();
UseINTOAsValue();
UseVALUESAsValue();
UseDELETEAsValue();
UseUPDATEAsValue();
UseEXECAsValue();
UseQueryAsValue();
}
[Test] public void SetByProperty()
{
exp = null;
cmd = new OracleCommand();
cmd.CommandText = "SELECT * FROM Employees";
try
{
BeginCase("CommandText2");
Compare(cmd.CommandText, "SELECT * FROM Employees");
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
[Test] public void SetInConstractor()
{
exp = null;
cmd = new OracleCommand("SELECT * FROM Employees");
try
{
BeginCase("CommandText1");
Compare(cmd.CommandText, "SELECT * FROM Employees");
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
[Test] public void UseSemiColonAsValue()
{
RunValueInColumnTest("T_VARCHAR", ";");
}
[Test] public void UseColonAsValue()
{
RunValueInColumnTest("T_VARCHAR", ":");
}
[Test] public void UseQuestionMarkAsValue()
{
RunValueInColumnTest("T_VARCHAR", "?");
}
[Test] public void UseExclamationMarkAsValue()
{
RunValueInColumnTest("T_VARCHAR", "?");
}
[Test] public void UseApostropheAsValue()
{
RunValueInColumnTest("T_VARCHAR", "'");
}
[Test] public void UseCommaAsValue()
{
RunValueInColumnTest("T_VARCHAR", ",");
}
[Test] public void UseDotAsValue()
{
RunValueInColumnTest("T_VARCHAR", ".");
}
[Test] public void UseAtAsValue()
{
RunValueInColumnTest("T_VARCHAR", "@");
}
[Test] public void UseQuoteAsValue()
{
RunValueInColumnTest("T_VARCHAR", "\"");
}
[Test] public void UseDiezAsValue()
{
RunValueInColumnTest("T_VARCHAR", "#");
}
[Test] public void UseDollarAsValue()
{
RunValueInColumnTest("T_VARCHAR", "$");
}
[Test] public void UsePercentAsValue()
{
RunValueInColumnTest("T_VARCHAR", "%");
}
[Test] public void UseHatAsValue()
{
RunValueInColumnTest("T_VARCHAR", "^");
}
[Test] public void UseAmpersnadAsValue()
{
RunValueInColumnTest("T_VARCHAR", "&");
}
[Test] public void UseStartAsValue()
{
RunValueInColumnTest("T_VARCHAR", "*");
}
[Test] public void UseParentesesAsValue()
{
RunValueInColumnTest("T_VARCHAR", "(");
RunValueInColumnTest("T_VARCHAR", "()");
RunValueInColumnTest("T_VARCHAR", ")");
RunValueInColumnTest("T_VARCHAR", "{");
RunValueInColumnTest("T_VARCHAR", "{}");
RunValueInColumnTest("T_VARCHAR", "}");
RunValueInColumnTest("T_VARCHAR", "[");
RunValueInColumnTest("T_VARCHAR", "[]");
RunValueInColumnTest("T_VARCHAR", "]");
RunValueInColumnTest("T_VARCHAR", "<");
RunValueInColumnTest("T_VARCHAR", "<>");
RunValueInColumnTest("T_VARCHAR", ">");
}
[Test] public void UsePlusAsValue()
{
RunValueInColumnTest("T_VARCHAR", "+");
}
[Test] public void UseMinusAsValue()
{
RunValueInColumnTest("T_VARCHAR", "-");
}
[Test] public void UseUnderscoreAsValue()
{
RunValueInColumnTest("T_VARCHAR", "_");
}
[Test] public void UseSpaceAsValue()
{
RunValueInColumnTest("T_VARCHAR", " ");
}
[Test] public void UseEqualAsValue()
{
RunValueInColumnTest("T_VARCHAR", "=");
}
[Test] public void UseSlashAsValue()
{
RunValueInColumnTest("T_VARCHAR", "\\");
}
[Test] public void UseBackSlashAsValue()
{
RunValueInColumnTest("T_VARCHAR", "/");
}
[Test] public void UseTildeAsValue()
{
RunValueInColumnTest("T_VARCHAR", "~");
}
[Test] public void UseNOTAsValue()
{
RunValueInColumnTest("T_VARCHAR", "NOT");
}
[Test] public void UseORAsValue()
{
RunValueInColumnTest("T_VARCHAR", "OR");
}
[Test] public void UseANDAsValue()
{
RunValueInColumnTest("T_VARCHAR", "AND");
}
[Test] public void UseSELECTAsValue()
{
RunValueInColumnTest("T_VARCHAR", "SELECT");
}
[Test] public void UseFROMAsValue()
{
RunValueInColumnTest("T_VARCHAR", "FROM");
}
[Test] public void UseWHEREAsValue()
{
RunValueInColumnTest("T_VARCHAR", "WHERE");
}
[Test] public void UseINSERTAsValue()
{
RunValueInColumnTest("T_VARCHAR", "INSERT");
}
[Test] public void UseINTOAsValue()
{
RunValueInColumnTest("T_VARCHAR", "INTO");
}
[Test] public void UseVALUESAsValue()
{
RunValueInColumnTest("T_VARCHAR", "VALUES");
}
[Test] public void UseDELETEAsValue()
{
RunValueInColumnTest("T_VARCHAR", "DELETE");
}
[Test] public void UseUPDATEAsValue()
{
RunValueInColumnTest("T_VARCHAR", "UPDATE");
}
[Test] public void UseEXECAsValue()
{
RunValueInColumnTest("T_VARCHAR", "EXEC");
}
[Test] public void UseQueryAsValue()
{
string columnName;
switch (ConnectedDataProvider.GetDbType())
{
case DataBaseServer.SQLServer:
columnName = "T_VARCHAR";
break;
case DataBaseServer.Oracle:
columnName = "T_LONG";
break;
case DataBaseServer.DB2:
columnName = "T_LONGVARCHAR";
break;
default:
columnName = "T_VARCHAR";
break;
}
RunValueInColumnTest(columnName, "SELECT * FROM TYPES_SIMPLE");
}
private void RunValueInColumnTest(string columnToTest, string valueToTest)
{
UnQuotedValueInColumn(columnToTest, valueToTest);
QuotedValueInColumn(columnToTest, valueToTest);
}
private void QuotedValueInColumn(string columnToTest, string valueToTest)
{
ValueInColumn(columnToTest, string.Format("'{0}'", valueToTest));
}
private void UnQuotedValueInColumn(string columnToTest, string valueToTest)
{
ValueInColumn(columnToTest, valueToTest);
}
private void ValueInColumn(string columnToTest, string valueToTest)
{
exp = null;
OracleDataReader rdr = null;
OracleConnection con = null;
DbTypeParametersCollection row = ConnectedDataProvider.GetSimpleDbTypesParameters();
BeginCase(string.Format("Use {0} as value", valueToTest));
string rowId = TEST_CASE_ID + TestCaseNumber.ToString();
try
{
foreach(DbTypeParameter param in row)
{
param.Value = DBNull.Value;
}
row[columnToTest].Value = valueToTest;
Log("rowId:" + rowId + " columnToTest:" + columnToTest + " valueToTest:" + valueToTest);
row.ExecuteInsert(rowId);
row.ExecuteSelectReader(rowId, out rdr, out con);
rdr.Read();
int columnOrdinal = rdr.GetOrdinal(columnToTest);
//this.Log(valueToTest);
Compare(valueToTest, rdr.GetValue(columnOrdinal));
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
if (rdr != null && !rdr.IsClosed)
{
rdr.Close();
}
row.ExecuteDelete(rowId);
if (con != null && con.State != ConnectionState.Closed)
{
con.Close();
}
}
}
}
}

View File

@ -0,0 +1,76 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_CommandTimeout : GHTBase
{
public static void Main()
{
OracleCommand_CommandTimeout tc = new OracleCommand_CommandTimeout();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_CommandTimeout");
tc.run();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
#if !TARGET_JVM
[Category("NotWorking")]
#endif
public void run()
{
OracleCommand cmd = new OracleCommand();
Assert.AreEqual( ((IDbCommand)cmd).CommandTimeout , 30);
((IDbCommand)cmd).CommandTimeout = 12;
Assert.AreEqual(((IDbCommand)cmd).CommandTimeout , 12);
}
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
}
}

View File

@ -0,0 +1,311 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
#if DAAB
using Microsoft.ApplicationBlocks.Data;
#endif
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_CommandType : ADONetTesterClass
{
OracleConnection con;
// transaction is must on PostgreSQL
OracleTransaction tr;
OracleCommand cmd;
OracleDataReader dr = null;
DataBaseServer dbServerType;
[SetUp]
public void SetUp()
{
Exception exp = null;
BeginCase("Setup");
try
{
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
con.Open();
tr = con.BeginTransaction();
cmd = new OracleCommand("", con, tr);
dbServerType = ConnectedDataProvider.GetDbType(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
Assert.AreEqual("Setup", "Setup");
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
[TearDown]
public void TearDown()
{
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
public static void Main()
{
OracleCommand_CommandType tc = new OracleCommand_CommandType();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_CommandType");
tc.SetUp();
tc.run();
tc.TearDown();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
OracleCommand cmd = new OracleCommand();
try
{
BeginCase("CommandType - default");
Assert.AreEqual(cmd.CommandType , CommandType.Text );
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
#if NotWorking
try
{
BeginCase("CommandType - TableDirect");
cmd.CommandType = CommandType.TableDirect;
Assert.AreEqual(cmd.CommandType , CommandType.TableDirect);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
#endif
try
{
BeginCase("CommandType - Text");
cmd.CommandType = CommandType.Text ;
Assert.AreEqual(cmd.CommandType , CommandType.Text);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
#region ---- CommandType.Text using Parameters.Add ----
try
{
BeginCase("CommandType.Text using Parameters.Add");
cmd = new OracleCommand();
cmd.Connection = con;
cmd.Transaction = tr;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "call GH_REFCURSOR3(:IN_LASTNAME, :RCT_Employees)";
OracleParameter param1 = cmd.Parameters.Add("IN_LASTNAME", OracleType.VarChar,20);
param1.Direction = ParameterDirection.Input;
param1.Value = "Yavine";
cmd.Parameters.Add("RCT_Employees", OracleType.Cursor).Direction = ParameterDirection.Output;
#if DAAB
#if !JAVA
if ((dbServerType == DataBaseServer.PostgreSQL))
{
dr = PostgresOracleHelper.OLEDB4ODBCExecuteReader(cmd,true);
}
else
#endif
#endif
{
dr = cmd.ExecuteReader();
}
if (dr.HasRows)
{
dr.Read();
Assert.AreEqual(dr.GetValue(0).ToString(),"1");
Assert.AreEqual(dr.GetString(1),"Yavine");
}
else
Assert.AreEqual("error","HasRows=0");
}
catch(Exception ex)
{
exp = ex;
}
finally
{
if (dr != null)dr.Close();
if (con != null)
{if (con.State == ConnectionState.Open) con.Close();}
EndCase(exp);
exp = null;
}
#endregion
CommandTypeSP_Manual_InOutParameters();
#region ---- ORACLE CommandType.StoredProcedure using DeriveParameters ----
if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.Oracle)
{
try
{
BeginCase("ORACLE CommandType.StoredProcedure using DeriveParameters");
con.Open();
cmd = new OracleCommand();
cmd.Connection = con;
cmd.Transaction = tr;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GH_REFCURSOR3";
OracleCommandBuilder.DeriveParameters(cmd);
cmd.Parameters[0].Value = "Yavine";
//cmd.Parameters.RemoveAt(1); // the ORACLE DAAB trick is to remove the out parameter
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
Assert.AreEqual(dr.GetValue(0).ToString(),"1");
Assert.AreEqual(dr.GetString(1),"Yavine");
}
else
Assert.AreEqual("error","HasRows=0");
}
catch(Exception ex)
{
exp = ex;
}
finally
{
if (dr != null)dr.Close();
if (con != null)
{if (con.State == ConnectionState.Open) con.Close();}
EndCase(exp);
exp = null;
}
}
#endregion
#region CommandType.StoredProcedure in order to repreduce bug 4003
if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.SQLServer)
{
exp = null;
try
{
if (con.State == ConnectionState.Closed) con.Open();
BeginCase("Bug 4003");
OracleCommand cmd4003 = new OracleCommand("[mainsoft].[GH_DUMMY]",con);
cmd4003.CommandType = CommandType.StoredProcedure;
cmd4003.Parameters.Add("@EmployeeIDPrm","1");
cmd4003.ExecuteReader();
}
catch (Exception ex)
{
exp=ex;
}
finally
{
if (con.State == ConnectionState.Open) con.Close();
EndCase(exp);
}
}
#endregion
}
#region ---- CommandType.StoredProcedure manual in out parameters ----
public void CommandTypeSP_Manual_InOutParameters()
{
Exception exp = null;
try
{
BeginCase("CommandType.StoredProcedure manual in out parameters");
if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL)
{
this.Log("CommandType.StoredProcedure manual in out parameters is not tested in oracle.");
return;
}
if (con.State != ConnectionState.Open)
con.Open();
cmd = new OracleCommand("", con, tr);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GH_INOUT1";
//RETURN_VALUE for SQLServer
if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.SQLServer)
{
OracleParameter param0 = cmd.Parameters.Add("@RETURN_VALUE", OracleType.Int32);
param0.Direction = ParameterDirection.ReturnValue;
}
OracleParameter param1 = cmd.Parameters.Add("INPARAM", OracleType.VarChar,20);
param1.Direction = ParameterDirection.Input;
param1.Value = Convert.ToString("dummy");
OracleParameter param2 = cmd.Parameters.Add("OUTPARAM", OracleType.Int32);//VarNumeric);
param2.Direction = ParameterDirection.Output;
int ret = cmd.ExecuteNonQuery();
int intReturn;
intReturn = Convert.ToInt32(cmd.Parameters["OUTPARAM"].Value);
Assert.AreEqual(intReturn,100);
}
catch(Exception ex)
{
exp = ex;
}
finally
{
if (dr != null)dr.Close();
if (con != null)
{if (con.State == ConnectionState.Open) con.Close();}
EndCase(exp);
exp = null;
}
}
#endregion
}
}

View File

@ -0,0 +1,95 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_Connection : GHTBase
{
OracleCommand cmd;
OracleConnection con;
[SetUp]
public void SetUp()
{
cmd = new OracleCommand("SELECT * FROM Employees");
con = new OracleConnection();
}
[TearDown]
public void TearDown()
{
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
public static void Main()
{
OracleCommand_Connection tc = new OracleCommand_Connection();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_Connection");
tc.SetUp();
tc.run();
tc.TearDown();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
try
{
BeginCase("Command Connection - set");
cmd.Connection = con;
Compare(cmd.Connection ,con);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Command Connection - ctor");
cmd = new OracleCommand("",con);
Compare(cmd.Connection ,con);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
}
}

View File

@ -0,0 +1,152 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_Dispose : GHTBase
{
public static void Main()
{
OracleCommand_Dispose tc = new OracleCommand_Dispose();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_Dispose");
tc.run();
}
catch(Exception ex)
{
exp = ex;
}
finally
{
tc.EndTest(exp);
}
}
//problems from Synergy
//Ofer,
//Take a look at #1. Test this to see if we have a problem in dispose. If we do, add a test for this to make sure we catch it in next rounds.
//
//-----Original Message-----
//From: David Teplitchi [mailto:davidt@mainsoft.com]
//Sent: Sunday, March 21, 2004 9:31 AM
//To: //Oved Yavine//
//Subject: 2 problems from Synergy
//Please check those 2 problems reported by Synergy and tell me what do you think.
//1) The following code works in dotnet but doesn//t work in j2ee.
//// Oracle Drivers
//OracleConnection Connect;
//OracleDataReader DbReader;
//OracleCommand DbCommand;
//IDataReader DR;
//string sSQL;
//int iField;
//bool bFound;
//try
//{
//Connect = new OracleConnection("Provider=\"MSDAORA.1\";User
//ID=COM;Password=SQL;Data Source=LLO1;HostName=WS10359;Port=1521");
//Connect.Open();
//sSQL = "SELECT * FROM PRODUCT WHERE PRO_SKU = //SKU_208//";
//DbCommand = new OracleCommand(sSQL, Connect);
//DbReader = DbCommand.ExecuteReader(CommandBehavior.SingleRow);
//DR = DbReader;
//DbCommand.Dispose(); // comment out
////DbCommand = null;
//bFound = DbReader.HasRows;
//DR.Read();
//// Get Column Ordinal
//iField = DR.GetOrdinal("PRO_DESCRIPTION");
//string sDesc = DR.GetString(iField);
//}
//catch(Exception e)
//{
//this.WriteErrorLog(e.Message);
//}
//i have identified the problem as being "DbCommand.Dispose()". If you comment this line out or make it
//"DbCommand = null", then its okay. So this instruction doesnt work the same in both in .net and j2ee.
[Test]
public void run()
{
Exception exp = null;
//OracleConnection con = null;
//this test was added due to a request from Oved:
//this bug occur on all databases (SQL,Oracle,DB2)
OracleCommand DbCommand = null;
OracleConnection Connect = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
Connect.Open();
DbCommand = new OracleCommand("SELECT * FROM Customers", Connect);
OracleDataReader DbReader = DbCommand.ExecuteReader();
BeginCase("Check DataReader.IsClosed - before dispose");
try
{
Compare(DbReader.IsClosed,false); //.Net=false, GH=false
}
catch (Exception ex){exp = ex;}
finally{EndCase(exp);exp = null;}
BeginCase("Check DataReader.IsClosed - after dispose");
try
{
DbCommand.Dispose();
Compare(DbReader.IsClosed,false); //.Net=false, GH=true
}
catch (Exception ex){exp = ex;}
finally{EndCase(exp);exp = null;}
if (Connect.State != ConnectionState.Closed)
Connect.Close();
}
}
}

View File

@ -0,0 +1,222 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_ExecuteNonQuery : GHTBase
{
OracleConnection con;
OracleCommand cmd;
[SetUp]
public void SetUp()
{
Exception exp = null;
BeginCase("Setup");
try
{
//prepare Data
OracleCommand cmdPrepare = new OracleCommand("", new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString));
cmdPrepare.Connection.Open();
cmdPrepare.CommandText = "DELETE FROM Employees WHERE EmployeeID = 99999";
cmdPrepare.ExecuteScalar();
cmdPrepare.Connection.Close();
cmdPrepare.Dispose();
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
cmd = new OracleCommand("", con);
con.Open();
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
[TearDown]
public void TearDown()
{
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
public static void Main()
{
OracleCommand_ExecuteNonQuery tc = new OracleCommand_ExecuteNonQuery();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_ExecuteNonQuery");
tc.SetUp();
tc.run();
tc.TearDown();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
int intRecordsAffected = 0;
try
{
BeginCase("Execute Insert");
cmd.CommandText = "INSERT INTO Employees (EmployeeID,FirstName, LastName) VALUES (99999,'OferXYZ', 'Testing')";
intRecordsAffected = cmd.ExecuteNonQuery();
Compare(intRecordsAffected, 1);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Check insert operation");
cmd.CommandText = "SELECT FirstName FROM Employees WHERE (EmployeeID = 99999)";
string strFirstName = cmd.ExecuteScalar().ToString();
Compare(strFirstName, "OferXYZ");
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Execute Select");
cmd.CommandText = "SELECT EmployeeID FROM Employees WHERE (EmployeeID = 99999)";
intRecordsAffected = cmd.ExecuteNonQuery();
switch (ConnectedDataProvider.GetDbType())
{
case DataBaseServer.PostgreSQL:
// postgres odbc returns 1
#if !JAVA
{
Compare(intRecordsAffected, 1);
}
#else
{
Compare(intRecordsAffected, -1);
}
#endif
break;
default:
Compare(intRecordsAffected, -1);
break;
}
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Execute UPDATE");
cmd.CommandText = "UPDATE Employees SET FirstName = 'OferABC', LastName = 'TestXYZ' WHERE (EmployeeID = 99999)";
intRecordsAffected = cmd.ExecuteNonQuery();
Compare(intRecordsAffected, 1);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Check Update operation");
cmd.CommandText = "SELECT FirstName FROM Employees WHERE (EmployeeID = 99999)";
string strFirstName = cmd.ExecuteScalar().ToString();
Compare(strFirstName, "OferABC");
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Execute UPDATE");
cmd.CommandText = "DELETE FROM Employees WHERE (EmployeeID = 99999)";
intRecordsAffected = cmd.ExecuteNonQuery();
Compare(intRecordsAffected, 1);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Check Delete operation");
cmd.CommandText = "SELECT FirstName FROM Employees WHERE (EmployeeID = 99999)";
object obj = cmd.ExecuteScalar();
Compare(obj==null, true);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Check OracleException - update with bad value");
cmd.CommandText = "UPDATE Employees SET BirthDate = 'bad value' WHERE (EmployeeID = 1)";
try
{
cmd.ExecuteNonQuery();
}
catch (OracleException ex)
{
exp = ex;
}
Compare(exp.GetType().FullName, typeof(OracleException).FullName);
exp=null;
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Check OracleException - missing EmployeeID");
cmd.CommandText = "INSERT INTO Employees (FirstName, BirthDate) VALUES ('Dado', 'Ben David')";
try
{
cmd.ExecuteNonQuery();
}
catch (OracleException ex)
{
exp = ex;
}
Compare(exp.GetType().FullName, typeof(OracleException).FullName);
exp=null;
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
}
}

View File

@ -0,0 +1,423 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
#if DAAB
using Microsoft.ApplicationBlocks;
#endif
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_ExecuteReader : ADONetTesterClass
{
OracleConnection con;
OracleCommand cmd;
[SetUp]
public void SetUp()
{
Exception exp = null;
BeginCase("Setup");
try
{
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
cmd = new OracleCommand("", con);
con.Open();
this.Pass("Setup.");
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
[TearDown]
public void TearDown()
{
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
public static void Main()
{
OracleCommand_ExecuteReader tc = new OracleCommand_ExecuteReader();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_ExecuteReader");
tc.SetUp();
tc.run();
tc.TearDown();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
bool RecordsExists = false;
OracleDataReader rdr =null;
// testBug3965();
// TestMultipleResultsets();
// TestCompoundVariable();
cmd.CommandText = "Select FirstName,City From Employees";
if (con.State != ConnectionState.Open)
{
con.Open();
}
try
{
BeginCase("check reader is null");
rdr = cmd.ExecuteReader();
Compare(rdr==null, false);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
}
try
{
BeginCase("check reader.read");
rdr = cmd.ExecuteReader();
RecordsExists = rdr.Read();
Compare(RecordsExists ,true);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
}
try
{
BeginCase("execute reader again ");
rdr = cmd.ExecuteReader();
Compare(rdr==null, false);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
}
try
{
BeginCase("Test compound SQL statement");
//Build a compund SQL command.
string[] sqlStatements = new string[] {
"INSERT INTO Categories (CategoryName, Description) VALUES('__TEST_RECORD__', 'Inserted')",
"UPDATE Categories SET Description='Updated' WHERE CategoryName='__TEST_RECORD__'",
"DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'" ,
};
cmd.CommandText = CreateCompundSqlStatement(sqlStatements, ConnectedDataProvider.GetDbType());
rdr = cmd.ExecuteReader();
Compare(rdr.Read(), false);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
}
if (ConnectedDataProvider.GetDbType() != DataBaseServer.Oracle)
{
try
{
BeginCase("Check that in a compound SQL statement, resultsets are returned only for SELECT statements. (bug #3358)");
//prepare db:
OracleCommand prepare = new OracleCommand("DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'", con);
prepare.ExecuteNonQuery();
//Test body
int resultSetCount ;
//Build a compund SQL command that contains only one select statement.
string[] sqlStatements = new string[] {
"INSERT INTO Categories (CategoryName, Description) VALUES('__TEST_RECORD__', 'Inserted')",
"UPDATE Categories SET Description='Updated' WHERE CategoryName='__TEST_RECORD__'",
"DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'" ,
"SELECT * FROM Categories "
};
string insertCmdTxt = CreateCompundSqlStatement(sqlStatements, ConnectedDataProvider.GetDbType());
//this.Log(insertCmdTxt);
OracleCommand InsertCmd = new OracleCommand(insertCmdTxt, con);
rdr = InsertCmd.ExecuteReader();
//Count the number of result sets.
resultSetCount = 0;
do
{
resultSetCount++;
}while (rdr.NextResult());
//Test that there is only one result set.
Compare(resultSetCount, 1);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
//cleanup db:
OracleCommand cleanup = new OracleCommand("DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'", con);
cleanup.ExecuteNonQuery();
}
}
}
//Create the compund sql statement according to the dbserver.
private string CreateCompundSqlStatement(string[] sqlStatements, DataBaseServer dbServer)
{
string beginStatement;
string endStatement;
string commandDelimiter;
GetDBSpecificSyntax(dbServer, out beginStatement, out endStatement, out commandDelimiter);
StringBuilder cmdBuilder = new StringBuilder();
cmdBuilder.Append(beginStatement);
cmdBuilder.Append(" ");
foreach (string statement in sqlStatements)
{
cmdBuilder.Append(statement);
cmdBuilder.Append(commandDelimiter);
cmdBuilder.Append(" ");
}
cmdBuilder.Append(endStatement);
return cmdBuilder.ToString();
}
private void GetDBSpecificSyntax(DataBaseServer dbServer, out string beginStatement, out string endStatement, out string commandDelimiter)
{
switch (dbServer)
{
case DataBaseServer.SQLServer:
case DataBaseServer.PostgreSQL:
beginStatement = "";
endStatement = "";
commandDelimiter = ";";
break;
case DataBaseServer.Sybase:
beginStatement = "BEGIN";
endStatement = "END";
commandDelimiter = "";
break;
case DataBaseServer.Oracle:
beginStatement = "BEGIN";
endStatement = "END;";
commandDelimiter = ";";
break;
case DataBaseServer.DB2:
beginStatement = "BEGIN ATOMIC";
endStatement = "END";
commandDelimiter = ";";
break;
default:
this.Fail("Unknown DataBaseServer type");
throw new ApplicationException("Unknown DataBaseServer type");
}
}
[Test]
public void TestMultipleResultsets()
{
#if !JAVA
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.Oracle)
{
//In .NET there is a bug when calling a SP with multiple REFCURSORS, the workaround is to use OracleClient and not Oracle.
//In GH we are not bug complient in this issue, because there is no workaround (We do not support the OracleClient namespace.
this.Log("Not testing multi result set Oracle on .NET");
return;
}
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
{
// fail to work on .NET OLEDB
//reader = Microsoft.ApplicationBlocks.Data.PostgresOracleHelper.ADOExecuteReader(cmd1);
this.Log("Not testing PostgreSQL CommandType.StoredProcedure which return SETOF");
return;
}
#endif
Exception exp = null;
BeginCase("Test multi result set from stored procedure");
OracleDataReader reader = null;
OracleTransaction tr = null;
try
{
//Check SP with the structre : insert Select + update Select + delete Select
if (con.State != ConnectionState.Open)
{
con.Open();
}
// transaction use was add for PostgreSQL
tr = con.BeginTransaction();
OracleCommand cmd1 = new OracleCommand("GHSP_TYPES_SIMPLE_4", con, tr);
cmd1.CommandType = CommandType.StoredProcedure;
OracleParameter param = new OracleParameter();
param.ParameterName = "ID1";
param.Value = string.Format("13268_{0}", this.TestCaseNumber);
param.OracleType = OracleType.VarChar;
cmd1.Parameters.Add(param);
cmd1.Parameters.Add(new OracleParameter("RESULT", OracleType.Cursor)).Direction = ParameterDirection.Output;
cmd1.Parameters.Add(new OracleParameter("RESULT1", OracleType.Cursor)).Direction = ParameterDirection.Output;
cmd1.Parameters.Add(new OracleParameter("RESULT2", OracleType.Cursor)).Direction = ParameterDirection.Output;
reader = cmd1.ExecuteReader();
//Count the number of result sets.
int resultSetCount = 0;
//Count the number of the records
int recordCounter=0;
do
{
//this.Log(string.Format("resultSetCount:{0}",resultSetCount));
while (reader.Read())
{
recordCounter++;
}
//this.Log(string.Format("recordCounter:{0}",recordCounter));
if (resultSetCount != 2)
{
Compare(recordCounter,1); //Insert + update
}
else
{
Compare(recordCounter,0); //Delete
}
recordCounter=0;
resultSetCount++;
}while (reader.NextResult());
Compare(resultSetCount,3);
}
catch (Exception ex)
{
exp=ex;
}
finally
{
EndCase(exp);
if (reader != null) reader.Close();
tr.Commit();
con.Close();
}
}
[Test]
public void TestCompoundVariable()
{
OracleDataReader rdr = null;
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
{
this.Log("not testing PostgreSQL");
return;
}
Exception exp = null;
try
{
BeginCase("Check sql statement that declares a local variable and uses it.");
if (con.State != ConnectionState.Open)
{
con.Open();
}
string sqlTxt = "";
switch (ConnectedDataProvider.GetDbType(cmd.Connection))
{
case DataBaseServer.SQLServer:
sqlTxt = "declare @var int; select @var=1;";
break;
case DataBaseServer.Sybase:
sqlTxt = "declare @var int select @var=1";
break;
case DataBaseServer.Oracle:
sqlTxt = "declare var int;begin var:=1;end;";
break;
case DataBaseServer.DB2:
sqlTxt = "begin atomic declare var integer; set var = 1; end";
break;
case DataBaseServer.PostgreSQL:
// we don't know how the heck to do this in PostgreSQL
sqlTxt = "";
break;
default:
throw new ApplicationException(string.Format("GHT: Unknown DataBaseServer '{0}'", ConnectedDataProvider.GetDbType(cmd.Connection)));
}
cmd.CommandText = sqlTxt;
rdr = cmd.ExecuteReader();
Compare(rdr.Read(), false);
}
catch(Exception ex){exp = ex;}
finally
{
if (rdr != null) rdr.Close();
EndCase(exp);
exp = null;
}
}
}
}

View File

@ -0,0 +1,129 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_ExecuteScalar : GHTBase
{
OracleConnection con;
OracleCommand cmd;
[SetUp]
public void SetUp()
{
Exception exp = null;
BeginCase("Setup");
try
{
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
con.Open();
//prepare Data
OracleCommand cmdPrepare = new OracleCommand("", con);
cmdPrepare.CommandText = "DELETE FROM Employees WHERE EmployeeID = 99999";
cmdPrepare.ExecuteNonQuery();
cmdPrepare.CommandText = "INSERT INTO Employees (EmployeeID, FirstName, LastName) VALUES (99999,'OferXYZ', 'Testing')";
cmdPrepare.ExecuteNonQuery();
cmdPrepare.Dispose();
cmd = new OracleCommand("", con);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
[TearDown]
public void TearDown()
{
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
public static void Main()
{
OracleCommand_ExecuteScalar tc = new OracleCommand_ExecuteScalar();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_ExecuteScalar");
tc.SetUp();
tc.run();
tc.TearDown();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
object objResult = null;
cmd.CommandText="Select FirstName,City From Employees Where EmployeeID=-1";
try
{
BeginCase("Execute Scalar");
objResult = cmd.ExecuteScalar();
Compare(objResult==null,true);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
cmd.CommandText="Select FirstName,City From Employees Where EmployeeID=99999 ";
try
{
BeginCase("Execute Scalar");
objResult = cmd.ExecuteScalar();
Compare(objResult.ToString(), "OferXYZ");
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("Execute Scalar again");
objResult = cmd.ExecuteScalar();
Compare(objResult.ToString(), "OferXYZ");
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
}
}

View File

@ -0,0 +1,113 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_New : GHTBase
{
public static void Main()
{
OracleCommand_New tc = new OracleCommand_New();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_New");
tc.run();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
OracleCommand cmd = null;
OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString );
OracleTransaction tran;
try
{
BeginCase("OracleCommand New");
cmd = new OracleCommand();
Compare(cmd==null, false);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("OracleCommand - new CommandText");
cmd = new OracleCommand("Select * from Table");
Compare(cmd==null, false);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("OracleCommand CommandText");
Compare(cmd.CommandText , "Select * from Table");
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("OracleCommand - Connection");
cmd = new OracleCommand("Select * from Table",con);
Compare(cmd.Connection ,con);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
con.Open();
tran = con.BeginTransaction();
try
{
BeginCase("OracleCommand - Transaction");
cmd = new OracleCommand("Select * from Table",con,tran);
Compare(cmd.Transaction ,tran);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
if (con.State == ConnectionState.Open) con.Close();
}
}
}

View File

@ -0,0 +1,224 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using MonoTests.System.Data.Utils.Data;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_Parameters : ADONetTesterClass
{
//Used to test GUID.
private const string TEST_GUID_STRING = "239A3C5E-8D41-11D1-B675-00C04FA3C554";
private Exception exp;
public static void Main()
{
OracleCommand_Parameters tc = new OracleCommand_Parameters();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_Parameters");
tc.run();
}
catch(Exception ex)
{
exp = ex;
}
finally
{
tc.EndTest(exp);
}
}
[Test]
public void run()
{
#region Simple Tests
//string str="";
string sql;
OracleConnection con = null;
sql = "UPDATE Employees SET Region = :Region, TitleOfCourtesy = :TitleOfCourtesy WHERE EmployeeID=1";
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
//not testing with DB2 provider
if (ConnectedDataProvider.GetDbType(con) != DataBaseServer.DB2)
{
OracleCommand cmd = new OracleCommand(sql, con);
cmd.Parameters.Add(new OracleParameter(":Region", OracleType.VarChar));
cmd.Parameters.Add(new OracleParameter(":TitleOfCourtesy", OracleType.VarChar));
con.Open();
cmd.Parameters[":Region"].Value = "WA";
cmd.Parameters[":TitleOfCourtesy"].Value = "Mr";
//return the number of rows affected
int i = cmd.ExecuteNonQuery();
try
{
BeginCase("Check row count");
Compare(i, 1);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
if (con.State == ConnectionState.Open) con.Close();
#endregion
#region Test Parameter Types
#region General
TypesSubTests(ConnectedDataProvider.GetSimpleDbTypesParameters());
TypesSubTests(ConnectedDataProvider.GetExtendedDbTypesParameters());
#endregion
#endregion
}
private void TypesSubTests(DbTypeParametersCollection typesToTest)
{
DbTypeParametersCollection currentlyTested = new DbTypeParametersCollection(typesToTest.TableName);
int affectedRows;
string rowId = string.Empty;
foreach (DbTypeParameter currentParamType in typesToTest)
{
try
{
BeginCase("Test INSERT with parameter of type: " + currentParamType.DbTypeName);
rowId = string.Format("13282_{0}", this.TestCaseNumber);
currentlyTested.Clear();
currentlyTested.Add(currentParamType);
affectedRows = currentlyTested.ExecuteInsert(rowId);
Compare(affectedRows, 1);
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
exp = null;
currentlyTested.ExecuteDelete(rowId);
}
}
}
//Test insertion of a GUID parameter on MSSQLServer.
[Test]
public void DoTestGUIDOnMSSQLServer()
{
if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
return;
DbTypeParametersCollection guidRow = new DbTypeParametersCollection(ConnectedDataProvider.SPECIFIC_TYPES_TABLE_NAME);
guidRow.Add("UNIQUEIDENTIFIER", new Guid(TEST_GUID_STRING));
TypesSubTests(guidRow);
}
//Test problems specific to the TIME type on DB2.
[Test]
public void DoTestTimeOnDB2()
{
if (ConnectedDataProvider.GetDbType() != DataBaseServer.DB2)
return;
OracleConnection conn = new OracleConnection(ConnectedDataProvider.ConnectionString);
string rowId = string .Empty;
try
{
BeginCase("Test INSERT to TIME column using only TimeOfDate part of DateTime");
rowId = "13282_" + this.TestCaseNumber.ToString();
OracleCommand cmd = new OracleCommand();
conn.Open();
cmd.Connection = conn;
cmd.CommandText = string.Format("INSERT INTO {0} (ID, T_TIME) VALUES ('{1}', ?)",ConnectedDataProvider.EXTENDED_TYPES_TABLE_NAME ,rowId);
cmd.Parameters.Add("time", DateTime.Now.TimeOfDay);
int affectedRows;
affectedRows = cmd.ExecuteNonQuery();
Compare(affectedRows, 1);
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
exp = null;
DbTypeParametersCollection.ExecuteDelete(ConnectedDataProvider.EXTENDED_TYPES_TABLE_NAME, rowId);
conn.Close();
}
}
[Test]
#if JAVA
[Category("NotWorking")]
#endif
public void DoTestTimeOnDB2_bug3391()
{
if (ConnectedDataProvider.GetDbType() != DataBaseServer.DB2)
return;
OracleConnection conn = new OracleConnection(ConnectedDataProvider.ConnectionString);
string rowId = string .Empty;
try {
BeginCase("Test INSERT to TIME column using all of the DateTime");
rowId = "13282_" + this.TestCaseNumber.ToString();
OracleCommand cmd = new OracleCommand();
conn.Open();
cmd.Connection = conn;
cmd.CommandText = string.Format("INSERT INTO {0} (ID, T_TIME) VALUES ('{1}', ?)",ConnectedDataProvider.EXTENDED_TYPES_TABLE_NAME ,rowId);
cmd.Parameters.Add("time", DateTime.Now);
try {
cmd.ExecuteNonQuery();
ExpectedExceptionNotCaught("System.OracleException");
}
catch (OracleException ex) {
ExpectedExceptionCaught(ex);
}
}
catch (Exception ex) {
exp = ex;
}
finally {
EndCase(exp);
exp = null;
DbTypeParametersCollection.ExecuteDelete(ConnectedDataProvider.EXTENDED_TYPES_TABLE_NAME, rowId);
conn.Close();
}
}
}
}

View File

@ -0,0 +1,145 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class OracleCommand_Prepare : GHTBase
{
public static void Main()
{
OracleCommand_Prepare tc = new OracleCommand_Prepare();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_Prepare");
tc.run();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
int intRecordsAffected = 0;
string sql = "Update Shippers Set CompanyName=:CompName Where ShipperID = 2";
OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
OracleCommand cmd = new OracleCommand("", con);
con.Open();
//get expected result
cmd.CommandText = "select count(*) from Shippers where ShipperID = 2";
int ExpectedRows = int.Parse(cmd.ExecuteScalar().ToString());
cmd.CommandText = sql;
//Currently not running on DB2: .Net-Failed, GH:Pass
//if (con.Provider.IndexOf("IBMDADB2") >= 0) return ;
cmd.Parameters.Add(new OracleParameter());
cmd.Parameters[0].ParameterName = "CompName";
cmd.Parameters[0].OracleType = OracleType.VarChar; //System.InvalidOperationException:
cmd.Parameters[0].Size = 20; //System.InvalidOperationException
cmd.Parameters[0].SourceColumn = "CompanyName";
cmd.Parameters[0].Value = "Comp1";
try
{
BeginCase("Prepare Exception - missing OracleType");
cmd.Prepare();
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
cmd.Parameters[0].OracleType = OracleType.VarChar;
// try
// {
// BeginCase("Prepare Exception - missing Size");
// try
// {
// cmd.Parameters[0].Size = 0;
// cmd.Prepare();
// }
// catch (Exception ex) {exp = ex;}
// Compare(exp.GetType().FullName, typeof(InvalidOperationException).FullName );
// exp=null;
// }
// catch(Exception ex){exp = ex;}
// finally{EndCase(exp); exp = null;}
// cmd.Parameters[0].Size = 20;
try
{
BeginCase("Prepare Exception - missing Size");
try
{
con.Close();
cmd.Prepare();
}
catch (Exception ex) {exp = ex;}
Compare(exp.GetType().FullName, typeof(InvalidOperationException).FullName );
exp=null;
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
con.Open();
try
{
BeginCase("ExecuteNonQuery first time");
intRecordsAffected = cmd.ExecuteNonQuery();
Compare(intRecordsAffected , ExpectedRows);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("ExecuteNonQuery second time, chage value");
cmd.Parameters[0].Value = "Comp2";
intRecordsAffected = cmd.ExecuteNonQuery();
Compare(intRecordsAffected , ExpectedRows);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
if (con.State == ConnectionState.Open) con.Close();
}
}
}

View File

@ -0,0 +1,83 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Data;
using System.Data.OracleClient ;
using MonoTests.System.Data.Utils;
using NUnit.Framework;
namespace MonoTests.System.Data.OracleClient
{
[TestFixture]
public class TestId13266 : GHTBase
{
public static void Main()
{
TestId13266 tc = new TestId13266();
Exception exp = null;
try
{
tc.BeginTest("OracleCommand_Transaction");
tc.run();
}
catch(Exception ex){exp = ex;}
finally {tc.EndTest(exp);}
}
[Test]
public void run()
{
Exception exp = null;
OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
con.Open();
OracleTransaction txn = con.BeginTransaction();
OracleCommand cmd = new OracleCommand("Select * From Employees", con);
try
{
BeginCase("check Transaction property - default");
Compare(cmd.Transaction==null , true);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
cmd.Transaction = txn;
try
{
BeginCase("check Transaction property");
Compare(cmd.Transaction , txn);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
if (con.State == ConnectionState.Open) con.Close();
}
}
}