OleDbCommand.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // System.Data.OleDb.OleDbCommand
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. //
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Data.Common;
  14. using System.Collections;
  15. namespace System.Data.OleDb
  16. {
  17. /// <summary>
  18. /// Represents an SQL statement or stored procedure to execute against a data source.
  19. /// </summary>
  20. public sealed class OleDbCommand : Component, ICloneable, IDbCommand
  21. {
  22. #region Fields
  23. string commandText;
  24. int timeout;
  25. CommandType commandType;
  26. OleDbConnection connection;
  27. OleDbParameterCollection parameters;
  28. OleDbTransaction transaction;
  29. bool designTimeVisible;
  30. OleDbDataReader dataReader;
  31. CommandBehavior behavior;
  32. ArrayList gdaCommands;
  33. ArrayList gdaResults;
  34. #endregion // Fields
  35. #region Constructors
  36. public OleDbCommand ()
  37. {
  38. commandText = String.Empty;
  39. timeout = 30; // default timeout per .NET
  40. commandType = CommandType.Text;
  41. connection = null;
  42. parameters = new OleDbParameterCollection ();
  43. transaction = null;
  44. designTimeVisible = false;
  45. dataReader = null;
  46. behavior = CommandBehavior.Default;
  47. gdaCommands = new ArrayList ();
  48. gdaResults = new ArrayList ();
  49. }
  50. public OleDbCommand (string cmdText)
  51. : this ()
  52. {
  53. CommandText = cmdText;
  54. }
  55. public OleDbCommand (string cmdText, OleDbConnection connection)
  56. : this (cmdText)
  57. {
  58. Connection = connection;
  59. }
  60. public OleDbCommand (string cmdText, OleDbConnection connection, OleDbTransaction transaction)
  61. : this (cmdText, connection)
  62. {
  63. this.transaction = transaction;
  64. }
  65. #endregion // Constructors
  66. #region Properties
  67. public string CommandText
  68. {
  69. get { return commandText; }
  70. set {
  71. string[] queries = value.Split (new Char[] {';'});
  72. gdaCommands.Clear ();
  73. foreach (string query in queries)
  74. gdaCommands.Add (libgda.gda_command_new (query, 0, 0));
  75. commandText = value;
  76. }
  77. }
  78. public int CommandTimeout {
  79. get { return timeout; }
  80. set { timeout = value; }
  81. }
  82. public CommandType CommandType {
  83. get { return commandType; }
  84. set { commandType = value; }
  85. }
  86. public OleDbConnection Connection {
  87. get { return connection; }
  88. set { connection = value; }
  89. }
  90. public bool DesignTimeVisible {
  91. get { return designTimeVisible; }
  92. set { designTimeVisible = value; }
  93. }
  94. public OleDbParameterCollection Parameters {
  95. get { return parameters; }
  96. set { parameters = value; }
  97. }
  98. public OleDbTransaction Transaction {
  99. get { return transaction; }
  100. set { transaction = value; }
  101. }
  102. public UpdateRowSource UpdatedRowSource {
  103. [MonoTODO]
  104. get { throw new NotImplementedException (); }
  105. [MonoTODO]
  106. set { throw new NotImplementedException (); }
  107. }
  108. IDbConnection IDbCommand.Connection {
  109. get { return Connection; }
  110. set { Connection = (OleDbConnection) value; }
  111. }
  112. IDataParameterCollection IDbCommand.Parameters {
  113. get { return Parameters; }
  114. }
  115. IDbTransaction IDbCommand.Transaction {
  116. get { return Transaction; }
  117. set { Transaction = (OleDbTransaction) value; }
  118. }
  119. internal ArrayList GdaResults {
  120. get { return gdaResults; }
  121. }
  122. #endregion // Properties
  123. #region Methods
  124. [MonoTODO]
  125. public void Cancel ()
  126. {
  127. throw new NotImplementedException ();
  128. }
  129. public OleDbParameter CreateParameter ()
  130. {
  131. return new OleDbParameter ();
  132. }
  133. [MonoTODO]
  134. protected override void Dispose (bool disposing)
  135. {
  136. throw new NotImplementedException ();
  137. }
  138. public int ExecuteNonQuery ()
  139. {
  140. if (connection == null)
  141. throw new InvalidOperationException ();
  142. if (connection.State == ConnectionState.Closed)
  143. throw new InvalidOperationException ();
  144. // FIXME: a third check is mentioned in .NET docs
  145. IntPtr gdaConnection = connection.GdaConnection;
  146. IntPtr gdaParameterList = parameters.GdaParameterList;
  147. return libgda.gda_connection_execute_non_query (gdaConnection, (IntPtr) gdaCommands[0], gdaParameterList);
  148. }
  149. public OleDbDataReader ExecuteReader ()
  150. {
  151. return ExecuteReader (CommandBehavior.Default);
  152. }
  153. public OleDbDataReader ExecuteReader (CommandBehavior behavior)
  154. {
  155. if (connection.State != ConnectionState.Open)
  156. throw new InvalidOperationException ();
  157. this.behavior = behavior;
  158. IntPtr gdaConnection = connection.GdaConnection;
  159. IntPtr gdaParameterList = parameters.GdaParameterList;
  160. foreach (IntPtr gdaCommand in gdaCommands)
  161. GdaResults.Add (libgda.gda_connection_execute_single_command (gdaConnection, gdaCommand, gdaParameterList));
  162. dataReader = new OleDbDataReader (this);
  163. dataReader.NextResult ();
  164. return dataReader;
  165. }
  166. [MonoTODO]
  167. public object ExecuteScalar ()
  168. {
  169. throw new NotImplementedException ();
  170. }
  171. [MonoTODO]
  172. object ICloneable.Clone ()
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. [MonoTODO]
  177. IDbDataParameter IDbCommand.CreateParameter ()
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. [MonoTODO]
  182. IDataReader IDbCommand.ExecuteReader ()
  183. {
  184. throw new NotImplementedException ();
  185. }
  186. [MonoTODO]
  187. IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
  188. {
  189. throw new NotImplementedException ();
  190. }
  191. [MonoTODO]
  192. public void Prepare ()
  193. {
  194. throw new NotImplementedException ();
  195. }
  196. public void ResetCommandTimeout ()
  197. {
  198. timeout = 30;
  199. }
  200. #endregion
  201. #region Internal Methods
  202. // only meant to be used between OleDbConnectioin,
  203. // OleDbCommand, and OleDbDataReader
  204. internal void OpenReader (OleDbDataReader reader)
  205. {
  206. connection.OpenReader (reader);
  207. }
  208. #endregion
  209. }
  210. }