2 // System.Data.SqlClient.SqlCommand.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
8 // (C) Ximian, Inc 2002
11 // use #define DEBUG_SqlCommand if you want to spew debug messages
12 // #define DEBUG_SqlCommand
15 using System.ComponentModel;
17 using System.Data.Common;
18 using System.Runtime.InteropServices;
21 namespace System.Data.SqlClient
24 /// Represents a SQL statement that is executed
25 /// while connected to a SQL database.
27 // public sealed class SqlCommand : Component, IDbCommand, ICloneable
28 public sealed class SqlCommand : IDbCommand
30 // FIXME: Console.WriteLine() is used for debugging throughout
36 // default is 30 seconds
37 // for command execution
39 SqlConnection conn = null;
40 SqlTransaction trans = null;
41 CommandType cmdType = CommandType.Text;
42 bool designTime = false;
43 SqlParameterCollection parmCollection = new
44 SqlParameterCollection();
55 public SqlCommand (string cmdText)
60 public SqlCommand (string cmdText, SqlConnection connection)
66 public SqlCommand (string cmdText, SqlConnection connection,
67 SqlTransaction transaction)
74 #endregion // Constructors
81 // FIXME: use non-blocking Exec for this
82 throw new NotImplementedException ();
85 // FIXME: is this the correct way to return a stronger type?
87 IDbDataParameter IDbCommand.CreateParameter ()
89 return CreateParameter ();
93 public SqlParameter CreateParameter ()
95 return new SqlParameter ();
99 public int ExecuteNonQuery ()
101 IntPtr pgResult; // PGresult
102 int rowsAffected = -1;
103 ExecStatusType execStatus;
104 String rowsAffectedString;
106 if(conn.State != ConnectionState.Open)
107 throw new InvalidOperationException(
108 "ConnnectionState is not Open");
110 // FIXME: PQexec blocks
111 // while PQsendQuery is non-blocking
112 // which is better to use?
113 // int PQsendQuery(PGconn *conn,
114 // const char *query);
116 // execute SQL command
117 // uses internal property to get the PGConn IntPtr
118 pgResult = PostgresLibrary.
119 PQexec (conn.PostgresConnection, sql);
121 execStatus = PostgresLibrary.
122 PQresultStatus (pgResult);
124 if(execStatus == ExecStatusType.PGRES_COMMAND_OK)
126 rowsAffectedString = PostgresLibrary.
127 PQcmdTuples (pgResult);
129 Console.WriteLine("rowsAffectedString: " +
131 #endif // DEBUG_SqlCommand
132 if(rowsAffectedString != null)
133 if(rowsAffectedString.Equals("") == false)
134 rowsAffected = int.Parse(rowsAffectedString);
140 errorMessage = PostgresLibrary.
141 PQresStatus(execStatus);
143 errorMessage += " " + PostgresLibrary.
\r
144 PQresultErrorMessage(pgResult);
\r
146 throw new SqlException(0, 0,
148 conn.DataSource, "SqlCommand", 0);
\r
152 cmdStatus = PostgresLibrary.
153 PQcmdStatus(pgResult);
155 Console.WriteLine("*** Command Status: " +
157 #endif // DEBUG_SqlCommand
158 PostgresLibrary.PQclear (pgResult);
160 // FIXME: get number of rows
161 // affected for INSERT, UPDATE, or DELETE
162 // any other, return -1 (such as, CREATE TABLE)
167 IDataReader IDbCommand.ExecuteReader ()
169 return ExecuteReader ();
173 SqlDataReader ExecuteReader ()
175 throw new NotImplementedException ();
179 IDataReader IDbCommand.ExecuteReader (
180 CommandBehavior behavior)
182 return ExecuteReader (behavior);
186 public SqlDataReader ExecuteReader (CommandBehavior behavior)
188 throw new NotImplementedException ();
192 public object ExecuteScalar ()
194 throw new NotImplementedException ();
198 public XmlReader ExecuteXmlReader ()
200 throw new NotImplementedException ();
204 public void Prepare ()
206 // FIXME: parameters have to be implemented for this
207 throw new NotImplementedException ();
211 public SqlCommand Clone ()
213 throw new NotImplementedException ();
216 #endregion // Methods
220 public string CommandText {
230 public int CommandTimeout {
236 // FIXME: if value < 0, throw
239 // throw ArgumentException;
244 public CommandType CommandType {
254 // FIXME: for property Connection, is this the correct
255 // way to handle a return of a stronger type?
256 IDbConnection IDbCommand.Connection {
262 // FIXME: throw an InvalidOperationException
263 // if the change was during a
264 // transaction in progress
267 Connection = (SqlConnection) value;
269 // Connection = value;
271 // FIXME: set Transaction property to null
275 public SqlConnection Connection {
277 // conn defaults to null
282 // FIXME: throw an InvalidOperationException
283 // if the change was during
284 // a transaction in progress
286 // FIXME: set Transaction property to null
290 public bool DesignTimeVisible {
300 // FIXME; for property Parameters, is this the correct
301 // way to handle a stronger return type?
302 IDataParameterCollection IDbCommand.Parameters {
308 SqlParameterCollection Parameters {
310 return parmCollection;
314 // FIXME: for property Transaction, is this the correct
315 // way to handle a return of a stronger type?
316 IDbTransaction IDbCommand.Transaction {
322 // FIXME: error handling - do not allow
323 // setting of transaction if transaction
327 Transaction = (SqlTransaction) value;
329 // Transaction = value;
333 public SqlTransaction Transaction {
339 // FIXME: error handling
345 public UpdateRowSource UpdatedRowSource {
346 // FIXME: do this once DbDataAdaptor
347 // and DataRow are done
349 throw new NotImplementedException ();
352 throw new NotImplementedException ();
356 #endregion // Properties
361 public void Dispose() {
362 // FIXME: need proper way to release resources
369 // FIXME: need proper way to release resources
373 #endregion //Destructors