OdbcDataReaderTest.cs 56 KB

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