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


C# QueryBuilder.AndWhere方法代码示例

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


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

示例1: RenameCategory

        /// <summary>
        /// Renames a Category.
        /// </summary>
        /// <param name="category">The Category to rename.</param>
        /// <param name="newName">The new Name.</param>
        /// <returns>The correct CategoryInfo object.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="category"/> or <paramref name="newName"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="newName"/> is empty.</exception>
        public CategoryInfo RenameCategory(CategoryInfo category, string newName)
        {
            if(category == null) throw new ArgumentNullException("category");
            if(newName == null) throw new ArgumentNullException("newName");
            if(newName.Length == 0) throw new ArgumentException("New Name cannot be empty", "newName");

            string nspace = null;
            string name = null;
            NameTools.ExpandFullName(category.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.Update("Category", new string[] { "Name" }, new string[] { "NewName" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "OldName");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "NewName", newName));
            parameters.Add(new Parameter(ParameterType.String, "OldName", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            int rows = ExecuteNonQuery(command, false);

            if(rows > 0) {
                CategoryInfo result = GetCategory(transaction, NameTools.GetFullName(nspace, newName));
                CommitTransaction(transaction);
                return result;
            }
            else {
                RollbackTransaction(transaction);
                return null;
            }
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:48,代码来源:SqlPagesStorageProviderBase.cs

示例2: RetrievePageAttachment

        /// <summary>
        /// Retrieves a Page Attachment.
        /// </summary>
        /// <param name="pageInfo">The Page Info that owns the Attachment.</param>
        /// <param name="name">The name of the Attachment, for example "myfile.jpg".</param>
        /// <param name="destinationStream">A Stream object used as <b>destination</b> of a byte stream,
        /// i.e. the method writes to the Stream the file content.</param>
        /// <param name="countHit">A value indicating whether or not to count this retrieval in the statistics.</param>
        /// <returns><c>true</c> if the Attachment is retrieved, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="pageInfo"/>, <paramref name="name"/> or <paramref name="destinationStream"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty or if <paramref name="destinationStream"/> does not support writing,
        /// or if the page does not have attachments or if the attachment does not exist.</exception>
        public bool RetrievePageAttachment(PageInfo pageInfo, string name, System.IO.Stream destinationStream, bool countHit)
        {
            if(pageInfo == null) throw new ArgumentNullException("pageInfo");
            if(name == null) throw new ArgumentNullException("name");
            if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name");
            if(destinationStream == null) throw new ArgumentNullException("destinationStream");
            if(!destinationStream.CanWrite) throw new ArgumentException("Cannot write into Destination Stream", "destinationStream");

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            if(!AttachmentExists(transaction, pageInfo, name)) {
                RollbackTransaction(transaction);
                throw new ArgumentException("Attachment does not exist", "name");
            }

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Attachment", new string[] { "Size", "Data" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Page", WhereOperator.Equals, "Page");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));
            parameters.Add(new Parameter(ParameterType.String, "Page", pageInfo.FullName));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                bool done = false;

                if(reader.Read()) {
                    int read = ReadBinaryColumn(reader, "Data", destinationStream);
                    done = (long)read == (long)reader["Size"];
                }

                CloseReader(reader);

                if(!done) {
                    RollbackTransaction(transaction);
                    return false;
                }
            }
            else {
                RollbackTransaction(transaction);
                return false;
            }

            if(countHit) {
                // Update download count
                query = queryBuilder.UpdateIncrement("Attachment", "Downloads", 1);
                query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
                query = queryBuilder.AndWhere(query, "Page", WhereOperator.Equals, "Page");

                parameters = new List<Parameter>(2);
                parameters.Add(new Parameter(ParameterType.String, "Name", name));
                parameters.Add(new Parameter(ParameterType.String, "Page", pageInfo.FullName));

                command = builder.GetCommand(transaction, query, parameters);

                int rows = ExecuteNonQuery(command, false);
                if(rows != 1) {
                    RollbackTransaction(transaction);
                    return false;
                }
            }

            CommitTransaction(transaction);

            return true;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:86,代码来源:SqlFilesStorageProviderBase.cs

