Ejemplo n.º 1
0
 public function test_execute_should_handle_bindings()
 {
     $db = new AkDbAdapter(array());
     // no conection details, we're using a Mock
     Mock::generate('ADOConnection');
     $connection = new MockADOConnection();
     $connection->setReturnValue('Execute', true);
     $connection->expectAt(0, 'Execute', array('SELECT * FROM articles WHERE id=1'));
     $connection->expectAt(1, 'Execute', array('SELECT * FROM articles WHERE id=?', array(1)));
     $db->connection =& $connection;
     $db->execute('SELECT * FROM articles WHERE id=1');
     $db->execute(array('SELECT * FROM articles WHERE id=?', 1));
 }
Ejemplo n.º 2
0
 function _checkDbConfig($type, $settings = array())
 {
     $this->debug('Checking if database config for "' . $type . '" is available');
     require_once AK_BASE_DIR . DS . 'lib' . DS . 'AkActiveRecord' . DS . 'AkDbAdapter.php';
     require_once AK_LIB_DIR . DS . 'Ak.php';
     if (empty($settings)) {
         require_once AK_BASE_DIR . DS . 'lib' . DS . 'AkConfig.php';
         $config = new AkConfig();
         $settings = $config->get($type, 'testing');
     }
     $db = new AkDbAdapter($settings);
     $db->connect(false);
     if (!($res = $db->connected())) {
         $this->error("[{$type}] " . 'Cannot connect to DB');
     } else {
         $this->info("[{$type}] " . 'Successfully connected to database ' . ($settings['type'] == 'sqlite' ? $settings['database_file'] : $settings['database_name']));
         $createRes = $db->execute('CREATE table ci_test_dummy(id integer)');
         if (!$createRes) {
             $res = false;
             $this->error("[{$type}] " . 'Could not create test table: ci_test_dummy');
         } else {
             $res = true;
             $this->info("[{$type}] " . 'Successfully created test table: ci_test_dummy');
             $db->execute('DROP table ci_test_dummy');
         }
     }
     return $res;
 }