1 // created on 22/6/2003 at 18:33
3 // Npgsql.NpgsqlParse.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
27 using System
.Collections
;
38 /// This class represents the Parse message sent to PostgreSQL
42 internal sealed class NpgsqlParse
44 // Logging related values
45 private static readonly String CLASSNAME
= "NpgsqlParse";
47 private String _prepareName
;
48 private String _queryString
;
49 private Int32
[] _parameterIDs
;
52 public NpgsqlParse(String prepareName
, String queryString
, Int32
[] parameterIDs
)
54 _prepareName
= prepareName
;
55 _queryString
= queryString
;
56 _parameterIDs
= parameterIDs
;
60 public void WriteToStream(Stream outputStream
, Encoding encoding
)
62 outputStream
.WriteByte((Byte
)'P');
66 // name of prepared statement + 1 null string terminator +
67 // query string + 1 null string terminator
69 // + Int32 * number of parameters.
70 Int32 messageLength
= 4 + encoding
.GetByteCount(_prepareName
) + 1 + encoding
.GetByteCount(_queryString
) + 1 + 2 + (_parameterIDs
.Length
* 4);
71 //Int32 messageLength = 4 + _prepareName.Length + 1 + _queryString.Length + 1 + 2 + (_parameterIDs.Length * 4);
73 PGUtil
.WriteInt32(outputStream
, messageLength
);
74 PGUtil
.WriteString(_prepareName
, outputStream
, encoding
);
75 PGUtil
.WriteString(_queryString
, outputStream
, encoding
);
76 PGUtil
.WriteInt16(outputStream
, (Int16
)_parameterIDs
.Length
);
79 for(Int32 i
= 0; i
< _parameterIDs
.Length
; i
++)
80 PGUtil
.WriteInt32(outputStream
, _parameterIDs
[i
]);