SQLiteParameterCollection.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Text;
  5. namespace System.Data.SQLiteClient
  6. {
  7. sealed public class SQLiteParameterCollection : CollectionBase, IDataParameterCollection
  8. {
  9. internal SQLiteParameterCollection ()
  10. {
  11. }
  12. public SQLiteParameter this[String pParamName]
  13. {
  14. get
  15. {
  16. int index = IndexOf(pParamName);
  17. if( index < 0 )
  18. return null;
  19. else
  20. return InnerList[index] as SQLiteParameter;
  21. }
  22. set
  23. {
  24. throw new NotSupportedException();
  25. }
  26. }
  27. Object IDataParameterCollection.this[String pParamName]
  28. {
  29. get
  30. {
  31. return this[pParamName];
  32. }
  33. set
  34. {
  35. this[pParamName] = value as SQLiteParameter;
  36. }
  37. }
  38. public SQLiteParameter this[int index]
  39. {
  40. get
  41. {
  42. return (SQLiteParameter)(InnerList[index]);
  43. }
  44. set
  45. {
  46. throw new NotSupportedException();
  47. }
  48. }
  49. public int Add(Object param)
  50. {
  51. if( param == null )
  52. throw new ArgumentNullException();
  53. if( InnerList.Contains(param) )
  54. throw new ArgumentException("Parameter is already added into the collection");
  55. return InnerList.Add((SQLiteParameter)param);
  56. }
  57. public SQLiteParameter Add(SQLiteParameter param)
  58. {
  59. Add((Object)param);
  60. return param;
  61. }
  62. public SQLiteParameter Add(String parameterName, Object val)
  63. {
  64. SQLiteParameter param = Add(parameterName,DbType.String);
  65. param.Value = val;
  66. return param;
  67. }
  68. public SQLiteParameter Add(String parameterName, DbType dbType)
  69. {
  70. return Add(parameterName,dbType,0);
  71. }
  72. public SQLiteParameter Add(String parameterName, DbType dbType, int size)
  73. {
  74. return Add(parameterName,dbType,size,null);
  75. }
  76. public SQLiteParameter Add(String parameterName, DbType dbType, int size, String sourceColumn)
  77. {
  78. SQLiteParameter param = new SQLiteParameter(parameterName,dbType);
  79. param.Size = size;
  80. if( sourceColumn != null )
  81. param.SourceColumn = sourceColumn;
  82. return Add(param);
  83. }
  84. public bool Contains (String parameterName)
  85. {
  86. return IndexOf(parameterName) >= 0;
  87. }
  88. public int IndexOf (String parameterName)
  89. {
  90. if( parameterName == null )
  91. return -1;
  92. int count = InnerList.Count;
  93. for( int i=0 ; i < count ; ++i )
  94. {
  95. String name = this[i].ParameterName;
  96. if( name != null && String.Compare(name,parameterName,true,System.Globalization.CultureInfo.InvariantCulture) == 0 )
  97. return i;
  98. }
  99. return -1;
  100. }
  101. public void RemoveAt (String parameterName)
  102. {
  103. throw new NotSupportedException();
  104. }
  105. }
  106. }