function setValue($values) { if ($values) { $ds = new TableReader('blog_tag'); $tags = $ds->select('tag')->where('blog_tag_id', $values, 'in')->orderby('tag')->fetchArray(); $this->_value = implode($this->separator . ($this->separator != ' ' ? ' ' : ''), $tags); } }
/** * Validates the passed value with respect to the options specified * * @param mixed $value The value that wants to be validated * @return bool True if the value is valid, false if not. */ function validate($value) { if (is_array($value) || is_object($value)) { $this->error = 'array_type'; return false; } $valid = $this->doGeneralChecks($value); if ($valid !== null) { return $valid; } $is_null = in_array($value, $this->options['null_values'], true); if ($this->options['required'] && $is_null) { $this->error = "required"; return false; } if ($is_null) { return true; } if ($this->options['expression'] && !preg_match($this->options['expression'], $value)) { $this->error = 'expression'; return false; } /** * WTF? in_array returns true if the array contains the number 0 * and the value searched is any string other than a number. */ if (!empty($this->options['in'])) { foreach ($this->options['in'] as &$in) { if ($in === 0) { $in = '0'; } } } if (!empty($this->options['in']) && !in_array($value, $this->options['in'])) { $this->error = 'in'; return false; } if (!empty($this->options['not_in']) && in_array($value, $this->options['not_in'])) { $this->error = 'not_in'; return false; } $str_value = (string) $value; //Assumes mbstring extension installed if ($this->options['max_length'] !== null && mb_strlen($str_value) > $this->options['max_length']) { $this->error = 'max_length'; return false; } //Assumes mbstring extension installed if ($this->options['min_length'] !== null && mb_strlen($str_value) < $this->options['min_length']) { $this->error = 'min_length'; return false; } if ($this->options['encoding']) { $converted = @iconv(AppConfig::CHARSET, AppConfig::CHARSET, $str_value); if (mb_strlen($converted) != mb_strlen($str_value)) { $this->error = 'encoding'; return false; } } $float_value = (double) $value; if ($this->options['max_value'] !== null && $float_value > $this->options['max_value']) { $this->error = 'max_value'; return false; } if ($this->options['min_value'] !== null && $float_value < $this->options['min_value']) { $this->error = 'min_value'; return false; } if ($this->options['db_in_column']) { list($table_name, $column_name) = $this->options['db_in_column']; $query = new TableReader($table_name); $count = $query->select(array('count', '*'))->where($column_name, $value)->fetchScalar(); if ($count == 0) { $this->error = 'db_in_column'; return false; } } if ($this->options['db_not_in_column']) { list($table_name, $column_name) = $this->options['db_not_in_column']; $query = new TableReader($table_name); $count = $query->select(array('count', '*'))->where($column_name, $value)->fetchScalar(); if ($count > 0) { $this->error = 'db_not_in_column'; return false; } } return true; }
protected function deleteRows($conditions, &$files_to_delete = array()) { if (!$conditions) { return true; } $rows = $this->getAllRows($conditions); $files_to_delete = $this->getFilesToDelete($rows, $files_to_delete); /** * Creates an array with all the the primary_key => value pairs of all the rows that have to be deleted. */ $row_conditions = array(); foreach ($rows as $row) { $values = array(); foreach ($this->primary as $primary) { $values[$primary] = $row[$primary]; } $row_conditions[] = $values; } $children = $this->schema->getChildren($this->name); foreach ($children as $child) { if (!isset($child['key'][2]) || is_null($child['key'][2])) { } elseif ($child['key'][2] == self::ON_DELETE_RESTRICT) { $reader = new TableReader($child['table']->getName()); foreach ($row_conditions as $row_condition) { foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $reader->where($column, $value); } } } if ($reader->count()) { return false; } } elseif ($child['key'][2] == self::ON_DELETE_CASCADE) { foreach ($row_conditions as $row_condition) { $child_conditions = array(); foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $child_conditions[$column] = $value; } } if (!$child['table']->deleteRows($child_conditions, $files_to_delete)) { return false; } } } elseif ($child['key'][2] == self::ON_DELETE_SET_NULL) { //Not implemented yet } } foreach ($this->getKeys() as $column => $key) { if ($key[2] == AdminTable::ON_DELETE_CASCADE_REVERSED) { $table = $this->schema->getTable($key[0]); foreach ($rows as $row) { if (!$table->deleteRows(array($key[1] => $row[$key[1]]), $files_to_delete)) { return false; } } } } $ds = new TableWriter($this->name); foreach ($conditions as $column => $value) { $ds->where($column, $value); } return $ds->delete(); }
private static function urlCountMatches($url_title, $table, $url_field, $extra) { $query = new TableReader($table); $query->where($url_field, $url_title, 'LIKE'); if ($extra) { $query->where($extra[0], $extra[1]); } return $query->count(); }
<html> <head> </head> <body> <?php $ROOT = dirname(__FILE__); include_once $ROOT . '/lib/php/SQLServerCredentials.php'; include_once $ROOT . '/lib/php/Log.php'; require_once $ROOT . '/lib/php/PDOConnection.php'; require_once $ROOT . '/lib/php/SQLControls.php'; require_once $ROOT . '/lib/php/TableReader.php'; $testTable = TableReader::get_table("items.js"); SQLControls::create_table($testTable); $testTable = TableReader::get_table("classifications.js"); SQLControls::create_table($testTable); $testTable = TableReader::get_table("classification_relations.js"); SQLControls::create_table($testTable); ?> </body> </html>