diff options
author | lbsa71 | 2008-03-03 07:48:35 +0000 |
---|---|---|
committer | lbsa71 | 2008-03-03 07:48:35 +0000 |
commit | b3b1f74485882c14478a6e74de0f7c9da13ff7d2 (patch) | |
tree | 146e00bb25325eef313336fc084d0bb102b7ab60 /OpenSim/Framework/Data.Base/BaseDataReader.cs | |
parent | Thank you very much, Ahzzmandius for: (diff) | |
download | opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.zip opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.gz opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.bz2 opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.xz |
* Started the ardous task to rename the TribalMedia.Framework.Data to OpenSim.Framework.Data.Base
It's you !!
How are you gentlemen !!
Diffstat (limited to 'OpenSim/Framework/Data.Base/BaseDataReader.cs')
-rw-r--r-- | OpenSim/Framework/Data.Base/BaseDataReader.cs | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.Base/BaseDataReader.cs b/OpenSim/Framework/Data.Base/BaseDataReader.cs new file mode 100644 index 0000000..67fb7c1 --- /dev/null +++ b/OpenSim/Framework/Data.Base/BaseDataReader.cs | |||
@@ -0,0 +1,127 @@ | |||
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 BaseDataReader | ||
34 | { | ||
35 | private readonly IDataReader m_source; | ||
36 | |||
37 | public BaseDataReader(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 float GetFloat(string name) | ||
65 | { | ||
66 | return m_source.GetFloat(m_source.GetOrdinal(name)); | ||
67 | } | ||
68 | |||
69 | public byte[] GetBytes(string name) | ||
70 | { | ||
71 | int ordinal = m_source.GetOrdinal(name); | ||
72 | |||
73 | if (m_source.GetValue(ordinal) == DBNull.Value) | ||
74 | { | ||
75 | return null; | ||
76 | } | ||
77 | |||
78 | byte[] buffer = new byte[16384]; | ||
79 | |||
80 | MemoryStream memStream = new MemoryStream(); | ||
81 | |||
82 | long totalRead = 0; | ||
83 | |||
84 | int bytesRead; | ||
85 | do | ||
86 | { | ||
87 | bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); | ||
88 | totalRead += bytesRead; | ||
89 | |||
90 | memStream.Write(buffer, 0, bytesRead); | ||
91 | } while (bytesRead == buffer.Length); | ||
92 | |||
93 | return memStream.ToArray(); | ||
94 | } | ||
95 | |||
96 | public string GetString(string name) | ||
97 | { | ||
98 | int ordinal = m_source.GetOrdinal(name); | ||
99 | object value = m_source.GetValue(ordinal); | ||
100 | |||
101 | if (value is DBNull) | ||
102 | { | ||
103 | return null; | ||
104 | } | ||
105 | |||
106 | return (string)value; | ||
107 | } | ||
108 | |||
109 | public bool Read() | ||
110 | { | ||
111 | return m_source.Read(); | ||
112 | } | ||
113 | |||
114 | public Guid GetGuid(string name) | ||
115 | { | ||
116 | string guidString = GetString(name); | ||
117 | if (String.IsNullOrEmpty(guidString)) | ||
118 | { | ||
119 | return Guid.Empty; | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | return new Guid(guidString); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } \ No newline at end of file | ||