diff options
* Added ThirdParty node for external library sources that are shipped with the solution.
* Added conceptual TribalMedia.Framework.Data library; this is meant as a generic database layer abstraction library, that should be specialized into OpenSim.Framework.Data
* OpenSim.Framework.Data should subclass FieldMappers to extend LLVector3 and LLQuaternions
Diffstat (limited to '')
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs new file mode 100644 index 0000000..f0b3e88 --- /dev/null +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs | |||
@@ -0,0 +1,150 @@ | |||
1 | /* | ||
2 | * Copyright (c) Tribal Media AB, http://tribalmedia.se/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * The name of Tribal Media AB may not be used to endorse or promote products | ||
12 | * derived from this software without specific prior written permission. | ||
13 | * | ||
14 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
17 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | using System; | ||
28 | using System.Data; | ||
29 | using System.IO; | ||
30 | |||
31 | namespace TribalMedia.Framework.Data | ||
32 | { | ||
33 | public class DataReader | ||
34 | { | ||
35 | private readonly IDataReader m_source; | ||
36 | |||
37 | public DataReader(IDataReader source) | ||
38 | { | ||
39 | m_source = source; | ||
40 | } | ||
41 | |||
42 | public object Get(string name) | ||
43 | { | ||
44 | return m_source[name]; | ||
45 | } | ||
46 | |||
47 | public ushort GetUShort(string name) | ||
48 | { | ||
49 | return (ushort) m_source.GetInt32(m_source.GetOrdinal(name)); | ||
50 | } | ||
51 | |||
52 | public byte GetByte(string name) | ||
53 | { | ||
54 | int ordinal = m_source.GetOrdinal(name); | ||
55 | byte value = (byte) m_source.GetInt16(ordinal); | ||
56 | return value; | ||
57 | } | ||
58 | |||
59 | public sbyte GetSByte(string name) | ||
60 | { | ||
61 | return (sbyte) m_source.GetInt16(m_source.GetOrdinal(name)); | ||
62 | } | ||
63 | |||
64 | //public Vector3 GetVector(string s) | ||
65 | //{ | ||
66 | // float x = GetFloat(s + "X"); | ||
67 | // float y = GetFloat(s + "Y"); | ||
68 | // float z = GetFloat(s + "Z"); | ||
69 | |||
70 | // Vector3 vector = new Vector3(x, y, z); | ||
71 | |||
72 | // return vector; | ||
73 | //} | ||
74 | |||
75 | //public Quaternion GetQuaternion(string s) | ||
76 | //{ | ||
77 | // float x = GetFloat(s + "X"); | ||
78 | // float y = GetFloat(s + "Y"); | ||
79 | // float z = GetFloat(s + "Z"); | ||
80 | // float w = GetFloat(s + "W"); | ||
81 | |||
82 | // Quaternion quaternion = new Quaternion(x, y, z, w); | ||
83 | |||
84 | // return quaternion; | ||
85 | //} | ||
86 | |||
87 | public float GetFloat(string name) | ||
88 | { | ||
89 | return m_source.GetFloat(m_source.GetOrdinal(name)); | ||
90 | } | ||
91 | |||
92 | public byte[] GetBytes(string name) | ||
93 | { | ||
94 | int ordinal = m_source.GetOrdinal(name); | ||
95 | |||
96 | if (m_source.GetValue(ordinal) == DBNull.Value) | ||
97 | { | ||
98 | return null; | ||
99 | } | ||
100 | |||
101 | byte[] buffer = new byte[16384]; | ||
102 | |||
103 | MemoryStream memStream = new MemoryStream(); | ||
104 | |||
105 | long totalRead = 0; | ||
106 | |||
107 | int bytesRead; | ||
108 | do | ||
109 | { | ||
110 | bytesRead = (int) m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); | ||
111 | totalRead += bytesRead; | ||
112 | |||
113 | memStream.Write(buffer, 0, bytesRead); | ||
114 | } while (bytesRead == buffer.Length); | ||
115 | |||
116 | return memStream.ToArray(); | ||
117 | } | ||
118 | |||
119 | public string GetString(string name) | ||
120 | { | ||
121 | int ordinal = m_source.GetOrdinal(name); | ||
122 | object value = m_source.GetValue(ordinal); | ||
123 | |||
124 | if (value is DBNull) | ||
125 | { | ||
126 | return null; | ||
127 | } | ||
128 | |||
129 | return (string) value; | ||
130 | } | ||
131 | |||
132 | public bool Read() | ||
133 | { | ||
134 | return m_source.Read(); | ||
135 | } | ||
136 | |||
137 | internal Guid GetGuid(string name) | ||
138 | { | ||
139 | string guidString = GetString(name); | ||
140 | if (String.IsNullOrEmpty(guidString)) | ||
141 | { | ||
142 | return Guid.Empty; | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | return new Guid(guidString); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | } \ No newline at end of file | ||