1 // created on 12/7/2003 at 18:36
3 // Npgsql.NpgsqlError.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
34 /// This class represents the ErrorResponse message sent from PostgreSQL
38 internal sealed class NpgsqlError
40 // Logging related values
41 private static readonly String CLASSNAME = "NpgsqlError";
43 private Int32 _protocolVersion;
44 private String _severity;
46 private String _message;
47 private String _detail;
49 private String _position;
50 private String _where;
53 private String _routine;
68 public NpgsqlError(Int32 protocolVersion)
70 _protocolVersion = protocolVersion;
74 public void ReadFromStream(Stream inputStream, Encoding encoding)
77 if (_protocolVersion == ProtocolVersion.Version2)
79 _message = PGUtil.ReadString(inputStream, encoding);
84 Int32 messageLength = PGUtil.ReadInt32(inputStream, new Byte[4]);
86 //[TODO] Would this be the right way to do?
87 // Check the messageLength value. If it is 1178686529, this would be the
88 // "FATA" string, which would mean a protocol 2.0 error string.
90 if (messageLength == 1178686529)
92 _message = "FATA" + PGUtil.ReadString(inputStream, encoding);
99 field = (Char) inputStream.ReadByte();
101 // Now start to read fields.
105 fieldValue = PGUtil.ReadString(inputStream, encoding);
110 _severity = fieldValue;
116 _message = fieldValue;
119 _detail = fieldValue;
125 _position = fieldValue;
137 _routine = fieldValue;
142 field = (Char) inputStream.ReadByte();
146 // Read 0 byte terminator.
147 //inputStream.ReadByte();