<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="query-attributes">
      </a>
      11.6 Query Attributes
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045218358416">
  </a>
  <p>
   The most visible part of an SQL statement is the text of the
      statement. Clients can also define query attributes that apply to
      the next statement sent to the server for execution:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Attributes are defined prior to sending the statement.
     </p>
    </li>
    <li class="listitem">
     <p>
      Attributes exist until statement execution ends, at which
          point the attribute set is cleared.
     </p>
    </li>
    <li class="listitem">
     <p>
      While attributes exist, they can be accessed on the server
          side.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Examples of the ways query attributes may be used:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A web application produces pages that generate database
          queries, and for each query must track the URL of the page
          that generated it.
     </p>
    </li>
    <li class="listitem">
     <p>
      An application passes extra processing information with each
          query, for use by a plugin such as an audit plugin or query
          rewrite plugin.
     </p>
    </li>
   </ul>
  </div>
  <p>
   MySQL supports these capabilities without the use of workarounds
      such as specially formatted comments included in query strings.
      The remainder of this section describes how to use query attribute
      support, including the prerequisites that must be satisfied.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="query-attributes.html#using-query-attributes" title="Defining and Accessing Query Attributes">
       Defining and Accessing Query Attributes
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="query-attributes.html#query-attributes-prerequisites" title="Prerequisites for Using Query Attributes">
       Prerequisites for Using Query Attributes
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="query-attributes.html#query-attribute-functions" title="Query Attribute Loadable Functions">
       Query Attribute Loadable Functions
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="using-query-attributes">
       </a>
       Defining and Accessing Query Attributes
      </h3>
     </div>
    </div>
   </div>
   <p>
    Applications that use the MySQL C API define query attributes by
        calling the
    <a class="ulink" href="/doc/c-api/8.4/en/mysql-bind-param.html" target="_top">
     <code class="literal">
      mysql_bind_param()
     </code>
    </a>
    function. See
    <a class="ulink" href="/doc/c-api/8.4/en/mysql-bind-param.html" target="_top">
     mysql_bind_param()
    </a>
    . Other MySQL
        connectors may also provide query-attribute support. See the
        documentation for individual connectors.
   </p>
   <p>
    The
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client has a
    <code class="literal">
     query_attributes
    </code>
    command that enables
        defining up to 32 pairs of attribute names and values. See
    <a class="xref" href="mysql-commands.html" title="6.5.1.2 mysql Client Commands">
     Section 6.5.1.2, “mysql Client Commands”
    </a>
    .
   </p>
   <p>
    Query attribute names are transmitted using the character set
        indicated by the
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    system
        variable.
   </p>
   <p>
    To access query attributes within SQL statements for which
        attributes have been defined, install the
    <code class="literal">
     query_attributes
    </code>
    component as described in
    <a class="xref" href="query-attributes.html#query-attributes-prerequisites" title="Prerequisites for Using Query Attributes">
     Prerequisites for Using Query Attributes
    </a>
    . The component
        implements a
    <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
     <code class="literal">
      mysql_query_attribute_string()
     </code>
    </a>
    loadable function that takes an attribute name argument and
        returns the attribute value as a string, or
    <code class="literal">
     NULL
    </code>
    if the attribute does not exist. See
    <a class="xref" href="query-attributes.html#query-attribute-functions" title="Query Attribute Loadable Functions">
     Query Attribute Loadable Functions
    </a>
    .
   </p>
   <p>
    The following examples use the
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client
    <code class="literal">
     query_attributes
    </code>
    command to define attribute
        name/value pairs, and the
    <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
     <code class="literal">
      mysql_query_attribute_string()
     </code>
    </a>
    function to access attribute values by name.
   </p>
   <p>
    This example defines two attributes named
    <code class="literal">
     n1
    </code>
    and
    <code class="literal">
     n2
    </code>
    . The first
    <code class="literal">
     SELECT
    </code>
    shows how to retrieve those attributes, and also demonstrates
        that retrieving a nonexistent attribute (
    <code class="literal">
     n3
    </code>
    )
        returns
    <code class="literal">
     NULL
    </code>
    . The second
    <code class="literal">
     SELECT
    </code>
    shows that attributes do not persist
        across statements.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52185679"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> query_attributes n1 v1 n2 v2<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 1'</span><span class="token punctuation">,</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 2'</span><span class="token punctuation">,</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n3'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 3'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> attr 1 <span class="token punctuation">|</span> attr 2 <span class="token punctuation">|</span> attr 3 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> v1     <span class="token punctuation">|</span> v2     <span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 1'</span><span class="token punctuation">,</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 2'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> attr 1 <span class="token punctuation">|</span> attr 2 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    As shown by the second
    <code class="literal">
     SELECT
    </code>
    statement,
        attributes defined prior to a given statement are available only
        to that statement and are cleared after the statement executes.
        To use an attribute value across multiple statements, assign it
        to a variable. The following example shows how to do this, and
        illustrates that attribute values are available in subsequent
        statements by means of the variables, but not by calling
    <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
     <code class="literal">
      mysql_query_attribute_string()
     </code>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56033934"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> query_attributes n1 v1 n2 v2<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span>
         <span class="token variable">@attr1</span> <span class="token operator">=</span> mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
         <span class="token variable">@attr2</span> <span class="token operator">=</span> mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span>
         <span class="token variable">@attr1</span><span class="token punctuation">,</span> mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 1'</span><span class="token punctuation">,</span>
         <span class="token variable">@attr2</span><span class="token punctuation">,</span> mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 2'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> @attr1 <span class="token punctuation">|</span> attr 1 <span class="token punctuation">|</span> @attr2 <span class="token punctuation">|</span> attr 2 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> v1     <span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span> v2     <span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    Attributes can also be saved for later use by storing them in a
        table:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22416118"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>c1 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> c2 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> query_attributes n1 v1 n2 v2<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t1 <span class="token punctuation">(</span>c1<span class="token punctuation">,</span> c2<span class="token punctuation">)</span> <span class="token keyword">VALUES</span><span class="token punctuation">(</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
         mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span>
       <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> c1   <span class="token punctuation">|</span> c2   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> v1   <span class="token punctuation">|</span> v2   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    Query attributes are subject to these limitations and
        restrictions:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       If multiple attribute-definition operations occur prior to
            sending a statement to the server for execution, the most
            recent definition operation applies and replaces attributes
            defined in earlier operations.
      </p>
     </li>
     <li class="listitem">
      <p>
       If multiple attributes are defined with the same name,
            attempts to retrieve the attribute value have an undefined
            result.
      </p>
     </li>
     <li class="listitem">
      <p>
       An attribute defined with an empty name cannot be retrieved
            by name.
      </p>
     </li>
     <li class="listitem">
      <p>
       Attributes are not available to statements prepared with
       <a class="link" href="prepare.html" title="15.5.1 PREPARE Statement">
        <code class="literal">
         PREPARE
        </code>
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string()
        </code>
       </a>
       function cannot be used in DDL statements.
      </p>
     </li>
     <li class="listitem">
      <p>
       Attributes are not replicated. Statements that invoke the
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string()
        </code>
       </a>
       function will not get the same value on all servers.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="query-attributes-prerequisites">
       </a>
       Prerequisites for Using Query Attributes
      </h3>
     </div>
    </div>
   </div>
   <p>
    To access query attributes within SQL statements for which
        attributes have been defined, the
    <code class="literal">
     query_attributes
    </code>
    component must be installed.
        Do so using this statement:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa69347645"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INSTALL</span> <span class="token keyword">COMPONENT</span> <span class="token string">"file://component_query_attributes"</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Component installation is a one-time operation that need not be
        done per server startup.
    <a class="link" href="install-component.html" title="15.7.4.3 INSTALL COMPONENT Statement">
     <code class="literal">
      INSTALL
        COMPONENT
     </code>
    </a>
    loads the component, and also registers it
        in the
    <code class="literal">
     mysql.component
    </code>
    system table to cause
        it to be loaded during subsequent server startups.
   </p>
   <p>
    The
    <code class="literal">
     query_attributes
    </code>
    component accesses query
        attributes to implement a
    <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
     <code class="literal">
      mysql_query_attribute_string()
     </code>
    </a>
    function. See
    <a class="xref" href="query-attribute-components.html" title="7.5.4 Query Attribute Components">
     Section 7.5.4, “Query Attribute Components”
    </a>
    .
   </p>
   <p>
    To uninstall the
    <code class="literal">
     query_attributes
    </code>
    component,
        use this statement:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa35081325"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">UNINSTALL</span> <span class="token keyword">COMPONENT</span> <span class="token string">"file://component_query_attributes"</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    <a class="link" href="uninstall-component.html" title="15.7.4.5 UNINSTALL COMPONENT Statement">
     <code class="literal">
      UNINSTALL COMPONENT
     </code>
    </a>
    unloads the
        component, and unregisters it from the
    <code class="literal">
     mysql.component
    </code>
    system table to cause it not
        to be loaded during subsequent server startups.
   </p>
   <p>
    Because installing and uninstalling the
    <code class="literal">
     query_attributes
    </code>
    component installs and
        uninstalls the
    <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
     <code class="literal">
      mysql_query_attribute_string()
     </code>
    </a>
    function that the component implements, it is not necessary to
        use
    <a class="link" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
     <code class="literal">
      CREATE
        FUNCTION
     </code>
    </a>
    or
    <a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
     <code class="literal">
      DROP
        FUNCTION
     </code>
    </a>
    to do so.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="query-attribute-functions">
       </a>
       Query Attribute Loadable Functions
      </h3>
     </div>
    </div>
   </div>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <a name="function_mysql-query-attribute-string">
       </a>
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string(
         <em class="replaceable">
          <code>
           name
          </code>
         </em>
         )
        </code>
       </a>
      </p>
      <a class="indexterm" name="idm46045218268448">
      </a>
      <p>
       Applications can define attributes that apply to the next
            query sent to the server. The
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string()
        </code>
       </a>
       function 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.
      </p>
      <p>
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string()
        </code>
       </a>
       is installed by installing the
       <code class="literal">
        query_attributes
       </code>
       component. See
       <a class="xref" href="query-attributes.html" title="11.6 Query Attributes">
        Section 11.6, “Query Attributes”
       </a>
       , which also discusses the
            purpose and use of query attributes.
      </p>
      <p>
       Arguments:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: circle; ">
        <li class="listitem">
         <p>
          <em class="replaceable">
           <code>
            name
           </code>
          </em>
          : The attribute name.
         </p>
        </li>
       </ul>
      </div>
      <p>
       Return value:
      </p>
      <p>
       Returns the attribute value as a string for success, or
       <code class="literal">
        NULL
       </code>
       if the attribute does not exist.
      </p>
      <p>
       Example:
      </p>
      <p>
       The following example uses the
       <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
        <span class="command">
         <strong>
          mysql
         </strong>
        </span>
       </a>
       client
       <code class="literal">
        query_attributes
       </code>
       command to define
            query attributes that can be retrieved by
       <a class="link" href="query-attributes.html#function_mysql-query-attribute-string">
        <code class="literal">
         mysql_query_attribute_string()
        </code>
       </a>
       .
            The
       <code class="literal">
        SELECT
       </code>
       shows that retrieving a
            nonexistent attribute (
       <code class="literal">
        n3
       </code>
       ) returns
       <code class="literal">
        NULL
       </code>
       .
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99040379"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> query_attributes n1 v1 n2 v2<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span>
<span class="token prompt">    -&gt;</span>   mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n1'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 1'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>   mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 2'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>   mysql_query_attribute_string<span class="token punctuation">(</span><span class="token string">'n3'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'attr 3'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> attr 1 <span class="token punctuation">|</span> attr 2 <span class="token punctuation">|</span> attr 3 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> v1     <span class="token punctuation">|</span> v2     <span class="token punctuation">|</span> NULL   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
      </div>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
