databases
[ class tree: databases ] [ index: databases ] [ all elements ]

Source for file ABSTDatabaseTable.class.php

Documentation is available at ABSTDatabaseTable.class.php

  1. <?php
  2. /**
  3.  * @package databases
  4.  */
  5.  
  6.  
  7. /**
  8.  * Loading the supirior class on which this class depends.
  9.  */
  10. require_onceCLASSPATH."databases/Database.class.php" );
  11.  
  12. /**
  13.  * @abstract
  14.  *
  15.  * @package   databases
  16.  * @version   0.1.85
  17.  *
  18.  * @author    Daniel Plücken <daniel@debakel.net>
  19.  * @license   http://www.gnu.org/copyleft/lesser.html
  20.  *             GNU Lesser General Public License
  21.  * @copyright Copyright (C) 2004 Daniel Plücken <daniel@debakel.net>
  22.  *
  23.  *  This library is free software; you can redistribute it and/or
  24.  *  modify it under the terms of the GNU Lesser General Public
  25.  *  License as published by the Free Software Foundation; either
  26.  *  version 2.1 of the License.
  27.  *
  28.  *  This library is distributed in the hope that it will be useful,
  29.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  30.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31.  *  GNU Lesser General Public License for more details.
  32.  *
  33.  *  You should have received a copy of the GNU Lesser General
  34.  *  Public License along with this library; if not, write to the
  35.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  36.  *  Boston, MA 02111-1307 USA
  37.  */
  38. {
  39.     /**
  40.      * The name of the databasetable.
  41.      *
  42.      * @var    string $name 
  43.      * @access public
  44.      */
  45.     var $name;
  46.     /*
  47.     * Carries the field's objects of this databasetable.
  48.     *
  49.     * @var    array   $field
  50.     * @access private
  51.     */
  52.     // var $field;
  53.     /*
  54.     * Will be set to true if the fields's information become stored.
  55.     *
  56.     * @var    boolean $field_info_stored
  57.     * @access private
  58.     */
  59.     // var $field_info_stored = false;
  60.     /**
  61.      * Carries the fieldnames of this databasetable.
  62.      *
  63.      * @access public
  64.      * @var    array  $fieldname 
  65.      */
  66.     var $fieldname = array();
  67.     /**
  68.      * Will be set to true if the fieldnames become stored.
  69.      *
  70.      * @access private
  71.      * @var    boolean $field_names_stored 
  72.      */
  73.     var $field_names_stored = false;
  74.     /**
  75.      * Carries the field properties whether they can be NULL.
  76.      *
  77.      * @access public
  78.      * @var    array  $field_can_be_null 
  79.      */
  80.     var $field_can_be_null = array();
  81.     /**
  82.      * Carries the field properties whether they are a member of a primary key.
  83.      *
  84.      * @access public
  85.      * @var    array  $field_is_primary_member 
  86.      */
  87.     var $field_is_primary_member = array();
  88.     /**
  89.      * Carries the field properties whether they have auto increment.
  90.      *
  91.      * @access public
  92.      * @var    array  $field_has_auto_increment 
  93.      */
  94.     var $field_has_auto_increment = array();
  95.     /**
  96.      * Will be set to true if the field flags become stored.
  97.      *
  98.      * @access private
  99.      * @var    boolean $field_flags_stored 
  100.      */
  101.     var $field_flags_stored = false;
  102.     /**
  103.      * Refers to the database in which this relation lies.
  104.      *
  105.      * @access private
  106.      * @var    Database $parent 
  107.      */
  108.     var $parent;
  109.     /**
  110.      * Stores the last query made to the underlying database table.
  111.      *
  112.      * @access public
  113.      * @var    string $last_query 
  114.      */
  115.     var $last_query;
  116.     /**
  117.      * Stores the last insert id of the underlying database table.
  118.      *
  119.      * @access public
  120.      * @var    integer $insert_id 
  121.      */
  122.     var $insert_id = null;
  123.     /**
  124.      * Holds the field members of the primary key of this table object.
  125.      *
  126.      * @access private
  127.      * @var    array $primary_key 
  128.      */
  129.     var $primary_key = null;
  130.     /**
  131.      * Holds the fieldname of the auto increment Column.
  132.      *
  133.      * @access private
  134.      * @var    string  $auto_increment_field 
  135.      */
  136.     var $auto_increment_field = null;
  137.     /**
  138.      * Shows whether the fieldnames are overruled.
  139.      *
  140.      * @access private
  141.      * @var    boolean $overruled_fieldnames 
  142.      */
  143.     var $overruled_fieldnames = false;
  144.  
  145.  
  146.     /**
  147.      * Fake-Constructor
  148.      *
  149.      * @access  public
  150.      * @version 1.0
  151.      * @since   0.1.3
  152.      *
  153.      * @return  void 
  154.      */
  155.     function ABSTDatabaseTable()
  156.     {
  157.         echo "<h3>This is an abstract class. "
  158.                 ."You cannot get an instance of it!</h3>";
  159.         exit();
  160.     }
  161.  
  162.  
  163.  
  164.     /**
  165.      * Constructor
  166.      *
  167.      * @access  public
  168.      * @version 1.2
  169.      * @since   0.1.3
  170.      *
  171.      * @param   string   $name 
  172.      * @param   string   $kind 
  173.      * @param   Database $parent 
  174.      *
  175.      * @return  ABSTDatabaseTable 
  176.      */
  177.     function __contructor$name ""$kind$parent "" )
  178.     {
  179.         if !empty$name ) )
  180.         {
  181.             $this->name = $name;
  182.  
  183.             if (
  184.                  !function_exists"is_a" )
  185.               && (
  186.                    get_class$parent == "database"
  187.                 || get_parent_class$parent == "database"
  188.                  )
  189.                )
  190.             {   $this->parent =$parent}
  191.             else
  192.             if (
  193.                  function_exists"is_a" )
  194.               && (
  195.                    is_a$parent"Database" )
  196.                 || @is_subclass_of$parent"Database" )
  197.                  )
  198.                )
  199.             {   $this->parent =$parent}
  200.             else
  201.             if $parent !== "" )
  202.             {
  203.                 echo "<h3>The third parameter is not a reference to an object "
  204.                      ."of a database!</h3>";
  205.  
  206.                 if function_exists"debug_backtrace" ) )
  207.                 {
  208.                     $debugArr debug_backtrace();
  209.                     echo "<b>BACKTRACE DEBUG</b><br />\r\n";
  210.                     echo "<pre>\r\n";
  211.                     print_r$debugArr );
  212.                     echo "</pre>\r\n";
  213.                 }
  214.                 exit();
  215.             }
  216.         }
  217.         else
  218.         {
  219.             die(
  220.                  "<h3>You have to give a name to this database table!</h3>"
  221.                 ."<b>Use following Syntax:<b><br><br>\r\n"
  222.                 ."<pre>\r\n"
  223.                 ."  \x24dbt = new {$kind}DatabaseTable"
  224.                                         ."( \x24name, \x24parent );\r\n"
  225.                 ."</pre>\r\n"
  226.                );
  227.         }
  228.     }
  229.  
  230.  
  231.  
  232.     /**
  233.      * Sets the name of the databasetable.
  234.      *
  235.      * @access  public
  236.      * @version 1.0
  237.      * @since   0.1.0
  238.      *
  239.      * @param   string  $string  The name the database table should get.
  240.      *
  241.      * @return  void 
  242.      */
  243.     function setName$string )
  244.     {    $this->name = $string}
  245.  
  246.  
  247.  
  248.     /**
  249.      * Sets the parent of this object.
  250.      *
  251.      * @access  public
  252.      * @version 1.1
  253.      * @since   0.1.2
  254.      *
  255.      * @param   string $obj_ref Should be a reference of a database object.
  256.      *
  257.      * @return  void 
  258.      */
  259.     function setParent&$obj_ref )
  260.     {
  261.         if (
  262.              !function_exists"is_a" )
  263.           && (
  264.                get_class$obj_ref == "database"
  265.             || get_parent_class$obj_ref == "database"
  266.              )
  267.            )
  268.         {   $this->parent = &$obj_ref}
  269.         else
  270.         if (
  271.              function_exists"is_a" )
  272.           && (
  273.                is_a$obj_ref"Database" )
  274.             || @is_subclass_of$obj_ref"Database" )
  275.              )
  276.            )
  277.         {   $this->parent = &$obj_ref}
  278.         else
  279.         {
  280.             die(
  281.                    "<h3>The given parameter is not a reference "
  282.                       ."of an object of a database!</h3>"
  283.                );
  284.         }
  285.     }
  286.  
  287.  
  288.  
  289.     /**
  290.      * Adds a join's reference to this object of a database table.
  291.      *
  292.      * @access  public
  293.      * @version 1.0
  294.      * @since   0.1.4
  295.      *
  296.      * @param   object $obj_ref Should be a reference of a join object.
  297.      *
  298.      * @return  void 
  299.      */
  300.     function addJoin&$obj_ref )
  301.     {
  302.         if (
  303.              !function_exists"is_a" )
  304.           && (
  305.                get_class$obj_ref == "join"
  306.             || get_parent_class$obj_ref == "join"
  307.              )
  308.            )
  309.         {   $this->join[=$obj_ref}
  310.         else
  311.         if (
  312.              function_exists"is_a" )
  313.           && (
  314.                is_a$obj_ref"Join" )
  315.             || @is_subclass_of$obj_ref"Join" )
  316.              )
  317.            )
  318.         {   $this->join[=$obj_ref}
  319.         else
  320.         {
  321.             die(
  322.                  "<h3>The given parameter is not a reference "
  323.                     ."of an object of a join!</h3>"
  324.                );
  325.         }
  326.     }
  327.  
  328.  
  329.  
  330.     /**
  331.      * Adds a field's reference to this object of a database table.
  332.      *
  333.      * @access  public
  334.      * @version 1.0
  335.      * @since   0.1.2
  336.      *
  337.      * @param   object  $obj_ref 
  338.      *
  339.      * @return  void 
  340.      */
  341.     function addField&$obj_ref )
  342.     {    $this->field[=$obj_ref}
  343.  
  344.  
  345.  
  346.     /**
  347.      * Adds a field's reference to this object of a database table.
  348.      *
  349.      * @access  public
  350.      * @version 1.0
  351.      * @since   0.1.2
  352.      *
  353.      * @param   string  $string 
  354.      *
  355.      * @return  void 
  356.      */
  357.     function addFieldname$string )
  358.     {    $this->fieldname[$string}
  359.  
  360.  
  361.  
  362.     /**
  363.      * Returns the name of the database table.
  364.      *
  365.      * @access  public
  366.      * @version 1.0
  367.      * @since   0.1.0
  368.      *
  369.      * @return  string 
  370.      */
  371.     function getName()
  372.     {    return $this->name}
  373.  
  374.  
  375.  
  376.     /**
  377.      * Returns the table's fieldnames.
  378.      *
  379.      * @access  public
  380.      * @version 1.0
  381.      * @since   0.1.2
  382.      *
  383.      * @return  array 
  384.      */
  385.     function getFieldnames()
  386.     {    return $this->fieldname}
  387.  
  388.  
  389.  
  390.     /**
  391.      * Returns the last stored database query.
  392.      *
  393.      * @access  public
  394.      * @version 1.0
  395.      * @since   0.1.1
  396.      *
  397.      * @return  array 
  398.      */
  399.     function getLastQuery()
  400.     {    return $this->parent->last_query}
  401.  
  402.  
  403.  
  404.     /**
  405.      * Returns the parent object of this object.
  406.      *
  407.      * @access  public
  408.      * @version 1.0
  409.      * @since   0.1.2
  410.      *
  411.      * @return  Database 
  412.      */
  413.     function &getParent ()
  414.     {    return $this->parent}
  415.  
  416.  
  417.  
  418.     /**
  419.      * Returns the id of the connection resource to the database host.
  420.      *
  421.      * @access  public
  422.      * @version 1.0
  423.      * @since   0.1.81
  424.      *
  425.      * @return  object 
  426.      */
  427.     function &getResourceID()
  428.     {    return $this->parent->getResourceID()}
  429.  
  430.  
  431.  
  432.     /**
  433.      * Returns the last insert id that was made to the underlying database
  434.      * table.
  435.      *
  436.      * @access  public
  437.      * @version 1.0
  438.      * @since   0.1.82
  439.      *
  440.      * @return  integer 
  441.      */
  442.     function &getInsertID()
  443.     {    return $this->insert_id}
  444.  
  445.  
  446.  
  447.     /**
  448.      * This method has to be implement in a subclass!
  449.      *
  450.      * @abstract
  451.      *
  452.      * @access  public
  453.      * @version 1.0
  454.      * @since   0.1.85
  455.      *
  456.      * @return void 
  457.      */
  458.     function getPrimaryKey()
  459.     {
  460.         die(
  461.              "Please implement in subclass - this is an abstract method in "
  462.             ."ABSTDatabaseTable!"
  463.            );
  464.     }
  465. // End of class ABSTDatabaseTable
  466. ?>

Documentation generated on Thu, 05 Jun 2008 19:09:42 +0200 by phpDocumentor 1.4.1