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,4 @@
2006-10-17 Leszek Ciesielski <skolima@gmail.com>
* OciDefineHandleTest.cs: regression for bugs 79004 and 78840
(trimming of unicode strings)

View File

@@ -0,0 +1,114 @@
//
// OracleParameterTest.cs -
// NUnit Test Cases for OciDefineHandle
//
// Author:
// Leszek Ciesielski <skolima@gmail.com>
//
// Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
//
// 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 NUnit.Framework;
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.Data.OracleClient;
using System.Data;
using System;
namespace MonoTests.System.Data.OracleClient {
[TestFixture]
public class OciDefineHandleTest {
String connection_string;
OracleConnection connection;
OracleCommand command;
// test string
string test_value = " sim\u4FF5ply\u65E5 tri\u672Cm te\u4F00st ";
string test_value2 = " simply \u672Ctrim\u4F00 test in\u65E5 query \u4FF5 ";
[TestFixtureSetUp]
public void FixtureSetUp ()
{
connection_string = ConfigurationSettings.AppSettings.Get ("ConnectionString");
if(connection_string == null)
Assert.Ignore ("Please consult README.tests.");
}
[SetUp]
public void SetUp ()
{
connection = new OracleConnection (connection_string);
connection.Open ();
using (command = connection.CreateCommand ()) {
// create the tables
command.CommandText =
"create table utf8test (id number(10), text nvarchar2(64), text2 nvarchar2(64) )";
command.ExecuteNonQuery ();
}
}
[TearDown]
public void TearDown ()
{
using (command = connection.CreateCommand ()) {
command.CommandText = "drop table utf8test";
command.ExecuteNonQuery ();
}
connection.Close ();
connection.Dispose ();
}
[Test] // regression for bug #79004
public void TrimsUnicodeStringsTest ()
{
using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
// insert test values
command.CommandText =
"insert into utf8test (id,text,text2) values (:id,:txt,'" + test_value2 + "')";
command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
command.Parameters.Add( new OracleParameter ("TXT", OracleType.NVarChar));
command.Parameters ["ID"].Value = 101;
command.Parameters ["TXT"].Value = test_value;
command.ExecuteNonQuery ();
// read test values
command.CommandText =
"select text,text2 from utf8test where id = 101";
command.Parameters.Clear ();
using (OracleDataReader reader = command.ExecuteReader ()) {
if (reader.Read ()) {
Assert.AreEqual (test_value, reader.GetString (0), "Passed through bind value mismatched");
Assert.AreEqual (test_value2, reader.GetString (1), "Directly passed value mismatched");
}
else {
Assert.Fail ("Expected records not found.");
}
}
}
}
}
}

View File

@@ -0,0 +1,4 @@
2006-10-17 Leszek Ciesielski <skolima@gmail.com>
* ConnectedDataProvider.cs: Connected test are ignored when
no configuration is found.

View File

