搜索
首页数据库mysql教程Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Opera

In this blog post regardingMySQL for Excelnew features included in the 1.2.x versions family, we are going to talk about a new option that is used along withEditMySQLDataoperations; very useful when editing data in a multi-user environment. If you are not familiar with editingMySQLdata it is very advisable that you visit our thorough blog post about that topic: How To - Guide to editingMySQLdata withinExcel.

Remember you can install the latest GA or maintenance version using theMySQL Installeror optionally you can download directly any GA or non-GA version from theMySQL Developer Zone.

MySQL for Excel allows inserting, deleting and updating a table's rows usingExcelas a friendly front-end; a snapshot of the selectedMySQLtable is imported into aExcelworksheet and the Edit Session works with that detached copy of the data. Any changes done to that copy are translated into SQL statements that are applied against the selected MySQLtable. So far, so good.

In a multi-user environment, more than 1 person may be performing changes to the exact same records on a specificMySQLtable meaning the changes done by one person can be overwritten by another unless records are explicitly locked. By designMySQL for Exceldoes not lock a table when its data is imported to open an Edit Session because it is simply not practical, the session may be left open by a user for an unknown amount of time which can be very long, hence the disconnected nature of the Edit Session.

In all previous 1.x versions what could happen if 2 different persons were editing the exact same MySQL table would be the following as illustrated in the image below:

  1. User 1 (orange) opens an Edit Session against a MySQL table.
  2. User 2 (purple) also opens an Edit Session against the same MySQL table.
  3. User 2 modifies a record where C1 =1, modifies C2 =b, C3 =jand C4 =z, then commits the modifications.
  4. User 1 modifies the same record where C1 =1, modifies C2 =w, then commits that single modification.
  5. User 2 retrieves again from the database the record where C1 =1and notices C2 =wand is left wondering why since he expected it to have a value ofb.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

InMySQL for Excel1.2.0 we introduced a new global option to allow optimistic updates to be used on Edit Sessions to avoid overwriting any data that may have been modified by another user between the moment the Edit Session retrieved/refreshed the data from the database and the moment the Edit Session changes are committed. The Global Options dialog can be accessed from the Optionsbutton located in the Schema Selection panel or the DB Objects Selection one as shown below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQLOptimistic updates for Edit Data operations in MySQL for Exc_MySQL

After clicking onOptionstheGlobal Advanced Optionsdialog will appear, under theSQL Queries Optionssection there is an option calledUse optimistic updates on all Edit Data sessionsthat if checked (which is by default) it will prevent the unintentional overwriting we mentioned above on all Edit Sessions inMySQL for Excel.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

The use of optimistic updates can also be turned on/off for all Edit Sessions or a specific one by right-clicking the Edit Session floating dialog and selecting from the context menuUse Optimistic Update  For all sessionsorFor this sessionrespectively.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

To understand better the mechanism of how the unintentional overwriting is done inMySQL for Excelwe can take a look at the SQL statements generated without and with optimistic updates turned on.  As an example, lets say we have an Edit Session open for theMySQLtableactor_copy, we turn off optimistic updates for this single session (unchecking the option in the screenshot above), and then we change some data as we can see in the screenshot below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Now having turned on thePreview SQL statements before they are sent to the serverglobal option (look at the screenshot with the global options up above) we can inspect the SQL statements generated byMySQL for Excelto apply the modifications after clickingCommit Changes.  In the screenshot below you can notice how the WHEREclause of theUPDATEstatements reference just the primary key columns of the table. We will clickCanceland not commit these changes.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

