OracleDataAdapter_Fill_2.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OracleClient;
  26. using NUnit.Framework;
  27. using MonoTests.System.Data.Utils;
  28. namespace MonoTests.System.Data.OracleClient
  29. {
  30. [TestFixture]
  31. public class OracleDataAdapter_Fill_2 : ADONetTesterClass
  32. {
  33. private string nonUniqueId;
  34. public static void Main()
  35. {
  36. OracleDataAdapter_Fill_2 tc = new OracleDataAdapter_Fill_2();
  37. Exception exp = null;
  38. try
  39. {
  40. tc.BeginTest("OracleDataAdapter_Fill_2");
  41. tc.run();
  42. }
  43. catch(Exception ex){exp = ex;}
  44. finally {tc.EndTest(exp);}
  45. }
  46. [Test]
  47. public void run()
  48. {
  49. OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  50. con.Open();
  51. //DoTestThis(con);
  52. DoTestTypes1(con);
  53. //Don't know how to access diffrent database
  54. if ((ConnectedDataProvider.GetDbType(con) != DataBaseServer.DB2) && (ConnectedDataProvider.GetDbType(con) != DataBaseServer.PostgreSQL))
  55. {
  56. DoTestTypes2(con);
  57. DoTestTypes3(con);
  58. }
  59. #if TARGET_JVM
  60. DoTestTypes4(con);
  61. #endif
  62. // DoTestTypes5(con); //Table direct --> multipe tables
  63. DoTestTypes6(con);
  64. if ((ConnectedDataProvider.GetDbType(con) != DataBaseServer.Oracle) &&
  65. (ConnectedDataProvider.GetDbType(con) != DataBaseServer.PostgreSQL))
  66. {
  67. DoTestTypes7(con); //Diffrent owner
  68. }
  69. DoTestTypes8(con); //Diffrent owner
  70. //TBD!!
  71. //DoTestTypes9(con);
  72. if (ConnectedDataProvider.GetDbType(con) != DataBaseServer.PostgreSQL)
  73. {
  74. DoTestTypes10(con);
  75. }
  76. CallStoredProcedureInPackage(con);
  77. StoredProcedurePackageambiguity_InsidePackage(con);
  78. StoredProcedurePackageambiguity_OutsidePackage(con);
  79. if (con.State == ConnectionState.Open) con.Close();
  80. }
  81. //[Test]
  82. public void DoTestThis(OracleConnection con)
  83. {
  84. Exception exp = null;
  85. OracleCommand cmd = new OracleCommand("GH_CREATETABLE", con);
  86. cmd.CommandType = CommandType.StoredProcedure;
  87. OracleDataAdapter da = new OracleDataAdapter(cmd);
  88. DataSet ds = new DataSet();
  89. try
  90. {
  91. BeginCase("Check effected rows after create table ddl in stored procedure.");
  92. int RowsAffected;
  93. RowsAffected = cmd.ExecuteNonQuery();
  94. int ExpectedRowsAffected;
  95. switch (ConnectedDataProvider.GetDbType(con))
  96. {
  97. case DataBaseServer.SQLServer:
  98. case DataBaseServer.Sybase:
  99. ExpectedRowsAffected = 3;
  100. break;
  101. case DataBaseServer.Oracle:
  102. //In .NET the ExpectedRowsAffected is '1', where as in Java it is '-1', this gap is because of jdbc driver for oracle.
  103. ExpectedRowsAffected = -1;
  104. break;
  105. case DataBaseServer.DB2:
  106. ExpectedRowsAffected = -1;
  107. break;
  108. default:
  109. string errMsg = string.Format("GHT: Test not implemented for DB type: {0}", ConnectedDataProvider.GetDbType(con));
  110. throw new NotImplementedException(errMsg);
  111. }
  112. Compare(RowsAffected ,ExpectedRowsAffected);
  113. }
  114. catch(Exception ex) {exp = ex;}
  115. finally {EndCase(exp); exp = null;}
  116. }
  117. #region Select by full table name in the same catalog
  118. //[Test]
  119. public void DoTestTypes1(OracleConnection conn)
  120. {
  121. DataSet ds = new DataSet();
  122. OracleCommand comm = new OracleCommand("",conn);
  123. OracleDataAdapter da = new OracleDataAdapter();
  124. da.SelectCommand = comm;
  125. string tableName = getDbObjectName("Employees",conn);
  126. int expectedRowsCount = 8;
  127. #region Select by full table name in the same catalog
  128. string[] arr = new string[2];
  129. arr[0] = "LastName";
  130. arr[1] = "FirstName";
  131. prepareTableForTest(conn,expectedRowsCount,"Employees","EmployeeID",arr);
  132. comm.CommandText="select max(EmployeeID) from " + tableName;
  133. // on some databases the max is on a field which is decimal
  134. decimal maxEmployee = decimal.Parse(comm.ExecuteScalar().ToString()) - expectedRowsCount;
  135. comm.CommandText = "SELECT EmployeeID FROM " + tableName + " where EmployeeID > " + maxEmployee.ToString() ;
  136. da.Fill(ds);
  137. Exception exp = null;
  138. try
  139. {
  140. BeginCase("Select by full table name in the same catalog");
  141. Compare(ds.Tables[0].Rows.Count ,expectedRowsCount );
  142. }
  143. catch(Exception ex) {exp = ex;}
  144. finally {cleanTableAfterTest(conn,"Employees","EmployeeID",Convert.ToInt32(maxEmployee));
  145. EndCase(exp); exp = null;}
  146. #endregion //Select by full table name in the same catalog
  147. }
  148. #endregion
  149. #region Select by full table name in the different catalog
  150. //[Test]
  151. public void DoTestTypes2(OracleConnection conn)
  152. {
  153. BeginCase("Select by full table name in the different catalog");
  154. nonUniqueId = "48951_" + TestCaseNumber.ToString();
  155. Exception exp=null;
  156. string tableName = getDbObjectName("Customers",conn,"GHTDB_EX");
  157. int expectedRowsCount = 5;
  158. DataSet ds = new DataSet();
  159. OracleCommand comm = new OracleCommand("",conn);
  160. OracleDataAdapter da = new OracleDataAdapter();
  161. da.SelectCommand = comm;
  162. insertIntoStandatTable(conn,tableName,expectedRowsCount,"CustomerID");
  163. comm.CommandText = "SELECT * FROM " + tableName + " where CustomerID='" + nonUniqueId + "'" ;
  164. ds.Tables.Clear();
  165. da.Fill(ds);
  166. try
  167. {
  168. Compare(ds.Tables[0].Rows.Count ,expectedRowsCount );
  169. }
  170. catch(Exception ex) {exp = ex;}
  171. finally {EndCase(exp); exp = null;
  172. cleanStandatTable(conn,tableName,"CustomerID");
  173. }
  174. }
  175. #endregion
  176. #region Call stored procedure in the different catalog
  177. //[Test]
  178. public void DoTestTypes3(OracleConnection conn)
  179. {
  180. BeginCase("Call stored procedure in the different catalog");
  181. nonUniqueId = "48951_" + TestCaseNumber.ToString();
  182. Exception exp =null;
  183. DataSet ds = new DataSet();
  184. OracleCommand comm = new OracleCommand("",conn);
  185. OracleDataAdapter da = new OracleDataAdapter();
  186. da.SelectCommand = comm;
  187. string tableName = getDbObjectName("Customers",conn,"GHTDB_EX");
  188. int expectedRowsCount = 5;
  189. insertIntoStandatTable(conn,tableName,expectedRowsCount,"CustomerID");
  190. comm.CommandType = CommandType.StoredProcedure;
  191. comm.CommandText = getDbObjectName("GH_DUMMY",conn,"GHTDB_EX");
  192. comm.Parameters.Add(new OracleParameter("CustomerIDPrm",OracleType.Char));
  193. comm.Parameters.Add(new OracleParameter("result",OracleType.Cursor)).Direction = ParameterDirection.Output;
  194. comm.Parameters[0].Value = nonUniqueId;
  195. ds.Tables.Clear();
  196. try
  197. {
  198. da.Fill(ds);
  199. Compare(ds.Tables[0].Rows.Count ,expectedRowsCount );
  200. }
  201. catch(Exception ex) {exp = ex;}
  202. finally {EndCase(exp); exp = null;
  203. cleanStandatTable(conn,tableName,"CustomerID"); }
  204. }
  205. #endregion // Call stored procedure in the different catalog
  206. #region Select using Table direct - single table
  207. //[Test]
  208. public void DoTestTypes4(OracleConnection conn)
  209. {
  210. Exception exp =null;
  211. DataSet ds = new DataSet();
  212. OracleCommand comm = new OracleCommand("",conn);
  213. OracleDataAdapter da = new OracleDataAdapter();
  214. da.SelectCommand = comm;
  215. string tableName = getDbObjectName("Customers",conn);
  216. //int expectedRowsCount = 5;
  217. comm.CommandText = tableName;
  218. comm.CommandType = CommandType.TableDirect;
  219. ds.Tables.Clear();
  220. da.Fill(ds);
  221. try
  222. {
  223. BeginCase("Select using Table direct - single table");
  224. Compare(ds.Tables[0].Rows.Count > 0 ,true );
  225. }
  226. catch(Exception ex) {exp = ex;}
  227. finally {EndCase(exp); exp = null;}
  228. }
  229. #endregion // Select using Table direct - single table
  230. #region Select using Table direct - multiple tables
  231. //[Test]
  232. public void DoTestTypes5(OracleConnection conn)
  233. {
  234. Exception exp =null;
  235. DataSet ds = new DataSet();
  236. OracleCommand comm = new OracleCommand("",conn);
  237. OracleDataAdapter da = new OracleDataAdapter();
  238. da.SelectCommand = comm;
  239. //string tableName = getDbObjectName("Customers",conn);
  240. comm.CommandType = CommandType.TableDirect;
  241. comm.CommandText = "Categories;Employees";
  242. ds.Tables.Clear();
  243. da.Fill(ds);
  244. try
  245. {
  246. BeginCase("Select using Table direct - multiple tables");
  247. int result = + ds.Tables[1].Rows.Count + ds.Tables[2].Rows.Count;
  248. Compare(ds.Tables[0].Rows.Count > 0 ,true );
  249. Compare(ds.Tables[1].Rows.Count > 0 ,true );
  250. Compare(ds.Tables[0].Rows.Count == ds.Tables[1].Rows.Count ,true );
  251. }
  252. catch(Exception ex) {exp = ex;}
  253. finally {EndCase(exp); exp = null;}
  254. }
  255. #endregion // Select using Table direct - multiple tables
  256. #region Test view
  257. //[Test]
  258. public void DoTestTypes6(OracleConnection conn)
  259. {
  260. Exception exp =null;
  261. DataSet ds = new DataSet();
  262. OracleCommand comm = new OracleCommand("",conn);
  263. OracleDataAdapter da = new OracleDataAdapter();
  264. da.SelectCommand = comm;
  265. //string tableName = getDbObjectName("Customers",conn);
  266. comm.CommandType = CommandType.Text;
  267. switch (ConnectedDataProvider.GetDbType(conn))
  268. {
  269. case DataBaseServer.SQLServer:
  270. case DataBaseServer.Sybase:
  271. comm.CommandText = "select * from [Current Product List]";
  272. break;
  273. case DataBaseServer.Oracle:
  274. case DataBaseServer.PostgreSQL:
  275. comm.CommandText = "select * from Current_Product_List";
  276. break;
  277. default:
  278. comm.CommandText = "select * from DB2ADMIN.Current_Product_List";
  279. break;
  280. }
  281. ds.Tables.Clear();
  282. da.Fill(ds);
  283. try
  284. {
  285. BeginCase("Testing view");
  286. Compare(ds.Tables[0].Rows.Count >0,true);
  287. Compare(ds.Tables[0].Columns.Count,2);
  288. }
  289. catch(Exception ex) {exp = ex;}
  290. finally {EndCase(exp); exp = null;}
  291. }
  292. #endregion
  293. #region select table with diffrent owner - diffrent name
  294. //[Test]
  295. public void DoTestTypes7(OracleConnection conn)
  296. {
  297. Exception exp =null;
  298. DataSet ds = new DataSet();
  299. OracleCommand comm = new OracleCommand("",conn);
  300. OracleDataAdapter da = new OracleDataAdapter();
  301. da.SelectCommand = comm;
  302. //string tableName = getDbObjectName("Customers",conn);
  303. comm.CommandType = CommandType.Text;
  304. //First change ownerShip
  305. //chageOwnerShip(conn,"Categories","mainsoft");
  306. comm.CommandText = "SELECT * FROM mainsoft.CategoriesNew";
  307. da.Fill(ds);
  308. try
  309. {
  310. BeginCase("select table with diffrent owner - diffrent name");
  311. Compare(ds.Tables[0].Rows.Count ,2);
  312. }
  313. catch(Exception ex) {exp = ex;}
  314. finally {EndCase(exp); exp = null;}
  315. try
  316. {
  317. BeginCase("select table with diffrent owner - diffrent name --> negetive");
  318. ds.Tables.Clear();
  319. comm.CommandText = "select * from " + getDbObjectName("CategoriesNew",conn);
  320. da.Fill(ds);
  321. }
  322. catch (OracleException ex)
  323. {
  324. ExpectedExceptionCaught(ex);
  325. }
  326. catch {ExpectedExceptionNotCaught("OracleException"); }
  327. finally {EndCase(exp); exp = null;}
  328. //Change back
  329. //chageOwnerShip(conn,"mainsoft.Categories","dbo");
  330. }
  331. #endregion
  332. #region select table with diffrent owner - same name
  333. //[Test]
  334. public void DoTestTypes8(OracleConnection conn)
  335. {
  336. Exception exp =null;
  337. DataSet ds = new DataSet();
  338. OracleCommand comm = new OracleCommand("",conn);
  339. OracleDataAdapter da = new OracleDataAdapter();
  340. da.SelectCommand = comm;
  341. //string tableName = getDbObjectName("Customers",conn);
  342. comm.CommandType = CommandType.Text;
  343. //First change ownerShip
  344. //chageOwnerShip(conn,"Categories","mainsoft");
  345. comm.CommandText = "SELECT * FROM GHTDB_EX.Categories";
  346. da.Fill(ds);
  347. try
  348. {
  349. BeginCase("Select table with diffrent owner same name");
  350. Compare(ds.Tables[0].Rows.Count ,2);
  351. }
  352. catch(Exception ex) {exp = ex;}
  353. finally {EndCase(exp); exp = null;}
  354. }
  355. #endregion
  356. #region select table with diffrent owner - SP
  357. //[Test]
  358. public void DoTestTypes9(OracleConnection conn)
  359. {
  360. Exception exp =null;
  361. DataSet ds = new DataSet();
  362. BeginCase("Select table with diffrent owner SP");
  363. nonUniqueId = "48951" ;
  364. int expectedRowsCount = 5;
  365. OracleCommand comm = new OracleCommand("",conn);
  366. OracleDataAdapter da = new OracleDataAdapter();
  367. da.SelectCommand = comm;
  368. string tableName = getDbObjectName("Employees",conn);
  369. comm.CommandType = CommandType.StoredProcedure;
  370. //insertIntoStandatTable(conn,tableName,5,"EmployeeID");
  371. string[] arr = new string[2];
  372. arr[0] = "LastName";
  373. arr[1] = "FirstName";
  374. int maxValue = prepareTableForTest(conn,expectedRowsCount,"Employees","EmployeeID",arr);
  375. comm.Parameters.Add("CustomerIdPrm",maxValue.ToString());
  376. comm.Parameters.Add(new OracleParameter("result",OracleType.Cursor)).Direction = ParameterDirection.Output;
  377. try
  378. {
  379. comm.CommandText = "GHTDB_EX.GH_DUMMY";
  380. da.Fill(ds);
  381. Compare(ds.Tables[0].Rows.Count ,expectedRowsCount);
  382. }
  383. catch(Exception ex) {exp = ex;}
  384. finally {EndCase(exp); exp = null;
  385. cleanTableAfterTest (conn,"Employees","EmployeeID",maxValue); }
  386. }
  387. #endregion
  388. #region select table with diffrent owner - and diffrent structure
  389. //[Test]
  390. public void DoTestTypes10(OracleConnection conn)
  391. {
  392. Exception exp =null;
  393. DataSet ds = new DataSet();
  394. BeginCase("Select table with diffrent owner and diffrent structure");
  395. nonUniqueId = "48951" ;
  396. OracleCommand comm = new OracleCommand("",conn);
  397. OracleDataAdapter da = new OracleDataAdapter();
  398. da.SelectCommand = comm;
  399. string tableName = getDbObjectName("Categories",conn);
  400. comm.CommandType = CommandType.Text;
  401. OracleDataReader reader = null;
  402. try
  403. {
  404. comm.CommandText = "select CategoryID,CategoryName from " + tableName;
  405. reader = comm.ExecuteReader();
  406. //da.Fill(ds);
  407. }
  408. catch (Exception ex)
  409. {
  410. EndCase(ex);
  411. }
  412. finally
  413. {
  414. reader.Close();
  415. }
  416. comm.CommandText="select CategoryID,CategoryName from GHTDB_EX.Categories where CategoryID = :a";
  417. comm.Parameters.Add("a","10");
  418. da.Fill(ds);
  419. try
  420. {
  421. Compare(ds.Tables[0].Rows.Count ,1);
  422. }
  423. catch(Exception ex) {exp = ex;}
  424. finally
  425. {
  426. EndCase(exp); exp = null;}
  427. }
  428. #endregion
  429. #region Oracle - use stored procedure inside package
  430. //[Test(Description="Call a stored procedure which is defined within a package.")]
  431. public void CallStoredProcedureInPackage(OracleConnection con)
  432. {
  433. if (ConnectedDataProvider.GetDbType(con) != DataBaseServer.Oracle)
  434. {
  435. //Packages exist only in oracle.
  436. return;
  437. }
  438. Exception exp = null;
  439. OracleDataReader rdr = null;
  440. try
  441. {
  442. BeginCase("Call a stored procedure which is defined within a package.");
  443. exp = null;
  444. DataSet ds = new DataSet();
  445. OracleDataAdapter da = new OracleDataAdapter();
  446. OracleCommand cmd = new OracleCommand();
  447. cmd.Connection = con;
  448. cmd.CommandType = CommandType.StoredProcedure;
  449. cmd.CommandText = "ghtpkg.ghsp_inPkg";
  450. cmd.Parameters.Add("CustomerIdPrm", "ALFKI");
  451. cmd.Parameters.Add(new OracleParameter("result",OracleType.Cursor)).Direction = ParameterDirection.Output;
  452. da.SelectCommand = cmd;
  453. da.Fill(ds);
  454. Compare(ds.Tables[0].Rows.Count, 1);
  455. }
  456. catch(Exception ex)
  457. {
  458. exp = ex;
  459. }
  460. finally
  461. {
  462. if (rdr != null)
  463. {
  464. rdr.Close();
  465. }
  466. EndCase(exp);
  467. }
  468. }
  469. //[Test(Description="Call a stored procedure ghsp_pkgAmbig from a package, where ghsp_pkgAmbig is defined both inside and outside of a package.")]
  470. public void StoredProcedurePackageambiguity_InsidePackage(OracleConnection con)
  471. {
  472. if (ConnectedDataProvider.GetDbType(con) != DataBaseServer.Oracle)
  473. {
  474. //Packages exist only in oracle.
  475. return;
  476. }
  477. Exception exp = null;
  478. OracleDataReader rdr = null;
  479. try
  480. {
  481. BeginCase("Call a stored procedure ghsp_pkgAmbig from a package, where ghsp_pkgAmbig is defined both inside and outside of a package.");
  482. exp = null;
  483. DataSet ds = new DataSet();
  484. OracleDataAdapter da = new OracleDataAdapter();
  485. OracleCommand cmd = new OracleCommand();
  486. cmd.Connection = con;
  487. cmd.CommandType = CommandType.StoredProcedure;
  488. cmd.CommandText = "ghtpkg.ghsp_pkgAmbig";
  489. cmd.Parameters.Add(new OracleParameter("res",OracleType.Cursor)).Direction = ParameterDirection.Output;
  490. da.SelectCommand = cmd;
  491. da.Fill(ds);
  492. Compare(ds.Tables[0].Rows[0]["IN_PKG"], "TRUE");
  493. }
  494. catch(Exception ex)
  495. {
  496. exp = ex;
  497. }
  498. finally
  499. {
  500. if (rdr != null)
  501. {
  502. rdr.Close();
  503. }
  504. EndCase(exp);
  505. }
  506. }
  507. //[Test(Description="Call a stored procedure ghsp_pkgAmbig not from a package, where ghsp_pkgAmbig is defined both inside and outside of a package.")]
  508. public void StoredProcedurePackageambiguity_OutsidePackage(OracleConnection con)
  509. {
  510. if (ConnectedDataProvider.GetDbType(con) != DataBaseServer.Oracle)
  511. {
  512. //Packages exist only in oracle.
  513. return;
  514. }
  515. Exception exp = null;
  516. OracleDataReader rdr = null;
  517. try
  518. {
  519. BeginCase("Call a stored procedure ghsp_pkgAmbig not from a package, where ghsp_pkgAmbig is defined both inside and outside of a package.");
  520. exp = null;
  521. DataSet ds = new DataSet();
  522. OracleDataAdapter da = new OracleDataAdapter();
  523. OracleCommand cmd = new OracleCommand();
  524. cmd.Connection = con;
  525. cmd.CommandType = CommandType.StoredProcedure;
  526. cmd.CommandText = "ghsp_pkgAmbig";
  527. cmd.Parameters.Add(new OracleParameter("res",OracleType.Cursor)).Direction = ParameterDirection.Output;
  528. da.SelectCommand = cmd;
  529. da.Fill(ds);
  530. Compare(ds.Tables[0].Rows[0]["IN_PKG"], "FALSE");
  531. }
  532. catch(Exception ex)
  533. {
  534. exp = ex;
  535. }
  536. finally
  537. {
  538. if (rdr != null)
  539. {
  540. rdr.Close();
  541. }
  542. EndCase(exp);
  543. }
  544. }
  545. #endregion
  546. private string getDbObjectName(string objectName,OracleConnection con)
  547. {
  548. return getDbObjectName(objectName,con,string.Empty);
  549. }
  550. private string getDbObjectName(string objectName,OracleConnection con,string databaseName)
  551. {
  552. switch (ConnectedDataProvider.GetDbType(con))
  553. {
  554. case DataBaseServer.SQLServer:
  555. case DataBaseServer.Sybase:
  556. {
  557. if (databaseName == string.Empty)
  558. {
  559. return "GHTDB.dbo." + objectName;
  560. }
  561. else
  562. {
  563. return databaseName + ".dbo." + objectName;
  564. }
  565. }
  566. case DataBaseServer.PostgreSQL:
  567. {
  568. return "public." + objectName.ToUpper();
  569. }
  570. case DataBaseServer.Oracle:
  571. {
  572. if (databaseName == string.Empty)
  573. {
  574. return "GHTDB." + objectName.ToUpper();
  575. }
  576. else
  577. {
  578. return databaseName.ToUpper() + "." + objectName.ToUpper();
  579. }
  580. }
  581. case DataBaseServer.DB2:
  582. {
  583. if (databaseName == string.Empty)
  584. {
  585. return "DB2ADMIN." + objectName;
  586. }
  587. else
  588. {
  589. return databaseName + ".DB2ADMIN." + objectName;
  590. }
  591. }
  592. default:
  593. {
  594. throw new NotImplementedException();
  595. }
  596. }
  597. }
  598. /// <summary>
  599. /// This method will prepare table for test
  600. /// </summary>
  601. private int prepareTableForTest(OracleConnection con,int recordsNumber,string baseTableName,string keyField
  602. ,params string[] otherNonNullableFieldsName)
  603. {
  604. string tableName = getDbObjectName(baseTableName,con);
  605. OracleCommand cmd = new OracleCommand("select max(" + keyField + ") from " + tableName,con);
  606. string str_ret = cmd.ExecuteScalar().ToString();
  607. // Console.WriteLine("ExecuteScalar:" + str_ret);
  608. // on some databases the max is on a field which is decimal
  609. decimal maxRecord = decimal.Parse(str_ret);
  610. int resultCount = Convert.ToInt32(maxRecord)+recordsNumber;
  611. string sqlStmt = string.Empty;
  612. string valueStmt = string.Empty;
  613. //Constrcut the statemnet once : --> TODO://Move this logic to seperate method
  614. for(int i=0;i<otherNonNullableFieldsName.Length;i++)
  615. {
  616. sqlStmt+= otherNonNullableFieldsName[i] + ",";
  617. valueStmt+="'a',";
  618. }
  619. //Trim the last ","
  620. if (otherNonNullableFieldsName.Length > 0)
  621. {
  622. sqlStmt = sqlStmt.Remove(sqlStmt.Length-1,1);
  623. sqlStmt = "," + sqlStmt;
  624. valueStmt = valueStmt.Remove(valueStmt.Length-1,1);
  625. valueStmt = "," + valueStmt;
  626. }
  627. for (int index=Convert.ToInt32(maxRecord)+1;index<=resultCount;index++)
  628. {
  629. cmd.CommandText="Insert into " + tableName + " (" + keyField + sqlStmt + ") values ("
  630. + index + valueStmt + ")";
  631. cmd.ExecuteNonQuery();
  632. }
  633. return Convert.ToInt32(maxRecord);
  634. }
  635. private void cleanTableAfterTest(OracleConnection con,string baseTableName, string keyField, int recordNumber)
  636. {
  637. string tableName = getDbObjectName(baseTableName, con);
  638. OracleCommand cmd = new OracleCommand("delete from " + tableName + " where " + keyField + " > " + recordNumber ,con);
  639. cmd.ExecuteNonQuery();
  640. }
  641. private void insertIntoStandatTable(OracleConnection con,string tableName,int recordsNumber,string keyField)
  642. {
  643. OracleCommand cmd = new OracleCommand("delete from " + tableName + " where " + keyField + "= '" + nonUniqueId + "'",con);
  644. cmd.ExecuteNonQuery();
  645. for (int index=0;index<recordsNumber;index++)
  646. {
  647. cmd.CommandText = "Insert into " + tableName + "(" + keyField + ") values ('" + nonUniqueId + "')";
  648. cmd.ExecuteNonQuery();
  649. }
  650. }
  651. private void cleanStandatTable(OracleConnection con,string tableName,string keyField)
  652. {
  653. OracleCommand cmd = new OracleCommand("delete from " + tableName + " where " + keyField + " = '" + nonUniqueId + "'",con);
  654. cmd.ExecuteNonQuery();
  655. }
  656. private void chageOwnerShip(OracleConnection con,string objectName,string newOwner)
  657. {
  658. OracleCommand cmd = new OracleCommand();
  659. cmd.Connection = con;
  660. switch (ConnectedDataProvider.GetDbType(con))
  661. {
  662. case DataBaseServer.SQLServer:
  663. case DataBaseServer.Sybase:
  664. {
  665. cmd.CommandType = CommandType.StoredProcedure;
  666. cmd.CommandText = "[dbo].[sp_changeobjectowner]";
  667. cmd.Parameters.Add("@objname",objectName);
  668. cmd.Parameters.Add("@newowner",newOwner);
  669. cmd.ExecuteNonQuery();
  670. return;
  671. }
  672. default:
  673. {
  674. throw new NotImplementedException();
  675. }
  676. }
  677. }
  678. }
  679. }