OdbcDataReaderTest.cs 58 KB

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