OleDbDataAdapter_Fill_2.cs 22 KB

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