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