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


C# QueryBuilder.DeleteFrom方法代码示例

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


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

示例1: DeleteDataForDocument

        /// <summary>
        /// Deletes all data associated to a document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param>
        private void DeleteDataForDocument(IDocument document, object state)
        {
            // 1. Delete all data related to a document
            // 2. Delete all words that have no more mappings

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

            string query = queryBuilder.DeleteFrom("IndexDocument");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "DocName");
            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "DocName", document.Name));

            string subQuery = queryBuilder.SelectFrom("IndexWordMapping", new string[] { "Word" });
            subQuery = queryBuilder.GroupBy(subQuery, new string[] { "Word" });
            string query2 = queryBuilder.DeleteFrom("IndexWord");
            query2 = queryBuilder.WhereNotInSubquery(query2, "IndexWord", "Id", subQuery);

            query = queryBuilder.AppendForBatch(query, query2);

            DbCommand command = null;
            if(state != null) command = builder.GetCommand((DbTransaction)state, query, parameters);
            else command = builder.GetCommand(connString, query, parameters);

            // Close only if state is null
            ExecuteNonQuery(command, state == null);
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:32,代码来源:SqlPagesStorageProviderBase.cs

示例2: RemoveUserGroupMembership

        /// <summary>
        /// Removes the user group membership for a user.
        /// </summary>
        /// <param name="transaction">A database transaction.</param>
        /// <param name="username">The username.</param>
        private void RemoveUserGroupMembership(DbTransaction transaction, string username)
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("UserGroupMembership");
            query = queryBuilder.Where(query, "User", WhereOperator.Equals, "Username");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Username", username));

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

            ExecuteNonQuery(command, false);
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:20,代码来源:SqlUsersStorageProviderBase.cs

示例3: 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

示例4: DeleteBackups

        /// <summary>
        /// Deletes the Backups of a Page, up to a specified revision.
        /// </summary>
        /// <param name="page">The Page to delete the backups of.</param>
        /// <param name="revision">The newest revision to delete (newer revision are kept) o -1 to delete all the Backups.</param>
        /// <returns><c>true</c> if the deletion succeeded, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="page"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="revision"/> is less than -1.</exception>
        public bool DeleteBackups(PageInfo page, int revision)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(revision < -1) throw new ArgumentOutOfRangeException("revision", "Invalid Revision");

            // 1. Retrieve target content (revision-1 = first kept revision)
            // 2. Replace the current content (delete, store)
            // 3. Delete all older revisions up to the specified on (included) "N-m...N"
            // 4. Re-number remaining revisions starting from FirstRevision (zero) to revision-1 (don't re-number revs -1, -100)

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

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

            int[] baks = GetBackups(transaction, page);
            if(baks.Length > 0 && revision > baks[baks.Length - 1]) {
                RollbackTransaction(transaction);
                return true;
            }

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

            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");
            if(revision != -1) query = queryBuilder.AndWhere(query, "Revision", WhereOperator.LessThanOrEqualTo, "Revision");
            query = queryBuilder.AndWhere(query, "Revision", WhereOperator.GreaterThanOrEqualTo, "FirstRevision");

            List<Parameter> parameters = new List<Parameter>(4);
            parameters.Add(new Parameter(ParameterType.String, "Page", name));
            parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
            if(revision != -1) parameters.Add(new Parameter(ParameterType.Int16, "Revision", revision));
            parameters.Add(new Parameter(ParameterType.Int16, "FirstRevision", FirstRevision));

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

            int rows = ExecuteNonQuery(command, false);

            if(rows == -1) {
                RollbackTransaction(transaction);
                return false;
            }

            if(revision != -1) {
                int revisionDelta = revision + 1;

                query = queryBuilder.UpdateIncrement("PageContent", "Revision", -revisionDelta);
                query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
                query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
                query = queryBuilder.AndWhere(query, "Revision", WhereOperator.GreaterThanOrEqualTo, "FirstRevision");

                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, "FirstRevision", FirstRevision));

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

                rows = ExecuteNonQuery(command, false);

                if(rows > 0) CommitTransaction(transaction);
                else RollbackTransaction(transaction);

                return rows >= 0;
            }
            else {
                CommitTransaction(transaction);
                return true;
            }
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:87,代码来源:SqlPagesStorageProviderBase.cs

示例5: DeleteFile

        /// <summary>
        /// Deletes a File.
        /// </summary>
        /// <param name="fullName">The full name of the File.</param>
        /// <returns><c>true</c> if the File is deleted, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="fullName"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="fullName"/> is empty or it does not exist.</exception>
        public bool DeleteFile(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();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            if(!FileExists(transaction, fullName)) {
                RollbackTransaction(transaction);
                throw new ArgumentException("File does not exist", "fullName");
            }

            QueryBuilder queryBuilder = new QueryBuilder(builder);

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

            string query = queryBuilder.DeleteFrom("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", filename));
            parameters.Add(new Parameter(ParameterType.String, "Directory", directory));

            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,代码行数:42,代码来源:SqlFilesStorageProviderBase.cs