@@ -0,0 +1,363 @@
// Authors:
// Rafael Mizrahi <rafim@mainsoft.com>
// Erez Lotan <erezl@mainsoft.com>
// Oren Gurfinkel <oreng@mainsoft.com>
// Ofer Borstein
//
// Copyright (c) 2004 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 System.IO;
using System.Collections;
using Sys = System;
using MonoTests.System.Data.Utils.Data;
// Provide All Data required by the diffderent tests e.g.DataTable, DataRow ...
namespace MonoTests.System.Data.Utils {
/// <summary>
/// Types of Database Servers that tests can be run on.
/// </summary>
public enum DataBaseServer {
SQLServer,
Oracle,
DB2,
Sybase,
PostgreSQL,
Unknown
}
public class ConnectedDataProvider {
#region Private
//A string containing all printable charachters.
private const string SAMPLE_STRING = "abcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_+-=[]\\|;:,./<>? ";
#endregion
#region Public
/// <summary>
/// Name of the table in the database, that contain columns of simple types.
/// </summary>
public const string SIMPLE_TYPES_TABLE_NAME = "TYPES_SIMPLE";
/// <summary>
/// Name of the table in the database, that contain columns of extended types.
/// </summary>
public const string EXTENDED_TYPES_TABLE_NAME = "TYPES_EXTENDED";
/// <summary>
/// Name of the table in the database, that contain columns of DB specific types.
/// </summary>
public const string SPECIFIC_TYPES_TABLE_NAME = "TYPES_SPECIFIC";
#endregion
public static string ConnectionString {
get {
string connection_string = Sys.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
if(connection_string == null)
NUnit.Framework.Assert.Ignore ("Please consult README.tests.");
return connection_string;
}
}
// SQLClient does not allow to use the Provider token
// since Provider is always the first parameter(in GHT framework),
// we trim it.
public static string ConnectionStringSQLClient {
get {
return ConnectionString.Substring(ConnectionString.IndexOf(";"));
}
}
/// <summary>
/// Resolves the type of DB server specified by the "ADOConString.txt" file.
/// </summary>
/// <returns>The type of DB server specified by the "ADOConString.txt" file.</returns>
public static DataBaseServer GetDbType() {
return ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString);
}
/// <summary>
/// Resolves the type of DB server that the specified connection refers.
/// </summary>
/// <param name="OleCon">A valid connection object to a DataBase.</param>
/// <returns>The type of DB server that the specified connection refers to.</returns>
public static DataBaseServer GetDbType(Sys.Data.OracleClient.OracleConnection OleCon) {
return ConnectedDataProvider.GetDbType(OleCon.ConnectionString);
}
/// <summary>
/// Resolves the type of DB server that the specified connection string refers.
/// </summary>
/// <param name="ConnectionString">A valid connection string to a DataBase server.</param>
/// <returns>The type of DB server that the specified connection string refers to.</returns>
public static DataBaseServer GetDbType(string ConnectionString) {
return DataBaseServer.Oracle;
}
/// <summary>
/// Creates a DbTypeParametersCollection with default types and data for the TYPES_SIMPLE table.
/// </summary>
/// <returns>The initialized DbTypeParametersCollection</returns>
public static DbTypeParametersCollection GetSimpleDbTypesParameters() {
DbTypeParametersCollection row = new DbTypeParametersCollection(SIMPLE_TYPES_TABLE_NAME);
switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
#region SQLServer
case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
row.Add("bit", true, 1);
row.Add("tinyint", (byte)25, 1);
row.Add("smallint", (Int16)77, 2);
row.Add("int", (Int32)2525, 4);
row.Add("bigint", (Int64)25251414, 8);
row.Add("decimal", 10M, 9); //(Decimal)10
row.Add("numeric", 123123M, 9); //(Decimal)123123
row.Add("float", 17.1414257, 8);
row.Add("real", (float)0.71425, 4);
row.Add("char", "abcdefghij", 10);
row.Add("nchar", "klmnopqrst", 10);
row.Add("varchar", "qwertasdfg", 50);
row.Add("nvarchar", "qwertasdfg", 50);
break;
#endregion
#region Sybase
case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
//row.Add("BIT", true, 1);
row.Add("TINYINT", (byte)25, 1);
row.Add("SMALLINT", (Int16)77, 2);
row.Add("INT", (Int32)2525, 4);
//row.Add("BIGINT", (Int64)25251414, 8);
row.Add("DECIMAL", 10M, 9); //(Decimal)10
row.Add("NUMERIC", 123123M, 9); //(Decimal)123123
row.Add("FLOAT", 17.1414257, 8);
row.Add("REAL", (float)0.71425, 4);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "klmnopqrst", 10);
row.Add("VARCHAR", "qwertasdfg", 50);
row.Add("NVARCHAR", "qwertasdfg", 50);
break;
#endregion
#region ORACLE
case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
row.Add("NUMBER", 21M, 22); //(Decimal)21
row.Add("LONG", SAMPLE_STRING, 2147483647); //Default data type in .NET is system.String.
row.Add("FLOAT", 1.234, 22);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("NVARCHAR", "qwertasdfg", 20);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "abcdefghij", 10);
break;
#endregion
#region DB2
case MonoTests.System.Data.Utils.DataBaseServer.DB2:
row.Add("SMALLINT", (Int16)2, 2);
row.Add("INTEGER", 7777, 4);
row.Add("BIGINT", (Int64)21767267, 8);
row.Add("DECIMAL", 123M, 9); //(decimal)123
row.Add("REAL", (float)0.7, 4);
row.Add("DOUBLE", 1.7, 8);
row.Add("CHARACTER", "abcdefghij", 10);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("LONGVARCHAR", SAMPLE_STRING, 32000);
break;
#endregion
#region PostgreSQL
case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
// PostgreSQL ODBC Type BOOL returns String with value "1"
// so we don't run it on .NET
// if (!GHTEnvironment.IsJavaRunTime())
// {
// row.Add("BOOL", "1", 1);
// }
// else
// {
row.Add("BOOL", (bool)true, 1);
// }
row.Add("INT2", (Int16)21, 2);
row.Add("INT4", (Int32)30000, 4);
row.Add("INT8", (Int64)30001, 8);
row.Add("NUMERIC", (decimal)100000M, 10); //(decimal)100000
row.Add("FLOAT4", (Single)7.23157, 4);
row.Add("FLOAT8", (Double)7.123456, 8);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "klmnopqrst", 10);
break;
#endregion
}
return row;
}
/// <summary>
/// Creates a DbTypeParametersCollection with default types and data for the TYPES_EXTENDED table.
/// </summary>
/// <returns>The initialized DbTypeParametersCollection</returns>
public static DbTypeParametersCollection GetExtendedDbTypesParameters() {
DbTypeParametersCollection row = new DbTypeParametersCollection(EXTENDED_TYPES_TABLE_NAME);
switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
#region SQLServer
case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
row.Add("text", SAMPLE_STRING, 16);
row.Add("ntext", SAMPLE_STRING, 16);
row.Add("binary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("varbinary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("datetime", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
row.Add("smalldatetime", new DateTime(2004, 8, 9, 20, 30, 00), 4);
break;
#endregion
#region Sybase
case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
row.Add("TEXT", SAMPLE_STRING, 16);
//There is probably a bug in the jdbc driver , we've tried to insert this string using
//sybase command tool and it gave the same result (3850)
row.Add("NTEXT", SAMPLE_STRING.Trim() , 16);
row.Add("BINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("VARBINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("DATETIME", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
row.Add("SMALLDATETIME", new DateTime(2004, 8, 9, 20, 30, 00), 4);
break;
#endregion
#region ORACLE
case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
row.Add("RAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 10);
row.Add("LONGRAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
}, 100);
row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15), 7);
// The .NET Framework provides support for Oracle LOBs in the OracleClient namespace, but not in the Oracle namespace.
// Since Visual MainWin does not support the OracleClient namespace, a partial support for this important feature is provided in the Oracle namespace.
// See ms-help://MS.VSCC.2003/VMW.GH.1033/ghdoc/vmwdoc_ADONET_data_access_limitations_51.htm
#if TARGET_JVM
row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
}, 4000);
row.Add("CLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
, 4000);
row.Add("NCLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
, 4000);
#endif
break;
#endregion
#region DB2
case MonoTests.System.Data.Utils.DataBaseServer.DB2:
row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15, 500).Date);
row.Add("TIME", new TimeSpan(20, 30, 15));
row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500));
row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
});
row.Add("CLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
);
row.Add("DBCLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
);
break;
#endregion
#region PostgreSQL
case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
row.Add("BYTEA", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("DATE", new DateTime(2004, 8, 9));
row.Add("TEXT", "abcdefg", 16);
row.Add("TIME", new Sys.TimeSpan(02,02,02));
row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
break;
#endregion
}
return row;
}
}
}

