Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 236

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="10. Database Event Hooks" />
  <meta name="dc.subject" content="10. Database Event Hooks" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="hooks.html" title="Chapter Contents" />
  <link rel="prev" href="fn_dbev_startup.html" title="Database Startup" />
  <link rel="next" href="fn_logins.html" title="Database Logins" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>10. Database Event Hooks</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="fn_dbev_connect" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>10. Database Event Hooks</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="hooks.html">Chapter Contents</a> | <a class="link" href="fn_dbev_startup.html" title="Database Startup">Prev</a> | <a class="link" href="fn_logins.html" title="Database Logins">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="hooks.html">Database Event Hooks</a>
   </div>
    <br />
   <div>
      <a href="fn_dbev_startup.html">Database Startup</a>
   </div>
   <div class="selected">
      <a href="fn_dbev_connect.html">Database Connections</a>
   </div>
   <div>
      <a href="fn_logins.html">Database Logins</a>
   </div>
   <div>
      <a href="fn_disconnect.html">Database Disconnections</a>
   </div>
   <div>
      <a href="fn_dbev_shutdown.html">Database Shutdown</a>
   </div>
   <div>
      <a href="fn_dbev_prepare.html">SQL Statement Preparation</a>
   </div>
   <div>
      <a href="sqlparsetree.html">SQL Parse Tree</a>
   </div>
   <div>
      <a href="fn_davlogins.html">WebDAV Logins</a>
   </div>
   <div>
      <a href="assocauxdata.html">Associating Auxiliary Data With A Connection</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="fn_dbev_connect" />
    <h2>10.2. Database Connections</h2>

<p>
      <span class="computeroutput">DB.DBA.DBEV_CONNECT()</span>
    </p>
  <p>
If defined, this hook is called for each successful ODBC
or JDBC connection.  The hook is only called after password and
license checks have passed.  The hook is called before the server acknowledges a
successful connect and is therefore guaranteed to run before any other action
by the connected client.
</p>
  <p>
The function runs in its own transaction, which is automatically committed following
successful return.  Result sets may not be generated and return values are discarded.
The connection_id () and user are defined in the function.
SQL states signalled inside this hook will be sent to the client and will cause the
connection to be closed server side.
</p>

<a name="" />
    <div class="example">
      <div class="exampletitle">Simple Connection Logging</div>
<div>
        <pre class="programlisting">
create table security_log (
  sl_user varchar,
  sl_logged_in datetime,
  sl_logged_out datetime,
  primary key (sl_user, sl_logged_in)
);
</pre>
      </div>
<div>
        <pre class="programlisting">
create procedure DB.DBA.DBEV_CONNECT ()
{
  dbg_obj_print (user, &#39; connected&#39;);
  if (user = &#39;NOGO&#39;)
    signal (&#39;EAUTH&#39;, &#39;	External Authorization Failed&#39;);
  insert into security_log (sl_user, sl_logged_in) values (user, curdatetime ());
  connection_set (&#39;login_time&#39;, curdatetime ());
}
</pre>
      </div>

  <p>
This function will print a message to the server&#39;s standard output, check if
the username of the logged in user is NOGO and disconnect the user if so,
This will thereafter insert a row into the security_log table and set the
connection variable &#39;login_time&#39; to be the current time.
This information will be used at disconnect time to identify which entry to
mark closed.
</p>
</div>

<p>
      <span class="computeroutput">DB.DBA.DBEV_DSN_LOGIN
  (<span class="paramdef">inout <span class="parameter">dsn</span> varchar</span>, 
  <span class="paramdef">inout <span class="parameter">user_id</span> varchar</span>, 
  <span class="paramdef">inout <span class="parameter">pwd</span> varchar</span>);
  </span>
    </p>

<p>If defined this function is executed just before Virtuoso makes connections
to remote data sources. It can change all of it&#39;s inout parameters depending on
it&#39;s logic.</p>

<a name="ex_dbev_dsn_login" />
    <div class="example">
      <div class="exampletitle">Remote Connection Hook</div>
<p>
This examples contains a sample DBEV_DSN_LOGIN hook that will be called
just before the Virtual Database connection to a datasource is made.  The
following parameters can be used in this function as demonstrated in this example:</p>
<ul>
        <li>
          <strong>dsn</strong>: the dsn to connect to</li>
        <li>
          <strong>user_id</strong>: the user id used in connecting to the DSN</li>
        <li>
          <strong>pwd</strong>: the password used in connecting to the DSN</li>
      </ul>
<div>
        <pre class="programlisting">
create procedure &quot;DB&quot;.&quot;DBA&quot;.&quot;DBEV_DSN_LOGIN&quot;
(in dsn varchar,
 inout user_id varchar,
 inout pwd varchar)
{
  if (user_id = &#39;U1&#39; and pwd = &#39;U1&#39;)
    {
      -- map U1 to U2
      dbg_obj_print (&#39;mapping U1 to U2&#39;);
      user_id := &#39;U2&#39;;
      pwd := &#39;U2&#39;;
    }
   dbg_obj_print (dsn, user_id, pwd);
};
</pre>
      </div>
</div>
<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="fn_dbev_startup.html" title="Database Startup">Previous</a>
          <br />Database Startup</td>
     <td align="center" width="34%">
          <a href="hooks.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="fn_logins.html" title="Database Logins">Next</a>
          <br />Database Logins</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>