本文整理汇总了C#中NHibernate.SqlCommand.SqlString.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlString.ToString方法的具体用法?C# SqlString.ToString怎么用?C# SqlString.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.SqlCommand.SqlString
的用法示例。
在下文中一共展示了SqlString.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
public static ADOException Convert(ISQLExceptionConverter converter, Exception sqle, string message, SqlString sql,
object[] parameterValues, IDictionary<string, TypedValue> namedParameters)
{
sql = TryGetActualSqlQuery(sqle, sql);
string extendMessage = ExtendMessage(message, sql.ToString(), parameterValues, namedParameters);
ADOExceptionReporter.LogExceptions(sqle, extendMessage);
return new ADOException(extendMessage, sqle, sql.ToString());
}
示例2: Replace
public void Replace()
{
SqlString sql =
new SqlString(
new object[] {"select ", "from table ", "where a = ", Parameter.Placeholder, " and c = ", Parameter.Placeholder});
SqlString replacedSql = sql.Replace("table", "replacedTable");
Assert.AreEqual(sql.ToString().Replace("table", "replacedTable"), replacedSql.ToString());
replacedSql = sql.Replace("not found", "not in here");
Assert.AreEqual(sql.ToString().Replace("not found", "not in here"), replacedSql.ToString(), "replace no found string");
replacedSql = sql.Replace("le", "LE");
Assert.AreEqual(sql.ToString().Replace("le", "LE"), replacedSql.ToString(), "multi-match replace");
}
示例3: Convert
/// <summary>
/// Converts the given SQLException into Exception hierarchy, as well as performing
/// appropriate logging.
/// </summary>
/// <param name="converter">The converter to use.</param>
/// <param name="sqlException">The exception to convert.</param>
/// <param name="message">An optional error message.</param>
/// <param name="sql">The SQL executed.</param>
/// <returns> The converted <see cref="ADOException"/>.</returns>
public static Exception Convert(ISQLExceptionConverter converter, Exception sqlException, string message,
SqlString sql)
{
return Convert(converter,
new AdoExceptionContextInfo
{SqlException = sqlException, Message = message, Sql = sql != null ? sql.ToString() : null});
}
示例4: CompareSqlStrings
protected void CompareSqlStrings(SqlString actualSqlString, string expectedString, int expectedNumOfParameters)
{
Parameter[] actualParameters = new Parameter[expectedNumOfParameters];
int numOfParameters = 0;
GetParameters(actualSqlString, ref actualParameters, ref numOfParameters);
Assert.AreEqual(expectedString, actualSqlString.ToString(), "SqlString.ToString()");
Assert.AreEqual(expectedNumOfParameters, numOfParameters, "Num of Parameters");
}
示例5: Generate
public IDbCommand Generate(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
{
IDbCommand cmd = factory.ConnectionProvider.Driver.GenerateCommand(type, sqlString, parameterTypes);
LogOpenPreparedCommand();
if (log.IsDebugEnabled)
{
log.Debug("Building an IDbCommand object for the SqlString: " + sqlString.ToString());
}
commandsToClose.Add(cmd);
return cmd;
}
示例6: Generate
/// <summary>
///
/// </summary>
/// <param name="sqlString"></param>
/// <returns></returns>
public IDbCommand Generate( SqlString sqlString )
{
// need to build the IDbCommand from the sqlString bec
IDbCommand cmd = factory.ConnectionProvider.Driver.GenerateCommand( factory.Dialect, sqlString );
LogOpenPreparedCommand();
if( log.IsDebugEnabled )
{
log.Debug( "Building an IDbCommand object for the SqlString: " + sqlString.ToString() );
}
commandsToClose.Add( cmd );
return cmd;
}
示例7: AddLeftOuterJoinCondition
/// <summary>
/// This method is a bit of a hack, and assumes
/// that the column on the "right" side of the
/// join appears on the "left" side of the
/// operator, which is extremely weird if this
/// was a normal join condition, but is natural
/// for a filter.
/// </summary>
private void AddLeftOuterJoinCondition(SqlString on)
{
StringBuilder buf = new StringBuilder(on.ToString());
for (int i = 0; i < buf.Length; i++)
{
char character = buf[i];
bool isInsertPoint = Operators.Contains(character) ||
(character == ' ' && buf.Length > i + 3 && "is ".Equals(buf.ToString(i + 1, 3)));
if (isInsertPoint)
{
buf.Insert(i, "(+)");
i += 3;
}
}
AddCondition(SqlString.Parse(buf.ToString()));
}
示例8: DetermineNumberOfPreceedingParametersForEachQuery
private void DetermineNumberOfPreceedingParametersForEachQuery(SqlString text)
{
int currentParameterIndex = 0;
int currentQueryParameterCount = 0;
int currentQueryIndex = 0;
hasReturnParameter = false;
foundReturnParameter = false;
CallableParser.Detail callableDetail = CallableParser.Parse(text.ToString());
if (callableDetail.IsCallable && callableDetail.HasReturn)
hasReturnParameter = true;
foreach (object part in text.Parts)
{
if (part.ToString().Equals(multipleQueriesSeparator))
{
queryIndexToNumberOfPreceedingParameters[currentQueryIndex] = currentParameterIndex - currentQueryParameterCount;
currentQueryParameterCount = 0;
currentQueryIndex++;
continue;
}
Parameter parameter = part as Parameter;
if (parameter != null)
{
if (hasReturnParameter && !foundReturnParameter)
{
foundReturnParameter = true;
}
else
{
parameterIndexToQueryIndex[currentParameterIndex] = currentQueryIndex;
}
currentQueryParameterCount++;
currentParameterIndex++;
}
}
}
示例9: ProcessFilters
public void ProcessFilters(SqlString sql, ISessionImplementor session)
{
filteredParameterValues = new List<object>();
filteredParameterTypes = new List<IType>();
filteredParameterLocations = new List<int>();
if (session.EnabledFilters.Count == 0 || sql.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
{
processedSQL = sql.Copy();
return;
}
Dialect.Dialect dialect = session.Factory.Dialect;
string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;
var result = new SqlStringBuilder();
int originalParameterIndex = 0; // keep track of the positional parameter
int newParameterIndex = 0;
_adjustedParameterLocations = new Dictionary<int, int>();
foreach (var part in sql.Parts)
{
if (part is Parameter)
{
result.AddParameter();
// (?) can be a position parameter or a named parameter (already substituted by (?),
// but only the positional parameters are available at this point. Adding them in the
// order of appearance is best that can be done at this point of time, but if they
// are mixed with named parameters, the order is still wrong, because values and
// types for the named parameters are added later to the end of the list.
// see test fixture NH-1098
_adjustedParameterLocations[originalParameterIndex] = newParameterIndex;
originalParameterIndex++;
newParameterIndex++;
continue;
}
var tokenizer = new StringTokenizer((string) part, symbols, true);
foreach (var token in tokenizer)
{
if (token.StartsWith(ParserHelper.HqlVariablePrefix))
{
string filterParameterName = token.Substring(1);
object value = session.GetFilterParameterValue(filterParameterName);
IType type = session.GetFilterParameterType(filterParameterName);
// If the value is not a value of the type but a collection of values...
if (value != null && !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882
typeof (ICollection).IsAssignableFrom(value.GetType()))
{
var coll = (ICollection) value;
int i = 0;
foreach (var elementValue in coll)
{
i++;
int span = type.GetColumnSpan(session.Factory);
if (span > 0)
{
result.AddParameter();
filteredParameterTypes.Add(type);
filteredParameterValues.Add(elementValue);
filteredParameterLocations.Add(newParameterIndex);
newParameterIndex++;
if (i < coll.Count)
{
result.Add(", ");
}
}
}
}
else
{
int span = type.GetColumnSpan(session.Factory);
if (span > 0)
{
result.AddParameter();
filteredParameterTypes.Add(type);
filteredParameterValues.Add(value);
filteredParameterLocations.Add(newParameterIndex);
newParameterIndex++;
}
}
}
else
{
result.Add(token);
}
}
}
processedSQL = result.ToSqlString();
}
示例10: TrimAllParam
public void TrimAllParam()
{
Parameter p1 = Parameter.Placeholder;
Parameter p2 = Parameter.Placeholder;
SqlString sql = new SqlString(new object[] { p1, p2 });
sql = sql.Trim();
Assert.AreEqual("??", sql.ToString());
}
示例11: TrimBeginStringEndParam
public void TrimBeginStringEndParam()
{
Parameter p1 = Parameter.Placeholder;
SqlString sql = new SqlString(new object[] { " extra space ", p1 });
sql = sql.Trim();
Assert.AreEqual("extra space ?", sql.ToString());
}
示例12: TrimBeginParamEndString
public void TrimBeginParamEndString()
{
Parameter p1 = Parameter.Placeholder;
SqlString sql = new SqlString(new object[] { p1, " extra space " });
sql = sql.Trim();
Assert.AreEqual("? extra space", sql.ToString());
}
示例13: TrimAllString
public void TrimAllString()
{
SqlString sql = new SqlString(new string[] { " extra space", " in the middle", " at the end " });
sql = sql.Trim();
Assert.AreEqual("extra space in the middle at the end", sql.ToString());
}
示例14: OnPrepareStatement
public override SqlString OnPrepareStatement(SqlString sql)
{
Trace.WriteLine(sql.ToString());
return base.OnPrepareStatement(sql);
}
示例15: CompareSqlStrings
/// <summary>
/// This compares the text output of the SqlString to what was expected. It does
/// not take into account the parameters.
/// </summary>
protected void CompareSqlStrings(SqlString actualSqlString, string expectedString)
{
Assert.AreEqual(expectedString, actualSqlString.ToString(), "SqlString.ToString()");
}