当前位置: 首页>>代码示例>>C#>>正文


C# SqlStringBuilder.AddParameter方法代码示例

本文整理汇总了C#中NHibernate.SqlCommand.SqlStringBuilder.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# SqlStringBuilder.AddParameter方法的具体用法?C# SqlStringBuilder.AddParameter怎么用?C# SqlStringBuilder.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.SqlCommand.SqlStringBuilder的用法示例。


在下文中一共展示了SqlStringBuilder.AddParameter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToSqlString

		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
		{
			//TODO: add default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();
			string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);

			if (columnNames.Length != 1)
			{
				throw new HibernateException("insensitive like may only be used with single-column properties");
			}

			if (criteriaQuery.Factory.Dialect is PostgreSQLDialect)
			{
				sqlBuilder.Add(columnNames[0]);
				sqlBuilder.Add(" ilike ");
			}
			else
			{
				sqlBuilder.Add(criteriaQuery.Factory.Dialect.LowercaseFunction)
					.Add("(")
					.Add(columnNames[0])
					.Add(")")
					.Add(" like ");
			}

			sqlBuilder.AddParameter();

			return sqlBuilder.ToSqlString();
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:29,代码来源:InsensitiveLikeExpression.cs

示例2: RenderText

		public override SqlString RenderText(ISessionFactoryImplementor sessionFactory)
		{
			int count;
			if (ExpectedType != null && (count = ExpectedType.GetColumnSpan(sessionFactory)) > 1)
			{
				SqlStringBuilder buffer = new SqlStringBuilder();
				buffer.Add("(");
				buffer.AddParameter();
				for (int i = 1; i < count; i++)
				{
					buffer.Add(",");
					buffer.AddParameter();
				}
				buffer.Add(")");
				return buffer.ToSqlString();
			}
			else
			{
				return new SqlString(Parameter.Placeholder);
			}
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:21,代码来源:ParameterNode.cs

示例3: AddValueOrProjection

		private void AddValueOrProjection(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters, SqlStringBuilder result)
		{
			if (_projection == null)
			{
				result.AddParameter();
			}
			else
			{
				SqlString sql = _projection.ToSqlString(criteria, GetHashCode(),criteriaQuery, enabledFilters);
				result.Add(StringHelper.RemoveAsAliasesFromSql(sql));
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:12,代码来源:IdentifierEqExpression.cs

示例4: ToSqlString

		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
		{
			IType type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName);
			if (type.IsCollectionType)
			{
				throw new QueryException("Cannot use collections with InExpression");
			}

			if (_values.Length == 0)
			{
				// "something in ()" is always false
				return new SqlString("1=0");
			}

			//TODO: add default capacity
			SqlStringBuilder result = new SqlStringBuilder();
			string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);

			// Generate SqlString of the form:
			// columnName1 in (values) and columnName2 in (values) and ...

			for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
			{
				string columnName = columnNames[columnIndex];

				if (columnIndex > 0)
				{
					result.Add(" and ");
				}

				result
					.Add(columnName)
					.Add(" in (");

				for (int i = 0; i < _values.Length; i++)
				{
					if (i > 0)
					{
						result.Add(StringHelper.CommaSpace);
					}
					result.AddParameter();
				}

				result.Add(")");
			}

			return result.ToSqlString();
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:48,代码来源:InExpression.cs

示例5: ToSqlString

		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
		                                      IDictionary<string, IFilter> enabledFilters)
		{
			if (projection == null)
				AssertPropertyIsNotCollection(criteriaQuery, criteria);

			if (_values.Length == 0)
			{
				// "something in ()" is always false
				return new SqlString("1=0");
			}

			//TODO: add default capacity
			SqlStringBuilder result = new SqlStringBuilder();
			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(_propertyName, projection, criteriaQuery, criteria, enabledFilters);
			
			// Generate SqlString of the form:
			// columnName1 in (values) and columnName2 in (values) and ...

			for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
			{
				SqlString columnName = columnNames[columnIndex];

				if (columnIndex > 0)
				{
					result.Add(" and ");
				}

				result
					.Add(columnName)
					.Add(" in (");

				for (int i = 0; i < _values.Length; i++)
				{
					if (i > 0)
					{
						result.Add(StringHelper.CommaSpace);
					}
					result.AddParameter();
				}

				result.Add(")");
			}

			return result.ToSqlString();
		}
开发者ID:pallmall,项目名称:WCell,代码行数:47,代码来源:InExpression.cs

示例6: WithParameterTest

		public void WithParameterTest()
		{
			using (ISession session = factory.OpenSession())
			{
				SqlStringBuilder builder = new SqlStringBuilder();

				string expectedSql = "sql_alias.address = ?";

				builder.Add("{alias}.address = ");
				builder.AddParameter();

				ICriterion sqlExpression = Expression.Sql(builder.ToSqlString(), "some address", NHibernateUtil.String);

				CreateObjects(typeof(Simple), session);
				SqlString sqlString = sqlExpression.ToSqlString(criteria, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());

				CompareSqlStrings(sqlString, expectedSql, 1);
			}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:19,代码来源:SQLExpressionFixture.cs

示例7: Parse

		/// <summary>
		/// Parse SQL in <paramref name="sql" /> and create a SqlString representing it.
		/// </summary>
		/// <remarks>
		/// Parameter marks in single quotes will be correctly skipped, but otherwise the
		/// lexer is very simple and will not parse double quotes or escape sequences
		/// correctly, for example.
		/// </remarks>
		public static SqlString Parse(string sql)
		{
			SqlStringBuilder result = new SqlStringBuilder();

			bool inQuote = false;

			StringBuilder stringPart = new StringBuilder();

			foreach (char ch in sql)
			{
				switch (ch)
				{
					case '?':
						if (inQuote)
						{
							stringPart.Append(ch);
						}
						else
						{
							if (stringPart.Length > 0)
							{
								result.Add(stringPart.ToString());
								stringPart.Length = 0;
							}
							result.AddParameter();
						}
						break;

					case '\'':
						inQuote = !inQuote;
						stringPart.Append(ch);
						break;

					default:
						stringPart.Append(ch);
						break;
				}
			}

			if (stringPart.Length > 0)
			{
				result.Add(stringPart.ToString());
			}

			return result.ToSqlString();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:54,代码来源:SqlString.cs

示例8: ApplyLocksToSql

		public override SqlString ApplyLocksToSql(SqlString sql, IDictionary<string, LockMode> aliasedLockModes, IDictionary<string, string[]> keyColumnNames)
		{
			bool doWork = false;

			foreach (KeyValuePair<string, LockMode> de in aliasedLockModes)
			{
				if (NeedsLockHint(de.Value))
				{
					doWork = true;
					break;
				}
			}

			if (!doWork)
			{
				return sql;
			}

			// Regex matching any alias out of those given. Aliases should contain
			// no dangerous characters (they are identifiers) so they are not escaped.
			string aliasesPattern = StringHelper.Join("|", aliasedLockModes.Keys);

			// Match < alias >, < alias,>, or < alias$>, the intent is to capture alias names
			// in various kinds of "FROM table1 alias1, table2 alias2".
			Regex matchRegex = new Regex(" (" + aliasesPattern + ")([, ]|$)");

			SqlStringBuilder result = new SqlStringBuilder();
			MatchEvaluator evaluator = new LockHintAppender(this, aliasedLockModes).ReplaceMatch;

			foreach (object part in sql.Parts)
			{
				if (part == Parameter.Placeholder)
				{
					result.AddParameter();
					continue;
				}

				result.Add(matchRegex.Replace((string)part, evaluator));
			}

			return result.ToSqlString();
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:42,代码来源:MsSql2000Dialect.cs

示例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();
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:96,代码来源:QueryParameters.cs

示例10: AddParameters

        private void AddParameters(String propertyName, SqlStringBuilder sql, ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            bool hasProperty = false;
            bool hasParameter = false;

            sql.Add(FunctionName).Add("(");

            if (ParameterValues != null && ParameterValues.Length > 0)
            {
                for (int i = 0; i < ParameterValues.Length; i++)
                {
                    if (PropertyPosition == i)
                    {
                        if (i > 0) sql.Add(", ");
                        sql.Add(criteriaQuery.GetColumn(criteria, propertyName)).Add(", ");
                        hasProperty = true;
                    }
                    else if (i > 0)
                    {
                        sql.Add(", ");
                    }

                    sql.AddParameter();
                    hasParameter = true;
                }
            }
            if (!hasProperty)
            {
                if (hasParameter) sql.Add(", ");
                sql.Add(criteriaQuery.GetColumn(criteria, propertyName));
            }

            sql.Add(")");
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:34,代码来源:SqlFunctionExpression.cs

示例11: ToSqlString

        public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
            IDictionary<string, IFilter> enabledFilters)
        {
            var sql = new SqlStringBuilder();
            string leftPropertyName = null;
            string rightPropertyName = null;

            if (InnerCriterion is SimpleExpression)
            {
                leftPropertyName = ((SimpleExpression)InnerCriterion).PropertyName;
            }
            else if (InnerCriterion is PropertyExpression)
            {
                System.Type type = typeof(PropertyExpression);
                leftPropertyName =
                    type.GetField("_lhsPropertyName", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(InnerCriterion) as
                    String;
                rightPropertyName =
                    type.GetField("_rhsPropertyName", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(InnerCriterion) as
                    String;
            }

            AddParameters(leftPropertyName, sql, criteria, criteriaQuery);
            sql.Add(" ").Add(Op).Add(" ");

            if (RightFunction != null)
            {
                RightFunction.AddParameters(rightPropertyName, sql, criteria, criteriaQuery);
            }
            else
            {
                sql.AddParameter();
            }

            return sql.ToSqlString();
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:36,代码来源:SqlFunctionExpression.cs


注:本文中的NHibernate.SqlCommand.SqlStringBuilder.AddParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。