Rechercher dans le manuel MySQL

5.6.6.4 Version Tokens Reference

The following discussion serves as a reference to these Version Tokens components:

Version Tokens Functions

The Version Tokens plugin library includes several user-defined functions. One set of UDFs permits the server's list of version tokens to be manipulated and inspected. Another set of UDFs permits version tokens to be locked and unlocked. The VERSION_TOKEN_ADMIN or SUPER privilege is required to invoke any Version Tokens UDF.

The following UDFs permit the server's list of version tokens to be created, changed, removed, and inspected. Interpretation of name_list and token_list arguments (including whitespace handling) occurs as described in Section 5.6.6.3, “Using Version Tokens”, which provides details about the syntax for specifying tokens, as well as additional examples.

  • version_tokens_delete(name_list)

    Deletes tokens from the server's list of version tokens using the name_list argument and returns a binary string that indicates the outcome of the operation. name_list is a semicolon-separated list of version token names to delete.

    1. mysql> SELECT version_tokens_delete('tok1;tok3');
    2. +------------------------------------+
    3. | version_tokens_delete('tok1;tok3') |
    4. +------------------------------------+
    5. | 2 version tokens deleted.          |
    6. +------------------------------------+

    An argument of NULL is treated as an empty string, which has no effect on the token list.

    version_tokens_delete() deletes the tokens named in its argument, if they exist. (It is not an error to delete nonexisting tokens.) To clear the token list entirely without knowing which tokens are in the list, pass NULL or a string containing no tokens to version_tokens_set():

    1. mysql> SELECT version_tokens_set(NULL);
    2. +------------------------------+
    3. | version_tokens_set(NULL)     |
    4. +------------------------------+
    5. | Version tokens list cleared. |
    6. +------------------------------+
    7. mysql> SELECT version_tokens_set('');
    8. +------------------------------+
    9. | version_tokens_set('')       |
    10. +------------------------------+
    11. | Version tokens list cleared. |
    12. +------------------------------+
  • version_tokens_edit(token_list)

    Modifies the server's list of version tokens using the token_list argument and returns a binary string that indicates the outcome of the operation. token_list is a semicolon-separated list of name=value pairs specifying the name of each token to be defined and its value. If a token exists, its value is updated with the given value. If a token does not exist, it is created with the given value. If the argument is NULL or a string containing no tokens, the token list remains unchanged.

    1. mysql> SELECT version_tokens_set('tok1=value1;tok2=value2');
    2. +-----------------------------------------------+
    3. | version_tokens_set('tok1=value1;tok2=value2') |
    4. +-----------------------------------------------+
    5. | 2 version tokens set.                         |
    6. +-----------------------------------------------+
    7. mysql> SELECT version_tokens_edit('tok2=new_value2;tok3=new_value3');
    8. +--------------------------------------------------------+
    9. | version_tokens_edit('tok2=new_value2;tok3=new_value3') |
    10. +--------------------------------------------------------+
    11. | 2 version tokens updated.                              |
    12. +--------------------------------------------------------+
  • version_tokens_set(token_list)

    Replaces the server's list of version tokens with the tokens defined in the token_list argument and returns a binary string that indicates the outcome of the operation. token_list is a semicolon-separated list of name=value pairs specifying the name of each token to be defined and its value. If the argument is NULL or a string containing no tokens, the token list is cleared.

    1. mysql> SELECT version_tokens_set('tok1=value1;tok2=value2');
    2. +-----------------------------------------------+
    3. | version_tokens_set('tok1=value1;tok2=value2') |
    4. +-----------------------------------------------+
    5. | 2 version tokens set.                         |
    6. +-----------------------------------------------+
  • version_tokens_show()

    Returns the server's list of version tokens as a binary string containing a semicolon-separated list of name=value pairs.

    1. mysql> SELECT version_tokens_show();
    2. +--------------------------+
    3. | version_tokens_show()    |
    4. +--------------------------+
    5. | tok2=value2;tok1=value1; |
    6. +--------------------------+

The following UDFs permit version tokens to be locked and unlocked:

  • version_tokens_lock_exclusive(token_name[, token_name] ..., timeout)

    Acquires exclusive locks on one or more version tokens, specified by name as strings, timing out with an error if the locks are not acquired within the given timeout value.

    1. mysql> SELECT version_tokens_lock_exclusive('lock1', 'lock2', 10);
    2. +-----------------------------------------------------+
    3. | version_tokens_lock_exclusive('lock1', 'lock2', 10) |
    4. +-----------------------------------------------------+
    5. |                                                   1 |
    6. +-----------------------------------------------------+
  • version_tokens_lock_shared(token_name[, token_name] ..., timeout)

    Acquires shared locks on one or more version tokens, specified by name as strings, timing out with an error if the locks are not acquired within the given timeout value.

    1. mysql> SELECT version_tokens_lock_shared('lock1', 'lock2', 10);
    2. +--------------------------------------------------+
    3. | version_tokens_lock_shared('lock1', 'lock2', 10) |
    4. +--------------------------------------------------+
    5. |                                                1 |
    6. +--------------------------------------------------+
  • version_tokens_unlock()

    Releases all locks that were acquired within the current session using version_tokens_lock_exclusive() and version_tokens_lock_shared().

    1. mysql> SELECT version_tokens_unlock();
    2. +-------------------------+
    3. | version_tokens_unlock() |
    4. +-------------------------+
    5. |                       1 |
    6. +-------------------------+

