示例#1
1
 public static decimal? GetDecimal(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetDecimal(index);
 }
 private static ExcelRow SpreadsheetRowResolver(DbDataReader dr)
 {
     if ((dr.IsDBNull(0) == false) && (dr.IsDBNull(1) == false))
     {
         return new ExcelRow
         {
             PaymentDossierID = (long)dr.GetDouble(0),
             AffiliateSynergyId = (long)dr.GetDouble(1)
         };
     }
     return null;
 }
示例#3
0
文件: Page.cs 项目: minhchau2236/pgkh
        protected override void MappingData(System.Data.Common.DbDataReader reader)
        {
            _id    = (Guid)reader["PageId"];
            _name  = (string)reader["PageName"];
            _title = (string)reader["PageTitle"];

            if (!reader.IsDBNull(reader.GetOrdinal("PageLanguage")))
            {
                _language = (int)reader["PageLanguage"];
            }
            if (!reader.IsDBNull(reader.GetOrdinal("PageTemplate")))
            {
                _template = (int)reader["PageTemplate"];
            }
        }
示例#4
0
 public static double? GetDouble(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetDouble(index);
 }
示例#5
0
 public static char? GetChar(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetChar(index);
 }
示例#6
0
        public override object Map(DbDataReader dataReader, RowMapperContext context)
        {
            if (dataReader.IsDBNull(0))
                return null;

            return _converter(dataReader.GetValue(0));
        }
示例#7
0
 public static Guid? GetGuid(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetGuid(index);
 }
示例#8
0
 public static Int32? GetInt32(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetInt32(index);
 }
示例#9
0
 public static bool? GetBoolean(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetBoolean(index);
 }
示例#10
0
 public static float? GetFloat(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     else
         return reader.GetFloat(index);
 }
示例#11
0
        public double? ReadDouble(DbDataReader reader, int index)
        {
            double d = double.NaN;

            if (reader.IsDBNull(index))
                return 0;

            Object obj = reader.GetValue(index);
            if (obj.GetType() == typeof(Decimal))
            {
                d = Decimal.ToDouble((Decimal)obj);
            }
            else if (obj.GetType() == typeof(double))
            {
                d = (double)obj;
            }
            else if (obj.GetType() == typeof(float))
            {
                d = (float)obj;
            }
            else if (obj.GetType() == typeof(string))
            {
                d = double.Parse((string)obj);
            }
            else
                return null;
            return d;
        }
示例#12
0
文件: Database.cs 项目: jags9415/chat
        protected Conversation GetCurrentConversation(DbDataReader reader)
        {
            int colID = reader.GetOrdinal("grupoid_grupo");
            int colName = reader.GetOrdinal("nombre");

            Conversation conversation = new Conversation();
            if (!reader.IsDBNull(colID))
            {
                conversation.ID = reader.GetInt32(colID);
            }
            if (!reader.IsDBNull(colName))
            {
                conversation.Name = reader.GetString(colName);
            }

            return conversation;
        }
示例#13
0
 protected override void MappingData(System.Data.Common.DbDataReader reader)
 {
     if (!reader.IsDBNull(reader.GetOrdinal("VoteQuestionId")))
     {
         _id = (Guid)reader["VoteQuestionId"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("VoteQuestionName")))
     {
         _name = (string)reader["VoteQuestionName"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("SubDomainId")))
     {
         _SubDomainId = (Guid)reader["SubDomainId"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("IsActive")))
     {
         _isActive = (bool)reader["IsActive"];
     }
 }
示例#14
0
 protected override void MappingData(System.Data.Common.DbDataReader reader)
 {
     if (!reader.IsDBNull(reader.GetOrdinal("Id")))
     {
         Id = (Guid)reader["Id"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("Title")))
     {
         Title = (string)reader["Title"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("Path")))
     {
         Path = (string)reader["Path"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("CreationDate")))
     {
         CreationDate       = (DateTime)reader["CreationDate"];
         CreationDateString = string.Format("{0:dd/MM/yyyy}", (DateTime)reader["CreationDate"]);
     }
     if (!reader.IsDBNull(reader.GetOrdinal("Priority")))
     {
         Priority = (int)reader["Priority"];
     }
     if (!reader.IsDBNull(reader.GetOrdinal("FileExtension")))
     {
         FileExtension = (string)reader["FileExtension"];
     }
 }
示例#15
0
        public override object Map(DbDataReader dataReader, RowMapperContext context)
        {
            var arrayType = context.Type.GetElementType();
            var array = Array.CreateInstance(arrayType, _posNames.Length);

            for (int i = 0; i < _posNames.Length; i++)
            {
                if (!dataReader.IsDBNull(_posNames[i].Pos))
                {
                    array.SetValue(dataReader.GetValue(_posNames[i].Pos), i);
                }
            }

            return array;
        }
