private SqlString GetSqlStringWithLimitsIfNeeded(QueryWriter queryWriter) { Parameter skipParameter = null; Parameter takeParameter = null; if (queryWriter.SkipParameter != null) { queryWriter.SkipParameter.ExpectedType = NHibernateUtil.Int32; queryWriter.SkipParameter.IsSkipParameter(); skipParameter = Parameter.Placeholder; skipParameter.BackTrack = queryWriter.SkipParameter.GetIdsForBackTrack(sessionFactory).First(); } if (queryWriter.TakeParameter != null) { queryWriter.TakeParameter.ExpectedType = NHibernateUtil.Int32; queryWriter.TakeParameter.IsTakeParameterWithSkipParameter(queryWriter.SkipParameter); takeParameter = Parameter.Placeholder; takeParameter.BackTrack = queryWriter.TakeParameter.GetIdsForBackTrack(sessionFactory).First(); } // We allow the user to specify either constants or parameters for their limits. // The dialect can move the given parameters where he need, what it can't do is generates new parameters, losing the BackTrack. var dialect = sessionFactory.Dialect; return(dialect.GetLimitString(queryWriter.ToSqlString(), queryWriter.Skip.HasValue ? (int?)dialect.GetOffsetValue(queryWriter.Skip.Value) : null, queryWriter.Take.HasValue ? (int?)dialect.GetLimitValue(queryWriter.Skip ?? 0, queryWriter.Take.Value) : null, skipParameter, takeParameter)); }
private void EndQuery() { QueryWriter queryWriter = ((QueryWriter)writer); SqlString sqlString = queryWriter.ToSqlString(); if (queryWriter.Take.HasValue || queryWriter.Skip.HasValue) { sqlString = sessionFactory.Dialect.GetLimitString(sqlString, queryWriter.Skip ?? 0, queryWriter.Take ?? int.MaxValue); } writer = outputStack[0]; outputStack.RemoveAt(0); Out(sqlString); }
private SqlString GetSqlStringWithLimitsIfNeeded(QueryWriter queryWriter) { Parameter skipParameter = null; Parameter takeParameter = null; if(queryWriter.SkipParameter != null) { queryWriter.SkipParameter.ExpectedType = NHibernateUtil.Int32; skipParameter = Parameter.Placeholder; skipParameter.BackTrack = queryWriter.SkipParameter.GetIdsForBackTrack(sessionFactory).First(); } if (queryWriter.TakeParameter != null) { queryWriter.TakeParameter.ExpectedType = NHibernateUtil.Int32; takeParameter = Parameter.Placeholder; takeParameter.BackTrack = queryWriter.TakeParameter.GetIdsForBackTrack(sessionFactory).First(); } // We allow the user to specify either constants or parameters for their limits. // The dialect can move the given parameters where he need, what it can't do is generates new parameters, losing the BackTrack. var dialect = sessionFactory.Dialect; return dialect.GetLimitString(queryWriter.ToSqlString(), queryWriter.Skip.HasValue ? (int?) dialect.GetOffsetValue(queryWriter.Skip.Value) : null, queryWriter.Take.HasValue ? (int?) dialect.GetLimitValue(queryWriter.Skip ?? 0, queryWriter.Take.Value) : null, skipParameter, takeParameter); }