Maison base de données tutoriel mysql Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Jun 01, 2016 pm 01:07 PM

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!

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Meilleurs paramètres graphiques
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Comment réparer l'audio si vous n'entendez personne
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Où trouver la courte de la grue à atomide atomique
1 Il y a quelques semaines By DDD

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Comment modifier une table dans MySQL en utilisant l'instruction ALTER TABLE? Comment modifier une table dans MySQL en utilisant l'instruction ALTER TABLE? Mar 19, 2025 pm 03:51 PM

L'article discute de l'utilisation de l'instruction ALTER TABLE de MySQL pour modifier les tables, notamment en ajoutant / abandon les colonnes, en renommant des tables / colonnes et en modifiant les types de données de colonne.

Comment configurer le cryptage SSL / TLS pour les connexions MySQL? Comment configurer le cryptage SSL / TLS pour les connexions MySQL? Mar 18, 2025 pm 12:01 PM

L'article discute de la configuration du cryptage SSL / TLS pour MySQL, y compris la génération et la vérification de certificat. Le problème principal est d'utiliser les implications de sécurité des certificats auto-signés. [Compte de caractère: 159]

Comment gérez-vous les grands ensembles de données dans MySQL? Comment gérez-vous les grands ensembles de données dans MySQL? Mar 21, 2025 pm 12:15 PM

L'article traite des stratégies pour gérer de grands ensembles de données dans MySQL, y compris le partitionnement, la rupture, l'indexation et l'optimisation des requêtes.

Quels sont les outils de GUI MySQL populaires (par exemple, MySQL Workbench, PhpMyAdmin)? Quels sont les outils de GUI MySQL populaires (par exemple, MySQL Workbench, PhpMyAdmin)? Mar 21, 2025 pm 06:28 PM

L'article traite des outils de GUI MySQL populaires comme MySQL Workbench et PhpMyAdmin, en comparant leurs fonctionnalités et leur pertinence pour les débutants et les utilisateurs avancés. [159 caractères]

Comment déposez-vous une table dans MySQL à l'aide de l'instruction TABLE DROP? Comment déposez-vous une table dans MySQL à l'aide de l'instruction TABLE DROP? Mar 19, 2025 pm 03:52 PM

L'article discute de la suppression des tables dans MySQL en utilisant l'instruction TABLE DROP, mettant l'accent sur les précautions et les risques. Il souligne que l'action est irréversible sans sauvegardes, détaillant les méthodes de récupération et les risques potentiels de l'environnement de production.

Comment représentez-vous des relations en utilisant des clés étrangères? Comment représentez-vous des relations en utilisant des clés étrangères? Mar 19, 2025 pm 03:48 PM

L'article discute de l'utilisation de clés étrangères pour représenter les relations dans les bases de données, en se concentrant sur les meilleures pratiques, l'intégrité des données et les pièges communs à éviter.

Comment créez-vous des index sur les colonnes JSON? Comment créez-vous des index sur les colonnes JSON? Mar 21, 2025 pm 12:13 PM

L'article discute de la création d'index sur les colonnes JSON dans diverses bases de données comme PostgreSQL, MySQL et MongoDB pour améliorer les performances de la requête. Il explique la syntaxe et les avantages de l'indexation des chemins JSON spécifiques et répertorie les systèmes de base de données pris en charge.

Comment sécuriser MySQL contre les vulnérabilités communes (injection SQL, attaques par force brute)? Comment sécuriser MySQL contre les vulnérabilités communes (injection SQL, attaques par force brute)? Mar 18, 2025 pm 12:00 PM

L'article discute de la sécurisation MySQL contre l'injection SQL et les attaques brutales à l'aide de déclarations préparées, de validation des entrées et de politiques de mot de passe solides (159 caractères)

See all articles