function test_should_establish_a_connection()
    {
        $this->installAndIncludeModels(array('DummyModel'=>'id'));
        
        $Model =& $this->DummyModel;
        $default_connection =& AkDbAdapter::getInstance();
        $available_tables_on_default = $default_connection->availableTables(); 
        unset ($Model->_db);
        
        $this->assertReference($Model->establishConnection(),$default_connection);
        $development_connection =& $Model->establishConnection('development');
        
        $available_tables_on_development = $development_connection->availableTables();
        $this->assertFalse($development_connection===$default_connection);
        
        $this->assertFalse($Model->establishConnection('not_specified_profile'));
        $this->assertError("The environment not_specified_profile is not allowed. Allowed environments: setup,testing,development,production");
        $this->assertError("Could not find the database profile 'not_specified_profile' in config/database.yml.");
        
        $check_default_connection =& AkDbAdapter::getInstance();
        $this->assertReference($default_connection,$check_default_connection);
        $this->assertReference($default_connection->connection,$check_default_connection->connection);

        //because we dont get two different connections at the same time on PHP if user and password is identical 
        //thus: !$this->assertEqual($available_tables_on_default,$check_default_connection->availableTables());
        //we have to:
        $check_default_connection->connect();
        //now we get:
        $this->assertEqual($available_tables_on_default,$check_default_connection->availableTables());
        //BUT again: !!
        //$this->assertNotEqual($available_tables_on_development,$development_connection->availableTables());
        //$this->assertEqual($available_tables_on_default,$development_connection->availableTables());
        
    }
Ejemplo n.º 2
0
Archivo: Ak.php Proyecto: joeymetal/v1
 /**
  * Gets an instance of AkDbAdapter
  *
  * Whenever a database connection is required you can get a
  * reference to the default database connection by doing:
  *
  * $db =& Ak::db(); // get an adodb instance
  * 
  * AdoDB manual can be found at http://phplens.com/adodb/
  *
  * @access public
  * @param    string    $dns    A string containing Data Source Name (information
  * regarding database connection)
  * http://phplens.com/adodb/code.initialization.html#dsnsupport
  * @static
  * @return resource Php AdoDb instance.
  */
 function &db($dsn = null)
 {
     require_once AK_LIB_DIR . DS . 'AkActiveRecord' . DS . 'AkDbAdapter.php';
     if (empty($dsn) || !is_array($dsn)) {
         return AkDbAdapter::getInstance();
     }
     return AkDbAdapter::getInstance($dsn);
 }
Ejemplo n.º 3
0
 public function test_should_rename_columns_for_postgre()
 {
     $db =& AkDbAdapter::getInstance();
     if ($db->type() !== 'postgre') {
         return;
     }
     $this->installAndIncludeModels(array('RenameColumn' => "id,namen string(55),postcunt int not null default 0,help string default 'none'"));
     $table_name = 'rename_columns';
     $db->renameColumn($table_name, 'namen', 'name');
 }
Ejemplo n.º 4
0
 function AkInstaller($db_connection = null)
 {
     if (empty($db_connection)) {
         $this->db =& AkDbAdapter::getInstance();
     } else {
         $this->db =& $db_connection;
     }
     $this->data_dictionary =& $this->db->getDictionary();
     $this->available_tables = $this->getAvailableTables();
 }
Ejemplo n.º 5
0
 function testSetUp()
 {
     $this->assertThat($this->User->getTableName(), $this->equalTo('my_users'));
     $this->assertThat($this->Customer->getTableName(), $this->equalTo('my_customers'));
     $this->assertThat($this->Client->getTableName(), $this->equalTo('my_clients'));
     $this->assertArrayHasKey('clients', $this->User->getAssociated('hasAndBelongsToMany'));
     $this->assertContains('my_users', AkDbAdapter::getInstance()->availableTables());
     $this->assertContains('my_customers', AkDbAdapter::getInstance()->availableTables());
     $this->assertContains('my_clients', AkDbAdapter::getInstance()->availableTables());
 }
Ejemplo n.º 6
0
 public function test_should_establish_a_connection()
 {
     $this->installAndIncludeModels(array('DummyModel' => 'id'));
     $Model = $this->DummyModel;
     $default_connection = AkDbAdapter::getInstance();
     $available_tables_on_default = $default_connection->getAvailableTables();
     unset($Model->_db);
     $this->assertReference($Model->establishConnection(), $default_connection);
     $development_connection = $Model->establishConnection('development', true);
     $available_tables_on_development = $development_connection->getAvailableTables();
     $this->assertFalse($development_connection === $default_connection);
     $this->assertUpcomingError("Could not find the");
     $this->assertFalse($Model->establishConnection('not_specified_profile', true));
     $check_default_connection = AkDbAdapter::getInstance();
     $this->assertReference($default_connection, $check_default_connection);
     $this->assertReference($default_connection->connection, $check_default_connection->connection);
 }
