OdbcDataReaderTest.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. //
  2. // OdbcDataReaderTest.cs - NUnit Test Cases for testing the
  3. // OdbcDataReader class
  4. //
  5. // Author:
  6. // Sureshkumar T ([email protected])
  7. //
  8. // Copyright (c) 2004 Novell Inc., and the individuals listed
  9. // on the ChangeLog entries.
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Data;
  32. using System.Data.Common;
  33. using System.Data.Odbc;
  34. using System.Globalization;
  35. using System.Text;
  36. using Mono.Data;
  37. using NUnit.Framework;
  38. namespace MonoTests.System.Data
  39. {
  40. [TestFixture]
  41. [Category ("odbc")]
  42. public class OdbcDataReaderTest
  43. {
  44. static byte [] long_bytes = new byte [] {
  45. 0x00, 0x66, 0x06, 0x66, 0x97, 0x00, 0x66, 0x06, 0x66,
  46. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  47. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  48. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  49. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  50. 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  51. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  52. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  53. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  54. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  55. 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  56. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  57. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  58. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  59. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  60. 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  61. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  62. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  63. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  64. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  65. 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  66. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  67. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  68. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  69. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  70. 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  71. 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  72. 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  73. 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  74. 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  75. 0x06, 0x66, 0x06, 0x66, 0x98};
  76. OdbcConnection conn;
  77. OdbcCommand cmd;
  78. [SetUp]
  79. public void SetUp ()
  80. {
  81. conn = (OdbcConnection) ConnectionManager.Singleton.Connection;
  82. ConnectionManager.Singleton.OpenConnection ();
  83. cmd = conn.CreateCommand ();
  84. }
  85. [TearDown]
  86. public void TearDown ()
  87. {
  88. if (cmd != null)
  89. cmd.Dispose ();
  90. ConnectionManager.Singleton.CloseConnection ();
  91. }
  92. [Test]
  93. public void GetBytes ()
  94. {
  95. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  96. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
  97. Assert.IsTrue (reader.Read (), "#C1");
  98. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  99. byte [] val = new byte [totalsize];
  100. long ret = reader.GetBytes (0, 0L, val, 0, (int) (totalsize * 2));
  101. Assert.AreEqual (totalsize, ret, "#C2");
  102. Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#C3");
  103. }
  104. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
  105. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
  106. Assert.IsTrue (reader.Read (), "#G1");
  107. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  108. byte [] val = new byte [totalsize];
  109. int offset = 0;
  110. long ret = 0;
  111. long count = 0;
  112. do {
  113. ret = reader.GetBytes (0, offset, val, offset, 50);
  114. offset += (int) ret;
  115. count += ret;
  116. } while (count < totalsize);
  117. Assert.AreEqual (long_bytes.Length, count, "#G2");
  118. Assert.AreEqual (long_bytes, val, "#G3");
  119. }
  120. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
  121. Assert.IsTrue (reader.Read (), "#H1");
  122. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  123. byte [] val = new byte [totalsize];
  124. int offset = 0;
  125. long ret = 0;
  126. long count = 0;
  127. do {
  128. ret = reader.GetBytes (0, offset, val, offset, 50);
  129. offset += (int) ret;
  130. count += ret;
  131. } while (count < totalsize);
  132. Assert.AreEqual (long_bytes.Length, count, "#H2");
  133. Assert.AreEqual (long_bytes, val, "#H3");
  134. }
  135. }
  136. [Test]
  137. public void GetBytes_Buffer_TooSmall ()
  138. {
  139. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
  140. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
  141. Assert.IsTrue (reader.Read ());
  142. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  143. byte [] val = new byte [totalsize - 1];
  144. long ret = reader.GetBytes (0, 0, val, 0, (int) totalsize);
  145. Assert.AreEqual (274, ret, "#A1");
  146. for (int i = 0; i < ret; i++)
  147. Assert.AreEqual (long_bytes [i], val [i], "#A2:" + i);
  148. for (long i = ret; i < val.Length; i++)
  149. Assert.AreEqual (0x00, val [i], "#A3:" + i);
  150. }
  151. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
  152. Assert.IsTrue (reader.Read ());
  153. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  154. byte [] val = new byte [totalsize];
  155. int buffer_offset = 1;
  156. #if NET_2_0
  157. long ret = reader.GetBytes (0, 0, val, buffer_offset, (int) totalsize);
  158. Assert.AreEqual (274, ret, "#B1");
  159. Assert.AreEqual (0x00, val [0], "#B2");
  160. for (int i = 0; i < ret; i++)
  161. Assert.AreEqual (long_bytes [i], val [i + buffer_offset], "#B2:" + i);
  162. for (long i = (ret + buffer_offset); i < val.Length; i++)
  163. Assert.AreEqual (0x00, val [i], "#B3:" + i);
  164. #else
  165. try {
  166. reader.GetBytes (0, 0, val, buffer_offset, (int) totalsize);
  167. Assert.Fail ("#B1");
  168. } catch (ArgumentOutOfRangeException ex) {
  169. // Requested range extends past the end
  170. // of the array
  171. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
  172. Assert.IsNull (ex.InnerException, "#B3");
  173. Assert.IsNotNull (ex.Message, "#B4");
  174. Assert.IsNull (ex.ParamName, "#B5");
  175. }
  176. #endif
  177. }
  178. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
  179. Assert.IsTrue (reader.Read ());
  180. long totalsize = reader.GetBytes (0, 0, null, 0, 0);
  181. byte [] val = new byte [totalsize];
  182. long ret = reader.GetBytes (0, 0, val, 0, (int) (totalsize + 1));
  183. Assert.AreEqual (totalsize, ret, "#C1");
  184. }
  185. ConnectionManager.Singleton.CloseConnection ();
  186. }
  187. [Test]
  188. public void GetBytes_BufferIndex_Negative ()
  189. {
  190. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  191. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
  192. Assert.IsTrue (reader.Read (), "#1");
  193. try {
  194. reader.GetBytes (0, 0, null, -1, 0);
  195. Assert.Fail ("#2");
  196. #if NET_2_0
  197. } catch (ArgumentOutOfRangeException ex) {
  198. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
  199. Assert.IsNull (ex.InnerException, "#4");
  200. Assert.IsNotNull (ex.Message, "#5");
  201. Assert.AreEqual ("bufferIndex", ex.ParamName, "#6");
  202. }
  203. #else
  204. } catch (ArgumentException ex) {
  205. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#3");
  206. Assert.IsNull (ex.InnerException, "#4");
  207. Assert.AreEqual ("bufferIndex", ex.Message, "#5");
  208. Assert.IsNull (ex.ParamName, "#6");
  209. }
  210. #endif
  211. }
  212. }
  213. [Test]
  214. #if ONLY_1_1
  215. [Ignore ("dataIndex is ignored")]
  216. #endif
  217. public void GetBytes_DataIndex_Negative ()
  218. {
  219. IDbCommand cmd = conn.CreateCommand ();
  220. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  221. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
  222. Assert.IsTrue (reader.Read (), "#A1");
  223. #if NET_2_0
  224. try {
  225. reader.GetBytes (0, -1L, null, 0, 0);
  226. Assert.Fail ("#A2");
  227. } catch (ArgumentOutOfRangeException ex) {
  228. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A3");
  229. Assert.IsNull (ex.InnerException, "#A4");
  230. Assert.IsNotNull (ex.Message, "#A5");
  231. Assert.AreEqual ("dataIndex", ex.ParamName, "#A6");
  232. }
  233. #else
  234. long totalsize = reader.GetBytes (0, -1L, null, 0, 0);
  235. Assert.AreEqual (5, totalsize, "#A2");
  236. byte [] val = new byte [totalsize];
  237. try {
  238. reader.GetBytes (0, -1L, val, 0, 3);
  239. Assert.Fail ("#A3");
  240. } catch (InvalidOperationException ex) {
  241. // Invalid GetBytes attempt at dataIndex '-1'.
  242. // With CommandBehavior.SequentialAccess, you
  243. // may only read from dataIndex '0' or greater
  244. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A4");
  245. Assert.IsNull (ex.InnerException, "#A5");
  246. Assert.IsNotNull (ex.Message, "#A6");
  247. Assert.IsTrue (ex.Message.IndexOf ("CommandBehavior.SequentialAccess") != -1, "#A7:" + ex.Message);
  248. Assert.IsTrue (ex.Message.IndexOf ("'" + (-1L).ToString (CultureInfo.InvariantCulture) + "'") != -1, "#A8:" + ex.Message);
  249. Assert.IsTrue (ex.Message.IndexOf ("'" + 0L.ToString (CultureInfo.InvariantCulture) + "'") != -1, "#A9:" + ex.Message);
  250. }
  251. #endif
  252. }
  253. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
  254. Assert.IsTrue (reader.Read (), "#B1");
  255. #if NET_2_0
  256. try {
  257. reader.GetBytes (0, -1L, null, 0, 0);
  258. Assert.Fail ("#B2");
  259. } catch (ArgumentOutOfRangeException ex) {
  260. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B3");
  261. Assert.IsNull (ex.InnerException, "#B4");
  262. Assert.IsNotNull (ex.Message, "#B5");
  263. Assert.AreEqual ("dataIndex", ex.ParamName, "#B6");
  264. }
  265. #else
  266. long totalsize = reader.GetBytes (0, -1L, null, 0, 0);
  267. Assert.AreEqual (5, totalsize, "#B2");
  268. byte [] val = new byte [totalsize];
  269. try {
  270. reader.GetBytes (0, -1L, val, 0, 3);
  271. Assert.Fail ("#B3");
  272. } catch (ArgumentOutOfRangeException) {
  273. }
  274. #endif
  275. }
  276. }
  277. [Test]
  278. public void GetBytes_Length_Negative ()
  279. {
  280. cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  281. using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
  282. Assert.IsTrue (reader.Read (), "#1");
  283. try {
  284. reader.GetBytes (0, 0, null, 0, -1);
  285. Assert.Fail ("#2");
  286. #if NET_2_0
  287. } catch (ArgumentOutOfRangeException ex) {
  288. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
  289. Assert.IsNull (ex.InnerException, "#4");
  290. Assert.IsNotNull (ex.Message, "#5");
  291. Assert.AreEqual ("length", ex.ParamName, "#6");
  292. }
  293. #else
  294. } catch (ArgumentException ex) {
  295. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#3");
  296. Assert.IsNull (ex.InnerException, "#4");
  297. Assert.AreEqual ("length", ex.Message, "#5");
  298. Assert.IsNull (ex.ParamName, "#6");
  299. }
  300. #endif
  301. }
  302. }
  303. [Test]
  304. public void GetSchemaTable ()
  305. {
  306. IDataReader reader = null;
  307. DataTable schema;
  308. DataRow pkRow;
  309. try {
  310. cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
  311. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
  312. schema = reader.GetSchemaTable ();
  313. reader.Close ();
  314. AssertSchemaTableStructure (schema, "#A:");
  315. Assert.AreEqual (3, schema.Rows.Count, "#A:RowCount");
  316. pkRow = schema.Select ("ColumnName = 'id'") [0];
  317. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#A:ColumnName_IsNull");
  318. Assert.AreEqual ("id", pkRow ["ColumnName"], "#A:ColumnName_Value");
  319. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#A:ColumnOrdinal_IsNull");
  320. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#A:ColumnOrdinal_Value");
  321. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#A:ColumnSize_IsNull");
  322. Assert.AreEqual (4, pkRow ["ColumnSize"], "#A:ColumnSize_Value");
  323. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#A:NumericPrecision_IsNull");
  324. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#A:NumericPrecision_Value");
  325. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#A:NumericScale_IsNull");
  326. Assert.AreEqual (0, pkRow ["NumericScale"], "#A:NumericScale_Value");
  327. Assert.IsFalse (pkRow.IsNull ("DataType"), "#A:DataType_IsNull");
  328. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#A:DataType_Value");
  329. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#A:ProviderType_IsNull");
  330. Assert.AreEqual (10, pkRow ["ProviderType"], "#A:ProviderType_Value");
  331. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#A:IsLong_IsNull");
  332. Assert.AreEqual (false, pkRow ["IsLong"], "#A:IsLong_Value");
  333. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#A:AllowDBNull_IsNull");
  334. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#A:AllowDBNull_Value");
  335. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#A:IsReadOnly_IsNull");
  336. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#A:IsReadOnly_Value");
  337. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#A:IsRowVersion_IsNull");
  338. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#A:IsRowVersion_Value");
  339. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#A:IsUnique_IsNull");
  340. Assert.AreEqual (true, pkRow ["IsUnique"], "#A:IsUnique_Value");
  341. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#A:IsKey_IsNull");
  342. Assert.AreEqual (true, pkRow ["IsKey"], "#A:IsKey_Value");
  343. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#A:IsAutoIncrement_IsNull");
  344. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#A:IsAutoIncrement_Value");
  345. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#A:BaseSchemaName_IsNull");
  346. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#A:BaseSchemaName_Value");
  347. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#A:BaseCatalogName_IsNull");
  348. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#A:BaseCatalogName_Value");
  349. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#A:BaseTableName_IsNull");
  350. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#A:BaseTableName_Value");
  351. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#A:BaseColumnName_IsNull");
  352. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#A:BaseColumnName_Value");
  353. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
  354. schema = reader.GetSchemaTable ();
  355. reader.Close ();
  356. AssertSchemaTableStructure (schema, "#B:");
  357. Assert.AreEqual (3, schema.Rows.Count, "#B:RowCount");
  358. pkRow = schema.Select ("ColumnName = 'id'") [0];
  359. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#B:ColumnName_IsNull");
  360. Assert.AreEqual ("id", pkRow ["ColumnName"], "#B:ColumnName_Value");
  361. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#B:ColumnOrdinal_IsNull");
  362. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#B:ColumnOrdinal_Value");
  363. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#B:ColumnSize_IsNull");
  364. Assert.AreEqual (4, pkRow ["ColumnSize"], "#B:ColumnSize_Value");
  365. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#B:NumericPrecision_IsNull");
  366. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#B:NumericPrecision_Value");
  367. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#B:NumericScale_IsNull");
  368. Assert.AreEqual (0, pkRow ["NumericScale"], "#B:NumericScale_Value");
  369. Assert.IsFalse (pkRow.IsNull ("DataType"), "#B:DataType_IsNull");
  370. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#B:DataType_Value");
  371. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#B:ProviderType_IsNull");
  372. Assert.AreEqual (10, pkRow ["ProviderType"], "#B:ProviderType_Value");
  373. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#B:IsLong_IsNull");
  374. Assert.AreEqual (false, pkRow ["IsLong"], "#B:IsLong_Value");
  375. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#B:AllowDBNull_IsNull");
  376. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#B:AllowDBNull_Value");
  377. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#B:IsReadOnly_IsNull");
  378. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#B:IsReadOnly_Value");
  379. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#B:IsRowVersion_IsNull");
  380. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#B:IsRowVersion_Value");
  381. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#B:IsUnique_IsNull");
  382. Assert.AreEqual (false, pkRow ["IsUnique"], "#B:IsUnique_Value");
  383. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#B:IsKey_IsNull");
  384. Assert.AreEqual (false, pkRow ["IsKey"], "#B:IsKey_Value");
  385. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#B:IsAutoIncrement_IsNull");
  386. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#B:IsAutoIncrement_Value");
  387. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#B:BaseSchemaName_IsNull");
  388. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#B:BaseSchemaName_Value");
  389. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#B:BaseCatalogName_IsNull");
  390. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#B:BaseCatalogName_Value");
  391. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#B:BaseTableName_IsNull");
  392. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#B:BaseTableName_Value");
  393. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#B:BaseColumnName_IsNull");
  394. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#B:BaseColumnName_Value");
  395. reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
  396. schema = reader.GetSchemaTable ();
  397. reader.Close ();
  398. AssertSchemaTableStructure (schema, "#C:");
  399. Assert.AreEqual (3, schema.Rows.Count, "#C:RowCount");
  400. pkRow = schema.Select ("ColumnName = 'id'") [0];
  401. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#C:ColumnName_IsNull");
  402. Assert.AreEqual ("id", pkRow ["ColumnName"], "#C:ColumnName_Value");
  403. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#C:ColumnOrdinal_IsNull");
  404. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#C:ColumnOrdinal_Value");
  405. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#C:ColumnSize_IsNull");
  406. Assert.AreEqual (4, pkRow ["ColumnSize"], "#C:ColumnSize_Value");
  407. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#C:NumericPrecision_IsNull");
  408. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#C:NumericPrecision_Value");
  409. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#C:NumericScale_IsNull");
  410. Assert.AreEqual (0, pkRow ["NumericScale"], "#C:NumericScale_Value");
  411. Assert.IsFalse (pkRow.IsNull ("DataType"), "#C:DataType_IsNull");
  412. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#C:DataType_Value");
  413. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#C:ProviderType_IsNull");
  414. Assert.AreEqual (10, pkRow ["ProviderType"], "#C:ProviderType_Value");
  415. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#C:IsLong_IsNull");
  416. Assert.AreEqual (false, pkRow ["IsLong"], "#C:IsLong_Value");
  417. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#C:AllowDBNull_IsNull");
  418. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#C:AllowDBNull_Value");
  419. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#C:IsReadOnly_IsNull");
  420. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#C:IsReadOnly_Value");
  421. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#C:IsRowVersion_IsNull");
  422. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#C:IsRowVersion_Value");
  423. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#C:IsUnique_IsNull");
  424. Assert.AreEqual (true, pkRow ["IsUnique"], "#C:IsUnique_Value");
  425. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#C:IsKey_IsNull");
  426. Assert.AreEqual (true, pkRow ["IsKey"], "#C:IsKey_Value");
  427. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#C:IsAutoIncrement_IsNull");
  428. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#C:IsAutoIncrement_Value");
  429. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#C:BaseSchemaName_IsNull");
  430. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#C:BaseSchemaName_Value");
  431. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#C:BaseCatalogName_IsNull");
  432. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#C:BaseCatalogName_Value");
  433. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#C:BaseTableName_IsNull");
  434. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#C:BaseTableName_Value");
  435. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#C:BaseColumnName_IsNull");
  436. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#C:BaseColumnName_Value");
  437. reader = cmd.ExecuteReader ();
  438. schema = reader.GetSchemaTable ();
  439. reader.Close ();
  440. AssertSchemaTableStructure (schema, "#D:");
  441. Assert.AreEqual (3, schema.Rows.Count, "#D:RowCount");
  442. pkRow = schema.Select ("ColumnName = 'id'") [0];
  443. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#D:ColumnName_IsNull");
  444. Assert.AreEqual ("id", pkRow ["ColumnName"], "#D:ColumnName_Value");
  445. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#D:ColumnOrdinal_IsNull");
  446. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#D:ColumnOrdinal_Value");
  447. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#D:ColumnSize_IsNull");
  448. Assert.AreEqual (4, pkRow ["ColumnSize"], "#D:ColumnSize_Value");
  449. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#D:NumericPrecision_IsNull");
  450. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#D:NumericPrecision_Value");
  451. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#D:NumericScale_IsNull");
  452. Assert.AreEqual (0, pkRow ["NumericScale"], "#D:NumericScale_Value");
  453. Assert.IsFalse (pkRow.IsNull ("DataType"), "#D:DataType_IsNull");
  454. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#D:DataType_Value");
  455. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#D:ProviderType_IsNull");
  456. Assert.AreEqual (10, pkRow ["ProviderType"], "#D:ProviderType_Value");
  457. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#D:IsLong_IsNull");
  458. Assert.AreEqual (false, pkRow ["IsLong"], "#D:IsLong_Value");
  459. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#D:AllowDBNull_IsNull");
  460. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#D:AllowDBNull_Value");
  461. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#D:IsReadOnly_IsNull");
  462. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#D:IsReadOnly_Value");
  463. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#D:IsRowVersion_IsNull");
  464. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#D:IsRowVersion_Value");
  465. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#D:IsUnique_IsNull");
  466. Assert.AreEqual (false, pkRow ["IsUnique"], "#D:IsUnique_Value");
  467. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#D:IsKey_IsNull");
  468. Assert.AreEqual (false, pkRow ["IsKey"], "#D:IsKey_Value");
  469. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#D:IsAutoIncrement_IsNull");
  470. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#D:IsAutoIncrement_Value");
  471. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#D:BaseSchemaName_IsNull");
  472. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#D:BaseSchemaName_Value");
  473. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#D:BaseCatalogName_IsNull");
  474. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#D:BaseCatalogName_Value");
  475. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#D:BaseTableName_IsNull");
  476. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#D:BaseTableName_Value");
  477. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#D:BaseColumnName_IsNull");
  478. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#D:BaseColumnName_Value");
  479. cmd = conn.CreateCommand ();
  480. cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
  481. cmd.Prepare ();
  482. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
  483. schema = reader.GetSchemaTable ();
  484. reader.Close ();
  485. AssertSchemaTableStructure (schema, "#E:");
  486. Assert.AreEqual (3, schema.Rows.Count, "#E:RowCount");
  487. pkRow = schema.Select ("ColumnName = 'id'") [0];
  488. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#E:ColumnName_IsNull");
  489. Assert.AreEqual ("id", pkRow ["ColumnName"], "#E:ColumnName_Value");
  490. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#E:ColumnOrdinal_IsNull");
  491. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#E:ColumnOrdinal_Value");
  492. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#E:ColumnSize_IsNull");
  493. Assert.AreEqual (4, pkRow ["ColumnSize"], "#E:ColumnSize_Value");
  494. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#E:NumericPrecision_IsNull");
  495. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#E:NumericPrecision_Value");
  496. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#E:NumericScale_IsNull");
  497. Assert.AreEqual (0, pkRow ["NumericScale"], "#E:NumericScale_Value");
  498. Assert.IsFalse (pkRow.IsNull ("DataType"), "#E:DataType_IsNull");
  499. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#E:DataType_Value");
  500. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#E:ProviderType_IsNull");
  501. Assert.AreEqual (10, pkRow ["ProviderType"], "#E:ProviderType_Value");
  502. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#E:IsLong_IsNull");
  503. Assert.AreEqual (false, pkRow ["IsLong"], "#E:IsLong_Value");
  504. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#E:AllowDBNull_IsNull");
  505. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#E:AllowDBNull_Value");
  506. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#E:IsReadOnly_IsNull");
  507. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#E:IsReadOnly_Value");
  508. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#E:IsRowVersion_IsNull");
  509. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#E:IsRowVersion_Value");
  510. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#E:IsUnique_IsNull");
  511. Assert.AreEqual (true, pkRow ["IsUnique"], "#E:IsUnique_Value");
  512. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#E:IsKey_IsNull");
  513. Assert.AreEqual (true, pkRow ["IsKey"], "#E:IsKey_Value");
  514. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#E:IsAutoIncrement_IsNull");
  515. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#E:IsAutoIncrement_Value");
  516. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#E:BaseSchemaName_IsNull");
  517. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#E:BaseSchemaName_Value");
  518. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#E:BaseCatalogName_IsNull");
  519. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#E:BaseCatalogName_Value");
  520. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#E:BaseTableName_IsNull");
  521. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#E:BaseTableName_Value");
  522. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#E:BaseColumnName_IsNull");
  523. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#E:BaseColumnName_Value");
  524. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
  525. schema = reader.GetSchemaTable ();
  526. reader.Close ();
  527. AssertSchemaTableStructure (schema, "#F:");
  528. Assert.AreEqual (3, schema.Rows.Count, "#F:RowCount");
  529. pkRow = schema.Select ("ColumnName = 'id'") [0];
  530. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#F:ColumnName_IsNull");
  531. Assert.AreEqual ("id", pkRow ["ColumnName"], "#F:ColumnName_Value");
  532. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#F:ColumnOrdinal_IsNull");
  533. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#F:ColumnOrdinal_Value");
  534. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#F:ColumnSize_IsNull");
  535. Assert.AreEqual (4, pkRow ["ColumnSize"], "#F:ColumnSize_Value");
  536. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#F:NumericPrecision_IsNull");
  537. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#F:NumericPrecision_Value");
  538. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#F:NumericScale_IsNull");
  539. Assert.AreEqual (0, pkRow ["NumericScale"], "#F:NumericScale_Value");
  540. Assert.IsFalse (pkRow.IsNull ("DataType"), "#F:DataType_IsNull");
  541. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#F:DataType_Value");
  542. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#F:ProviderType_IsNull");
  543. Assert.AreEqual (10, pkRow ["ProviderType"], "#F:ProviderType_Value");
  544. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#F:IsLong_IsNull");
  545. Assert.AreEqual (false, pkRow ["IsLong"], "#F:IsLong_Value");
  546. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#F:AllowDBNull_IsNull");
  547. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#F:AllowDBNull_Value");
  548. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#F:IsReadOnly_IsNull");
  549. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#F:IsReadOnly_Value");
  550. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#F:IsRowVersion_IsNull");
  551. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#F:IsRowVersion_Value");
  552. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#F:IsUnique_IsNull");
  553. Assert.AreEqual (false, pkRow ["IsUnique"], "#F:IsUnique_Value");
  554. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#F:IsKey_IsNull");
  555. Assert.AreEqual (false, pkRow ["IsKey"], "#F:IsKey_Value");
  556. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#F:IsAutoIncrement_IsNull");
  557. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#F:IsAutoIncrement_Value");
  558. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#F:BaseSchemaName_IsNull");
  559. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#F:BaseSchemaName_Value");
  560. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#F:BaseCatalogName_IsNull");
  561. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#F:BaseCatalogName_Value");
  562. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#F:BaseTableName_IsNull");
  563. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#F:BaseTableName_Value");
  564. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#F:BaseColumnName_IsNull");
  565. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#F:BaseColumnName_Value");
  566. reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
  567. schema = reader.GetSchemaTable ();
  568. reader.Close ();
  569. AssertSchemaTableStructure (schema, "#G:");
  570. Assert.AreEqual (3, schema.Rows.Count, "#G:RowCount");
  571. pkRow = schema.Select ("ColumnName = 'id'") [0];
  572. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#G:ColumnName_IsNull");
  573. Assert.AreEqual ("id", pkRow ["ColumnName"], "#G:ColumnName_Value");
  574. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#G:ColumnOrdinal_IsNull");
  575. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#G:ColumnOrdinal_Value");
  576. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#G:ColumnSize_IsNull");
  577. Assert.AreEqual (4, pkRow ["ColumnSize"], "#G:ColumnSize_Value");
  578. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#G:NumericPrecision_IsNull");
  579. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#G:NumericPrecision_Value");
  580. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#G:NumericScale_IsNull");
  581. Assert.AreEqual (0, pkRow ["NumericScale"], "#G:NumericScale_Value");
  582. Assert.IsFalse (pkRow.IsNull ("DataType"), "#G:DataType_IsNull");
  583. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#G:DataType_Value");
  584. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#G:ProviderType_IsNull");
  585. Assert.AreEqual (10, pkRow ["ProviderType"], "#G:ProviderType_Value");
  586. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#G:IsLong_IsNull");
  587. Assert.AreEqual (false, pkRow ["IsLong"], "#G:IsLong_Value");
  588. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#G:AllowDBNull_IsNull");
  589. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#G:AllowDBNull_Value");
  590. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#G:IsReadOnly_IsNull");
  591. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#G:IsReadOnly_Value");
  592. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#G:IsRowVersion_IsNull");
  593. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#G:IsRowVersion_Value");
  594. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#G:IsUnique_IsNull");
  595. Assert.AreEqual (true, pkRow ["IsUnique"], "#G:IsUnique_Value");
  596. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#G:IsKey_IsNull");
  597. Assert.AreEqual (true, pkRow ["IsKey"], "#G:IsKey_Value");
  598. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#G:IsAutoIncrement_IsNull");
  599. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#G:IsAutoIncrement_Value");
  600. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#G:BaseSchemaName_IsNull");
  601. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#G:BaseSchemaName_Value");
  602. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#G:BaseCatalogName_IsNull");
  603. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#G:BaseCatalogName_Value");
  604. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#G:BaseTableName_IsNull");
  605. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#G:BaseTableName_Value");
  606. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#G:BaseColumnName_IsNull");
  607. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#G:BaseColumnName_Value");
  608. reader = cmd.ExecuteReader ();
  609. schema = reader.GetSchemaTable ();
  610. reader.Close ();
  611. AssertSchemaTableStructure (schema, "#H:");
  612. Assert.AreEqual (3, schema.Rows.Count, "#H:RowCount");
  613. pkRow = schema.Select ("ColumnName = 'id'") [0];
  614. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#H:ColumnName_IsNull");
  615. Assert.AreEqual ("id", pkRow ["ColumnName"], "#H:ColumnName_Value");
  616. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#H:ColumnOrdinal_IsNull");
  617. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#H:ColumnOrdinal_Value");
  618. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#H:ColumnSize_IsNull");
  619. Assert.AreEqual (4, pkRow ["ColumnSize"], "#H:ColumnSize_Value");
  620. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#H:NumericPrecision_IsNull");
  621. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#H:NumericPrecision_Value");
  622. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#H:NumericScale_IsNull");
  623. Assert.AreEqual (0, pkRow ["NumericScale"], "#H:NumericScale_Value");
  624. Assert.IsFalse (pkRow.IsNull ("DataType"), "#H:DataType_IsNull");
  625. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#H:DataType_Value");
  626. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#H:ProviderType_IsNull");
  627. Assert.AreEqual (10, pkRow ["ProviderType"], "#H:ProviderType_Value");
  628. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#H:IsLong_IsNull");
  629. Assert.AreEqual (false, pkRow ["IsLong"], "#H:IsLong_Value");
  630. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#H:AllowDBNull_IsNull");
  631. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#H:AllowDBNull_Value");
  632. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#H:IsReadOnly_IsNull");
  633. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#H:IsReadOnly_Value");
  634. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#H:IsRowVersion_IsNull");
  635. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#H:IsRowVersion_Value");
  636. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#H:IsUnique_IsNull");
  637. Assert.AreEqual (false, pkRow ["IsUnique"], "#H:IsUnique_Value");
  638. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#H:IsKey_IsNull");
  639. Assert.AreEqual (false, pkRow ["IsKey"], "#H:IsKey_Value");
  640. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#H:IsAutoIncrement_IsNull");
  641. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#H:IsAutoIncrement_Value");
  642. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#H:BaseSchemaName_IsNull");
  643. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#H:BaseSchemaName_Value");
  644. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#H:BaseCatalogName_IsNull");
  645. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#H:BaseCatalogName_Value");
  646. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#H:BaseTableName_IsNull");
  647. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#H:BaseTableName_Value");
  648. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#H:BaseColumnName_IsNull");
  649. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#H:BaseColumnName_Value");
  650. cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee where id = ?";
  651. IDbDataParameter param = cmd.CreateParameter ();
  652. cmd.Parameters.Add (param);
  653. param.DbType = DbType.Int32;
  654. param.Value = 2;
  655. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
  656. schema = reader.GetSchemaTable ();
  657. reader.Close ();
  658. AssertSchemaTableStructure (schema, "#I:");
  659. Assert.AreEqual (3, schema.Rows.Count, "#I:RowCount");
  660. pkRow = schema.Select ("ColumnName = 'id'") [0];
  661. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#I:ColumnName_IsNull");
  662. Assert.AreEqual ("id", pkRow ["ColumnName"], "#I:ColumnName_Value");
  663. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#I:ColumnOrdinal_IsNull");
  664. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#I:ColumnOrdinal_Value");
  665. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#I:ColumnSize_IsNull");
  666. Assert.AreEqual (4, pkRow ["ColumnSize"], "#I:ColumnSize_Value");
  667. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#I:NumericPrecision_IsNull");
  668. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#I:NumericPrecision_Value");
  669. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#I:NumericScale_IsNull");
  670. Assert.AreEqual (0, pkRow ["NumericScale"], "#I:NumericScale_Value");
  671. Assert.IsFalse (pkRow.IsNull ("DataType"), "#I:DataType_IsNull");
  672. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#I:DataType_Value");
  673. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#I:ProviderType_IsNull");
  674. Assert.AreEqual (10, pkRow ["ProviderType"], "#I:ProviderType_Value");
  675. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#I:IsLong_IsNull");
  676. Assert.AreEqual (false, pkRow ["IsLong"], "#I:IsLong_Value");
  677. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#I:AllowDBNull_IsNull");
  678. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#I:AllowDBNull_Value");
  679. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#I:IsReadOnly_IsNull");
  680. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#I:IsReadOnly_Value");
  681. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#I:IsRowVersion_IsNull");
  682. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#I:IsRowVersion_Value");
  683. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#I:IsUnique_IsNull");
  684. Assert.AreEqual (true, pkRow ["IsUnique"], "#I:IsUnique_Value");
  685. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#I:IsKey_IsNull");
  686. Assert.AreEqual (true, pkRow ["IsKey"], "#I:IsKey_Value");
  687. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#I:IsAutoIncrement_IsNull");
  688. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#I:IsAutoIncrement_Value");
  689. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#I:BaseSchemaName_IsNull");
  690. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#I:BaseSchemaName_Value");
  691. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#I:BaseCatalogName_IsNull");
  692. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#I:BaseCatalogName_Value");
  693. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#I:BaseTableName_IsNull");
  694. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#I:BaseTableName_Value");
  695. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#I:BaseColumnName_IsNull");
  696. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#I:BaseColumnName_Value");
  697. reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
  698. schema = reader.GetSchemaTable ();
  699. reader.Close ();
  700. AssertSchemaTableStructure (schema, "#J:");
  701. Assert.AreEqual (3, schema.Rows.Count, "#J:RowCount");
  702. pkRow = schema.Select ("ColumnName = 'id'") [0];
  703. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#J:ColumnName_IsNull");
  704. Assert.AreEqual ("id", pkRow ["ColumnName"], "#J:ColumnName_Value");
  705. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#J:ColumnOrdinal_IsNull");
  706. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#J:ColumnOrdinal_Value");
  707. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#J:ColumnSize_IsNull");
  708. Assert.AreEqual (4, pkRow ["ColumnSize"], "#J:ColumnSize_Value");
  709. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#J:NumericPrecision_IsNull");
  710. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#J:NumericPrecision_Value");
  711. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#J:NumericScale_IsNull");
  712. Assert.AreEqual (0, pkRow ["NumericScale"], "#J:NumericScale_Value");
  713. Assert.IsFalse (pkRow.IsNull ("DataType"), "#J:DataType_IsNull");
  714. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#J:DataType_Value");
  715. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#J:ProviderType_IsNull");
  716. Assert.AreEqual (10, pkRow ["ProviderType"], "#J:ProviderType_Value");
  717. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#J:IsLong_IsNull");
  718. Assert.AreEqual (false, pkRow ["IsLong"], "#J:IsLong_Value");
  719. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#J:AllowDBNull_IsNull");
  720. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#J:AllowDBNull_Value");
  721. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#J:IsReadOnly_IsNull");
  722. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#J:IsReadOnly_Value");
  723. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#J:IsRowVersion_IsNull");
  724. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#J:IsRowVersion_Value");
  725. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#J:IsUnique_IsNull");
  726. Assert.AreEqual (false, pkRow ["IsUnique"], "#J:IsUnique_Value");
  727. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#J:IsKey_IsNull");
  728. Assert.AreEqual (false, pkRow ["IsKey"], "#J:IsKey_Value");
  729. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#J:IsAutoIncrement_IsNull");
  730. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#J:IsAutoIncrement_Value");
  731. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#J:BaseSchemaName_IsNull");
  732. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#J:BaseSchemaName_Value");
  733. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#J:BaseCatalogName_IsNull");
  734. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#J:BaseCatalogName_Value");
  735. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#J:BaseTableName_IsNull");
  736. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#J:BaseTableName_Value");
  737. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#J:BaseColumnName_IsNull");
  738. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#J:BaseColumnName_Value");
  739. reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
  740. schema = reader.GetSchemaTable ();
  741. reader.Close ();
  742. AssertSchemaTableStructure (schema, "#K:");
  743. Assert.AreEqual (3, schema.Rows.Count, "#K:RowCount");
  744. pkRow = schema.Select ("ColumnName = 'id'") [0];
  745. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#K:ColumnName_IsNull");
  746. Assert.AreEqual ("id", pkRow ["ColumnName"], "#K:ColumnName_Value");
  747. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#K:ColumnOrdinal_IsNull");
  748. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#K:ColumnOrdinal_Value");
  749. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#K:ColumnSize_IsNull");
  750. Assert.AreEqual (4, pkRow ["ColumnSize"], "#K:ColumnSize_Value");
  751. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#K:NumericPrecision_IsNull");
  752. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#K:NumericPrecision_Value");
  753. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#K:NumericScale_IsNull");
  754. Assert.AreEqual (0, pkRow ["NumericScale"], "#K:NumericScale_Value");
  755. Assert.IsFalse (pkRow.IsNull ("DataType"), "#K:DataType_IsNull");
  756. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#K:DataType_Value");
  757. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#K:ProviderType_IsNull");
  758. Assert.AreEqual (10, pkRow ["ProviderType"], "#K:ProviderType_Value");
  759. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#K:IsLong_IsNull");
  760. Assert.AreEqual (false, pkRow ["IsLong"], "#K:IsLong_Value");
  761. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#K:AllowDBNull_IsNull");
  762. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#K:AllowDBNull_Value");
  763. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#K:IsReadOnly_IsNull");
  764. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#K:IsReadOnly_Value");
  765. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#K:IsRowVersion_IsNull");
  766. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#K:IsRowVersion_Value");
  767. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#K:IsUnique_IsNull");
  768. Assert.AreEqual (true, pkRow ["IsUnique"], "#K:IsUnique_Value");
  769. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#K:IsKey_IsNull");
  770. Assert.AreEqual (true, pkRow ["IsKey"], "#K:IsKey_Value");
  771. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#K:IsAutoIncrement_IsNull");
  772. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#K:IsAutoIncrement_Value");
  773. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#K:BaseSchemaName_IsNull");
  774. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#K:BaseSchemaName_Value");
  775. Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#K:BaseCatalogName_IsNull");
  776. Assert.AreEqual ("monotest", pkRow ["BaseCatalogName"], "#K:BaseCatalogName_Value");
  777. Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#K:BaseTableName_IsNull");
  778. Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#K:BaseTableName_Value");
  779. Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#K:BaseColumnName_IsNull");
  780. Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#K:BaseColumnName_Value");
  781. reader = cmd.ExecuteReader ();
  782. schema = reader.GetSchemaTable ();
  783. reader.Close ();
  784. AssertSchemaTableStructure (schema, "#L:");
  785. Assert.AreEqual (3, schema.Rows.Count, "#L:RowCount");
  786. pkRow = schema.Select ("ColumnName = 'id'") [0];
  787. Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#L:ColumnName_IsNull");
  788. Assert.AreEqual ("id", pkRow ["ColumnName"], "#L:ColumnName_Value");
  789. Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#L:ColumnOrdinal_IsNull");
  790. Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#L:ColumnOrdinal_Value");
  791. Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#L:ColumnSize_IsNull");
  792. Assert.AreEqual (4, pkRow ["ColumnSize"], "#L:ColumnSize_Value");
  793. Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#L:NumericPrecision_IsNull");
  794. Assert.AreEqual (10, pkRow ["NumericPrecision"], "#L:NumericPrecision_Value");
  795. Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#L:NumericScale_IsNull");
  796. Assert.AreEqual (0, pkRow ["NumericScale"], "#L:NumericScale_Value");
  797. Assert.IsFalse (pkRow.IsNull ("DataType"), "#L:DataType_IsNull");
  798. Assert.AreEqual (typeof (int), pkRow ["DataType"], "#L:DataType_Value");
  799. Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#L:ProviderType_IsNull");
  800. Assert.AreEqual (10, pkRow ["ProviderType"], "#L:ProviderType_Value");
  801. Assert.IsFalse (pkRow.IsNull ("IsLong"), "#L:IsLong_IsNull");
  802. Assert.AreEqual (false, pkRow ["IsLong"], "#L:IsLong_Value");
  803. Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#L:AllowDBNull_IsNull");
  804. Assert.AreEqual (false, pkRow ["AllowDBNull"], "#L:AllowDBNull_Value");
  805. Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#L:IsReadOnly_IsNull");
  806. Assert.AreEqual (false, pkRow ["IsReadOnly"], "#L:IsReadOnly_Value");
  807. Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#L:IsRowVersion_IsNull");
  808. Assert.AreEqual (false, pkRow ["IsRowVersion"], "#L:IsRowVersion_Value");
  809. Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#L:IsUnique_IsNull");
  810. Assert.AreEqual (false, pkRow ["IsUnique"], "#L:IsUnique_Value");
  811. Assert.IsFalse (pkRow.IsNull ("IsKey"), "#L:IsKey_IsNull");
  812. Assert.AreEqual (false, pkRow ["IsKey"], "#L:IsKey_Value");
  813. Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#L:IsAutoIncrement_IsNull");
  814. Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#L:IsAutoIncrement_Value");
  815. Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#L:BaseSchemaName_IsNull");
  816. Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#L:BaseSchemaName_Value");
  817. Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#L:BaseCatalogName_IsNull");
  818. Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#L:BaseCatalogName_Value");
  819. Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#L:BaseTableName_IsNull");
  820. Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#L:BaseTableName_Value");
  821. Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#L:BaseColumnName_IsNull");
  822. Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#L:BaseColumnName_Value");
  823. } finally {
  824. if (reader != null)
  825. reader.Close ();
  826. }
  827. }
  828. [Test]
  829. public void OutputParametersTest ()
  830. {
  831. // MySQL currently does not support output parameters
  832. // in its ODBC connector:
  833. // http://www.paragon-cs.com/mag/issue3.pdf
  834. if (ConnectionManager.Singleton.Engine.Type != EngineType.SQLServer)
  835. Assert.Ignore ("MySQL does not (yet) support output parameters using ODBC.");
  836. IDataReader reader = null;
  837. try {
  838. cmd.CommandText = "{? = CALL sp_get_age (?, ?)}";
  839. OdbcParameter ret = new OdbcParameter ("ret", OdbcType.Int);
  840. cmd.Parameters.Add (ret);
  841. ret.Direction = ParameterDirection.ReturnValue;
  842. OdbcParameter name = new OdbcParameter ("fname", OdbcType.VarChar);
  843. cmd.Parameters.Add (name);
  844. name.Direction = ParameterDirection.Input;
  845. name.Value = "suresh";
  846. OdbcParameter age = new OdbcParameter ("age", OdbcType.Int);
  847. cmd.Parameters.Add (age);
  848. age.Direction = ParameterDirection.Output;
  849. reader = cmd.ExecuteReader ();
  850. reader.Close ();
  851. /* FIXME: we don't support output/return parameters */
  852. if (!RunningOnMono) {
  853. Assert.IsTrue (((int) (age.Value)) > 0, "#1");
  854. Assert.IsTrue (((int) ret.Value) > 0, "#2");
  855. }
  856. } finally {
  857. if (reader != null)
  858. reader.Close ();
  859. }
  860. }
  861. [Test]
  862. public void LongTextTest ()
  863. {
  864. IDataReader reader = null;
  865. try {
  866. cmd.CommandText = "Select type_text from string_family where id=2";
  867. reader = cmd.ExecuteReader ();
  868. reader.Read ();
  869. reader.GetValue (0);
  870. }finally {
  871. if (reader != null)
  872. reader.Close ();
  873. }
  874. }
  875. [Test]
  876. public void Bug82135Test ()
  877. {
  878. const string drop_table = "drop table odbcnodatatest";
  879. // cleanup in case of previously failed test
  880. DBHelper.ExecuteNonQuery (conn, drop_table);
  881. cmd = new OdbcCommand ("create table odbcnodatatest (ID int not null, Val1 text)",
  882. conn);
  883. cmd.ExecuteNonQuery ();
  884. cmd = new OdbcCommand ("delete from odbcnodatatest", conn);
  885. Assert.AreEqual (0, cmd.ExecuteNonQuery ());
  886. // cleanup
  887. cmd = new OdbcCommand (drop_table, conn);
  888. cmd.ExecuteNonQuery ();
  889. }
  890. [Test]
  891. public void Bug82560Test ()
  892. {
  893. string drop_table = "DROP TABLE odbc_alias_test";
  894. // cleanup in case of previously failed test
  895. DBHelper.ExecuteNonQuery (conn, drop_table);
  896. DoExecuteNonQuery (conn, "CREATE TABLE odbc_alias_test" +
  897. "(ifld INT NOT NULL PRIMARY KEY, sfld VARCHAR(20))");
  898. DoExecuteNonQuery (conn, "INSERT INTO odbc_alias_test" +
  899. "(ifld, sfld) VALUES (1, '1111')");
  900. DoExecuteScalar (conn, "SELECT A.ifld FROM odbc_alias_test " +
  901. "A WHERE A.ifld = 1");
  902. DoExecuteNonQuery (conn, drop_table);
  903. }
  904. [Test]
  905. public void FindZeroInToStringTest ()
  906. {
  907. if (ConnectionManager.Singleton.Engine.Type != EngineType.MySQL)
  908. Assert.Ignore ("Only applies to MySQL.");
  909. IDataReader reader = null;
  910. try {
  911. // Create table
  912. cmd.CommandText = "Create table foo ( bar long varchar )";
  913. cmd.ExecuteNonQuery();
  914. cmd.Dispose ();
  915. // Insert a record into foo
  916. cmd = conn.CreateCommand ();
  917. cmd.CommandText = "Insert into foo (bar) values ( '"
  918. + "This string has more than 255 characters"
  919. + "This string has more than 255 characters"
  920. + "This string has more than 255 characters"
  921. + "This string has more than 255 characters"
  922. + "This string has more than 255 characters"
  923. + "This string has more than 255 characters"
  924. + "This string has more than 255 characters"
  925. + "This string has more than 255 characters"
  926. + "This string has more than 255 characters"
  927. + "This string has more than 255 characters"
  928. + "This string has more than 255 characters"
  929. + "This string has more than 255 characters"
  930. + "This string has more than 255 characters"
  931. + "This string has more than 255 characters"
  932. + "This string has more than 255 characters"
  933. + "This string has more than 255 characters"
  934. + "This string has more than 255 characters"
  935. + "This string has more than 255 characters"
  936. + "This string has more than 255 characters"
  937. + "This string has more than 255 characters"
  938. + "This string has more than 255 characters"
  939. + "This string has more than 255 characters"
  940. + "This string has more than 255 characters"
  941. + "This string has more than 255 characters"
  942. + "' )";
  943. cmd.ExecuteNonQuery();
  944. cmd.Dispose ();
  945. // Now, get the record back - try and read it two different ways.
  946. cmd = conn.CreateCommand ();
  947. cmd.CommandText = "SELECT bar FROM foo" ;
  948. reader = cmd.ExecuteReader ();
  949. string readAsString = "";
  950. while (reader.Read ()) {
  951. readAsString = reader[0].ToString();
  952. }
  953. reader.Close();
  954. cmd.Dispose ();
  955. // Now, read it using GetBytes
  956. cmd = conn.CreateCommand ();
  957. cmd.CommandText = "SELECT bar FROM foo";
  958. reader = cmd.ExecuteReader ();
  959. byte[] buffer = new byte [2048];
  960. long total = 0;
  961. while (reader.Read ()) {
  962. total = reader.GetBytes (0, 0, buffer, 0, 2048);
  963. }
  964. reader.Close();
  965. // Convert bytes read to string - look for binary zero - there is none (OK)
  966. string readAsBytes = Encoding.Default.GetString (buffer, 0, (int) total);
  967. Assert.AreEqual (readAsBytes, readAsString, "#1 ReadAsString is not same as ReadAsBytes");
  968. } finally {
  969. if (reader != null)
  970. reader.Close ();
  971. DBHelper.ExecuteNonQuery (conn, "Drop table foo");
  972. }
  973. }
  974. [Test]
  975. public void Bug332404Test ()
  976. {
  977. if (ConnectionManager.Singleton.Engine.Type != EngineType.MySQL)
  978. Assert.Ignore ("Only applies to MySQL.");
  979. cmd = new OdbcCommand ("DROP TABLE IF EXISTS odbc_test");
  980. cmd.Connection = conn;
  981. cmd.ExecuteNonQuery ();
  982. cmd = new OdbcCommand ("CREATE TABLE odbc_test (id_test INTEGER NOT NULL, payload DECIMAL (14,4) NOT NULL)");
  983. cmd.Connection = conn;
  984. cmd.ExecuteNonQuery ();
  985. cmd = new OdbcCommand ("INSERT INTO odbc_test (id_test, payload) VALUES (1, 1.23456789)");
  986. cmd.Connection = conn;
  987. cmd.ExecuteNonQuery ();
  988. OdbcDataAdapter Adaptador = new OdbcDataAdapter ();
  989. DataSet Lector = new DataSet ();
  990. Adaptador.SelectCommand = new OdbcCommand ("SELECT * FROM odbc_test WHERE id_test=1", (OdbcConnection) conn);
  991. Adaptador.Fill (Lector);
  992. Assert.AreEqual (Lector.Tables[0].Rows[0]["payload"], 1.2346);
  993. }
  994. [Test]
  995. public void Bug332400Test ()
  996. {
  997. if (ConnectionManager.Singleton.Engine.Type != EngineType.MySQL)
  998. Assert.Ignore ("Only applies to MySQL.");
  999. cmd = new OdbcCommand ("DROP TABLE IF EXISTS blob_test");
  1000. cmd.Connection = conn;
  1001. cmd.ExecuteNonQuery ();
  1002. cmd = new OdbcCommand ("CREATE TABLE blob_test (id_test INTEGER NOT NULL, payload LONGBLOB NOT NULL)");
  1003. cmd.Connection = conn;
  1004. cmd.ExecuteNonQuery ();
  1005. cmd = new OdbcCommand ("INSERT INTO blob_test (id_test, payload) VALUES (1, 'test')");
  1006. cmd.Connection = conn;
  1007. cmd.ExecuteNonQuery ();
  1008. OdbcDataAdapter Adaptador = new OdbcDataAdapter();
  1009. DataSet Lector = new DataSet();
  1010. Adaptador.SelectCommand = new OdbcCommand("SELECT * FROM blob_test WHERE id_test=1", (OdbcConnection) conn);
  1011. Adaptador.Fill(Lector);
  1012. }
  1013. static void DoExecuteNonQuery (OdbcConnection conn, string sql)
  1014. {
  1015. IDbCommand cmd = new OdbcCommand (sql, conn);
  1016. cmd.ExecuteNonQuery ();
  1017. }
  1018. static void DoExecuteScalar (OdbcConnection conn, string sql)
  1019. {
  1020. IDbCommand cmd = new OdbcCommand (sql, conn);
  1021. cmd.ExecuteScalar ();
  1022. }
  1023. static void AssertSchemaTableStructure (DataTable schemaTable, string prefix)
  1024. {
  1025. object [] [] columns = {
  1026. new object [] { "ColumnName", typeof (string) },
  1027. new object [] { "ColumnOrdinal", typeof (int) },
  1028. new object [] { "ColumnSize", typeof (int) },
  1029. new object [] { "NumericPrecision", typeof (short) },
  1030. new object [] { "NumericScale", typeof (short) },
  1031. new object [] { "DataType", typeof (object) },
  1032. new object [] { "ProviderType", typeof (int) },
  1033. new object [] { "IsLong", typeof (bool) },
  1034. new object [] { "AllowDBNull", typeof (bool) },
  1035. new object [] { "IsReadOnly", typeof (bool) },
  1036. new object [] { "IsRowVersion", typeof (bool) },
  1037. new object [] { "IsUnique", typeof (bool) },
  1038. new object [] { "IsKey", typeof (bool) },
  1039. new object [] { "IsAutoIncrement", typeof (bool) },
  1040. new object [] { "BaseSchemaName", typeof (string) },
  1041. new object [] { "BaseCatalogName", typeof (string) },
  1042. new object [] { "BaseTableName", typeof (string) },
  1043. new object [] { "BaseColumnName", typeof (string) }
  1044. };
  1045. Assert.AreEqual (columns.Length, schemaTable.Columns.Count, prefix);
  1046. for (int i = 0; i < columns.Length; i++) {
  1047. DataColumn col = schemaTable.Columns [i];
  1048. Assert.IsTrue (col.AllowDBNull, prefix + "AllowDBNull (" + i + ")");
  1049. Assert.AreEqual (columns [i] [0], col.ColumnName, prefix + "ColumnName (" + i + ")");
  1050. Assert.AreEqual (columns [i] [1], col.DataType, prefix + "DataType (" + i + ")");
  1051. }
  1052. }
  1053. static bool RunningOnMono {
  1054. get {
  1055. return (Type.GetType ("System.MonoType", false) != null);
  1056. }
  1057. }
  1058. }
  1059. }