TestOracleClient.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312
  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 SCOTT.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 SCOTT.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 SCOTT.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 SCOTT.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 SCOTT.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 SCOTT.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 SCOTT.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 SCOTT.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. if (byt < 0x10)
  1010. sb2.Append ("0");
  1011. sb2.Append (byt.ToString("x"));
  1012. }
  1013. if (sb2.Length > 0)
  1014. bvalue = "0x" + sb2.ToString ();
  1015. return bvalue;
  1016. }
  1017. static void StoredProcedureTest1 (OracleConnection con)
  1018. {
  1019. // test stored procedure with no parameters
  1020. OracleCommand cmd2 = con.CreateCommand ();
  1021. Console.WriteLine(" Drop table MONO_TEST_TABLE1...");
  1022. try {
  1023. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE1";
  1024. cmd2.ExecuteNonQuery ();
  1025. }
  1026. catch(OracleException oe1) {
  1027. // ignore if table did not exist
  1028. }
  1029. Console.WriteLine(" Drop procedure SP_TEST1...");
  1030. try {
  1031. cmd2.CommandText = "DROP PROCEDURE SP_TEST1";
  1032. cmd2.ExecuteNonQuery ();
  1033. }
  1034. catch(OracleException oe1) {
  1035. // ignore if procedure did not exist
  1036. }
  1037. Console.WriteLine(" Create table MONO_TEST_TABLE1...");
  1038. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE1 (" +
  1039. " COL1 VARCHAR2(8), "+
  1040. " COL2 VARCHAR2(32))";
  1041. cmd2.ExecuteNonQuery ();
  1042. Console.WriteLine(" Create stored procedure SP_TEST1...");
  1043. cmd2.CommandText = "CREATE PROCEDURE SP_TEST1 " +
  1044. " IS " +
  1045. " BEGIN " +
  1046. " INSERT INTO MONO_TEST_TABLE1 (COL1,COL2) VALUES ('aaa','bbbb');" +
  1047. " COMMIT;" +
  1048. " END;";
  1049. cmd2.ExecuteNonQuery ();
  1050. Console.WriteLine("COMMIT...");
  1051. cmd2.CommandText = "COMMIT";
  1052. cmd2.ExecuteNonQuery ();
  1053. Console.WriteLine(" Call stored procedure sp_test1...");
  1054. OracleCommand cmd3 = con.CreateCommand ();
  1055. cmd3.CommandType = CommandType.StoredProcedure;
  1056. cmd3.CommandText = "sp_test1";
  1057. cmd3.ExecuteNonQuery ();
  1058. }
  1059. static void StoredProcedureTest2 (OracleConnection con)
  1060. {
  1061. // test stored procedure with 2 parameters
  1062. Console.WriteLine(" Drop table MONO_TEST_TABLE2...");
  1063. OracleCommand cmd2 = con.CreateCommand ();
  1064. try {
  1065. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE2";
  1066. cmd2.ExecuteNonQuery ();
  1067. }
  1068. catch(OracleException oe1) {
  1069. // ignore if table already exists
  1070. }
  1071. Console.WriteLine(" Drop procedure SP_TEST2...");
  1072. try {
  1073. cmd2.CommandText = "DROP PROCEDURE SP_TEST2";
  1074. cmd2.ExecuteNonQuery ();
  1075. }
  1076. catch(OracleException oe1) {
  1077. // ignore if table already exists
  1078. }
  1079. Console.WriteLine(" Create table MONO_TEST_TABLE2...");
  1080. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE2 (" +
  1081. " COL1 VARCHAR2(8), "+
  1082. " COL2 VARCHAR2(32))";
  1083. cmd2.ExecuteNonQuery ();
  1084. Console.WriteLine(" Create stored procedure SP_TEST2...");
  1085. cmd2.CommandText = "CREATE PROCEDURE SP_TEST2(parm1 VARCHAR2,parm2 VARCHAR2) " +
  1086. " IS " +
  1087. " BEGIN " +
  1088. " INSERT INTO MONO_TEST_TABLE2 (COL1,COL2) VALUES (parm1,parm2);" +
  1089. " COMMIT;" +
  1090. " END;";
  1091. cmd2.ExecuteNonQuery ();
  1092. Console.WriteLine(" COMMIT...");
  1093. cmd2.CommandText = "COMMIT";
  1094. cmd2.ExecuteNonQuery ();
  1095. Console.WriteLine(" Call stored procedure SP_TEST2 with two parameters...");
  1096. OracleCommand cmd3 = con.CreateCommand ();
  1097. cmd3.CommandType = CommandType.StoredProcedure;
  1098. cmd3.CommandText = "sp_test2";
  1099. OracleParameter myParameter1 = new OracleParameter("parm1", OracleType.VarChar);
  1100. myParameter1.Value = "yyy13";
  1101. myParameter1.Size = 8;
  1102. myParameter1.Direction = ParameterDirection.Input;
  1103. OracleParameter myParameter2 = new OracleParameter("parm2", OracleType.VarChar);
  1104. myParameter2.Value = "iii13";
  1105. myParameter2.Size = 32;
  1106. myParameter2.Direction = ParameterDirection.Input;
  1107. cmd3.Parameters.Add (myParameter1);
  1108. cmd3.Parameters.Add (myParameter2);
  1109. cmd3.ExecuteNonQuery ();
  1110. }
  1111. static void OutParmTest1 (OracleConnection con)
  1112. {
  1113. // test stored procedure with 2 parameters
  1114. // 1. input varchar2
  1115. // 2. output varchar
  1116. OracleCommand cmd2 = null;
  1117. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST1...");
  1118. try {
  1119. cmd2 = con.CreateCommand ();
  1120. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST1";
  1121. cmd2.ExecuteNonQuery ();
  1122. }
  1123. catch(OracleException oe1) {
  1124. // ignore if table already exists
  1125. }
  1126. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST1...");
  1127. // stored procedure concatenates strings
  1128. cmd2.CommandText =
  1129. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM1(parm1 IN VARCHAR2,parm2 OUT VARCHAR2) " +
  1130. "IS " +
  1131. "BEGIN " +
  1132. " parm2 := 'one' || parm1 || 'three';" +
  1133. "END;";
  1134. cmd2.ExecuteNonQuery ();
  1135. Console.WriteLine(" COMMIT...");
  1136. cmd2.CommandText = "COMMIT";
  1137. cmd2.ExecuteNonQuery ();
  1138. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM1 with two parameters...");
  1139. OracleCommand cmd3 = con.CreateCommand ();
  1140. cmd3.CommandType = CommandType.Text;
  1141. cmd3.CommandText =
  1142. "BEGIN " +
  1143. " SP_TESTOUTPARM1(:p1, :p2);" +
  1144. "END;";
  1145. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.VarChar);
  1146. myParameter1.Value = "two";
  1147. myParameter1.Size = 4;
  1148. myParameter1.Direction = ParameterDirection.Input;
  1149. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.VarChar);
  1150. myParameter2.Size = 12;
  1151. myParameter2.Direction = ParameterDirection.Output;
  1152. cmd3.Parameters.Add (myParameter1);
  1153. cmd3.Parameters.Add (myParameter2);
  1154. cmd3.ExecuteNonQuery ();
  1155. string outValue = (string) myParameter2.Value;
  1156. Console.WriteLine (" Out Value should be: onetwothree");
  1157. Console.WriteLine (" Out Value: " + outValue);
  1158. }
  1159. static void OutParmTest2 (OracleConnection con)
  1160. {
  1161. // test stored procedure with 2 parameters
  1162. // 1. input number(18,2)
  1163. // 2. output number(18,2)
  1164. OracleCommand cmd2 = null;
  1165. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST2...");
  1166. try {
  1167. cmd2 = con.CreateCommand ();
  1168. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST2";
  1169. cmd2.ExecuteNonQuery ();
  1170. }
  1171. catch(OracleException oe1) {
  1172. // ignore if table already exists
  1173. }
  1174. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST2...");
  1175. // stored procedure addes two numbers
  1176. cmd2.CommandText =
  1177. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM2(parm1 IN NUMBER,parm2 OUT NUMBER) " +
  1178. "IS " +
  1179. "BEGIN " +
  1180. " parm2 := parm1 + 3; " +
  1181. "END;";
  1182. cmd2.ExecuteNonQuery ();
  1183. Console.WriteLine(" COMMIT...");
  1184. cmd2.CommandText = "COMMIT";
  1185. cmd2.ExecuteNonQuery ();
  1186. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM2 with two parameters...");
  1187. OracleCommand cmd3 = con.CreateCommand ();
  1188. cmd3.CommandType = CommandType.Text;
  1189. cmd3.CommandText =
  1190. "BEGIN " +
  1191. " SP_TESTOUTPARM2(:p1, :p2);" +
  1192. "END;";
  1193. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.Number);
  1194. myParameter1.Value = 2;
  1195. myParameter1.Direction = ParameterDirection.Input;
  1196. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.Number);
  1197. myParameter2.Direction = ParameterDirection.Output;
  1198. cmd3.Parameters.Add (myParameter1);
  1199. cmd3.Parameters.Add (myParameter2);
  1200. cmd3.ExecuteNonQuery ();
  1201. decimal outValue = (decimal) myParameter2.Value;
  1202. Console.WriteLine (" Out Value should be: 5");
  1203. Console.WriteLine (" Out Value: {0}", outValue);
  1204. }
  1205. static void OutParmTest3 (OracleConnection con)
  1206. {
  1207. // test stored procedure with 2 parameters
  1208. // 1. input date
  1209. // 2. output date
  1210. OracleCommand cmd2 = null;
  1211. Console.WriteLine(" Drop procedure SP_OUTPUTPARMTEST3...");
  1212. try {
  1213. cmd2 = con.CreateCommand ();
  1214. cmd2.CommandText = "DROP PROCEDURE SP_OUTPUTPARMTEST3";
  1215. cmd2.ExecuteNonQuery ();
  1216. }
  1217. catch(OracleException oe1) {
  1218. // ignore if table already exists
  1219. }
  1220. Console.WriteLine(" Create stored procedure SP_OUTPUTPARMTEST3...");
  1221. // stored procedure adds 3 days to date
  1222. cmd2.CommandText =
  1223. "CREATE OR REPLACE PROCEDURE SP_TESTOUTPARM3(parm1 IN DATE,parm2 OUT DATE) " +
  1224. "IS " +
  1225. "BEGIN " +
  1226. " parm2 := parm1 + 3; " +
  1227. "END;";
  1228. cmd2.ExecuteNonQuery ();
  1229. Console.WriteLine(" COMMIT...");
  1230. cmd2.CommandText = "COMMIT";
  1231. cmd2.ExecuteNonQuery ();
  1232. Console.WriteLine(" Call stored procedure SP_TESTOUTPARM3 with two parameters...");
  1233. OracleCommand cmd3 = con.CreateCommand ();
  1234. cmd3.CommandType = CommandType.Text;
  1235. cmd3.CommandText =
  1236. "BEGIN " +
  1237. " SP_TESTOUTPARM3(:p1, :p2);" +
  1238. "END;";
  1239. OracleParameter myParameter1 = new OracleParameter("p1", OracleType.DateTime);
  1240. myParameter1.Value = new DateTime(2004,12,15);
  1241. myParameter1.Direction = ParameterDirection.Input;
  1242. OracleParameter myParameter2 = new OracleParameter("p2", OracleType.DateTime);
  1243. myParameter2.Direction = ParameterDirection.Output;
  1244. cmd3.Parameters.Add (myParameter1);
  1245. cmd3.Parameters.Add (myParameter2);
  1246. cmd3.ExecuteNonQuery ();
  1247. DateTime outValue = (DateTime) myParameter2.Value;
  1248. Console.WriteLine (" Out Value should be: 2004-12-18");
  1249. Console.WriteLine (" Out Value: {0}", outValue.ToString ("yyyy-MM-dd"));
  1250. }
  1251. static void ShowConnectionProperties (OracleConnection con)
  1252. {
  1253. try {
  1254. Console.WriteLine ("ServerVersion: " + con.ServerVersion);
  1255. } catch (System.InvalidOperationException ioe) {
  1256. Console.WriteLine ("InvalidOperationException caught.");
  1257. Console.WriteLine ("Message: " + ioe.Message);
  1258. }
  1259. Console.WriteLine ("DataSource: " + con.DataSource);
  1260. }
  1261. static void NullAggregateTest (OracleConnection con)
  1262. {
  1263. Console.WriteLine(" Drop table MONO_TEST_TABLE3...");
  1264. OracleCommand cmd2 = con.CreateCommand ();
  1265. try {
  1266. cmd2.CommandText = "DROP TABLE MONO_TEST_TABLE3";
  1267. cmd2.ExecuteNonQuery ();
  1268. }
  1269. catch(OracleException oe1) {
  1270. // ignore if table already exists
  1271. }
  1272. Console.WriteLine(" Create table MONO_TEST_TABLE3...");
  1273. cmd2.CommandText = "CREATE TABLE MONO_TEST_TABLE3 (" +
  1274. " COL1 VARCHAR2(8), "+
  1275. " COL2 VARCHAR2(32))";
  1276. cmd2.ExecuteNonQuery ();
  1277. Console.WriteLine(" Insert some rows into table MONO_TEST_TABLE3...");
  1278. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('1','one')";
  1279. cmd2.ExecuteNonQuery ();
  1280. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('1','uno')";
  1281. cmd2.ExecuteNonQuery ();
  1282. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3','three')";
  1283. cmd2.ExecuteNonQuery ();
  1284. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3', null)";
  1285. cmd2.ExecuteNonQuery ();
  1286. cmd2.CommandText = "INSERT INTO MONO_TEST_TABLE3 (COL1, COL2) VALUES ('3','few')";
  1287. cmd2.ExecuteNonQuery ();
  1288. Console.WriteLine(" ExecuteScalar...");
  1289. cmd2.CommandText = "SELECT COL1, COUNT(COL2) AS MAX_COL1 FROM MONO_TEST_TABLE3 GROUP BY COL1";
  1290. OracleDataReader reader = cmd2.ExecuteReader ();
  1291. Console.WriteLine (" Read...");
  1292. while (reader.Read ()) {
  1293. object obj0 = reader.GetValue (0);
  1294. Console.WriteLine("Value 0: " + obj0.ToString ());
  1295. object obj1 = reader.GetValue (1);
  1296. Console.WriteLine("Value 1: " + obj1.ToString ());
  1297. Console.WriteLine (" Read...");
  1298. }
  1299. Console.WriteLine (" No more records.");
  1300. }
  1301. static void OnInfoMessage (object sender, OracleInfoMessageEventArgs e)
  1302. {
  1303. Console.WriteLine("InfoMessage Message: " + e.Message.ToString());
  1304. Console.WriteLine("InfoMessage Code: " + e.Code.ToString());
  1305. Console.WriteLine("InfoMessage Source: " + e.Source.ToString());
  1306. }
  1307. static void OnStateChange (object sender, StateChangeEventArgs e)
  1308. {
  1309. Console.WriteLine("StateChange CurrentSate:" + e.CurrentState.ToString ());
  1310. Console.WriteLine("StateChange OriginalState:" + e.OriginalState.ToString ());
  1311. }
  1312. static void RefCursorTests(OracleConnection con)
  1313. {
  1314. SetupRefCursorTests(con); // for ref cursor tests 1 thru 3
  1315. RefCursorTest1(con); // using BEGIN/END
  1316. RefCursorTest2(con); // using call
  1317. RefCursorTest3(con); // using CommandType.StoredProcedure
  1318. RefCursorTest4(con);
  1319. }
  1320. static void SetupRefCursorTests(OracleConnection con)
  1321. {
  1322. Console.WriteLine("Setup Oracle package curspkg_join...");
  1323. OracleCommand cmd = con.CreateCommand();
  1324. Console.Error.WriteLine(" create or replace package curspkg_join...");
  1325. cmd.CommandText =
  1326. "CREATE OR REPLACE PACKAGE curspkg_join AS\n" +
  1327. "TYPE t_cursor IS REF CURSOR;\n" +
  1328. "Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);\n" +
  1329. "END curspkg_join;";
  1330. cmd.ExecuteNonQuery();
  1331. Console.Error.WriteLine(" create or replace package body curspkg_join...");
  1332. cmd.CommandText =
  1333. "CREATE OR REPLACE PACKAGE BODY curspkg_join AS\n" +
  1334. " Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)\n" +
  1335. " IS\n" +
  1336. " v_cursor t_cursor;\n" +
  1337. " BEGIN\n" +
  1338. " IF n_EMPNO <> 0 THEN\n" +
  1339. " OPEN v_cursor FOR\n" +
  1340. " SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME\n" +
  1341. " FROM SCOTT.EMP, SCOTT.DEPT\n" +
  1342. " WHERE EMP.DEPTNO = DEPT.DEPTNO\n" +
  1343. " AND EMP.EMPNO = n_EMPNO;\n" +
  1344. "\n" +
  1345. " ELSE\n" +
  1346. " OPEN v_cursor FOR\n" +
  1347. " SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME\n" +
  1348. " FROM SCOTT.EMP, SCOTT.DEPT\n" +
  1349. " WHERE EMP.DEPTNO = DEPT.DEPTNO;\n" +
  1350. "\n" +
  1351. " END IF;\n" +
  1352. " io_cursor := v_cursor;\n" +
  1353. " END open_join_cursor1;\n" +
  1354. "END curspkg_join;";
  1355. cmd.ExecuteNonQuery();
  1356. cmd.CommandText = "commit";
  1357. cmd.ExecuteNonQuery();
  1358. }
  1359. public static void RefCursorTest4(OracleConnection connection)
  1360. {
  1361. Console.WriteLine("Setup test package and data for RefCursorTest4...");
  1362. OracleCommand cmddrop = connection.CreateCommand();
  1363. cmddrop.CommandText = "DROP TABLE TESTTABLE";
  1364. try {
  1365. cmddrop.ExecuteNonQuery();
  1366. }
  1367. catch(OracleException e) {
  1368. Console.WriteLine("Ignore this error: " + e.Message);
  1369. }
  1370. cmddrop.Dispose();
  1371. cmddrop = null;
  1372. OracleCommand cmd = connection.CreateCommand();
  1373. // create table TESTTABLE
  1374. cmd.CommandText =
  1375. "create table TESTTABLE (\n" +
  1376. " col1 numeric(18,0),\n" +
  1377. " col2 char(32),\n" +
  1378. " col3 date)";
  1379. cmd.ExecuteNonQuery();
  1380. // insert some rows into TESTTABLE
  1381. cmd.CommandText =
  1382. "insert into TESTTABLE\n" +
  1383. "(col1, col2, col3)\n" +
  1384. "values(45, 'Mono', sysdate)";
  1385. cmd.ExecuteNonQuery();
  1386. cmd.CommandText =
  1387. "insert into TESTTABLE\n" +
  1388. "(col1, col2, col3)\n" +
  1389. "values(136, 'Fun', sysdate)";
  1390. cmd.ExecuteNonQuery();
  1391. cmd.CommandText =
  1392. "insert into TESTTABLE\n" +
  1393. "(col1, col2, col3)\n" +
  1394. "values(526, 'System.Data.OracleClient', sysdate)";
  1395. cmd.ExecuteNonQuery();
  1396. cmd.CommandText = "commit";
  1397. cmd.ExecuteNonQuery();
  1398. // create Oracle package TestTablePkg
  1399. cmd.CommandText =
  1400. "CREATE OR REPLACE PACKAGE TestTablePkg\n" +
  1401. "AS\n" +
  1402. " TYPE T_CURSOR IS REF CURSOR;\n" +
  1403. "\n" +
  1404. " PROCEDURE GetData(tableCursor OUT T_CURSOR);\n" +
  1405. "END TestTablePkg;";
  1406. cmd.ExecuteNonQuery();
  1407. // create Oracle package body for package TestTablePkg
  1408. cmd.CommandText =
  1409. "CREATE OR REPLACE PACKAGE BODY TestTablePkg AS\n" +
  1410. " PROCEDURE GetData(tableCursor OUT T_CURSOR)\n" +
  1411. " IS\n" +
  1412. " BEGIN\n" +
  1413. " OPEN tableCursor FOR\n" +
  1414. " SELECT *\n" +
  1415. " FROM TestTable;\n" +
  1416. " END GetData;\n" +
  1417. "END TestTablePkg;";
  1418. cmd.ExecuteNonQuery();
  1419. cmd.Dispose();
  1420. cmd = null;
  1421. Console.WriteLine("Set up command and parameters to call stored proc...");
  1422. OracleCommand command = new OracleCommand("TestTablePkg.GetData", connection);
  1423. command.CommandType = CommandType.StoredProcedure;
  1424. OracleParameter parameter = new OracleParameter("tableCursor", OracleType.Cursor);
  1425. parameter.Direction = ParameterDirection.Output;
  1426. command.Parameters.Add(parameter);
  1427. Console.WriteLine("Execute...");
  1428. command.ExecuteNonQuery();
  1429. Console.WriteLine("Get OracleDataReader for cursor output parameter...");
  1430. OracleDataReader reader = (OracleDataReader) parameter.Value;
  1431. Console.WriteLine("Read data...");
  1432. int r = 0;
  1433. while (reader.Read()) {
  1434. Console.WriteLine("Row {0}", r);
  1435. for (int f = 0; f < reader.FieldCount; f ++) {
  1436. object val = reader.GetValue(f);
  1437. Console.WriteLine(" Field {0} Value: {1}", f, val.ToString());
  1438. }
  1439. r ++;
  1440. }
  1441. Console.WriteLine("Rows retrieved: {0}", r);
  1442. Console.WriteLine("Clean up...");
  1443. reader.Close();
  1444. reader = null;
  1445. command.Dispose();
  1446. command = null;
  1447. }
  1448. static void RefCursorTest1(OracleConnection con)
  1449. {
  1450. Console.WriteLine("Ref Cursor Test 1 - using BEGIN/END for proc - Begin...");
  1451. Console.WriteLine("Create command...");
  1452. OracleCommand cmd = new OracleCommand();
  1453. cmd.Connection = con;
  1454. cmd.CommandText =
  1455. "BEGIN\n" +
  1456. " curspkg_join.open_join_cursor1(:n_Empno,:io_cursor);\n" +
  1457. "END;";
  1458. // PL/SQL definition of stored procedure in package curspkg_join
  1459. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1460. Console.WriteLine("Create parameters...");
  1461. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1462. parm1.Direction = ParameterDirection.Input;
  1463. parm1.Value = 7902;
  1464. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1465. parm2.Direction = ParameterDirection.Output;
  1466. cmd.Parameters.Add(parm1);
  1467. cmd.Parameters.Add(parm2);
  1468. // positional parm
  1469. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1470. // named parm
  1471. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1472. OracleDataReader reader;
  1473. Console.WriteLine("Execute Non Query...");
  1474. cmd.ExecuteNonQuery();
  1475. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1476. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1477. int x, count;
  1478. count = 0;
  1479. Console.WriteLine("Get data from ref cursor...");
  1480. while (reader.Read()) {
  1481. for (x = 0; x < reader.FieldCount; x++)
  1482. Console.Write(reader[x] + " ");
  1483. Console.WriteLine();
  1484. count += 1;
  1485. }
  1486. Console.WriteLine(count.ToString() + " Rows Returned.");
  1487. reader.Close();
  1488. }
  1489. static void RefCursorTest2(OracleConnection con)
  1490. {
  1491. Console.WriteLine("Ref Cursor Test 2 - using call - Begin...");
  1492. Console.WriteLine("Create command...");
  1493. OracleCommand cmd = new OracleCommand();
  1494. cmd.Connection = con;
  1495. cmd.CommandText = "call curspkg_join.open_join_cursor1(:n_Empno,:io_cursor)";
  1496. // PL/SQL definition of stored procedure in package curspkg_join
  1497. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1498. Console.WriteLine("Create parameters...");
  1499. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1500. parm1.Direction = ParameterDirection.Input;
  1501. parm1.Value = 7902;
  1502. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1503. parm2.Direction = ParameterDirection.Output;
  1504. cmd.Parameters.Add(parm1);
  1505. cmd.Parameters.Add(parm2);
  1506. // positional parm
  1507. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1508. // named parm
  1509. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1510. OracleDataReader reader;
  1511. Console.WriteLine("Execute Non Query...");
  1512. cmd.ExecuteNonQuery();
  1513. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1514. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1515. int x, count;
  1516. count = 0;
  1517. Console.WriteLine("Get data from ref cursor...");
  1518. while (reader.Read()) {
  1519. for (x = 0; x < reader.FieldCount; x++)
  1520. Console.Write(reader[x] + " ");
  1521. Console.WriteLine();
  1522. count += 1;
  1523. }
  1524. Console.WriteLine(count.ToString() + " Rows Returned.");
  1525. reader.Close();
  1526. }
  1527. static void RefCursorTest3(OracleConnection con)
  1528. {
  1529. Console.WriteLine("Ref Cursor Test 3 - CommandType.StoredProcedure - Begin...");
  1530. Console.WriteLine("Create command...");
  1531. OracleCommand cmd = new OracleCommand();
  1532. cmd.Connection = con;
  1533. cmd.CommandText = "curspkg_join.open_join_cursor1";
  1534. cmd.CommandType = CommandType.StoredProcedure;
  1535. // PL/SQL definition of stored procedure in package curspkg_join
  1536. // open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
  1537. Console.WriteLine("Create parameters...");
  1538. OracleParameter parm1 = new OracleParameter("n_Empno", OracleType.Number);
  1539. parm1.Direction = ParameterDirection.Input;
  1540. parm1.Value = 7902;
  1541. OracleParameter parm2 = new OracleParameter("io_cursor", OracleType.Cursor);
  1542. parm2.Direction = ParameterDirection.Output;
  1543. cmd.Parameters.Add(parm1);
  1544. cmd.Parameters.Add(parm2);
  1545. // positional parm
  1546. //cmd.Parameters.Add(new OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output;
  1547. // named parm
  1548. //cmd.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 7902;
  1549. OracleDataReader reader;
  1550. Console.WriteLine("Execute Non Query...");
  1551. cmd.ExecuteNonQuery();
  1552. Console.WriteLine("Get data reader (ref cursor) from out parameter...");
  1553. reader = (OracleDataReader) cmd.Parameters["io_cursor"].Value;
  1554. int x, count;
  1555. count = 0;
  1556. Console.WriteLine("Get data from ref cursor...");
  1557. while (reader.Read()) {
  1558. for (x = 0; x < reader.FieldCount; x++)
  1559. Console.Write(reader[x] + " ");
  1560. Console.WriteLine();
  1561. count += 1;
  1562. }
  1563. Console.WriteLine(count.ToString() + " Rows Returned.");
  1564. reader.Close();
  1565. }
  1566. static void ExternalAuthenticationTest ()
  1567. {
  1568. string user = Environment.UserName;
  1569. if (!Environment.UserDomainName.Equals(String.Empty))
  1570. user = Environment.UserDomainName + "\\" + Environment.UserName;
  1571. Console.WriteLine("Environment UserDomainName and UserName: " + user);
  1572. Console.WriteLine("Open connection using external authentication...");
  1573. OracleConnection con = new OracleConnection("Data Source=palis;Integrated Security=true");
  1574. try {
  1575. con.Open();
  1576. OracleCommand cmd = con.CreateCommand();
  1577. cmd.CommandText = "SELECT USER FROM DUAL";
  1578. OracleDataReader reader = cmd.ExecuteReader();
  1579. if (reader.Read())
  1580. Console.WriteLine("User: " + reader.GetString(reader.GetOrdinal("USER")));
  1581. con.Close();
  1582. }
  1583. catch (Exception e) {
  1584. Console.WriteLine("Exception caught: " + e.Message);
  1585. Console.WriteLine("Probably not setup for external authentication.");
  1586. }
  1587. con.Dispose();
  1588. con = null;
  1589. }
  1590. public static void TestPersistSucurityInfo1()
  1591. {
  1592. Console.WriteLine("\nTestPersistSucurityInfo1 - persist security info=false");
  1593. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=false");
  1594. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1595. con.Open();
  1596. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1597. con.Close();
  1598. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1599. con = null;
  1600. }
  1601. public static void TestPersistSucurityInfo2()
  1602. {
  1603. Console.WriteLine("\nTestPersistSucurityInfo2 - persist security info=true");
  1604. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=true");
  1605. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1606. con.Open();
  1607. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1608. con.Close();
  1609. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1610. con = null;
  1611. }
  1612. public static void TestPersistSucurityInfo3()
  1613. {
  1614. Console.WriteLine("\nTestPersistSucurityInfo3 - use default for persist security info which is false");
  1615. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger");
  1616. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1617. con.Open();
  1618. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1619. con.Close();
  1620. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1621. con = null;
  1622. }
  1623. public static void TestPersistSucurityInfo4()
  1624. {
  1625. Console.WriteLine("\nTestPersistSucurityInfo4 - persist security info=false with password at front");
  1626. OracleConnection con = new OracleConnection(";password=tiger;data source=palis;user id=scott;persist security info=false");
  1627. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1628. con.Open();
  1629. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1630. con.Close();
  1631. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1632. con = null;
  1633. }
  1634. public static void TestPersistSucurityInfo5()
  1635. {
  1636. Console.WriteLine("\nTestPersistSucurityInfo5 - persist security info=false");
  1637. OracleConnection con = new OracleConnection("data source=palis;user id=scott;password=tiger;persist security info=false");
  1638. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1639. con.Open();
  1640. Console.WriteLine("ConnectionString after open: " + con.ConnectionString);
  1641. Console.WriteLine("ConnectionState for con: " + con.State.ToString() + "\n");
  1642. Console.WriteLine("Clone OracleConnection...");
  1643. OracleConnection con2 = (OracleConnection) ((ICloneable) con).Clone();
  1644. Console.WriteLine("ConnectionState for con2: " + con2.State.ToString());
  1645. Console.WriteLine("con2 ConnectionString before open: " + con2.ConnectionString);
  1646. con2.Open();
  1647. Console.WriteLine("con2 ConnectionString after open: " + con2.ConnectionString);
  1648. con2.Close();
  1649. Console.WriteLine("con2 ConnectionString after close: " + con2.ConnectionString);
  1650. con.Close();
  1651. }
  1652. public static void TestPersistSucurityInfo6()
  1653. {
  1654. Console.WriteLine("\nTestPersistSucurityInfo6 - external auth using persist security info");
  1655. string user = Environment.UserName;
  1656. if (!Environment.UserDomainName.Equals(String.Empty))
  1657. user = Environment.UserDomainName + "\\" + Environment.UserName;
  1658. Console.WriteLine("Environment UserDomainName and UserName: " + user);
  1659. Console.WriteLine("Open connection using external authentication...");
  1660. OracleConnection con = new OracleConnection("Data Source=palis;Integrated Security=true");
  1661. Console.WriteLine("ConnectionString before open: " + con.ConnectionString);
  1662. try {
  1663. con.Open();
  1664. OracleCommand cmd = con.CreateCommand();
  1665. cmd.CommandText = "SELECT USER FROM DUAL";
  1666. OracleDataReader reader = cmd.ExecuteReader();
  1667. if (reader.Read())
  1668. Console.WriteLine("User: " + reader.GetString(reader.GetOrdinal("USER")));
  1669. con.Close();
  1670. Console.WriteLine("ConnectionString after close: " + con.ConnectionString);
  1671. }
  1672. catch (Exception e) {
  1673. Console.WriteLine("Exception caught: " + e.Message);
  1674. Console.WriteLine("Probably not setup for external authentication. This is fine.");
  1675. }
  1676. con.Dispose();
  1677. Console.WriteLine("ConnectionString after dispose: " + con.ConnectionString);
  1678. con = null;
  1679. Console.WriteLine("\n\n");
  1680. }
  1681. public static void ConnectionPoolingTest1 ()
  1682. {
  1683. Console.WriteLine("Start Connection Pooling Test 1...");
  1684. OracleConnection[] connections = null;
  1685. int maxCon = MAX_CONNECTIONS + 1; // add 1 more over the max connections to cause it to wait for the next available connection
  1686. int i = 0;
  1687. try {
  1688. connections = new OracleConnection[maxCon];
  1689. for (i = 0; i < maxCon; i++) {
  1690. Console.WriteLine(" Open connection: {0}", i);
  1691. connections[i] = new OracleConnection(conStr);
  1692. connections[i].Open ();
  1693. }
  1694. } catch (InvalidOperationException e) {
  1695. Console.WriteLine("Expected exception InvalidOperationException caught.");
  1696. Console.WriteLine(e);
  1697. }
  1698. for (i = 0; i < maxCon; i++) {
  1699. if (connections[i] != null) {
  1700. Console.WriteLine(" Close connection: {0}", i);
  1701. if (connections[i].State == ConnectionState.Open)
  1702. connections[i].Close ();
  1703. connections[i].Dispose ();
  1704. connections[i] = null;
  1705. }
  1706. }
  1707. connections = null;
  1708. Console.WriteLine("Done Connection Pooling Test 1.");
  1709. }
  1710. public static void ConnectionPoolingTest2 ()
  1711. {
  1712. Console.WriteLine("Start Connection Pooling Test 2...");
  1713. OracleConnection[] connections = null;
  1714. int maxCon = MAX_CONNECTIONS;
  1715. int i = 0;
  1716. connections = new OracleConnection[maxCon];
  1717. for (i = 0; i < maxCon; i++) {
  1718. Console.WriteLine(" Open connection: {0}", i);
  1719. connections[i] = new OracleConnection(conStr);
  1720. connections[i].Open ();
  1721. }
  1722. Console.WriteLine("Start another thread...");
  1723. t = new Thread(new ThreadStart(AnotherThreadProc));
  1724. t.Start ();
  1725. Console.WriteLine("Sleep...");
  1726. Thread.Sleep(100);
  1727. Console.WriteLine("Closing...");
  1728. for (i = 0; i < maxCon; i++) {
  1729. if (connections[i] != null) {
  1730. Console.WriteLine(" Close connection: {0}", i);
  1731. if (connections[i].State == ConnectionState.Open)
  1732. connections[i].Close ();
  1733. connections[i].Dispose ();
  1734. connections[i] = null;
  1735. }
  1736. }
  1737. connections = null;
  1738. }
  1739. private static void AnotherThreadProc ()
  1740. {
  1741. Console.WriteLine("Open connection via another thread...");
  1742. OracleConnection[] connections = null;
  1743. int maxCon = MAX_CONNECTIONS;
  1744. int i = 0;
  1745. connections = new OracleConnection[maxCon];
  1746. for (i = 0; i < maxCon; i++) {
  1747. Console.WriteLine(" Open connection: {0}", i);
  1748. connections[i] = new OracleConnection(conStr);
  1749. connections[i].Open ();
  1750. }
  1751. Console.WriteLine("Done Connection Pooling Test 2.");
  1752. System.Environment.Exit (0);
  1753. }
  1754. [STAThread]
  1755. static void Main(string[] args)
  1756. {
  1757. if(args.Length != 3) {
  1758. Console.WriteLine("Usage: mono TestOracleClient database userid password");
  1759. return;
  1760. }
  1761. string connectionString = String.Format(
  1762. "Data Source={0};" +
  1763. "User ID={1};" +
  1764. "Password={2}",
  1765. args[0], args[1], args[2]);
  1766. conStr = connectionString;
  1767. OracleConnection con1 = new OracleConnection();
  1768. ShowConnectionProperties (con1);
  1769. con1.ConnectionString = connectionString;
  1770. con1.InfoMessage += new OracleInfoMessageEventHandler (OnInfoMessage);
  1771. con1.StateChange += new StateChangeEventHandler (OnStateChange);
  1772. Console.WriteLine("Opening...");
  1773. con1.Open ();
  1774. Console.WriteLine("Opened.");
  1775. ShowConnectionProperties (con1);
  1776. Console.WriteLine ("Mono Oracle Test BEGIN ...");
  1777. MonoTest (con1);
  1778. Console.WriteLine ("Mono Oracle Test END ...");
  1779. Wait ("");
  1780. Console.WriteLine ("LOB Test BEGIN...");
  1781. CLOBTest (con1);
  1782. BLOBTest (con1);
  1783. Console.WriteLine ("LOB Test END.");
  1784. Wait ("");
  1785. Console.WriteLine ("Read Simple Test BEGIN - scott.emp...");
  1786. ReadSimpleTest(con1, "SELECT e.*, e.rowid FROM scott.emp e");
  1787. Console.WriteLine ("Read Simple Test END - scott.emp");
  1788. Wait ("");
  1789. Console.WriteLine ("DataAdapter Test BEGIN...");
  1790. DataAdapterTest(con1);
  1791. Console.WriteLine ("DataAdapter Test END.");
  1792. Wait ("");
  1793. Console.WriteLine ("DataAdapter Test 2 BEGIN...");
  1794. DataAdapterTest2(con1);
  1795. Console.WriteLine ("DataAdapter Test 2 END.");
  1796. Wait ("");
  1797. Console.WriteLine ("Rollback Test BEGIN...");
  1798. RollbackTest(con1);
  1799. Console.WriteLine ("Rollback Test END.");
  1800. Wait ("");
  1801. Console.WriteLine ("Commit Test BEGIN...");
  1802. CommitTest(con1);
  1803. Console.WriteLine ("Commit Test END.");
  1804. Wait ("");
  1805. Console.WriteLine ("Parameter Test BEGIN...");
  1806. ParameterTest(con1);
  1807. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE7");
  1808. Console.WriteLine ("Parameter Test END.");
  1809. Wait ("");
  1810. Console.WriteLine ("Stored Proc Test 1 BEGIN...");
  1811. StoredProcedureTest1 (con1);
  1812. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE1");
  1813. Console.WriteLine ("Stored Proc Test 1 END...");
  1814. Wait ("");
  1815. Console.WriteLine ("Stored Proc Test 2 BEGIN...");
  1816. StoredProcedureTest2 (con1);
  1817. ReadSimpleTest(con1, "SELECT * FROM MONO_TEST_TABLE2");
  1818. Console.WriteLine ("Stored Proc Test 2 END...");
  1819. Console.WriteLine ("Out Parameter and PL/SQL Block Test 1 BEGIN...");
  1820. OutParmTest1 (con1);
  1821. Console.WriteLine ("Out Parameter and PL/SQL Block Test 1 END...");
  1822. Console.WriteLine ("Out Parameter and PL/SQL Block Test 2 BEGIN...");
  1823. OutParmTest2 (con1);
  1824. Console.WriteLine ("Out Parameter and PL/SQL Block Test 2 END...");
  1825. Console.WriteLine ("Out Parameter and PL/SQL Block Test 3 BEGIN...");
  1826. OutParmTest3 (con1);
  1827. Console.WriteLine ("Out Parameter and PL/SQL Block Test 3 END...");
  1828. Wait ("");
  1829. Console.WriteLine ("Test a Non Query using Execute Reader BEGIN...");
  1830. TestNonQueryUsingExecuteReader (con1);
  1831. Console.WriteLine ("Test a Non Query using Execute Reader END...");
  1832. Wait ("");
  1833. Console.WriteLine ("Null Aggregate Warning BEGIN test...");
  1834. NullAggregateTest (con1);
  1835. Console.WriteLine ("Null Aggregate Warning END test...");
  1836. Console.WriteLine ("Ref Cursor BEGIN tests...");
  1837. RefCursorTests (con1);
  1838. Console.WriteLine ("Ref Cursor END tests...");
  1839. Console.WriteLine("Closing...");
  1840. con1.Close ();
  1841. Console.WriteLine("Closed.");
  1842. // Need to have an external authentication user setup in Linux and oracle
  1843. // before running this test
  1844. //ExternalAuthenticationTest();
  1845. /*
  1846. TestPersistSucurityInfo1();
  1847. TestPersistSucurityInfo2();
  1848. TestPersistSucurityInfo3();
  1849. TestPersistSucurityInfo4();
  1850. TestPersistSucurityInfo5();
  1851. TestPersistSucurityInfo6();
  1852. */
  1853. //conStr = conStr + ";pooling=true;min pool size=4;max pool size=" + MAX_CONNECTIONS.ToString ();
  1854. //ConnectionPoolingTest1 ();
  1855. //ConnectionPoolingTest2 ();
  1856. Console.WriteLine("Done.");
  1857. }
  1858. }
  1859. }