using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
-#if NET_2_0
using System.Data.Sql;
-#endif
using System.Globalization;
-#if NET_2_0
using System.Xml;
-#endif
using NUnit.Framework;
-namespace MonoTests.System.Data.SqlClient
+namespace MonoTests.System.Data.Connected.SqlClient
{
[TestFixture]
[Category ("sqlserver")]
{
SqlConnection conn;
SqlCommand cmd;
- string connectionString = ConnectionManager.Singleton.ConnectionString;
+ string connectionString = ConnectionManager.Instance.Sql.ConnectionString;
+ EngineConfig engine;
static readonly decimal SMALLMONEY_MAX = 214748.3647m;
static readonly decimal SMALLMONEY_MIN = -214748.3648m;
+ [SetUp]
+ public void SetUp ()
+ {
+ engine = ConnectionManager.Instance.Sql.EngineConfig;
+ }
+
[TearDown]
public void TearDown ()
{
Assert.AreSame (connA, cmd.Connection, "#A4");
Assert.IsNull (cmd.Container, "#A5");
Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
-#if NET_2_0
Assert.IsNull (cmd.Notification, "#A7");
Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
-#endif
Assert.IsNotNull (cmd.Parameters, "#A9");
Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
Assert.IsNull (cmd.Site, "#A11");
Assert.AreSame (connA, cmd.Connection, "#B4");
Assert.IsNull (cmd.Container, "#B5");
Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
-#if NET_2_0
Assert.IsNull (cmd.Notification, "#B7");
Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
-#endif
Assert.IsNotNull (cmd.Parameters, "#B9");
Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
Assert.IsNull (cmd.Site, "#B11");
[Test] // bug #341743
public void Dispose_Connection_Disposed ()
{
- IDbConnection conn = ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
+ conn = ConnectionManager.Instance.Sql.Connection;
- IDbCommand cmd = null;
- try {
- cmd = conn.CreateCommand ();
- cmd.CommandText = "SELECT 'a'";
- cmd.ExecuteNonQuery ();
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = "SELECT 'a'";
+ cmd.ExecuteNonQuery ();
- conn.Dispose ();
+ conn.Dispose ();
- Assert.AreSame (conn, cmd.Connection, "#1");
- cmd.Dispose ();
- Assert.AreSame (conn, cmd.Connection, "#2");
- } finally {
- if (cmd != null)
- cmd.Dispose ();
- ConnectionManager.Singleton.CloseConnection ();
- }
+ Assert.AreSame (conn, cmd.Connection, "#1");
+ cmd.Dispose ();
+ Assert.AreSame (conn, cmd.Connection, "#2");
}
[Test]
+ [Category("NotWorking")]
public void ExecuteScalar ()
{
conn = new SqlConnection (connectionString);
result = cmd.ExecuteScalar ();
Assert.Fail ("#B1");
} catch (SqlException ex) {
- // Incorrect syntax near the keyword 'from'
Assert.AreEqual (typeof (SqlException), ex.GetType (), "#B2");
Assert.AreEqual ((byte) 15, ex.Class, "#B3");
Assert.IsNull (ex.InnerException, "#B4");
Assert.IsNotNull (ex.Message, "#B5");
- Assert.IsTrue (ex.Message.IndexOf ("'from'") != -1, "#B6");
- Assert.AreEqual (156, ex.Number, "#B7");
+ if (ClientVersion == 7) {
+ // Incorrect syntax near '*'
+ Assert.IsTrue (ex.Message.IndexOf ("'*'") != -1, "#B6: " + ex.Message);
+ Assert.AreEqual (170, ex.Number, "#B7");
+ } else {
+ // Incorrect syntax near the keyword 'from'
+ Assert.IsTrue (ex.Message.IndexOf ("'from'") != -1, "#B6: " + ex.Message);
+ Assert.AreEqual (156, ex.Number, "#B7");
+ }
Assert.AreEqual ((byte) 1, ex.State, "#B8");
}
}
}
+ [Test]
+ public void ExecuteScalar_CommandText_Empty ()
+ {
+ conn = ConnectionManager.Instance.Sql.Connection;
+
+ cmd = conn.CreateCommand ();
+
+ try {
+ cmd.ExecuteScalar ();
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // ExecuteScalar: CommandText property
+ // has not been initialized
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ Assert.IsTrue (ex.Message.StartsWith ("ExecuteScalar"), "#A5:" + ex.Message);
+ }
+
+ cmd.CommandText = string.Empty;
+
+ try {
+ cmd.ExecuteScalar ();
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // ExecuteScalar: CommandText property
+ // has not been initialized
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ Assert.IsTrue (ex.Message.StartsWith ("ExecuteScalar"), "#B5:" + ex.Message);
+ }
+
+ cmd.CommandText = null;
+
+ try {
+ cmd.ExecuteScalar ();
+ Assert.Fail ("#C1");
+ } catch (InvalidOperationException ex) {
+ // ExecuteScalar: CommandText property
+ // has not been initialized
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+ Assert.IsNull (ex.InnerException, "#C3");
+ Assert.IsNotNull (ex.Message, "#C4");
+ Assert.IsTrue (ex.Message.StartsWith ("ExecuteScalar"), "#C5:" + ex.Message);
+ }
+ }
+
[Test]
public void ExecuteScalar_Connection_PendingTransaction ()
{
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf ("ExecuteScalar") != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf ("Execute") != -1, "#5:" + ex.Message);
-#endif
}
}
}
Assert.AreEqual ((byte) 16, ex.Class, "#3");
Assert.IsNull (ex.InnerException, "#4");
Assert.IsNotNull (ex.Message, "#5");
- Assert.IsTrue (ex.Message.IndexOf ("'InvalidQuery'") != -1, "#6");
+ Assert.IsTrue (ex.Message.IndexOf ("'InvalidQuery'") != -1, "#6:" + ex.Message);
Assert.AreEqual (2812, ex.Number, "#7");
Assert.AreEqual ((byte) 62, ex.State, "#8");
}
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.StartsWith ("ExecuteScalar:"), "#5");
-#else
- Assert.IsTrue (ex.Message.StartsWith ("ExecuteReader:"), "#5");
-#endif
} finally {
trans.Dispose ();
}
}
[Test]
+ [Category("NotWorking")]
public void ExecuteNonQuery ()
{
conn = new SqlConnection (connectionString);
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf ("ExecuteNonQuery") != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf ("Execute") != -1, "#5:" + ex.Message);
-#endif
}
}
}
Assert.AreEqual ((byte) 16, ex.Class, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
Assert.IsNotNull (ex.Message, "#A5");
- Assert.IsTrue (ex.Message.IndexOf ("'id1'") != -1, "#A6");
+ Assert.IsTrue (ex.Message.IndexOf ("'id1'") != -1, "#A6:" + ex.Message);
Assert.AreEqual (207, ex.Number, "#A7");
- Assert.AreEqual ((byte) 1, ex.State, "#A8");
+ if (ClientVersion == 7)
+ Assert.AreEqual ((byte) 3, ex.State, "#A8");
+ else
+ Assert.AreEqual ((byte) 1, ex.State, "#A8");
}
// ensure connection is not closed after error
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf ("ExecuteReader") != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf ("Execute") != -1, "#5:" + ex.Message);
-#endif
}
}
}
cmd = new SqlCommand ("InvalidQuery", conn);
try {
cmd.ExecuteReader ();
- Assert.Fail ("#1");
+ Assert.Fail ("#A1");
} catch (SqlException ex) {
// Could not find stored procedure 'InvalidQuery'
- Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
- Assert.AreEqual ((byte) 16, ex.Class, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- Assert.IsTrue (ex.Message.IndexOf ("'InvalidQuery'") != -1, "#6");
- Assert.AreEqual (2812, ex.Number, "#7");
- Assert.AreEqual ((byte) 62, ex.State, "#8");
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#A2");
+ Assert.AreEqual ((byte) 16, ex.Class, "#A3");
+ Assert.IsNull (ex.InnerException, "#A4");
+ Assert.IsNotNull (ex.Message, "#A5");
+ Assert.IsTrue (ex.Message.IndexOf ("'InvalidQuery'") != -1, "#A6:" + ex.Message);
+ Assert.AreEqual (2812, ex.Number, "#A7");
+ Assert.AreEqual ((byte) 62, ex.State, "#A8");
+
+ // connection is not closed
+ Assert.AreEqual (ConnectionState.Open, conn.State, "#A9");
+ }
+
+ try {
+ cmd.ExecuteReader (CommandBehavior.CloseConnection);
+ Assert.Fail ("#B1");
+ } catch (SqlException ex) {
+ // Could not find stored procedure 'InvalidQuery'
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#B2");
+ Assert.AreEqual ((byte) 16, ex.Class, "#B3");
+ Assert.IsNull (ex.InnerException, "#B4");
+ Assert.IsNotNull (ex.Message, "#B5");
+ Assert.IsTrue (ex.Message.IndexOf ("'InvalidQuery'") != -1, "#B6:" + ex.Message);
+ Assert.AreEqual (2812, ex.Number, "#B7");
+ Assert.AreEqual ((byte) 62, ex.State, "#B8");
+
+ // connection is closed
+ Assert.AreEqual (ConnectionState.Closed, conn.State, "#B9");
}
}
// Test InvalidOperation Exception is thrown if Parameter Type
// is not explicitly set
-#if NET_2_0
cmd.Parameters.AddWithValue ("@ID", 2);
-#else
- cmd.Parameters.Add ("@ID", 2);
-#endif
try {
cmd.Prepare ();
Assert.Fail ("#A1");
Assert.IsNotNull (ex.Message, "#B4");
}
+ // Test Exception is not thrown if DbType is set - #569543
+ try {
+ cmd.CommandText = "select type_guid from string_family where type_guid=@p1";
+ cmd.Parameters.Clear ();
+ cmd.Parameters.Add ("@p1", SqlDbType.UniqueIdentifier);
+ cmd.Parameters ["@p1"].Value = new Guid ("1C47DD1D-891B-47E8-AAC8-F36608B31BC5");
+ cmd.Prepare ();
+ } catch (Exception ex) {
+ Assert.Fail ("#B5 "+ex.Message);
+ }
+
// Test Exception is not thrown for Stored Procs
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ABFSDSFSF";
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf ("Prepare") != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf ("Execute") != -1, "#5:" + ex.Message);
-#endif
}
// Text, parameters cleared
}
[Test]
+ [Category("NotWorking")]
public void Prepare_Transaction_Only ()
{
SqlTransaction trans = null;
// Text, without parameters
cmd = new SqlCommand ("select count(*) from whatever");
cmd.Transaction = trans;
-#if NET_2_0
- try {
- cmd.Prepare ();
- Assert.Fail ("#A1");
- } catch (NullReferenceException) {
- }
-#else
- cmd.Prepare ();
-#endif
+ cmd.Prepare();
// Text, with parameters
cmd = new SqlCommand ("select count(*) from whatever");
cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
cmd.Transaction = trans;
- try {
- cmd.Prepare ();
- Assert.Fail ("#B1");
-#if NET_2_0
- } catch (NullReferenceException) {
- }
-#else
- } catch (InvalidOperationException ex) {
- // Prepare: Connection property has not been
- // initialized
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsTrue (ex.Message.StartsWith ("Prepare:"), "#B5");
- }
-#endif
+ Assert.Throws<InvalidOperationException>(() => cmd.Prepare());
// Text, parameters cleared
cmd = new SqlCommand ("select count(*) from whatever");
cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
cmd.Parameters.Clear ();
cmd.Transaction = trans;
-#if NET_2_0
- try {
- cmd.Prepare ();
- Assert.Fail ("#C1");
- } catch (NullReferenceException) {
- }
-#else
- cmd.Prepare ();
-#endif
+ cmd.Prepare();
// StoredProcedure, without parameters
cmd = new SqlCommand ("FindCustomer");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Transaction = trans;
-#if NET_2_0
- try {
- cmd.Prepare ();
- Assert.Fail ("#D1");
- } catch (NullReferenceException) {
- }
-#else
- cmd.Prepare ();
-#endif
+ cmd.Prepare();
// StoredProcedure, with parameters
cmd = new SqlCommand ("FindCustomer");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
cmd.Transaction = trans;
-#if NET_2_0
- try {
- cmd.Prepare ();
- Assert.Fail ("#E1");
- } catch (NullReferenceException) {
- }
-#else
- cmd.Prepare ();
-#endif
+ cmd.Prepare();
}
[Test] // bug #412576
SqlCommand cmdB = new SqlCommand ("select @@version", connA, trans);
using (SqlDataReader reader = cmdB.ExecuteReader ()) {
-#if NET_2_0
cmdA.Connection = connA;
Assert.AreSame (connA, cmdA.Connection, "#A1");
Assert.AreSame (trans, cmdA.Transaction, "#A2");
-#else
- try {
- cmdA.Connection = connA;
- Assert.Fail ("#A1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
-
- Assert.AreSame (connA, cmdA.Connection, "#A5");
- Assert.AreSame (trans, cmdA.Transaction, "#A6");
- }
-#endif
-#if NET_2_0
cmdA.Connection = connB;
Assert.AreSame (connB, cmdA.Connection, "#B1");
Assert.AreSame (trans, cmdA.Transaction, "#B2");
-#else
- try {
- cmdA.Connection = connB;
- Assert.Fail ("#B1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
-
- Assert.AreSame (connA, cmdA.Connection, "#B5");
- Assert.AreSame (trans, cmdA.Transaction, "#B6");
- }
-#endif
-#if NET_2_0
cmdA.Connection = null;
Assert.IsNull (cmdA.Connection, "#C1");
Assert.AreSame (trans, cmdA.Transaction, "#C2");
-#else
- try {
- cmdA.Connection = null;
- Assert.Fail ("#C1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
-
- Assert.AreSame (connA, cmdA.Connection, "#C5");
- Assert.AreSame (trans, cmdA.Transaction, "#C6");
- }
-#endif
}
} finally {
if (trans != null)
SqlCommand cmdB = new SqlCommand ("select * from employee", connA, transA);
using (SqlDataReader reader = cmdB.ExecuteReader ()) {
-#if NET_2_0
cmdA.Transaction = transA;
Assert.AreSame (transA, cmdA.Transaction, "#A1");
-#else
- try {
- cmdA.Transaction = transA;
- Assert.Fail ("#A1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
-
- Assert.AreSame (transA, cmdA.Transaction, "#A5");
- }
-#endif
-#if NET_2_0
cmdA.Transaction = transB;
Assert.AreSame (transB, cmdA.Transaction, "#B1");
-#else
- try {
- cmdA.Transaction = transB;
- Assert.Fail ("#B1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
-
- Assert.AreSame (transA, cmdA.Transaction, "#B5");
- }
-#endif
-#if NET_2_0
cmdA.Transaction = null;
Assert.IsNull (cmdA.Transaction, "#C1");
-#else
- try {
- cmdA.Transaction = null;
- Assert.Fail ("#C1");
- } catch (InvalidOperationException ex) {
- // The SqlCommand is currently busy
- // Open, Fetching
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
-
- Assert.AreSame (transA, cmdA.Transaction, "#C5");
- }
-#endif
}
cmdA.Transaction = transA;
SqlParameter idParam;
SqlParameter dojParam;
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- conn.Open ();
+ conn = ConnectionManager.Instance.Sql.Connection;
// parameters with leading '@'
try {
idParam = cmd.Parameters.Add ("id", SqlDbType.Int);
idParam.Direction = ParameterDirection.ReturnValue;
-#if NET_2_0
Assert.AreEqual (1, cmd.ExecuteNonQuery (), "#B1");
cmd.Dispose ();
Assert.IsFalse (dr.Read (), "#B9");
cmd.Dispose ();
dr.Close ();
-#else
- try {
- cmd.ExecuteNonQuery ();
- Assert.Fail ("#B1");
- } catch (SqlException) {
- // Procedure or Function '#sp_temp_insert_employee'
- // expects parameter '@fname', which was not supplied
- }
-#endif
} finally {
if (cmd != null)
cmd.Dispose ();
}
[Test] // bug #319598
+ [Category("NotWorking")]
public void LongQueryTest ()
{
+ if (ClientVersion == 7)
+ Assert.Ignore ("Hangs on SQL Server 7.0");
+
SqlConnection conn = new SqlConnection (
connectionString + ";Pooling=false");
using (conn) {
}
[Test] // bug #319598
+ [Category("NotWorking")]
public void LongStoredProcTest ()
{
+ if (ClientVersion == 7)
+ Assert.Ignore ("Hangs on SQL Server 7.0");
+
SqlConnection conn = new SqlConnection (
connectionString + ";Pooling=false");
using (conn) {
[Test]
public void EnumParameterTest ()
{
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
+ conn = ConnectionManager.Instance.Sql.Connection;
try {
- ConnectionManager.Singleton.OpenConnection ();
// create temp sp here, should normally be created in Setup of test
// case, but cannot be done right now because of ug #68978
DBHelper.ExecuteNonQuery (conn, "CREATE PROCEDURE #Bug66630 ("
DBHelper.ExecuteNonQuery (conn, "if exists (select name from sysobjects " +
" where name like '#temp_Bug66630' and type like 'P') " +
" drop procedure #temp_Bug66630; ");
- ConnectionManager.Singleton.CloseConnection ();
+ ConnectionManager.Instance.Sql.CloseConnection ();
}
}
}
[Test]
+ [Category("NotWorking")]
public void StoredProc_ParameterTest ()
{
string create_query = CREATE_TMP_SP_PARAM_TEST;
[Test]
public void OutputParamSizeTest1 ()
{
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
+ conn = ConnectionManager.Instance.Sql.Connection;
cmd = new SqlCommand ();
cmd.Connection = conn;
[Test]
public void OutputParamSizeTest2 ()
{
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
+ conn = ConnectionManager.Instance.Sql.Connection;
cmd = new SqlCommand ();
cmd.Connection = conn;
[Test]
public void OutputParamSizeTest3 ()
{
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
+ conn = ConnectionManager.Instance.Sql.Connection;
cmd = new SqlCommand ();
cmd.Connection = conn;
[Test]
public void OutputParamSizeTest4 ()
{
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
+ conn = ConnectionManager.Instance.Sql.Connection;
cmd = new SqlCommand ();
cmd.Connection = conn;
}
}
+ [Test] // bug #470579
+ public void OutputParamTest ()
+ {
+ SqlParameter newId, id;
+
+ conn = ConnectionManager.Instance.Sql.Connection;
+
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = "set @NewId=@Id + 2";
+ cmd.CommandType = CommandType.Text;
+ newId = cmd.Parameters.Add ("@NewId", SqlDbType.Int);
+ newId.Direction = ParameterDirection.Output;
+ id = cmd.Parameters.Add ("@Id", SqlDbType.Int);
+ id.Value = 3;
+ cmd.ExecuteNonQuery ();
+
+ Assert.AreEqual (5, newId.Value, "#A1");
+ Assert.AreEqual (3, id.Value, "#A2");
+
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = "set @NewId=@Id + 2";
+ cmd.CommandType = CommandType.Text;
+ newId = cmd.Parameters.Add ("NewId", SqlDbType.Int);
+ newId.Direction = ParameterDirection.Output;
+ id = cmd.Parameters.Add ("Id", SqlDbType.Int);
+ id.Value = 6;
+ cmd.ExecuteNonQuery ();
+
+ Assert.AreEqual (8, newId.Value, "#B1");
+ Assert.AreEqual (6, id.Value, "#B2");
+ }
+
[Test]
public void SmallMoney_Overflow_Max ()
{
Assert.AreEqual (typeof (OverflowException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf (string.Format (
CultureInfo.InvariantCulture, "'{0}'",
overflow)) != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf (string.Format (
- CultureInfo.CurrentCulture, "'{0}'",
- overflow)) != -1, "#5:" + ex.Message);
-#endif
Assert.IsTrue (ex.Message.IndexOf (string.Format (
CultureInfo.InvariantCulture, "{0:N4}",
SMALLMONEY_MIN)) != -1, "#6:" + ex.Message);
Assert.AreEqual (typeof (OverflowException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsTrue (ex.Message.IndexOf (string.Format (
CultureInfo.InvariantCulture, "'{0}'",
overflow)) != -1, "#5:" + ex.Message);
-#else
- Assert.IsTrue (ex.Message.IndexOf (string.Format (
- CultureInfo.CurrentCulture, "'{0}'",
- overflow)) != -1, "#5:" + ex.Message);
-#endif
Assert.IsTrue (ex.Message.IndexOf (string.Format (
CultureInfo.InvariantCulture, "{0:N4}",
SMALLMONEY_MIN)) != -1, "#6:" + ex.Message);
}
}
-#if NET_2_0
[Test]
public void NotificationTest ()
{
{
cmd = new SqlCommand ();
string connectionString1 = null;
- connectionString1 = ConnectionManager.Singleton.ConnectionString + "Asynchronous Processing=true";
+ connectionString1 = ConnectionManager.Instance.Sql.ConnectionString + ";Asynchronous Processing=true";
try {
SqlConnection conn1 = new SqlConnection (connectionString1);
conn1.Open ();
Assert.AreEqual ("kumar", reader["lname"], "#1 ");
}
} finally {
- ConnectionManager.Singleton.CloseConnection ();
+ ConnectionManager.Instance.Sql.CloseConnection ();
}
}
[Test]
+ [Ignore("MS .NET doesn't throw IOE here. TODO: check corefx")]
public void BeginExecuteXmlReaderExceptionTest ()
{
cmd = new SqlCommand ();
try {
/*IAsyncResult result = */cmd.BeginExecuteXmlReader ();
} catch (InvalidOperationException) {
- Assert.AreEqual (ConnectionManager.Singleton.ConnectionString, connectionString, "#1 Connection string has changed");
+ Assert.AreEqual (ConnectionManager.Instance.Sql.ConnectionString, connectionString, "#1 Connection string has changed");
return;
}
Assert.Fail ("Expected Exception InvalidOperationException not thrown");
} finally {
- ConnectionManager.Singleton.CloseConnection ();
+ ConnectionManager.Instance.Sql.CloseConnection ();
}
}
-#endif
[Test]
public void SqlCommandDisposeTest ()
{
IDataReader reader = null;
+ conn = ConnectionManager.Instance.Sql.Connection;
try {
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
IDbCommand command = conn.CreateCommand ();
try {
while (reader.Read ()) ;
} finally {
reader.Dispose ();
- ConnectionManager.Singleton.CloseConnection ();
+ ConnectionManager.Instance.Sql.CloseConnection ();
}
}
out int param3Val,
out int rvalVal)
{
+ conn = ConnectionManager.Instance.Sql.Connection;
try {
- conn = (SqlConnection) ConnectionManager.Singleton.Connection;
- ConnectionManager.Singleton.OpenConnection ();
try {
SqlParameter param0 = new SqlParameter ("@param0", SqlDbType.Int);
cmd = null;
}
} finally {
- ConnectionManager.Singleton.CloseConnection ();
+ ConnectionManager.Instance.Sql.CloseConnection ();
conn = null;
}
}
Assert.AreEqual (100, param0Val);
}
+ [Test]
+ public void DeriveParameterTest_FullSchema ()
+ {
+ string create_tbl = "CREATE TABLE decimalCheck (deccheck DECIMAL (19, 5) null)";
+ string create_sp = "CREATE PROCEDURE sp_bug584833(@deccheck decimal(19,5) OUT)"
+ + "AS " + Environment.NewLine
+ + "BEGIN" + Environment.NewLine
+ + "INSERT INTO decimalCheck values (@deccheck)" + Environment.NewLine
+ + "SELECT @deccheck=deccheck from decimalCheck" + Environment.NewLine
+ + "END";
+
+ conn = ConnectionManager.Instance.Sql.Connection;
+ try {
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = create_tbl;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = create_sp;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "dbo.sp_bug584833";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlCommandBuilder.DeriveParameters (cmd);
+ Assert.AreEqual (2, cmd.Parameters.Count, "#DPT - FullSchema - Parameter count mismatch");
+ Assert.AreEqual ("@deccheck", cmd.Parameters[1].ParameterName, "#DPT - FullSchema - Parameter name mismatch");
+ Assert.AreEqual (SqlDbType.Decimal, cmd.Parameters[1].SqlDbType, "#DPT - FullSchema - Parameter type mismatch");
+ } finally {
+ cmd.Parameters.Clear ();
+ cmd.CommandText = "drop procedure sp_bug584833";
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+ cmd.CommandText = "drop table decimalCheck";
+ cmd.ExecuteNonQuery ();
+ cmd.Dispose ();
+ cmd = null;
+ ConnectionManager.Instance.Sql.CloseConnection ();
+ conn = null;
+ }
+
+ }
+
+ [Test]
+ public void DeriveParameterTest_SPName ()
+ {
+ string create_tbl = "CREATE TABLE decimalCheck (deccheck DECIMAL (19, 5) null)";
+ string create_sp = "CREATE PROCEDURE sp_bug584833(@deccheck decimal(19,5) OUT)"
+ + "AS " + Environment.NewLine
+ + "BEGIN" + Environment.NewLine
+ + "INSERT INTO decimalCheck values (@deccheck)" + Environment.NewLine
+ + "SELECT @deccheck=deccheck from decimalCheck" + Environment.NewLine
+ + "END";
+
+ conn = ConnectionManager.Instance.Sql.Connection;
+ try {
+
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = create_tbl;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = create_sp;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "sp_bug584833";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlCommandBuilder.DeriveParameters (cmd);
+ Assert.AreEqual (2, cmd.Parameters.Count, "#DPT - SPName - Parameter count mismatch");
+ Assert.AreEqual ("@deccheck", cmd.Parameters[1].ParameterName, "#DPT - SPName - Parameter name mismatch");
+ Assert.AreEqual (SqlDbType.Decimal, cmd.Parameters[1].SqlDbType, "#DPT - SPName - Parameter type mismatch");
+ } finally {
+ cmd.Parameters.Clear ();
+ cmd.CommandType = CommandType.Text;
+ cmd.CommandText = "drop procedure sp_bug584833";
+ cmd.ExecuteNonQuery ();
+ cmd.CommandText = "drop table decimalCheck";
+ cmd.ExecuteNonQuery ();
+ cmd.Dispose ();
+ cmd = null;
+ ConnectionManager.Instance.Sql.CloseConnection ();
+ conn = null;
+ }
+ }
+
+ [Test]
+ public void DeriveParameterTest_UserSchema ()
+ {
+ string create_tbl = "CREATE TABLE decimalCheck (deccheck DECIMAL (19, 5) null)";
+ string create_sp = "CREATE PROCEDURE sp_bug584833(@deccheck decimal(19,5) OUT)"
+ + "AS " + Environment.NewLine
+ + "BEGIN" + Environment.NewLine
+ + "INSERT INTO decimalCheck values (@deccheck)" + Environment.NewLine
+ + "SELECT @deccheck=deccheck from decimalCheck" + Environment.NewLine
+ + "END";
+
+ try {
+ conn = ConnectionManager.Instance.Sql.Connection;
+
+ cmd = conn.CreateCommand ();
+ cmd.CommandText = create_tbl;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = create_sp;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "dbo.sp_bug584833";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlCommandBuilder.DeriveParameters (cmd);
+ Assert.AreEqual (2, cmd.Parameters.Count, "#DPT - user schema - Parameter count mismatch");
+ Assert.AreEqual ("@deccheck", cmd.Parameters[1].ParameterName, "#DPT - user schema - Parameter name mismatch");
+ Assert.AreEqual (SqlDbType.Decimal, cmd.Parameters[1].SqlDbType, "#DPT - user schema - Parameter type mismatch");
+ } finally {
+ cmd.Parameters.Clear ();
+ cmd.CommandType = CommandType.Text;
+ cmd.CommandText = "drop procedure dbo.sp_bug584833";
+ cmd.ExecuteNonQuery ();
+ cmd.CommandText = "drop table decimalCheck";
+ cmd.ExecuteNonQuery ();
+ cmd.Dispose ();
+ cmd = null;
+ ConnectionManager.Instance.Sql.CloseConnection ();
+ conn = null;
+ }
+ }
+
+ [Test] // bug#561667
+ public void CmdDispose_DataReaderReset ()
+ {
+ conn = ConnectionManager.Instance.Sql.Connection;
+ try
+ {
+ string query1 = "SELECT fname FROM employee where lname='kumar'";
+ string query2 = "SELECT type_int FROM numeric_family where type_bit = 1";
+ DataTable t = null;
+
+ t = GetColumns(conn, query1);
+ Assert.AreEqual ("suresh", t.Rows[0][0], "CmdDD#1: Query1 result mismatch");
+ t = GetColumns(conn, query2);
+ Assert.AreEqual (int.MaxValue, t.Rows[0][0], "CmdDD#2: Query2 result mismatch");
+ } finally {
+ ConnectionManager.Instance.Sql.CloseConnection ();
+ conn = null;
+ }
+ }
+
+ private DataTable GetColumns(DbConnection connection, string query)
+ {
+ DataTable t = new DataTable("Columns");
+ using (DbCommand c = connection.CreateCommand())
+ {
+ c.CommandText = query;
+ t.Load(c.ExecuteReader());
+ }
+ return t;
+ }
+
// used as workaround for bugs in NUnit 2.2.0
static void AreEqual (object x, object y, string msg)
{
}
}
+ int ClientVersion {
+ get {
+ return (engine.ClientVersion);
+ }
+ }
+
private enum Status
{
OK = 0,