View File

@@ -0,0 +1,293 @@
//
// 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;
namespace MonoTests.System.Data.Utils.Data
{
/// <summary>
/// Represents a parameter type for use in tests of System.Data.
/// </summary>
public class DbTypeParameter
{
#region Members
//Name of the Database type of this parameter.
private string m_sDbTypeName;
//Value of this parameter.
private object m_oValue;
//Size of this parameter.
private int m_iSize;
//Indicates wheather the size of this DbTypeParameter was initialized.
private bool m_bIsSizeSet = false;
#endregion
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public DbTypeParameter()
{
}
/// <summary>
/// Constructor, Initializes the DbTypeParameter's properties according to specified values.
/// </summary>
/// <param name="a_sTypeName">Specifies the initial parameter type Name for the DbTypeParameter.</param>
/// <param name="a_oValue">Specifies the initial value for the DbTypeParameter.</param>
public DbTypeParameter(string a_sTypeName, object a_oValue)
{
DbTypeName = a_sTypeName;
Value = a_oValue;
}
/// <summary>
/// Constructor, Initializes the DbTypeParameter's properties according to specified values.
/// </summary>
/// <param name="a_sTypeName">Specifies the initial parameter type Name for the DbTypeParameter.</param>
/// <param name="a_oValue">Specifies the initial value for the DbTypeParameter.</param>
/// <param name="a_iSize">Specifies the initial size for the DbTypeParameter.</param>
public DbTypeParameter(string a_sTypeName, object a_oValue, int a_iSize)
{
DbTypeName = a_sTypeName;
Value = a_oValue;
Size = a_iSize;
}
#endregion
#region Properties
public string DbColumnName
{
get
{
return string.Format("T_{0}", m_sDbTypeName);
}
}
public string ParameterName
{
get
{
return String.Format(":T_{0}", m_sDbTypeName);
}
}
public string DbTypeName
{
get
{
return m_sDbTypeName;
}
set
{
m_sDbTypeName = value;
}
}
public object Value
{
get
{
return m_oValue;
}
set
{
m_oValue = value;
}
}
public int Size
{
get
{
if (IsSizeSet)
{
return m_iSize;
}
else
{
throw new InvalidOperationException("DbTypeParameter size was not set.");
}
}
set
{
m_iSize = value;
m_bIsSizeSet = true;
}
}
public bool IsSizeSet
{
get
{
return m_bIsSizeSet;
}
}
public DbType DbType
{
get
{
return GetDefaultDbType(DbTypeName);
}
}
#endregion
#region Methods
public static DbType GetDefaultDbType(string dbTypeName)
{
switch (dbTypeName.ToUpper())
{
case "BIT": //SQLServer.
return DbType.Boolean;
case "TINYINT": //SQLServer.
return DbType.Byte;
case "SMALLINT": //SQLServer & DB2.
return DbType.Int16;
case "INT": //SQLServer.
return DbType.Int32;
case "INTEGER": //DB2
return DbType.Int32;
case "BIGINT": //MSSQLServer &DB2
return DbType.Int64;
case "NUMERIC": //MSSQLServer.
return DbType.Decimal;
case "NUMBER": //Oracle.
return DbType.VarNumeric;
case "DECIMAL": //MSSQLServer & DB2
return DbType.Decimal;
case "FLOAT": //MSSQLServer & Oracle
return DbType.Double;
case "REAL": //MSSQLServer & DB2
return DbType.Single;
case "DOUBLE":
return DbType.Double;
case "CHAR": //MSSQLServer & Oracle.
return DbType.AnsiStringFixedLength;
case "NCHAR": //MSSQLServer & Oracle.
return DbType.AnsiStringFixedLength;
case "VARCHAR": //MSSQLServer, Oracle & DB2.
return DbType.AnsiString;
case "NVARCHAR": //MSSQLServer & Oracle.
return DbType.AnsiString;
case "CHARACTER": //DB2
return DbType.AnsiStringFixedLength;
case "LONGVARCHAR": //DB2
return DbType.String;
case "LONG": //Oracle.
return DbType.AnsiString;
default:
throw new ApplicationException(string.Format("Dont know the default DbType for {0}.", dbTypeName));
}
}
public object ApplyDefaultDataTransformation()
{
if (Value == DBNull.Value)
{
return DBNull.Value;
}
else if (Value.GetType() == typeof(bool))
{
return DefaultBooleanTransformation((bool)Value);
}
else if (Value.GetType() == typeof(byte))
{
return DefaultByteTransformation((byte)Value);
}
else if (Value.GetType() == typeof(Int16))
{
return DefaultInt16Transformation((Int16)Value);
}
else if (Value.GetType() == typeof(int))
{
return DefaultIntTransformation((int)Value);
}
else if (Value.GetType() == typeof(Int64))
{
return DefaultInt64Transformation((Int64)Value);
}
else if (Value.GetType() == typeof(decimal))
{
return DefaultDecimalTransformation((decimal)Value);
}
else if (Value.GetType() == typeof(double))
{
return DefaultDoubleTransformation((double)Value);
}
else if (Value.GetType() == typeof(float))
{
return DefaultFloatTransformation((float)Value);
}
else if (Value.GetType() == typeof(string))
{
return DefaultStringTransformation((string)Value);
}
else
{
throw new ApplicationException(string.Format("No default transformation for type {0}.", Value));
}
}
public static bool DefaultBooleanTransformation(bool val)
{
return !val;
}
public static byte DefaultByteTransformation(byte val)
{
return (byte)(val*2);;
}
public static Int16 DefaultInt16Transformation(Int16 val)
{
return (Int16)(val*2);
}
public static int DefaultIntTransformation(int val)
{
return (int)(val*2);;
}
public static Int64 DefaultInt64Transformation(Int64 val)
{
return (Int64)(val*2);;
}
public static decimal DefaultDecimalTransformation(decimal val)
{
return (decimal)(val*2);;
}
public static double DefaultDoubleTransformation(double val)
{
return (double)(val*2);;
}
public static float DefaultFloatTransformation(float val)
{
return (float)(val*2);;
}
public static string DefaultStringTransformation(string val)
{
return val.ToUpper();;
}
/// <summary>
/// Invalidates the size of this DbTypeParameter.
/// </summary>
public void InvalidateSize()
{
m_bIsSizeSet = false;
}
#endregion
}
}