示例#16
0
    public static IEnumerable <PSObject> Translate(System.Data.Common.DbDataReader dataReader, Boolean ProviderTypes)
    {
        List <Map> MapList = new List <Map>();
        int        Ord     = 0;

        foreach (var x in dataReader.GetSchemaTable().Select("", "ColumnOrdinal"))
        {
            MapList.Add(new Map(Ord, x["DataType"].ToString(), x["ColumnName"].ToString())); // x("AllowDBNull"),
            Ord += 1;
        }

        PSObject responseObject = new PSObject();

        while (dataReader.Read())
        {
            PSObject psObj = new PSObject();
            foreach (Map m in MapList)
            {
                {
                    var withBlock = psObj.Members;
                    if (dataReader.IsDBNull(m.Ordinal))
                    {
                        withBlock.Add(new PSNoteProperty(m.Name, null), true);
                    }
                    else
                    {
                        try
                        {
                            if (ProviderTypes)
                            {
                                withBlock.Add(new PSNoteProperty(m.Name, dataReader.GetProviderSpecificValue(m.Ordinal)), true);
                            }
                            else
                            {
                                withBlock.Add(new PSNoteProperty(m.Name, dataReader.GetValue(m.Ordinal)), true);
                            }
                        }
                        catch (Exception ex)
                        {
                            string msg = string.Format("Failed to translate, ColumnName = {0} | ColumnOrdinal = {1} | ColumnType = {2} | ToStringValue = '{3}' | See InnerException for details", m.Name, m.Ordinal, m.DataType, dataReader.GetValue(m.Ordinal).ToString());
                            throw new Exception(msg, ex);
                        }
                    }
                }
            }
            yield return(psObj);
        }
    }
