public static BooruPostList DoSearch(string Pattern, ServerBooru Booru) { string[] parts = SplitString(Pattern); if (parts.Length < 1) { using (DataTable postTable = Booru.DB.ExecuteTable(SQLStatements.GetPosts)) return(BooruPostList.FromTable(postTable)); } //Get all posts //Perform all the special patterns //return the post ids List <string> tagSearchQueries = new List <string>(); var specialPatterns = new List <SpecialPattern>(); //Extract all the needed information for (int i = 0; i < parts.Length; i++) { string part = parts[i]; bool negate = ExtractNegate(ref part); if (!IsSpecialPattern(part)) { DataRow tagRow = Booru.DB.ExecuteRow(SQLStatements.GetTagByTagString, part); BooruTag tag = BooruTag.FromRow(tagRow); if (tag != null) { tagSearchQueries.Add(string.Format("id {0} (SELECT post FROM post_tags WHERE tag = {1})", negate ? "NOT IN" : "IN", tag.ID)); } } else { SpecialPattern sPattern = ExtractSpecialPattern(part); sPattern.Negate = negate; specialPatterns.Add(sPattern); } } string tagSearchQuery = tagSearchQueries.Count > 0 ? "SELECT * FROM posts WHERE " + string.Join(" AND ", tagSearchQueries) + " ORDER BY creationdate DESC" : SQLStatements.GetPosts; using (DataTable postTable = Booru.DB.ExecuteTable(tagSearchQuery)) { BooruPostList postList = new BooruPostList(); foreach (BooruPost post in BooruPostList.FromTable(postTable)) { if (DoSpecialPatternChecks(specialPatterns, post)) { postList.Add(post); } } return(postList); } }
public BooruTag GetTag(BooruUser User, ulong TagID) { DataRow tagRow = _DB.ExecuteRow(SQLStatements.GetTagByID, TagID); BooruTag tag = BooruTag.FromRow(tagRow); if (tag != null) { return(tag); } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } }
private void CheckAndAddPostTags(ref BooruPost newPost) { for (int i = newPost.Tags.Count - 1; !(i < 0); i--) { newPost.Tags[i].Tag = newPost.Tags[i].Tag.Trim().ToLower(); if (string.IsNullOrWhiteSpace(newPost.Tags[i].Tag)) { newPost.Tags.RemoveAt(i); } } foreach (BooruTag tag in newPost.Tags) { DataRow existingTagRow = _DB.ExecuteRow(SQLStatements.GetTagByTagString, tag.Tag); BooruTag existingTag = BooruTag.FromRow(existingTagRow); if (existingTag == null) { bool taggedAliasAdded = false; DataRow existingAliasRow = _DB.ExecuteRow(SQLStatements.GetAliasByString, tag.Tag); if (existingAliasRow != null) { ulong tagID = Convert.ToUInt64(existingAliasRow["tagid"]); if (_DB.ExecuteScalar <int>(SQLStatements.GetTagCountByID, tagID) > 0) { _DB.ExecuteNonQuery(SQLStatements.InsertPostTag, newPost.ID, tagID); taggedAliasAdded = true; } } if (!taggedAliasAdded) { _DB.ExecuteNonQuery(SQLStatements.InsertTag, tag.Tag, BooruInfo.DefaultTagType); ulong newTagID = _DB.GetLastInsertedID(); _DB.ExecuteNonQuery(SQLStatements.InsertPostTag, newPost.ID, newTagID); } } else { _DB.ExecuteNonQuery(SQLStatements.InsertPostTag, newPost.ID, existingTag.ID); } } }