TestOracleClient.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // TestOracleClient.cs - Tests Sytem.Data.OracleClient
  3. // data provider in Mono.
  4. //
  5. // Part of managed C#/.NET library System.Data.OracleClient.dll
  6. //
  7. // Part of the Mono class libraries at
  8. // mcs/class/System.Data.OracleClient/System.Data.OracleClient.OCI
  9. //
  10. // Tests:
  11. // Assembly: System.Data.OracleClient.dll
  12. // Namespace: System.Data.OracleClient
  13. //
  14. // Author:
  15. // Daniel Morgan <[email protected]>
  16. //
  17. // Copyright (C) Daniel Morgan, 2002
  18. //
  19. // Expected Results:
  20. // 3 new rows where ENAME being: 'conn3', 'conn9', and 'conn1'
  21. using System;
  22. using System.Runtime.InteropServices;
  23. using System.Data;
  24. using System.Data.OracleClient;
  25. namespace Test.OracleClient
  26. {
  27. public class OracleTest
  28. {
  29. public OracleTest()
  30. {
  31. }
  32. static void DoTest1(OracleConnection con, int conn)
  33. {
  34. string inst = conn.ToString();
  35. string insertSql =
  36. "insert into scott.emp " +
  37. "(empno, ename, job, sal, deptno) " +
  38. "values(123" + inst + "," +
  39. "'conn" + inst + "'," +
  40. "'homy" + inst + "'," +
  41. "321" + inst + ",20)";
  42. Console.WriteLine("insertSql: " + insertSql);
  43. OracleCommand cmd = new OracleCommand();
  44. cmd.Connection = con;
  45. cmd.CommandText = insertSql;
  46. cmd.ExecuteNonQuery();
  47. if(conn == 2)
  48. cmd.CommandText = "rollback";
  49. else
  50. cmd.CommandText = "commit";
  51. cmd.ExecuteNonQuery();
  52. }
  53. static void DoTest9(OracleConnection con) {
  54. string inst = "9";
  55. string insertSql =
  56. "insert into scott.emp " +
  57. "(empno, ename, job, sal, deptno) " +
  58. "values(123" + inst + "," +
  59. "'conn" + inst + "'," +
  60. "'homy" + inst + "'," +
  61. "321" + inst + ",20)";
  62. Console.WriteLine("insertSql: " + insertSql);
  63. OracleCommand cmd = new OracleCommand();
  64. cmd.Connection = con;
  65. cmd.CommandText = insertSql;
  66. cmd.ExecuteNonQuery();
  67. cmd.CommandText = "commit";
  68. cmd.ExecuteNonQuery();
  69. }
  70. static void ReadSimpleTest(OracleConnection con)
  71. {
  72. string selectSql =
  73. "SELECT ename, job FROM scott.emp";
  74. OracleCommand cmd = new OracleCommand();
  75. cmd.Connection = con;
  76. cmd.CommandText = selectSql;
  77. OracleDataReader reader = cmd.ExecuteReader();
  78. Console.WriteLine("Results...");
  79. Console.WriteLine("Schema");
  80. DataTable table;
  81. table = reader.GetSchemaTable();
  82. for(int c = 0; c < reader.FieldCount; c++) {
  83. Console.WriteLine(" Column " + c.ToString());
  84. DataRow row = table.Rows[c];
  85. string ColumnName = (string) row["ColumnName"];
  86. string BaseColumnName = (string) row["BaseColumnName"];
  87. int ColumnSize = (int) row["ColumnSize"];
  88. int NumericScale = Convert.ToInt32( row["NumericScale"]);
  89. int NumericPrecision = Convert.ToInt32(row["NumericPrecision"]);
  90. Type DataType = (Type) row["DataType"];
  91. Console.WriteLine(" ColumnName: " + ColumnName);
  92. Console.WriteLine(" BaseColumnName: " + BaseColumnName);
  93. Console.WriteLine(" ColumnSize: " + ColumnSize.ToString());
  94. Console.WriteLine(" NumericScale: " + NumericScale.ToString());
  95. Console.WriteLine(" NumericPrecision: " + NumericPrecision.ToString());
  96. Console.WriteLine(" DataType: " + DataType.ToString());
  97. }
  98. int row = 0;
  99. Console.WriteLine("Data");
  100. while(reader.Read()) {
  101. row++;
  102. Console.WriteLine(" Row: " + row.ToString());
  103. for(int f = 0; f < reader.FieldCount; f++) {
  104. object ovalue;
  105. string svalue;
  106. ovalue = reader.GetValue(0);
  107. svalue = ovalue.ToString();
  108. Console.WriteLine(" Field: " + f.ToString());
  109. Console.WriteLine(" Value: " + svalue);
  110. }
  111. }
  112. if(row == 0)
  113. Console.WriteLine("No data returned.");
  114. }
  115. static void Wait(string msg)
  116. {
  117. //Console.WriteLine(msg);
  118. //Console.WriteLine("Waiting... Presee Enter to continue...");
  119. //string nothing = Console.ReadLine();
  120. }
  121. [STAThread]
  122. static void Main(string[] args)
  123. {
  124. if(args.Length != 3) {
  125. Console.WriteLine("Usage: mono TestOracleClient database userid password");
  126. return;
  127. }
  128. string connectionString = String.Format(
  129. "Data Source={0};" +
  130. "User ID={1};" +
  131. "Password={2}",
  132. args[0], args[1], args[2]);
  133. Wait("Verify database.");
  134. OracleConnection con1 = new OracleConnection();
  135. con1.ConnectionString = connectionString;
  136. con1.Open();
  137. Wait("Verify 1 connection.");
  138. OracleConnection con2 = new OracleConnection();
  139. con2.ConnectionString = connectionString;
  140. con2.Open();
  141. Wait("Verify 2 connections.");
  142. OracleConnection con3 = new OracleConnection();
  143. con3.ConnectionString = connectionString;
  144. con3.Open();
  145. Wait("Verify 3 connections.");
  146. //DoTest1(con1, 1);
  147. //DoTest1(con2, 2);
  148. //DoTest1(con3, 3);
  149. //DoTest9(con1);
  150. Console.WriteLine ("Read Simple Test BEGIN...");
  151. ReadSimpleTest(con1);
  152. Console.WriteLine ("Read Simple Test END.");
  153. Wait("Verify Proper Results.");
  154. con1.Close();
  155. Wait("Verify 2 connections left.");
  156. con2.Close();
  157. Wait("Verify 1 connection left.");
  158. con3.Close();
  159. Wait("Verify all disconnected.");
  160. }
  161. }
  162. }