(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Npgsql / Npgsql / NpgsqlBind.cs
blob2c7ae1352700ed3a29b417eeb5895c5f46444d0a
1 // created on 29/6/2003 at 13:28
3 // Npgsql.NpgsqlBind.cs
4 //
5 // Author:
6 // Francisco Jr. (fxjrlists@yahoo.com.br)
7 //
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
26 using System;
27 using System.IO;
28 using System.Text;
30 namespace Npgsql
33 /// <summary>
34 /// This class represents the Bind message sent to PostgreSQL
35 /// server.
36 /// </summary>
37 ///
38 internal sealed class NpgsqlBind
41 // Logging related values
42 private static readonly String CLASSNAME = "NpgsqlBind";
44 private String _portalName;
45 private String _preparedStatementName;
46 private Int16[] _parameterFormatCodes;
47 private Object[] _parameterValues;
48 private Int16[] _resultFormatCodes;
51 public NpgsqlBind(String portalName,
52 String preparedStatementName,
53 Int16[] parameterFormatCodes,
54 Object[] parameterValues,
55 Int16[] resultFormatCodes)
58 _portalName = portalName;
59 _preparedStatementName = preparedStatementName;
60 _parameterFormatCodes = parameterFormatCodes;
61 _parameterValues = parameterValues;
62 _resultFormatCodes = resultFormatCodes;
67 public String PortalName
69 get
71 return _portalName;
75 public Int16[] ParameterFormatCodes
77 get
79 return _parameterFormatCodes;
82 set
84 _parameterFormatCodes = value;
88 public Object[] ParameterValues
90 get
92 return _parameterValues;
95 set
97 _parameterValues = value;
102 public void WriteToStream(Stream outputStream, Encoding encoding)
107 Int32 messageLength = 4 +
108 encoding.GetByteCount(_portalName) + 1 +
109 encoding.GetByteCount(_preparedStatementName) + 1 +
111 (_parameterFormatCodes.Length * 2) +
115 // Get size of parameter values.
116 Int32 i;
118 if (_parameterValues != null)
119 for (i = 0; i < _parameterValues.Length; i++)
121 messageLength += 4;
122 if ( _parameterValues[i] != null)
123 if ( ((_parameterFormatCodes.Length == 1) && (_parameterFormatCodes[0] == (Int16) FormatCode.Binary)) ||
124 ((_parameterFormatCodes.Length != 1) && (_parameterFormatCodes[i] == (Int16) FormatCode.Binary)) )
125 messageLength += ((Byte[])_parameterValues[i]).Length;
126 else
127 messageLength += encoding.GetByteCount((String)_parameterValues[i]);
131 messageLength += 2 + (_resultFormatCodes.Length * 2);
134 outputStream.WriteByte((Byte)'B');
136 PGUtil.WriteInt32(outputStream, messageLength);
137 PGUtil.WriteString(_portalName, outputStream, encoding);
138 PGUtil.WriteString(_preparedStatementName, outputStream, encoding);
140 PGUtil.WriteInt16(outputStream, (Int16)_parameterFormatCodes.Length);
142 for (i = 0; i < _parameterFormatCodes.Length; i++)
143 PGUtil.WriteInt16(outputStream, _parameterFormatCodes[i]);
145 if (_parameterValues != null)
147 PGUtil.WriteInt16(outputStream, (Int16)_parameterValues.Length);
149 for (i = 0; i < _parameterValues.Length; i++)
151 if ( ((_parameterFormatCodes.Length == 1) && (_parameterFormatCodes[0] == (Int16) FormatCode.Binary)) ||
152 ((_parameterFormatCodes.Length != 1) && (_parameterFormatCodes[i] == (Int16) FormatCode.Binary)) )
155 Byte[] parameterValue = (Byte[])_parameterValues[i];
156 if (parameterValue == null)
157 PGUtil.WriteInt32(outputStream, -1);
158 else
160 PGUtil.WriteInt32(outputStream, parameterValue.Length);
161 outputStream.Write(parameterValue, 0, parameterValue.Length);
164 else
166 String parameterValue = (String)_parameterValues[i];
167 if (parameterValue == null)
168 PGUtil.WriteInt32(outputStream, -1);
169 else
171 PGUtil.WriteInt32(outputStream, encoding.GetByteCount(parameterValue));
172 outputStream.Write(encoding.GetBytes(parameterValue), 0, encoding.GetByteCount(parameterValue));
178 else
179 PGUtil.WriteInt16(outputStream, 0);
181 PGUtil.WriteInt16(outputStream, (Int16)_resultFormatCodes.Length);
182 for (i = 0; i < _resultFormatCodes.Length; i++)
183 PGUtil.WriteInt16(outputStream, _resultFormatCodes[i]);