2 // System.Data.SqlClient.SqlCommand.cs
5 // Rodrigo Moya (rdorigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
8 // (C) Ximian, Inc 2002
12 using System.ComponentModel;
14 using System.Data.Common;
15 using System.Runtime.InteropServices;
18 namespace System.Data.SqlClient
21 /// Represents a SQL statement that is executed
22 /// while connected to a SQL database.
24 // public sealed class SqlCommand : Component, IDbCommand, ICloneable
25 public sealed class SqlCommand : IDbCommand
27 // FIXME: Console.WriteLine() is used for debugging throughout
33 // default is 30 seconds
34 // for command execution
36 SqlConnection conn = null;
37 SqlTransaction trans = null;
38 CommandType cmdType = CommandType.Text;
39 bool designTime = false;
40 SqlParameterCollection parmCollection = new
41 SqlParameterCollection();
52 public SqlCommand (string cmdText)
57 public SqlCommand (string cmdText, SqlConnection connection)
63 public SqlCommand (string cmdText, SqlConnection connection,
64 SqlTransaction transaction)
71 #endregion // Constructors
78 throw new NotImplementedException ();
81 // FIXME: is this the correct way to return a stronger type?
83 IDbDataParameter IDbCommand.CreateParameter ()
85 return CreateParameter ();
89 public SqlParameter CreateParameter ()
91 return new SqlParameter ();
95 public int ExecuteNonQuery ()
97 IntPtr pgResult; // PGresult
98 int rowsAffected = -1;
99 ExecStatusType execStatus;
100 String rowsAffectedString;
103 // InvalidOperationException
104 // exception if the the connection
105 // does not exist or is not open
107 // FIXME: PQexec blocks
108 // while PQsendQuery is non-blocking
109 // which is better to use?
110 // int PQsendQuery(PGconn *conn,
111 // const char *query);
113 // execute SQL command
114 // uses internal property to get the PGConn IntPtr
115 pgResult = PostgresLibrary.
116 PQexec (conn.PostgresConnection, sql);
118 /* FIXME: throw an SqlException exception
119 * if there is a SQL Error
125 execStatus = PostgresLibrary.
126 PQresultStatus (pgResult);
128 if(execStatus == ExecStatusType.PGRES_COMMAND_OK)
130 Console.WriteLine("*** SqlCommand Execute " +
131 "got PGRES_COMMAND_OK");
132 rowsAffectedString = PostgresLibrary.
133 PQcmdTuples (pgResult);
134 Console.WriteLine("*** Rows Affected: " +
136 // FIXME: convert string to number
140 Console.WriteLine("*** Error: SqlCommand " +
141 "did not get PGRES_COMMAND_OK");
144 statusString = PostgresLibrary.
145 PQresStatus(execStatus);
146 Console.WriteLine("*** Command Status: " +
150 errorMessage = PostgresLibrary.
\r
151 PQresultErrorMessage(pgResult);
\r
153 Console.WriteLine("*** Error message: " +
\r
158 cmdStatus = PostgresLibrary.
159 PQcmdStatus(pgResult);
161 Console.WriteLine("*** Command Status: " +
164 PostgresLibrary.PQclear (pgResult);
166 // FIXME: get number of rows
167 // affected for INSERT, UPDATE, or DELETE
168 // any other, return -1 (such as, CREATE TABLE)
172 // FIXME: temporarily commmented out, so I could get a simple working
173 // SqlConnection and SqlCommand. I had to temporarily
174 // comment it out the ExecuteReader in IDbCommand as well.
177 IDataReader IDbCommand.ExecuteReader ()
179 throw new NotImplementedException ();
183 SqlDataReader ExecuteReader ()
185 throw new NotImplementedException ();
189 IDataReader IDbCommand.ExecuteReader (
190 CommandBehavior behavior)
192 throw new NotImplementedException ();
196 public SqlDataReader ExecuteReader (CommandBehavior behavior)
198 throw new NotImplementedException ();
203 public object ExecuteScalar ()
205 throw new NotImplementedException ();
209 public XmlReader ExecuteXmlReader ()
211 throw new NotImplementedException ();
215 public void Prepare ()
217 throw new NotImplementedException ();
221 public SqlCommand Clone ()
223 throw new NotImplementedException ();
226 #endregion // Methods
230 public string CommandText {
240 public int CommandTimeout {
246 // FIXME: if value < 0, throw
249 // throw ArgumentException;
254 public CommandType CommandType {
264 // FIXME: for property Connection, is this the correct
265 // way to handle a return of a stronger type?
266 IDbConnection IDbCommand.Connection {
272 // FIXME: throw an InvalidOperationException
273 // if the change was during a
274 // transaction in progress
275 Connection = (SqlConnection) value;
276 // FIXME: set Transaction property to null
280 public SqlConnection Connection {
282 // conn defaults to null
287 // FIXME: throw an InvalidOperationException
288 // if the change was during
289 // a transaction in progress
291 // FIXME: set Transaction property to null
295 public bool DesignTimeVisible {
305 // FIXME; for property Parameters, is this the correct
306 // way to handle a stronger return type?
307 IDataParameterCollection IDbCommand.Parameters {
313 SqlParameterCollection Parameters {
315 return parmCollection;
319 // FIXME: for property Transaction, is this the correct
320 // way to handle a return of a stronger type?
321 IDbTransaction IDbCommand.Transaction {
327 // FIXME: error handling
328 Transaction = (SqlTransaction) value;
332 public SqlTransaction Transaction {
338 // FIXME: error handling
344 public UpdateRowSource UpdatedRowSource {
345 // FIXME: do this once DbDataAdaptor
346 // and DataRow are done
348 throw new NotImplementedException ();
351 throw new NotImplementedException ();
355 #endregion // Properties
360 [ClassInterface(ClassInterfaceType.AutoDual)]
363 FIXME: need proper way to release resources
366 #endregion //Destructors