OracleCommand_Prepare.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OracleClient ;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OracleClient
  29. {
  30. [TestFixture]
  31. public class OracleCommand_Prepare : GHTBase
  32. {
  33. public static void Main()
  34. {
  35. OracleCommand_Prepare tc = new OracleCommand_Prepare();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OracleCommand_Prepare");
  40. tc.run();
  41. }
  42. catch(Exception ex){exp = ex;}
  43. finally {tc.EndTest(exp);}
  44. }
  45. [Test]
  46. public void run()
  47. {
  48. Exception exp = null;
  49. int intRecordsAffected = 0;
  50. string sql = "Update Shippers Set CompanyName=:CompName Where ShipperID = 2";
  51. OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  52. OracleCommand cmd = new OracleCommand("", con);
  53. con.Open();
  54. //get expected result
  55. cmd.CommandText = "select count(*) from Shippers where ShipperID = 2";
  56. int ExpectedRows = int.Parse(cmd.ExecuteScalar().ToString());
  57. cmd.CommandText = sql;
  58. //Currently not running on DB2: .Net-Failed, GH:Pass
  59. //if (con.Provider.IndexOf("IBMDADB2") >= 0) return ;
  60. cmd.Parameters.Add(new OracleParameter());
  61. cmd.Parameters[0].ParameterName = "CompName";
  62. cmd.Parameters[0].OracleType = OracleType.VarChar; //System.InvalidOperationException:
  63. cmd.Parameters[0].Size = 20; //System.InvalidOperationException
  64. cmd.Parameters[0].SourceColumn = "CompanyName";
  65. cmd.Parameters[0].Value = "Comp1";
  66. try
  67. {
  68. BeginCase("Prepare Exception - missing OracleType");
  69. cmd.Prepare();
  70. }
  71. catch(Exception ex){exp = ex;}
  72. finally{EndCase(exp); exp = null;}
  73. cmd.Parameters[0].OracleType = OracleType.VarChar;
  74. // try
  75. // {
  76. // BeginCase("Prepare Exception - missing Size");
  77. // try
  78. // {
  79. // cmd.Parameters[0].Size = 0;
  80. // cmd.Prepare();
  81. // }
  82. // catch (Exception ex) {exp = ex;}
  83. // Compare(exp.GetType().FullName, typeof(InvalidOperationException).FullName );
  84. // exp=null;
  85. // }
  86. // catch(Exception ex){exp = ex;}
  87. // finally{EndCase(exp); exp = null;}
  88. // cmd.Parameters[0].Size = 20;
  89. try
  90. {
  91. BeginCase("Prepare Exception - missing Size");
  92. try
  93. {
  94. con.Close();
  95. cmd.Prepare();
  96. }
  97. catch (Exception ex) {exp = ex;}
  98. Compare(exp.GetType().FullName, typeof(InvalidOperationException).FullName );
  99. exp=null;
  100. }
  101. catch(Exception ex){exp = ex;}
  102. finally{EndCase(exp); exp = null;}
  103. con.Open();
  104. try
  105. {
  106. BeginCase("ExecuteNonQuery first time");
  107. intRecordsAffected = cmd.ExecuteNonQuery();
  108. Compare(intRecordsAffected , ExpectedRows);
  109. }
  110. catch(Exception ex){exp = ex;}
  111. finally{EndCase(exp); exp = null;}
  112. try
  113. {
  114. BeginCase("ExecuteNonQuery second time, chage value");
  115. cmd.Parameters[0].Value = "Comp2";
  116. intRecordsAffected = cmd.ExecuteNonQuery();
  117. Compare(intRecordsAffected , ExpectedRows);
  118. }
  119. catch(Exception ex){exp = ex;}
  120. finally{EndCase(exp); exp = null;}
  121. if (con.State == ConnectionState.Open) con.Close();
  122. }
  123. }
  124. }