Query that return a single result
Inheritance: Castle.ActiveRecord.Queries.HqlBasedQuery
Exemple #1
0
		private void Init()
		{
			var str = string.Format("SELECT max(r.{0}) FROM {1} r", m_idMember, m_table);
			var query = new ScalarQuery<object>(m_type, str);
			object highestId;
			try
			{
				highestId = query.Execute();
			}
			catch (Exception e)
			{
				OnError(e);
				highestId = query.Execute();
			}

			if (highestId == null)
			{
				m_highestId = 0;
			}
			else
			{
				m_highestId = (long)Convert.ChangeType(highestId, typeof(long));
			}

			if (m_highestId < m_minId)
			{
				m_highestId = m_minId;
			}
		}
 public void IncompatibleGenericTypesThrowMeaningfulErrorsOnMediatorCall()
 {
     int result;
     var query = new ScalarQuery<int>(typeof(Post), validQuery);
     try
     {
         result = ActiveRecordMediator<Post>.ExecuteQuery2(query);
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOf(typeof(NHibernate.QueryException), ex);
         Assert.IsTrue(ex.Message.Contains("Int32"));
         Assert.IsTrue(ex.Message.Contains("Int64"));
     }
 }
 public int NumberOfChildrens()
 {
     ScalarQuery q = new ScalarQuery(typeof(Category),
                                     "select count(*) from Category where Parent = ?", Id);
     return (int) ExecuteQuery(q);
 }
Exemple #4
0
		private static uint GetNextHighestPlayerId()
		{
			ScalarQuery idQuery = new ScalarQuery(typeof(CharacterRecord), QueryLanguage.Hql,
												  "select max(chr.EntityId) from CharacterRecord chr");
			object highestId = ActiveRecordMediator.ExecuteQuery(idQuery);

			return (highestId == null ? 0 : (highestId as CharacterRecord).EntityLowId + 1);
		}
		public void InvalidGenericQueryWithDirectCall()
		{
			var query = new ScalarQuery<int>(typeof(Post), invalidQuery);
			Assert.AreEqual(default(int), query.Execute());
		}
		public void InvalidResultGeneric()
		{
			ScalarQuery<int> query = new ScalarQuery<int>(typeof(Post), invalidQuery);
			int result = ActiveRecordMediator<Post>.ExecuteQuery2(query);
			Assert.AreEqual(default(int), result);
		}
		public void InvalidResultWithNonGenericQueryYieldsNull()
		{
			ScalarQuery query = new ScalarQuery(typeof(Post), invalidQuery);
			Assert.IsNull(ActiveRecordMediator<Post>.ExecuteQuery(query));
		}
		public void ValidGenericQueryWithDirectCall()
		{
			var query = new ScalarQuery<long>(typeof(Post), validQuery);
			Assert.AreEqual(1, query.Execute());
		}
		public void ValidResultGeneric()
		{
			ScalarQuery<long> query = new ScalarQuery<long>(typeof(Post), validQuery);
			long result = ActiveRecordMediator<Post>.ExecuteQuery2(query);
			Assert.AreEqual(1, result);
		}
		public void ValidResult()
		{
			ScalarQuery query = new ScalarQuery(typeof(Post), validQuery);
			long result = (long) ActiveRecordMediator<Post>.ExecuteQuery(query);
			Assert.AreEqual(1, result);
		}
        public static int FindLastIdMsg(int chat)
        {
            ScalarQuery q = new ScalarQuery(typeof(ChatMessage), @"
            SELECT MAX(C.Id)
            FROM ChatMessage C
            WHERE C.Chat = ?", chat);

// return (int) ExecuteQuery(q);
            object val = ExecuteQuery(q);
            if (val != null)
                return (int)val;
            else
                return 0;
        }