OdbcDataReaderTest.cs 56 KB

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