Ejemplo n.º 7
0
 public function init($db_connection = null, $reinit = false)
 {
     if (!$this->_inited || $reinit) {
         // Install scripts might use more RAM than normal requests.
         @ini_set('memory_limit', -1);
         if (empty($db_connection)) {
             $this->db = AkDbAdapter::getInstance();
         } else {
             $this->db = $db_connection;
         }
         $this->ensureAkelosMigrationsModelIsAvailable();
         AkDbSchemaCache::clearAll();
         $this->data_dictionary = $this->db->getDictionary();
         $this->available_tables = $this->getAvailableTables();
         $this->_inited = true;
     }
 }
 function __construct()
 {
     $adapter =& AkDbAdapter::getInstance('sqlite_databases');
     parent::AkInstaller($adapter);
 }
Ejemplo n.º 9
0
 function assertTableHasColumns($table_name, $columns)
 {
     $column_details = AkDbAdapter::getInstance()->getColumnDetails($table_name);
     self::assertEquals($columns, array_map('strtolower', array_keys($column_details)));
 }
Ejemplo n.º 10
0
Archivo: Ak.php Proyecto: joeymetal/v1
 /**
  * Gets an instance of AkDbAdapter
  *
  * Whenever a database connection is required you can get a
  * reference to the default database connection by doing:
  *
  * $db =& Ak::db(); // get an adodb instance
  * 
  * AdoDB manual can be found at http://phplens.com/adodb/
  *
  * @access public
  * @param    string    $dns    A string containing Data Source Name (information
  * regarding database connection)
  * http://phplens.com/adodb/code.initialization.html#dsnsupport
  * @static
  * @return resource Php AdoDb instance.
  */
 function &db($dsn = null)
 {
     require_once AK_LIB_DIR . DS . 'AkActiveRecord' . DS . 'AkDbAdapter.php';
     return AkDbAdapter::getInstance($dsn);
 }
Ejemplo n.º 11
0
 /**
 * Sets the connection for the class.
 */
 function &setConnection($db_adapter = null)
 {
     if (is_null($db_adapter)){
         $db_adapter =& AkDbAdapter::getInstance();
     }
     return $this->_db =& $db_adapter;
 }
Ejemplo n.º 12
0
 /**
  * Sets the connection for the class.
  */
 public function &setConnection($db_adapter = null)
 {
     if (is_null($db_adapter)) {
         $db_adapter = AkDbAdapter::getInstance();
     }
     $this->_db = $db_adapter;
     return $db_adapter;
 }
Ejemplo n.º 13
0
 function _test_investigate_DBTimeStamp()
 {
     $db =& AkDbAdapter::getInstance();
     var_dump($db->DBTimeStamp('2007.11.17'));
     var_dump($db->DBTimeStamp('2007-11-17'));
     var_dump($db->DBTimeStamp('2007-11-17 17:40:23'));
     var_dump($db->DBTimeStamp('2007-11-17 8:40:23'));
     var_dump($db->DBTimeStamp('17-11-2007'));
     var_dump($db->DBTimeStamp(time()));
 }
Ejemplo n.º 14
0
 /**
  * Gets an instance of AkDbAdapter
  *
  * Whenever a database connection is required you can get a
  * reference to the default database connection by doing:
  *
  * $db = Ak::db(); // get an adodb instance
  *
  * AdoDB manual can be found at http://phplens.com/adodb/
  *
  * @access public
  * @param    string    $dns    A string containing Data Source Name (information
  * regarding database connection)
  * http://phplens.com/adodb/code.initialization.html#dsnsupport
  * @static
  * @return resource Php AdoDb instance.
  */
 static function &db($dsn = null)
 {
     return AkDbAdapter::getInstance($dsn);
 }
Ejemplo n.º 15
0
 function runFrameworkInstaller()
 {
     static $unique_dsn = array();
     require_once AK_LIB_DIR . DS . 'AkInstaller.php';
     require_once AK_APP_DIR . DS . 'installers' . DS . 'framework_installer.php';
     foreach (array('production', 'development') as $mode) {
         $dsn = $this->_getDsn($mode);
         if (!isset($unique_dsn[$dsn])) {
             $DbInstance =& AkDbAdapter::getInstance(array('type' => $this->getDatabaseType($mode), 'file' => AK_CONFIG_DIR . DS . $this->getDatabaseName($mode) . '-' . $this->random . '.sqlite', 'user' => $this->getDatabaseUser($mode), 'password' => $this->getDatabasePassword($mode), 'host' => $this->getDatabaseHost($mode), 'database_name' => $this->getDatabaseName($mode)));
             $installer =& new FrameworkInstaller($DbInstance);
             $installer->install(null, array('mode' => $mode));
             $unique_dsn[$dsn] = true;
         }
     }
     return true;
 }
 public function __construct()
 {
     $adapter = AkDbAdapter::getInstance('sqlite_databases', true, 'database');
     parent::__construct($adapter);
 }