tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file db_connection_installer.class.php

Documentation is available at db_connection_installer.class.php

  1. <?php
  2.  
  3. /**
  4.  * Contains DB_Connection_Installer class
  5.  *
  6.  * @package tangra_lib
  7.  * @subpackage db
  8.  */
  9.  
  10. /**
  11.  *
  12.  */
  13. require_once(TANGRA_MAIN_DIR.'db/db_connection.class.php');
  14. /**
  15.  *
  16.  */
  17. require_once(TANGRA_MAIN_DIR.'db/db_recordset_installer.class.php');
  18. /**
  19.  *
  20.  */
  21. require_once(TANGRA_MAIN_DIR.'exceptions/te_dbc_sql_failed.class.php');
  22. /**
  23.  *
  24.  */
  25. require_once(TANGRA_MAIN_DIR.'exceptions/te_dbc_connect_failed.class.php');
  26. /**
  27.  *
  28.  */
  29. require_once(TANGRA_MAIN_DIR.'exceptions/te_dbc_generate_id_failed.class.php');
  30.  
  31.  
  32. /**
  33.  * This class is ment to be used ONLY by module installers
  34.  *
  35.  * DB_Connection_Installer resembles adodb_db_connection but is created with already connected db connection instead of DSN. It's purpose is to fake "normal" db connection in order module instalators to be able to use *_DBC when installing/uninstalling
  36.  *
  37.  * @package tangra_lib
  38.  * @subpackage db
  39.  */
  40.  
  41.     /**
  42.      * Constructor
  43.      *
  44.      * @param ADODB_Connection $conn 
  45.      */
  46.     function __construct($conn{
  47.         $this->conn = $conn;
  48.         $this->conn->SetFetchMode(ADODB_FETCH_NUM);
  49.         $this->set_connected(true);
  50.     }
  51.  
  52.  
  53.     /**
  54.      * Fake
  55.      *
  56.      * @return boolean 
  57.      */
  58.     public function connect({
  59.         $ret true;
  60.  
  61.         return $ret;
  62.     }
  63.  
  64.  
  65.     /**
  66.      * Disconnects
  67.      *
  68.      */
  69.     public function disconnect({
  70.         if ($this->is_connected()) {
  71.             $this->conn->Close();
  72.             $this->set_connected(false);
  73.         }
  74.     }
  75.  
  76.  
  77.     /**
  78.      * Starts db transaction
  79.      *
  80.      */
  81.     public function start_trans({
  82.         $old_err_rep error_reporting(SYSTEM_ERROR_REPORTING_PHP4_LIBS);
  83.         $this->conn->StartTrans();
  84.         error_reporting($old_err_rep);
  85.     }
  86.  
  87.  
  88.     /**
  89.      * Ends (commit) db transaction
  90.      *
  91.      */
  92.     public function complete_trans({
  93.         $old_err_rep error_reporting(SYSTEM_ERROR_REPORTING_PHP4_LIBS);
  94.         $this->conn->CompleteTrans();
  95.         error_reporting($old_err_rep);
  96.     }
  97.  
  98.  
  99.     /**
  100.      * Executes SQL statemen
  101.      *
  102.      *
  103.      * @param string $sql 
  104.      * @throws TE_DBC_SQL_Failed
  105.      * @throws TE_DBC
  106.      */
  107.     public function execute($sql$ignore_sql_injection_warning false{
  108.         if ($this->is_connected()) {
  109.             $old_err_rep error_reporting(SYSTEM_ERROR_REPORTING_PHP4_LIBS);
  110.  
  111.             $rs_cache $this->conn->Execute($sql);
  112.             error_reporting($old_err_rep);
  113.  
  114.             $tmp_error_msg $this->conn->ErrorMsg();
  115.             if (!$rs_cache{
  116.                 if ($this->conn->transOff 0{
  117.                     $this->conn->CompleteTrans();
  118.                 }
  119.  
  120.                 throw new TE_DBC_SQL_Failed($sql$tmp_error_msg);
  121.             }
  122.  
  123.             $rs new DB_Recordset_Installer($rs_cache);
  124.         else {
  125.             throw new TE_DBC('Database connection is in disconnected state. May be you called $dbc->disconnect() somewhere?');
  126.         }
  127.  
  128.         return $rs;
  129.     }
  130.  
  131.  
  132.     /**
  133.      * Alias of execute
  134.      *
  135.      * @param string $sql 
  136.      */
  137.     public function query($sql//alias of execute()
  138.         $this->execute($sql);
  139.     }
  140.  
  141.  
  142.     /**
  143.      * Generates ID
  144.      *
  145.      * @param string $sequence_name Name of the sequence that will be used (for MySQL where sequences are not available - name of the db table that fakes the sequence)
  146.      * @param integer $start Starting value of the sequence (will be used only if sequence does not exist yet, i.e. for initialization)
  147.      * @return integer Generated ID
  148.      */
  149.     public function generate_id($sequence_name$start 1{
  150.         $old_err_rep error_reporting(SYSTEM_ERROR_REPORTING_PHP4_LIBS);
  151.  
  152.         $ret $this->conn->GenID($sequence_name$start);
  153.         error_reporting($old_err_rep);
  154.  
  155.         if (!$ret{
  156.             throw new TE_DBC_Generate_Id_Failed($sequence_name);
  157.         }
  158.  
  159.         return $ret;
  160.     }
  161.  
  162.  
  163.     /**
  164.      * Fails transaction (rollback)
  165.      *
  166.      */
  167.     public function fail_trans({
  168.         $this->conn->FailTrans();
  169.     }
  170.  
  171.  
  172.     /**
  173.      * Return error message (if any)
  174.      *
  175.      */
  176.     public function get_error_msg({
  177.         $this->conn->ErrorMsg();
  178.     }
  179.  
  180.  
  181.     /**
  182.      * Fake
  183.      *
  184.      * @param unknown_type $sql 
  185.      * @param unknown_type $num_rows 
  186.      * @param unknown_type $offset 
  187.      */
  188.     public function select_limit($sql$num_rows$offset{
  189.  
  190.     }
  191.  
  192.  
  193.     /**
  194.      * Destructor
  195.      *
  196.      * Disconnects
  197.      *
  198.      */
  199.     function __destruct({
  200.         $this->disconnect();
  201.  
  202.     }
  203. }