DbCommandBuilder.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. //
  2. // System.Data.Common.DbCommandBuilder
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2003
  8. //
  9. //
  10. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0 || TARGET_JVM
  32. using System.ComponentModel;
  33. using System.Data;
  34. using System.Text;
  35. namespace System.Data.Common {
  36. public abstract class DbCommandBuilder : Component
  37. {
  38. bool _setAllValues = false;
  39. bool _disposed = false;
  40. DataTable _dbSchemaTable;
  41. DbDataAdapter _dbDataAdapter = null;
  42. private CatalogLocation _catalogLocation = CatalogLocation.Start;
  43. private ConflictOption _conflictOption = ConflictOption.CompareAllSearchableValues;
  44. private string _tableName;
  45. private string _catalogSeperator = ".";
  46. private string _quotePrefix;
  47. private string _quoteSuffix;
  48. private string _schemaSeperator = ".";
  49. private DbCommand _dbCommand = null;
  50. // Used to construct WHERE clauses
  51. static readonly string clause1 = "({0} = 1 AND {1} IS NULL)";
  52. static readonly string clause2 = "({0} = {1})";
  53. DbCommand _deleteCommand;
  54. DbCommand _insertCommand;
  55. DbCommand _updateCommand;
  56. #region Constructors
  57. protected DbCommandBuilder ()
  58. {
  59. }
  60. #endregion // Constructors
  61. #region Properties
  62. private void BuildCache (bool closeConnection)
  63. {
  64. DbCommand sourceCommand = SourceCommand;
  65. if (sourceCommand == null)
  66. throw new InvalidOperationException ("The DataAdapter.SelectCommand property needs to be initialized.");
  67. DbConnection connection = sourceCommand.Connection;
  68. if (connection == null)
  69. throw new InvalidOperationException ("The DataAdapter.SelectCommand.Connection property needs to be initialized.");
  70. if (_dbSchemaTable == null) {
  71. if (connection.State == ConnectionState.Open)
  72. closeConnection = false;
  73. else
  74. connection.Open ();
  75. DbDataReader reader = sourceCommand.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
  76. _dbSchemaTable = reader.GetSchemaTable ();
  77. reader.Close ();
  78. if (closeConnection)
  79. connection.Close ();
  80. BuildInformation (_dbSchemaTable);
  81. }
  82. }
  83. private string QuotedTableName {
  84. get { return GetQuotedString (_tableName); }
  85. }
  86. bool IsCommandGenerated {
  87. get {
  88. return (_insertCommand != null || _updateCommand != null || _deleteCommand != null);
  89. }
  90. }
  91. private string GetQuotedString (string value)
  92. {
  93. if (value == String.Empty || value == null)
  94. return value;
  95. string prefix = QuotePrefix;
  96. string suffix = QuoteSuffix;
  97. if (prefix.Length == 0 && suffix.Length == 0)
  98. return value;
  99. return String.Format ("{0}{1}{2}", prefix, value, suffix);
  100. }
  101. private void BuildInformation (DataTable schemaTable)
  102. {
  103. _tableName = String.Empty;
  104. foreach (DataRow schemaRow in schemaTable.Rows) {
  105. if (schemaRow.IsNull ("BaseTableName") || (string) schemaRow ["BaseTableName"] == String.Empty)
  106. continue;
  107. if (_tableName == String.Empty)
  108. _tableName = (string) schemaRow ["BaseTableName"];
  109. else if (_tableName != (string) schemaRow["BaseTableName"])
  110. throw new InvalidOperationException ("Dynamic SQL generation is not supported against multiple base tables.");
  111. }
  112. if (_tableName == String.Empty)
  113. throw new InvalidOperationException ("Dynamic SQL generation is not supported with no base table.");
  114. _dbSchemaTable = schemaTable;
  115. }
  116. private bool IncludedInInsert (DataRow schemaRow)
  117. {
  118. // If the parameter has one of these properties, then we don't include it in the insert:
  119. // AutoIncrement, Hidden, Expression, RowVersion, ReadOnly
  120. if (!schemaRow.IsNull ("IsAutoIncrement") && (bool) schemaRow ["IsAutoIncrement"])
  121. return false;
  122. // if (!schemaRow.IsNull ("IsHidden") && (bool) schemaRow ["IsHidden"])
  123. // return false;
  124. if (!schemaRow.IsNull ("IsExpression") && (bool) schemaRow ["IsExpression"])
  125. return false;
  126. if (!schemaRow.IsNull ("IsRowVersion") && (bool) schemaRow ["IsRowVersion"])
  127. return false;
  128. if (!schemaRow.IsNull ("IsReadOnly") && (bool) schemaRow ["IsReadOnly"])
  129. return false;
  130. return true;
  131. }
  132. private bool IncludedInUpdate (DataRow schemaRow)
  133. {
  134. // If the parameter has one of these properties, then we don't include it in the insert:
  135. // AutoIncrement, Hidden, RowVersion
  136. if (!schemaRow.IsNull ("IsAutoIncrement") && (bool) schemaRow ["IsAutoIncrement"])
  137. return false;
  138. // if (!schemaRow.IsNull ("IsHidden") && (bool) schemaRow ["IsHidden"])
  139. // return false;
  140. if (!schemaRow.IsNull ("IsRowVersion") && (bool) schemaRow ["IsRowVersion"])
  141. return false;
  142. if (!schemaRow.IsNull ("IsExpression") && (bool) schemaRow ["IsExpression"])
  143. return false;
  144. if (!schemaRow.IsNull ("IsReadOnly") && (bool) schemaRow ["IsReadOnly"])
  145. return false;
  146. return true;
  147. }
  148. private bool IncludedInWhereClause (DataRow schemaRow)
  149. {
  150. if ((bool) schemaRow ["IsLong"])
  151. return false;
  152. return true;
  153. }
  154. private DbCommand CreateDeleteCommand (bool option)
  155. {
  156. // If no table was found, then we can't do an delete
  157. if (QuotedTableName == String.Empty)
  158. return null;
  159. CreateNewCommand (ref _deleteCommand);
  160. string command = String.Format ("DELETE FROM {0}", QuotedTableName);
  161. StringBuilder whereClause = new StringBuilder ();
  162. bool keyFound = false;
  163. int parmIndex = 1;
  164. foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
  165. if (!schemaRow.IsNull ("IsExpression") && (bool)schemaRow["IsExpression"] == true)
  166. continue;
  167. if (!IncludedInWhereClause (schemaRow))
  168. continue;
  169. if (whereClause.Length > 0)
  170. whereClause.Append (" AND ");
  171. bool isKey = (bool) schemaRow ["IsKey"];
  172. DbParameter parameter = null;
  173. if (isKey)
  174. keyFound = true;
  175. //ms.net 1.1 generates the null check for columns even if AllowDBNull is false
  176. //while ms.net 2.0 does not. Anyways, since both forms are logically equivalent
  177. //following the 2.0 approach
  178. bool allowNull = (bool) schemaRow ["AllowDBNull"];
  179. if (!isKey && allowNull) {
  180. parameter = _deleteCommand.CreateParameter ();
  181. if (option) {
  182. parameter.ParameterName = String.Format ("@{0}",
  183. schemaRow ["BaseColumnName"]);
  184. } else {
  185. parameter.ParameterName = String.Format ("@p{0}", parmIndex++);
  186. }
  187. String sourceColumnName = (string) schemaRow ["BaseColumnName"];
  188. parameter.Value = 1;
  189. whereClause.Append ("(");
  190. whereClause.Append (String.Format (clause1, parameter.ParameterName,
  191. GetQuotedString (sourceColumnName)));
  192. whereClause.Append (" OR ");
  193. }
  194. parameter = CreateParameter (_deleteCommand, String.Format ("@{0}", option ? schemaRow ["BaseColumnName"] : "p" + parmIndex++), schemaRow);
  195. parameter.SourceVersion = DataRowVersion.Original;
  196. whereClause.Append (String.Format (clause2, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
  197. if (!isKey && allowNull)
  198. whereClause.Append (")");
  199. }
  200. if (!keyFound)
  201. throw new InvalidOperationException ("Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.");
  202. // We're all done, so bring it on home
  203. string sql = String.Format ("{0} WHERE ({1})", command, whereClause.ToString ());
  204. _deleteCommand.CommandText = sql;
  205. _dbCommand = _deleteCommand;
  206. return _deleteCommand;
  207. }
  208. private DbCommand CreateInsertCommand (bool option)
  209. {
  210. if (QuotedTableName == String.Empty)
  211. return null;
  212. CreateNewCommand (ref _insertCommand);
  213. string command = String.Format ("INSERT INTO {0}", QuotedTableName);
  214. string sql;
  215. StringBuilder columns = new StringBuilder ();
  216. StringBuilder values = new StringBuilder ();
  217. int parmIndex = 1;
  218. foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
  219. if (!IncludedInInsert (schemaRow))
  220. continue;
  221. if (columns.Length > 0) {
  222. columns.Append (", ");
  223. values.Append (", ");
  224. }
  225. DbParameter parameter = CreateParameter (_insertCommand, String.Format ("@{0}", option ? schemaRow ["BaseColumnName"] : "p" + parmIndex++), schemaRow);
  226. parameter.SourceVersion = DataRowVersion.Current;
  227. columns.Append (GetQuotedString (parameter.SourceColumn));
  228. values.Append (parameter.ParameterName);
  229. }
  230. sql = String.Format ("{0} ({1}) VALUES ({2})", command, columns.ToString (), values.ToString ());
  231. _insertCommand.CommandText = sql;
  232. _dbCommand = _insertCommand;
  233. return _insertCommand;
  234. }
  235. private void CreateNewCommand (ref DbCommand command)
  236. {
  237. DbCommand sourceCommand = SourceCommand;
  238. if (command == null) {
  239. command = sourceCommand.Connection.CreateCommand ();
  240. command.CommandTimeout = sourceCommand.CommandTimeout;
  241. command.Transaction = sourceCommand.Transaction;
  242. }
  243. command.CommandType = CommandType.Text;
  244. command.UpdatedRowSource = UpdateRowSource.None;
  245. command.Parameters.Clear ();
  246. }
  247. private DbCommand CreateUpdateCommand (bool option)
  248. {
  249. // If no table was found, then we can't do an update
  250. if (QuotedTableName == String.Empty)
  251. return null;
  252. CreateNewCommand (ref _updateCommand);
  253. string command = String.Format ("UPDATE {0} SET ", QuotedTableName);
  254. StringBuilder columns = new StringBuilder ();
  255. StringBuilder whereClause = new StringBuilder ();
  256. int parmIndex = 1;
  257. bool keyFound = false;
  258. // First, create the X=Y list for UPDATE
  259. foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
  260. if (!IncludedInUpdate (schemaRow))
  261. continue;
  262. if (columns.Length > 0)
  263. columns.Append (", ");
  264. DbParameter parameter = CreateParameter (_updateCommand, String.Format ("@{0}", option ? schemaRow ["BaseColumnName"] : "p" + parmIndex++), schemaRow);
  265. parameter.SourceVersion = DataRowVersion.Current;
  266. columns.Append (String.Format ("{0} = {1}", GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
  267. }
  268. // Now, create the WHERE clause. This may be optimizable, but it would be ugly to incorporate
  269. // into the loop above. "Premature optimization is the root of all evil." -- Knuth
  270. foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
  271. if (!schemaRow.IsNull ("IsExpression") && (bool) schemaRow ["IsExpression"] == true)
  272. continue;
  273. if (!IncludedInWhereClause (schemaRow))
  274. continue;
  275. if (whereClause.Length > 0)
  276. whereClause.Append (" AND ");
  277. bool isKey = (bool) schemaRow ["IsKey"];
  278. DbParameter parameter = null;
  279. if (isKey)
  280. keyFound = true;
  281. //ms.net 1.1 generates the null check for columns even if AllowDBNull is false
  282. //while ms.net 2.0 does not. Anyways, since both forms are logically equivalent
  283. //following the 2.0 approach
  284. bool allowNull = (bool) schemaRow ["AllowDBNull"];
  285. if (!isKey && allowNull) {
  286. parameter = _updateCommand.CreateParameter ();
  287. if (option) {
  288. parameter.ParameterName = String.Format ("@{0} IS NULL",
  289. schemaRow ["BaseColumnName"]);
  290. } else {
  291. parameter.ParameterName = String.Format ("@p{0}", parmIndex++);
  292. }
  293. parameter.Value = 1;
  294. whereClause.Append ("(");
  295. whereClause.Append (String.Format (clause1, parameter.ParameterName,
  296. GetQuotedString ((string) schemaRow ["BaseColumnName"])));
  297. whereClause.Append (" OR ");
  298. }
  299. if (option)
  300. parameter = CreateParameter (_updateCommand, String.Format ("@Original_{0}", schemaRow ["BaseColumnName"]), schemaRow);
  301. else
  302. parameter = CreateParameter (_updateCommand, String.Format ("@p{0}", parmIndex++), schemaRow);
  303. parameter.SourceVersion = DataRowVersion.Original;
  304. whereClause.Append (String.Format (clause2, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
  305. if (!isKey && allowNull)
  306. whereClause.Append (")");
  307. }
  308. if (!keyFound)
  309. throw new InvalidOperationException ("Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.");
  310. // We're all done, so bring it on home
  311. string sql = String.Format ("{0}{1} WHERE ({2})", command, columns.ToString (), whereClause.ToString ());
  312. _updateCommand.CommandText = sql;
  313. _dbCommand = _updateCommand;
  314. return _updateCommand;
  315. }
  316. private DbParameter CreateParameter (DbCommand _dbCommand, string parameterName, DataRow schemaRow)
  317. {
  318. DbParameter parameter = _dbCommand.CreateParameter ();
  319. parameter.ParameterName = parameterName;
  320. parameter.SourceColumn = (string) schemaRow ["BaseColumnName"];
  321. parameter.Size = (int) schemaRow ["ColumnSize"];
  322. _dbCommand.Parameters.Add (parameter);
  323. return parameter;
  324. }
  325. [DefaultValue (CatalogLocation.Start)]
  326. public virtual CatalogLocation CatalogLocation {
  327. get { return _catalogLocation; }
  328. set { _catalogLocation = value; }
  329. }
  330. [DefaultValue (".")]
  331. public virtual string CatalogSeparator {
  332. get { return _catalogSeperator; }
  333. set { if (value != null) _catalogSeperator = value; }
  334. }
  335. [DefaultValue (ConflictOption.CompareAllSearchableValues)]
  336. public virtual ConflictOption ConflictOption {
  337. get { return _conflictOption; }
  338. set { _conflictOption = value; }
  339. }
  340. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  341. [Browsable (false)]
  342. public DbDataAdapter DataAdapter {
  343. get { return _dbDataAdapter; }
  344. set { if (value != null) _dbDataAdapter = value; }
  345. }
  346. [DefaultValue ("")]
  347. public virtual string QuotePrefix {
  348. get {
  349. if (_quotePrefix == null)
  350. return string.Empty;
  351. return _quotePrefix;
  352. }
  353. set {
  354. if (IsCommandGenerated)
  355. throw new InvalidOperationException (
  356. "QuotePrefix cannot be set after " +
  357. "an Insert, Update or Delete command " +
  358. "has been generated.");
  359. _quotePrefix = value;
  360. }
  361. }
  362. [DefaultValue ("")]
  363. public virtual string QuoteSuffix {
  364. get {
  365. if (_quoteSuffix == null)
  366. return string.Empty;
  367. return _quoteSuffix;
  368. }
  369. set {
  370. if (IsCommandGenerated)
  371. throw new InvalidOperationException (
  372. "QuoteSuffix cannot be set after " +
  373. "an Insert, Update or Delete command " +
  374. "has been generated.");
  375. _quoteSuffix = value;
  376. }
  377. }
  378. [DefaultValue (".")]
  379. public virtual string SchemaSeparator {
  380. get { return _schemaSeperator; }
  381. set { if (value != null) _schemaSeperator = value; }
  382. }
  383. [DefaultValue (false)]
  384. public bool SetAllValues {
  385. get { return _setAllValues; }
  386. set { _setAllValues = value; }
  387. }
  388. private DbCommand SourceCommand {
  389. get {
  390. if (_dbDataAdapter != null)
  391. return _dbDataAdapter.SelectCommand;
  392. return null;
  393. }
  394. }
  395. #endregion // Properties
  396. #region Methods
  397. protected abstract void ApplyParameterInfo (DbParameter parameter,
  398. DataRow row,
  399. StatementType statementType,
  400. bool whereClause);
  401. protected override void Dispose (bool disposing)
  402. {
  403. if (!_disposed) {
  404. if (disposing) {
  405. if (_insertCommand != null)
  406. _insertCommand.Dispose ();
  407. if (_deleteCommand != null)
  408. _deleteCommand.Dispose ();
  409. if (_updateCommand != null)
  410. _updateCommand.Dispose ();
  411. if (_dbSchemaTable != null)
  412. _dbSchemaTable.Dispose ();
  413. }
  414. _disposed = true;
  415. }
  416. }
  417. public DbCommand GetDeleteCommand ()
  418. {
  419. BuildCache (true);
  420. if (_deleteCommand == null)
  421. return CreateDeleteCommand (false);
  422. return _deleteCommand;
  423. }
  424. public DbCommand GetDeleteCommand (bool option)
  425. {
  426. BuildCache (true);
  427. if (_deleteCommand == null)
  428. return CreateDeleteCommand (option);
  429. return _deleteCommand;
  430. }
  431. public DbCommand GetInsertCommand ()
  432. {
  433. BuildCache (true);
  434. if (_insertCommand == null)
  435. return CreateInsertCommand (false);
  436. return _insertCommand;
  437. }
  438. public DbCommand GetInsertCommand (bool option)
  439. {
  440. BuildCache (true);
  441. if (_insertCommand == null)
  442. return CreateInsertCommand (option);
  443. return _insertCommand;
  444. }
  445. public DbCommand GetUpdateCommand ()
  446. {
  447. BuildCache (true);
  448. if (_updateCommand == null)
  449. return CreateUpdateCommand (false);
  450. return _updateCommand;
  451. }
  452. public DbCommand GetUpdateCommand (bool option)
  453. {
  454. BuildCache (true);
  455. if (_updateCommand == null)
  456. return CreateUpdateCommand (option);
  457. return _updateCommand;
  458. }
  459. protected virtual DbCommand InitializeCommand (DbCommand command)
  460. {
  461. if (_dbCommand == null) {
  462. _dbCommand = SourceCommand;
  463. } else {
  464. _dbCommand.CommandTimeout = 30;
  465. _dbCommand.Transaction = null;
  466. _dbCommand.CommandType = CommandType.Text;
  467. _dbCommand.UpdatedRowSource = UpdateRowSource.None;
  468. }
  469. return _dbCommand;
  470. }
  471. public virtual string QuoteIdentifier (string unquotedIdentifier)
  472. {
  473. if (unquotedIdentifier == null) {
  474. throw new ArgumentNullException("Unquoted identifier parameter cannot be null");
  475. }
  476. return String.Format ("{0}{1}{2}", this.QuotePrefix, unquotedIdentifier, this.QuoteSuffix);
  477. }
  478. public virtual string UnquoteIdentifier (string quotedIdentifier)
  479. {
  480. if (quotedIdentifier == null) {
  481. throw new ArgumentNullException ("Quoted identifier parameter cannot be null");
  482. }
  483. string unquotedIdentifier = quotedIdentifier.Trim ();
  484. if (unquotedIdentifier.StartsWith (this.QuotePrefix)) {
  485. unquotedIdentifier = unquotedIdentifier.Remove (0, 1);
  486. }
  487. if (unquotedIdentifier.EndsWith (this.QuoteSuffix)) {
  488. unquotedIdentifier = unquotedIdentifier.Remove (unquotedIdentifier.Length - 1, 1);
  489. }
  490. return unquotedIdentifier;
  491. }
  492. public virtual void RefreshSchema ()
  493. {
  494. _tableName = String.Empty;
  495. _dbSchemaTable = null;
  496. _deleteCommand = null;
  497. _updateCommand = null;
  498. _insertCommand = null;
  499. }
  500. protected void RowUpdatingHandler (RowUpdatingEventArgs args)
  501. {
  502. if (args.Command != null)
  503. return;
  504. try {
  505. switch (args.StatementType) {
  506. case StatementType.Insert:
  507. args.Command = GetInsertCommand ();
  508. break;
  509. case StatementType.Update:
  510. args.Command = GetUpdateCommand ();
  511. break;
  512. case StatementType.Delete:
  513. args.Command = GetDeleteCommand ();
  514. break;
  515. }
  516. } catch (Exception e) {
  517. args.Errors = e;
  518. args.Status = UpdateStatus.ErrorsOccurred;
  519. }
  520. }
  521. protected abstract string GetParameterName (int parameterOrdinal);
  522. protected abstract string GetParameterName (String parameterName);
  523. protected abstract string GetParameterPlaceholder (int parameterOrdinal);
  524. protected abstract void SetRowUpdatingHandler (DbDataAdapter adapter);
  525. protected virtual DataTable GetSchemaTable (DbCommand cmd)
  526. {
  527. using (DbDataReader rdr = cmd.ExecuteReader ())
  528. return rdr.GetSchemaTable ();
  529. }
  530. #endregion // Methods
  531. }
  532. }
  533. #endif