The locking functions share these characteristics:

  • The return value is nonzero for success. Otherwise, an error occurs.

  • Token names are strings.

  • In contrast to argument handling for the UDFs that manipulate the server token list, whitespace surrounding token name arguments is not ignored and = and ; characters are permitted.

  • It is possible to lock nonexisting token names. This does not create the tokens.

  • Timeout values are nonnegative integers representing the time in seconds to wait to acquire locks before timing out with an error. If the timeout is 0, there is no waiting and the function produces an error if locks cannot be acquired immediately.

  • Version Tokens locking functions are based on the locking service described at Section 29.3.1, “The Locking Service”.

Table des matières Haut

Version Tokens System Variables

Version Tokens supports the following system variables. These variables are unavailable unless the Version Tokens plugin is installed (see Section 5.6.6.2, “Installing or Uninstalling Version Tokens”).

System variables:

  • version_tokens_session

    Property Value
    Command-Line Format --version-tokens-session=value
    System Variable version_tokens_session
    Scope Global, Session
    Dynamic Yes
    SET_VAR Hint Applies No
    Type String
    Default Value NULL

    The session value of this variable specifies the client version token list and indicates the tokens that the client session requires the server version token list to have.

    If the version_tokens_session variable is NULL (the default) or has an empty value, any server version token list matches. (In effect, an empty value disables matching requirements.)

    If the version_tokens_session variable has a nonempty value, any mismatch between its value and the server version token list results in an error for any statement the session sends to the server. A mismatch occurs under these conditions:

    It is not a mismatch for the server version token list to include a token not named in the version_tokens_session value.

    Suppose that a management application has set the server token list as follows:

    1. mysql> SELECT version_tokens_set('tok1=a;tok2=b;tok3=c');
    2. +--------------------------------------------+
    3. | version_tokens_set('tok1=a;tok2=b;tok3=c') |
    4. +--------------------------------------------+
    5. | 3 version tokens set.                      |
    6. +--------------------------------------------+

    A client registers the tokens it requires the server to match by setting its version_tokens_session value. Then, for each subsequent statement sent by the client, the server checks its token list against the client version_tokens_session value and produces an error if there is a mismatch:

    1. mysql> SET @@SESSION.version_tokens_session = 'tok1=a;tok2=b';
    2. mysql> SELECT 1;
    3. +---+
    4. | 1 |
    5. +---+
    6. | 1 |
    7. +---+
    8.  
    9. mysql> SET @@SESSION.version_tokens_session = 'tok1=b';
    10. mysql> SELECT 1;
    11. ERROR 3136 (42000): Version token mismatch for tok1. Correct value a

    The first SELECT succeeds because the client tokens tok1 and tok2 are present in the server token list and each token has the same value in the server list. The second SELECT fails because, although tok1 is present in the server token list, it has a different value than specified by the client.

    At this point, any statement sent by the client fails, unless the server token list changes such that it matches again. Suppose that the management application changes the server token list as follows:

    1. mysql> SELECT version_tokens_edit('tok1=b');
    2. +-------------------------------+
    3. | version_tokens_edit('tok1=b') |
    4. +-------------------------------+
    5. | 1 version tokens updated.     |
    6. +-------------------------------+
    7. mysql> SELECT version_tokens_show();
    8. +-----------------------+
    9. | version_tokens_show() |
    10. +-----------------------+
    11. | tok3=c;tok1=b;tok2=b; |
    12. +-----------------------+

    Now the client version_tokens_session value matches the server token list and the client can once again successfully execute statements:

    1. mysql> SELECT 1;
    2. +---+
    3. | 1 |
    4. +---+
    5. | 1 |
    6. +---+
  • version_tokens_session_number

    Property Value
    Command-Line Format --version-tokens-session-number=N
    System Variable version_tokens_session_number
    Scope Global, Session
    Dynamic No
    SET_VAR Hint Applies No
    Type Integer
    Default Value 0

    This variable is for internal use.


Rechercher dans le manuel MySQL

Traduction non disponible

Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-version-tokens-reference.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :en Manuel MySQL : https://dev.mysql.com/

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut