本文整理汇总了C#中NHibernate.SqlCommand.SqlStringBuilder.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# SqlStringBuilder.AddObject方法的具体用法?C# SqlStringBuilder.AddObject怎么用?C# SqlStringBuilder.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.SqlCommand.SqlStringBuilder
的用法示例。
在下文中一共展示了SqlStringBuilder.AddObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
if (args.Count < 2)
{
throw new QueryException("coalesce() requires at least two arguments");
}
var sb = new SqlStringBuilder();
sb.Add("Switch");
sb.Add("(");
for (int i = 0; i < args.Count; i++)
{
if (i>0)
{
sb.Add(",");
}
var arg = args[i];
sb.Add("not IsNull(");
sb.AddObject(arg);
sb.Add(")");
sb.Add(",");
sb.AddObject(arg);
}
sb.Add(",");
sb.Add("1=1");
sb.Add(",");
sb.AddObject(args[args.Count - 1]);
sb.Add(")");
return sb.ToSqlString();
}
示例2: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
//ANSI-SQL92 definition
//<general set function> ::=
//<set function type> <leftparen> [ <setquantifier> ] <value expression> <right paren>
//<set function type> : := AVG | MAX | MIN | SUM | COUNT
//<setquantifier> ::= DISTINCT | ALL
if (args.Count < 1 || args.Count > 2)
{
throw new QueryException(string.Format("Aggregate {0}(): Not enough parameters (attended from 1 to 2).", name));
}
else if ("*".Equals(args[args.Count - 1]) && !acceptAsterisk)
{
throw new QueryException(string.Format("Aggregate {0}(): invalid argument '*'.", name));
}
SqlStringBuilder cmd = new SqlStringBuilder();
cmd.Add(name)
.Add("(");
if (args.Count > 1)
{
object firstArg = args[0];
if (!StringHelper.EqualsCaseInsensitive("distinct", firstArg.ToString()) &&
!StringHelper.EqualsCaseInsensitive("all", firstArg.ToString()))
{
throw new QueryException(string.Format("Aggregate {0}(): token unknow {1}.", name, firstArg));
}
cmd.AddObject(firstArg).Add(" ");
}
cmd.AddObject(args[args.Count - 1])
.Add(")");
return cmd.ToSqlString();
}
示例3: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
// TODO: QueryException if args.Count<2 (not present in H3.2)
bool threeArgs = args.Count > 2;
object pattern = args[0];
object orgString = args[1];
object start = threeArgs ? args[2] : null;
SqlStringBuilder buf = new SqlStringBuilder();
buf.Add("charindex(")
.AddObject(pattern)
.Add(", ");
if (threeArgs)
{
buf.Add("right(");
}
buf.AddObject(orgString);
if (threeArgs)
{
buf.Add(", char_length(")
.AddObject(orgString)
.Add(")-(")
.AddObject(start)
.Add("-1))");
}
buf.Add(")");
return buf.ToSqlString();
}
示例4: Render
public override SqlString Render(IList args, ISessionFactoryImplementor factory)
{
bool hasArgs = args.Count > 0;
SqlStringBuilder buf = new SqlStringBuilder();
buf.Add(name);
if (hasArgs)
{
buf.Add("(");
for (int i = 0; i < args.Count; i++)
{
object arg = args[i];
if (arg is Parameter || arg is SqlString)
{
buf.AddObject(arg);
}
else
{
buf.Add(arg.ToString());
}
if (i < (args.Count - 1)) buf.Add(", ");
}
buf.Add(")");
}
return buf.ToSqlString();
}
示例5: Render
/// <summary>
/// Render the function call as SQL.
/// </summary>
/// <param name="args">List of arguments</param>
/// <param name="factory"></param>
/// <returns>SQL fragment for the function.</returns>
public override SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder builder = new SqlStringBuilder();
builder.AddObject(args[0]);
builder.Add(".");
builder.Add(name);
return builder.ToSqlString();
}
示例6: Render
/// <summary>
/// Render the function call as SQL.
/// </summary>
/// <param name="args">List of arguments</param>
/// <param name="factory"></param>
/// <returns>SQL fragment for the function.</returns>
public override SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder builder = new SqlStringBuilder();
builder.AddObject(args[0]);
builder.Add(".");
builder.Add(name);
builder.Add("(");
for (int i = 1; i < args.Count; i++)
{
builder.AddObject(args[i]);
if (i < (args.Count - 1))
{
builder.Add(", ");
}
}
builder.Add(")");
return builder.ToSqlString();
}
示例7: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder buf = new SqlStringBuilder().Add(begin);
for (int i = 0; i < args.Count; i++)
{
buf.AddObject(args[i]);
if (i < args.Count - 1) buf.Add(sep);
}
return buf.Add(end).ToSqlString();
}
示例8: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
if (args.Count != 2)
{
throw new QueryException("NullIf() requires two arguments");
}
var sb = new SqlStringBuilder();
sb.Add("iif");
sb.Add("(");
sb.AddObject(args[0]);
sb.Add("=");
sb.AddObject(args[1]);
sb.Add(",");
sb.Add("NULL");
sb.Add(",");
sb.AddObject(args[0]);
sb.Add(")");
return sb.ToSqlString();
}
示例9: Render
/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <param name="factory"></param>
/// <returns></returns>
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder buffer = new SqlStringBuilder();
buffer.Add(this.nameFunction);
buffer.Add(begin);
for (int i = 0; i < args.Count; i++)
{
buffer.AddObject(args[i]);
if (i < args.Count - 1)
buffer.Add(sep);
}
buffer.Add(end);
return buffer.ToSqlString();
}
示例10: ToSqlStringFragment
/// <summary></summary>
public SqlString ToSqlStringFragment()
{
SqlStringBuilder buf = new SqlStringBuilder(lhs.Length * 4);
string prefix = tableAlias + StringHelper.Dot;
for (int i = 0; i < lhs.Length; i++)
{
buf.Add(prefix)
.Add(lhs[i] + op);
buf.AddObject(rhs[i]);
if (i < lhs.Length - 1)
{
buf.Add(" and ");
}
}
return buf.ToSqlString();
}
示例11: Join
public static SqlString Join(SqlString separator, IEnumerable objects)
{
SqlStringBuilder buf = new SqlStringBuilder();
bool first = true;
foreach (object obj in objects)
{
if (!first)
{
buf.Add(separator);
}
first = false;
buf.AddObject(obj);
}
return buf.ToSqlString();
}
示例12: Render
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
// DONE: QueryException if args.Count<2 (not present in H3.2)
if (args.Count < 2)
{
throw new QueryException("position(): Not enough parameters (attended from 2 to 3).");
}
bool threeArgs = args.Count > 2;
object pattern = args[0];
object orgString = args[1];
object start = threeArgs ? args[2] : null;
SqlStringBuilder buf = new SqlStringBuilder();
if (threeArgs)
{
buf.Add("(");
}
buf.Add("position(")
.AddObject(pattern)
.Add(" in ");
if (threeArgs)
{
buf.Add("substring(");
}
buf.AddObject(orgString);
if (threeArgs)
{
buf.Add(", ")
.AddObject(start)
.Add(")");
}
buf.Add(")");
if (threeArgs)
{
buf.Add("+")
.AddObject(start)
.Add("-1)");
}
return buf.ToSqlString();
}
示例13: Render
/// <summary>
/// Applies the template to passed in arguments.
/// </summary>
/// <param name="args">args function arguments</param>
/// <param name="factory">generated SQL function call</param>
/// <returns></returns>
public SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder buf = new SqlStringBuilder();
foreach (TemplateChunk tc in chunks)
{
if (tc.ArgumentIndex != InvalidArgumentIndex)
{
int adjustedIndex = tc.ArgumentIndex - 1; // Arg indices are one-based
object arg = adjustedIndex < args.Count ? args[adjustedIndex] : null;
// TODO: if (arg == null) QueryException is better ?
if (arg != null)
{
if (arg is Parameter || arg is SqlString)
{
buf.AddObject(arg);
}
else
{
buf.Add(arg.ToString());
}
}
}
else
{
buf.Add(tc.Text);
}
}
return buf.ToSqlString();
}
示例14: Insert
public SqlString Insert(int index, string text)
{
if (index < 0)
{
throw new ArgumentException("index should be greater than or equal to 0", "index");
}
SqlStringBuilder result = new SqlStringBuilder();
int offset = 0;
bool inserted = false;
foreach (object part in sqlParts)
{
if (inserted)
{
result.AddObject(part);
continue;
}
int nextOffset = offset + LengthOfPart(part);
if (nextOffset < index)
{
result.AddObject(part);
offset = nextOffset;
}
else if (nextOffset == index)
{
result.AddObject(part);
result.Add(text);
inserted = true;
}
else if (offset == index)
{
result.Add(text);
result.AddObject(part);
inserted = true;
}
else if (index > offset && index < nextOffset)
{
string partString = (string) part;
result.Add(partString.Insert(index - offset, text));
inserted = true;
}
else
{
throw new ArgumentException("index too large", "index");
}
}
return result.ToSqlString();
}
示例15: GetLimitString
private SqlString GetLimitString(SqlString querySqlString, object offset, object limit)
{
SqlStringBuilder pagingBuilder = new SqlStringBuilder();
pagingBuilder.Add(querySqlString);
if (limit != null)
{
pagingBuilder.Add(" limit ");
pagingBuilder.AddObject(limit);
}
if (offset != null)
{
pagingBuilder.Add(" offset ");
pagingBuilder.AddObject(offset);
}
return pagingBuilder.ToSqlString();
}