2 // System.Data.SqlClient.SqlXmlTextReader.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
7 // Tim Coleman (tim@timcoleman.com)
9 // (C) Ximian, Inc 2002
10 // (C) Daniel Morgan 2002
11 // Copyright (C) Tim Coleman, 2002
15 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using Mono
.Data
.Tds
.Protocol
;
42 namespace System
.Data
.SqlClient
{
43 internal sealed class SqlXmlTextReader
: TextReader
, IDisposable
47 bool disposed
= false;
50 string localBuffer
= "<results>";
57 internal SqlXmlTextReader (SqlDataReader reader
)
67 public override void Close()
72 protected override void Dispose (bool disposing
)
77 ((IDisposable
) reader
).Dispose ();
83 void IDisposable
.Dispose ()
86 GC
.SuppressFinalize (this);
89 private bool GetNextBuffer ()
98 localBuffer
= reader
.GetString (0);
99 else if (reader
.NextResult () && reader
.Read ())
100 localBuffer
= reader
.GetString (0);
103 localBuffer
= "</results>";
108 public override int Peek ()
111 if (localBuffer
== null || localBuffer
.Length
== 0) {
112 moreResults
= GetNextBuffer ();
116 if (eof
&& position
>= localBuffer
.Length
)
118 return (int) localBuffer
[position
];
121 public override int Read ()
123 int result
= Peek ();
125 if (!eof
&& position
>= localBuffer
.Length
)
130 public override int Read (char[] buffer
, int index
, int count
)
132 bool moreResults
= true;
135 if (localBuffer
== null)
136 moreResults
= GetNextBuffer ();
138 while (moreResults
&& count
- countRead
> localBuffer
.Length
- position
) {
139 localBuffer
.CopyTo (position
, buffer
, index
+ countRead
, localBuffer
.Length
);
140 countRead
+= localBuffer
.Length
;
141 moreResults
= GetNextBuffer ();
143 if (moreResults
&& countRead
< count
) {
144 localBuffer
.CopyTo (position
, buffer
, index
+ countRead
, count
- countRead
);
145 position
+= count
- countRead
;
151 public override int ReadBlock (char[] buffer
, int index
, int count
)
153 return Read (buffer
, index
, count
);
156 public override string ReadLine ()
158 bool moreResults
= true;
160 if (localBuffer
== null)
161 moreResults
= GetNextBuffer ();
164 outBuffer
= localBuffer
;
169 public override string ReadToEnd ()
171 string outBuffer
= String
.Empty
;
173 bool moreResults
= true;
174 if (localBuffer
== null)
175 moreResults
= GetNextBuffer ();
176 while (moreResults
) {
177 outBuffer
+= localBuffer
;
178 moreResults
= GetNextBuffer ();
183 #endregion // Methods