If then we turn back on optimistic updates for this Edit Session, and clickCommit Changesagain we will be able to see how the SQL statements for the same modifications look like using optimistic updates. In the screenshot below you can notice how the WHEREclause of theUPDATE statements reference all columns in the table, this way if any value of a record was changed by another user, the record will not be found and that UPDATE statement will not do anything.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Lets say that before we hitApplyanother user is making modifications to theactor_copytable usingMySQL Workbench, and they change thelast_name column's value from"LEWIS"to"LOPEZ"of the record whereactor_id=4, and commit the change as seen in the screenshot below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Then we commit our changes inMySQL for Excel. Since another user committed a change on the record whereactor_id=4, theWHEREclause of the firstUPDATEstatement generated with optimistic updates turned on (see 2 screenshots above) will not find the record it was supposed to, and as we expected that change will not be unintentionally overwritten by the changes done inMySQL for Excel.  The cells that encountered optimistic updates conflicts will be colored orange and the information dialog that displays the operation results will show the conflicts as warnings as you can see below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

At this point all non-conflicting changes are committed to the database, but the conflicting changes are not. In order to fix the conflicts we need to locate the orange colored cells that depict the conflicting data, retrieve a fresh snapshot of data from the database by clickingRevert Dataon the Edit Session dialog thenRefresh Data from DB, then re-apply our changes on the conflicting cells and commit those changes again.

Optimistic updates makes Edit MySQL Data operations inMySQL for Excelmore friendly in multi-user environments and can prevent some data updating concurrency troubles. We hope you give this and the other new features inMySQL for Excela try!

Remember that your feedback is very important for us, so drop us a message and follow us:

  • MySQL on Windows (this) Blog:https://blogs.oracle.com/MySqlOnWindows/
  • MySQL for Excel forum:http://forums.mysql.com/list.php?172
  • Facebook: http://www.facebook.com/mysql
  • YouTube channel:https://www.youtube.com/user/MySQLChannel

Cheers!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
减少在Docker中使用MySQL内存的使用减少在Docker中使用MySQL内存的使用Mar 04, 2025 pm 03:52 PM

本文探讨了Docker中的优化MySQL内存使用量。 它讨论了监视技术(Docker统计,性能架构,外部工具)和配置策略。 其中包括Docker内存限制,交换和cgroups

mysql无法打开共享库怎么解决mysql无法打开共享库怎么解决Mar 04, 2025 pm 04:01 PM

本文介绍了MySQL的“无法打开共享库”错误。 该问题源于MySQL无法找到必要的共享库(.SO/.DLL文件)。解决方案涉及通过系统软件包M验证库安装

如何使用Alter Table语句在MySQL中更改表?如何使用Alter Table语句在MySQL中更改表?Mar 19, 2025 pm 03:51 PM

本文讨论了使用MySQL的Alter Table语句修改表,包括添加/删除列,重命名表/列以及更改列数据类型。

在 Linux 中运行 MySQl(有/没有带有 phpmyadmin 的 podman 容器)在 Linux 中运行 MySQl(有/没有带有 phpmyadmin 的 podman 容器)Mar 04, 2025 pm 03:54 PM

本文比较使用/不使用PhpMyAdmin的Podman容器直接在Linux上安装MySQL。 它详细介绍了每种方法的安装步骤,强调了Podman在孤立,可移植性和可重复性方面的优势,还

什么是 SQLite?全面概述什么是 SQLite?全面概述Mar 04, 2025 pm 03:55 PM

本文提供了SQLite的全面概述,SQLite是一个独立的,无服务器的关系数据库。 它详细介绍了SQLite的优势(简单,可移植性,易用性)和缺点(并发限制,可伸缩性挑战)。 c

在MacOS上运行多个MySQL版本:逐步指南在MacOS上运行多个MySQL版本:逐步指南Mar 04, 2025 pm 03:49 PM

本指南展示了使用自制在MacOS上安装和管理多个MySQL版本。 它强调使用自制装置隔离安装,以防止冲突。 本文详细详细介绍了安装,起始/停止服务和最佳PRA

如何为MySQL连接配置SSL/TLS加密?如何为MySQL连接配置SSL/TLS加密?Mar 18, 2025 pm 12:01 PM

文章讨论了为MySQL配置SSL/TLS加密,包括证书生成和验证。主要问题是使用自签名证书的安全含义。[角色计数:159]

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什么?哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什么?Mar 21, 2025 pm 06:28 PM

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)