/** * Create a new database table object. * * @param Webdb_DBMS_Database The database to which this table belongs. * @param string $name The name of the table. */ public function __construct($db, $name) { $this->_database = $db; $this->_db = $db->get_db(); $this->_name = $name; if (!isset($this->_columns)) { $this->_columns = array(); $columns_info = $this->_db->query(Database::SELECT, 'SHOW FULL COLUMNS FROM ' . $this->_db->quote_table($name), FALSE); foreach ($columns_info as $column_info) { $column = new Webdb_DBMS_Column($this, $column_info); $this->_columns[$column->get_name()] = $column; } } //$this->_config = Kohana::config('webdb')->file_locations; }
/** * Determine whether a given value is valid for a foreign key (i.e. is the * title of a foreign row). * * @param Webdb_DBMS_Column $column * @param integer $col_num * @param integer $row_num * @param string $value * @return FALSE if the value is valid * @return array error array if the value is not valid */ protected function validate_foreign_key($column, $col_num, $row_num, $value) { $foreign_table = $column->get_referenced_table(); if (!$this->get_fk_rows($foreign_table, $value)) { $link = '<a href="' . $foreign_table->get_url() . '" title="Opens in a new tab or window" target="_blank" >' . $foreign_table->get_title() . '</a>'; return "Value <code>{$value}</code> not found in {$link}"; } return false; }
/** * Determine whether a given value is valid for a foreign key (i.e. is the * title of a foreign row). * * @param Webdb_DBMS_Column $column * @param integer $col_num * @param integer $row_num * @param string $value * @return FALSE if the value is valid * @return array error array if the value is not valid */ public function validate_foreign_key($column, $col_num, $row_num, $value) { $foreign_table = $column->get_referenced_table(); if (!$this->get_fk_rows($foreign_table, $value)->valid()) { $route_params = array('action' => 'index', 'dbname' => $foreign_table->get_database()->get_name(), 'tablename' => $foreign_table->get_name()); $uri = Route::url('default', $route_params, TRUE); $a_params = array('target' => '_blank', 'title' => 'Opens in a new tab or window'); $link = HTML::anchor($uri, Webdb_Text::titlecase($foreign_table->get_name()), $a_params); return 'Value (' . $value . ') not found in ' . $link; } return FALSE; }