TestOracleClient.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  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. // To Compile:
  15. // mcs TestOracleClient.cs /r:System.Data.dll /r:System.Data.OracleClient.dll /nowarn:0168
  16. //
  17. // Author:
  18. // Daniel Morgan <[email protected]>
  19. //
  20. // Copyright (C) Daniel Morgan, 2002, 2004-2005
  21. //
  22. using System;
  23. using System.IO;
  24. using System.Runtime.InteropServices;
  25. using System.Data;
  26. using System.Data.OracleClient;
  27. using System.Text;
  28. using System.Threading;
  29. namespace Test.OracleClient
  30. {
  31. public class OracleTest
  32. {
  33. private static Thread t = null;
  34. private static string conStr;
  35. public static readonly int MAX_CONNECTIONS = 30; // max connections default to 100, but I will set to 30.
  36. public OracleTest()
  37. {
  38. }
  39. static void MonoTest(OracleConnection con)
  40. {
  41. Console.WriteLine (" Drop table MONO_ORACLE_TEST ...");
  42. try {
  43. OracleCommand cmd2 = con.CreateCommand ();
  44. cmd2.CommandText = "DROP TABLE MONO_ORACLE_TEST";
  45. cmd2.ExecuteNonQuery ();
  46. }
  47. catch (OracleException oe1) {
  48. // ignore if table already exists
  49. }
  50. OracleCommand cmd = null;
  51. Console.WriteLine(" Creating table MONO_ORACLE_TEST...");
  52. cmd = new OracleCommand();
  53. cmd.Connection = con;
  54. cmd.CommandText = "CREATE TABLE MONO_ORACLE_TEST ( " +
  55. " varchar2_value VarChar2(32), " +
  56. " long_value long, " +
  57. " number_whole_value Number(18), " +
  58. " number_scaled_value Number(18,2), " +
  59. " number_integer_value Integer, " +
  60. " float_value Float, " +
  61. " date_value Date, " +
  62. " char_value Char(32), " +
  63. " clob_value Clob, " +
  64. " blob_value Blob, " +
  65. " clob_empty_value Clob, " +
  66. " blob_empty_value Blob, " +
  67. " varchar2_null_value VarChar2(32), " +
  68. " number_whole_null_value Number(18), " +
  69. " number_scaled_null_value Number(18,2), " +
  70. " number_integer_null_value Integer, " +
  71. " float_null_value Float, " +
  72. " date_null_value Date, " +
  73. " char_null_value Char(32), " +
  74. " clob_null_value Clob, " +
  75. " blob_null_value Blob " +
  76. ")";
  77. cmd.ExecuteNonQuery();
  78. Console.WriteLine(" Begin Trans for table MONO_ORACLE_TEST...");
  79. OracleTransaction trans = con.BeginTransaction ();
  80. Console.WriteLine(" Inserting value into MONO_ORACLE_TEST...");
  81. cmd = new OracleCommand();
  82. cmd.Connection = con;
  83. cmd.Transaction = trans;
  84. cmd.CommandText = "INSERT INTO mono_oracle_test " +
  85. " ( varchar2_value, " +
  86. " long_value, " +
  87. " number_whole_value, " +
  88. " number_scaled_value, " +
  89. " number_integer_value, " +
  90. " float_value, " +
  91. " date_value, " +
  92. " char_value, " +
  93. " clob_value, " +
  94. " blob_value, " +
  95. " clob_empty_value, " +
  96. " blob_empty_value " +
  97. ") " +
  98. " VALUES( " +
  99. " 'Mono', " +
  100. " 'This is a LONG column', " +
  101. " 123, " +
  102. " 456.78, " +
  103. " 8765, " +
  104. " 235.2, " +
  105. " TO_DATE( '2004-12-31', 'YYYY-MM-DD' ), " +
  106. " 'US', " +
  107. " EMPTY_CLOB(), " +
  108. " EMPTY_BLOB()," +
  109. " EMPTY_CLOB(), " +
  110. " EMPTY_BLOB()" +
  111. ")";
  112. cmd.ExecuteNonQuery();
  113. Console.WriteLine(" Select/Update CLOB columns on table MONO_ORACLE_TEST...");
  114. // update BLOB and CLOB columns
  115. OracleCommand select = con.CreateCommand ();
  116. select.Transaction = trans;
  117. select.CommandText = "SELECT CLOB_VALUE, BLOB_VALUE FROM MONO_ORACLE_TEST FOR UPDATE";
  118. OracleDataReader reader = select.ExecuteReader ();
  119. if (!reader.Read ())
  120. Console.WriteLine ("ERROR: RECORD NOT FOUND");
  121. // update clob_value
  122. Console.WriteLine(" Update CLOB column on table MONO_ORACLE_TEST...");
  123. OracleLob clob = reader.GetOracleLob (0);
  124. byte[] bytes = null;
  125. UnicodeEncoding encoding = new UnicodeEncoding ();
  126. bytes = encoding.GetBytes ("Mono is fun!");
  127. clob.Write (bytes, 0, bytes.Length);
  128. clob.Close ();
  129. // update blob_value
  130. Console.WriteLine(" Update BLOB column on table MONO_ORACLE_TEST...");
  131. OracleLob blob = reader.GetOracleLob (1);
  132. bytes = new byte[6] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x036 };
  133. blob.Write (bytes, 0, bytes.Length);
  134. blob.Close ();
  135. Console.WriteLine(" Commit trans for table MONO_ORACLE_TEST...");
  136. trans.Commit ();
  137. // OracleCommand.ExecuteReader of MONO_ORACLE_TEST table
  138. Console.WriteLine(" Read simple test for table MONO_ORACLE_TEST...");
  139. ReadSimpleTest(con, "SELECT * FROM MONO_ORACLE_TEST");
  140. // OracleCommand.ExecuteScalar
  141. Console.WriteLine(" -ExecuteScalar tests...");
  142. string varchar2_value = (string) ReadScalar (con,"SELECT MAX(varchar2_value) FROM MONO_ORACLE_TEST");
  143. Console.WriteLine(" String Value: " + varchar2_value);
  144. Console.WriteLine(" Read Scalar: number_whole_value");
  145. decimal number_whole_value = (decimal)
  146. ReadScalar (con,"SELECT MAX(number_whole_value) FROM MONO_ORACLE_TEST");
  147. Console.WriteLine(" Int32 Value: " + number_whole_value.ToString());
  148. Console.WriteLine(" Read Scalar: number_scaled_value");
  149. decimal number_scaled_value = (decimal)
  150. ReadScalar (con,"SELECT number_scaled_value FROM MONO_ORACLE_TEST");
  151. Console.WriteLine(" Decimal Value: " + number_scaled_value.ToString());
  152. Console.WriteLine(" Read Scalar: date_value");
  153. DateTime date_value = (DateTime)
  154. ReadScalar (con,"SELECT date_value FROM MONO_ORACLE_TEST");
  155. Console.WriteLine(" DateTime Value: " + date_value.ToString());
  156. Console.WriteLine(" Read Scalar: clob_value");
  157. string clob_value = (string)
  158. ReadScalar (con,"SELECT clob_value FROM MONO_ORACLE_TEST");
  159. Console.WriteLine(" CLOB Value: " + clob_value);
  160. Console.WriteLine(" Read Scalar: blob_value");
  161. byte[] blob_value = (byte[])
  162. ReadScalar (con,"SELECT blob_value FROM MONO_ORACLE_TEST");
  163. string sblob_value = GetHexString (blob_value);
  164. Console.WriteLine(" BLOB Value: " + sblob_value);
  165. // OracleCommand.ExecuteOracleScalar
  166. Console.WriteLine(" -ExecuteOracleScalar tests...");
  167. Console.WriteLine(" Read Oracle Scalar: varchar2_value");
  168. ReadOracleScalar (con,"SELECT MAX(varchar2_value) FROM MONO_ORACLE_TEST");
  169. Console.WriteLine(" Read Oracle Scalar: number_whole_value");
  170. ReadOracleScalar (con,"SELECT MAX(number_whole_value) FROM MONO_ORACLE_TEST");
  171. Console.WriteLine(" Read Oracle Scalar: number_scaled_value");
  172. ReadOracleScalar (con,"SELECT number_scaled_value FROM MONO_ORACLE_TEST");
  173. Console.WriteLine(" Read Oracle Scalar: date_value");
  174. ReadOracleScalar (con,"SELECT date_value FROM MONO_ORACLE_TEST");
  175. Console.WriteLine(" Read Oracle Scalar: clob_value");
  176. ReadOracleScalar (con,"SELECT clob_value FROM MONO_ORACLE_TEST");
  177. Console.WriteLine(" Read Oracle Scalar: blob_value");
  178. ReadOracleScalar (con,"SELECT blob_value FROM MONO_ORACLE_TEST");
  179. }
  180. static object ReadScalar (OracleConnection con, string selectSql)
  181. {
  182. OracleCommand cmd = null;
  183. cmd = con.CreateCommand();
  184. cmd.CommandText = selectSql;
  185. object o = cmd.ExecuteScalar ();
  186. string dataType = o.GetType ().ToString ();
  187. Console.WriteLine (" DataType: " + dataType);
  188. return o;
  189. }
  190. static void ReadOracleScalar (OracleConnection con, string selectSql)
  191. {
  192. OracleCommand cmd = null;
  193. cmd = con.CreateCommand();
  194. cmd.CommandText = selectSql;
  195. object o = cmd.ExecuteOracleScalar ();
  196. string dataType = o.GetType ().ToString ();
  197. Console.WriteLine (" DataType: " + dataType);
  198. if (dataType.Equals("System.Data.OracleClient.OracleLob"))
  199. o = ((OracleLob) o).Value;
  200. if (o.GetType ().ToString ().Equals ("System.Byte[]"))
  201. o = GetHexString ((byte[])o);
  202. Console.WriteLine (" Value: " + o.ToString ());
  203. }
  204. static void ReadSimpleTest(OracleConnection con, string selectSql)
  205. {
  206. OracleCommand cmd = null;
  207. OracleDataReader reader = null;
  208. cmd = con.CreateCommand();
  209. cmd.CommandText = selectSql;
  210. reader = cmd.ExecuteReader();
  211. Console.WriteLine(" Results...");
  212. Console.WriteLine(" Schema");
  213. DataTable table;
  214. table = reader.GetSchemaTable();
  215. for(int c = 0; c < reader.FieldCount; c++) {
  216. Console.WriteLine(" Column " + c.ToString());
  217. DataRow row = table.Rows[c];
  218. string strColumnName = row["ColumnName"].ToString();
  219. string strBaseColumnName = row["BaseColumnName"].ToString();
  220. string strColumnSize = row["ColumnSize"].ToString();
  221. string strNumericScale = row["NumericScale"].ToString();
  222. string strNumericPrecision = row["NumericPrecision"].ToString();
  223. string strDataType = row["DataType"].ToString();
  224. Console.WriteLine(" ColumnName: " + strColumnName);
  225. Console.WriteLine(" BaseColumnName: " + strBaseColumnName);
  226. Console.WriteLine(" ColumnSize: " + strColumnSize);
  227. Console.WriteLine(" NumericScale: " + strNumericScale);
  228. Console.WriteLine(" NumericPrecision: " + strNumericPrecision);
  229. Console.WriteLine(" DataType: " + strDataType);
  230. }
  231. int r = 0;
  232. Console.WriteLine (" Data");
  233. while (reader.Read ()) {
  234. r++;
  235. Console.WriteLine (" Row: " + r.ToString ());
  236. for (int f = 0; f < reader.FieldCount; f++) {
  237. string sname = "";
  238. object ovalue = "";
  239. string svalue = "";
  240. string sDataType = "";
  241. string sFieldType = "";
  242. string sDataTypeName = "";
  243. string sOraDataType = "";
  244. sname = reader.GetName (f);
  245. if (reader.IsDBNull (f)) {
  246. ovalue = DBNull.Value;
  247. svalue = "";
  248. sDataType = "DBNull.Value";
  249. sOraDataType = "DBNull.Value";
  250. }
  251. else {
  252. //ovalue = reader.GetValue (f);
  253. ovalue = reader.GetOracleValue (f);
  254. object oravalue = null;
  255. sDataType = ovalue.GetType ().ToString ();
  256. switch (sDataType) {
  257. case "System.Data.OracleClient.OracleString":
  258. oravalue = ((OracleString) ovalue).Value;
  259. break;
  260. case "System.Data.OracleClient.OracleNumber":
  261. oravalue = ((OracleNumber) ovalue).Value;
  262. break;
  263. case "System.Data.OracleClient.OracleLob":
  264. OracleLob lob = (OracleLob) ovalue;
  265. oravalue = lob.Value;
  266. lob.Close ();
  267. break;
  268. case "System.Data.OracleClient.OracleDateTime":
  269. oravalue = ((OracleDateTime) ovalue).Value;
  270. break;
  271. case "System.Byte[]":
  272. oravalue = GetHexString((byte[])ovalue);
  273. break;
  274. case "System.Decimal":
  275. //Console.WriteLine(" *** Get Decimal, Int16, Int32, Int64, Float, Double, ...");
  276. decimal dec = reader.GetDecimal (f);
  277. //Console.WriteLine(" GetDecimal: " + dec.ToString ());
  278. oravalue = (object) dec;
  279. /*
  280. try {
  281. reader.GetInt16 (f);
  282. } catch (NotSupportedException e) {
  283. Console.WriteLine (" ** Expected exception caught for GetInt16: NotSupportedException: " + e.Message);
  284. }
  285. try {
  286. long lng = reader.GetInt64 (f);
  287. Console.WriteLine(" GetInt64: " + lng.ToString ());
  288. int n = reader.GetInt32 (f);
  289. Console.WriteLine(" GetInt32: " + n.ToString ());
  290. float flt = reader.GetFloat (f);
  291. Console.WriteLine(" GetFloat: " + flt.ToString ());
  292. double dbl = reader.GetDouble (f);
  293. Console.WriteLine(" GetDouble: " + dbl.ToString ());
  294. } catch (OverflowException oe1) {
  295. Console.WriteLine (" ** Overflow exception for numbers to big or too small: " + oe1.Message);
  296. }
  297. */
  298. break;
  299. default:
  300. oravalue = ovalue.ToString ();
  301. break;
  302. }
  303. sOraDataType = oravalue.GetType ().ToString ();
  304. if (sOraDataType.Equals ("System.Byte[]"))
  305. svalue = GetHexString ((byte[]) oravalue);
  306. else
  307. svalue = oravalue.ToString();
  308. }
  309. sFieldType = reader.GetFieldType(f).ToString();
  310. sDataTypeName = reader.GetDataTypeName(f);
  311. Console.WriteLine(" Field: " + f.ToString());
  312. Console.WriteLine(" Name: " + sname);
  313. Console.WriteLine(" Value: " + svalue);
  314. Console.WriteLine(" Oracle Data Type: " + sOraDataType);
  315. Console.WriteLine(" Data Type: " + sDataType);
  316. Console.WriteLine(" Field Type: " + sFieldType);
  317. Console.WriteLine(" Data Type Name: " + sDataTypeName);
  318. }
  319. }
  320. if(r == 0)
  321. Console.WriteLine(" No data returned.");
  322. }
  323. static void DataAdapterTest (OracleConnection connection)
  324. {
  325. Console.WriteLine(" Create select command...");
  326. OracleCommand command = connection.CreateCommand ();
  327. command.CommandText = "SELECT * FROM EMP";
  328. Console.WriteLine(" Create data adapter...");
  329. OracleDataAdapter adapter = new OracleDataAdapter (command);
  330. Console.WriteLine(" Create DataSet...");
  331. DataSet dataSet = new DataSet ("EMP");
  332. Console.WriteLine(" Fill DataSet via data adapter...");
  333. adapter.Fill (dataSet);
  334. Console.WriteLine(" Get DataTable...");
  335. DataTable table = dataSet.Tables [0];
  336. Console.WriteLine(" Display each row...");
  337. int rowCount = 0;
  338. foreach (DataRow row in table.Rows) {
  339. Console.WriteLine (" row {0}", rowCount + 1);
  340. for (int i = 0; i < table.Columns.Count; i += 1) {
  341. Console.WriteLine (" {0}: {1}", table.Columns [i].ColumnName, row [i]);
  342. }
  343. Console.WriteLine ();
  344. rowCount += 1;
  345. }
  346. }
  347. public static void DataAdapterTest2 (OracleConnection con)
  348. {
  349. DataAdapterTest2_Setup (con);
  350. ReadSimpleTest (con, "SELECT * FROM mono_adapter_test");
  351. GetMetaData (con, "SELECT * FROM mono_adapter_test");
  352. DataAdapterTest2_Insert (con);
  353. ReadSimpleTest (con, "SELECT * FROM mono_adapter_test");
  354. DataAdapterTest2_Update (con);
  355. ReadSimpleTest (con, "SELECT * FROM mono_adapter_test");
  356. DataAdapterTest2_Delete (con);
  357. ReadSimpleTest (con, "SELECT * FROM mono_adapter_test");
  358. }
  359. public static void GetMetaData (OracleConnection con, string sql)
  360. {
  361. OracleCommand cmd = null;
  362. OracleDataReader rdr = null;
  363. cmd = con.CreateCommand();
  364. cmd.CommandText = sql;
  365. Console.WriteLine("Read Schema With KeyInfo");
  366. rdr = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly);
  367. DataTable dt;
  368. dt = rdr.GetSchemaTable();
  369. foreach (DataRow schemaRow in dt.Rows) {
  370. foreach (DataColumn schemaCol in dt.Columns) {
  371. Console.WriteLine(schemaCol.ColumnName +
  372. " = " +
  373. schemaRow[schemaCol]);
  374. Console.WriteLine("---Type: " + schemaRow[schemaCol].GetType ().ToString());
  375. }
  376. Console.WriteLine("");
  377. }
  378. Console.WriteLine("Read Schema with No KeyInfo");
  379. rdr = cmd.ExecuteReader();
  380. dt = rdr.GetSchemaTable();
  381. foreach (DataRow schemaRow in dt.Rows) {
  382. foreach (DataColumn schemaCol in dt.Columns) {
  383. Console.WriteLine(schemaCol.ColumnName +
  384. " = " +
  385. schemaRow[schemaCol]);
  386. Console.WriteLine("---Type: " + schemaRow[schemaCol].GetType ().ToString());
  387. Console.WriteLine();
  388. }
  389. }
  390. }
  391. public static void DataAdapterTest2_Setup (OracleConnection con)
  392. {
  393. Console.WriteLine (" Drop table mono_adapter_test ...");
  394. try {
  395. OracleCommand cmd2 = con.CreateCommand ();
  396. cmd2.CommandText = "DROP TABLE mono_adapter_test";
  397. cmd2.ExecuteNonQuery ();
  398. }
  399. catch (OracleException oe1) {
  400. // ignore if table already exists
  401. }
  402. OracleCommand cmd = null;
  403. int rowsAffected = 0;
  404. Console.WriteLine(" Creating table mono_adapter_test...");
  405. cmd = new OracleCommand ();
  406. cmd.Connection = con;
  407. cmd.CommandText = "CREATE TABLE mono_adapter_test ( " +
  408. " varchar2_value VarChar2(32), " +
  409. " number_whole_value Number(18) PRIMARY KEY, " +
  410. " number_scaled_value Number(18,2), " +
  411. " number_integer_value Integer, " +
  412. " float_value Float, " +
  413. " date_value Date, " +
  414. " clob_value Clob, " +
  415. " blob_value Blob ) ";
  416. // FIXME: char_value does not work
  417. /*
  418. cmd.CommandText = "CREATE TABLE mono_adapter_test ( " +
  419. " varchar2_value VarChar2(32), " +
  420. " number_whole_value Number(18) PRIMARY KEY, " +
  421. " number_scaled_value Number(18,2), " +
  422. " number_integer_value Integer, " +
  423. " float_value Float, " +
  424. " date_value Date, " +
  425. " char_value Char(32), " +
  426. " clob_value Clob, " +
  427. " blob_value Blob ) ";
  428. */
  429. rowsAffected = cmd.ExecuteNonQuery();
  430. Console.WriteLine(" Begin Trans for table mono_adapter_test...");
  431. OracleTransaction trans = con.BeginTransaction ();
  432. Console.WriteLine(" Inserting value into mono_adapter_test...");
  433. cmd = new OracleCommand();
  434. cmd.Connection = con;
  435. cmd.Transaction = trans;
  436. cmd.CommandText = "INSERT INTO mono_adapter_test " +
  437. " ( varchar2_value, " +
  438. " number_whole_value, " +
  439. " number_scaled_value, " +
  440. " number_integer_value, " +
  441. " float_value, " +
  442. " date_value, " +
  443. " clob_value, " +
  444. " blob_value " +
  445. ") " +
  446. " VALUES( " +
  447. " 'Mono', " +
  448. " 11, " +
  449. " 456.78, " +
  450. " 8765, " +
  451. " 235.2, " +
  452. " TO_DATE( '2004-12-31', 'YYYY-MM-DD' ), " +
  453. " EMPTY_CLOB(), " +
  454. " EMPTY_BLOB() " +
  455. ")";
  456. /*
  457. cmd.CommandText = "INSERT INTO mono_adapter_test " +
  458. " ( varchar2_value, " +
  459. " number_whole_value, " +
  460. " number_scaled_value, " +
  461. " number_integer_value, " +
  462. " float_value, " +
  463. " date_value, " +
  464. " char_value, " +
  465. " clob_value, " +
  466. " blob_value " +
  467. ") " +
  468. " VALUES( " +
  469. " 'Mono', " +
  470. " 11, " +
  471. " 456.78, " +
  472. " 8765, " +
  473. " 235.2, " +
  474. " TO_DATE( '2004-12-31', 'YYYY-MM-DD' ), " +
  475. " 'US', " +
  476. " EMPTY_CLOB(), " +
  477. " EMPTY_BLOB() " +
  478. ")";
  479. */
  480. rowsAffected = cmd.ExecuteNonQuery();
  481. Console.WriteLine(" Select/Update CLOB columns on table mono_adapter_test...");
  482. // update BLOB and CLOB columns
  483. OracleCommand select = con.CreateCommand ();
  484. select.Transaction = trans;
  485. select.CommandText = "SELECT CLOB_VALUE, BLOB_VALUE FROM mono_adapter_test FOR UPDATE";
  486. OracleDataReader reader = select.ExecuteReader ();
  487. if (!reader.Read ())
  488. Console.WriteLine ("ERROR: RECORD NOT FOUND");
  489. // update clob_value
  490. Console.WriteLine(" Update CLOB column on table mono_adapter_test...");
  491. OracleLob clob = reader.GetOracleLob (0);
  492. byte[] bytes = null;
  493. UnicodeEncoding encoding = new UnicodeEncoding ();
  494. bytes = encoding.GetBytes ("Mono is fun!");
  495. clob.Write (bytes, 0, bytes.Length);
  496. clob.Close ();
  497. // update blob_value
  498. Console.WriteLine(" Update BLOB column on table mono_adapter_test...");
  499. OracleLob blob = reader.GetOracleLob (1);
  500. bytes = new byte[6] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x036 };
  501. blob.Write (bytes, 0, bytes.Length);
  502. blob.Close ();
  503. Console.WriteLine(" Commit trans for table mono_adapter_test...");
  504. trans.Commit ();
  505. CommitCursor (con);
  506. }
  507. public static void DataAdapterTest2_Insert (OracleConnection con)
  508. {
  509. Console.WriteLine("================================");
  510. Console.WriteLine("=== Adapter Insert =============");
  511. Console.WriteLine("================================");
  512. OracleTransaction transaction = con.BeginTransaction ();
  513. Console.WriteLine(" Create adapter...");
  514. OracleDataAdapter da = new OracleDataAdapter("select * from mono_adapter_test", con);
  515. da.SelectCommand.Transaction = transaction;
  516. Console.WriteLine(" Create command builder...");
  517. OracleCommandBuilder mycb = new OracleCommandBuilder(da);
  518. Console.WriteLine(" Create data set ...");
  519. DataSet ds = new DataSet();
  520. Console.WriteLine(" Fill data set via adapter...");
  521. da.Fill(ds, "mono_adapter_test");
  522. Console.WriteLine(" New Row...");
  523. DataRow myRow;
  524. myRow = ds.Tables["mono_adapter_test"].NewRow();
  525. byte[] bytes = new byte[] { 0x45,0x46,0x47,0x48,0x49,0x50 };
  526. Console.WriteLine(" Set values in the new DataRow...");
  527. myRow["varchar2_value"] = "OracleClient";
  528. myRow["number_whole_value"] = 22;
  529. myRow["number_scaled_value"] = 12.34;
  530. myRow["number_integer_value"] = 456;
  531. myRow["float_value"] = 98.76;
  532. myRow["date_value"] = new DateTime(2001,07,09);
  533. Console.WriteLine(" *** FIXME; char value not working");
  534. //myRow["char_value"] = "Romeo";
  535. myRow["clob_value"] = "clobtest";
  536. myRow["blob_value"] = bytes;
  537. Console.WriteLine(" Add DataRow to DataTable...");
  538. ds.Tables["mono_adapter_test"].Rows.Add(myRow);
  539. Console.WriteLine("da.Update(ds...");
  540. da.Update(ds, "mono_adapter_test");
  541. transaction.Commit();
  542. }
  543. public static void DataAdapterTest2_Update (OracleConnection con)
  544. {
  545. Console.WriteLine("================================");
  546. Console.WriteLine("=== Adapter Update =============");
  547. Console.WriteLine("================================");
  548. OracleTransaction transaction = con.BeginTransaction ();
  549. Console.WriteLine(" Create adapter...");
  550. OracleCommand selectCmd = con.CreateCommand ();
  551. selectCmd.Transaction = transaction;
  552. selectCmd.CommandText = "SELECT * FROM mono_adapter_test";
  553. OracleDataAdapter da = new OracleDataAdapter(selectCmd);
  554. Console.WriteLine(" Create command builder...");
  555. OracleCommandBuilder mycb = new OracleCommandBuilder(da);
  556. Console.WriteLine(" Create data set ...");
  557. DataSet ds = new DataSet();
  558. Console.WriteLine(" Set missing schema action...");
  559. Console.WriteLine(" Fill data set via adapter...");
  560. da.Fill(ds, "mono_adapter_test");
  561. DataRow myRow;
  562. Console.WriteLine(" New Row...");
  563. myRow = ds.Tables["mono_adapter_test"].Rows[0];
  564. Console.WriteLine("Tables Count: " + ds.Tables.Count.ToString());
  565. DataTable table = ds.Tables["mono_adapter_test"];
  566. DataRowCollection rows;
  567. rows = table.Rows;
  568. Console.WriteLine(" Row Count: " + rows.Count.ToString());
  569. myRow = rows[0];
  570. byte[] bytes = new byte[] { 0x62,0x63,0x64,0x65,0x66,0x67 };
  571. Console.WriteLine(" Set values in the new DataRow...");
  572. myRow["varchar2_value"] = "Super Power!";
  573. myRow["number_scaled_value"] = 12.35;
  574. myRow["number_integer_value"] = 457;
  575. myRow["float_value"] = 198.76;
  576. myRow["date_value"] = new DateTime(2002,08,09);
  577. //myRow["char_value"] = "Juliet";
  578. myRow["clob_value"] = "this is a clob";
  579. myRow["blob_value"] = bytes;
  580. Console.WriteLine("da.Update(ds...");
  581. da.Update(ds, "mono_adapter_test");
  582. transaction.Commit();
  583. }
  584. public static void DataAdapterTest2_Delete (OracleConnection con)
  585. {
  586. Console.WriteLine("================================");
  587. Console.WriteLine("=== Adapter Delete =============");
  588. Console.WriteLine("================================");
  589. OracleTransaction transaction = con.BeginTransaction ();
  590. Console.WriteLine(" Create adapter...");
  591. OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM mono_adapter_test", con);
  592. Console.WriteLine(" Create command builder...");
  593. OracleCommandBuilder mycb = new OracleCommandBuilder(da);
  594. Console.WriteLine(" set transr...");
  595. da.SelectCommand.Transaction = transaction;
  596. Console.WriteLine(" Create data set ...");
  597. DataSet ds = new DataSet();
  598. Console.WriteLine("Fill data set via adapter...");
  599. da.Fill(ds, "mono_adapter_test");
  600. Console.WriteLine("delete row...");
  601. ds.Tables["mono_adapter_test"].Rows[0].Delete();
  602. Console.WriteLine("da.Update(table...");
  603. da.Update(ds, "mono_adapter_test");
  604. Console.WriteLine("Commit...");
  605. transaction.Commit();
  606. }
  607. static void TestNonQueryUsingExecuteReader(OracleConnection con)
  608. {
  609. OracleDataReader reader = null;
  610. OracleTransaction trans = null;
  611. Console.WriteLine(" drop table mono_adapter_test...");
  612. OracleCommand cmd = con.CreateCommand();
  613. cmd.CommandText = "DROP TABLE MONO_ADAPTER_TEST";
  614. trans = con.BeginTransaction();
  615. cmd.Transaction = trans;
  616. try {
  617. reader = cmd.ExecuteReader();
  618. Console.WriteLine(" RowsAffected before read: " + reader.RecordsAffected.ToString());
  619. reader.Read();
  620. Console.WriteLine(" RowsAffected after read: " + reader.RecordsAffected.ToString());
  621. reader.Close();
  622. Console.WriteLine(" RowsAffected after close: " + reader.RecordsAffected.ToString());
  623. trans.Commit();
  624. }
  625. catch(OracleException e) {
  626. Console.WriteLine(" OracleException caught: " + e.Message);
  627. trans.Commit();
  628. }
  629. Console.WriteLine(" Create table mono_adapter_test...");
  630. cmd.CommandText = "CREATE TABLE MONO_ADAPTER_TEST ( " +
  631. " varchar2_value VarChar2(32), " +
  632. " number_whole_value Number(18,0) PRIMARY KEY ) ";
  633. trans = con.BeginTransaction();
  634. cmd.Transaction = trans;
  635. reader = cmd.ExecuteReader();
  636. Console.WriteLine(" RowsAffected before read: " + reader.RecordsAffected.ToString());
  637. reader.Read();
  638. Console.WriteLine(" RowsAffected after read: " + reader.RecordsAffected.ToString());
  639. reader.Close();
  640. Console.WriteLine(" RowsAffected after close: " + reader.RecordsAffected.ToString());
  641. trans.Commit();
  642. Console.WriteLine("Insert into table mono_adapter_test...");
  643. string sql =
  644. "INSERT INTO MONO_ADAPTER_TEST " +
  645. "(VARCHAR2_VALUE,NUMBER_WHOLE_VALUE) " +
  646. "VALUES(:p1,:p2)";
  647. OracleCommand cmd2 = con.CreateCommand();
  648. trans = con.BeginTransaction();
  649. cmd2.Transaction = trans;
  650. cmd2.CommandText = sql;
  651. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.VarChar, 32);
  652. myParameter1.Direction = ParameterDirection.Input;
  653. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.Number);
  654. myParameter2.Direction = ParameterDirection.Input;
  655. myParameter2.Value = 182;
  656. myParameter1.Value = "Mono";
  657. cmd2.Parameters.Add (myParameter1);
  658. cmd2.Parameters.Add (myParameter2);
  659. // insert 1 record
  660. reader = cmd2.ExecuteReader();
  661. Console.WriteLine(" RowsAffected before read: " + reader.RecordsAffected.ToString());
  662. reader.Read();
  663. Console.WriteLine(" RowsAffected after read: " + reader.RecordsAffected.ToString());
  664. reader.Close();
  665. Console.WriteLine(" RowsAffected after close: " + reader.RecordsAffected.ToString());
  666. // insert another record
  667. Console.WriteLine(" Insert another record...");
  668. myParameter2.Value = 183;
  669. myParameter1.Value = "Oracle";
  670. reader = cmd2.ExecuteReader();
  671. Console.WriteLine(" RowsAffected before read: " + reader.RecordsAffected.ToString());
  672. reader.Read();
  673. Console.WriteLine(" RowsAffected after read: " + reader.RecordsAffected.ToString());
  674. reader.Close();
  675. Console.WriteLine(" RowsAffected after close: " + reader.RecordsAffected.ToString());
  676. trans.Commit();
  677. trans = null;
  678. ReadSimpleTest(con, "SELECT * FROM MONO_ADAPTER_TEST");
  679. }
  680. static void CommitCursor (OracleConnection con)
  681. {
  682. OracleCommand cmd = con.CreateCommand ();
  683. cmd.CommandText = "COMMIT";
  684. cmd.ExecuteNonQuery ();
  685. cmd.Dispose ();
  686. cmd = null;
  687. }
  688. static void RollbackTest (OracleConnection connection)
  689. {
  690. OracleTransaction transaction = connection.BeginTransaction ();
  691. OracleCommand insert = connection.CreateCommand ();
  692. insert.Transaction = transaction;
  693. insert.CommandText = "INSERT INTO EMP (EMPNO, ENAME, JOB) VALUES (8787, 'T Coleman', 'Monoist')";
  694. Console.WriteLine (" Inserting record ...");
  695. insert.ExecuteNonQuery ();
  696. OracleCommand select = connection.CreateCommand ();
  697. select.CommandText = "SELECT COUNT(*) FROM EMP WHERE EMPNO = 8787";
  698. select.Transaction = transaction;
  699. OracleDataReader reader = select.ExecuteReader ();
  700. reader.Read ();
  701. Console.WriteLine (" Row count SHOULD BE 1, VALUE IS {0}", reader.GetValue (0));
  702. reader.Close ();
  703. Console.WriteLine (" Rolling back transaction ...");
  704. transaction.Rollback ();
  705. select = connection.CreateCommand ();
  706. select.CommandText = "SELECT COUNT(*) FROM EMP WHERE EMPNO = 8787";
  707. reader = select.ExecuteReader ();
  708. reader.Read ();
  709. Console.WriteLine (" Row count SHOULD BE 0, VALUE IS {0}", reader.GetValue (0));
  710. reader.Close ();
  711. }
  712. static void CommitTest (OracleConnection connection)
  713. {
  714. OracleTransaction transaction = connection.BeginTransaction ();
  715. OracleCommand insert = connection.CreateCommand ();
  716. insert.Transaction = transaction;
  717. insert.CommandText = "INSERT INTO EMP (EMPNO, ENAME, JOB) VALUES (8787, 'T Coleman', 'Monoist')";
  718. Console.WriteLine (" Inserting record ...");
  719. insert.ExecuteNonQuery ();
  720. OracleCommand select = connection.CreateCommand ();
  721. select.CommandText = "SELECT COUNT(*) FROM EMP WHERE EMPNO = 8787";
  722. select.Transaction = transaction;
  723. Console.WriteLine (" Row count SHOULD BE 1, VALUE IS {0}", select.ExecuteScalar ());
  724. Console.WriteLine (" Committing transaction ...");
  725. transaction.Commit ();
  726. select = connection.CreateCommand ();
  727. select.CommandText = "SELECT COUNT(*) FROM EMP WHERE EMPNO = 8787";
  728. Console.WriteLine ("Row count SHOULD BE 1, VALUE IS {0}", select.ExecuteScalar ());
  729. transaction = connection.BeginTransaction ();
  730. OracleCommand delete = connection.CreateCommand ();
  731. delete.Transaction = transaction;
  732. delete.CommandText = "DELETE FROM EMP WHERE EMPNO = 8787";
  733. delete.ExecuteNonQuery ();
  734. transaction.Commit ();
  735. }
  736. public static void ParameterTest2 (OracleConnection connection)
  737. {
  738. Console.WriteLine(" Setting NLS_DATE_FORMAT...");
  739. OracleCommand cmd2 = connection.CreateCommand();
  740. cmd2.CommandText = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
  741. cmd2.ExecuteNonQuery ();
  742. Console.WriteLine(" Drop table MONO_TEST_TABLE2...");
  743. try {
  744. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE7";
  745. cmd2.ExecuteNonQuery ();
  746. }
  747. catch(OracleException oe1) {
  748. // ignore if table already exists
  749. }
  750. Console.WriteLine(" Create table MONO_TEST_TABLE7...");
  751. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE7(" +
  752. " COL1 VARCHAR2(8) NOT NULL, " +
  753. " COL2 VARCHAR2(32), " +
  754. " COL3 NUMBER(18,2), " +
  755. " COL4 NUMBER(18,2), " +
  756. " COL5 DATE NOT NULL, " +
  757. " COL6 DATE, " +
  758. " COL7 BLOB NOT NULL, " +
  759. " COL8 BLOB, " +
  760. " COL9 CLOB NOT NULL, " +
  761. " COL10 CLOB " +
  762. ")";
  763. cmd2.ExecuteNonQuery ();
  764. Console.WriteLine(" COMMIT...");
  765. cmd2.CommandText = "COMMIT";
  766. cmd2.ExecuteNonQuery ();
  767. Console.WriteLine(" create insert command...");
  768. OracleTransaction trans = connection.BeginTransaction ();
  769. OracleCommand cmd = connection.CreateCommand ();
  770. cmd.Transaction = trans;
  771. cmd.CommandText = "INSERT INTO MONO_TEST_TABLE7 " +
  772. "(COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10) " +
  773. "VALUES(:P1,:P2,:P3,:P4,:P5,:P6,:P7,:P8,:P9,:P10)";
  774. Console.WriteLine(" Add parameters...");
  775. OracleParameter parm1 = cmd.Parameters.Add (":P1", OracleType.VarChar, 8);
  776. OracleParameter parm2 = cmd.Parameters.Add (":P2", OracleType.VarChar, 32);
  777. OracleParameter parm3 = cmd.Parameters.Add (":P3", OracleType.Number);
  778. OracleParameter parm4 = cmd.Parameters.Add (":P4", OracleType.Number);
  779. OracleParameter parm5 = cmd.Parameters.Add (":P5", OracleType.DateTime);
  780. OracleParameter parm6 = cmd.Parameters.Add (":P6", OracleType.DateTime);
  781. // FIXME: fix BLOBs and CLOBs in OracleParameter
  782. OracleParameter parm7 = cmd.Parameters.Add (":P7", OracleType.Blob);
  783. OracleParameter parm8 = cmd.Parameters.Add (":P8", OracleType.Blob);
  784. OracleParameter parm9 = cmd.Parameters.Add (":P9", OracleType.Clob);
  785. OracleParameter parm10 = cmd.Parameters.Add (":P10", OracleType.Clob);
  786. // TODO: implement out, return, and ref parameters
  787. string s = "Mono";
  788. decimal d = 123456789012345.678M;
  789. DateTime dt = DateTime.Now;
  790. string clob = "Clob";
  791. byte[] blob = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
  792. Console.WriteLine(" Set Values...");
  793. parm1.Value = s;
  794. parm2.Value = DBNull.Value;
  795. parm3.Value = d;
  796. parm4.Value = DBNull.Value;
  797. parm5.Value = dt;
  798. parm6.Value = DBNull.Value;
  799. parm7.Value = blob;
  800. parm8.Value = DBNull.Value;
  801. parm9.Value = clob;
  802. parm10.Value = DBNull.Value;
  803. Console.WriteLine(" ExecuteNonQuery...");
  804. cmd.ExecuteNonQuery ();
  805. trans.Commit();
  806. }
  807. public static void ParameterTest (OracleConnection connection)
  808. {
  809. Console.WriteLine(" Setting NLS_DATE_FORMAT...");
  810. OracleCommand cmd2 = connection.CreateCommand();
  811. cmd2.CommandText = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
  812. cmd2.ExecuteNonQuery ();
  813. Console.WriteLine(" Drop table MONO_TEST_TABLE2...");
  814. try {
  815. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE7";
  816. cmd2.ExecuteNonQuery ();
  817. }
  818. catch(OracleException oe1) {
  819. // ignore if table already exists
  820. }
  821. Console.WriteLine(" Create table MONO_TEST_TABLE7...");
  822. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE7(" +
  823. " COL1 VARCHAR2(8) NOT NULL, " +
  824. " COL2 VARCHAR2(32), " +
  825. " COL3 NUMBER(18,2) NOT NULL, " +
  826. " COL4 NUMBER(18,2), " +
  827. " COL5 DATE NOT NULL, " +
  828. " COL6 DATE, " +
  829. " COL7 BLOB NOT NULL, " +
  830. " COL8 BLOB, " +
  831. " COL9 CLOB NOT NULL, " +
  832. " COL10 CLOB " +
  833. ")";
  834. cmd2.ExecuteNonQuery ();
  835. Console.WriteLine(" COMMIT...");
  836. cmd2.CommandText = "COMMIT";
  837. cmd2.ExecuteNonQuery ();
  838. Console.WriteLine(" create insert command...");
  839. OracleTransaction trans = connection.BeginTransaction ();
  840. OracleCommand cmd = connection.CreateCommand ();
  841. cmd.Transaction = trans;
  842. cmd.CommandText = "INSERT INTO MONO_TEST_TABLE7 " +
  843. "(COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10) " +
  844. "VALUES(:P1,:P2,:P3,:P4,:P5,:P6,:P7,:P8,:P9,:P10)";
  845. Console.WriteLine(" Add parameters...");
  846. OracleParameter parm1 = cmd.Parameters.Add (":P1", OracleType.VarChar, 8);
  847. OracleParameter parm2 = cmd.Parameters.Add (":P2", OracleType.VarChar, 32);
  848. OracleParameter parm3 = cmd.Parameters.Add (":P3", OracleType.Number);
  849. OracleParameter parm4 = cmd.Parameters.Add (":P4", OracleType.Number);
  850. OracleParameter parm5 = cmd.Parameters.Add (":P5", OracleType.DateTime);
  851. OracleParameter parm6 = cmd.Parameters.Add (":P6", OracleType.DateTime);
  852. // FIXME: fix BLOBs and CLOBs in OracleParameter
  853. OracleParameter parm7 = cmd.Parameters.Add (":P7", OracleType.Blob);
  854. OracleParameter parm8 = cmd.Parameters.Add (":P8", OracleType.Blob);
  855. OracleParameter parm9 = cmd.Parameters.Add (":P9", OracleType.Clob);
  856. OracleParameter parm10 = cmd.Parameters.Add (":P10", OracleType.Clob);
  857. // TODO: implement out, return, and ref parameters
  858. string s = "Mono";
  859. decimal d = 123456789012345.678M;
  860. DateTime dt = DateTime.Now;
  861. string clob = "Clob";
  862. byte[] blob = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
  863. Console.WriteLine(" Set Values...");
  864. parm1.Value = s;
  865. parm2.Value = DBNull.Value;
  866. parm3.Value = d;
  867. parm4.Value = DBNull.Value;
  868. parm5.Value = dt;
  869. parm6.Value = DBNull.Value;
  870. parm7.Value = blob;
  871. parm8.Value = DBNull.Value;
  872. parm9.Value = clob;
  873. parm10.Value = DBNull.Value;
  874. Console.WriteLine(" ExecuteNonQuery...");
  875. cmd.ExecuteNonQuery ();
  876. trans.Commit();
  877. }
  878. public static void CLOBTest (OracleConnection connection)
  879. {
  880. Console.WriteLine (" BEGIN TRANSACTION ...");
  881. OracleTransaction transaction = connection.BeginTransaction ();
  882. Console.WriteLine (" Drop table CLOBTEST ...");
  883. try {
  884. OracleCommand cmd2 = connection.CreateCommand ();
  885. cmd2.Transaction = transaction;
  886. cmd2.CommandText = "DROP TABLE CLOBTEST";
  887. cmd2.ExecuteNonQuery ();
  888. }
  889. catch (OracleException oe1) {
  890. // ignore if table already exists
  891. }
  892. Console.WriteLine (" CREATE TABLE ...");
  893. OracleCommand create = connection.CreateCommand ();
  894. create.Transaction = transaction;
  895. create.CommandText = "CREATE TABLE CLOBTEST (CLOB_COLUMN CLOB)";
  896. create.ExecuteNonQuery ();
  897. Console.WriteLine (" INSERT RECORD ...");
  898. OracleCommand insert = connection.CreateCommand ();
  899. insert.Transaction = transaction;
  900. insert.CommandText = "INSERT INTO CLOBTEST VALUES (EMPTY_CLOB())";
  901. insert.ExecuteNonQuery ();
  902. OracleCommand select = connection.CreateCommand ();
  903. select.Transaction = transaction;
  904. select.CommandText = "SELECT CLOB_COLUMN FROM CLOBTEST FOR UPDATE";
  905. Console.WriteLine (" SELECTING A CLOB (CHARACTER) VALUE FROM CLOBTEST");
  906. OracleDataReader reader = select.ExecuteReader ();
  907. if (!reader.Read ())
  908. Console.WriteLine ("ERROR: RECORD NOT FOUND");
  909. Console.WriteLine (" TESTING OracleLob OBJECT ...");
  910. OracleLob lob = reader.GetOracleLob (0);
  911. Console.WriteLine (" LENGTH: {0}", lob.Length);
  912. Console.WriteLine (" CHUNK SIZE: {0}", lob.ChunkSize);
  913. UnicodeEncoding encoding = new UnicodeEncoding ();
  914. byte[] value = new byte [lob.Length * 2];
  915. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  916. Console.WriteLine (" UPDATING VALUE TO 'TEST ME!'");
  917. value = encoding.GetBytes ("TEST ME!");
  918. lob.Write (value, 0, value.Length);
  919. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  920. Console.WriteLine (" RE-READ VALUE...");
  921. lob.Seek (1, SeekOrigin.Begin);
  922. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  923. value = new byte [lob.Length * 2];
  924. lob.Read (value, 0, value.Length);
  925. Console.WriteLine (" VALUE: {0}", encoding.GetString (value));
  926. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  927. Console.WriteLine (" CLOSE OracleLob...");
  928. lob.Close ();
  929. Console.WriteLine (" CLOSING READER...");
  930. reader.Close ();
  931. transaction.Commit ();
  932. }
  933. public static void BLOBTest (OracleConnection connection)
  934. {
  935. Console.WriteLine (" BEGIN TRANSACTION ...");
  936. OracleTransaction transaction = connection.BeginTransaction ();
  937. Console.WriteLine (" Drop table BLOBTEST ...");
  938. try {
  939. OracleCommand cmd2 = connection.CreateCommand ();
  940. cmd2.Transaction = transaction;
  941. cmd2.CommandText = "DROP TABLE BLOBTEST";
  942. cmd2.ExecuteNonQuery ();
  943. }
  944. catch (OracleException oe1) {
  945. // ignore if table already exists
  946. }
  947. Console.WriteLine (" CREATE TABLE ...");
  948. OracleCommand create = connection.CreateCommand ();
  949. create.Transaction = transaction;
  950. create.CommandText = "CREATE TABLE BLOBTEST (BLOB_COLUMN BLOB)";
  951. create.ExecuteNonQuery ();
  952. Console.WriteLine (" INSERT RECORD ...");
  953. OracleCommand insert = connection.CreateCommand ();
  954. insert.Transaction = transaction;
  955. insert.CommandText = "INSERT INTO BLOBTEST VALUES (EMPTY_BLOB())";
  956. insert.ExecuteNonQuery ();
  957. OracleCommand select = connection.CreateCommand ();
  958. select.Transaction = transaction;
  959. select.CommandText = "SELECT BLOB_COLUMN FROM BLOBTEST FOR UPDATE";
  960. Console.WriteLine (" SELECTING A BLOB (Binary) VALUE FROM BLOBTEST");
  961. OracleDataReader reader = select.ExecuteReader ();
  962. if (!reader.Read ())
  963. Console.WriteLine ("ERROR: RECORD NOT FOUND");
  964. Console.WriteLine (" TESTING OracleLob OBJECT ...");
  965. OracleLob lob = reader.GetOracleLob (0);
  966. byte[] value = null;
  967. string bvalue = "";
  968. Console.WriteLine (" UPDATING VALUE");
  969. byte[] bytes = new byte[6];
  970. bytes[0] = 0x31;
  971. bytes[1] = 0x32;
  972. bytes[2] = 0x33;
  973. bytes[3] = 0x34;
  974. bytes[4] = 0x35;
  975. bytes[5] = 0x36;
  976. lob.Write (bytes, 0, bytes.Length);
  977. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  978. Console.WriteLine (" RE-READ VALUE...");
  979. lob.Seek (1, SeekOrigin.Begin);
  980. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  981. value = new byte [lob.Length];
  982. lob.Read (value, 0, value.Length);
  983. bvalue = "";
  984. if (value.GetType ().ToString ().Equals ("System.Byte[]"))
  985. bvalue = GetHexString (value);
  986. Console.WriteLine (" Bytes: " + bvalue);
  987. Console.WriteLine (" CURRENT POSITION: {0}", lob.Position);
  988. Console.WriteLine (" CLOSE OracleLob...");
  989. lob.Close ();
  990. Console.WriteLine (" CLOSING READER...");
  991. reader.Close ();
  992. transaction.Commit ();
  993. }
  994. static void Wait(string msg)
  995. {
  996. Console.WriteLine(msg);
  997. if (msg.Equals(""))
  998. Console.WriteLine("Waiting... Press Enter to continue...");
  999. Console.ReadLine();
  1000. }
  1001. // use this function to read a byte array into a string
  1002. // for easy display of binary data, such as, a BLOB value
  1003. public static string GetHexString (byte[] bytes)
  1004. {
  1005. string bvalue = "";
  1006. StringBuilder sb2 = new StringBuilder();
  1007. for (int z = 0; z < bytes.Length; z++) {
  1008. byte byt = bytes[z];
  1009. sb2.Append (byt.ToString("x"));
  1010. }
  1011. if (sb2.Length > 0)
  1012. bvalue = "0x" + sb2.ToString ();
  1013. return bvalue;
  1014. }
  1015. static void StoredProcedureTest1 (OracleConnection con)
  1016. {
  1017. // test stored procedure with no parameters
  1018. OracleCommand cmd2 = con.CreateCommand ();
  1019. Console.WriteLine(" Drop table MONO_TEST_TABLE1...");
  1020. try {
  1021. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE1";
  1022. cmd2.ExecuteNonQuery ();
  1023. }
  1024. catch(OracleException oe1) {
  1025. // ignore if table did not exist
  1026. }
  1027. Console.WriteLine(" Drop procedure SP_TEST1...");
  1028. try {
  1029. cmd2.CommandText = "DROP PROCEDURE SP_TEST1";
  1030. cmd2.ExecuteNonQuery ();
  1031. }
  1032. catch(OracleException oe1) {
  1033. // ignore if procedure did not exist
  1034. }
  1035. Console.WriteLine(" Create table MONO_TEST_TABLE1...");
  1036. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE1 (" +
  1037. " COL1 VARCHAR2(8), "+
  1038. " COL2 VARCHAR2(32))";
  1039. cmd2.ExecuteNonQuery ();
  1040. Console.WriteLine(" Create stored procedure SP_TEST1...");
  1041. cmd2.CommandText = "CREATE PROCEDURE SP_TEST1 " +
  1042. " IS " +
  1043. " BEGIN " +
  1044. " INSERT INTO MONO_TEST_TABLE1 (COL1,COL2) VALUES ('aaa','bbbb');" +
  1045. " COMMIT;" +
  1046. " END;";
  1047. cmd2.ExecuteNonQuery ();
  1048. Console.WriteLine("COMMIT...");
  1049. cmd2.CommandText = "COMMIT";
  1050. cmd2.ExecuteNonQuery ();
  1051. Console.WriteLine(" Call stored procedure sp_test1...");
  1052. OracleCommand cmd3 = con.CreateCommand ();
  1053. cmd3.CommandType = CommandType.StoredProcedure;
  1054. cmd3.CommandText = "sp_test1";
  1055. cmd3.ExecuteNonQuery ();
  1056. }
  1057. static void StoredProcedureTest2 (OracleConnection con)
  1058. {
  1059. // test stored procedure with 2 parameters
  1060. Console.WriteLine(" Drop table MONO_TEST_TABLE2...");
  1061. OracleCommand cmd2 = con.CreateCommand ();
  1062. try {
  1063. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE2";
  1064. cmd2.ExecuteNonQuery ();
  1065. }
  1066. catch(OracleException oe1) {
  1067. // ignore if table already exists
  1068. }
  1069. Console.WriteLine(" Drop procedure SP_TEST2...");
  1070. try {
  1071. cmd2.CommandText = "DROP PROCEDURE SP_TEST2";
  1072. cmd2.ExecuteNonQuery ();
  1073. }
  1074. catch(OracleException oe1) {
  1075. // ignore if table already exists
  1076. }
  1077. Console.WriteLine(" Create table MONO_TEST_TABLE2...");
  1078. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE2 (" +
  1079. " COL1 VARCHAR2(8), "+
  1080. " COL2 VARCHAR2(32))";
  1081. cmd2.ExecuteNonQuery ();
  1082. Console.WriteLine(" Create stored procedure SP_TEST2...");
  1083. cmd2.CommandText = "CREATE PROCEDURE SP_TEST2(parm1 VARCHAR2,parm2 VARCHAR2) " +
  1084. " IS " +
  1085. " BEGIN " +
  1086. " INSERT INTO MONO_TEST_TABLE2 (COL1,COL2) VALUES (parm1,parm2);" +
  1087. " COMMIT;" +
  1088. " END;";
  1089. cmd2.ExecuteNonQuery ();
  1090. Console.WriteLine(" COMMIT...");
  1091. cmd2.CommandText = "COMMIT";
  1092. cmd2.ExecuteNonQuery ();
  1093. Console.WriteLine(" Call stored procedure SP_TEST2 with two parameters...");
  1094. OracleCommand cmd3 = con.CreateCommand ();
  1095. cmd3.CommandType = CommandType.StoredProcedure;
  1096. cmd3.CommandText = "sp_test2";
  1097. OracleParameter myParameter1 = new OracleParameter("parm1", OracleType.VarChar);
  1098. myParameter1.Value = "yyy13";
  1099. myParameter1.Size = 8;
  1100. myParameter1.Direction = ParameterDirection.Input;
  1101. OracleParameter myParameter2 = new OracleParameter("parm2", OracleType.VarChar);
  1102. myParameter2.Value = "iii13";
  1103. myParameter2.Size = 32;
  1104. myParameter2.Direction = ParameterDirection.Input;
  1105. cmd3.Parameters.Add (myParameter1);
  1106. cmd3.Parameters.Add (myParameter2);
  1107. cmd3.ExecuteNonQuery ();
  1108. }
  1109. static void OutParmTest1 (OracleConnection con)
  1110. {
  1111. // test stored procedure with 2 parameters
  1112. // 1. input varchar2
  1113. // 2. output varchar
  1114. OracleCommand cmd2 = null;
  1115. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST1...");
  1116. try {
  1117. cmd2 = con.CreateCommand ();
  1118. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST1";
  1119. cmd2.ExecuteNonQuery ();
  1120. }
  1121. catch(OracleException oe1) {
  1122. // ignore if table already exists
  1123. }
  1124. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST1...");
  1125. // stored procedure concatenates strings
  1126. cmd2.CommandText =
  1127. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM1(parm1 IN VARCHAR2,parm2 OUT VARCHAR2) " +
  1128. "IS " +
  1129. "BEGIN " +
  1130. " parm2 := 'one' || parm1 || 'three';" +
  1131. "END;";
  1132. cmd2.ExecuteNonQuery ();
  1133. Console.WriteLine(" COMMIT...");
  1134. cmd2.CommandText = "COMMIT";
  1135. cmd2.ExecuteNonQuery ();
  1136. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM1 with two parameters...");
  1137. OracleCommand cmd3 = con.CreateCommand ();
  1138. cmd3.CommandType = CommandType.Text;
  1139. cmd3.CommandText =
  1140. "BEGIN " +
  1141. " SP_TESTOUTPARM1(:p1, :p2);" +
  1142. "END;";
  1143. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.VarChar);
  1144. myParameter1.Value = "two";
  1145. myParameter1.Size = 4;
  1146. myParameter1.Direction = ParameterDirection.Input;
  1147. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.VarChar);
  1148. myParameter2.Size = 12;
  1149. myParameter2.Direction = ParameterDirection.Output;
  1150. cmd3.Parameters.Add (myParameter1);
  1151. cmd3.Parameters.Add (myParameter2);
  1152. cmd3.ExecuteNonQuery ();
  1153. string outValue = (string) myParameter2.Value;
  1154. Console.WriteLine (" Out Value should be: onetwothree");
  1155. Console.WriteLine (" Out Value: " + outValue);
  1156. }
  1157. static void OutParmTest2 (OracleConnection con)
  1158. {
  1159. // test stored procedure with 2 parameters
  1160. // 1. input number(18,2)
  1161. // 2. output number(18,2)
  1162. OracleCommand cmd2 = null;
  1163. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST2...");
  1164. try {
  1165. cmd2 = con.CreateCommand ();
  1166. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST2";
  1167. cmd2.ExecuteNonQuery ();
  1168. }
  1169. catch(OracleException oe1) {
  1170. // ignore if table already exists
  1171. }
  1172. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST2...");
  1173. // stored procedure addes two numbers
  1174. cmd2.CommandText =
  1175. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM2(parm1 IN NUMBER,parm2 OUT NUMBER) " +
  1176. "IS " +
  1177. "BEGIN " +
  1178. " parm2 := parm1 + 3; " +
  1179. "END;";
  1180. cmd2.ExecuteNonQuery ();
  1181. Console.WriteLine(" COMMIT...");
  1182. cmd2.CommandText = "COMMIT";
  1183. cmd2.ExecuteNonQuery ();
  1184. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM2 with two parameters...");
  1185. OracleCommand cmd3 = con.CreateCommand ();
  1186. cmd3.CommandType = CommandType.Text;
  1187. cmd3.CommandText =
  1188. "BEGIN " +
  1189. " SP_TESTOUTPARM2(:p1, :p2);" +
  1190. "END;";
  1191. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.Number);
  1192. myParameter1.Value = 2;
  1193. myParameter1.Direction = ParameterDirection.Input;
  1194. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.Number);
  1195. myParameter2.Direction = ParameterDirection.Output;
  1196. cmd3.Parameters.Add (myParameter1);
  1197. cmd3.Parameters.Add (myParameter2);
  1198. cmd3.ExecuteNonQuery ();
  1199. decimal outValue = (decimal) myParameter2.Value;
  1200. Console.WriteLine (" Out Value should be: 5");
  1201. Console.WriteLine (" Out Value: {0}", outValue);
  1202. }
  1203. static void OutParmTest3 (OracleConnection con)
  1204. {
  1205. // test stored procedure with 2 parameters
  1206. // 1. input date
  1207. // 2. output date
  1208. OracleCommand cmd2 = null;
  1209. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST3...");
  1210. try {
  1211. cmd2 = con.CreateCommand ();
  1212. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST3";
  1213. cmd2.ExecuteNonQuery ();
  1214. }
  1215. catch(OracleException oe1) {
  1216. // ignore if table already exists
  1217. }
  1218. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST3...");
  1219. // stored procedure adds 3 days to date
  1220. cmd2.CommandText =
  1221. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM3(parm1 IN DATE,parm2 OUT DATE) " +
  1222. "IS " +
  1223. "BEGIN " +
  1224. " parm2 := parm1 + 3; " +
  1225. "END;";
  1226. cmd2.ExecuteNonQuery ();
  1227. Console.WriteLine(" COMMIT...");
  1228. cmd2.CommandText = "COMMIT";
  1229. cmd2.ExecuteNonQuery ();
  1230. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM3 with two parameters...");
  1231. OracleCommand cmd3 = con.CreateCommand ();
  1232. cmd3.CommandType = CommandType.Text;
  1233. cmd3.CommandText =
  1234. "BEGIN " +
  1235. " SP_TESTOUTPARM3(:p1, :p2);" +
  1236. "END;";
  1237. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.DateTime);
  1238. myParameter1.Value = new DateTime(2004,12,15);
  1239. myParameter1.Direction = ParameterDirection.Input;
  1240. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.DateTime);
  1241. myParameter2.Direction = ParameterDirection.Output;
  1242. cmd3.Parameters.Add (myParameter1);
  1243. cmd3.Parameters.Add (myParameter2);
  1244. cmd3.ExecuteNonQuery ();
  1245. DateTime outValue = (DateTime) myParameter2.Value;
  1246. Console.WriteLine (" Out Value should be: 2004-12-18");
  1247. Console.WriteLine (" Out Value: {0}", outValue.ToString ("yyyy-mm-dd"));
  1248. }
  1249. static void ShowConnectionProperties (OracleConnection con)
  1250. {
  1251. try {
  1252. Console.WriteLine ("ServerVersion: " + con.ServerVersion);
  1253. } catch (System.InvalidOperationException ioe) {
  1254. Console.WriteLine ("InvalidOperationException caught.");
  1255. Console.WriteLine ("Message: " + ioe.Message);
  1256. }
  1257. Console.WriteLine ("DataSource: " + con.DataSource);
  1258. }
  1259. static void NullAggregateTest (OracleConnection con)
  1260. {
  1261. Console.WriteLine(" Drop table MONO_TEST_TABLE3...");
  1262. OracleCommand cmd2 = con.CreateCommand ();
  1263. try {
  1264. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE3";
  1265. cmd2.ExecuteNonQuery ();
  1266. }
  1267. catch(OracleException oe1) {
  1268. // ignore if table already exists
  1269. }
  1270. Console.WriteLine(" Create table MONO_TEST_TABLE3...");
  1271. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE3 (" +
  1272. " COL1 VARCHAR2(8), "+
  1273. " COL2 VARCHAR2(32))";
  1274. cmd2.ExecuteNonQuery ();
  1275. Console.WriteLine(" Insert some rows into table MONO_TEST_TABLE3...");
  1276. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('1','one')";
  1277. cmd2.ExecuteNonQuery ();
  1278. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('1','uno')";
  1279. cmd2.ExecuteNonQuery ();
  1280. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3','three')";
  1281. cmd2.ExecuteNonQuery ();
  1282. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3', null)";
  1283. cmd2.ExecuteNonQuery ();
  1284. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3','few')";
  1285. cmd2.ExecuteNonQuery ();
  1286. Console.WriteLine(" ExecuteScalar...");
  1287. cmd2.CommandText = "SELECT COL1, COUNT(COL2) AS MAX_COL1 FROM MONO_TEST_TABLE3 GROUP BY COL1";
  1288. OracleDataReader reader = cmd2.ExecuteReader ();
  1289. Console.WriteLine (" Read...");
  1290. while (reader.Read ()) {
  1291. object obj0 = reader.GetValue (0);
  1292. Console.WriteLine("Value 0: " + obj0.ToString ());
  1293. object obj1 = reader.GetValue (1);
  1294. Console.WriteLine("Value 1: " + obj1.ToString ());
  1295. Console.WriteLine (" Read...");
  1296. }
  1297. Console.WriteLine (" No more records.");
  1298. }
  1299. static void OnInfoMessage (object sender, OracleInfoMessageEventArgs e)
  1300. {
  1301. Console.WriteLine("InfoMessage Message: " + e.Message.ToString());
  1302. Console.WriteLine("InfoMessage Code: " + e.Code.ToString());
  1303. Console.WriteLine("InfoMessage Source: " + e.Source.ToString());
  1304. }
  1305. static void OnStateChange (object sender, StateChangeEventArgs e)
  1306. {
  1307. Console.WriteLine("StateChange CurrentSate:" + e.CurrentState.ToString ());
  1308. Console.WriteLine("StateChange OriginalState:" + e.OriginalState.ToString ());
  1309. }
  1310. static void RefCursorTests(OracleConnection con)
  1311. {
  1312. SetupRefCursorTests(con); // for ref cursor tests 1 thru 3
  1313. RefCursorTest1(con); // using BEGIN/END
  1314. RefCursorTest2(con); // using call
  1315. RefCursorTest3(con); // using CommandType.StoredProcedure
  1316. RefCursorTest4(con);
  1317. }
  1318. static void SetupRefCursorTests(OracleConnection con)
  1319. {
  1320. Console.WriteLine("Setup Oracle package curspkg_join...");
  1321. OracleCommand cmd = con.CreateCommand();
  1322. cmd.CommandText =
  1323. "CREATE OR REPLACE PACKAGE curspkg_join AS\n" +
  1324. "TYPE t_cursor IS REF CURSOR;\n" +
  1325. "Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);\n" +
  1326. "END curspkg_join;";
  1327. cmd.CommandText =
  1328. "CREATE OR REPLACE PACKAGE BODY curspkg_join AS\n" +
  1329. " Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)\n" +
  1330. " IS\n" +
  1331. " v_cursor t_cursor;\n" +
  1332. " BEGIN\n" +
  1333. " IF n_EMPNO <> 0 THEN\n" +
  1334. " OPEN v_cursor FOR\n" +
  1335. " SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME\n" +
  1336. " FROM EMP, DEPT\n" +
  1337. " WHERE EMP.DEPTNO = DEPT.DEPTNO\n" +
  1338. " AND EMP.EMPNO = n_EMPNO;\n" +
  1339. "\n" +
  1340. " ELSE\n" +
  1341. " OPEN v_cursor FOR\n" +
  1342. " SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME\n" +
  1343. " FROM EMP, DEPT\n" +
  1344. " WHERE EMP.DEPTNO = DEPT.DEPTNO;\n" +
  1345. "\n" +
  1346. " END IF;\n" +
  1347. " io_cursor := v_cursor;\n" +
  1348. " END open_join_cursor1;\n" +
  1349. "END curspkg_join;";
  1350. cmd.ExecuteNonQuery();
  1351. }
  1352. public static void RefCursorTest4(OracleConnection connection)
  1353. {
  1354. Console.WriteLine("Setup test package and data...");
  1355. OracleCommand cmddrop = connection.CreateCommand();
  1356. cmddrop.CommandText = "DROP TABLE TESTTABLE";
  1357. try {
  1358. cmddrop.ExecuteNonQuery();
  1359. }
  1360. catch(OracleException e) {
  1361. Console.WriteLine("Ignore this error: " + e.Message);
  1362. }
  1363. cmddrop.Dispose();
  1364. cmddrop = null;
  1365. OracleCommand cmd = connection.CreateCommand();
  1366. // create table TESTTABLE
  1367. cmd.CommandText =
  1368. "create table TESTTABLE (\n" +
  1369. " col1 numeric(18,0),\n" +
  1370. " col2 varchar(32),\n" +
  1371. " col3 date)";
  1372. cmd.ExecuteNonQuery();
  1373. // insert some rows into TESTTABLE
  1374. cmd.CommandText =
  1375. "insert into TESTTABLE\n" +
  1376. "(col1, col2, col3)\n" +
  1377. "values(45, 'Mono', sysdate)";
  1378. cmd.ExecuteNonQuery();
  1379. cmd.CommandText =
  1380. "insert into TESTTABLE\n" +
  1381. "(col1, col2, col3)\n" +
  1382. "values(136, 'Fun', sysdate)";
  1383. cmd.ExecuteNonQuery();
  1384. cmd.CommandText =
  1385. "insert into TESTTABLE\n" +
  1386. "(col1, col2, col3)\n" +
  1387. "values(526, 'System.Data.OracleClient', sysdate)";
  1388. cmd.ExecuteNonQuery();
  1389. cmd.CommandText = "commit";
  1390. cmd.ExecuteNonQuery();
  1391. // create Oracle package TestTablePkg
  1392. cmd.CommandText =
  1393. "CREATE OR REPLACE PACKAGE TestTablePkg\n" +
  1394. "AS\n" +
  1395. " TYPE T_CURSOR IS REF CURSOR;\n" +
  1396. "\n" +
  1397. " PROCEDURE GetData(tableCursor OUT T_CURSOR);\n" +
  1398. "END TestTablePkg;";
  1399. cmd.ExecuteNonQuery();
  1400. // create Oracle package body for package TestTablePkg
  1401. cmd.CommandText =
  1402. "CREATE OR REPLACE PACKAGE BODY TestTablePkg AS\n" +
  1403. " PROCEDURE GetData(tableCursor OUT T_CURSOR)\n" +
  1404. " IS\n" +
  1405. " BEGIN\n" +
  1406. " OPEN tableCursor FOR\n" +
  1407. " SELECT *\n" +
  1408. " FROM TestTable;\n" +
  1409. " END GetData;\n" +
  1410. "END TestTablePkg;";
  1411. cmd.ExecuteNonQuery();
  1412. cmd.Dispose();
  1413. cmd = null;
  1414. Console.WriteLine("Set up command and parameters to call stored proc...");
  1415. OracleCommand command = new OracleCommand("TestTablePkg.GetData", connection);
  1416. command.CommandType = CommandType.StoredProcedure;
  1417. OracleParameter parameter = new OracleParameter("tableCursor", OracleType.Cursor);
  1418. parameter.Direction = ParameterDirection.Output;
  1419. command.Parameters.Add(parameter);
  1420. Console.WriteLine("Execute...");
  1421. command.ExecuteNonQuery();
  1422. Console.WriteLine("Get OracleDataReader for cursor output parameter...");
  1423. OracleDataReader reader = (OracleDataReader) parameter.Value;
  1424. Console.WriteLine("Read data...");
  1425. int r = 0;
  1426. while (reader.Read()) {
  1427. Console.WriteLine("Row {0}", r);
  1428. for (int f = 0; f < reader.FieldCount; f ++) {
  1429. object val = reader.GetValue(f);
  1430. Console.WriteLine(" Field {0} Value: {1}", f, val);
  1431. }
  1432. r ++;
  1433. }
  1434. Console.WriteLine("Rows retrieved: {0}", r);
  1435. Console.WriteLine("Clean up...");
  1436. reader.Close();
  1437. reader = null;
  1438. command.Dispose();
  1439. command = null;
  1440. }
  1441. static void RefCursorTest1(OracleConnection con)
  1442. {
  1443. Console.WriteLine("Ref Cursor Test 1 - using BEGIN/END for proc - Begin...");
  1444. Console.WriteLine("Create command...");
  1445. OracleCommand cmd = new OracleCommand();
  1446. cmd.Connection = con;
  1447. cmd.CommandText =
  1448. "BEGIN\n" +
  1449. " curspkg_join.open_join_cursor1(:n_Empno,:io_cursor);\n" +
  1450. "END;";
  1451. // PL/SQL definition of stored procedure in package curspkg_join
  1452. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1453. Console.WriteLine("Create parameters...");
  1454. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1455. parm1.Direction = ParameterDirection.Input;
  1456. parm1.Value = 7902;
  1457. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1458. parm2.Direction = ParameterDirection.Output;
  1459. cmd.Parameters.Add(parm1);
  1460. cmd.Parameters.Add(parm2);
  1461. // positional parm
  1462. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1463. // named parm
  1464. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1465. OracleDataReader reader;
  1466. Console.WriteLine("Execute Non Query...");
  1467. cmd.ExecuteNonQuery();
  1468. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1469. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1470. int x, count;
  1471. count = 0;
  1472. Console.WriteLine("Get data from ref cursor...");
  1473. while (reader.Read()) {
  1474. for (x = 0; x < reader.FieldCount; x++)
  1475. Console.Write(reader[x] + " ");
  1476. Console.WriteLine();
  1477. count += 1;
  1478. }
  1479. Console.WriteLine(count.ToString() + " Rows Returned.");
  1480. reader.Close();
  1481. }
  1482. static void RefCursorTest2(OracleConnection con)
  1483. {
  1484. Console.WriteLine("Ref Cursor Test 2 - using call - Begin...");
  1485. Console.WriteLine("Create command...");
  1486. OracleCommand cmd = new OracleCommand();
  1487. cmd.Connection = con;
  1488. cmd.CommandText = "call curspkg_join.open_join_cursor1(:n_Empno,:io_cursor)";
  1489. // PL/SQL definition of stored procedure in package curspkg_join
  1490. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1491. Console.WriteLine("Create parameters...");
  1492. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1493. parm1.Direction = ParameterDirection.Input;
  1494. parm1.Value = 7902;
  1495. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1496. parm2.Direction = ParameterDirection.Output;
  1497. cmd.Parameters.Add(parm1);
  1498. cmd.Parameters.Add(parm2);
  1499. // positional parm
  1500. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1501. // named parm
  1502. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1503. OracleDataReader reader;
  1504. Console.WriteLine("Execute Non Query...");
  1505. cmd.ExecuteNonQuery();
  1506. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1507. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1508. int x, count;
  1509. count = 0;
  1510. Console.WriteLine("Get data from ref cursor...");
  1511. while (reader.Read()) {
  1512. for (x = 0; x < reader.FieldCount; x++)
  1513. Console.Write(reader[x] + " ");
  1514. Console.WriteLine();
  1515. count += 1;
  1516. }
  1517. Console.WriteLine(count.ToString() + " Rows Returned.");
  1518. reader.Close();
  1519. }
  1520. static void RefCursorTest3(OracleConnection con)
  1521. {
  1522. Console.WriteLine("Ref Cursor Test 3 - CommandType.StoredProcedure - Begin...");
  1523. Console.WriteLine("Create command...");
  1524. OracleCommand cmd = new OracleCommand();
  1525. cmd.Connection = con;
  1526. cmd.CommandText = "curspkg_join.open_join_cursor1";
  1527. cmd.CommandType = CommandType.StoredProcedure;
  1528. // PL/SQL definition of stored procedure in package curspkg_join
  1529. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1530. Console.WriteLine("Create parameters...");
  1531. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1532. parm1.Direction = ParameterDirection.Input;
  1533. parm1.Value = 7902;
  1534. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1535. parm2.Direction = ParameterDirection.Output;
  1536. cmd.Parameters.Add(parm1);
  1537. cmd.Parameters.Add(parm2);
  1538. // positional parm
  1539. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1540. // named parm
  1541. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1542. OracleDataReader reader;
  1543. Console.WriteLine("Execute Non Query...");
  1544. cmd.ExecuteNonQuery();
  1545. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1546. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1547. int x, count;
  1548. count = 0;
  1549. Console.WriteLine("Get data from ref cursor...");
  1550. while (reader.Read()) {
  1551. for (x = 0; x < reader.FieldCount; x++)
  1552. Console.Write(reader[x] + " ");
  1553. Console.WriteLine();
  1554. count += 1;
  1555. }
  1556. Console.WriteLine(count.ToString() + " Rows Returned.");
  1557. reader.Close();
  1558. }
  1559. static void ExternalAuthenticationTest ()
  1560. {
  1561. string user = Environment.UserName;
  1562. if (!Environment.UserDomainName.Equals(String.Empty))
  1563. user = Environment.UserDomainName + "\\" + Environment.UserName;
  1564. Console.WriteLine("Environment UserDomainName and UserName: " + user);
  1565. Console.WriteLine("Open connection using external authentication...");
  1566. OracleConnection con = new OracleConnection("Data Source=palis;Integrated Security=true");
  1567. try {
  1568. con.Open();
  1569. OracleCommand cmd = con.CreateCommand();
  1570. cmd.CommandText = "SELECT USER FROM DUAL";
  1571. OracleDataReader reader = cmd.ExecuteReader();
  1572. if (reader.Read())
  1573. Console.WriteLine("User: " + reader.GetString(reader.GetOrdinal("USER")));
  1574. con.Close();
  1575. }
  1576. catch (Exception e) {
  1577. Console.WriteLine("Exception caught: " + e.Message);
  1578. Console.WriteLine("Probably not setup for external authentication.");
  1579. }
  1580. con.Dispose();
  1581. con = null;
  1582. }
  1583. public static void TestPersistSucurityInfo1()
  1584. {
  1585. Console.WriteLine("\nTestPersistSucurityInfo1 - persist security info=false");
  1586. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=false");
  1587. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1588. con.Open();
  1589. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1590. con.Close();
  1591. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1592. con = null;
  1593. }
  1594. public static void TestPersistSucurityInfo2()
  1595. {
  1596. Console.WriteLine("\nTestPersistSucurityInfo2 - persist security info=true");
  1597. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=true");
  1598. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1599. con.Open();
  1600. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1601. con.Close();
  1602. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1603. con = null;
  1604. }
  1605. public static void TestPersistSucurityInfo3()
  1606. {
  1607. Console.WriteLine("\nTestPersistSucurityInfo3 - use default for persist security info which is false");
  1608. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger");
  1609. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1610. con.Open();
  1611. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1612. con.Close();
  1613. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1614. con = null;
  1615. }
  1616. public static void TestPersistSucurityInfo4()
  1617. {
  1618. Console.WriteLine("\nTestPersistSucurityInfo4 - persist security info=false with password at front");
  1619. OracleConnection con = new OracleConnection(";password=tiger;data source=palis;user id=scott;persist security info=false");
  1620. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1621. con.Open();
  1622. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1623. con.Close();
  1624. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1625. con = null;
  1626. }
  1627. public static void TestPersistSucurityInfo5()
  1628. {
  1629. Console.WriteLine("\nTestPersistSucurityInfo5 - persist security info=false");
  1630. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=false");
  1631. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1632. con.Open();
  1633. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1634. Console.WriteLine("ConnectionState for con: " + con.State.ToString() + "\n");
  1635. Console.WriteLine("Clone OracleConnection...");
  1636. OracleConnection con2 = (OracleConnection) ((ICloneable) con).Clone();
  1637. Console.WriteLine("ConnectionState for con2: " + con2.State.ToString());
  1638. Console.WriteLine("con2 ConnectionString before open: " + con2.ConnectionString);
  1639. con2.Open();
  1640. Console.WriteLine("con2 ConnectionString after open: " + con2.ConnectionString);
  1641. con2.Close();
  1642. Console.WriteLine("con2 ConnectionString after close: " + con2.ConnectionString);
  1643. con.Close();
  1644. }
  1645. public static void TestPersistSucurityInfo6()
  1646. {
  1647. Console.WriteLine("\nTestPersistSucurityInfo6 - external auth using persist security info");
  1648. string user = Environment.UserName;
  1649. if (!Environment.UserDomainName.Equals(String.Empty))
  1650. user = Environment.UserDomainName + "\\" + Environment.UserName;
  1651. Console.WriteLine("Environment UserDomainName and UserName: " + user);
  1652. Console.WriteLine("Open connection using external authentication...");
  1653. OracleConnection con = new OracleConnection("Data Source=palis;Integrated Security=true");
  1654. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1655. try {
  1656. con.Open();
  1657. OracleCommand cmd = con.CreateCommand();
  1658. cmd.CommandText = "SELECT USER FROM DUAL";
  1659. OracleDataReader reader = cmd.ExecuteReader();
  1660. if (reader.Read())
  1661. Console.WriteLine("User: " + reader.GetString(reader.GetOrdinal("USER")));
  1662. con.Close();
  1663. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1664. }
  1665. catch (Exception e) {
  1666. Console.WriteLine("Exception caught: " + e.Message);
  1667. Console.WriteLine("Probably not setup for external authentication. This is fine.");
  1668. }
  1669. con.Dispose();
  1670. Console.WriteLine("ConnectionString after dispose: " + con.ConnectionString);
  1671. con = null;
  1672. Console.WriteLine("\n\n");
  1673. }
  1674. public static void ConnectionPoolingTest1 ()
  1675. {
  1676. Console.WriteLine("Start Connection Pooling Test 1...");
  1677. OracleConnection[] connections = null;
  1678. int maxCon = MAX_CONNECTIONS + 1; // add 1 more over the max connections to cause it to wait for the next available connection
  1679. int i = 0;
  1680. try {
  1681. connections = new OracleConnection[maxCon];
  1682. for (i = 0; i < maxCon; i++) {
  1683. Console.WriteLine(" Open connection: {0}", i);
  1684. connections[i] = new OracleConnection(conStr);
  1685. connections[i].Open ();
  1686. }
  1687. } catch (InvalidOperationException e) {
  1688. Console.WriteLine("Expected exception InvalidOperationException caught.");
  1689. Console.WriteLine(e);
  1690. }
  1691. for (i = 0; i < maxCon; i++) {
  1692. if (connections[i] != null) {
  1693. Console.WriteLine(" Close connection: {0}", i);
  1694. if (connections[i].State == ConnectionState.Open)
  1695. connections[i].Close ();
  1696. connections[i].Dispose ();
  1697. connections[i] = null;
  1698. }
  1699. }
  1700. connections = null;
  1701. Console.WriteLine("Done Connection Pooling Test 1.");
  1702. }
  1703. public static void ConnectionPoolingTest2 ()
  1704. {
  1705. Console.WriteLine("Start Connection Pooling Test 2...");
  1706. OracleConnection[] connections = null;
  1707. int maxCon = MAX_CONNECTIONS;
  1708. int i = 0;
  1709. connections = new OracleConnection[maxCon];
  1710. for (i = 0; i < maxCon; i++) {
  1711. Console.WriteLine(" Open connection: {0}", i);
  1712. connections[i] = new OracleConnection(conStr);
  1713. connections[i].Open ();
  1714. }
  1715. Console.WriteLine("Start another thread...");
  1716. t = new Thread(new ThreadStart(AnotherThreadProc));
  1717. t.Start ();
  1718. Console.WriteLine("Sleep...");
  1719. Thread.Sleep(100);
  1720. Console.WriteLine("Closing...");
  1721. for (i = 0; i < maxCon; i++) {
  1722. if (connections[i] != null) {
  1723. Console.WriteLine(" Close connection: {0}", i);
  1724. if (connections[i].State == ConnectionState.Open)
  1725. connections[i].Close ();
  1726. connections[i].Dispose ();
  1727. connections[i] = null;
  1728. }
  1729. }
  1730. connections = null;
  1731. }
  1732. private static void AnotherThreadProc ()
  1733. {
  1734. Console.WriteLine("Open connection via another thread...");
  1735. OracleConnection[] connections = null;
  1736. int maxCon = MAX_CONNECTIONS;
  1737. int i = 0;
  1738. connections = new OracleConnection[maxCon];
  1739. for (i = 0; i < maxCon; i++) {
  1740. Console.WriteLine(" Open connection: {0}", i);
  1741. connections[i] = new OracleConnection(conStr);
  1742. connections[i].Open ();
  1743. }
  1744. Console.WriteLine("Done Connection Pooling Test 2.");
  1745. System.Environment.Exit (0);
  1746. }
  1747. [STAThread]
  1748. static void Main(string[] args)
  1749. {
  1750. if(args.Length != 3) {
  1751. Console.WriteLine("Usage: mono TestOracleClient database userid password");
  1752. return;
  1753. }
  1754. string connectionString = String.Format(
  1755. "Data Source={0};" +
  1756. "User ID={1};" +
  1757. "Password={2}",
  1758. args[0], args[1], args[2]);
  1759. conStr = connectionString;
  1760. OracleConnection con1 = new OracleConnection();
  1761. ShowConnectionProperties (con1);
  1762. con1.ConnectionString = connectionString;
  1763. con1.InfoMessage += new OracleInfoMessageEventHandler (OnInfoMessage);
  1764. con1.StateChange += new StateChangeEventHandler (OnStateChange);
  1765. Console.WriteLine("Opening...");
  1766. con1.Open ();
  1767. Console.WriteLine("Opened.");
  1768. ShowConnectionProperties (con1);
  1769. Console.WriteLine ("Mono Oracle Test BEGIN ...");
  1770. MonoTest (con1);
  1771. Console.WriteLine ("Mono Oracle Test END ...");
  1772. Wait ("");
  1773. Console.WriteLine ("LOB Test BEGIN...");
  1774. CLOBTest (con1);
  1775. BLOBTest (con1);
  1776. Console.WriteLine ("LOB Test END.");
  1777. Wait ("");
  1778. Console.WriteLine ("Read Simple Test BEGIN - scott.emp...");
  1779. ReadSimpleTest(con1, "SELECT e.*, e.rowid FROM scott.emp e");
  1780. Console.WriteLine ("Read Simple Test END - scott.emp");
  1781. Wait ("");
  1782. Console.WriteLine ("DataAdapter Test BEGIN...");
  1783. DataAdapterTest(con1);
  1784. Console.WriteLine ("DataAdapter Test END.");
  1785. Wait ("");
  1786. Console.WriteLine ("DataAdapter Test 2 BEGIN...");
  1787. DataAdapterTest2(con1);
  1788. Console.WriteLine ("DataAdapter Test 2 END.");
  1789. Wait ("");
  1790. Console.WriteLine ("Rollback Test BEGIN...");
  1791. RollbackTest(con1);
  1792. Console.WriteLine ("Rollback Test END.");
  1793. Wait ("");
  1794. Console.WriteLine ("Commit Test BEGIN...");
  1795. CommitTest(con1);
  1796. Console.WriteLine ("Commit Test END.");
  1797. Wait ("");
  1798. Console.WriteLine ("Parameter Test BEGIN...");
  1799. ParameterTest(con1);
  1800. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE7");
  1801. Console.WriteLine ("Parameter Test END.");
  1802. Wait ("");
  1803. Console.WriteLine ("Stored Proc Test 1 BEGIN...");
  1804. StoredProcedureTest1 (con1);
  1805. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE1");
  1806. Console.WriteLine ("Stored Proc Test 1 END...");
  1807. Wait ("");
  1808. Console.WriteLine ("Stored Proc Test 2 BEGIN...");
  1809. StoredProcedureTest2 (con1);
  1810. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE2");
  1811. Console.WriteLine ("Stored Proc Test 2 END...");
  1812. Console.WriteLine ("Out Parameter and PL/SQL Block Test 1 BEGIN...");
  1813. OutParmTest1 (con1);
  1814. Console.WriteLine ("Out Parameter and PL/SQL Block Test 1 END...");
  1815. Console.WriteLine ("Out Parameter and PL/SQL Block Test 2 BEGIN...");
  1816. OutParmTest2 (con1);
  1817. Console.WriteLine ("Out Parameter and PL/SQL Block Test 2 END...");
  1818. Console.WriteLine ("Out Parameter and PL/SQL Block Test 3 BEGIN...");
  1819. OutParmTest3 (con1);
  1820. Console.WriteLine ("Out Parameter and PL/SQL Block Test 3 END...");
  1821. Wait ("");
  1822. Console.WriteLine ("Test a Non Query using Execute Reader BEGIN...");
  1823. TestNonQueryUsingExecuteReader (con1);
  1824. Console.WriteLine ("Test a Non Query using Execute Reader END...");
  1825. Wait ("");
  1826. Console.WriteLine ("Null Aggregate Warning BEGIN test...");
  1827. NullAggregateTest (con1);
  1828. Console.WriteLine ("Null Aggregate Warning END test...");
  1829. Console.WriteLine ("Ref Cursor BEGIN tests...");
  1830. RefCursorTests (con1);
  1831. Console.WriteLine ("Ref Cursor END tests...");
  1832. Console.WriteLine("Closing...");
  1833. con1.Close ();
  1834. Console.WriteLine("Closed.");
  1835. ExternalAuthenticationTest();
  1836. TestPersistSucurityInfo1();
  1837. TestPersistSucurityInfo2();
  1838. TestPersistSucurityInfo3();
  1839. TestPersistSucurityInfo4();
  1840. TestPersistSucurityInfo5();
  1841. TestPersistSucurityInfo6();
  1842. //conStr = conStr + ";pooling=true;min pool size=4;max pool size=" + MAX_CONNECTIONS.ToString ();
  1843. //ConnectionPoolingTest1 ();
  1844. //ConnectionPoolingTest2 ();
  1845. Console.WriteLine("Done.");
  1846. }
  1847. }
  1848. }