OracleDataReader_GetGuiid_I.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 MonoTests.System.Data.Utils.Data;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Data.OracleClient
  30. {
  31. [TestFixture]
  32. public class OracleDataReader_GetGuiid_I : ADONetTesterClass
  33. {
  34. private const string GUID_COLUMN_NAME = "T_UNIQUEIDENTIFIER";
  35. private const string GUID_TABLE_NAME = ConnectedDataProvider.SPECIFIC_TYPES_TABLE_NAME;
  36. private const string TEST_GUID_STRING = "239A3C5E-8D41-11D1-B675-00C04FA3C554";
  37. public static void Main()
  38. {
  39. OracleDataReader_GetGuiid_I tc = new OracleDataReader_GetGuiid_I();
  40. Exception exp = null;
  41. try
  42. {
  43. tc.BeginTest("OracleDataReader_GetGuiid_I");
  44. tc.run();
  45. }
  46. catch(Exception ex){exp = ex;}
  47. finally {tc.EndTest(exp);}
  48. }
  49. public void run()
  50. {
  51. TestUsingSQLTextOnly();
  52. TestUsingParametersArray();
  53. }
  54. [Test]
  55. public void TestUsingSQLTextOnly()
  56. {
  57. //Only apply to MSSQL
  58. if ( (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)) {
  59. return;
  60. }
  61. Exception exp = null;
  62. OracleDataReader rdr = null;
  63. OracleConnection con = null;
  64. OracleCommand cmdDelete = null;
  65. try
  66. {
  67. BeginCase("Test using SQL text only.");
  68. string rowId = "43973_" + TestCaseNumber.ToString();
  69. string insertText = string.Format("INSERT INTO {0} (ID, {1}) VALUES ('{2}', '{{{3}}}')", GUID_TABLE_NAME, GUID_COLUMN_NAME, rowId, TEST_GUID_STRING);
  70. string selectText = string.Format("SELECT {0} FROM {1} WHERE ID='{2}'", GUID_COLUMN_NAME, GUID_TABLE_NAME, rowId);
  71. string deleteText = string.Format("DELETE FROM {0} WHERE ID='{1}'", GUID_TABLE_NAME, rowId);
  72. con = new OracleConnection(ConnectedDataProvider.ConnectionString);
  73. OracleCommand cmdInsert = new OracleCommand(insertText, con);
  74. OracleCommand cmdSelect = new OracleCommand(selectText, con);
  75. cmdDelete = new OracleCommand(deleteText, con);
  76. con.Open();
  77. cmdInsert.ExecuteNonQuery();
  78. rdr = cmdSelect.ExecuteReader();
  79. rdr.Read();
  80. Guid guidValue = rdr.GetGuid (0);
  81. Guid origGuid = new Guid(TEST_GUID_STRING);
  82. Compare(guidValue, origGuid);
  83. }
  84. catch(Exception ex)
  85. {
  86. exp = ex;
  87. }
  88. finally
  89. {
  90. EndCase(exp);
  91. exp = null;
  92. if ( (rdr != null) && (!rdr.IsClosed) )
  93. {
  94. rdr.Close();
  95. }
  96. if (cmdDelete != null)
  97. {
  98. cmdDelete.ExecuteNonQuery();
  99. }
  100. if ( (con != null) && (con.State != ConnectionState.Closed) )
  101. {
  102. con.Close();
  103. }
  104. }
  105. }
  106. [Test]
  107. public void TestUsingParametersArray()
  108. {
  109. //Only apply to MSSQL
  110. if ( (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer))
  111. {
  112. return;
  113. }
  114. Exception exp = null;
  115. OracleDataReader rdr = null;
  116. OracleConnection con = null;
  117. DbTypeParametersCollection row = new DbTypeParametersCollection(GUID_TABLE_NAME);
  118. string rowId = string.Empty;
  119. try
  120. {
  121. BeginCase("Test using parameters array");
  122. rowId = "43973_" + TestCaseNumber.ToString();
  123. row.Add("UNIQUEIDENTIFIER", new Guid(TEST_GUID_STRING));
  124. row.ExecuteInsert(rowId);
  125. row.ExecuteSelectReader(rowId, out rdr, out con);
  126. rdr.Read();
  127. Guid guidValue = rdr.GetGuid (0);
  128. Compare(guidValue, row[GUID_COLUMN_NAME].Value);
  129. }
  130. catch(Exception ex)
  131. {
  132. exp = ex;
  133. }
  134. finally
  135. {
  136. EndCase(exp);
  137. exp = null;
  138. if ( (rdr != null) && (!rdr.IsClosed) )
  139. {
  140. rdr.Close();
  141. }
  142. if (rowId != String.Empty)
  143. {
  144. row.ExecuteDelete(rowId);
  145. }
  146. if ( (con != null) && (con.State != ConnectionState.Closed) )
  147. {
  148. con.Close();
  149. }
  150. }
  151. }
  152. }
  153. }