1 // created on 30/7/2002 at 00:31
3 // Npgsql.NpgsqlMediator.cs
6 // Francisco Jr. (fxjrlists@yahoo.com.br)
8 // Copyright (C) 2002 The Npgsql Development Team
9 // npgsql-general@gborg.postgresql.org
10 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 using System.Collections;
29 using System.Collections.Specialized;
34 /// This class is responsible for serving as bridge between the backend
35 /// protocol handling and the core classes. It is used as the mediator for
36 /// exchanging data generated/sent from/to backend.
39 internal sealed class NpgsqlMediator
42 // Expectations that depend on context.
43 // Non-default values must be set before collecting responses.
45 // Some kinds of messages only get one response, and do not
46 // expect a ready_for_query response.
47 private bool _require_ready_for_query;
50 // Responses collected from the backend.
52 private ArrayList _errors;
53 private ArrayList _notices;
54 private ArrayList _resultSets;
55 private ArrayList _responses;
56 private ArrayList _notifications;
57 private ListDictionary _parameters;
58 private NpgsqlBackEndKeyData _backend_key_data;
59 private NpgsqlRowDescription _rd;
60 private ArrayList _rows;
61 private String _sqlSent;
62 private Int32 _commandTimeout;
65 public NpgsqlMediator()
67 _require_ready_for_query = true;
69 _errors = new ArrayList();
70 _notices = new ArrayList();
71 _resultSets = new ArrayList();
72 _responses = new ArrayList();
73 _notifications = new ArrayList();
74 _parameters = new ListDictionary(CaseInsensitiveComparer.Default);
75 _backend_key_data = null;
76 _sqlSent = String.Empty;
80 public void ResetExpectations()
82 _require_ready_for_query = true;
85 public void ResetResponses()
91 _notifications.Clear();
93 _backend_key_data = null;
94 _sqlSent = String.Empty;
101 public Boolean RequireReadyForQuery
105 return _require_ready_for_query;
109 _require_ready_for_query = value;
115 public NpgsqlRowDescription LastRowDescription
123 public ArrayList ResultSets
131 public ArrayList CompletedResponses
139 public ArrayList Errors
147 public ArrayList Notices
155 public ArrayList Notifications
159 return _notifications;
163 public ListDictionary Parameters
171 public NpgsqlBackEndKeyData BackendKeyData
175 return _backend_key_data;
179 public String SqlSent
192 public Int32 CommandTimeout
196 _commandTimeout = value;
201 return _commandTimeout;
206 public void AddNotification(NpgsqlNotificationEventArgs data)
208 _notifications.Add(data);
211 public void AddCompletedResponse(String response)
215 // Finished receiving the resultset. Add it to the buffer.
216 _resultSets.Add(new NpgsqlResultSet(_rd, _rows));
218 // Add a placeholder response.
219 _responses.Add(null);
221 // Discard the RowDescription.
226 // Add a placeholder resultset.
227 _resultSets.Add(null);
228 // It was just a non query string. Just add the response.
229 _responses.Add(response);
234 public void AddRowDescription(NpgsqlRowDescription rowDescription)
236 _rd = rowDescription;
237 _rows = new ArrayList();
240 public void AddAsciiRow(NpgsqlAsciiRow asciiRow)
245 public void AddBinaryRow(NpgsqlBinaryRow binaryRow)
247 _rows.Add(binaryRow);
251 public void SetBackendKeydata(NpgsqlBackEndKeyData keydata)
253 _backend_key_data = keydata;
256 public void AddParameterStatus(String Key, NpgsqlParameterStatus PS)
258 _parameters[Key] = PS;