public function set_up($connection_name = null) { ActiveRecord\Table::clear_cache(); $config = ActiveRecord\Config::instance(); $this->original_default_connection = $config->get_default_connection(); $this->original_date_class = $config->get_date_class(); if ($connection_name) { $config->set_default_connection($connection_name); } if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') { // need to create the db. the adapter specifically does not create it for us. static::$db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'), 9); new SQLite3(static::$db); } $this->connection_name = $connection_name; try { $this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name); } catch (ActiveRecord\DatabaseException $e) { $this->mark_test_skipped($connection_name . ' failed to connect. ' . $e->getMessage()); } $GLOBALS['ACTIVERECORD_LOG'] = false; $loader = new DatabaseLoader($this->conn); $loader->reset_table_data(); if (self::$log) { $GLOBALS['ACTIVERECORD_LOG'] = true; } }
public function set_up() { $this->column = new Column(); try { $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection()); } catch (DatabaseException $e) { $this->mark_test_skipped('failed to connect using default connection. ' . $e->getMessage()); } }
public function set_up($connection_name = null) { ActiveRecord\Table::clear_cache(); $config = ActiveRecord\Config::instance(); $this->original_default_connection = $config->get_default_connection(); if ($connection_name) { $config->set_default_connection($connection_name); } if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') { // need to create the db. the adapter specifically does not create it for us. $this->db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'), 9); new SQLite3($this->db); } $this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name); $GLOBALS['ACTIVERECORD_LOG'] = false; $loader = new DatabaseLoader($this->conn); $loader->reset_table_data(); if (self::$log) { $GLOBALS['ACTIVERECORD_LOG'] = true; } }
/** * вернет количество лайк мемберс * * результат в $this->_actions_data['like_members_count'] */ public function action_like_members_count($post_id = null) { if ($post_id === null) { if (empty($_REQUEST['post_id']) || !is_numeric($_REQUEST['post_id'])) { return; } $post_id = $_REQUEST['post_id']; } $this->_actions_data['like_members_count'] = ActiveRecord\ConnectionManager::get_connection()->query_and_fetch_one('SELECT count(id) as count FROM posts_like_members WHERE post_id=' . $post_id); }
private function create_table_db() { switch ($this->dbdriver) { case 'mysql': $sql_table = "CREATE TABLE " . $this->controller_name . " ("; $sql_table .= "id INT(9) NOT NULL AUTO_INCREMENT PRIMARY KEY ,"; foreach ($this->arrayjson as $index => $value) { $sql_table_aux = ""; switch ($value['type']) { case 'text': case 'image': case 'file': if ($value['multilanguage'] == "TRUE") { foreach ($this->languages as $prefix => $language) { $sql_table_aux .= $index . "_" . $prefix . " varchar(256) DEFAULT '' "; if ($value['required']) { $sql_table_aux .= "NOT NULL, "; } else { $sql_table_aux .= ", "; } } $sql_table .= $sql_table_aux; } else { $sql_table .= $index . " varchar(256) DEFAULT '' "; if ($value['required']) { $sql_table .= "NOT NULL, "; } else { $sql_table .= ", "; } } break; case 'textarea': if ($value['multilanguage'] == "TRUE") { foreach ($this->languages as $prefix => $language) { $sql_table_aux .= $index . "_" . $prefix . " text DEFAULT '' "; if ($value['required']) { $sql_table_aux .= "NOT NULL, "; } else { $sql_table_aux .= ", "; } } $sql_table .= $sql_table_aux; } else { $sql_table .= $index . " text DEFAULT '' "; if ($value['required']) { $sql_table .= "NOT NULL, "; } else { $sql_table .= ", "; } } break; case 'checkbox': $sql_table .= $index . " INT(1) "; if ($value['required']) { $sql_table .= "NOT NULL, "; } else { $sql_table .= ", "; } break; case 'select': case 'radio': $sql_table .= $index . " varchar(32) DEFAULT '' "; if ($value['required']) { $sql_table .= "NOT NULL, "; } else { $sql_table .= ", "; } break; case 'selectbd': $sql_table .= $index . " INT(9) "; if ($value['required']) { $sql_table .= "NOT NULL, "; } else { $sql_table .= ", "; } break; case 'datepicker': $sql_table .= $index . " date, "; break; case 'hidden': $sql_table .= $index . " INT(9) NOT NULL, "; break; } } $sql_table .= "created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "; $sql_table .= "updated_at TIMESTAMP NOT NULL"; $sql_table .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8;"; break; } $conn = ActiveRecord\ConnectionManager::get_connection("development"); $result = (object) $conn->query($sql_table); //$result = TRUE; if ($result) { return TRUE; } else { $this->errors = lang('scaffolds_error_bd') . "<br>{$sql_table}"; return FALSE; } }
public function set_up() { $this->column = new Column(); $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection()); }
public function testSubstituteEscapeQuotesWithConnectionsEscapeMethod() { $conn = ActiveRecord\ConnectionManager::getConnection(); $a = new Expressions(null, 'name=?', "Tito's Guild"); $a->setConnection($conn); $escaped = $conn->escape("Tito's Guild"); $this->assertEquals("name={$escaped}", $a->toS(true)); }
public function test_substitute_escape_quotes_with_connections_escape_method() { $conn = ActiveRecord\ConnectionManager::get_connection(); $a = new Expressions(null, 'name=?', "Tito's Guild"); $a->set_connection($conn); $escaped = $conn->escape("Tito's Guild"); $this->assert_equals("name='{$escaped}'", $a->to_s(true)); }
static function change_orders_categories($category, $order = 1) { $conn = ActiveRecord\ConnectionManager::get_connection("development"); $result = $conn->query('UPDATE categories SET orden = ' . $order . ' WHERE id = ' . $category); return $result; }