public SqlConstraint(IQuery query)
		{
			this.query = (SqlQuery) query;
		}
Example #2
0
		protected virtual string GetDeleteSql(SqlQuery query)
		{
			StringBuilder buf = new StringBuilder("delete from ");
			if (schema != null && schema.Length > 0)
				buf.Append("[").Append(schema).Append("].");
			buf.Append("[").Append(name).Append("]");
			if (query != null)
				buf.Append(" ").Append(query.GetSql(this));
			buf.Append(";");
			return buf.ToString();
		}
Example #3
0
		protected virtual string GetSelectSql(SqlQuery query)
		{
			if (selectSQL == null)
			{
				StringBuilder buf = new StringBuilder("select ");
				bool comma = false;
				foreach (SqlColumn column in columns)
				{
					if (comma)
						buf.Append(",");
					else
						comma = true;
					buf.Append("[").Append(column.Name).Append("]");
				}
				buf.Append(" from ");
				if (schema != null && schema.Length > 0)
					buf.Append("[").Append(schema).Append("].");
				buf.Append("[").Append(name).Append("]");
				selectSQL = buf.ToString();
			}
			if (query != null)
			{
				StringBuilder buf = new StringBuilder(selectSQL);
				buf.Append(" ").Append(query.GetSql(this));
				buf.Append(";");
				return buf.ToString();
			}
			else
				return string.Format("{0};", selectSQL);
		}
Example #4
0
		public virtual object Find(IDb session, object key)
		{
			ErrorIfSPResult();
			SqlColumn pk = null;
			object result = null;
			foreach (SqlColumn c in columns)
			{
				if (c.IsPK)
				{
					pk = c;
					break;
				}
			}
			if (pk != null)
			{
				SqlQuery q = new SqlQuery();
				q.Constrain(pk.Alias).Equal(key);
				IList list = new ArrayList(1);
				Select(session, q, list);
				if (list.Count > 0)
					result = list[0];
			}
			return result;
		}