<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="sys-sys-get-config">
      </a>
      30.4.5.19 The sys_get_config() Function
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045060696528">
  </a>
  <a class="indexterm" name="idm46045060695056">
  </a>
  <p>
   Given a configuration option name, returns the option value
          from the
   <a class="link" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
    <code class="literal">
     sys_config
    </code>
   </a>
   table, or
          the provided default value (which may be
   <code class="literal">
    NULL
   </code>
   ) if the option does not exist in the
          table.
  </p>
  <p>
   If
   <a class="link" href="sys-sys-get-config.html" title="30.4.5.19 The sys_get_config() Function">
    <code class="literal">
     sys_get_config()
    </code>
   </a>
   returns the
          default value and that value is
   <code class="literal">
    NULL
   </code>
   , it is
          expected that the caller is able to handle
   <code class="literal">
    NULL
   </code>
   for the given configuration option.
  </p>
  <p>
   By convention, routines that call
   <a class="link" href="sys-sys-get-config.html" title="30.4.5.19 The sys_get_config() Function">
    <code class="literal">
     sys_get_config()
    </code>
   </a>
   first check
          whether the corresponding user-defined variable exists and is
          non-
   <code class="literal">
    NULL
   </code>
   . If so, the routine uses the
          variable value without reading the
   <a class="link" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
    <code class="literal">
     sys_config
    </code>
   </a>
   table. If the
          variable does not exist or is
   <code class="literal">
    NULL
   </code>
   , the
          routine reads the option value from the table and sets the
          user-defined variable to that value. For more information
          about the relationship between configuration options and their
          corresponding user-defined variables, see
   <a class="xref" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
    Section 30.4.2.1, “The sys_config Table”
   </a>
   .
  </p>
  <p>
   If you want to check whether the configuration option has
          already been set and, if not, use the return value of
   <code class="literal">
    sys_get_config()
   </code>
   , you can use
   <code class="literal">
    IFNULL(...)
   </code>
   (see example later). However,
          this should not be done inside a loop (for example, for each
          row in a result set) because for repeated calls where the
          assignment is needed only in the first iteration, using
   <code class="literal">
    IFNULL(...)
   </code>
   is expected to be significantly
          slower than using an
   <code class="literal">
    IF (...) THEN ... END
          IF;
   </code>
   block (see example later).
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="sys-sys-get-config-parameters">
       </a>
       Parameters
      </h5>
     </div>
    </div>
   </div>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <code class="literal">
        in_variable_name VARCHAR(128)
       </code>
       : The
                name of the configuration option for which to return the
                value.
      </p>
     </li>
     <li class="listitem">
      <p>
       <code class="literal">
        in_default_value VARCHAR(128)
       </code>
       : The
                default value to return if the configuration option is
                not found in the
       <code class="literal">
        sys_config
       </code>
       table.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="sys-sys-get-config-return-value">
       </a>
       Return Value
      </h5>
     </div>
    </div>
   </div>
   <p>
    A
    <code class="literal">
     VARCHAR(128)
    </code>
    value.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="sys-sys-get-config-example">
       </a>
       Example
      </h5>
     </div>
    </div>
   </div>
   <p>
    Get a configuration value from the
    <a class="link" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
     <code class="literal">
      sys_config
     </code>
    </a>
    table, falling back
            to 128 as the default if the option is not present in the
            table:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21440983"><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">SELECT</span> sys<span class="token punctuation">.</span>sys_get_config<span class="token punctuation">(</span><span class="token string">'statement_truncate_len'</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">Value</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>
<span class="token output"><span class="token punctuation">|</span> Value <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>
<span class="token output"><span class="token punctuation">|</span> 64    <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></code></pre>
   </div>
   <p>
    One-liner example: Check whether the option is already set;
            if not, assign the
    <code class="literal">
     IFNULL(...)
    </code>
    result
            (using the value from the
    <a class="link" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
     <code class="literal">
      sys_config
     </code>
    </a>
    table):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27692445"><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">SET</span> <span class="token variable">@sys.statement_truncate_len</span> <span class="token operator">=</span>
       <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token variable">@sys.statement_truncate_len</span><span class="token punctuation">,</span>
              sys<span class="token punctuation">.</span>sys_get_config<span class="token punctuation">(</span><span class="token string">'statement_truncate_len'</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    <code class="literal">
     IF (...) THEN ... END IF;
    </code>
    block example:
            Check whether the option is already set; if not, assign the
            value from the
    <a class="link" href="sys-sys-config.html" title="30.4.2.1 The sys_config Table">
     <code class="literal">
      sys_config
     </code>
    </a>
    table:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44803775"><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 function">IF</span> <span class="token punctuation">(</span><span class="token variable">@sys.statement_truncate_len</span> <span class="token operator">IS</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span> <span class="token keyword">THEN</span>
  <span class="token keyword">SET</span> <span class="token variable">@sys.statement_truncate_len</span> <span class="token operator">=</span> sys<span class="token punctuation">.</span>sys_get_config<span class="token punctuation">(</span><span class="token string">'statement_truncate_len'</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span></code></pre>
   </div>
  </div>
 </div>
 <br/>
</div>
