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 TSectionMs getSectionByCd(string companyCd, string secCd) { TSectionMs section = null; ISession ss = holder.CreateSession(typeof(TSectionMsDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { ScalarQuery <TSectionMs> q = new ScalarQuery <TSectionMs>(typeof(TSectionMs), @" from TSectionMs where Id.ICompanyCd=:ICompanyCd and Id.ISectionCd=:ISectionCd "); q.SetParameter("ICompanyCd", companyCd); q.SetParameter("ISectionCd", secCd); section = q.Execute(); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } return(section); }
//public TRateMs getTRateMs(string facCd) //{ // TRateMs rateMs = null; // return rateMs; //} #region Sample public TFactoryMs getFactoryByCd(string facCd) { TFactoryMs factory = null; ISession ss = holder.CreateSession(typeof(TFactoryMsDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { //result = (IList<MFunctioncatalog>)FindAll(typeof(MFunctioncatalog)); ScalarQuery <TFactoryMs> q = new ScalarQuery <TFactoryMs>(typeof(TFactoryMs), @" from TFactoryMs where IFacCd=:IFacCd"); q.SetParameter("IFacCd", facCd); factory = q.Execute(); //FindByPrimaryKey找不到数据的时候是抛出ActiveRecordException,不太好处理 //termms = (TTermMs)FindByPrimaryKey(typeof(TTermMs), userid); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); } return(factory); }
public int placeIdByURL(string url) { String sql = "SELECT s.id FROM Place AS s WHERE s.CustomUrl = '" + url + "'"; ScalarQuery <int> q = new ScalarQuery <int>(typeof(place), sql); int id = q.Execute(); return(id); }
public static uint GetGuildId(uint charId) { var sql = string.Format("SELECT {0} FROM {1} WHERE {2} = {3} LIMIT 1", DatabaseUtil.Dialect.QuoteForColumnName("GuildId"), DatabaseUtil.Dialect.QuoteForTableName(typeof(CharacterRecord).Name), DatabaseUtil.Dialect.QuoteForColumnName("Guid"), charId); var query = new ScalarQuery <int>(typeof(CharacterRecord), QueryLanguage.Sql, sql); return((uint)query.Execute()); }
public static uint GetIdByName(string name) { var sql = string.Format("SELECT {0} FROM {1} WHERE {2} = {3} LIMIT 1", DatabaseUtil.Dialect.QuoteForColumnName("EntityLowId"), DatabaseUtil.Dialect.QuoteForTableName(typeof(CharacterRecord).Name), DatabaseUtil.Dialect.QuoteForColumnName("Name"), DatabaseUtil.ToSqlValueString(name)); var query = new ScalarQuery <long>(typeof(CharacterRecord), QueryLanguage.Sql, sql); return((uint)query.Execute()); }
private void Init() { ScalarQuery <object> scalarQuery = new ScalarQuery <object>(this.m_type, string.Format("SELECT max(r.{0}) FROM {1} r", (object)this.m_idMember, (object)this.m_table)); object obj; try { obj = scalarQuery.Execute(); } catch (Exception ex) { NHIdGenerator.OnError(ex); obj = scalarQuery.Execute(); } this.m_highestId = obj != null ? (long)Convert.ChangeType(obj, typeof(long)) : 0L; if (this.m_highestId >= this.m_minId) { return; } this.m_highestId = this.m_minId; }
/// <summary> /// Returns all value mail that was sent to the Character with the given Id to their original sender /// </summary> public static void ReturnValueMailFor(uint charId) { var sql = string.Format("UPDATE {0} SET {1} = {2}, {3} = 0 WHERE {4} = {5} AND ({6} > 0 OR {7} > 0 OR {8} > 0)", DatabaseUtil.Dialect.QuoteForTableName(typeof(MailMessage).Name), DatabaseUtil.Dialect.QuoteForColumnName("ReceiverId"), DatabaseUtil.Dialect.QuoteForColumnName("SenderId"), DatabaseUtil.Dialect.QuoteForColumnName("CashOnDelivery"), DatabaseUtil.Dialect.QuoteForColumnName("SenderId"), charId, DatabaseUtil.Dialect.QuoteForColumnName("CashOnDelivery"), DatabaseUtil.Dialect.QuoteForColumnName("IncludedMoney"), DatabaseUtil.Dialect.QuoteForColumnName("IncludedItemCount")); var query = new ScalarQuery <long>(typeof(CharacterRecord), QueryLanguage.Sql, sql); var result = query.Execute(); }
public void IncompatibleGenericTypesThrowMeaningfulErrorsOnDirectCall() { int result; var query = new ScalarQuery <int>(typeof(Post), validQuery); try { result = query.Execute(); } catch (Exception ex) { Assert.IsInstanceOf(typeof(NHibernate.QueryException), ex); Assert.IsTrue(ex.Message.Contains("Int32")); Assert.IsTrue(ex.Message.Contains("Int64")); } }
public MLoginUser GetLoginUserInfo(string userid, string password) { MLoginUser result = null; ISession ss = holder.CreateSession(typeof(MLoginUserDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { //result = (IList<MFunctioncatalog>)FindAll(typeof(MFunctioncatalog)); ScalarQuery <MLoginUser> q = new ScalarQuery <MLoginUser>(typeof(MLoginUser), @" from MLoginUser where Userid=:userid and Password=:password"); q.SetParameter("userid", userid); q.SetParameter("password", password); result = q.Execute(); // string query = @" // select LANGID,CATALOGID,CATALOGNAME from M_FUNCTIONCATALOG // where // LANGID = :key"; // result = ss.CreateSQLQuery(query) // .AddEntity(typeof(MFunctioncatalog)) // .SetParameter("key", langid) // .List<MFunctioncatalog>(); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } return(result); }
public TTradeMs getTradeByCd(string companyCd, string dlCd) { TTradeMs tradems = null; ISession ss = holder.CreateSession(typeof(TTradeMsDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { //result = (IList<MFunctioncatalog>)FindAll(typeof(MFunctioncatalog)); StringBuilder sb = new StringBuilder(); sb.AppendLine("from TTradeMs where Id.ICompanyCd=:ICompanyCd"); sb.AppendLine(" and Id.IDlCd=:IDlCd"); ScalarQuery <TTradeMs> q = new ScalarQuery <TTradeMs>(typeof(TTradeMs), sb.ToString()); q.SetParameter("ICompanyCd", companyCd); q.SetParameter("IDlCd", dlCd); tradems = q.Execute(); //FindByPrimaryKey找不到数据的时候是抛出ActiveRecordException,不太好处理 //termms = (TTermMs)FindByPrimaryKey(typeof(TTermMs), userid); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } return(tradems); }
public TCompanyConditionMs getCompanyCondition(string companyCd) { TCompanyConditionMs companyconditionms = null; ISession ss = holder.CreateSession(typeof(TPersonMsDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { //result = (IList<MFunctioncatalog>)FindAll(typeof(MFunctioncatalog)); ScalarQuery <TCompanyConditionMs> q = new ScalarQuery <TCompanyConditionMs>(typeof(TCompanyConditionMs), @" from TCompanyConditionMs where ICompanyCd=:ICompanyCd"); q.SetParameter("ICompanyCd", companyCd); companyconditionms = q.Execute(); //FindByPrimaryKey找不到数据的时候是抛出ActiveRecordException,不太好处理 //termms = (TTermMs)FindByPrimaryKey(typeof(TTermMs), userid); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } return(companyconditionms); }
/// <summary> /// 根据ClsCd取得DetailList /// </summary> /// <param name="langId"></param> /// <param name="clsCd"></param> /// <returns></returns> public IList <CClsDetailNoAR> GetClsDetailList(string langId, string clsCd) { IList <CClsDetailNoAR> result = new List <CClsDetailNoAR>(); ISession ss = holder.CreateSession(typeof(CClsDetailNoARDaoOracleImp)); ITransaction tran = ss.BeginTransaction(); try { //IList<TClsMs> clsmslist = new List<TClsMs>(); TClsMs clsms = null; //get role by userid ScalarQuery <TClsMs> queryclsms = new ScalarQuery <TClsMs>(typeof(TClsMs), @" from TClsMs where IClsCd=:clsCd"); queryclsms.SetParameter("clsCd", clsCd); clsms = queryclsms.Execute(); if (clsms == null) { throw new ApplicationException(MessageUtils.GetMessage("E0001")); } StringBuilder sb = new StringBuilder(); //select f.catalogid,f.functionid,f.functionimage,f.functionindex,f.functionname,f.functionpath,f.langid,c.catalogimage,c.catalogname from (M_FUNCTION f inner join (select functionid from m_role_function //where roleid=1 group by functionid) r on (f.functionid=r.functionid)) left join //m_functioncatalog c on (f.catalogid=c.catalogid and f.langid=c.langid) //where f.langid='zh-CN' //order by f.catalogid,f.functionindex if ("1".Equals(clsms.IClsCls)) { sb.Append(" select d.i_cls_cd as iClsCd,"); sb.Append(" d.i_language_cd as iLanguageCd,"); sb.Append(" d.i_cls_detail_cd as iClsDetailCd,"); sb.Append(" d.i_cls_detail_desc as iClsDetailDesc,"); sb.Append(" d.i_inq_item as iInqItem,"); sb.Append(" '' as iClsNameDesc"); sb.Append(" from t_cls_detail_ms d"); sb.Append(" where d.i_cls_cd=:clsCd"); sb.Append(" and d.i_language_cd=:langId"); } else if ("2".Equals(clsms.IClsCls)) { sb.Append(" select d.i_cls_cd as iClsCd ,"); sb.Append(" d.i_language_cd as iLanguageCd ,"); sb.Append(" d.i_name_cd as iClsDetailCd,"); sb.Append(" d.i_name_desc as iClsDetailDesc,"); sb.Append(" d.i_inq_item as iInqItem,"); sb.Append(" d.i_name_kana as iClsNameDesc"); sb.Append(" from t_desc_ms d"); sb.Append(" where d.i_cls_cd=:clsCd"); sb.Append(" and d.i_language_cd=:langId"); } ISQLQuery querycatalogfunction = ss.CreateSQLQuery(sb.ToString()); querycatalogfunction.AddScalar("iClsCd", NHibernateUtil.String); querycatalogfunction.AddScalar("iLanguageCd", NHibernateUtil.String); querycatalogfunction.AddScalar("iClsDetailCd", NHibernateUtil.String); querycatalogfunction.AddScalar("iClsDetailDesc", NHibernateUtil.String); querycatalogfunction.AddScalar("iInqItem", NHibernateUtil.String); querycatalogfunction.AddScalar("iClsNameDesc", NHibernateUtil.String); querycatalogfunction.SetParameter("langId", langId); querycatalogfunction.SetParameter("clsCd", clsms.IClsCd); result = querycatalogfunction.SetResultTransformer(Transformers.AliasToBean <CClsDetailNoAR>()).List <CClsDetailNoAR>(); tran.Commit(); } catch (Castle.ActiveRecord.Framework.ActiveRecordException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } catch (DbException ex) { tran.Rollback(); throw new ApplicationException(ex.Message, ex); } finally { tran.Dispose(); holder.ReleaseSession(ss); } return(result); }
public void InvalidGenericQueryWithDirectCall() { var query = new ScalarQuery <int>(typeof(Post), invalidQuery); Assert.AreEqual(default(int), query.Execute()); }
public void ValidGenericQueryWithDirectCall() { var query = new ScalarQuery <long>(typeof(Post), validQuery); Assert.AreEqual(1, query.Execute()); }