View File

@@ -0,0 +1,486 @@
//
// 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.IO;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Data.Utils
{
public class GHTBase
{
#region Constructors
/// <summary>Constructor
/// <param name="Logger">Custom TextWriter to log to</param>
/// <param name="LogOnSuccess">False to log only failed TestCases, True to log all</param>
/// </summary>
protected GHTBase(TextWriter Logger, bool LogOnSuccess)
{
this._logger = Logger;
this._logOnSuccess = LogOnSuccess;
}
/// <summary>Constructor, log to Console
/// <param name="LogOnSuccess">False to log only failed TestCases, True to log all</param>
/// </summary>
protected GHTBase(bool LogOnSuccess):this(Console.Out, LogOnSuccess){}
/// <summary>Constructor, log to Console only when Failed
/// </summary>
protected GHTBase():this(Console.Out, false){}
#endregion
#region protected methods
public void GHTSetLogger(TextWriter Logger)
{
this._logger = Logger;
}
/// <summary>Begin Test which containes TestCases
/// <param name="testName">Test name, used on logs</param>
/// </summary>
public virtual void BeginTest(string testName)
{
//set test name
this._testName = testName;
//reset the Failure Counter and the TestCase Number
UniqueId.ResetCounters();
if(this._logOnSuccess == true)
Log(string.Format("*** Starting Test: [{0}] ***", this._testName));
}
/// <summary>Begin TestCase
/// <param name="Description">TestCase Description, used on logs</param>
/// </summary>
public void BeginCase(string Description)
{
//Previous TestCase must be ended before beginning a new one.
if (_testCase != null) throw new Exception("Previous Case not Ended");
//init the new TestCase with Unique TestCase Number and Description
_testCase = new UniqueId(Description);
if(this._logOnSuccess == true)
Log(string.Format("Starting Case: [{0}]", _testCase.ToString()));
}
/// <summary>Compare two objects (using Object.Equals)
/// </summary>
protected bool Compare(object a, object b)
{
Assert.AreEqual(b, a);
//signal that the Compare method has been called
this._testCase.CompareInvoked = true;
//a string that holds the description of the objects for log
string ObjectData;
//check if one of the objects is null
if (a == null && b != null)
{
ObjectData = "Object a = null" + ", Object b.ToString() = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
this._testCase.Success = false; //objects are different, TestCase Failed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if the other object is null
if (a != null && b == null)
{
ObjectData = "Object a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + "), Object b = null";
this._testCase.Success = false; //objects are different, TestCase Failed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if both objects are null
if ( (a == null && b == null) )
{
ObjectData = "Object a = null, Object b = null";
this._testCase.Success = true; //both objects are null, TestCase Succeed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
ObjectData = "Object a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + "), Object b.ToString = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
//use Object.Equals to compare the objects
this._testCase.Success = (a.Equals(b));
LogCompareResult(ObjectData);
return this._testCase.Success;
}
/// <summary>Compare two Object Arrays.
/// <param name="a">First array.</param>
/// <param name="b">Second array.</param>
/// <param name="Sorted">Used to indicate if both arrays are sorted.</param>
/// </summary>
protected bool Compare(Array a, Array b)
{
Assert.AreEqual(b, a);
//signal that the Compare method has been called
this._testCase.CompareInvoked=true;
//a string that holds the description of the objects for log
string ObjectData;
//check if both objects are null
if ( (a == null && b == null) )
{
ObjectData = "Array a = null, Array b = null";
this._testCase.Success = true; //both objects are null, TestCase Succeed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if one of the objects is null.
//(If both were null, we wouldn't have reached here).
if (a == null || b == null)
{
string aData = (a==null) ? "null" : "'" + a.ToString() + "' (" + a.GetType().FullName + ")";
string bData = (b==null) ? "null" : "'" +b.ToString() + "' (" + b.GetType().FullName + ")";
ObjectData = "Array a = " + aData + ", Array b = " + bData;
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if both arrays are of the same rank.
if (a.Rank != b.Rank)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Rank = {0}, Array b.Rank = {1}", a.Rank, b.Rank);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Do not handle multi dimentional arrays.
if (a.Rank != 1)
{
this._testCase.Success = false;
ObjectData = "Multi-dimension array comparison is not supported";
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if both arrays are of the same length.
if (a.Length != b.Length)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Length = {0}, Array b.Length = {1}", a.Length, b.Length);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
ObjectData = "Array a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + ") Array b.ToString = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
//Compare elements of the Array.
int iLength = a.Length;
for (int i=0; i<iLength; i++)
{
object aValue = a.GetValue(i);
object bValue = b.GetValue(i);
if (aValue == null && bValue == null)
{
continue;
}
if (aValue == null || bValue == null || !aValue.Equals(bValue) )
{
string aData = (aValue==null) ? "null" : "'" + aValue.ToString() + "' (" + aValue.GetType().FullName + ")";
string bData = (bValue==null) ? "null" : "'" + bValue.ToString() + "' (" + bValue.GetType().FullName + ")";
ObjectData = string.Format("Array a[{0}] = {1}, Array b[{0}] = {2}", i, aData, bData);
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
}
this._testCase.Success = true;
LogCompareResult(ObjectData);
return this._testCase.Success;
}
/// <summary>
/// Intentionally fail a testcase, without calling the compare method.
/// </summary>
/// <param name="message">The reason for the failure.</param>
protected void Fail(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = false;
//Log(string.Format("TestCase \"{0}\" Failed: [{1}]", _testCase.ToString(), message));
Assert.Fail(message);
}
/// <summary>
/// Intentionally cause a testcase to pass, without calling the compare message.
/// </summary>
/// <param name="message">The reason for passing the test.</param>
protected void Pass(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = true;
if (this._logOnSuccess)
{
Log(string.Format("TestCase \"{0}\" Passed: [{1}]", _testCase.ToString(), message));
}
}
/// <summary>
/// Marks this testcase as success, but logs the reason for skipping regardless of _logOnSuccess value.
/// </summary>
/// <param name="message">The reason for skipping the test.</param>
protected void Skip(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = true;
Log(string.Format("TestCase \"{0}\" Skipped: [{1}]", _testCase.ToString(), message));
}
/// <summary>
/// Intentionally fail a testcase when an expected exception is not thrown.
/// </summary>
/// <param name="exceptionName">The name of the expected exception type.</param>
protected void ExpectedExceptionNotCaught(string exceptionName)
{
this.Fail(string.Format("Expected {0} was not caught.", exceptionName));
}
/// <summary>
/// Intentionally cause a testcase to pass, when an expected exception is thrown.
/// </summary>
/// <param name="ex"></param>
protected void ExpectedExceptionCaught(Exception ex)
{
this.Pass(string.Format("Expected {0} was caught.", ex.GetType().FullName));
}
/// <summary>End TestCase
/// <param name="ex">Exception object if exception occured during the TestCase, null if not</param>
/// </summary>
protected void EndCase(Exception ex)
{
//check if BeginCase was called. cannot end an unopen TestCase
if(_testCase == null)
{
throw new Exception("BeginCase was not called");
}
else
{
//if Exception occured during the test - log the error and faile the TestCase.
if(ex != null)
{
_testCase.Success=false;
Log(string.Format("TestCase: \"{0}\" Error: [Failed With Unexpected {1}: \n\t{2}]", _testCase.ToString(), ex.GetType().FullName, ex.Message + "\n" + ex.StackTrace ));
_testCase = null;
throw ex;
}
else
{
//check if Compare was called
if (_testCase.CompareInvoked == true)
{
if(this._logOnSuccess == true) Log(string.Format("Finished Case: [{0}] ", _testCase.ToString()));
}
else
{
//if compare was not called, log error message
Log(string.Format("TestCase \"{0}\" Warning: [TestCase didn't invoke the Compare mehtod] ", _testCase.ToString()));
}
}
//Terminate TestCase (set TestCase to null)
_testCase = null;
}
}
/// <summary>End Test
/// <param name="ex">Exception object if exception occured during the Test, null if not</param>
/// </summary>
public void EndTest(Exception ex)
{
//if all test cases succeeded but an exception occured - set exit code to -1
//if we wont set it to -1, the exit code will be 0 !!!
if (UniqueId.FailureCounter == 0 && ex != null)
{
Environment.ExitCode = -1;
}
else
{
//set exitcode to the count of failed TestCases
Environment.ExitCode = UniqueId.FailureCounter;
}
//if exception occured - log error
if(ex != null)
{
Log(string.Format("Unexpected Exception accured in Test [{0}] - {1} \n {2}" , this._testName, ex.Message ,ex.StackTrace));
}
if(this._logOnSuccess)
{
Log(string.Format("*** Finished Test: [{0}] ***", this._testName));
}
}
public int GHTGetExitCode()
{
return UniqueId.FailureCounter;
}
/// <summary>logger
/// <param name="text">string message to log</param>
/// </summary>
protected void Log(string text)
{
// _loggerBuffer = _loggerBuffer + "\n" + "GHTBase:Logger - " + text;
// _logger.WriteLine("GHTBase:Logger - " + text);
}
//used to log the results from the compare methods
private void LogCompareResult(string ObjectData)
{
if(this._testCase.Success == false)
{
Log(string.Format("TeseCase \"{0}\" Error: [Failed while comparing(" + ObjectData + ")] ", _testCase.ToString() ));
}
else
if(this._logOnSuccess == true)
Log(string.Format("TestCase \"{0}\" Passed ", _testCase.ToString()));
}
protected int TestCaseNumber
{
get
{
return _testCase.CaseNumber;
}
}
#endregion
#region private fields
private TextWriter _logger;
public string _loggerBuffer; // a public clone string of the _logger (used in web tests)
private string _testName;
private UniqueId _testCase;
private bool _logOnSuccess;
#endregion
}
//holds all the info on a TestCase
internal class UniqueId
{
//holds the unique name of the test case
//this name must be recieved from the test case itself
//when calling BeginCase.
//example: BeginCase("MyName")
private string _caseName;
//maintains the number generated for this test case
private static int _caseNumber;
//maintains the number of failed test case
private static int _FailureCounter;
internal static int FailureCounter
{
get
{
return _FailureCounter;
}
}
//indicate if the Compare method has been invoked AND containes compare objects message (ToString)
private bool _CompareInvoked;
internal bool CompareInvoked
{
get
{
return _CompareInvoked;
}
set
{
_CompareInvoked = value;
}
}
//reset the static counters when a new Test (not TestCase !!) begin
internal static void ResetCounters()
{
_FailureCounter = 0;
_caseNumber = 0;
}
//signal if a TestCase failed, if failed - increment the _FailureCounter
private bool _success;
internal bool Success
{
get
{
return this._success;
}
set
{
this._success = value;
if (value == false)
{
_FailureCounter++;
}
}
}
//Ctor, Recieve the name for the test case
//generate a unique number and apply it to the test case
internal UniqueId(string Name)
{
this._caseName = Name;
//this._caseNumber = ++UniqueId._counter;
_caseNumber++;
}
internal int CaseNumber
{
get
{
return _caseNumber;
}
}
public override string ToString()
{
return string.Format("\"{0}\" #{1}", this._caseName, _caseNumber);
}
}
}

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();
}
}
}

Some files were not shown because too many files have changed in this diff Show More