本文整理汇总了C#中NHibernate.SqlCommand.SqlString.Compact方法的典型用法代码示例。如果您正苦于以下问题:C# SqlString.Compact方法的具体用法?C# SqlString.Compact怎么用?C# SqlString.Compact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.SqlCommand.SqlString
的用法示例。
在下文中一共展示了SqlString.Compact方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompactWithNoParams
public void CompactWithNoParams()
{
SqlString sql = new SqlString( new string[] { "", "select", " from table" } );
SqlString compacted = sql.Compact();
Assert.AreEqual( 1, compacted.SqlParts.Length );
Assert.AreEqual( "select from table", compacted.ToString() );
}
示例2: CompactWithNoString
public void CompactWithNoString()
{
Parameter p1 = new Parameter( "p1" );
Parameter p2 = new Parameter( "p2" );
SqlString sql = new SqlString( new object[] {p1, p2} );
SqlString compacted = sql.Compact();
Assert.AreEqual( 2, compacted.SqlParts.Length );
Assert.AreEqual( ":p1:p2", compacted.ToString() );
}
示例3: ExpandDynamicFilterParameters
protected SqlString ExpandDynamicFilterParameters(SqlString sqlString, ICollection<IParameterSpecification> parameterSpecs, ISessionImplementor session)
{
var enabledFilters = session.EnabledFilters;
if (enabledFilters.Count == 0 || sqlString.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
{
return sqlString;
}
Dialect.Dialect dialect = session.Factory.Dialect;
string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;
var originSql = sqlString.Compact();
var result = new SqlStringBuilder();
foreach (var sqlPart in originSql.Parts)
{
var parameter = sqlPart as Parameter;
if (parameter != null)
{
result.Add(parameter);
continue;
}
var sqlFragment = sqlPart.ToString();
var tokens = new StringTokenizer(sqlFragment, symbols, true);
foreach (string token in tokens)
{
if (token.StartsWith(ParserHelper.HqlVariablePrefix))
{
string filterParameterName = token.Substring(1);
string[] parts = StringHelper.ParseFilterParameterName(filterParameterName);
string filterName = parts[0];
string parameterName = parts[1];
var filter = (FilterImpl)enabledFilters[filterName];
object value = filter.GetParameter(parameterName);
IType type = filter.FilterDefinition.GetParameterType(parameterName);
int parameterColumnSpan = type.GetColumnSpan(session.Factory);
var collectionValue = value as ICollection;
int? collectionSpan = null;
// Add query chunk
string typeBindFragment = string.Join(", ", Enumerable.Repeat("?", parameterColumnSpan).ToArray());
string bindFragment;
if (collectionValue != null && !type.ReturnedClass.IsArray)
{
collectionSpan = collectionValue.Count;
bindFragment = string.Join(", ", Enumerable.Repeat(typeBindFragment, collectionValue.Count).ToArray());
}
else
{
bindFragment = typeBindFragment;
}
// dynamic-filter parameter tracking
var filterParameterFragment = SqlString.Parse(bindFragment);
var dynamicFilterParameterSpecification = new DynamicFilterParameterSpecification(filterName, parameterName, type, collectionSpan);
var parameters = filterParameterFragment.GetParameters().ToArray();
var sqlParameterPos = 0;
var paramTrackers = dynamicFilterParameterSpecification.GetIdsForBackTrack(session.Factory);
foreach (var paramTracker in paramTrackers)
{
parameters[sqlParameterPos++].BackTrack = paramTracker;
}
parameterSpecs.Add(dynamicFilterParameterSpecification);
result.Add(filterParameterFragment);
}
else
{
result.Add(token);
}
}
}
return result.ToSqlString().Compact();
}
示例4: GetLimitString
/// <summary>
/// Add a <c>LIMIT (TOP)</c> clause to the given SQL <c>SELECT</c>
/// </summary>
/// <param name="querySqlString">A Query in the form of a SqlString.</param>
/// <param name="limit">Maximum number of rows to be returned by the query</param>
/// <param name="offset">Offset of the first row to process in the result set</param>
/// <returns>A new SqlString that contains the <c>LIMIT</c> clause.</returns>
public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
{
if (offset > 0)
{
throw new NotSupportedException("SQL Server does not support an offset" );
}
/*
* "SELECT TOP limit rest-of-sql-statement"
*/
querySqlString = querySqlString.Compact();
SqlStringBuilder pagingBuilder = new SqlStringBuilder();
bool topAdded = false;
foreach( object sqlPart in querySqlString.SqlParts )
{
if (!topAdded)
{
string sqlPartString = sqlPart as string;
if( sqlPartString != null )
{
string sqlFragment = sqlPartString.TrimStart();
int insertIndex = GetAfterSelectInsertPoint(sqlFragment);
if( insertIndex > 0 )
{
string newFragment = sqlFragment.Insert(insertIndex, " top " + limit.ToString());
pagingBuilder.Add(newFragment);
topAdded = true;
continue;
}
}
}
pagingBuilder.AddObject(sqlPart);
}
return pagingBuilder.ToSqlString();
}