示例#17
0
 static int IsDBNull(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         System.Data.Common.DbDataReader obj = (System.Data.Common.DbDataReader)ToLua.CheckObject(L, 1, typeof(System.Data.Common.DbDataReader));
         int  arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         bool o    = obj.IsDBNull(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
示例#18
0
        protected override object GetValue(System.Data.Common.DbDataReader reader, PropertyInfo property)
        {
            var oracleReader = (reader as OracleDataReader);
            int ord          = reader.GetOrdinal(property.Name);

            if (reader.IsDBNull(ord))
            {
                return(null);
            }

            if (oracleReader.GetFieldType(ord) == typeof(decimal))
            {
                return(GetDecimal(oracleReader, ord, property));
            }
            else
            {
                return(oracleReader[property.Name]);
            }
        }
示例#19
0
        public int? ReadInt(DbDataReader reader, int index)
        {
            if (reader.IsDBNull(index))
                return 0;

            int i;
            Object obj = reader.GetValue(index);


            if (obj.GetType() == typeof(int) ||
                obj.GetType() == typeof(Int16) ||
                obj.GetType() == typeof(Int32) ||
                obj.GetType() == typeof(Int64))
                i = Convert.ToInt32(obj);
            else if (obj.GetType() == typeof(string))
                i = int.Parse((string)obj);
            else
                return null;

            return i;
        }
示例#20
0
        private void mapValues(DbDataReader reader, object record)
        {
            foreach (var accessor in this.accessors) {
                var index = reader.GetOrdinal(accessor.Name);

                if (reader.IsDBNull(index)) {
                    continue;
                }

                if (accessor.PropertyType == typeof(string)) {
                    accessor.Set(record, reader.GetString(index));
                } else if (accessor.PropertyType == typeof(int) || accessor.PropertyType == typeof(int?)) {
                    accessor.Set(record, reader.GetInt32(index));
                } else if (accessor.PropertyType == typeof(long) || accessor.PropertyType == typeof(long?)) {
                    accessor.Set(record, reader.GetInt64(index));
                } else if (accessor.PropertyType == typeof(DateTime) || accessor.PropertyType == typeof(DateTime?)) {
                    accessor.Set(record, reader.GetDateTime(index));
                } else if (accessor.PropertyType == typeof(char) || accessor.PropertyType == typeof(char?)) {
                    accessor.Set(record, reader.GetChar(index));
                }
            }
        }
示例#21
0
        /// <summary>
        /// This may be useful if you want to serialize a full table as json. Usually, a IDictionary object is serialized as JSON object (eg Newtonsoft.Json)
        /// It can be used with dynmaic as well (http://stackoverflow.com/questions/18290852/generate-dynamic-object-from-dictionary-with-c-reflection)
        /// </summary>
        /// <typeparam name="T">The type of the IDictionary, usually Dictionary&lt;string,object&gt;</typeparam>
        /// <param name="table">The DbDataReader to convert to a Dictionary List</param>
        /// <param name="inputList">An existing list to append the items. Can be null to create a new list</param>
        /// <returns>A List containing the Objects</returns>
        public static List <T> AsDictionaryList <T>(this System.Data.Common.DbDataReader table, List <T>?inputList = null) where T : IDictionary <string, object?>, new()
        {
            if (inputList == null)
            {
                inputList = new List <T>();
            }

            int columnCount = table.FieldCount;



            while (table.Read())
            {
                T item = new T();
                foreach (var col in Enumerable.Range(0, columnCount))
                {
                    item.Add(table.GetName(col), table.IsDBNull(col) ? null : table[col]);
                }
                inputList.Add(item);
            }
            return(inputList);
        }
示例#22
0
 public static int GetIdentityValue(this System.Data.Common.DbDataReader reader, int ordinal = 0, int @default = -1)
 {
     if (ordinal >= 0)
     {
         if (!reader.IsDBNull(ordinal))
         {
             var obj = reader[ordinal];
             if (obj != null)
             {
                 if (typeof(Int32).IsAssignableFrom(obj.GetType()))
                 {
                     return((Int32)reader[0]);
                 }
                 else if (typeof(decimal).IsAssignableFrom(obj.GetType()))
                 {
                     return((int)(decimal)reader[0]);
                 }
             }
         }
     }
     return(@default);
 }
        public DateTime? ReadDateTime(DbDataReader reader, int index)
        {
            if (reader.IsDBNull(index))
                return null;

            Object obj = reader.GetValue(index);
            if (obj.GetType() == typeof(DateTime))
                return (DateTime)obj;
            else
                return Convert.ToDateTime(obj);
        }
        internal static List<OfferDetails> GetOfferDetailObject(DbDataReader reader)
        {
            OfferDetails hooOffer = null;
            List<OfferDetails> allOffers = new List<OfferDetails>();
            while (reader.Read())
            {
                hooOffer = new OfferDetails();
                hooOffer.OfferId = reader.IsDBNull(reader.GetOrdinal("OfferId")) ? 0 : Convert.ToInt32(reader["OfferId"], CultureInfo.InvariantCulture);
                hooOffer.OfferTitle = reader.IsDBNull(reader.GetOrdinal("OfferTitle")) ? string.Empty : Convert.ToString(reader["OfferTitle"], CultureInfo.InvariantCulture);
                hooOffer.OfferDescription = reader.IsDBNull(reader.GetOrdinal("OfferDescription")) ? string.Empty : Convert.ToString(reader["OfferDescription"], CultureInfo.InvariantCulture);
                hooOffer.ImageUrl = reader.IsDBNull(reader.GetOrdinal("OfferImageUrl")) ? string.Empty : Convert.ToString(reader["OfferImageUrl"], CultureInfo.InvariantCulture);
                hooOffer.StartDate = reader.IsDBNull(reader.GetOrdinal("StartDate")) ? DateTime.Now : Convert.ToDateTime(reader["StartDate"], CultureInfo.InvariantCulture);
                hooOffer.ExpireDate = reader.IsDBNull(reader.GetOrdinal("ExpireDate")) ? DateTime.Now : Convert.ToDateTime(reader["ExpireDate"], CultureInfo.InvariantCulture);
                hooOffer.comments = reader.IsDBNull(reader.GetOrdinal("Comments")) ? string.Empty : Convert.ToString(reader["Comments"], CultureInfo.InvariantCulture);
                hooOffer.Latitude = reader.IsDBNull(reader.GetOrdinal("Latitude")) ? 0 : Convert.ToDouble(reader["Latitude"], CultureInfo.InvariantCulture);
                hooOffer.Longitude = reader.IsDBNull(reader.GetOrdinal("Longitude")) ? 0 : Convert.ToDouble(reader["Longitude"], CultureInfo.InvariantCulture);
                hooOffer.City = reader.IsDBNull(reader.GetOrdinal("City")) ? string.Empty : Convert.ToString(reader["City"], CultureInfo.InvariantCulture);
                hooOffer.OfferCategory = reader.IsDBNull(reader.GetOrdinal("OfferCategory")) ? string.Empty : Convert.ToString(reader["OfferCategory"], CultureInfo.InvariantCulture);
                hooOffer.PromoCode = reader.IsDBNull(reader.GetOrdinal("PromoCode")) ? string.Empty : Convert.ToString(reader["PromoCode"], CultureInfo.InvariantCulture);

                hooOffer.Ratings = reader.IsDBNull(reader.GetOrdinal("SumOfRating")) ? 0 : Convert.ToInt32(reader["SumOfRating"], CultureInfo.InvariantCulture);

                hooOffer.Vendor = new Supplier();
                hooOffer.Vendor.SupplierId = reader.IsDBNull(reader.GetOrdinal("SupplierId")) ? 0 : Convert.ToInt32(reader["SupplierId"], CultureInfo.InvariantCulture);
                hooOffer.Vendor.SupplierName = reader.IsDBNull(reader.GetOrdinal("SupName")) ? string.Empty : Convert.ToString(reader["SupName"], CultureInfo.InvariantCulture);
                hooOffer.Vendor.ContactNumber = reader.IsDBNull(reader.GetOrdinal("SupContactNumber")) ? string.Empty : Convert.ToString(reader["SupContactNumber"], CultureInfo.InvariantCulture);
                hooOffer.Vendor.Email = reader.IsDBNull(reader.GetOrdinal("SupEmailId")) ? string.Empty : Convert.ToString(reader["SupEmailId"], CultureInfo.InvariantCulture);
                hooOffer.Vendor.ImageUrl = ConfigurationManager.AppSettings["ImageFolder"].ToString();
                hooOffer.Vendor.ImageUrl +=  reader.IsDBNull(reader.GetOrdinal("SupImageURL")) ? string.Empty : Convert.ToString(reader["SupImageURL"], CultureInfo.InvariantCulture);
                hooOffer.Vendor.SupplierAddress = reader.IsDBNull(reader.GetOrdinal("SupAddress")) ? string.Empty : Convert.ToString(reader["SupAddress"], CultureInfo.InvariantCulture);
                allOffers.Add(hooOffer);

            }
            reader.Close();

            return allOffers;
        }
示例#25
0
文件: DeptDao.cs 项目: qq5013/JXNG
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private DeptInfo BuilderEntity(DbDataReader reader)
        {
            DeptInfo info = new DeptInfo();

            info.DeptId = (reader.IsDBNull(reader.GetOrdinal("deptid"))) ? "" : reader["deptid"].ToString();
            info.DeptName = (reader.IsDBNull(reader.GetOrdinal("deptname"))) ? "" : reader["deptname"].ToString();
            info.ParentId = (reader.IsDBNull(reader.GetOrdinal("parentid"))) ? "" : reader["parentid"].ToString();
            info.Remark = (reader.IsDBNull(reader.GetOrdinal("remark"))) ? "" : reader["remark"].ToString();
            info.DeptType = (reader.IsDBNull(reader.GetOrdinal("DEPTTYPE"))) ? "" : reader["DEPTTYPE"].ToString();
            return info;
        }
示例#26
0
        private LogEntry ReadEntry(DbDataReader dataReader)
        {
            var entry = new LogEntry();

            int idOrd = dataReader.GetOrdinal("ID");
            entry.ID = dataReader.GetFieldValue<int>(idOrd);

            int applicationOrd = dataReader.GetOrdinal("Application");
            entry.Application = dataReader.IsDBNull(applicationOrd) ? null : dataReader.GetFieldValue<string>(applicationOrd);

            int machineOrd = dataReader.GetOrdinal("MachineName");
            entry.MachineName = dataReader.IsDBNull(machineOrd) ? null : dataReader.GetFieldValue<string>(machineOrd);

            int timestampOrd = dataReader.GetOrdinal("TimeStamp");
            entry.TimeStamp = dataReader.GetFieldValue<DateTime>(timestampOrd);

            int threadOrd = dataReader.GetOrdinal("Thread");
            entry.Thread = dataReader.IsDBNull(threadOrd) ? null : dataReader.GetFieldValue<string>(threadOrd);

            int levelOrd = dataReader.GetOrdinal("Level");
            entry.Level = dataReader.IsDBNull(levelOrd) ? null : dataReader.GetFieldValue<string>(levelOrd);

            int loggerOrd = dataReader.GetOrdinal("Logger");
            entry.Logger = dataReader.IsDBNull(loggerOrd) ? null : dataReader.GetFieldValue<string>(loggerOrd);

            int messageOrd = dataReader.GetOrdinal("Message");
            entry.Message = dataReader.IsDBNull(messageOrd) ? null : dataReader.GetFieldValue<string>(messageOrd);

            int exceptionOrd = dataReader.GetOrdinal("Exception");
            entry.Exception = dataReader.IsDBNull(exceptionOrd) ? null : dataReader.GetFieldValue<string>(exceptionOrd);

            int ntUserOrd = dataReader.GetOrdinal("NTUser");
            entry.NTUser = dataReader.IsDBNull(ntUserOrd) ? null : dataReader.GetFieldValue<string>(ntUserOrd);

            return entry;
        }
示例#27
0
        public static T GetValueOrDefault <T>(this DbDataReader reader, string name)
        {
            var idx = reader.GetOrdinal(name);

            return(reader.IsDBNull(idx) ? default : reader.GetFieldValue <T>(idx));
        }
示例#28
0
 protected Authority readAuthority(DbDataReader dataReader)
 {
     Authority auth = null;
       while (dataReader.Read())
         {
             auth = new Authority();
             //Authority_ID,Auth_Type_ID,Default_Group_ID,Authority_Guid,Authority_Name,
             //Authority_URL,Pass_Phrase, Email_Proxy,Description,Contact_Email,Bug_Email,Location
             if (!dataReader.IsDBNull(0))
                 auth.authorityID = dataReader.GetInt32(0);
             if (!dataReader.IsDBNull(1))
                 auth.authTypeID = dataReader.GetInt32(1);
             if (!dataReader.IsDBNull(2))
                 auth.defaultGroupID = dataReader.GetInt32(2);
             if (!dataReader.IsDBNull(3))
                 auth.authGuid = dataReader.GetString(3);
             if (!dataReader.IsDBNull(4))
                 auth.authName = dataReader.GetString(4);
             if (!dataReader.IsDBNull(5))
                 auth.authURL = dataReader.GetString(5);
             if (!dataReader.IsDBNull(6))
                 auth.passphrase = dataReader.GetString(6);
             if (!dataReader.IsDBNull(7))
                 auth.emailProxy = dataReader.GetString(7);
             if (!dataReader.IsDBNull(8))
                 auth.description = dataReader.GetString(8);
             if (!dataReader.IsDBNull(9))
                 auth.contactEmail = dataReader.GetString(9);
             if (!dataReader.IsDBNull(10))
                 auth.bugEmail = dataReader.GetString(10);
             if (!dataReader.IsDBNull(11))
                 auth.location = dataReader.GetString(11);
         }
     return auth;
 }
 protected override object ReadInternal(DbDataReader reader, int ordinal, SqlRandomTableColumn columnInfo, Type asType)
 {
     ValidateReadType(typeof(TimeSpan), asType);
     if (reader.IsDBNull(ordinal))
         return DBNull.Value;
     return ((System.Data.SqlClient.SqlDataReader)reader).GetTimeSpan(ordinal);
 }
 private static decimal? GetDecimalValue(DbDataReader dataReader, int index)
 {
     decimal? value = null;
     if (!dataReader.IsDBNull(index))
     {
         value = dataReader.GetDecimal(index);
     }
     return value;
 }
示例#31
0
		MembershipUser GetUserFromReader (DbDataReader reader, string username, object userId)
		{
			int i = 0;
			if (username == null)
				i = 1;

			if (userId != null)
				username = reader.GetString (8);

			return new MembershipUser (this.Name, /* XXX is this right?  */
				(username == null ? reader.GetString (0) : username), /* name */
				(userId == null ? reader.GetGuid (8 + i) : userId), /* providerUserKey */
				reader.IsDBNull (0 + i) ? null : reader.GetString (0 + i), /* email */
				reader.IsDBNull (1 + i) ? null : reader.GetString (1 + i), /* passwordQuestion */
				reader.IsDBNull (2 + i) ? null : reader.GetString (2 + i), /* comment */
				reader.GetBoolean (3 + i), /* isApproved */
				reader.GetBoolean (9 + i), /* isLockedOut */
				reader.GetDateTime (4 + i).ToLocalTime (), /* creationDate */
				reader.GetDateTime (5 + i).ToLocalTime (), /* lastLoginDate */
				reader.GetDateTime (6 + i).ToLocalTime (), /* lastActivityDate */
				reader.GetDateTime (7 + i).ToLocalTime (), /* lastPasswordChangedDate */
				reader.GetDateTime (10 + i).ToLocalTime () /* lastLockoutDate */);
		}
 internal static void FillCompatibleSettersFromReader(SmiEventSink_Default sink, SmiTypedGetterSetter setters, IList<SmiExtendedMetaData> metaData, DbDataReader reader)
 {
     for (int i = 0; i < metaData.Count; i++)
     {
         object sqlValue;
         DateTimeOffset dateTimeOffset;
         TimeSpan timeSpan;
         ExtendedClrTypeCode code;
         if (reader.IsDBNull(i))
         {
             SetDBNull_Unchecked(sink, setters, i);
             continue;
         }
         switch (metaData[i].SqlDbType)
         {
             case SqlDbType.BigInt:
             {
                 SetInt64_Unchecked(sink, setters, i, reader.GetInt64(i));
                 continue;
             }
             case SqlDbType.Binary:
             {
                 SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Bit:
             {
                 SetBoolean_Unchecked(sink, setters, i, reader.GetBoolean(i));
                 continue;
             }
             case SqlDbType.Char:
             {
                 SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.DateTime:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.Decimal:
             {
                 SqlDataReader reader6 = reader as SqlDataReader;
                 if (reader6 == null)
                 {
                     break;
                 }
                 SetSqlDecimal_Unchecked(sink, setters, i, reader6.GetSqlDecimal(i));
                 continue;
             }
             case SqlDbType.Float:
             {
                 SetDouble_Unchecked(sink, setters, i, reader.GetDouble(i));
                 continue;
             }
             case SqlDbType.Image:
             {
                 SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Int:
             {
                 SetInt32_Unchecked(sink, setters, i, reader.GetInt32(i));
                 continue;
             }
             case SqlDbType.Money:
             {
                 SetSqlMoney_Checked(sink, setters, i, metaData[i], new SqlMoney(reader.GetDecimal(i)));
                 continue;
             }
             case SqlDbType.NChar:
             case SqlDbType.NText:
             case SqlDbType.NVarChar:
             {
                 SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Real:
             {
                 SetSingle_Unchecked(sink, setters, i, reader.GetFloat(i));
                 continue;
             }
             case SqlDbType.UniqueIdentifier:
             {
                 SetGuid_Unchecked(sink, setters, i, reader.GetGuid(i));
                 continue;
             }
             case SqlDbType.SmallDateTime:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.SmallInt:
             {
                 SetInt16_Unchecked(sink, setters, i, reader.GetInt16(i));
                 continue;
             }
             case SqlDbType.SmallMoney:
             {
                 SetSqlMoney_Checked(sink, setters, i, metaData[i], new SqlMoney(reader.GetDecimal(i)));
                 continue;
             }
             case SqlDbType.Text:
             {
                 SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Timestamp:
             {
                 SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.TinyInt:
             {
                 SetByte_Unchecked(sink, setters, i, reader.GetByte(i));
                 continue;
             }
             case SqlDbType.VarBinary:
             {
                 SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.VarChar:
             {
                 SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Variant:
             {
                 SqlDataReader reader4 = reader as SqlDataReader;
                 if (reader4 == null)
                 {
                     goto Label_0311;
                 }
                 sqlValue = reader4.GetSqlValue(i);
                 goto Label_0319;
             }
             case SqlDbType.Xml:
             {
                 SqlDataReader reader5 = reader as SqlDataReader;
                 if (reader5 == null)
                 {
                     goto Label_02E4;
                 }
                 SetSqlXml_Unchecked(sink, setters, i, reader5.GetSqlXml(i));
                 continue;
             }
             case SqlDbType.Udt:
             {
                 SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                 continue;
             }
             case SqlDbType.Date:
             case SqlDbType.DateTime2:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.Time:
             {
                 SqlDataReader reader3 = reader as SqlDataReader;
                 if (reader3 == null)
                 {
                     goto Label_03A0;
                 }
                 timeSpan = reader3.GetTimeSpan(i);
                 goto Label_03AE;
             }
             case SqlDbType.DateTimeOffset:
             {
                 SqlDataReader reader2 = reader as SqlDataReader;
                 if (reader2 == null)
                 {
                     goto Label_03D5;
                 }
                 dateTimeOffset = reader2.GetDateTimeOffset(i);
                 goto Label_03E2;
             }
             default:
                 throw ADP.NotSupported();
         }
         SetSqlDecimal_Unchecked(sink, setters, i, new SqlDecimal(reader.GetDecimal(i)));
         continue;
     Label_02E4:
         SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
         continue;
     Label_0311:
         sqlValue = reader.GetValue(i);
     Label_0319:
         code = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(metaData[i].SqlDbType, metaData[i].IsMultiValued, sqlValue, null, 210L);
         SetCompatibleValueV200(sink, setters, i, metaData[i], sqlValue, code, 0, 0, null);
         continue;
     Label_03A0:
         timeSpan = (TimeSpan) reader.GetValue(i);
     Label_03AE:
         SetTimeSpan_Checked(sink, setters, i, metaData[i], timeSpan);
         continue;
     Label_03D5:
         dateTimeOffset = (DateTimeOffset) reader.GetValue(i);
     Label_03E2:
         SetDateTimeOffset_Unchecked(sink, setters, i, dateTimeOffset);
     }
 }
示例#33
0
        private bool MapValue(GroupResult<PosName> posName, DbDataReader reader, Func<object, object> converter, object instance, PocoColumn pocoColumn, object defaultValue)
        {
            if (!reader.IsDBNull(posName.Key.Pos))
            {
                var value = converter != null ? converter(reader.GetValue(posName.Key.Pos)) : reader.GetValue(posName.Key.Pos);
                pocoColumn.SetValue(instance, value);
                return true;
            }

            if (_mappingOntoExistingInstance && defaultValue == null)
            {
                pocoColumn.SetValue(instance, null);
            }

            return false;
        }
        public string ReadString(DbDataReader reader, int index)
        {
            if (reader.IsDBNull(index))
                return null;

            string str;
            Object obj = reader.GetValue(index);
            if (obj.GetType() == typeof(string))
                str = (string)obj;
            else
                return obj.ToString();

            return str;
        }
 protected override object ReadInternal(DbDataReader reader, int ordinal, SqlRandomTableColumn columnInfo, Type asType)
 {
     ValidateReadType(typeof(double), asType);
     if (reader.IsDBNull(ordinal))
         return DBNull.Value;
     return reader.GetDouble(ordinal);
 }
 public TimeSpan? ReadTimeSpan(DbDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
         return null;
     Object obj = reader.GetValue(index);
     if (obj.GetType() == typeof(TimeSpan))
         return (TimeSpan)obj;
     else
         return null;
 }
示例#37
0
 /// <summary>
 /// Load all values from DbDataReader
 /// </summary>
 /// <param name="reader">Reader from which to load all column values</param>
 public Donymous(DbDataReader reader)
 {
     for (int i = 0; i < reader.FieldCount; i++)
         this.memberValues[reader.GetName(i)] = reader.IsDBNull(i) ? null : reader.GetValue(i);
 }
示例#38
0
        // Copy multiple fields from reader to SmiTypedGetterSetter
        //  Supports V200 code path, without damaging backward compat for V100 code.
        //  Main differences are supporting DbDataReader, and for binary, character, decimal and Udt types.
        //  Assumes caller enforces that reader and setter metadata are compatible
        internal static void FillCompatibleSettersFromReader(SmiEventSink_Default sink, SmiTypedGetterSetter setters, IList<SmiExtendedMetaData> metaData, DbDataReader reader) {
            for (int i = 0; i < metaData.Count; i++) {
                if (reader.IsDBNull(i)) {
                    ValueUtilsSmi.SetDBNull_Unchecked(sink, setters, i);
                }
                else {
                    switch (metaData[i].SqlDbType) {
                        case SqlDbType.BigInt:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int64));
                            SetInt64_Unchecked(sink, setters, i, reader.GetInt64(i));
                            break;
                        case SqlDbType.Binary:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.ByteArray));
                            SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.Bit:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Boolean));
                            SetBoolean_Unchecked(sink, setters, i, reader.GetBoolean(i));
                            break;
                        case SqlDbType.Char:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.CharArray));
                            SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.DateTime:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTime));
                            SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                            break;
                        case SqlDbType.Decimal: { // block to scope sqlReader local to avoid conflicts
                                Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlDecimal));
                                // Support full fidelity for SqlDataReader
                                SqlDataReader sqlReader = reader as SqlDataReader;
                                if (null != sqlReader) {
                                    SetSqlDecimal_Unchecked(sink, setters, i, sqlReader.GetSqlDecimal(i));
                                }
                                else {
                                    SetSqlDecimal_Unchecked(sink, setters, i, new SqlDecimal(reader.GetDecimal(i)));
                                }
                            }
                            break;
                        case SqlDbType.Float:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Double));
                            SetDouble_Unchecked(sink, setters, i, reader.GetDouble(i));
                            break;
                        case SqlDbType.Image:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.ByteArray));
                            SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.Int:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int32));
                            SetInt32_Unchecked(sink, setters, i, reader.GetInt32(i));
                            break;
                        case SqlDbType.Money:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlMoney));
                            SetSqlMoney_Checked(sink, setters, i, metaData[i], new SqlMoney(reader.GetDecimal(i)));
                            break;
                        case SqlDbType.NChar:
                        case SqlDbType.NText:
                        case SqlDbType.NVarChar:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.CharArray));
                            SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.Real:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Single));
                            SetSingle_Unchecked(sink, setters, i, reader.GetFloat(i));
                            break;
                        case SqlDbType.UniqueIdentifier:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Guid));
                            SetGuid_Unchecked(sink, setters, i, reader.GetGuid(i));
                            break;
                        case SqlDbType.SmallDateTime:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTime));
                            SetDateTime_Checked(sink, setters, i,metaData[i], reader.GetDateTime(i));
                            break;
                        case SqlDbType.SmallInt:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int16));
                            SetInt16_Unchecked(sink, setters, i, reader.GetInt16(i));
                            break;
                        case SqlDbType.SmallMoney:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlMoney));
                            SetSqlMoney_Checked(sink, setters, i, metaData[i], new SqlMoney(reader.GetDecimal(i)));
                            break;
                        case SqlDbType.Text:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.CharArray));
                            SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.Timestamp:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.ByteArray));
                            SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.TinyInt:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Byte));
                            SetByte_Unchecked(sink, setters, i, reader.GetByte(i));
                            break;
                        case SqlDbType.VarBinary:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.ByteArray));
                            SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.VarChar:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.String));
                            SetCharsOrString_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;
                        case SqlDbType.Xml: {
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlXml));
                                SqlDataReader sqlReader = reader as SqlDataReader;
                                if (null != sqlReader) {
                                    SetSqlXml_Unchecked(sink, setters, i, sqlReader.GetSqlXml(i));
                                }
                                else {
                                    SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                                }
                            }
                            break;
                        case SqlDbType.Variant: {  // block to scope sqlReader local and avoid conflicts
                                // Support better options for SqlDataReader
                                SqlDataReader sqlReader = reader as SqlDataReader;
                                SqlBuffer.StorageType storageType = SqlBuffer.StorageType.Empty;
                                object o;
                                if (null != sqlReader) {
                                    o = sqlReader.GetSqlValue(i);
                                    storageType = sqlReader.GetVariantInternalStorageType(i);
                                }
                                else {
                                    o = reader.GetValue(i);
                                }
                                ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(metaData[i].SqlDbType, metaData[i].IsMultiValued, o, null,
                                    // 

                                    SmiContextFactory.KatmaiVersion
                                    );
                                if ((storageType == SqlBuffer.StorageType.DateTime2) || (storageType == SqlBuffer.StorageType.Date))
                                    SetCompatibleValueV200(sink, setters, i, metaData[i], o, typeCode, 0, 0, null, storageType);
                                else
                                    SetCompatibleValueV200(sink, setters, i, metaData[i], o, typeCode, 0, 0, null);
                            }
                            break;

                        case SqlDbType.Udt:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.ByteArray));
                            // Skip serialization for Udt types.
                            SetBytes_FromReader(sink, setters, i, metaData[i], reader, 0);
                            break;

                        // SqlDbType.Structured should have been caught before this point for TVPs.  SUDTs will still need to implement.

                        case SqlDbType.Date:
                        case SqlDbType.DateTime2:
                            Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTime));
                            SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                            break;
                        case SqlDbType.Time: { // block to scope sqlReader local and avoid conflicts
                                Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.TimeSpan));
                                SqlDataReader sqlReader = reader as SqlDataReader;
                                TimeSpan ts;
                                if (null != sqlReader) {
                                    ts = sqlReader.GetTimeSpan(i);
                                } else {
                                    ts = (TimeSpan)reader.GetValue(i);
                                }
                                SetTimeSpan_Checked(sink, setters, i, metaData[i], ts);
                            }
                            break;
                        case SqlDbType.DateTimeOffset: { // block to scope sqlReader local and avoid conflicts
                                Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTimeOffset));
                                SqlDataReader sqlReader = reader as SqlDataReader;
                                DateTimeOffset dto;
                                if (null != sqlReader) {
                                    dto = sqlReader.GetDateTimeOffset(i);
                                } else {
                                    dto = (DateTimeOffset)reader.GetValue(i);
                                }
                                SetDateTimeOffset_Unchecked(sink, setters, i, dto);
                            }
                            break;

                        default:
                            // In order for us to get here we would have to have an 
                            // invalid instance of SqlDbType, or one would have to add 
                            // new member to SqlDbType without adding a case in this 
                            // switch, hence the assert - it must be 

                            Debug.Assert(false, "unsupported DbType:" + metaData[i].SqlDbType.ToString());
                            throw ADP.NotSupported();

                    }
                }
            }
        }
