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


C# Term.SqlCondition方法代码示例

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


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

示例1: Query

	public Photo [] Query (Term searchexpression, string extra_condition, DateRange range, RollSet importidrange, RatingRange ratingrange)
	{
		bool hide = (extra_condition == null);

		// The SQL query that we want to construct is:
		//
		// SELECT photos.id
		//        photos.time
		//        photos.uri,
		//        photos.description,
		//	  photos.roll_id,
		//        photos.default_version_id
		//        photos.rating
		//                  FROM photos, photo_tags
		//		    WHERE photos.time >= time1 AND photos.time <= time2
		//				AND photos.rating >= rat1 AND photos.rating <= rat2
		//				AND photos.id NOT IN (select photo_id FROM photo_tags WHERE tag_id = HIDDEN)
		//				AND photos.id IN (select photo_id FROM photo_tags where tag_id IN (tag1, tag2..)
		//				AND extra_condition_string
		//                  GROUP BY photos.id
		
		StringBuilder query_builder = new StringBuilder ();
		ArrayList where_clauses = new ArrayList ();
		query_builder.Append ("SELECT id, " 			+
					     "time, "			+
					     "uri, "			+
					     "description, "		+
				      	     "roll_id, "   		+
					     "default_version_id, "	+
					     "rating, "			+
					     "md5_sum "			+
				      "FROM photos ");
		
		if (range != null) {
			where_clauses.Add (String.Format ("time >= {0} AND time <= {1}",
							  DbUtils.UnixTimeFromDateTime (range.Start), 
							  DbUtils.UnixTimeFromDateTime (range.End)));

		}

		if (ratingrange != null) {
			where_clauses.Add (ratingrange.SqlClause ());
		}

		if (importidrange != null) {
			where_clauses.Add (importidrange.SqlClause ());
		}		
		
		if (hide && Core.Database.Tags.Hidden != null) {
			where_clauses.Add (String.Format ("id NOT IN (SELECT photo_id FROM photo_tags WHERE tag_id = {0})", 
							  FSpot.Core.Database.Tags.Hidden.Id));
		}
		
		if (searchexpression != null) {
			where_clauses.Add (searchexpression.SqlCondition ());
		}

		if (extra_condition != null && extra_condition.Trim () != String.Empty) {
			where_clauses.Add (extra_condition);
		}
		
		if (where_clauses.Count > 0) {
			query_builder.Append (" WHERE ");
			query_builder.Append (String.Join (" AND ", ((String []) where_clauses.ToArray (typeof(String)))));
		}
		query_builder.Append (" ORDER BY time");
		return Query (query_builder.ToString ());
	}
开发者ID:guadalinex-archive,项目名称:guadalinex-v6,代码行数:68,代码来源:PhotoStore.cs

示例2: Query

	public Photo [] Query (Term searchexpression, string extra_condition, DateRange range, RollSet importidrange)
	{
		bool hide = (extra_condition == null);

		// The SQL query that we want to construct is:
		//
		// SELECT photos.id
		//        photos.time
		//        photos.directory_path,
		//        photos.name,
		//        photos.description,
		//	  photos.roll_id,
		//        photos.default_version_id
		//                  FROM photos, photo_tags
		//                  WHERE photos.id = photo_tags.photo_id
		// 		                AND (photo_tags.tag_id = cat1tag1
		//			            OR photo_tags.tag_id = cat1tag2 ) 
		// 		                AND (photo_tags.tag_id = cat2tag1
		//			            OR photo_tags.tag_id = cat2tag2 )
		//			  	AND (photos.roll_id = roll_id1
		//			   	    OR photos.roll_id = roll_id2 ...)
		//                  GROUP BY photos.id
		
		StringBuilder query_builder = new StringBuilder ();
		query_builder.Append ("SELECT photos.id, " 			+
					     "photos.time, "			+
					     "photos.directory_path, " 		+
					     "photos.name, "			+
					     "photos.description, "		+
				      	     "photos.roll_id, "   		+
					     "photos.default_version_id "	+
				      "FROM photos ");
		
		bool where_statement_added = false;

		if (range != null) {
			query_builder.Append (String.Format ("WHERE photos.time >= {0} AND photos.time <= {1} ",
							     DbUtils.UnixTimeFromDateTime (range.Start), 
							     DbUtils.UnixTimeFromDateTime (range.End)));
			where_statement_added = true;
		}

		if (importidrange != null) {
			query_builder.Append (AddLastImportFilter (importidrange, where_statement_added));
			where_statement_added = true;
		}		
		
		if (hide && Core.Database.Tags.Hidden != null) {
			query_builder.Append (String.Format ("{0} photos.id NOT IN (SELECT photo_id FROM photo_tags WHERE tag_id = {1}) ", 
							     where_statement_added ? " AND " : " WHERE ", Core.Database.Tags.Hidden.Id));
			where_statement_added = true;
		}
		
		if (searchexpression != null) {
			query_builder.Append (String.Format ("{0} {1}", 
							     where_statement_added ? " AND " : " WHERE ",
							     searchexpression.SqlCondition()));
			where_statement_added = true;
		}

		if (extra_condition != null && extra_condition.Length != 0) {
			query_builder.Append (String.Format ("{0} {1} ",
							     where_statement_added ? " AND " : " WHERE ",
							     extra_condition));
			where_statement_added = true;
		}
		
		query_builder.Append ("ORDER BY photos.time");
		Console.WriteLine("Query: {0}", query_builder.ToString());
		return Query (query_builder.ToString ());
	}
开发者ID:AminBonyadUni,项目名称:facedetect-f-spot,代码行数:71,代码来源:PhotoStore.cs


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