本文整理汇总了C#中NHibernate.SqlCommand.SqlString.LastIndexOfCaseInsensitive方法的典型用法代码示例。如果您正苦于以下问题:C# SqlString.LastIndexOfCaseInsensitive方法的具体用法?C# SqlString.LastIndexOfCaseInsensitive怎么用?C# SqlString.LastIndexOfCaseInsensitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.SqlCommand.SqlString
的用法示例。
在下文中一共展示了SqlString.LastIndexOfCaseInsensitive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveAsAliasesFromSql
public static SqlString RemoveAsAliasesFromSql(SqlString sql)
{
return sql.Substring(0, sql.LastIndexOfCaseInsensitive(" as "));
}
示例2: GetPrevTableInsertPoint
private static int GetPrevTableInsertPoint(SqlString text)
{
int i = text.LastIndexOfCaseInsensitive("from");
int j = text.LastIndexOfCaseInsensitive(",");
if (i == -1 && j == -1)
{
return -1;
}
if (j > i)
{
return j + 1;
}
return i + 5;
}
示例3: GetLimitString
/// <summary>
/// Add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c>
/// </summary>
/// <param name="querySqlString">The <see cref="SqlString"/> to base the limit query off.</param>
/// <param name="offset">Offset of the first row to be returned by the query (zero-based)</param>
/// <param name="limit">Maximum number of rows to be returned by the query</param>
/// <param name="offsetParameterIndex">Optionally, the Offset parameter index</param>
/// <param name="limitParameterIndex">Optionally, the Limit parameter index</param>
/// <returns>A new <see cref="SqlString"/> with the <c>LIMIT</c> clause applied.</returns>
/// <remarks>
/// Note that we need to explicitly specify the columns, because we need to be able to use them in a paged subselect [NH-1155]
/// </remarks>
public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit, int? offsetParameterIndex, int? limitParameterIndex)
{
SqlStringBuilder result = new SqlStringBuilder();
if (offset == 0)
{
int insertPoint = this.GetAfterSelectInsertPoint(querySqlString);
return result
.Add(querySqlString.Substring(0, insertPoint))
.Add(" TOP (")
.Add(limitParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(limitParameterIndex.Value))
.Add(")")
.Add(querySqlString.Substring(insertPoint))
.ToSqlString();
}
int fromIndex = GetFromIndex(querySqlString);
SqlString select = querySqlString.Substring(0, fromIndex);
List<SqlString> columnsOrAliases;
Dictionary<SqlString, SqlString> aliasToColumn;
ExtractColumnOrAliasNames(select, out columnsOrAliases, out aliasToColumn);
int orderIndex = querySqlString.LastIndexOfCaseInsensitive(" order by ");
SqlString fromAndWhere;
SqlString[] sortExpressions;
//don't use the order index if it is contained within a larger statement(assuming
//a statement with non matching parenthesis is part of a larger block)
if (orderIndex > 0 && HasMatchingParens(querySqlString.Substring(orderIndex).ToString()))
{
fromAndWhere = querySqlString.Substring(fromIndex, orderIndex - fromIndex).Trim();
SqlString orderBy = querySqlString.Substring(orderIndex).Trim();
sortExpressions = orderBy.Substring(9).Split(",");
}
else
{
fromAndWhere = querySqlString.Substring(fromIndex).Trim();
// Use dummy sort to avoid errors
sortExpressions = new[] {new SqlString("CURRENT_TIMESTAMP"),};
}
result
.Add("SELECT TOP (")
.Add(limitParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(limitParameterIndex.Value))
.Add(") ")
.Add(StringHelper.Join(", ", columnsOrAliases))
.Add(" FROM (")
.Add(select)
.Add(", ROW_NUMBER() OVER(ORDER BY ");
AppendSortExpressions(aliasToColumn, sortExpressions, result);
result
.Add(") as __hibernate_sort_row ")
.Add(fromAndWhere)
.Add(") as query WHERE query.__hibernate_sort_row > ")
.Add(offsetParameterIndex == null ? Parameter.Placeholder : Parameter.WithIndex(offsetParameterIndex.Value))
.Add(" ORDER BY query.__hibernate_sort_row");
return result.ToSqlString();
}
示例4: RemoveAsAliasesFromSql
public static SqlString RemoveAsAliasesFromSql(SqlString sql)
{
int index = sql.LastIndexOfCaseInsensitive(" as ");
if (index < 0) return sql;
return sql.Substring(0, index);
}