SqlParameter.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. //
  2. // System.Data.SqlClient.SqlParameter.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. // Diego Caravana ([email protected])
  9. // Umadevi S ([email protected])
  10. //
  11. // (C) Ximian, Inc. 2002
  12. // Copyright (C) Tim Coleman, 2002
  13. //
  14. //
  15. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  16. //
  17. // Permission is hereby granted, free of charge, to any person obtaining
  18. // a copy of this software and associated documentation files (the
  19. // "Software"), to deal in the Software without restriction, including
  20. // without limitation the rights to use, copy, modify, merge, publish,
  21. // distribute, sublicense, and/or sell copies of the Software, and to
  22. // permit persons to whom the Software is furnished to do so, subject to
  23. // the following conditions:
  24. //
  25. // The above copyright notice and this permission notice shall be
  26. // included in all copies or substantial portions of the Software.
  27. //
  28. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. //
  36. using Mono.Data.Tds;
  37. using Mono.Data.Tds.Protocol;
  38. using System;
  39. using System.ComponentModel;
  40. using System.Data;
  41. using System.Data.Common;
  42. #if NET_2_0
  43. using System.Data.ProviderBase;
  44. using System.Data.SqlTypes;
  45. #endif // NET_2_0
  46. using System.Runtime.InteropServices;
  47. using System.Text;
  48. namespace System.Data.SqlClient {
  49. [TypeConverterAttribute (typeof (SqlParameterConverter))]
  50. #if NET_2_0
  51. public sealed class SqlParameter : DbParameterBase, IDbDataParameter, IDataParameter, ICloneable
  52. #else
  53. public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
  54. #endif // NET_2_0
  55. {
  56. #region Fields
  57. TdsMetaParameter metaParameter;
  58. SqlParameterCollection container = null;
  59. DbType dbType;
  60. ParameterDirection direction = ParameterDirection.Input;
  61. bool isNullable;
  62. bool isSizeSet = false;
  63. bool isTypeSet = false;
  64. int offset;
  65. SqlDbType sqlDbType;
  66. string sourceColumn;
  67. DataRowVersion sourceVersion;
  68. #endregion // Fields
  69. #region Constructors
  70. public SqlParameter ()
  71. : this (String.Empty, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
  72. {
  73. }
  74. public SqlParameter (string parameterName, object value)
  75. {
  76. metaParameter = new TdsMetaParameter (parameterName, value);
  77. this.sourceVersion = DataRowVersion.Current;
  78. InferSqlType (value);
  79. }
  80. public SqlParameter (string parameterName, SqlDbType dbType)
  81. : this (parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
  82. {
  83. }
  84. public SqlParameter (string parameterName, SqlDbType dbType, int size)
  85. : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
  86. {
  87. }
  88. public SqlParameter (string parameterName, SqlDbType dbType, int size, string sourceColumn)
  89. : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null)
  90. {
  91. }
  92. [EditorBrowsable (EditorBrowsableState.Advanced)]
  93. public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
  94. {
  95. metaParameter = new TdsMetaParameter (parameterName, size, isNullable, precision, scale, value);
  96. SqlDbType = dbType;
  97. Direction = direction;
  98. SourceColumn = sourceColumn;
  99. SourceVersion = sourceVersion;
  100. }
  101. // This constructor is used internally to construct a
  102. // SqlParameter. The value array comes from sp_procedure_params_rowset.
  103. // This is in SqlCommand.DeriveParameters.
  104. internal SqlParameter (object[] dbValues)
  105. : this (dbValues [3].ToString (), String.Empty)
  106. {
  107. Precision = 0;
  108. Scale = 0;
  109. Direction = ParameterDirection.Input;
  110. ParameterName = (string) dbValues[3];
  111. switch ((short) dbValues[5]) {
  112. case 1:
  113. Direction = ParameterDirection.Input;
  114. break;
  115. case 2:
  116. Direction = ParameterDirection.Output;
  117. break;
  118. case 3:
  119. Direction = ParameterDirection.InputOutput;
  120. break;
  121. case 4:
  122. Direction = ParameterDirection.ReturnValue;
  123. break;
  124. default:
  125. Direction = ParameterDirection.Input;
  126. break;
  127. }
  128. IsNullable = (dbValues [8] != null &&
  129. dbValues [8] != DBNull.Value) ? (bool) dbValues [8] : false;
  130. if (dbValues [12] != null && dbValues [12] != DBNull.Value)
  131. Precision = (byte) ((short) dbValues [12]);
  132. if (dbValues [13] != null && dbValues [13] != DBNull.Value)
  133. Scale = (byte) ( (short) dbValues [13]);
  134. SetDbTypeName ((string) dbValues [16]);
  135. }
  136. #endregion // Constructors
  137. #region Properties
  138. // Used to ensure that only one collection can contain this
  139. // parameter
  140. internal SqlParameterCollection Container {
  141. get { return container; }
  142. set { container = value; }
  143. }
  144. #if ONLY_1_0 || ONLY_1_1
  145. [Browsable (false)]
  146. [DataSysDescription ("The parameter generic type.")]
  147. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  148. [RefreshProperties (RefreshProperties.All)]
  149. #endif
  150. [DataCategory ("Data")]
  151. public
  152. #if NET_2_0
  153. override
  154. #endif // NET_2_0
  155. DbType DbType {
  156. get { return dbType; }
  157. set {
  158. SetDbType (value);
  159. isTypeSet = true;
  160. }
  161. }
  162. [DataCategory ("Data")]
  163. #if ONLY_1_0 || ONLY_1_1
  164. [DataSysDescription ("Input, output, or bidirectional parameter.")]
  165. [DefaultValue (ParameterDirection.Input)]
  166. #endif
  167. #if NET_2_0
  168. [RefreshProperties (RefreshProperties.All)]
  169. #endif
  170. public
  171. #if NET_2_0
  172. override
  173. #endif // NET_2_0
  174. ParameterDirection Direction {
  175. get { return direction; }
  176. set {
  177. direction = value;
  178. switch( direction ) {
  179. case ParameterDirection.Output:
  180. MetaParameter.Direction = TdsParameterDirection.Output;
  181. break;
  182. case ParameterDirection.InputOutput:
  183. MetaParameter.Direction = TdsParameterDirection.InputOutput;
  184. break;
  185. case ParameterDirection.ReturnValue:
  186. MetaParameter.Direction = TdsParameterDirection.ReturnValue;
  187. break;
  188. }
  189. }
  190. }
  191. internal TdsMetaParameter MetaParameter {
  192. get { return metaParameter; }
  193. }
  194. string IDataParameter.ParameterName {
  195. get { return metaParameter.ParameterName; }
  196. set { metaParameter.ParameterName = value; }
  197. }
  198. #if ONLY_1_0 || ONLY_1_1
  199. [Browsable (false)]
  200. [DataSysDescription ("a design-time property used for strongly typed code-generation.")]
  201. [DefaultValue (false)]
  202. [DesignOnly (true)]
  203. [EditorBrowsable (EditorBrowsableState.Advanced)]
  204. #endif
  205. public
  206. #if NET_2_0
  207. override
  208. #endif // NET_2_0
  209. bool IsNullable {
  210. get { return metaParameter.IsNullable; }
  211. set { metaParameter.IsNullable = value; }
  212. }
  213. [Browsable (false)]
  214. [DataCategory ("Data")]
  215. #if ONLY_1_0 || ONLY_1_1
  216. [DataSysDescription ("Offset in variable length data types.")]
  217. [DefaultValue (0)]
  218. #endif
  219. #if NET_2_0
  220. [EditorBrowsable (EditorBrowsableState.Advanced)]
  221. #endif
  222. public
  223. #if NET_2_0
  224. override
  225. #endif // NET_2_0
  226. int Offset {
  227. get { return offset; }
  228. set { offset = value; }
  229. }
  230. #if ONLY_1_0 || ONLY_1_1
  231. [DataSysDescription ("Name of the parameter, like '@p1'")]
  232. [DefaultValue ("")]
  233. #endif
  234. public
  235. #if NET_2_0
  236. override
  237. #endif // NET_2_0
  238. string ParameterName {
  239. get { return metaParameter.ParameterName; }
  240. set { metaParameter.ParameterName = value; }
  241. }
  242. [DataCategory ("Data")]
  243. #if ONLY_1_0 || ONLY_1_1
  244. [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
  245. [DefaultValue (0)]
  246. #endif
  247. #if NET_2_0
  248. [Browsable (false)]
  249. [EditorBrowsable (EditorBrowsableState.Never)]
  250. #endif
  251. public
  252. #if NET_2_0
  253. override
  254. #endif // NET_2_0
  255. byte Precision {
  256. get { return metaParameter.Precision; }
  257. set { metaParameter.Precision = value; }
  258. }
  259. [DataCategory ("Data")]
  260. #if ONLY_1_0 || ONLY_1_1
  261. [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
  262. [DefaultValue (0)]
  263. #endif
  264. #if NET_2_0
  265. [Browsable (false)]
  266. [EditorBrowsable (EditorBrowsableState.Never)]
  267. #endif
  268. public
  269. #if NET_2_0
  270. override
  271. #endif // NET_2_0
  272. byte Scale {
  273. get { return metaParameter.Scale; }
  274. set { metaParameter.Scale = value; }
  275. }
  276. [DataCategory ("Data")]
  277. #if ONLY_1_0 || ONLY_1_1
  278. [DataSysDescription ("Size of variable length data types (strings & arrays).")]
  279. [DefaultValue (0)]
  280. #endif
  281. public
  282. #if NET_2_0
  283. override
  284. #endif // NET_2_0
  285. int Size {
  286. get { return metaParameter.Size; }
  287. set { metaParameter.Size = value; }
  288. }
  289. [DataCategory ("Data")]
  290. #if ONLY_1_0 || ONLY_1_1
  291. [DataSysDescription ("When used by a DataAdapter.Update, the source column name that is used to find the DataSetColumn name in the ColumnMappings. This is to copy a value between the parameter and a datarow.")]
  292. [DefaultValue ("")]
  293. #endif
  294. public
  295. #if NET_2_0
  296. override
  297. #endif // NET_2_0
  298. string SourceColumn {
  299. get { return sourceColumn; }
  300. set { sourceColumn = value; }
  301. }
  302. [DataCategory ("Data")]
  303. #if ONLY_1_0 || ONLY_1_1
  304. [DataSysDescription ("When used by a DataAdapter.Update (UpdateCommand only), the version of the DataRow value that is used to update the data source.")]
  305. [DefaultValue (DataRowVersion.Current)]
  306. #endif
  307. public
  308. #if NET_2_0
  309. override
  310. #endif // NET_2_0
  311. DataRowVersion SourceVersion {
  312. get { return sourceVersion; }
  313. set { sourceVersion = value; }
  314. }
  315. [DataCategory ("Data")]
  316. #if ONLY_1_0 || ONLY_1_1
  317. [DataSysDescription ("The parameter native type.")]
  318. [DefaultValue (SqlDbType.NVarChar)]
  319. #endif
  320. [RefreshProperties (RefreshProperties.All)]
  321. #if NET_2_0
  322. [DbProviderSpecificTypeProperty(true)]
  323. #endif
  324. public SqlDbType SqlDbType {
  325. get { return sqlDbType; }
  326. set {
  327. SetSqlDbType (value);
  328. isTypeSet = true;
  329. }
  330. }
  331. [DataCategory ("Data")]
  332. #if ONLY_1_0 || ONLY_1_1
  333. [DataSysDescription ("Value of the parameter.")]
  334. [DefaultValue (null)]
  335. #endif
  336. [TypeConverterAttribute (typeof (StringConverter))]
  337. #if NET_2_0
  338. [RefreshProperties (RefreshProperties.All)]
  339. #endif
  340. public
  341. #if NET_2_0
  342. override
  343. #endif // NET_2_0
  344. object Value {
  345. get { return metaParameter.Value; }
  346. set {
  347. if (!isTypeSet)
  348. InferSqlType (value);
  349. metaParameter.Value = value;
  350. }
  351. }
  352. //#if NET_2_0
  353. // public SqlCompareOptions CompareInfo{
  354. //#endif
  355. #endregion // Properties
  356. #region Methods
  357. object ICloneable.Clone ()
  358. {
  359. return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value);
  360. }
  361. // If the value is set without the DbType/SqlDbType being set, then we
  362. // infer type information.
  363. private void InferSqlType (object value)
  364. {
  365. Type type = value.GetType ();
  366. string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
  367. switch (type.FullName) {
  368. case "System.Int64":
  369. SetSqlDbType (SqlDbType.BigInt);
  370. break;
  371. case "System.Boolean":
  372. SetSqlDbType (SqlDbType.Bit);
  373. break;
  374. case "System.String":
  375. SetSqlDbType (SqlDbType.NVarChar);
  376. break;
  377. case "System.DateTime":
  378. SetSqlDbType (SqlDbType.DateTime);
  379. break;
  380. case "System.Decimal":
  381. SetSqlDbType (SqlDbType.Decimal);
  382. break;
  383. case "System.Double":
  384. SetSqlDbType (SqlDbType.Float);
  385. break;
  386. case "System.Byte[]":
  387. SetSqlDbType (SqlDbType.VarBinary);
  388. break;
  389. case "System.Byte":
  390. SetSqlDbType (SqlDbType.TinyInt);
  391. break;
  392. case "System.Int32":
  393. SetSqlDbType (SqlDbType.Int);
  394. break;
  395. case "System.Single":
  396. SetSqlDbType (SqlDbType.Real);
  397. break;
  398. case "System.Int16":
  399. SetSqlDbType (SqlDbType.SmallInt);
  400. break;
  401. case "System.Guid":
  402. SetSqlDbType (SqlDbType.UniqueIdentifier);
  403. break;
  404. case "System.Object":
  405. SetSqlDbType (SqlDbType.Variant);
  406. break;
  407. case "System.DBNull":
  408. SetSqlDbType(SqlDbType.Variant); // variant can contain numeric,
  409. //string,binary or data and also nul //values, so we can later resolve // it to correct type.
  410. break;
  411. default:
  412. throw new ArgumentException (exception);
  413. }
  414. }
  415. // When the DbType is set, we also set the SqlDbType, as well as the SQL Server
  416. // string representation of the type name. If the DbType is not convertible
  417. // to an SqlDbType, throw an exception.
  418. private void SetDbType (DbType type)
  419. {
  420. string exception = String.Format ("No mapping exists from DbType {0} to a known SqlDbType.", type);
  421. switch (type) {
  422. case DbType.AnsiString:
  423. MetaParameter.TypeName = "varchar";
  424. sqlDbType = SqlDbType.VarChar;
  425. break;
  426. case DbType.AnsiStringFixedLength:
  427. MetaParameter.TypeName = "char";
  428. sqlDbType = SqlDbType.Char;
  429. break;
  430. case DbType.Binary:
  431. MetaParameter.TypeName = "varbinary";
  432. sqlDbType = SqlDbType.VarBinary;
  433. break;
  434. case DbType.Boolean:
  435. MetaParameter.TypeName = "bit";
  436. sqlDbType = SqlDbType.Bit;
  437. break;
  438. case DbType.Byte:
  439. MetaParameter.TypeName = "tinyint";
  440. sqlDbType = SqlDbType.TinyInt;
  441. break;
  442. case DbType.Currency:
  443. sqlDbType = SqlDbType.Money;
  444. MetaParameter.TypeName = "money";
  445. break;
  446. case DbType.Date:
  447. case DbType.DateTime:
  448. MetaParameter.TypeName = "datetime";
  449. sqlDbType = SqlDbType.DateTime;
  450. break;
  451. case DbType.Decimal:
  452. MetaParameter.TypeName = "decimal";
  453. sqlDbType = SqlDbType.Decimal;
  454. break;
  455. case DbType.Double:
  456. MetaParameter.TypeName = "float";
  457. sqlDbType = SqlDbType.Float;
  458. break;
  459. case DbType.Guid:
  460. MetaParameter.TypeName = "uniqueidentifier";
  461. sqlDbType = SqlDbType.UniqueIdentifier;
  462. break;
  463. case DbType.Int16:
  464. MetaParameter.TypeName = "smallint";
  465. sqlDbType = SqlDbType.SmallInt;
  466. break;
  467. case DbType.Int32:
  468. MetaParameter.TypeName = "int";
  469. sqlDbType = SqlDbType.Int;
  470. break;
  471. case DbType.Int64:
  472. MetaParameter.TypeName = "bigint";
  473. sqlDbType = SqlDbType.BigInt;
  474. break;
  475. case DbType.Object:
  476. MetaParameter.TypeName = "sql_variant";
  477. sqlDbType = SqlDbType.Variant;
  478. break;
  479. case DbType.Single:
  480. MetaParameter.TypeName = "real";
  481. sqlDbType = SqlDbType.Real;
  482. break;
  483. case DbType.String:
  484. MetaParameter.TypeName = "nvarchar";
  485. sqlDbType = SqlDbType.NVarChar;
  486. break;
  487. case DbType.StringFixedLength:
  488. MetaParameter.TypeName = "nchar";
  489. sqlDbType = SqlDbType.NChar;
  490. break;
  491. case DbType.Time:
  492. MetaParameter.TypeName = "datetime";
  493. sqlDbType = SqlDbType.DateTime;
  494. break;
  495. default:
  496. throw new ArgumentException (exception);
  497. }
  498. dbType = type;
  499. }
  500. // Used by internal constructor which has a SQL Server typename
  501. private void SetDbTypeName (string dbTypeName)
  502. {
  503. switch (dbTypeName.ToLower ()) {
  504. case "bigint":
  505. SqlDbType = SqlDbType.BigInt;
  506. break;
  507. case "binary":
  508. SqlDbType = SqlDbType.Binary;
  509. break;
  510. case "bit":
  511. SqlDbType = SqlDbType.Bit;
  512. break;
  513. case "char":
  514. SqlDbType = SqlDbType.Char;
  515. break;
  516. case "datetime":
  517. SqlDbType = SqlDbType.DateTime;
  518. break;
  519. case "decimal":
  520. SqlDbType = SqlDbType.Decimal;
  521. break;
  522. case "float":
  523. SqlDbType = SqlDbType.Float;
  524. break;
  525. case "image":
  526. SqlDbType = SqlDbType.Image;
  527. break;
  528. case "int":
  529. SqlDbType = SqlDbType.Int;
  530. break;
  531. case "money":
  532. SqlDbType = SqlDbType.Money;
  533. break;
  534. case "nchar":
  535. SqlDbType = SqlDbType.NChar;
  536. break;
  537. case "ntext":
  538. SqlDbType = SqlDbType.NText;
  539. break;
  540. case "nvarchar":
  541. SqlDbType = SqlDbType.NVarChar;
  542. break;
  543. case "real":
  544. SqlDbType = SqlDbType.Real;
  545. break;
  546. case "smalldatetime":
  547. SqlDbType = SqlDbType.SmallDateTime;
  548. break;
  549. case "smallint":
  550. SqlDbType = SqlDbType.SmallInt;
  551. break;
  552. case "smallmoney":
  553. SqlDbType = SqlDbType.SmallMoney;
  554. break;
  555. case "text":
  556. SqlDbType = SqlDbType.Text;
  557. break;
  558. case "timestamp":
  559. SqlDbType = SqlDbType.Timestamp;
  560. break;
  561. case "tinyint":
  562. SqlDbType = SqlDbType.TinyInt;
  563. break;
  564. case "uniqueidentifier":
  565. SqlDbType = SqlDbType.UniqueIdentifier;
  566. break;
  567. case "varbinary":
  568. SqlDbType = SqlDbType.VarBinary;
  569. break;
  570. case "varchar":
  571. SqlDbType = SqlDbType.VarChar;
  572. break;
  573. default:
  574. SqlDbType = SqlDbType.Variant;
  575. break;
  576. }
  577. }
  578. // When the SqlDbType is set, we also set the DbType, as well as the SQL Server
  579. // string representation of the type name. If the SqlDbType is not convertible
  580. // to a DbType, throw an exception.
  581. private void SetSqlDbType (SqlDbType type)
  582. {
  583. string exception = String.Format ("No mapping exists from SqlDbType {0} to a known DbType.", type);
  584. switch (type) {
  585. case SqlDbType.BigInt:
  586. MetaParameter.TypeName = "bigint";
  587. dbType = DbType.Int64;
  588. break;
  589. case SqlDbType.Binary:
  590. MetaParameter.TypeName = "binary";
  591. dbType = DbType.Binary;
  592. break;
  593. case SqlDbType.Timestamp:
  594. MetaParameter.TypeName = "timestamp";
  595. dbType = DbType.Binary;
  596. break;
  597. case SqlDbType.VarBinary:
  598. MetaParameter.TypeName = "varbinary";
  599. dbType = DbType.Binary;
  600. break;
  601. case SqlDbType.Bit:
  602. MetaParameter.TypeName = "bit";
  603. dbType = DbType.Boolean;
  604. break;
  605. case SqlDbType.Char:
  606. MetaParameter.TypeName = "char";
  607. dbType = DbType.AnsiStringFixedLength;
  608. break;
  609. case SqlDbType.DateTime:
  610. MetaParameter.TypeName = "datetime";
  611. dbType = DbType.DateTime;
  612. break;
  613. case SqlDbType.SmallDateTime:
  614. MetaParameter.TypeName = "smalldatetime";
  615. dbType = DbType.DateTime;
  616. break;
  617. case SqlDbType.Decimal:
  618. MetaParameter.TypeName = "decimal";
  619. dbType = DbType.Decimal;
  620. break;
  621. case SqlDbType.Float:
  622. MetaParameter.TypeName = "float";
  623. dbType = DbType.Double;
  624. break;
  625. case SqlDbType.Image:
  626. MetaParameter.TypeName = "image";
  627. dbType = DbType.Binary;
  628. break;
  629. case SqlDbType.Int:
  630. MetaParameter.TypeName = "int";
  631. dbType = DbType.Int32;
  632. break;
  633. case SqlDbType.Money:
  634. MetaParameter.TypeName = "money";
  635. dbType = DbType.Currency;
  636. break;
  637. case SqlDbType.SmallMoney:
  638. MetaParameter.TypeName = "smallmoney";
  639. dbType = DbType.Currency;
  640. break;
  641. case SqlDbType.NChar:
  642. MetaParameter.TypeName = "nchar";
  643. dbType = DbType.StringFixedLength;
  644. break;
  645. case SqlDbType.NText:
  646. MetaParameter.TypeName = "ntext";
  647. dbType = DbType.String;
  648. break;
  649. case SqlDbType.NVarChar:
  650. MetaParameter.TypeName = "nvarchar";
  651. dbType = DbType.String;
  652. break;
  653. case SqlDbType.Real:
  654. MetaParameter.TypeName = "real";
  655. dbType = DbType.Single;
  656. break;
  657. case SqlDbType.SmallInt:
  658. MetaParameter.TypeName = "smallint";
  659. dbType = DbType.Int16;
  660. break;
  661. case SqlDbType.Text:
  662. MetaParameter.TypeName = "text";
  663. dbType = DbType.AnsiString;
  664. break;
  665. case SqlDbType.VarChar:
  666. MetaParameter.TypeName = "varchar";
  667. dbType = DbType.AnsiString;
  668. break;
  669. case SqlDbType.TinyInt:
  670. MetaParameter.TypeName = "tinyint";
  671. dbType = DbType.Byte;
  672. break;
  673. case SqlDbType.UniqueIdentifier:
  674. MetaParameter.TypeName = "uniqueidentifier";
  675. dbType = DbType.Guid;
  676. break;
  677. case SqlDbType.Variant:
  678. MetaParameter.TypeName = "sql_variant";
  679. dbType = DbType.Object;
  680. break;
  681. default:
  682. throw new ArgumentException (exception);
  683. }
  684. sqlDbType = type;
  685. }
  686. public override string ToString()
  687. {
  688. return ParameterName;
  689. }
  690. #if NET_2_0
  691. [MonoTODO]
  692. public override void CopyTo (DbParameter param)
  693. {
  694. throw new NotImplementedException ();
  695. }
  696. [MonoTODO]
  697. public override void ResetDbType ()
  698. {
  699. throw new NotImplementedException ();
  700. }
  701. #endif // NET_2_0
  702. #endregion // Methods
  703. }
  704. }