aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Base/BaseDataReader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Base/BaseDataReader.cs')
-rw-r--r--OpenSim/Data/Base/BaseDataReader.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/OpenSim/Data/Base/BaseDataReader.cs b/OpenSim/Data/Base/BaseDataReader.cs
new file mode 100644
index 0000000..3baefcd
--- /dev/null
+++ b/OpenSim/Data/Base/BaseDataReader.cs
@@ -0,0 +1,139 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Data;
30using System.IO;
31
32namespace OpenSim.Framework.Data.Base
33{
34 public abstract class BaseDataReader
35 {
36 private readonly IDataReader m_source;
37
38 public BaseDataReader(IDataReader source)
39 {
40 m_source = source;
41 }
42
43 public object Get(string name)
44 {
45 return m_source[name];
46 }
47
48 public ushort GetUShort(string name)
49 {
50 return (ushort)m_source.GetInt32(m_source.GetOrdinal(name));
51 }
52
53 public byte GetByte(string name)
54 {
55 int ordinal = m_source.GetOrdinal(name);
56 byte value = (byte)m_source.GetInt16(ordinal);
57 return value;
58 }
59
60 public sbyte GetSByte(string name)
61 {
62 return (sbyte)m_source.GetInt16(m_source.GetOrdinal(name));
63 }
64
65 public float GetFloat(string name)
66 {
67 return m_source.GetFloat(m_source.GetOrdinal(name));
68 }
69
70 public byte[] GetBytes(string name)
71 {
72 int ordinal = m_source.GetOrdinal(name);
73
74 if (m_source.GetValue(ordinal) == DBNull.Value)
75 {
76 return null;
77 }
78
79 byte[] buffer = new byte[16384];
80
81 MemoryStream memStream = new MemoryStream();
82
83 long totalRead = 0;
84
85 int bytesRead;
86 do
87 {
88 bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length);
89 totalRead += bytesRead;
90
91 memStream.Write(buffer, 0, bytesRead);
92 } while (bytesRead == buffer.Length);
93
94 return memStream.ToArray();
95 }
96
97 public string GetString(string name)
98 {
99 int ordinal = m_source.GetOrdinal(name);
100 object value = m_source.GetValue(ordinal);
101
102 if (value is DBNull)
103 {
104 return null;
105 }
106
107 return (string)value;
108 }
109
110 public bool Read()
111 {
112 return m_source.Read();
113 }
114
115 public virtual Guid GetGuid(string name)
116 {
117 return m_source.GetGuid(m_source.GetOrdinal(name));
118 }
119
120 public UInt32 GetUInt32(string name )
121 {
122 return (UInt32)GetInt32(name);
123 }
124
125 private Int32 GetInt32(string name)
126 {
127 int ordinal = m_source.GetOrdinal(name);
128 int int32 = m_source.GetInt32(ordinal);
129 return int32;
130 }
131
132 public Int64 GetInt64(string name)
133 {
134 int ordinal = m_source.GetOrdinal( name );
135 long int64 = m_source.GetInt64(ordinal);
136 return int64;
137 }
138 }
139}