示例3: SetPageAttachmentRetrievalCount

        /// <summary>
        /// Sets the number of times a page attachment was retrieved.
        /// </summary>
        /// <param name="pageInfo">The page.</param>
        /// <param name="name">The name of the attachment.</param>
        /// <param name="count">The count to set.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="pageInfo"/> or <paramref name="name"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="count"/> is less than zero.</exception>
        public void SetPageAttachmentRetrievalCount(PageInfo pageInfo, string name, int count)
        {
            if(pageInfo == null) throw new ArgumentNullException("pageInfo");
            if(name == null) throw new ArgumentNullException("name");
            if(name.Length == 0) throw new ArgumentException("Name cannot be empty");
            if(count < 0) throw new ArgumentOutOfRangeException("Count must be greater than or equal to zero", "count");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.Update("Attachment", new string[] { "Downloads" }, new string[] { "Downloads" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Page", WhereOperator.Equals, "Page");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));
            parameters.Add(new Parameter(ParameterType.String, "Page", pageInfo.FullName));
            parameters.Add(new Parameter(ParameterType.Int32, "Downloads", count));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            ExecuteNonQuery(command);
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:32,代码来源:SqlFilesStorageProviderBase.cs

示例4: GetFileDetails

        /// <summary>
        /// Gets the details of a file.
        /// </summary>
        /// <param name="fullName">The full name of the file.</param>
        /// <returns>The details, or <c>null</c> if the file does not exist.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="fullName"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="fullName"/> is empty.</exception>
        public FileDetails GetFileDetails(string fullName)
        {
            if(fullName == null) throw new ArgumentNullException("fullName");
            if(fullName.Length == 0) throw new ArgumentException("Full Name cannot be empty", "fullName");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string directory, filename;
            SplitFileFullName(fullName, out directory, out filename);

            string query = queryBuilder.SelectFrom("File", new string[] { "Size", "Downloads", "LastModified" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Directory", WhereOperator.Equals, "Directory");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", filename));
            parameters.Add(new Parameter(ParameterType.String, "Directory", directory));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                FileDetails details = null;

                if(reader.Read()) {
                    details = new FileDetails((long)reader["Size"],
                        (DateTime)reader["LastModified"], (int)reader["Downloads"]);
                }

                CloseReader(command, reader);

                return details;
            }
            else return null;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:44,代码来源:SqlFilesStorageProviderBase.cs

示例5: RenameFile

        /// <summary>
        /// Renames or moves a File.
        /// </summary>
        /// <param name="oldFullName">The old full name of the File.</param>
        /// <param name="newFullName">The new full name of the File.</param>
        /// <returns><c>true</c> if the File is renamed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="oldFullName"/> or <paramref name="newFullName"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="oldFullName"/> or <paramref name="newFullName"/> are empty, or if the old file does not exist, or if the new file already exist.</exception>
        public bool RenameFile(string oldFullName, string newFullName)
        {
            if(oldFullName == null) throw new ArgumentNullException("oldFullName");
            if(oldFullName.Length == 0) throw new ArgumentException("Old Full Name cannot be empty", "oldFullName");
            if(newFullName == null) throw new ArgumentNullException("newFullName");
            if(newFullName.Length == 0) throw new ArgumentException("New Full Name cannot be empty", "newFullName");

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            if(!FileExists(transaction, oldFullName)) {
                RollbackTransaction(transaction);
                throw new ArgumentException("File does not exist", "oldFullName");
            }
            if(FileExists(transaction, newFullName)) {
                RollbackTransaction(transaction);
                throw new ArgumentException("File already exists", "newFullPath");
            }

            string oldDirectory, newDirectory, oldFilename, newFilename;
            SplitFileFullName(oldFullName, out oldDirectory, out oldFilename);
            SplitFileFullName(newFullName, out newDirectory, out newFilename);

            string query = queryBuilder.Update("File", new string[] { "Name" }, new string[] { "NewName" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "OldName");
            query = queryBuilder.AndWhere(query, "Directory", WhereOperator.Equals, "OldDirectory");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "NewName", newFilename));
            parameters.Add(new Parameter(ParameterType.String, "OldName", oldFilename));
            parameters.Add(new Parameter(ParameterType.String, "OldDirectory", oldDirectory));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            int rows = ExecuteNonQuery(command, false);
            if(rows == 1) CommitTransaction(transaction);
            else RollbackTransaction(transaction);

            return rows == 1;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:51,代码来源:SqlFilesStorageProviderBase.cs

示例6: GetNamespaces

        /// <summary>
        /// Gets all the sub-namespaces.
        /// </summary>
        /// <returns>The sub-namespaces, sorted by name.</returns>
        public NamespaceInfo[] GetNamespaces()
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            // select ... from Namespace left join Page on Namespace.DefaultPage = Page.Name where Namespace.Name <> '' and (Namespace.DefaultPage is null or Page.Namespace <> '')
            string query = queryBuilder.SelectFrom("Namespace", "Page", "DefaultPage", "Name", Join.LeftJoin, new string[] { "Name", "DefaultPage" }, new string[] { "CreationDateTime" });
            query = queryBuilder.Where(query, "Namespace", "Name", WhereOperator.NotEquals, "Empty1");
            query = queryBuilder.AndWhere(query, "Namespace", "DefaultPage", WhereOperator.IsNull, null, true, false);
            query = queryBuilder.OrWhere(query, "Page", "Namespace", WhereOperator.NotEquals, "Empty2", false, true);
            query = queryBuilder.OrderBy(query, new[] { "Namespace_Name" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Empty1", ""));
            parameters.Add(new Parameter(ParameterType.String, "Empty2", ""));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<NamespaceInfo> result = new List<NamespaceInfo>(10);

                while(reader.Read()) {
                    string realName = reader["Namespace_Name"] as string;
                    string page = GetNullableColumn<string>(reader, "Namespace_DefaultPage", null);
                    PageInfo defaultPage = string.IsNullOrEmpty(page) ? null :
                        new PageInfo(NameTools.GetFullName(realName, page), this, (DateTime)reader["Page_CreationDateTime"]);

                    // The query returns duplicate entries if the main page of two or more namespaces have the same name
                    if(result.Find(n => { return n.Name.Equals(realName); }) == null) {
                        result.Add(new NamespaceInfo(realName, this, defaultPage));
                    }
                }

                CloseReader(command, reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:45,代码来源:SqlPagesStorageProviderBase.cs

示例7: FileExists

        /// <summary>
        /// Determines whether a file exists.
        /// </summary>
        /// <param name="transaction">A database transaction.</param>
        /// <param name="fullName">The file full name, for example "/file.txt" or "/directory/file.txt".</param>
        /// <returns><c>true</c> if the file exists, <c>false</c> otherwise.</returns>
        private bool FileExists(DbTransaction transaction, string fullName)
        {
            string directory, file;
            SplitFileFullName(fullName, out directory, out file);

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectCountFrom("File");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Directory", WhereOperator.Equals, "Directory");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", file));
            parameters.Add(new Parameter(ParameterType.String, "Directory", directory));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            int count = ExecuteScalar<int>(command, -1, false);

            return count == 1;
        }
开发者ID:robhughadams,项目名称:screwturnwiki,代码行数:28,代码来源:SqlFilesStorageProviderBase.cs

示例8: GetMessages

        /// <summary>
        /// Gets the Page Messages.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="page">The Page.</param>
        /// <returns>The list of the <b>first-level</b> Messages, containing the replies properly nested, sorted by date/time.</returns>
        private Message[] GetMessages(DbConnection connection, PageInfo page)
        {
            if(GetPage(connection, page.FullName) == null) return null;

            // 1. Load all messages in memory in a dictionary id->message
            // 2. Build tree using ParentID

            string nspace, name;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Message", new string[] { "Id", "Parent", "Username", "Subject", "DateTime", "Body" });
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.OrderBy(query, new string[] { "DateTime", "Id" }, new Ordering[] { Ordering.Asc, Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                Dictionary<short, Message> allMessages = new Dictionary<short, Message>(50);
                List<short> ids = new List<short>(50);
                List<short?> parents = new List<short?>(50);

                while(reader.Read()) {
                    Message msg = new Message((short)reader["Id"], reader["Username"] as string, reader["Subject"] as string,
                        (DateTime)reader["DateTime"], reader["Body"] as string);

                    ids.Add((short)msg.ID);

                    // Import from V2: parent = -1, otherwise null
                    if(!IsDBNull(reader, "Parent")) {
                        short par = (short)reader["Parent"];
                        if(par >= 0) parents.Add(par);
                        else parents.Add(null);
                    }
                    else parents.Add(null);

                    allMessages.Add((short)msg.ID, msg);
                }

                CloseReader(reader);

                // Add messages to their parents and build the top-level messages list
                List<Message> result = new List<Message>(20);

                for(int i = 0; i < ids.Count; i++) {
                    short? currentParent = parents[i];
                    short currentId = ids[i];

                    if(currentParent.HasValue) {
                        List<Message> replies = new List<Message>(allMessages[currentParent.Value].Replies);
                        replies.Add(allMessages[currentId]);
                        allMessages[currentParent.Value].Replies = replies.ToArray();
                    }
                    else result.Add(allMessages[currentId]);
                }

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:76,代码来源:SqlPagesStorageProviderBase.cs

示例9: BulkStoreMessages

        /// <summary>
        /// Removes all messages for a page and stores the new messages.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="messages">The new messages to store.</param>
        /// <returns><c>true</c> if the messages are stored, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/> or <paramref name="messages"/> are <c>null</c>.</exception>
        public bool BulkStoreMessages(PageInfo page, Message[] messages)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(messages == null) throw new ArgumentNullException("messages");

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            if(GetPage(transaction, page.FullName) == null) {
                RollbackTransaction(transaction);
                return false;
            }

            foreach(Message msg in GetMessages(transaction, page)) {
                UnindexMessageTree(page, msg, transaction);
            }

            string nspace, name;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("Message");
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            ExecuteNonQuery(command, false);

            List<Message> allMessages;
            List<int> parents;

            UnTreeMessages(messages, out allMessages, out parents, -1);

            string finalQuery = "";
            int count = 1;
            string countString;
            parameters = new List<Parameter>(MaxStatementsInBatch * 8);

            int rowsDone = 0;

            for(int i = 0; i < allMessages.Count; i++) {
                // Execute the batch in smaller chunks

                Message msg = allMessages[i];
                int parent = parents[i];

                countString = count.ToString();

                query = queryBuilder.InsertInto("Message", new string[] { "Page", "Namespace", "Id", "Parent", "Username", "Subject", "DateTime", "Body" },
                    new string[] { "Page" + countString, "Namespace" + countString, "Id" + countString, "Parent" + countString, "Username" + countString, "Subject" + countString, "DateTime" + countString, "Body" + countString });

                parameters.Add(new Parameter(ParameterType.String, "Page" + countString, name));
                parameters.Add(new Parameter(ParameterType.String, "Namespace" + countString, nspace));
                parameters.Add(new Parameter(ParameterType.Int16, "Id" + countString, (short)msg.ID));
                if(parent != -1) parameters.Add(new Parameter(ParameterType.Int16, "Parent" + countString, parent));
                else parameters.Add(new Parameter(ParameterType.Int16, "Parent" + countString, DBNull.Value));
                parameters.Add(new Parameter(ParameterType.String, "Username" + countString, msg.Username));
                parameters.Add(new Parameter(ParameterType.String, "Subject" + countString, msg.Subject));
                parameters.Add(new Parameter(ParameterType.DateTime, "DateTime" + countString, msg.DateTime));
                parameters.Add(new Parameter(ParameterType.String, "Body" + countString, msg.Body));

                finalQuery = queryBuilder.AppendForBatch(finalQuery, query);

                count++;

                if(count == MaxStatementsInBatch) {
                    command = builder.GetCommand(transaction, finalQuery, parameters);

                    rowsDone += ExecuteNonQuery(command, false);

                    finalQuery = "";
                    count = 1;
                    parameters.Clear();
                }
            }

            if(finalQuery.Length > 0) {
                command = builder.GetCommand(transaction, finalQuery, parameters);

                rowsDone += ExecuteNonQuery(command, false);
            }

            if(rowsDone == allMessages.Count) {
                foreach(Message msg in messages) {
                    IndexMessageTree(page, msg, transaction);
//.........这里部分代码省略.........
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:101,代码来源:SqlPagesStorageProviderBase.cs

示例10: GetCategory

        /// <summary>
        /// Gets a category.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="fullName">The full name of the category.</param>
        /// <returns>The <see cref="T:CategoryInfo" />, or <c>null</c> if no category is found.</returns>
        private CategoryInfo GetCategory(DbConnection connection, string fullName)
        {
            string nspace = null;
            string name = null;
            NameTools.ExpandFullName(fullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("Category", "CategoryBinding", new string[] { "Name", "Namespace" }, new string[] { "Category", "Namespace" }, Join.LeftJoin,
                new string[] { "Name", "Namespace" }, new string[] { "Page" });
            query = queryBuilder.Where(query, "Category", "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "Category", "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.String, "Name", name));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                CategoryInfo result = null;
                List<string> pages = new List<string>(50);

                while(reader.Read()) {
                    if(result == null) result = new CategoryInfo(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["Category_Name"] as string), this);

                    if(!IsDBNull(reader, "CategoryBinding_Page")) {
                        pages.Add(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["CategoryBinding_Page"] as string));
                    }
                }

                CloseReader(reader);

                if(result != null) result.Pages = pages.ToArray();

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:49,代码来源:SqlPagesStorageProviderBase.cs

示例11: GetContent

        /// <summary>
        /// Gets the content of a specific revision of a page.
        /// </summary>
        /// <param name="transaction">A database transaction.</param>
        /// <param name="page">The page.</param>
        /// <param name="revision">The revision.</param>
        /// <returns>The content.</returns>
        private PageContent GetContent(DbTransaction transaction, PageInfo page, int revision)
        {
            // Internal version to work with GetContent, GetBackupContent, GetDraft

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string name, nspace;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            string query = queryBuilder.SelectFrom("PageContent", "PageKeyword", new string[] { "Page", "Namespace", "Revision" }, new string[] { "Page", "Namespace", "Revision" }, Join.LeftJoin,
                new string[] { "Title", "User", "LastModified", "Comment", "Content", "Description" }, new string[] { "Keyword" });
            query = queryBuilder.Where(query, "PageContent", "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "PageContent", "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "PageContent", "Revision", WhereOperator.Equals, "Revision");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.Int16, "Revision", (short)revision));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                PageContent result = null;

                string title = null, user = null, comment = null, content = null, description = null;
                DateTime dateTime = DateTime.MinValue;
                List<string> keywords = new List<string>(10);

                while(reader.Read()) {
                    if(title == null) {
                        title = reader["PageContent_Title"] as string;
                        user = reader["PageContent_User"] as string;
                        dateTime = (DateTime)reader["PageContent_LastModified"];
                        comment = GetNullableColumn<string>(reader, "PageContent_Comment", "");
                        content = reader["PageContent_Content"] as string;
                        description = GetNullableColumn<string>(reader, "PageContent_Description", null);
                    }

                    if(!IsDBNull(reader, "PageKeyword_Keyword")) {
                        keywords.Add(reader["PageKeyword_Keyword"] as string);
                    }
                }

                if(title != null) {
                    result = new PageContent(page, title, user, dateTime, comment, content, keywords.ToArray(), description);
                }

                CloseReader(reader);

                return result;
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:65,代码来源:SqlPagesStorageProviderBase.cs

示例12: GetBackups

        /// <summary>
        /// Gets the Backup/Revision numbers of a Page.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="page">The Page to get the Backups of.</param>
        /// <returns>The Backup/Revision numbers.</returns>
        private int[] GetBackups(DbConnection connection, PageInfo page)
        {
            if(GetPage(connection, page.FullName) == null) {
                return null;
            }

            string name, nspace;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectFrom("PageContent", new string[] { "Revision" });
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "Revision", WhereOperator.GreaterThanOrEqualTo, "Revision");
            query = queryBuilder.OrderBy(query, new[] { "Revision" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.Int16, "Revision", FirstRevision));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<int> result = new List<int>(100);

                while(reader.Read()) {
                    result.Add((short)reader["Revision"]);
                }

                CloseReader(reader);

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:47,代码来源:SqlPagesStorageProviderBase.cs

示例13: DeleteContent

        /// <summary>
        /// Deletes a revision of a page content.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="page">The page.</param>
        /// <param name="revision">The revision.</param>
        /// <returns><c>true</c> if the content ir deleted, <c>false</c> otherwise.</returns>
        private bool DeleteContent(DbConnection connection, PageInfo page, int revision)
        {
            string name, nspace;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("PageContent");
            query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "Revision", WhereOperator.Equals, "Revision");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.String, "Revision", revision));

            DbCommand command = builder.GetCommand(connection, query, parameters);

            int rows = ExecuteNonQuery(command, false);

            return rows > 0;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:32,代码来源:SqlPagesStorageProviderBase.cs

示例14: RenamePage

        /// <summary>
        /// Renames a Page.
        /// </summary>
        /// <param name="page">The Page to rename.</param>
        /// <param name="newName">The new Name.</param>
        /// <returns>The correct <see cref="T:PageInfo"/> object.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/> or <paramref name="newName"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="newName"/> is empty.</exception>
        public PageInfo RenamePage(PageInfo page, string newName)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(newName == null) throw new ArgumentNullException("newName");
            if(newName.Length == 0) throw new ArgumentException("New Name cannot be empty", "newName");

            // Check
            // 1. Page is default page of its namespace
            // 2. New name already exists

            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            if(GetPage(transaction, page.FullName) == null) {
                RollbackTransaction(transaction);
                return null;
            }
            if(IsDefaultPage(transaction, page)) {
                RollbackTransaction(transaction);
                return null;
            }
            if(GetPage(transaction, NameTools.GetFullName(NameTools.GetNamespace(page.FullName), NameTools.GetLocalName(newName))) != null) {
                RollbackTransaction(transaction);
                return null;
            }

            PageContent currentContent = GetContent(transaction, page, CurrentRevision);
            UnindexPage(currentContent, transaction);
            foreach(Message msg in GetMessages(transaction, page)) {
                UnindexMessageTree(page, msg, transaction);
            }

            string nspace, name;
            NameTools.ExpandFullName(page.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

            CategoryInfo[] currCategories = GetCategories(transaction, nspace == "" ? null : GetNamespace(transaction, nspace));
            string lowerPageName = page.FullName.ToLowerInvariant();
            List<string> pageCategories = new List<string>(10);
            foreach(CategoryInfo cat in currCategories) {
                if(Array.Find(cat.Pages, (s) => { return s.ToLowerInvariant() == lowerPageName; }) != null) {
                    pageCategories.Add(NameTools.GetLocalName(cat.FullName));
                }
            }

            RebindPage(transaction, page, new string[0]);

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.Update("Page", new string[] { "Name" }, new string[] { "NewName" });
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "OldName");
            query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");

            List<Parameter> parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "NewName", newName));
            parameters.Add(new Parameter(ParameterType.String, "OldName", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));

            DbCommand command = builder.GetCommand(transaction, query, parameters);

            int rows = ExecuteNonQuery(command, false);

            if(rows > 0) {
                PageInfo result = new PageInfo(NameTools.GetFullName(nspace, newName), this, page.CreationDateTime);

                RebindPage(transaction, result, pageCategories.ToArray());

                PageContent newContent = GetContent(transaction, result, CurrentRevision);

                IndexPage(newContent, transaction);
                foreach(Message msg in GetMessages(transaction, result)) {
                    IndexMessageTree(result, msg, transaction);
                }

                CommitTransaction(transaction);

                return result;
            }
            else {
                RollbackTransaction(transaction);
                return null;
            }
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:92,代码来源:SqlPagesStorageProviderBase.cs

示例15: GetCategoriesForPage

        /// <summary>
        /// Gets all the categories of a page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns>The categories, sorted by name.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/> is <c>null</c>.</exception>
        public CategoryInfo[] GetCategoriesForPage(PageInfo page)
        {
            if(page == null) throw new ArgumentNullException("page");

            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string nspace, pageName;
            NameTools.ExpandFullName(page.FullName, out nspace, out pageName);
            if(nspace == null) nspace = "";

            string query = queryBuilder.SelectFrom("Category", "CategoryBinding", new string[] { "Name", "Namespace" }, new string[] { "Category", "Namespace" }, Join.LeftJoin,
                new string[] { "Name", "Namespace" }, new string[] { "Page" });
            query = queryBuilder.Where(query, "CategoryBinding", "Namespace", WhereOperator.Equals, "Namespace");
            query = queryBuilder.AndWhere(query, "CategoryBinding", "Page", WhereOperator.Equals, "Page");
            query = queryBuilder.OrderBy(query, new[] { "Category_Name" }, new[] { Ordering.Asc });

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            parameters.Add(new Parameter(ParameterType.String, "Page", pageName));

            DbCommand command = builder.GetCommand(connString, query, parameters);

            DbDataReader reader = ExecuteReader(command);

            if(reader != null) {
                List<CategoryInfo> result = new List<CategoryInfo>(20);
                List<string> pages = new List<string>(50);

                string prevName = "|||";
                string name = null;

                while(reader.Read()) {
                    name = reader["Category_Name"] as string;

                    if(name != prevName) {
                        if(prevName != "|||") {
                            result[result.Count - 1].Pages = pages.ToArray();
                            pages.Clear();
                        }

                        result.Add(new CategoryInfo(NameTools.GetFullName(reader["Category_Namespace"] as string, name), this));
                    }

                    prevName = name;
                    if(!IsDBNull(reader, "CategoryBinding_Page")) {
                        pages.Add(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["CategoryBinding_Page"] as string));
                    }
                }

                CloseReader(command, reader);

                if(result.Count > 0) result[result.Count - 1].Pages = pages.ToArray();

                return result.ToArray();
            }
            else return null;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:64,代码来源:SqlPagesStorageProviderBase.cs


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