2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Npgsql / Npgsql / NpgsqlQuery.cs
1 // Npgsql.NpgsqlQuery.cs
2 //
3 // Author:
4 //      Dave Joyner <d4ljoyn@yahoo.com>
5 //
6 //      Copyright (C) 2002 The Npgsql Development Team
7 //      npgsql-general@gborg.postgresql.org
8 //      http://gborg.postgresql.org/project/npgsql/projdisplay.php
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
25 using System;
26 using System.IO;
27 using System.Text;
28 using System.Net.Sockets;
29
30 namespace Npgsql
31 {
32     /// <summary>
33     /// Summary description for NpgsqlQuery
34     /// </summary>
35     internal sealed class NpgsqlQuery
36     {
37         private NpgsqlCommand _command;
38         private ProtocolVersion _protocolVersion;
39
40         public NpgsqlQuery(NpgsqlCommand command, ProtocolVersion protocolVersion)
41         {
42             _command = command;
43             _protocolVersion = protocolVersion;
44
45         }
46         public void WriteToStream( Stream outputStream, Encoding encoding )
47         {
48             //NpgsqlEventLog.LogMsg( this.ToString() + _commandText, LogLevel.Debug  );
49
50
51             String commandText = _command.GetCommandText();
52             // Send the query to server.
53             // Write the byte 'Q' to identify a query message.
54             outputStream.WriteByte((Byte)'Q');
55
56             if (_protocolVersion == ProtocolVersion.Version3)
57             {
58                 // Write message length. Int32 + string length + null terminator.
59                 PGUtil.WriteInt32(outputStream, 4 + encoding.GetByteCount(commandText) + 1);
60             }
61
62             // Write the query. In this case it is the CommandText text.
63             // It is a string terminated by a C NULL character.
64             PGUtil.WriteString(commandText, outputStream, encoding);
65         }
66
67
68     }
69 }