<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="chrome=1" />

    <!--
    <link rel="stylesheet" type="text/css" href="/oscar/css/main.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="/oscar/stylesheets/github-dark.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/oscar/stylesheets/print.css" media="print">
    -->
    <link rel="shortcut icon" type="image/x-icon" href="/oscar/favicon.ico?" />
    <link rel="stylesheet" type="text/css" href="/oscar/stylesheets/stylesheet.css" media="screen" />

    <title>OSCAR: DevODA_Database.pm</title>
  </head>

  <body>

    <div id="header_wrap" class="outer">
        <header class="inner">
		<a id="forkme_banner" href="https://github.com/oscar-cluster/oscar">View on GitHub</a>

        <div id="project_tagline">
          <img src="/oscar/images/oscar-logo.jpg" width="130" />
        </div>
          <h2 id="project_tagline1">Open Source Cluster Application Resources</h2>

            <section id="downloads">
		    <a class="zip_download_link" href="https://github.com/oscar-cluster//oscar/zipball/master">Download this project as a .zip file</a>
		    <a class="tar_download_link" href="https://github.com/oscar-cluster/oscar/tarball/master">Download this project as a tar.gz file</a>
            </section>
        </header>
    </div>
    <div class="container">
      <section id="main_content">

    <!-- MAIN CONTENT -->
    <div id="main_content_wrap" class="outer">
        <div class="middle">
               <div class="sidebox">
        <ul>
            <li><a href="/oscar/" title="home" class="" ><span>Main Page</span></a></li>
            <li><a href="/oscar/wiki/Status" title="home" class="" ><span>Current Status</span></a></li>
            <li><a href="/oscar/wiki/Download" title="download" class="" ><span>Download</span></a></li>
            <li><a href="/oscar/wiki/Document" title="document" class="current" ><span>Documentations</span></a></li>
            <li><a href="/oscar/wiki/Contact" title="contact" class="" ><span>Contact</span></a></li>
            <li><a href="/oscar/blog.html" title="blog" class="" ><span>Blog</span></a></li>
            <!--
            <li><a href="/oscar/publications" title="contact" class="" ><span>Publications</span></a></li>
            -->
        </ul>
       </div>


      <section id="main_content" class="inner">
<!-- Name: DevODA_Database.pm -->
<!-- Version: 14 -->
<!-- Author: dikim -->

<p>[DevelDocs] &gt; <a href="DevODA">ODA</a> &gt; Database.pm</p>
<h2 id="databasepm">Database.pm</h2>

<p><code class="language-plaintext highlighter-rouge">Database.pm</code>, located at the next level of the ODA hierarchy, is an[[BR]]
abstract Perl module to handle directly all the database operations under[[BR]]
the control of <code class="language-plaintext highlighter-rouge">oda.pm</code>. Many Perl subroutines defined at[[BR]]
<code class="language-plaintext highlighter-rouge">Database.pm</code> are exported so that non-database codes of OSCAR can[[BR]]
use its subroutines as if they are defined by importing <code class="language-plaintext highlighter-rouge">Database.pm</code>[[BR]]</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> (e.g., use Database.pm )
</code></pre></div></div>

<p>For example, <em>get_packages</em> in <code class="language-plaintext highlighter-rouge">Database.pm</code> is a subroutine[[BR]]
that the OSCAR installer can call to get the list of OSCAR packages.[[BR]]
The Perl module, <code class="language-plaintext highlighter-rouge">Database.pm</code> including the subroutine, <em>get_packages</em>,[[BR]]
looks like this:[[BR]]</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>package OSCAR::Database
use oda

@export = (get_packages,
           .... );

sub get_packages{
    my $ref_result = shift;
    my $sql = "SELECT package FROM Packages";
    my $error;
    my $local_result;
    my $status = ODA::query(\$sql, \$local_result,
       \$error);
    # ...translate $local_result into common
    # form and store in $ref_results...
    $status;
}
</code></pre></div></div>

<p>The subroutines have been created to query or update data from or to the[[BR]]
specific database tables. For the query of data, the name of the subroutines[[BR]]
starts with <em>get</em> and if there is an argument to set the <em>WHERE</em> clause,[[BR]]
<em>with__ and the argument name are added as a suffix.  On the other hand,[[BR]]
the subroutines to update data into the tables are named starting with _set</em>.[[BR]]
Like the query subroutines, the updated subroutines can also add <em>with__[[BR]]
and the argument for the _WHERE</em> clause as a suffix. There is a conventional[[BR]]
rule to set the arguments to the subroutines. The required arguments should[[BR]]
be set as the first and next argument and the optional arguments are supposed[[BR]]
to be set from the last, in the reverse order, so that the optional arguments[[BR]]
can be disregarded even though they are not given to the subroutines.[[BR]]
The usual optional arguments in <code class="language-plaintext highlighter-rouge">Database.pm</code> are <em>$options_ref</em> and[[BR]]
<em>$error_strings_ref</em>.</p>

<p>The subroutines most frequently used in <code class="language-plaintext highlighter-rouge">Database.pm</code> are <em>do_select</em>[[BR]]
for querying, <em>do_update</em> for updating, and <em>do_insert</em> for inserting.[[BR]]
The subroutine <em>do_select</em>, internally calls the <em>do_query</em> subroutine of[[BR]]
<em>oda.pm</em> and transfers the return values of <em>do_query</em> to the caller or[[BR]]
another subroutine. Like <em>do_select</em>, <em>do_update</em> and <em>do_insert</em> use[[BR]]
the <em>do_sql_command</em> subroutine of <em>oda.pm</em> to run the database works[[BR]]
at the back-end. Then, they return the signal to determine if the SQL query[[BR]]
is successfully implemented to the caller or another subroutine.[[BR]]</p>

<p>The source is available on the following link: [[BR]]
[https://svn.oscar.openclustergroup.org/trac/oscar/browser/trunk/lib/OSCAR/Database.pm]
—-</p>
<ul>
  <li><a href="DevODA_oda.pm">oda.pm</a></li>
  <li><a href="DevODA_architecture">Architecture</a></li>
  <li><a href="DevODA_maintenance">Maintenance</a> of ODA</li>
</ul>


      </section>
        </div>
    </div>


    <!-- FOOTER  -->
        <div id="footer_wrap" class="outer">
          <footer class="inner">
            <p class="copyright">Oscar maintained by <a href="https://github.com/oscar-cluster">oscar-cluster</a></p>
            <p class="copyright">Oscar package repository and downloads/ are hosted by <a href="http://www.usablesecurity.net/">UsableSecurity</a></p>
            <p>Published with <a href="https://pages.github.com">GitHub Pages</a></p>
          </footer>
        </div>
    </div>
  </body>
</html>
