OleDbDataAdapter_Fill_3.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.OleDb;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbDataAdapter_Fill_3: ADONetTesterClass
  32. {
  33. public static void Main()
  34. {
  35. OleDbDataAdapter_Fill_3 tc = new OleDbDataAdapter_Fill_3();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OleDbDataAdapter_Fill_3");
  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. //in DB2 when trying to fill an empty table - no table is loaded
  50. OleDbConnection conn = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  51. OleDbDataAdapter oleDBda = new OleDbDataAdapter();
  52. oleDBda.SelectCommand = new OleDbCommand("Select * from GH_EMPTYTABLE",conn);
  53. DataSet ds = new DataSet();
  54. oleDBda.Fill(ds);
  55. try
  56. {
  57. BeginCase("Table count - fill with SP");
  58. Compare(ds.Tables.Count ,1 );
  59. }
  60. catch(Exception ex) {exp = ex;}
  61. finally {EndCase(exp); exp = null;}
  62. //add for bug #2508 - OLEDBDataAdapter.Fill fills only the 1st result set, reported from an evaluation
  63. if (ConnectedDataProvider.GetDbType(oleDBda.SelectCommand.Connection) == DataBaseServer.SQLServer)
  64. //multiple commands can not be done with Oracle or DB2
  65. {
  66. //get excpected results
  67. if (oleDBda.SelectCommand.Connection.State != ConnectionState.Open)
  68. {
  69. oleDBda.SelectCommand.Connection.Open();
  70. }
  71. OleDbCommand cmd = new OleDbCommand("",oleDBda.SelectCommand.Connection);
  72. cmd.CommandText = "Select count(*) from Customers";
  73. int TblResult0 = (int)cmd.ExecuteScalar();
  74. cmd.CommandText = "Select count(*) from Categories";
  75. int TblResult1 = (int)cmd.ExecuteScalar();
  76. cmd.CommandText = "Select count(*) from Region";
  77. int TblResult2 = (int)cmd.ExecuteScalar();
  78. if (oleDBda.SelectCommand.Connection.State != ConnectionState.Closed)
  79. {
  80. oleDBda.SelectCommand.Connection.Close();
  81. }
  82. oleDBda.SelectCommand.CommandText = "Select * from Customers; " +
  83. "Select * from Categories; " +
  84. "Select * from Region";
  85. ds = new DataSet();
  86. oleDBda.Fill(ds);
  87. try
  88. {
  89. BeginCase("Table count - Fill with query");
  90. Compare(ds.Tables.Count ,3 );
  91. }
  92. catch(Exception ex) {exp = ex;}
  93. finally {EndCase(exp); exp = null;}
  94. try
  95. {
  96. BeginCase("Table 0 rows count");
  97. Compare(ds.Tables[0].Rows.Count ,TblResult0 );
  98. }
  99. catch(Exception ex) {exp = ex;}
  100. finally {EndCase(exp); exp = null;}
  101. try
  102. {
  103. BeginCase("Table 1 rows count");
  104. Compare(ds.Tables[1].Rows.Count ,TblResult1 );
  105. }
  106. catch(Exception ex) {exp = ex;}
  107. finally {EndCase(exp); exp = null;}
  108. try
  109. {
  110. BeginCase("Table 2 rows count");
  111. Compare(ds.Tables[2].Rows.Count ,TblResult2 );
  112. }
  113. catch(Exception ex) {exp = ex;}
  114. finally {EndCase(exp); exp = null;}
  115. }
  116. }
  117. }
  118. }