예제 #1
0
		public SqlConstraint(IQuery query)
		{
			this.query = (SqlQuery) query;
		}
예제 #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();
		}
예제 #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);
		}
예제 #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;
		}