示例6: RemoveCategory

        /// <summary>
        /// Removes a Category.
        /// </summary>
        /// <param name="transaction">A database transaction.</param>
        /// <param name="category">The Category to remove.</param>
        /// <returns>True if the Category has been removed successfully.</returns>
        private bool RemoveCategory(DbTransaction transaction, CategoryInfo category)
        {
            string nspace = null;
            string name = null;
            NameTools.ExpandFullName(category.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

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

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

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

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

            int rows = ExecuteNonQuery(command, false);

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

示例7: RemoveNavigationPath

        /// <summary>
        /// Removes a Navigation Path.
        /// </summary>
        /// <param name="connection">A database connection.</param>
        /// <param name="path">The navigation path to remove.</param>
        /// <returns><c>true</c> if the path is removed, <c>false</c> otherwise.</returns>
        private bool RemoveNavigationPath(DbConnection connection, NavigationPath path)
        {
            string nspace, name;
            NameTools.ExpandFullName(path.FullName, out nspace, out name);
            if(nspace == null) nspace = "";

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

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

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

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

            int rows = ExecuteNonQuery(command, false);

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

示例8: SetMetaDataItem

        /// <summary>
        /// Sets a meta-data items' content.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="tag">The tag that specifies the context (usually the namespace).</param>
        /// <param name="content">The content.</param>
        /// <returns><c>true</c> if the content is set, <c>false</c> otherwise.</returns>
        public bool SetMetaDataItem(MetaDataItem item, string tag, string content)
        {
            if(tag == null) tag = "";
            if(content == null) content = "";

            // 1. Delete old value, if any
            // 2. Store new value

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

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("MetaDataItem");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");
            query = queryBuilder.AndWhere(query, "Tag", WhereOperator.Equals, "Tag");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", item.ToString()));
            parameters.Add(new Parameter(ParameterType.String, "Tag", tag));

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

            int rows = ExecuteNonQuery(command, false);

            if(rows == -1) {
                RollbackTransaction(transaction);
                return false;
            }

            query = queryBuilder.InsertInto("MetaDataItem", new string[] { "Name", "Tag", "Data" }, new string[] { "Name", "Tag", "Content" });

            parameters = new List<Parameter>(3);
            parameters.Add(new Parameter(ParameterType.String, "Name", item.ToString()));
            parameters.Add(new Parameter(ParameterType.String, "Tag", tag));
            parameters.Add(new Parameter(ParameterType.String, "Content", content));

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

            rows = ExecuteNonQuery(command, false);

            if(rows == 1) CommitTransaction(transaction);
            else RollbackTransaction(transaction);

            return rows == 1;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:54,代码来源:SqlSettingsStorageProviderBase.cs

示例9: SetSetting

        /// <summary>
        /// Stores the value of a Setting.
        /// </summary>
        /// <param name="name">The name of the Setting.</param>
        /// <param name="value">The value of the Setting. Value cannot contain CR and LF characters, which will be removed.</param>
        /// <returns>True if the Setting is stored, false otherwise.</returns>
        /// <remarks>This method stores the Value immediately.</remarks>
        public bool SetSetting(string name, string value)
        {
            if(name == null) throw new ArgumentNullException("name");
            if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name");

            // 1. Delete old value, if any
            // 2. Store new value

            // Nulls are converted to empty strings
            if(value == null) value = "";

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

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("Setting");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

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

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

            int rows = ExecuteNonQuery(command, false);

            if(rows == -1) {
                RollbackTransaction(transaction);
                return false; // Deletion command failed (0-1 are OK)
            }

            query = queryBuilder.InsertInto("Setting",
                new string[] { "Name", "Value" }, new string[] { "Name", "Value" });
            parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Name", name));
            parameters.Add(new Parameter(ParameterType.String, "Value", value));

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

            rows = ExecuteNonQuery(command, false);

            if(rows == 1) CommitTransaction(transaction);
            else RollbackTransaction(transaction);

            return rows == 1;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:54,代码来源:SqlSettingsStorageProviderBase.cs

示例10: DeletePluginAssembly

        /// <summary>
        /// Removes a plugin's assembly.
        /// </summary>
        /// <param name="transaction">A database transaction.</param>
        /// <param name="filename">The file name of the assembly to remove, such as "Assembly.dll".</param>
        /// <returns><c>true</c> if the assembly is removed, <c>false</c> otherwise.</returns>
        private bool DeletePluginAssembly(DbTransaction transaction, string filename)
        {
            ICommandBuilder builder = GetCommandBuilder();
            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.DeleteFrom("PluginAssembly");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

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

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

            int rows = ExecuteNonQuery(command, false);

            return rows == 1;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:23,代码来源:SqlSettingsStorageProviderBase.cs

示例11: DeleteOutgoingLinks

        /// <summary>
        /// Deletes the outgoing links of a page and all the target links that include the page.
        /// </summary>
        /// <param name="page">The full name of the page.</param>
        /// <returns><c>true</c> if the links are deleted, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <b>page</b> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>page</b> is empty.</exception>
        public bool DeleteOutgoingLinks(string page)
        {
            if(page == null) throw new ArgumentNullException("page");
            if(page.Length == 0) throw new ArgumentException("Page cannot be empty", "page");

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

            string query = queryBuilder.DeleteFrom("OutgoingLink");
            query = queryBuilder.Where(query, "Source", WhereOperator.Equals, "Source");
            query = queryBuilder.OrWhere(query, "Destination", WhereOperator.Equals, "Destination");

            List<Parameter> parameters = new List<Parameter>(2);
            parameters.Add(new Parameter(ParameterType.String, "Source", page));
            parameters.Add(new Parameter(ParameterType.String, "Destination", page));

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

            int rows = ExecuteNonQuery(command);

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

示例12: DeleteEntries

        /// <summary>
        /// Deletes some ACL entries.
        /// </summary>
        /// <param name="entries">The entries to delete.</param>
        /// <returns><c>true</c> if one or more entries were deleted, <c>false</c> otherwise.</returns>
        private bool DeleteEntries(AclEntry[] entries)
        {
            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            foreach(AclEntry entry in entries) {
                string query = queryBuilder.DeleteFrom("AclEntry");
                query = queryBuilder.Where(query, "Resource", WhereOperator.Equals, "Resource");
                query = queryBuilder.AndWhere(query, "Action", WhereOperator.Equals, "Action");
                query = queryBuilder.AndWhere(query, "Subject", WhereOperator.Equals, "Subject");

                List<Parameter> parameters = new List<Parameter>(3);
                parameters.Add(new Parameter(ParameterType.String, "Resource", entry.Resource));
                parameters.Add(new Parameter(ParameterType.String, "Action", entry.Action));
                parameters.Add(new Parameter(ParameterType.String, "Subject", entry.Subject));

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

                if(ExecuteNonQuery(command, false) <= 0) {
                    RollbackTransaction(transaction);
                    return false;
                }
            }

            CommitTransaction(transaction);

            return true;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:36,代码来源:SqlSettingsStorageProviderBase.cs

示例13: CutRecentChangesIfNecessary

        /// <summary>
        /// Cuts the recent changes if necessary.
        /// </summary>
        private void CutRecentChangesIfNecessary()
        {
            ICommandBuilder builder = GetCommandBuilder();
            DbConnection connection = builder.GetConnection(connString);
            DbTransaction transaction = BeginTransaction(connection);

            QueryBuilder queryBuilder = new QueryBuilder(builder);

            string query = queryBuilder.SelectCountFrom("RecentChange");

            DbCommand command = builder.GetCommand(transaction, query, new List<Parameter>());

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

            int maxChanges = int.Parse(host.GetSettingValue(SettingName.MaxRecentChanges));

            if(rows > maxChanges) {
                // Remove 10% of old changes to avoid 1-by-1 deletion every time a change is made
                int entriesToDelete = maxChanges / 10;
                if(entriesToDelete > rows) entriesToDelete = rows;
                //entriesToDelete += entriesToDelete / 10;

                // This code is not optimized, but it surely works in most DBMS
                query = queryBuilder.SelectFrom("RecentChange", new string[] { "Id" });
                query = queryBuilder.OrderBy(query, new string[] { "Id" }, new Ordering[] { Ordering.Asc });

                command = builder.GetCommand(transaction, query, new List<Parameter>());

                DbDataReader reader = ExecuteReader(command);

                List<int> ids = new List<int>(entriesToDelete);

                if(reader != null) {
                    while(reader.Read() && ids.Count < entriesToDelete) {
                        ids.Add((int)reader["Id"]);
                    }

                    CloseReader(reader);
                }

                if(ids.Count > 0) {
                    // Given that the IDs to delete can be many, the query is split in many chunks, each one deleting 50 items
                    // This works-around the problem of too many parameters in a RPC call of SQL Server
                    // See also CutLog

                    for(int chunk = 0; chunk <= ids.Count / MaxParametersInQuery; chunk++) {
                        query = queryBuilder.DeleteFrom("RecentChange");
                        List<string> parms = new List<string>(MaxParametersInQuery);
                        List<Parameter> parameters = new List<Parameter>(MaxParametersInQuery);

                        for(int i = chunk * MaxParametersInQuery; i < Math.Min(ids.Count, (chunk + 1) * MaxParametersInQuery); i++) {
                            parms.Add("P" + i.ToString());
                            parameters.Add(new Parameter(ParameterType.Int32, parms[parms.Count - 1], ids[i]));
                        }

                        query = queryBuilder.WhereIn(query, "Id", parms.ToArray());

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

                        if(ExecuteNonQuery(command, false) < 0) {
                            RollbackTransaction(transaction);
                            return;
                        }
                    }
                }
            }

            CommitTransaction(transaction);
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:72,代码来源:SqlSettingsStorageProviderBase.cs

示例14: RemoveUserGroup

        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if(group == null) throw new ArgumentNullException("group");

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

            string query = queryBuilder.DeleteFrom("UserGroup");
            query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "Name");

            List<Parameter> parameters = new List<Parameter>(1);
            parameters.Add(new Parameter(ParameterType.String, "Name", group.Name));

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

            int rows = ExecuteNonQuery(command);

            return rows == 1;
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:25,代码来源:SqlUsersStorageProviderBase.cs

示例15: 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


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