示例#39
0
		MembershipUser GetUserFromReader (DbDataReader reader)
		{
			return new MembershipUser (this.Name, /* XXX is this right?  */
						   reader.GetString (0), /* name */
						   reader.GetGuid (1), /* providerUserKey */
						   reader.IsDBNull (2) ? null : reader.GetString (2), /* email */
						   reader.IsDBNull (3) ? null : reader.GetString (3), /* passwordQuestion */
						   reader.IsDBNull (4) ? null : reader.GetString (4), /* comment */
						   reader.GetBoolean (5), /* isApproved */
						   reader.GetBoolean (6), /* isLockedOut */
						   reader.GetDateTime (7).ToLocalTime (), /* creationDate */
						   reader.GetDateTime (8).ToLocalTime (), /* lastLoginDate */
						   reader.GetDateTime (9).ToLocalTime (), /* lastActivityDate */
						   reader.GetDateTime (10).ToLocalTime (), /* lastPasswordChangedDate */
						   reader.GetDateTime (11).ToLocalTime () /* lastLockoutDate */);
		}
示例#40
0
        public IEnumerable <Bunk> QueryBunkListView(DataTransferObject.Foundation.BunkQueryCondition condition, Core.Pagination pagination)
        {
            var result = new List <Bunk>();

            using (var dbOperator = new DbOperator(Provider, ConnectionString))
            {
                if (!string.IsNullOrWhiteSpace(condition.Airline))
                {
                    dbOperator.AddParameter("@iAirline", condition.Airline.Trim());
                }
                if (!string.IsNullOrWhiteSpace(condition.Departure))
                {
                    dbOperator.AddParameter("@iDeparture", condition.Departure.Trim());
                }
                if (!string.IsNullOrWhiteSpace(condition.Arrival))
                {
                    dbOperator.AddParameter("@iArrival", condition.Arrival.Trim());
                }
                if (!string.IsNullOrWhiteSpace(condition.BunkCode))
                {
                    dbOperator.AddParameter("@iBunkCode", condition.BunkCode.Trim());
                }
                if (condition.BunkType.HasValue)
                {
                    dbOperator.AddParameter("@iBunkType", (int)condition.BunkType);
                }
                if (condition.VoyageType.HasValue)
                {
                    dbOperator.AddParameter("@iVoyageType", (byte)condition.VoyageType);
                }
                if (condition.FlightBeginDate.HasValue)
                {
                    dbOperator.AddParameter("@iFlightBeginDate", condition.FlightBeginDate.Value.Date);
                }
                if (condition.FlightEndDate.HasValue)
                {
                    dbOperator.AddParameter("@iFlightEndDate", condition.FlightEndDate.Value.Date);
                }
                if (condition.Status.HasValue)
                {
                    dbOperator.AddParameter("@iStatus", condition.Status);
                }
                if (pagination != null)
                {
                    dbOperator.AddParameter("@iPageSize", pagination.PageSize);
                    dbOperator.AddParameter("@iPageIndex", pagination.PageIndex);
                }
                System.Data.Common.DbParameter totalCount = dbOperator.AddParameter("@oTotalCount");
                totalCount.DbType    = System.Data.DbType.Int32;
                totalCount.Direction = System.Data.ParameterDirection.Output;
                using (System.Data.Common.DbDataReader reader = dbOperator.ExecuteReader("dbo.P_QueryBunks", System.Data.CommandType.StoredProcedure))
                {
                    Guid?previousId = null;
                    Bunk bunk       = null;
                    while (reader.Read())
                    {
                        var currentId = reader.GetGuid(1);
                        if (bunk == null || previousId.Value != currentId)
                        {
                            bunk = null;
                        }
                        var bunkType = (BunkType)reader.GetInt32(0);
                        switch (bunkType)
                        {
                        case BunkType.Economic:
                            bunk = loadEconomicBunk(bunk, reader);
                            break;

                        case BunkType.FirstOrBusiness:
                            bunk = loadFirstBusinessBunk(bunk, reader);
                            break;

                        case BunkType.Promotion:
                            bunk = loadPromotionBunk(bunk, reader);
                            break;

                        case BunkType.Production:
                            bunk = loadProductionBunk(bunk, reader);
                            break;

                        case BunkType.Transfer:
                            bunk = loadTransferBunk(bunk, reader);
                            break;

                        case BunkType.Free:
                            bunk = loadFreeBunk(bunk, reader);
                            break;

                        case BunkType.Team:
                            bunk = loadTeamBunk(bunk, reader);
                            break;
                        }
                        bunk.VoyageType        = (VoyageTypeValue)reader.GetByte(19);
                        bunk.TravelType        = (TravelTypeValue)reader.GetByte(20);
                        bunk.PassengerType     = (PassengerTypeValue)reader.GetByte(21);
                        bunk.RefundRegulation  = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                        bunk.ChangeRegulation  = reader.IsDBNull(16) ? string.Empty : reader.GetString(16);
                        bunk.EndorseRegulation = reader.IsDBNull(17) ? string.Empty : reader.GetString(17);
                        bunk.Remarks           = reader.IsDBNull(18) ? string.Empty : reader.GetString(18);
                        if (!previousId.HasValue || previousId.Value != currentId)
                        {
                            result.Add(bunk);
                            previousId = currentId;
                        }
                    }
                }
                if (pagination.GetRowCount)
                {
                    pagination.RowCount = (int)totalCount.Value;
                }
            }
            return(result);
        }
 /// <summary>Gets the value of the specified column as an instance of type T.</summary>
 /// <typeparam name="T">The type of element to return.</typeparam>
 /// <param name="reader">The reader.</param>
 /// <param name="ordinal">The zero-based column ordinal.</param>
 /// <returns>This method returns default values for null database column values.</returns>
 public static T GetSafeValue <T>(this DbDataReader reader, int ordinal)
 {
     return(!reader.IsDBNull(ordinal) ? (T)reader.GetValue(ordinal) : default(T));
 }