1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
//
// System.Data.SqlClient.SqlDataReader
//
// Authors:
// Konstantin Triger <kostat@mainsoft.com>
// Boris Kirzner <borisk@mainsoft.com>
//
// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Data.SqlTypes;
using System.Data.ProviderBase;
using java.sql;
namespace System.Data.SqlClient
{
public class SqlDataReader : AbstractDataReader
{
#region Constructors
internal SqlDataReader(SqlCommand command) : base(command)
{
}
#endregion // Constructors
#region Properties
#endregion // Properties
#region Methods
protected sealed override SystemException CreateException(string message, SQLException e)
{
return new SqlException(message, e, (SqlConnection)_command.Connection);
}
protected sealed override SystemException CreateException(java.io.IOException e)
{
return new SqlException(e, (SqlConnection)_command.Connection);
}
public override String GetDataTypeName(int columnIndex)
{
try {
string jdbcTypeName = Results.getMetaData().getColumnTypeName(columnIndex + 1);
return SqlConvert.JdbcTypeNameToDbTypeName(jdbcTypeName);
}
catch (SQLException e) {
throw CreateException(e);
}
}
protected override int GetProviderType(int jdbcType)
{
return (int)SqlConvert.JdbcTypeToSqlDbType(jdbcType);
}
// Gets the value of the specified column as a SqlBinary.
public SqlBinary GetSqlBinary(int columnIndex)
{
byte[] bytes = GetBytes(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlBinary.Null;
}
else {
return new SqlBinary(bytes);
}
}
// Gets the value of the specified column as a SqlBoolean.
public SqlBoolean GetSqlBoolean(int columnIndex)
{
bool boolean = GetBoolean(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlBoolean.Null;
}
else {
return new SqlBoolean(boolean);
}
}
// Gets the value of the specified column as a SqlByte.
public SqlByte GetSqlByte(int columnIndex)
{
byte byt = GetByte(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlByte.Null;
}
else {
return new SqlByte(byt);
}
}
#if NET_2_0
public virtual SqlBytes GetSqlBytes (int columnIndex)
{
byte [] bytes = GetBytes (columnIndex);
if (IsDBNull (columnIndex)) {
return SqlBytes.Null;
}
else {
return new SqlBytes (bytes);
}
}
public virtual SqlChars GetSqlChars (int columnIndex)
{
SqlString sqlStr = GetSqlString (columnIndex);
if (sqlStr.IsNull) {
return SqlChars.Null;
}
else {
return new SqlChars (sqlStr);
}
}
[MonoNotSupported("SqlXml is not fully implemented")]
public virtual SqlXml GetSqlXml (int columnIndex)
{
throw new NotImplementedException ();
}
#endif
// Gets the value of the specified column as a SqlDecimal.
public SqlDecimal GetSqlDecimal(int columnIndex)
{
decimal dec = GetDecimal(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlDecimal.Null;
}
else {
return new SqlDecimal(dec);
}
}
// Gets the value of the specified column as a SqlDateTime.
public SqlDateTime GetSqlDateTime(int columnIndex)
{
DateTime dateTime = GetDateTime(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlDateTime.Null;
}
else {
return new SqlDateTime(dateTime);
}
}
// Gets the value of the specified column as a SqlDouble.
public SqlDouble GetSqlDouble(int columnIndex)
{
double doubl = GetDouble(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlDouble.Null;
}
else {
return new SqlDouble(doubl);
}
}
// Gets the value of the specified column as a SqlInt16.
public SqlInt16 GetSqlInt16(int columnIndex)
{
short s = GetInt16(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlInt16.Null;
}
else {
return new SqlInt16(s);
}
}
// Gets the value of the specified column as a SqlInt32.
public SqlInt32 GetSqlInt32(int columnIndex)
{
int i = GetInt32(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlInt32.Null;
}
else {
return new SqlInt32(i);
}
}
// Gets the value of the specified column as a SqlInt64.
public SqlInt64 GetSqlInt64(int columnIndex)
{
long l = GetInt64(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlInt64.Null;
}
else {
return new SqlInt64(l);
}
}
// Gets the value of the specified column as a SqlMoney.
public SqlMoney GetSqlMoney(int columnIndex)
{
decimal dec = GetDecimal(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlMoney.Null;
}
else {
return new SqlMoney(dec);
}
}
// Gets the value of the specified column as a SqlSingle.
public SqlSingle GetSqlSingle(int columnIndex)
{
float f = GetFloat(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlSingle.Null;
}
else {
return new SqlSingle(f);
}
}
// Gets the value of the specified column as a SqlString.
public SqlString GetSqlString(int columnIndex)
{
string str = GetString(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlString.Null;
}
else {
return new SqlString(str);
}
}
// Gets the value of the specified column as a SqlGuid.
public SqlGuid GetSqlGuid(int columnIndex)
{
object obj = GetValue(columnIndex);
if(IsDBNull(columnIndex)) {
return SqlGuid.Null;
}
else {
if (obj is byte[]) {
return new SqlGuid((byte[])obj);
}
else {
return new SqlGuid((string)obj);
}
}
}
// Gets all the attribute columns in the current row.
public int GetSqlValues(Object[] values)
{
int columnCount = FieldCount;
int i = 0;
for (; i < values.Length && i < columnCount; i++) {
values[i] = GetSqlValue(i);
}
return i;
}
// Gets an Object that is a representation of the underlying SqlDbType Variant.
public Object GetSqlValue(int columnIndex)
{
try {
int jdbcType = ResultsMetaData.getColumnType(columnIndex + 1);
SqlDbType sqlDbType = SqlConvert.JdbcTypeToSqlDbType(jdbcType);
switch (sqlDbType) {
case SqlDbType.BigInt : return GetSqlInt64(columnIndex);
case SqlDbType.Binary : return GetSqlBinary(columnIndex);
case SqlDbType.Bit : return GetSqlBoolean(columnIndex);
case SqlDbType.Char : return GetSqlString(columnIndex);
case SqlDbType.DateTime : return GetSqlDateTime(columnIndex);
case SqlDbType.Decimal : return GetSqlDecimal(columnIndex);
case SqlDbType.Float : return GetSqlDouble(columnIndex);
case SqlDbType.Image : return GetSqlBinary(columnIndex);
case SqlDbType.Int : return GetSqlInt32(columnIndex);
case SqlDbType.Money : return GetSqlDecimal(columnIndex);
case SqlDbType.NChar : return GetSqlString(columnIndex);
case SqlDbType.NText : return GetSqlString(columnIndex);
case SqlDbType.NVarChar : return GetSqlString(columnIndex);
case SqlDbType.Real : return GetSqlSingle(columnIndex);
case SqlDbType.UniqueIdentifier : return GetSqlGuid(columnIndex);
case SqlDbType.SmallDateTime : return GetSqlDateTime(columnIndex);
case SqlDbType.SmallInt : return GetSqlInt16(columnIndex);
case SqlDbType.SmallMoney : return GetSqlDecimal(columnIndex);
case SqlDbType.Text : return GetSqlString(columnIndex);
case SqlDbType.Timestamp : return GetSqlDateTime(columnIndex);
case SqlDbType.TinyInt : return GetSqlByte(columnIndex);
case SqlDbType.VarBinary : return GetSqlBinary(columnIndex);
case SqlDbType.VarChar : return GetSqlString(columnIndex);
case SqlDbType.Variant : return GetValue(columnIndex);
default : return GetValue(columnIndex);
}
}
catch (SQLException exp) {
throw new Exception(exp.Message);
}
}
#if NET_2_0
protected bool IsCommandBehavior (CommandBehavior condition)
{
return (_command.Behavior & condition) == condition;
}
#endif
#endregion // Methods
}
}
|