Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.2Mb
PDF (A4) - 40.3Mb
PDF (RPM) - 39.6Mb
HTML Download (TGZ) - 10.4Mb
HTML Download (Zip) - 10.4Mb
HTML Download (RPM) - 9.0Mb
Man Pages (TGZ) - 244.2Kb
Man Pages (Zip) - 349.3Kb
Info (Gzip) - 3.8Mb
Info (Zip) - 3.8Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  /  ...  /  Query Attribute User-Defined Functions

5.7.3 Query Attribute User-Defined Functions

  • mysql_query_attribute_string(name)

    Applications can define attributes that apply to the next query sent to the server. The mysql_query_attribute_string() function, available as of MySQL 8.0.23, returns an attribute value as a string, given the attribute name. This function enables a query to access and incorporate values of the attributes that apply to it.

    mysql_query_attribute_string() is installed by installing the query_attributes component. See Section 9.6, “Query Attributes”, which also discusses the purpose and use of query attributes.

    Arguments:

    • name: The attribute name.

    Return value:

    Returns the attribute value as a string for success, or NULL if the attribute does not exist.

    Example:

    The following example uses the mysql client query_attributes command to define query attributes that can be retrieved by mysql_query_attribute_string(). The SELECT shows that retrieving a nonexistent attribute (n3) returns NULL.

    mysql> query_attributes n1 v1 n2 v2;
    mysql> SELECT
        ->   mysql_query_attribute_string('n1') AS 'attr 1',
        ->   mysql_query_attribute_string('n2') AS 'attr 2',
        ->   mysql_query_attribute_string('n3') AS 'attr 3';
    +--------+--------+--------+
    | attr 1 | attr 2 | attr 3 |
    +--------+--------+--------+
    | v1     | v2     | NULL   |
    +--------+--------+--------+

    For additional examples, see Section 9.6, “Query Attributes”.